BeagleBone Black GPIO Benchmark

Look what the mailman brought: It’s a shiny (or maybe matte?) BeagleBone Black, freshly arrived (actually it’s been over a month, but time sure flies…) from Newark element14! I’ve been doing Raspberry Pi related hacking for a while, but especially when the Pi was still fresh and new, I did from time to time consider if the grass would be greener on other side of the fence. Or blacker, in this case, as I mean BeagleBone Black.

BeagleBone was long very much more powerful than Raspberry Pi, but now that Pi2 has come out, price and specification-wise they are closer than ever. A quick personal comparison chart:

  BeagleBone Black Raspberry Pi 2 (B)
Price 46 € (Element14) 32 € (Element14)
Processor 1GHz single-core Cortex-A8 0.9GHz quad-core Cortex-A7
Memory 512MB DDR3 1GB
Connections USB host, USB device, micro-HDMI 4x USB, HDMI, 3.5mm Audio/analog video
GPIO 2x 46 pin headers (65 digital I/O) 40 GPIO pins (26 digital I/O)
Other 4GB integrated flash, works as USB device camera and display interface on board

When Pi1 was out, the BeagleBone Black with the more modern Cortex-A8 chip and higher clockrate was definitely the more powerful, but now with 4-core Pi2, the tables have somewhat turned. Still, the clockrate is higher and there’s more GPIO. And speaking of GPIO, my Raspberry Pi vs. Pi2 GPIO benchmark has gotten a lot of interest, so I thought the best way to take this black beauty for a test drive would be to benchmark BeagleBone Black GPIO in a similar way.

Test setup

Test bench

The test subject is the most recent revision C of BeagleBone Black. I followed the (a bit lacking in detail and readability) Getting Started guide and downloaded the latest Debian Jessie image (8.3, 2016-01-24), flashed it to card and ran apt-get update and apt-get dist-upgrade (2016-04-14).
Continue reading BeagleBone Black GPIO Benchmark

RedBear Duo First Impressions

Look what a little beauty the mailman brought! I participated the Red Bear Duo Kickstarter Campaign a while ago, and the folks at Redbear did a really professional job in delivering on the promises of that campaign.

Headline features include ARM Cortex M3 120 MHz microcontroller with plenty of RAM and flash, and of course dual WiFi and Bluetooth connectivity. Setting up the Duo was quite simple by following the instructions provided, once I realized I’ll need to use the Zadig tool as instructed in this sub-howto (Redbear guys: I think 4-5 separate pages to get one started on Windows is something that might be optimized), I got the firmware updated and everything set up. Basic outline of my installation was about this:

  1. Plug in the board and see LEDs light up
  2. Try to install the serial driver, only to realize I already had working serial (I probably have all usb serial drivers between heaven and earth installed due to encounters with various devboards)
  3. Connect to COM6, 9600 with Putty to verify it works as it should, note down device ID
  4. Install dfu-util, and wonder why I cannot connect to the device, even with the yellow LED (looked more like yellow-green though) was blinking as it should
  5. Use Zadig tool to install drivers when in DFU mode
  6. Successfully update firmware and stuff
  7. Reboot the board a couple of times and connect with Putty to COM6 to see the IP address
  8. Visit the IP address to see the LED demo is working as it should! Nice! Cloud Programming

Once I had the basics figured out, I wanted to try out the cloud development platform. It seems like an Arduino on cloud steroids, meaning that instead of flashing the device over USB cable, you write the software in a web interface, and flashing the device will upload the sketch to your device using the active wifi connection on Redbear Duo (I believe the device is periodically polling service to see if there is a new sketch to download).
Continue reading RedBear Duo First Impressions

USB Mouse with ATmega32U4 Pro Micro Clone and LUFA

I have spent a fair amount of time with 8-bit AVR microcontrollers and one of the cooler things has been the V-USB library which implements low-speed USB with clever (and very time-critical) bit-banging. The popularity of my USB tutorials is a testament to its usefulness, and I’ve gotten lots of mileage out of that.

There are, however, some limitations to software USB with such a low spec microcontroller. USB communication hogs up the MCU completely during USB communication, which means you lose dozens of microseconds in random (or in many cases 8 ms) intervals. This rules out things like software UART at reasonable speeds (which I discovered when trying to implement MIDI on Adafruit Trinket). And more powerful ATmega328-based dev boards like Pro Trinket start to get quite large.

ProMicro on a breadboard

Not so with this tiny beauty shown in the image. It’s a ATmega32U4 based board, where the U4 means it has hardware USB support. The form factor is extremely compact 12 pin header length, which leaves 5 rows free on the smallest prototyping breadboards. That means you can have a DIP8 component with a few resistors on the same breadboard (such as a 6N137 optocoupler which is nice for MIDI… ;).

And the best part is, that because the chip is flashed with same firmware used in Arduino Leonardo (and a largely matching pinout), you can use Arduino for programming, and avrdude supports it out of the box.

Actually, scratch the above statement. The best part is the price. The board is based on Sparkfun Pro Micro 16 MHz, but it’s actually a Chinese clone, which you can get for $4 via DealExtreme and from quite many places in AliExpress: Just search for ATmega32U4 and they will come up. This means you can just order five and solder them into whatever project you’ll make permanently. And unlike Arduino Micro (for which clones exist as well), this has the micro-USB port already in place.

Using Pro Micro without Arduino IDE

Now you can just follow SparkFun’s instructions on how to use that thing on Arduino (short version: select Leonardo as board type, and look up the schematic if you are unsure which pins are connected to LEDs, etc.). But if you’re like me and want to get to raw metal, avr-gcc and avrdude is the way to go. Here’s a simple blinky demo:
Continue reading USB Mouse with ATmega32U4 Pro Micro Clone and LUFA

MIDI to USB Adapter with Teensy LC

Among my recent electronics purchase spree was the amazing Teensy LC from PJRC. It has a nice ARM Cortex-M0+ processor, real hardware USB, and what’s the nicest part, an Arduino add-on called Teensyduino which enables easy programming with Arduino, but with support for many of the hardware features.

Now I started playing piano a while ago, and just a few weeks ago bought a Pianoteq license to send notes via MIDI to my computer, and render high quality piano sound to speakers. However, it turns out my $8 USB-MIDI adapter from DealExtreme had a less than perfect implementation, essentially changing pedal events into “note on” events!

Thankfully, I had a MIDI connector and a high-speed optocoupler at hand, and with these I could implement a MIDI in rather easily. After some investigation with Arduino Uno, it seemed quite simple to receive the serial MIDI bytes and dump them over Arduino serial (I’ll write another post about this later).

However, Arduino cannot become a USB MIDI device very easily, so here comes the really nice part: Teensy LC can, and the Teensyduino add-on included a working USB MIDI and also serial MIDI libraries!

The Hardware

The Wikipedia page for MIDI essentially shows the required circuitry for receiving MIDI data – wire the DIN cable pins 4 and 5 through the receiving side of optocoupler and put a 200 ohm resistor in series with it. A diode is also suggested for reverse current (ESD) protection, but I skipped that. You can start with a LED instead of optocoupler to see it lights up if you’re unsure you have pins 4 and 5 the right way. Or just put the LED (with a resistor) on the other side of the optocoupler first.

The HCPL-2531 I had at hand requires an additional VCC connection on the sending side. After some experimentation, a 4k7 ohm pullup resistor between VCC and VO1 (NPN-transistor base?) gave the cleanest signal out. The wiring diagram (thanks Diptrace!) is shown below:

Teensy LC MIDI schematic
Continue reading MIDI to USB Adapter with Teensy LC

Adafruit Trinket USB keyboard without Arduino

Happy New Year 2016! After a long hiatus in electronics, I have been quite busy in the last month or so. I have a bigger (USB MIDI related) project posting coming up, but just wanted share a small nugget already.

I ordered a big chunk of things recently from Adafruit shop and Sparkfun. Among them was the lovely Adafruit Trinket (which actually came as a free bonus because I spent way too much on black friday :).

Now I am planning a project which involves transforming the very compact, but already USB-enabled Trinket into a USB MIDI device. However, there are two problems:

  1. Adafruit examples for USB come in Arduino form
  2. There are no USB MIDI examples

I somewhat dislike the high-level Arduino environment in cases where low-level performance is needed (and the V-USB implementation is one of those places), and for my later MIDI part, I will need fine-grained control to juggle serial communication and USB. Also, all USB MIDI examples are on “bare metal”, so the Adafruit example Arduino code would require deeper knowledge of Arduino inner workings than I have.

Time to do some chopping!

Slimming Down the TrinketKeyboard Example

I decided to adapt the excellent base code in Adafruit Trinket USB GitHub repository, but trim the keyboard example to bare essentials (my next step will be to transform it into a USB MIDI device, so the less code I have to adapt, the better). Turns out this was quite simple to do:
Continue reading Adafruit Trinket USB keyboard without Arduino

Simple X Audio Switch (Double-Y)

I’ve had a small problem over a year: I have two headphone amplifiers, a transistor-based O2 headphone amp, and a tube-based Little Dot MKII. I also have two sets of headsets. Because switching the cables all the time is somewhat tedious, I haven’t really used the other amp and headphone set.

There are several Y switches that you can buy, but most seemed either expensive or mostly tailored towards electric guitar enthusiasts. And I would still need to combine two Y switches to toggle between the two amps and headphones. As the construction is really simple, I decided to solder my own. Here’s a short tutorial on how to make one yourself. You’ll need:

  1. 4 audio connectors (I chose 3.5mm over RCA), two to each end
  2. 2 switches with at least 3 connectors (left, right, ground) – I chose two 4 way switches
  3. A box where you can drill holes for the connectors and switches
  4. Small length of wire, some solder and soldering iron

1. The Schematic

Audio X switch schematic

The design of the switch is extremely simple. In both ends, three wires come from each of the two connectors to a switch, and the switches are connected to each other. I chose not to combine any ground lines to avoid ground loops. You need also to select a switch which breaks the connection on one side before connecting the other so the amplifiers will not feed into each other.

2. Soldering the wires

Despite the simple construction, there is a lot of soldering involved. Each of the four connectors will have ground plus left and right channels, and all have the switch on the other end. That makes 24 solder points (4x3x2), and there’s six more between the switches for a total of 30 points. The 3.5mm connectors had small “L” and “R” markings to tell which channel is left and which is right. I used different colors of wires for each type to avoid mixing L, R and ground.

Continue reading Simple X Audio Switch (Double-Y)

Giving Raspberry Pi Camera Nearsight with Reading Glasses

Raspberry Pi with Reading Glasses

Back again! The summer holidays gave me some time to write after a long hiatus, and this time it’s a Raspberry Pi related article. I’ve had the excellent opportunity to play around with a Raspberry Pi Camera Module for a few days. Or actually modules, as I got both the normal and NoIR without IR filter (more about that later) from Farnell / Element 14. They also stock an excellent selection of Pi accessories, so be sure to check those out, too.

But without further ado, let’s get onward. I’m still thinking up cool projects to do with the camera, so if you have nice ideas, please feel free to share them in the comments section!

Unboxing and First Impressions

Raspberry Pi IR camera and a normal one

The camera modules arrived in simple boxes, branded with element14 logo and URL. A nice additional touch was an included instruction sheet outlining the installation procedure, as well as a link to with further info.

Both the IR-filtered (the one showing normal visible light) and the NoIR (the one without the filter, and thus showing both normal light AND infrared) have exact same outward appearance. The installation was quite easy, but the flat cable offers less positioning and flexing freedom that your standard webcam – obviously the Pi camera is meant for more integrated installations.

Raspberry Pi camera electronics
Continue reading Giving Raspberry Pi Camera Nearsight with Reading Glasses

Picoscope Beta for Linux

Picoscope for Linux

Tux logo by Larry Ewing, Simon Budig, Anja Gerwinski

I’ve been a big fan of Picotech’s USB connected PC oscilloscopes ever since I purchased my first PicoScope 2204 almost two years ago. I liked the compact form factor on my desk a lot, and the powerful Picoscope software for Windows – Picotech makes only one version of this software so you get the same functionality with a £159 ($260) 2204 scope as a £5,995 ($9,900) PicoScope 6407 user would – although of course the scope features would be wildly different.

Now Picoscope is a great piece of Windows software and as I generally use Win7 to avoid reboots every time I want to use Photoshop or play a session of Mass Effect, it’s been perfect for me. However, quite a few of electronics enthusiasts are also big advocates of open software movement, and while Picotech has had drivers and SDK for Linux for a while to implement things like my realtime composite decoder, the fact that there is no Linux version of the oscilloscope software has been unfortunate. So when I noticed in the latest Picotech newsletter that there is now a beta of Picoscope for Linux, I knew I had to take it for a spin.

Installing Picoscope on Linux Mint 15

Picotech’s installation process is built on apt packaging system, so a Debian-based Linux distro is the easiest installation target. This includes the wildly popular Ubuntu and Linux Mint distros, which means mainstream Linux users are well catered to. In Picotech forums, the beta thread had at least one user who extracted necessary stuff from the .deb packages and installed the software for Fedora, too.

In Debian-based Mint, the installation went without any hiccups just by following the instructions at Picotech’s Linux Drivers page. Note that sudo apt-get install picoscope also installs all drivers so you don’t need to install your model-specific driver separately. Essentially the installation is just:

sudo echo deb picoscope main >> /etc/apt/sources.list
wget -O - | sudo apt-key add -
sudo apt-get update
sudo apt-get install picoscope

Continue reading Picoscope Beta for Linux

Turning PC On with a Knock Using ATtiny45 and a Piezoelectric Sensor

PS/2 with ATtiny45

Today’s post is something I’ve prepared for a long time. Hardware-wise it’s a simple thing – ATtiny45 emulating a PS/2 device, sending a keypress when three knocks are detected in the attached piezoelectric sensor (or piezo buzzer as they are also called). But if your computer can boot on PS/2 keyboard input and you have your computer stowed somewhere hard to reach (or just want to impress your friends), it’s a pretty neat little gadget! Here’s a video of it in action:

My PC takes a few seconds to put anything on display, but if you look at the bottom right corner, you can see the blue power LEDs light up immediately after the knocks.

What You’ll Need

Hardware-wise this hack is super simple. You’ll need less than $10 in parts and many probably already have these lying around:

  • ATtiny45. Actually, any ATtiny or ATmega with 4kB or more flash, A/D converter and two timers will work with small adjustments, and with -Os -DMINIMAL compiler flags also 2kB MCUs (ATtiny2313 doesn’t have a A/D but you can either work around it or use a button)
  • Piezo buzzer and 1 Mohm resistor to act as knock sensor
  • PS/2 connector, or alternatively a passive USB-PS/2 adapter (I have half a dozen from old keyboards and mice) and USB cable (like the one I used in my V-USB tutorial)
  • Breadboard and wire. Alternatively you can solder it on a simple PCB like I eventually did.
  • Optionally, a 4k7 ohm pullup resistor for RESET line, and a LED and 330 ohm resistor to indicate state

The Schematic and Breadboard Setup


The PS/2 part as discussed in my minimal PS/2 keyboard post doesn’t require any other hardware than the ATtiny. The piezo element uses a 1 Mohm resistor like in the Arduino Knock Sensor tutorial, providing a path for voltage level to get back to zero over time. The LED is connected to PB4.

The PS/2 connector also provides power to the device. Instead of soldering a custom PS/2 connector for the project, I took a passive USB-PS/2 adapter I had lying around and used a multimeter to find out which USB pins correspond to the PS/2 ones. Not surprisingly, PS/2 GND and VCC are connected to USB GND and VCC. In my adapters, PS/2 clock was connected to D+ and data to D-. You can see the mnemonic printout I made on that one below, as well as one possible breadboard configuration.
Continue reading Turning PC On with a Knock Using ATtiny45 and a Piezoelectric Sensor

Tutorial: State Machines with C Callbacks

State machine

Many electronics projects involve the device transitioning from one state to another. On a high level, it could be that your project is initially in a state where it awaits input, and once it receives it, it goes to another state where it performs a series of actions, eventually returning back to the initial state. On a lower level, many communications protocols are often simple or increasingly complex state machines. In many cases, an elegantly implemented state machine can simplify your code and make it easier to manage.

There are several methods to implement state machines programmatically starting from simple if-conditions to state variables and switch structures. In this tutorial I’ll cover a slightly more advanced method of using callbacks or “function pointers” as they are implemented in C. This has some performance benefits, makes up for some clean code, and you’ll learn a bit on the way!

State Machines with Conditionals

First, to introduce the idea of a state machine, lets take a simple example: Blinking LEDs. Imagine you want the LED to turn on for a second, and then turn off. We could do it with a simple 2-state machine:

enum states { 

enum states state = LED_OFF;

while(1) {
  if(state == LED_OFF) {
    state = LED_ON;
  } else {
    state = LED_OFF;
  sleep(1); // sleep for a second

If you can understand the code above, you have pretty much grasped the fundamentals of state machines. We have some processing specific to given state, and when we want to go to another state, we use a variable (in this example it’s called state) to do that. And by the way, if you haven’t encountered enum before, you should check out Enumerated type in Wikipedia. It’s a very handful tool to add to your C coding arsenal.
Continue reading Tutorial: State Machines with C Callbacks