Adafruit 10DOF Sensor Library for BeagleBone Black

Screen Shot 2016-01-02 at 3.11.25 PM
L3GD20 Gyro Ouput in CSV Format

As part of my ongoing rover project, I have started writing C++ libraries for the various sensors and actuators. The first device I have begun to tackle writing a library for is the Adafruit 10DOF sensor. This sensor has libraries available for Arduino boards and in Python. Writing library code for the sensor hasn’t been without issues but has been a great learning experience. There are a lots of online tutorials but I have found that Derek Molloy’s tutorials have been consistently helpful. I recently bought Derek Molloy’s book Exploring BeagleBone: Tools and Techniques for Building with Embedded Linux to aid me in working with the BeagleBone Black. I did so because I found his freely available tutorials extremely thorough and have had the most success following them compared to other material online. His book includes the material in his tutorials plus more including  introductory topics such as administering Linux and basic electronic components to advanced topics such as interacting with the onboard Programmable Real-time Units (PRUs).

To start writing the driver for the 10DOF, I focused on one sensor at a time. I took the Arduino code for each sensor provided by Adafruit and went about replacing all calls to the Wire library to appropriate calls to the libmraa library. The 10DOF sensor uses the I2C bus to communicate with all the sensors and, initially, I used Derek Molloy’s I2CDevice class to handle communication. After some success with this class, I decided to use Intel’s libmraa for handling all communication between the BeagleBone  Black and peripherals. I made this switch because Molloy’s class is not as complete as libmraa and only deals with I2C communication whereas the libmraa api includes SPI, GPIO, UART and PWM functionality. This means I can use libmraa for controlling the motors and other sensors instead of having to write my own code or relying on separate libraries for sensors using different communication interfaces.

Writing the driver for each sensor was not as simple as replacing some functions in the Arduino code. The datatypes in the Arduino code had to be changed to match those recognized by the g++ compiler while staying true to the datatype used to store the data in the sensor’s registers. This required a close reading of each sensor’s data sheet to make sure I was storing the register data in variables with the same datatype. I won’t go into fine detail as to what changes I made since you can see the code yourself and compare it to the original Adafruit Arduino code.

There were a few times while working with the 10DOF sensor when I lost connection to it. This can occur when a register on a sensor is mishandled causing the sensor lock up becoming unresponsive. To deal with these lock ups when working remotely, I wired a P2N2222 transistor into the 10DOF sensor circuit so that I could power cycle the sensor if it became unresponsive. This has happened a couple of times while developing the driver software. I’ve been careful to make sure I’m properly working with the registers but mistakes still happen. Thankfully no damage was done and I haven’t needed to use this feature yet.

I’m still working on the driver and will post another update when it’s completed. The code for the BMP180, L3GD20 and LSM303 sensors can be found on my github page. Just make sure you have the libmraa library installed on your BeagleBone Black. This code is still under development and is provided with no warranty so use it at your own risk. If you have any comments on the code, please use the github issues page. My plan is to roll these separate libraries into one library for use with the 10DOF sensor but I will keep the repos for each sensor for those who buy the sensors individually.


Smart Light: Final Circuit and Enclosure

Here is quick update on the progress of my Smart Lamp project I started near the end of the summer. As I mentioned in my previous post, I have already put together a prototype circuit to test controlling the flow of power to a plugged in lamp based on the input of the light sensor. Below is the proposed final circuit for the smart light project. The only change I foresee is the removal of the LED indicator since the Trinket and the AC-DC converter both feature LEDs on them and space is tight in the enclosure.

Smart Lamp Final Circuit

Smart Lamp Final Circuit

I’ve bought a Hammond ABS enclosure to hold all the components. I removed the mounting stand-offs as they did not match well with any of the components and the relay would not fit if mounted to them. The white board you see in the picture is foam board which I was thinking of using as a medium to mount the parts to. My current plan is the use Velcro to secure the components right to the case. I tested this using my EDtracker build and a small Hammond enclosure and it worked well. The tracker is secure when in the case but can be easily removed if need be. I have included a picture that tries to illustrate how the extension cord will be routed through the enclosure. I still need to drill a hole for the end on the left of the picture.

The biggest change since my last post is the addition of a spare USB charger I had. This will serve the purpose of powering the microcontroller right off of the extension cord. I have removed the USB port from the charger and soldered wires where the power pins were in order to keep the USB port on the Trinket free for programming. Unlike the circuit shown above, the trinket is mounted on a (trimmed) proto-board in order to easily allow multiple connections for powering the relay and sensor.

There’s just testing, soldering and calibration left! I’ll post a final build update regarding the testing and calibration with pictures of the final product soon.

EDTracker Build

EDTracker Mounted
The EDTracker mounted to my headphones using Velcro strips.

The Kit

I’ve been playing Elite Dangerous since it was released and have been playing similar games for as long as I have been gaming. Since its release, I had wished that I could better utilize the ability to move my player’s head around while flying. It was only a few weeks ago that I heard of EDTracker while reading a post on reddit’s /r/EliteDangerous. EDTracker is exactly what it sounds like: a head tracker for Elite Dangerous. Actually it’s a head tracker that can be used for whatever game allows the use of a joystick to be assigned to head movement. It’s recognized by a PC as a USB joystick. For more details, checkout the EDTracker homepage. You can order parts form the EDTacker page or there is a kit available from I bought the kit available from featuring the now discontinued 9150 module. The 9150 has been replaced by the 9250. The difference seems to be increased performance while being smaller and using less power than the 9150 module. As you can see from the pricing is that this kit is very cheap for the components included. Similar components from other sites such as Sparkfun will cost you more as of early September 2015. Also, this kit is many times cheaper than other head tracking solutions such as TrackIR. So if you’re willing to put in the work, you can get very accurate head tracking as a fraction of the price.

The Build

building the tracker was not walk in the park since I was going for as compact a build as I could. Thankfully I didn’t have to design the circuit myself. The EDTracker website hosts a guide written by community member Bartybee that outlines how to build the tracker as you see it in the pictures. As you can see, The PCB is cut to size then sandwiched between the Arduino and 9150. Soldering the tracker together in this manner was tedious if your not an expert at soldering. Bartybee’s guide also calls for a very thin gauge wire described as “doll house wire”. The holes on the PCB allow for wire that is no bigger then 17 AWG including the wire’s casing. This wire allowed him to run it through the holes in the PCB. I didn’t have any wire that would fit through the PCB holes so I was forced to make it work with the wires soldered on the top side. This worked fine but it got a little crowed near the end. The wire soldered to the 9150 header didn’t interfere with mounting the 9150. I just made sure the wires were soldered as far down the post as I could without melting the header (too badly!).

I’d suggest buying the pre-made PCB if you’re looking for a cleaner and easier build. I didn’t feel like paying the extra cost so I paid for it in elbow grease! If you choose not buy the premade PCB then make sure you research cutting PCB. I got by with a heavy duty box cutter and patience but a hack saw would be a better choice. Thankfully, all was well once I double checked everything and powered it up for the first time.

The Experience

The tracker is used with a client program that you must download from the EDTracker website. You will also need to download the Arduino drivers from the site but only if you don’t have the Arduino IDE installed already. The drivers allow the PC to recognize the Arduino used in the tracker so that the client can flash it with the firmware they’ve written. I already had the IDE installed so this wasn’t an issue. I had no issues getting the client to recognize the tracker or flashing the firmware. Once that was done, I made sure to watch the calibration video made by the developers which explains how to use the client as well as how to calibrate the tracker. The calibration is very simple but is something that must be done every time the device is powered on. In fact, the tracker spends the first 20 seconds after powering up calibrating so be ready for that before you plug the USB cable in. From there, I booted up Elite and mapped the head look axes (up/down and right/left) with a only a very small deadzone.

With the tracker mapped, I jumped into the game and was quickly blown away by the added immersion that the head tracker added to the experience. The accuracy is great and the tracker is always responsive. I have very few issues with drift and whatever drift that has occurred was due to my poor initial calibration on power up. The only issue I have is mounting it to my head phones as they do not have a solid band but rather two stiff cable supports that connect the ear pads as you can see in the first photo.

I would readily recommend this to anyone who has a flight sim they enjoy even if its only casually. This tracker greatly increases the immersion while gaming so it is easily worth the price. Also, don’t be afraid of putting together yourself as the guide is very complete and there are videos that go through common issues that come up when putting the tracker together. Another thin to keep in mind though is that the tracker is not wireless so you will need a USB cable that is long enough to connect to your PC while allowing you to sit comfortably. I have seen others wrap their headphone and USB cables together to help cut down on the mess of wires. If you can handle the extra cable and the build then you too can bring your favourite flight sim experience to another level!

Smart Light Test Circuit

The light sensor (plus a few other goodies) arrived from Adafruit a couple of week ago. Since then I’ve had a chance to bread board the final circuit that will make up the smart lamp. I still have to order a case for the final product and decide where to mount the light sensor for optimal exposure. The plan has been modified from creating a smart lamp to creating a smart extension cord as I found out that there are multiple sets of lights that will run off this device. So I will mount the finished circuit to the end of an extension cord instead which will allow whatever is plugged into it to be activated when light levels drop below a set threshold.

I’ve posted the code that runs on the Adafruit 5v Trinket on my github page for those interested. Working with the Trinket itself has been mostly pain free. Adafruit has a great tutorial section for setting up and working with the Trinket. However, I did have trouble getting the light sensor to work with the Trinket when I first started out. Since the Trinket is not able to send back serial communications to a connected PC, I had to switch to an UNO R3 to see what was going on via the serial monitor. The light sensor from Adafruit I chose is perhaps not the best suited for this project because it requires a reference 3.3v inorder to gaurantee the best accuracy in taking readings. This is despite the fact that this sensor can be supplied with up to 7v. In the end I was able to get it working with the 5v Trinket  and accuracy does not seem to be an issue from the subjective testing I’ve done. Keep an eye out for a post with the final circuit all soldered together!

circuit transfer
Transferring the bread board circuit to a proto-board.

DIY Smart Lamp using Arduino

My Dad has been doing some remodeling of his living room recently and, as part of this, bought bookshelves and some lights to go with them. He wanted some way to turn them on without having to deal with the little switch included with the lights so he thought it would be nice if the lights turned on in the evening on their own. So the task fell to me and and I happily accepted.

This project is actually fairly simple as only a few cheap parts are needed and little coding is required. There is a real danger of electrocution with this project however as we are dealing with voltages from 120V to 220V ( depending on where you live). Please be sure to the necessary precautions when working with live wires for this and any project you take on.

I am using the following parts for this project:

  • Arduino Uno R3 (for prototyping) and an Adafruit Trinket 5V – Mini Microcontroller (finished product)
  • light sensor
  • Seed Grove Relay
  • Adafruit Perma-Proto Small Mint Tin Size Breadboard PCB
  • GA1A12S202 Log-scale Analog Light Sensor
  • Dollar store extension cord (for prototyping)
  • IR Motion Sensor

Since I didn’t have access to the lights when I started nor did I have a light sensor handy, I started by creating a prototype to test the relay with an Adruino Uno R3. I wrote a simple loop that closed the the relay, waited a second then opened it again. This was repeated so long as power was supplied to the Arduino.

Relay connected to extension cord.
Relay connected to extension cord.

For the next prototype I simply added a sensor I had lying around to test controlling the relay based on the input form a sensor. I sensor I chose was a IR motion sensor. The end result was an extension cord that would send power to whatever was plugged into it when motion was detected. I’ll post an update once the light sensor arrives and I find time wire up a circuit for testing.


Meet Geoff

Geoff bares all for the camera.


Geoff, named after Craig Ferguson’s sassy robot “co-host”, was born this past summer out of the desire to keep my coding skills sharp while applying my passion for technology. I’d been interested in robotics for quite some time, especially after I started seeing what Boston Dynamics was creating. Once I got over the fact that nothing I would make could match up, I looked at what my options were. Wheels are cheap so wheels it was. Instead of revolutionizing robotics, I create a simple goal for myself: create a wheeled robot with basic object avoidance. With this, I started down a technological path I had always wanted to travel.

New Frontier

The route I took had me learning more about electronics then coding. I decided to use the Arduino platform to power my robots brain because it was cheap and well supported. It also had just the right amount of power for what I wanted to do. My other options included the Lego NXT, or a variety of robot kits offered online powered by a variety of other micro-controllers.

Instead of buying an Arduino robotics kit straight away, I bought an Arduino starter’s kit that introduced me to basic electronics and interfacing them with the code. After wetting my feet in this, I jumped to soldering together my first Arduino shield. That was an education in and of itself but a successful one.

I was fairly surprised how easy it was to write the code once all the electronics were sorted. The Arduino is programmed in C++ and takes advantage of its ability to create objects. Libraries exist that define classes containing the methods and data used to control the various sensors, motors, and other electronics that can be connected. The initial (albeit messy) code I wrote to achieve my goal of object avoidance involved Geoff going forward while polling the infrared sensor mounted on the front of his chassis for objects that appear in front of him. Once objects entered a certain range of centimeters in front of him, he immediately starts to turn for a set period of time. Once the time is up, he polls the sensor to see if the coast is clear and if so continues going forward or else starts to turn again. Using a timer to control how long he turns for was a fast way of making sure he turned enough to clear his …ahem…wide… frame around objects as the field of view for the infrared sensor is very narrow especially the closer to the sensor objects are.

Git to it

I didn’t get much further then this basic object avoiding behaviour before school started. The first semester back did not leave me any time to take things any further. This semester though, I’d like to at least clean up the code and set up a git repo with at least a master and a dev branch. This semester has seen me get even more acquainted with git and coupled with encouragement to work on personal projects, I’d like to take this project further then adhoc object avoidance. With tools like git, it will be much easier to implement larger changes to the code such as implementing a Braitenberg vehicle.

What practical application does a project have? What problem does solve? Not a whole heck of a lot and not one a lot of people have or care about. But these are not concerns that projects like these are limited by. I started this project because I grew up loving sci-fi and a theme that came up quite often was synthetic life. Now I haven’t created life, but I’ve found a way to have the sci-fi geek in me work together with the computer science geek in me. And hell, robots aren’t going to build themselves; not yet at least!