Optocouplers: Defending Your Microcontroller, MIDI, And A Hot Tip For Speed

Deep in the heart of your latest project lies a little silicon brain. Much like the brain inside your own bone-plated noggin, your microcontroller needs protection from the outside world from time to time. When it comes to isolating your microcontroller’s sensitive little pins from high voltages, ground loops, or general noise, nothing beats an optocoupler. And while simple on-off control of a device through an optocoupler can be as simple as hooking up an LED, they are not perfect digital devices.

But first a step back. What is an optocoupler anyway? The prototype is an LED and a light-sensitive transistor stuck together in a lightproof case. But there are many choices for the receiver side: photodiodes, BJT phototransistors, MOSFETs, photo-triacs, photo-Darlingtons, and more.

So while implementation details vary, the crux is that your microcontroller turns on an LED, and it’s the light from that LED that activates the other side of the circuit. The only connection between the LED side and the transistor side is non-electrical — light across a small gap — and that provides the rock-solid, one-way isolation.

Continue reading “Optocouplers: Defending Your Microcontroller, MIDI, And A Hot Tip For Speed”

Sophie Wilson: ARM And How Making Things Simpler Made Them Faster & More Efficient

Sophie Wilson is one of the leading lights of modern CPU design. In the 1980s, she and colleague Steve Furber designed the ARM architecture, a new approach to CPU design that made mobile computing possible. They did this by realizing that you could do more, and quicker, with less. If you’ve use a Raspberry Pi, or any of the myriad of embedded devices that run on ARM chips, you’ve enjoyed the fruits of their labor.

It all began for Sophie Wilson with an electric lighter and a slot machine (or fruit machine, as they are called in the UK) in 1978. An aspiring thief had figured out that if you sparked an electric lighter next to the machine, the resulting wideband electromagnetic pulse could trigger the payout circuit. Electronics designer Hermann Hauser had been tasked with fixing the problem, and he turned to Wilson, a student working at his company.

Wilson quickly figured that if you added a small wideband radio receiver to detect the pulse, you could suppress the false payout, foiling the thief. Impressed with this innovation, Hauser challenged Wilson to build a computer over the summer holidays, based in part on a design for an automated cow feeder that Wilson had created at university. Wilson created this prototype computer that looked more like a hand-wired calculator than a modern computer, but the design became the basis for the Acorn System 1, the first computer that Hauser’s new company Acorn Computers launched in 1979. Continue reading “Sophie Wilson: ARM And How Making Things Simpler Made Them Faster & More Efficient”

The Aluminum Wiring Fiasco

Someone who decides to build a house faces a daunting task. It’s hard enough to act as the general contractor for someone else, but when you decide to build your own house, as my parents did in the early 1970s, it’s even tougher. There are a million decisions to make in an information-poor and rapidly changing environment, and one wrong step can literally cast in stone something you’ll have to live with forever. Add in the shoestring budget that my folks had to work with, and it’s a wonder they were able to succeed as well as they did.

It was a close call in a few spots, though. I can recall my dad agonizing over the wiring for the house. It would have been far cheaper to go with aluminum wiring, with the price of copper wire having recently skyrocketed. He bit the bullet and had the electrician install copper instead, which ended up being a wise choice, as houses that had succumbed to the siren call of cheaper wiring would start burning down all over the United States soon thereafter.

What happened in the late 60s and early 70s in the residential and commercial electrical trades was an expensive and in some cases tragic lesson in failure engineering. Let’s take a look at how it all happened.

Continue reading “The Aluminum Wiring Fiasco”

Biasing That Transistor: The Common Emitter Amplifier

If you open up the perennial favourite electronics textbook The Art Of Electronics and turn to the section on transistors, you will see a little cartoon. A transistor is shown as a room in which “transistor man” stands watching a dial showing the base current, while adjusting a potentiometer that limits the collector current. If you apply a little more base current, he pushes up the collector a bit. If you wind back the base current, he drops it back. It’s a simple but effective way of explaining the basic operation of a transistor, but it stops short of some of the nuances of how a transistor works.

Of course the base-emitter junction is a diode and it is not a simple potentiometer that sits between collector and emitter. The “better” description of these aspects of the device fills the heads of first-year electronic engineering students until they never want to hear about an h-paramater or the Ebers-Moll model of transistor function again in their entire lives. Fortunately it is possible to work with transistors without such an in-depth understanding of their operation, but before selecting the components surrounding a device it is still necessary to go a little way beyond transistor man.

Continue reading “Biasing That Transistor: The Common Emitter Amplifier”

Directly Executing Chunks Of Memory: Function Pointers In C

In the first part of this series, we covered the basics of pointers in C, and went on to more complex arrangements and pointer arithmetic in the second part. Both times, we focused solely on pointers representing data in memory.

But data isn’t the only thing residing in memory. All the program code is accessible through either the RAM or some other executable type of memory, giving each function a specific address inside that memory as entry point. Once again, pointers are simply memory addresses, and to fully utilize this similarity, C provides the concept of function pointers. Function pointers provide us with ways to make conditional code execution faster, implement callbacks to make code more modular, and even provide a foothold into the running machine code itself for reverse engineering or exploitation. So read on!

Function Pointers

In general, function pointers aren’t any more mysterious than data pointers: the main difference is that one references variables and the other references functions. If you recall from last time how arrays decay into pointers to their first element, a function equally decays into a pointer to the address of its entry point, with the () operator executing whatever is at that address. As a result, we can declare a function pointer variable fptr and assign a function func() to it: fptr = func;. Calling fptr(); will then resolve to the entry point of function func() and execute it.

Admittedly, the idea of turning a function into a variable may seem strange at first and might require some getting used to, but it gets easier with time and it can be a very useful idiom. The same is true for the function pointer syntax, which can be intimidating and confusing in the beginning. But let’s have a look at that ourselves.

Continue reading “Directly Executing Chunks Of Memory: Function Pointers In C”

Accessing Blockchain On ESP8266 Using The NodeMCU Board

Blockchains claim to be public, distributed, effectively immutable ledgers. Unfortunately, they also tend to get a little bit huge – presently the Bitcoin blockchain is 194GB and Ethereum weighs in at 444GB. That poses quite an inconvenience for me, as I was looking at making some fun ‘Ethereum blockchain aware’ gadgets and that’s several orders of magnitude too much data to deal with on a microcontroller, not to mention the bandwidth cost if using 3G.

Having imagined a thin device that I could integrate into my mobile phone cover (or perhaps… a wallet?) dealing with the whole blockchain was clearly not a possibility. I could use a VPS or router to efficiently download the necessary data and respond to queries, but even that seemed like a lot of overhead, so I investigated available APIs.

As it turns out, several blockchain explorers offer APIs that do what I want. My efforts get an ESP8266 involved with the blockchain began with two of the available APIs: Ethplorer and Etherscan.

Continue reading “Accessing Blockchain On ESP8266 Using The NodeMCU Board”

The Anxiety Of Open Source: Why We Struggle With Putting It Out There

You’ve just finished your project. Well, not finished, but it works and you’ve solved all the problems worth solving, and you have a thing that works for you. Then you think about sharing your creation with the world. “This is cool” you think. “Other people might think it’s cool, too.” So you have to take pictures and video, and you wish you had documented some more of the assembly steps, and you have to do a writeup, and comment your code, and create a repository for it, maybe think about licensing. All of a sudden, the actual project was only the beginning, and now you’re stressing out about all the other things involved in telling other people about your project, because you know from past experience that there are a lot of haters out there who are going to tear it down unless it’s perfect, or even if it is, and even if people like it they are going to ask you for help or to make one for them, and now it’s 7 years later and people are STILL asking you for the source code for some quick little thing you did and threw up on YouTube when you were just out of college, and of course it won’t work anymore because that was on Windows XP when people still used Java.

Take a deep breath. We’ve all been there. This is an article about finding a good solution to sharing your work without dealing with the hassle. If you read the previous paragraph and finished with a heart rate twice what you started, you know the problem. You just want to share something with the world, but you don’t want to support that project for the rest of your life; you want to move on to new and better and more interesting projects. Here are some tips.

Continue reading “The Anxiety Of Open Source: Why We Struggle With Putting It Out There”