Ben Stur

The Build:

I went to Ben’s to get a PS3 controller to assist him with a controller mod and he mentioned working on an upcoming Android episode. I told him I had a little experience with Android and bluetooth control and I offered my assistance. He came up with an idea of making a remote pot stirrer so you can stir and monitor your cooking from another room. We talked throughout the week about the basic look and he gave me some graphics to use.

As I was busy most of the week, I ended up doing the program Friday night. I had some sample code from my other apps, but strange Android errors still made it take me until 3AM before I finished a working product. I had weird layout issues, it seemed to be something to do with the main.xml file. I would move something and I’d get casting errors that crashed the program when it ran on the phone. I’d delete a few objects and re-add them, doing nothing in the java code, and the problem would go away. The biggest offender was the image button. I could not line the device id textview up with it otherwise I’d get one of those crashes. When doing the layout xml’s, I made it specifically for my phone, which included editing some of the graphics. I figured I’d port the program to Ben’s nook or phone the next day.

I showed up on Saturday for taping. Ben had the hardware for the stirrer complete.  It was an arm on a stand that moved a spoon back and forth using continuous rotation servos and limit switches.  As we had discussed the protocol over email, the firmware was pre-coded and working from a terminal.  I also had my app working with a terminal.

Despite having both of our devices working separately, getting them to work together didn’t work straight out of the box. First, our baudrate on the Arduino was incorrect. We were using the Roving Networks RN41 module and those modules default at 115,200 which I forgot. After we figured that out, we had to get our continuous rotation servo working correctly. We simplified our code to just send exactly what the android phone sends, to the arm via pwm, so 0-180 with 90 being stop. This fixed that issue.  And of course whenever you have an issue, you ended up “fixing” everything else until you find the real problem and have to go “unfix” what you had changed.

When trying to get this ported to the nook, I had problems. First of all, I needed to find usb dev drivers for the nook, not too bad. Then the version of Android I developed for 4.03 or Ice Cream Sandwich, was too new for the nook. I revered the project to 2.3, or Gingerbread, but then I had to take out the rotates as Gingerbread didn’t support the imagview.rotate command. I also had to change the layout a lot to get things to line up. I had edited Ben’s files to work on my phone and I had to edit them back to what he originally made.

Once I got it installed, I tried to get the bluetooth working. It would not, the nook, no matter what I did, would talk to the module. It couldn’t even pair. It would fail and give an error. Without even a successful pair, it was dead in the water.

Next, I tried Ben’s phone. This was harder, the drivers were not readily available to connect for development. I had to put his phone into recovery mode first, which windows then took over and installed the drivers. The phone took forever to reboot and I was worried I had broke it as I had to take out the battery to get it to leave recovery mode. It finally did boot though.

I tried to send the apk to the phone through eclipse. It didn’t work. No matter what I did, it couldn’t see his device as a target even with USB debugging enabled. I ended up having to put his phone into mass storage mode and dropping the apk on there. I got it installed on the phone and gave it a try. It would pair to the Roving Networks module, but would never connect. I’m not sure if it supports SPP or Serial Port Profile, which is a Bluetooth mode, kind of like HID or audio protocol. In the end I had to use my phone. We had to fix a few code problems on the receiver side and then we were up and running, except for the thermistor. We only worked half a day so Ben said he’d add the thermistor code that night and I would port the program back to my phone and re-add the rotate command for ICS.

I came in on Sunday for a few hours to finish up. Ben added the thermistor code and we started getting some sending errors back to the phone. We removed the old sending code, which sent the speed value received as a temp, it was a debugging tool of ours and no longer needed, and then it appeared to work on the terminal. I was still getting erratic behavior on the device when I plugged into Ben’s universal wall wart. I thought the previous day we had used a 5V supply, but apparently we must have used the 12V line to power the Arduino board. With the drop caused by the regulator, the Arduino wasn’t getting enough power to work correctly. After that fix, everything was working great. We finished taping the function and that was that. Not without problems, but definitely not as hectic as Robot Luggage.

Program Information:

I wrote this program based on some samples of previous programs I’ve written for Bluetooth Control.  Much of the Bluetooth code was used and Adapted from the book “Programming Android”.


AboutInfoActivity- This file is all about showing the “About” section when you hit the options key.  It just shows information I put in the about.xml file explaining the protocol

DeviceListActivity- This pertains to choosing a bluetooth device.  After you hit the sync button, a screen comes up letting you connect to a bluetooth device.

BtHelperHandler and BtSPPHelper- These are the bluetooth control classes.  They are pretty much exactly from “Programming Android” except I had to add some code to allow me to receive data.  These codes I believe were adapted from the bluetooth chat example on Google’s code database.

BenSturActivity- This is the main activity.  It is what you interface with for the program.  It controls the other activities, uses the bluetooth, reads the seekbar and button inputs, and sends the bluetooth information every 250mS by use of a thread.  You sync with a device and it will show the Device ID, you know its connected when the temperature changes from — to a number.  Then you slide your finger back and forth on the slider in the upper right to move the arm.  Releasing puts the position back to 90, or off.  That’s about it.

Protocol- Its a pretty simple protocol with everything sent in Ascii.  I did this because I was having trouble getting useful Byte data from the bluetooth helper classes but strings worked fine.

Sending- Start character – Three digits of position, always 3 digits, padded with 0’s when neccessary

ex- !090 (stop)    !180 (full CW)   !000 (full CCW)

Receving- Start character – One to Three digits of temperature, does not need to be 0 stuffed

ex-  !99  !120


Known Issues- When coming back from a screen off condition (like a sleep), the program often crashes from an inflater error.  Something about unknown class.  I’ll see if I can fix it, but I’m not an Android nor Java king.  If anyone else looks at this code and fixes it, let me know so I can update it.


Older Support- Because of the ImageView.rotate command, this is ICS and above only.  Remove the ImageView rotation command and then configure the project for an older version of Android to work on older phones.  Also remember to update the Minimum Version in the Android Manifest !


Eclipse Project file and APK is attached:

BenStur Files


Android Market Link:

Ben Stur

Robot Luggage- My Ben Heck Experience

Back in November I won a hat from Ben Heck, the host of the Ben Heck show produced by Newark Element14 and

I went and picked the hat up in person and talked to him and his assistant Alyson, they were finishing up the latest episode of the Ben Heck show.  See here for more info


During the visit, it was brought up that I might be able to help on a future episode.  Well that day came February 4th.  The project was robot luggage.  We started out by brainstorming over Skype.  I had thought about this prior and this is what we decided on:

2 Ultrasonic sensors (receivers) on the luggage, 1 Ultrasonic sensor (transmitter) on the person (the target), 1 Wireless transmitter/receiver on each.  The wireless is used to initiate the remote ultrasonic ping on the target.  I thought this was the better route than using wireless RSSI on the transceivers for a few reasons;

–  We don’t know what frequencies are in use in an airport and don’t want to be interfered with

– Wireless bounces a lot and is strange sometimes how it is affected by humidity, near ground effects, etc

–  If not using RSSI and instead using Time of Flight, you’d need a very fast micro to record the distance, Ultrasonic sound travels much slower and its easier to discern a distance


I went to the shop the next day to do the recording.  It was a little bit weird being on camera as you can tell I didn’t do the best acting in the beginning.  It became easier and more comfortable later on.  The recording day was all rehashing the design for the camera.  We went over why we chose what parts, the mechanical design of the device, dimensional analysis for the speed and many other things.  It was about 4 hours of work for 8 minutes of video.


Our next recording date was several weeks later as we needed to get the parts in.  That day consisted of more of the mechanical work and testing out all the electrical components.  Ben made a preliminary wheel, we soldered wires to all of our electronics and mounted them and added batteries.  I had a lot of trouble working with the motor drives because everything needed to be sent in hex and it’s hard to find a good terminal program in windows7 that lets you do that, had I brought a windows xp computer, I could have used realterm, which is my go to terminal.  I ended up using XCTU which is digi’s terminal program, originally meant to configure the xbee chips.  It was not supported on win7 but it worked.

Also, a note on UART dyslexia, if you are designing anything with a UART interface, please, please, mark your terminals in some manner like TXOut, RXIn so we know what direction the traffic should be.  Most things are marked TX and RX but they don’t indicate if its the TX of that device or the one connecting to it, I’ve seen it both ways on modules that use UART. Here is the best quote I’ve seen on this

Before purchasing this part you need to know if you have a condition called UART dyslexia. This is a neurological disorder that will render you incapable of properly wireing this device no matter how my times you triple check the the wiring. I have this disorder and I have only found three possible solutions:
1) Find someone else without UART dyslexia to wire it up for you
2) When you get the board, immediatly scratch out the silk screen for the TX and RX pins. You will have a better chance attaching the wires at random than attemping to determine the proper connections in your screwed up head. Test the device and if it doesn’t work swap the lines. The advantage of this approach is that you didn’t spend hours trying to figure out the wrong way to wire the connections.
3) Try to figure out the proper connections and do the opposite of what you think is correct. I have had some success with this approach. -MotiveForce sparkfun comment

I got some wheels spinning and we got the wireless generically working, and that was about it for the day.  One big comment about the transistor inverter-

Originally I wanted to do a NPN inverter but I wanted the signal pulled low so it was always low if the input was floating, this required me to change to the pnp approach, I switched the arrow, but did not switch the pins of the device.  Emitter should have went to VCC and collector to the signal out/pulldown resistor.  That is why it did not work.  The arrow represents the internal diode (because of PN junctions) of the device and you can think of it as the direction the current will flow, so of course current cannot flow backwards through it and the device didn’t work.  That was a fundamental mistake on my part, not much to blame it on but nerves and working on the fly on camera.


(Supposedly the ping has an internal pulldown, if that is the case you should be able to remove the pulldown off the pnp transistor)

I was supposed to come up the next Saturday and Sunday, but I got pretty sick, so I sat alone in my lab all day Saturday working on code

Let me say this, I hate programming for Arduino.  It’s a great platform for hobbyists and gets people into electronics and programming.  There are a ton of boards out there and quite the following.  Most Arduinos are based on AVRs which I use all the time at work.  I figured I’d do it as an Arduino this time, and I did not enjoy it.  This is how I expected the program to work

Decide to take a reading, send out a serial wireless command to do a ping, count on a uS timer until both left and right ping received, the distance is the turn value

I couldn’t find uS timers, so I tried the next approach

Decide to take a reading, send out a serial wireless command to do a ping, do pulsein to record time for one receiver, repeat for second receiver

This didn’t work as the serial library is so bloated that variable lag was causing my values to be off 50-150uS whereas the difference values I was looking for many times were less than that. I hooked up a scope and the end point of the value was bouncing but not the difference, it must be from inconsistent serial lag to the remote sensor. Basically I had to read them both on the same wireless ping to get accurate results.

Use interrupts, I set both ping sensors on an interrupt so when they changed state, I’d check the second sensor to see if it triggered, detatch the interrupt so it doesn’t happen again before I’m ready and then when I receive the next interrupt that is my distance.

Well, that didn’t work either, I think either the arduino doesn’t like detaching an interrupt within that interrupt or just how long it takes to do a digital read (which I didn’t know yet) was causing grief.

Next try, sit in a loop that’s doing uS delays and counting up (with a timeout) and polling the pins to see when they change (because they received the ping back), then receive that, set some flags so you know which one went first and wait for the second one, then do the difference value etc.

This didn’t work either, I think because digital read takes a very long time (longer than it should). Once I changed it to read directly from the port (PINB & 0xyadayada) that approach worked.

The whole project I was struggling with arduino based problems, if I had better access to the lower level parts of the AVR, especially timing interrupts, I would have been fine. Once I got the error values working correctly, the project worked great. Next time I skip the arduino and go avr studio and straight c.  Once I got the terminal result below, I went to bed


Error: -26
Direction: Left
Error Sum: -262
Error Correction -9.12

Error: -17
Direction: Left
Error Sum: -490
Error Correction -9.15

Error: -13
Direction: Left
Error Sum: -503
Error Correction -8.28

Error: -10
Direction: Left
Error Sum: -513
Error Correction -7.63

Error: -2
Direction: Left
Error Sum: -558
Error Correction -6.08

Error: 1
Direction: Right
Error Sum: 1
Error Correction 0.26

Error: 5
Direction: Right
Error Sum: 10
Error Correction 1.35

Error: 9
Direction: Right
Error Sum: 19
Error Correction 2.44

Error: 18
Direction: Right
Error Sum: 90
Error Correction 5.40

Error: 23
Direction: Right
Error Sum: 113
Error Correction 6.88

Error: 28
Direction: Right
Error Sum: 141
Error Correction 8.41

I was moving the target from left to right in front of the receivers, Error was the difference between the left and right times, Direction was which direction to turn, Error sum is basically the integral term before weighting, correction was what to add to the turn value.

The next day I showed up with my own box of kleenex, hand sanitizer, and trash bag as to not infect Ben and we went to work.  We got everything installed, Ben finished the 3rd leg and handle and I changed the code so it would send the turn value to the motor controllers.  Off the bat, it worked pretty well, had to do tweaking but I was surprised at how well it worked increasing and decreasing the separate wheel speeds based on location of the target.  I added a distance timeout for too close and too far, tweaked the P and I weights, and added flashing lights for status.  We tried a smaller battery pack but it died pretty short into it so we went back to the huge lead-acid batteries.  We got it following well and then I left.  Ben and Alyson finished closing up the front, added some decoration, and finished the taping.  All and all, it was an awesome experience, I had followed Ben’s work on HaD and it was a once in a lifetime experience to work with him, I hope I get to work with him more in the future.

Watch the full video below



Here is a little bit longer explanation of the program flow


Set up the 3 serial ports
Serial is for debug at 9600
Serial1 is for motor control at 38400 and 2 stop bits!
Serial2 is for zigbee for remote ping
Set up leds
Send some commands to motor control

Clear out important variables like difference and distance
See if handle switch is in disabled position
Flash status LED
If Not Disabled;        Do 4 pings and average difference result and distance result
If too close to person (based on distance); disable
If Difference looks good and not disabled; update the drives and
clear timeout; else increase timeout
If timeout counter is too high, disable
If disabled; set the drives to zero and blink lights

Do the high low thing to start both receivers
Send Zigbee start command
Wait for either left or right sensor to go to zero or timeout; record
that setpoint
Wait for second sensor to go to zero or timeout; record that setpoint
and break loop
Calculate the difference by subtracting
Calculate the distance by adding both values and dividing by 10 (for
scaling speed)
Return the difference (which is our error)

Calculate the direction of the error (basically left or right turn)
If direction has changed, clear out the error sum (integral part of PI Loop)
Add Error to the Error Sum
Calculate turn value by doing Kp*error + Ki*errorSum where Kp and Ki
are set to 0.5 and 0.25 respectively and then add to 128 which is our
Calculate the speed by taking our above distance divided by two, then
subtract from 128 because forward is 0-128 (with 0 being max allowed)
Make sure turn isn’t greater than 250 or less than 5 (preventing
overflow or underflow)
Make sure speed isn’t less than 5 (preventing an underflow)
If Debug is set output all of these numbers through the Serial port as well

Set speed and turn to 128 (bidirectional data around 128, 0 is max
one way 255 is max other way

I’ve also attached the code for download.  I’ts a .c file, but is actually the .ino, wordpress doesn’t like .ino files so just rename it to something.ino

Robot C Code


I don’t have the dimensions of the luggage, but here is a build list of the electronics:

Motors and controller-

Microprocessor board (brains)-

Ultrasonic Sensors (x3)-

Wireless Boards (x2) –

Power Convertor – Don’t remember, it was some off the shelf Buck Switch Mode powersupply with 5V output

Project Planning- WiFi Radio

My upcoming project is a WiFi Radio.  I have a small atom board computer that I will use as the base.  I am going to load it with XUbuntu (a lighter version of Ubuntu) and make it a WiFi radio.  I bought a cheap antique-looking radio from a pawn shop for $20.  I plan on using it as my case.

I bought 3 RGB encoders with push buttons to replace the current pots in the radio.  I want to still use the knobs but drill a hole down the center to allow the RGB light to shine through.  I will probably have to use some clear fill to spread the light out like a lightpipe, not sure what I will use for that.  I also bought an LED ring graph, that will be my channel/category indicator as I can make multiple categories of stations.  That’s all I plan on using for the UI.

Light Modes:


Playing a song- random fading, all the same or all different

Stopped- pulsing a color

In use- turn the one being turned a solid color

Possible Beat Mode- flashing/fading to a song beat


LED Ring-

Changing Volume/channel/category- display the amount on the bar graph using both sides, when done (as indicated by no change for a period of time) flash the lights a few times and go back to whatever the ring was set at

VU Mode- Left and Right channel VU set up split top and bottom

Equalizer Mode- 4 frequencies shown going from each quadrant to the next quadrant (so 4 LED’s each freq)

Chase Mode- have lights go back and forth to give the idea of chasing lights



AM/FM Knob Turn- will be used for changing categories of stations

AM/FM Knob PB- Change light mode of the knobs


Tuning Knob Turn- will be used for changing station within a category

Tuning Knob PB- change light mode on the LED Graph


Volume Knob Turn- used to adjust volume of course

Volume Knob PB- Mute/Unmute



Speakers- I got some sony mini speakers on sale from Best Buy.  I believe they were $5, originally like $40 though.  They sound pretty good.  Not as loud as the original speaker but has its own internal amplifier/driver and it’s stereo.


Software- I plan on using a teensy++ as my hardware interface.  It will send encoder and push button information via serial.  A python program on the computer will be doing the stream control using Streamtuner.  Also hoping to put the equalizer and VU work on the computer.  It would be nice to have all the LED control on the computer so it can be done quicker and more efficiently with the teensy board acting only as a hardware i/o interface.


The hard part will be the Python-Streamtuner interface, I  have never programmed in python before.  I typically use C, Java, or VB, but have used lots of other languages from time to time.  Also, because I won’t have a screen, connecting to new wifi networks will be difficult, I’m hoping to write a script that if a usb drive with a certain file (wifi.txt) is inserted, it parses that text file into its wifi connections to be able to connect, then I will never need to use a monitor after I get it set up.


Draftsight appx drawing