Category Archives: Percy The Robot

Waiting for stuff

Ahhh, I love the Chinese New Year period, when everything stops for a few weeks and your mail gets held up. I’ve been waiting for parts ordered from Ebay and DealExtreme for around a month now. Sigh. It shows how reliant we’ve become on cheaply bought Chinese electronic components.

Barbie disco light – waiting on the surface mount picaxe 08M2 which is still in production according to techsupplies. This has been the case for a couple of months.

Chicken Gate – waiting on the ebay buck converter to extend my battery life. $1.74 each delivered means I couldn’t build them at that price. Might also start using rechargeable NiMH batteries from Ebay.

Percy – my poor waiting robot, sitting looking lost on my desk, it waiting for an OV7670 cmos camera module that I have some fantasy about connecting to a laser as an accurate range finder. If I pull that one off it will only be with the help of others.

When all this stuff arrives my wife and kids won’t see me for a few weeks.

HC-SR04 Ultrasonic Sensors Added to Percy

Percy has some new working eyes. His HC-SR04 ultrasonic sensors are fitted and working. Picaxe code below. Here is the B4A code:

As an overview of the results so far testing them:

  • The picaxe allows you to connect the 2 middle pins of the HC-SR04 with a 1K8 resistor and send a pulse and read the pulse back from the same pin. In the pics below I’ve soldered and heat shrunk the resistors into place.
  • The sensors would be great with a backing plate, I used heat glue to stick on a flexible piece of plastic.
  • While the sensors work on the bench, the mission critical “don’t crash” bit isn’t so good.
  • Percy has 2 sensors (leftish and rightish) , but will probably end up with 4 (leftish, forward, rightish and don’t fall off the edge)
  • Couches and soft furnishings don’t reflect the sound – crash
  • Chair legs seem to be too narrow to work properly – crash

Also i2c has been replaced with UART/Serial as the i2c crashed, maybe due to a race condition. The asynch serial actually uses less processing power on the Android, which is paramount for decision making as the complexity of the navigation grows. Getting the data has dropped from 10ms to 2ms.

I have a dream of building a laser range finder to go with Percy, but I’m waiting on the camera component to try to get that to work.

BTW, the code as it stands is attached above or in snippets below these pictures.

The picaxe code with serial/uart link and averaging.

#no_table		'Speed up the programming time

HSERSETUP B115200_8, %00101

symbol PINRIGHT = c.2
symbol PINLEFT = c.1
symbol DATAIN = w0
symbol LDATA_ADD = w1
symbol RDATA_ADD = w2
symbol COUNTER = b10


	let RDATA_ADD = 0
	let LDATA_ADD = 0

	for COUNTER = 0 to 5

		'Right hand sensor
		High PINRIGHT										'trigger the HC-SR04 ultrasonic
		Pulsin PINRIGHT, 1, DATAIN			'get the distance reading
		let DATAIN = DATAIN / 11

		'Clean the data
		if DATAIN > 124 then 
			let DATAIN = 124
		end if

		if DATAIN < 0 then 
			let DATAIN = 0
		end if

		let RDATA_ADD = RDATA_ADD + DATAIN 		'My Ebay sensor is calibrated to x 11

		pause 5

		'Left hand sensor	
		High PINLEFT						'trigger the HC-SR04 ultrasonic
		Pulsin PINLEFT, 1, DATAIN		'get the distance reading
		let DATAIN = DATAIN / 11

		'Clean the data
		if DATAIN > 124 then 
			let DATAIN = 124
		end if

		if DATAIN < 0 then 
			let DATAIN = 0
		end if

		let LDATA_ADD = LDATA_ADD + DATAIN 		'My Ebay sensor is calibrated to x 11

		pause 5



	hserout 0, (b2, b4)


	goto main

Here is the connection code in the IOIO (VB4Android) – but also you need the navigation etc in the code.

Sub ReadFromUART		
	'uart order is is rx,spec,tx,spec,baud,pariy,stop

	Dim sSin As InputStream


	If sSin.BytesAvailable > 0 Then  
		Dim bufferin(sSin.BytesAvailable) As Byte
		Dim count As Int    
		count = sSin.ReadBytes(bufferin,0, bufferin.Length)

		If count = 2 Then		
			iDistanceRight = bufferin(0) : iDistanceLeft = bufferin(1)
			lblright.Text  = iDistanceRight 
			lblLeft.Text  = iDistanceLeft 

			lblMessage.Text = "Poor Read"
			NewServiceMessage("Poor serial read" , "", 1, 500)
		End If
	End If
End Sub

Picaxe 20X2 as i2c slave to IOIO board

I’ve connected up the Picaxe 20X2 to the HC-SR04 ultrasonic range finder and I can read the distance. The 20X2 is operating as the i2c slave. The distance measurements are saved into the EEPROM (known as the scratchpad in picaxe) where the IOIO can read them.

Then I’ve connected the IOIO to the Picaxe using the SDC (clock) and SDA (data) lines. These lines are connected to +5V with 4K7 resistors (pulled high). Full connection details below.

And yippee, after messing around with the settings, it all works.

One trick was to “write” a byte array of zeros (not nulls) before accessing the scratchpad area. This ensured that we read the data from the same location each time.

Here’s the picaxe code to make it all work:

#no_table		'Speed up the programming time

hi2csetup i2cslave, %01010011	'Slave address is decimal 41 = %0101001x


	High c.2						'trigger the HC-SR04 ultrasonic
	Pulsin c.2, 1, w0		'get the distance reading
	let w1 = w0 / 11 		'My Ebay sensor is calibrated to x 11
	put 0, word w1			'Save to EEPROM
	pause 250
	goto main

And here’s the VB4Android code using the IOIO library:

Sub GetDistance
	Dim wd(1) As Byte
	Dim rd1(2) As Byte
	Dim bSuccess As Boolean 

	TWI = YOYO.OpenTwiMaster(2, TWI.RATE_400KHZ, False)

	If TWI.IsInitialized Then
		bSuccess = TWI.WriteRead(41, False, wd, 0, rd1, 2) 
		If bSuccess = True Then						
			NewServiceMessage("Success" , "", 1, 2000)
		End If

	End If	
End Sub

Minimum Picaxe / IOIO I2C connection

  • Power to Picaxe
  • Power to IOIO
  • Common gnd connection
  • IOIO pin 25 CL2 to Picaxe 20X2 pin 11 hi2c scl
  • IOIO pin 26 DA2 to Picaxe 20X2 pin 13 hi2c sda
  • The sda and scl lines both need to be pulled high (4k7 resistor connected to +5V)

Picaxe 20X2 to the HC-SR04

  • +5V to VCC on SR04
  • GND to GND on SR04
  • C.2 pin to Trig
  • 1K6 Resistor between trig and echo on SR04



Motor driver and IOIO install

After testing the motors I found current draw as high as 1.3Amps. So I stuck 2 of the SN754410 H-Bridges on top of each other, and then built a heat sink from an aluminum can. Should be OK for 2Amps or more. The heat sink is just the aluminum can bent into fins with some heat transfer paste and a spot of silicon glue at each end to hold it on. Dodgy… but it might work.

I dropped the diodes from the previous circuit, and put more standard resistors instead. Also went for the standard pull down resistor to enable. This robot is going to draw plenty of power keeping the Android screen on, so having the SN754410 enabled isn’t going to make much difference anyhow.

Next step is the Picaxe sensors and the I2C interface to the IOIO. Yikes.


Testing and Breadboarding the Motor Driver Circuit

I’ve tested the motor driver circuit shown on the previous post by plugging it into a breadboard. I wasn’t confident on using the diodes to pull the enable pin high, but it seems to have worked. I still need to check the current draw using the pin for both enable and also to activate each motor.

Show in the pictures is a simple test using an Android phone hooked up to an IOIO board which goes to the SN754410 motor driver chip. The IOIO is an amazing piece of kit that provides a voltage regulator with 5V and 3V3 outputs to power your project. In this case I’ve created 5 buttons to test each of the motors in forward and reverse. Download the full source code in Basic for Android if you want to take a look. The IOIO connection method is particularly useful.

Still to do before soldering: Current on pins, stall current on motors, 0V on enable.

IOIO robot brain

Percy the robot is going to have a IOIO for the main brain, with some Picaxe chips (hopefully working with I2C) sending information back to the IOIO.

The IOIO board is actually a dumb unit, waiting for commands from an Android device. So really the true brains will be the Android, with the IOIO passing information to the Android, and executing commands on behalf of the Android device.

So why is an Android device such an great brain for a robot?

  • Massive memory space to write software
  • Easy to program with Basic For Android which has it’s very own IOIO library waiting for you
  • Built in compass
  • Built in GPS
  • Built in Bluetooth
  • Built in tilt sensor
  • Built in touch screen interface
  • Built in wifi
  • Built in camera
  • PLUS lots of extras like built in SQL…

So what would it cost, and how many wires would you need to include a compass, gps, bluetooth, tilt sensor, touch screen, wifi….etc etc into your project. A huge amount. OR you can hop onto ebay and grab a used Android phone, or even a new cheap Chinese tablet and get these great features.

So really an Android brain is a no brainer!

Robot Motor Driver SN754410

On my Chicken Gate circuit I had diodes everywhere to stop back current from the motors. I’ve done a bit more research and I believe the internal diodes in the SN754410 and L293D (interchangeable parts) will do the job. Having external diodes will reduce the heat produced, but for my chassis I have 2 x 170mA motor stall on each side of the motor driver, so a simple heat sink on the motor driver chip should be effective and easier. I still need the capacitors to smooth the inductive load. New circuit is at the bottom of this post.

One major change I’m going to trial is to pull the “enable” pins on the motor driver high using the pins from the IOIO with diodes to direct the current (see schematic). According to the datasheet the high level input voltage is 2. I’m guessing this is the voltage required to activate the enable or the operating pins. So the 3V3 (that’s 3.3V in techno speak apparently) comes from the IOIO, there’s a 0.7V drop across the diode, leaving 2V6 at the enable pin. I’ll also have to check that the current draw isn’t over 20mA from the IOIO pin. Why? Because on the chicken gate the motor driver remains warm when nothing is going on, so I don’t want the enable to be active, this achieves an enable switch without using another pin from the IOIO board. Note that I removed the diodes (dumb idea) and used resistors instead. The circuit diagram below works, but I don’t recommend it.

The robot has 4 motors, but I’m going to operate 2 at one time together – the left side and right side motors will be paired. So “all forward” – “all reverse” – “turn left with left reverse, right forward” – “turn right with right reverse, left forward”.

Robot Chassis Kit has arrived!

My 4WD Robot chassis has arrived from Hobby King. So far it seems like a great package for the price. It includes the 4 gear motors and a pretty good platform for what I’m doing. There’s space for the IOIO control board in a middle layer. I’ll build a motor driver board to glue underneath the chassis. The Android phone can sit on top and be visible along with some sensors.

e thing I liked was the low stall current of 170mA which means I can get away with a simple motor driver like the SN754410. I’ll have to put the DMM onto this for testing.

Building the kit was pretty easy, it took maybe 20 minutes. Don’t forget to push through the mounts in figure 1 on the instructions, otherwise you need to do the whole build again (like me!)

Kit can be found here:

Robot concept

OK, it’s time to start thinking about Percy.

I want a robot that can find it’s way around the house, not bump into things, return to the charge point and then add more stuff later.


  • IOIO board controlled by my old Samsung Galaxy I9000
  • Picaxe 20X2 chips acting as I2C slaves to measure distances etc
  • A bunch of sensors – ultrasonic, laser, sound.
  • A mapping system stored in SQL on the Android.

Let’s start ordering some stuff!