152 byte PICAXE-18X/SSC-32/24C65 walking BRAT demo

Hello!

I do not own a Basic Micro BasicATOM28-M so the following are programs to use a PICAXE-18X instead of an ATOM. The PICAXE-18X microcontroller does not have enough memory for this program:

lynxmotion.com/images/files/brata1.bas

But I want to thank Nathan Scherdin, Jim and James Frye for the above program. It helped me with servo codes needed for the PICAXE-18X BRAT.

Since the PICAXE-18X has limited memory, the idea is to store all those codes into an EXTERNAL memory such as Microchip’s I2C 24C65 leaving room for the main program in the PICAXE-18X.

Besides a PICAXE-18X and a 24C65, this demo also requires a SSC-32.

Before programming the 24C65, here is a document to help you connect it properly to the PICAXE-18X:

rev-ed.co.uk/docs/axe110_i2c.pdf

Of course, before making the BRAT walk with this demo, you will have to program the 24C65. Each of these programs needs to be run one at a time because of the memory issue and also for clarity. Here are the following programs to help you with this:

The following will program the RESET sequence codes:

'
'
' 152 BYTE PICAXE-18X BRAT
'
'
'*** SSC-32 pin assignment
'
' SSC-32 pin #13 =  LH hip
' SSC-32 pin #14 =  LH knee
' SSC-32 pin #15 =  LH ankle
' SSC-32 pin #29 =  RH hip
' SSC-32 pin #30 =  RH knee
' SSC-32 pin #31 =  RH ankle
'
' SSC-32 set @ 2400 baud rate
'
'*** 24C65 memory usage
'	
'	reset	(1 line)		@ 	24C65 location 0000-0064 (decimal)
'	walk (4 lines)		@	24C65 location 0100-0363 (decimal)
'	backup (4 lines)	@	24C65 location 0400-0663 (decimal)
'	turn LH (6 lines)	@	24C65 location 0700-1095 (decimal)
'	bow (1 line)		@	24C65 location 1100-1165 (decimal)
'
'
' WRITE 24C65 @ LOCATION 0000-0064 RESET SEQUENCE

main:

i2cslave %10100000, i2cfast, i2cword

writei2c    0,("#29 P1500 ")
pause 20     
writei2c    10,("#30 P1500 ")
pause 20
writei2c	20,("#31 P1500 ")
pause 20
writei2c	30,("#13 P1500 ")
pause 20
writei2c	40,("#14 P1500 ")
pause 20
writei2c	50,("#15 P1500 ")
pause 20
writei2c	60,("T500",13)
pause 20

end

Next , program the WALK sequence codes:

'
'
' 152 BYTE PICAXE-18X BRAT
'
'
'*** SSC-32 pin assignment
'
' SSC-32 pin #13 =  LH hip
' SSC-32 pin #14 =  LH knee
' SSC-32 pin #15 =  LH ankle
' SSC-32 pin #29 =  RH hip
' SSC-32 pin #30 =  RH knee
' SSC-32 pin #31 =  RH ankle
'
' SSC-32 set @ 2400 baud rate
'
'*** 24C65 memory usage
'	
'	reset	(1 line)		@ 	24C65 location 0000-0064 (decimal)
'	walk (4 lines)		@	24C65 location 0100-0363 (decimal)
'	backup (4 lines)	@	24C65 location 0400-0663 (decimal)
'	turn LH (6 lines)	@	24C65 location 0700-1095 (decimal)
'	bow (1 line)		@	24C65 location 1100-1165 (decimal)
'
'
'WRITE 24C65 @ LOCATION 0100-0363 WALK SEQUENCE
main:

i2cslave %10100000, i2cfast, i2cword

' *** 1st line of command
writei2c    100,("#13 p1166 ")
pause 20     
writei2c    110,("#29 p1166 ")
pause 20
writei2c	120,("#14 p1166 ")
pause 20
writei2c	130,("#30 p1166 ")
pause 20
writei2c	140,("#15 p1616 ")
pause 20
writei2c	150,("#31 p1616 ")
pause 20
writei2c	160,("T1000",13)
pause 20

' *** 2nd line of command
writei2c   166,("#13 p1166 ")
pause 20     
writei2c   176,("#29 p1166 ")
pause 20
writei2c   186,("#14 p1166 ")
pause 20
writei2c   196,("#30 p1166 ")
pause 20
writei2c   206,("#15 p1383 ")
pause 20
writei2c   216,("#31 p1383 ")
pause 20
writei2c   226,("T1000",13)
pause 20

' *** 3rd line of command
writei2c   232,("#13 p1833 ")
pause 20     
writei2c   242,("#29 p1833 ")
pause 20
writei2c   252,("#14 p1833 ")
pause 20
writei2c   262,("#30 p1833 ")
pause 20
writei2c   272,("#15 p1383 ")
pause 20
writei2c   282,("#31 p1383 ")
pause 20
writei2c   292,("T1000",13)
pause 20

' *** 4th line of command
writei2c   298,("#13 p1833 ")
pause 20     
writei2c   308,("#29 p1833 ")
pause 20
writei2c   318,("#14 p1833 ")
pause 20
writei2c   328,("#30 p1833 ")
pause 20
writei2c   338,("#15 p1616 ")
pause 20
writei2c   348,("#31 p1616 ")
pause 20
writei2c   358,("T1000",13)
pause 20

end

You also need to program the BACKUP sequence codes:

'
'
' 152 BYTE PICAXE-18X BRAT
'
'
'*** SSC-32 pin assignment
'
' SSC-32 pin #13 =  LH hip
' SSC-32 pin #14 =  LH knee
' SSC-32 pin #15 =  LH ankle
' SSC-32 pin #29 =  RH hip
' SSC-32 pin #30 =  RH knee
' SSC-32 pin #31 =  RH ankle
'
' SSC-32 set @ 2400 baud rate
'
'*** 24C65 memory usage
'	
'	reset	(1 line)		@ 	24C65 location 0000-0064 (decimal)
'	walk (4 lines)		@	24C65 location 0100-0363 (decimal)
'	backup (4 lines)	@	24C65 location 0400-0663 (decimal)
'	turn LH (6 lines)	@	24C65 location 0700-1095 (decimal)
'	bow (1 line)		@	24C65 location 1100-1165 (decimal)
'
'
'WRITE 24C65 @ LOCATION 0400-0663 BACKUP SEQUENCE
main:

i2cslave %10100000, i2cfast, i2cword

' *** 1st line of command
writei2c    400,("#13 p1166 ")
pause 20     
writei2c    410,("#29 p1166 ")
pause 20
writei2c	420,("#14 p1166 ")
pause 20
writei2c	430,("#30 p1166 ")
pause 20
writei2c	440,("#15 p1383 ")
pause 20
writei2c	450,("#31 p1383 ")
pause 20
writei2c	460,("T1000",13)
pause 20

' *** 2nd line of command
writei2c   466,("#13 p1166 ")
pause 20     
writei2c   476,("#29 p1166 ")
pause 20
writei2c   486,("#14 p1166 ")
pause 20
writei2c   496,("#30 p1166 ")
pause 20
writei2c   506,("#15 p1616 ")
pause 20
writei2c   516,("#31 p1616 ")
pause 20
writei2c   526,("T1000",13)
pause 20

' *** 3rd line of command
writei2c   532,("#13 p1833 ")
pause 20     
writei2c   542,("#29 p1833 ")
pause 20
writei2c   552,("#14 p1833 ")
pause 20
writei2c   562,("#30 p1833 ")
pause 20
writei2c   572,("#15 p1616 ")
pause 20
writei2c   582,("#31 p1616 ")
pause 20
writei2c   592,("T1000",13)
pause 20

' *** 4th line of command
writei2c   598,("#13 p1833 ")
pause 20     
writei2c   608,("#29 p1833 ")
pause 20
writei2c   618,("#14 p1833 ")
pause 20
writei2c   628,("#30 p1833 ")
pause 20
writei2c   638,("#15 p1383 ")
pause 20
writei2c   648,("#31 p1383 ")
pause 20
writei2c   658,("T1000",13)
pause 20

end

Then program the TURN LH sequence codes:

'
'
' 152 BYTE PICAXE-18X BRAT
'
'
'
'*** SSC-32 pin assignment
'
' SSC-32 pin #13 =  LH hip
' SSC-32 pin #14 =  LH knee
' SSC-32 pin #15 =  LH ankle
' SSC-32 pin #29 =  RH hip
' SSC-32 pin #30 =  RH knee
' SSC-32 pin #31 =  RH ankle
'
' SSC-32 set @ 2400 baud rate
'
'*** 24C65 memory usage
'	
'	reset	(1 line)		@ 	24C65 location 0000-0064 (decimal)
'	walk (4 lines)		@	24C65 location 0100-0363 (decimal)
'	backup (4 lines)	@	24C65 location 0400-0663 (decimal)
'	turn LH (6 lines)	@	24C65 location 0700-1095 (decimal)
'	bow (1 line)		@	24C65 location 1100-1165 (decimal)
'
'WRITE 24C65 @ LOCATION 0700-1095 TURN LEFT SEQUENCE
main:

i2cslave %10100000, i2cfast, i2cword

' *** 1st line of command
writei2c    700,("#13 p0883 ")
pause 20     
writei2c    710,("#29 p0833 ")
pause 20
writei2c	720,("#14 p0916 ")
pause 20
writei2c	730,("#30 p0916 ")
pause 20
writei2c	740,("#15 p1500 ")
pause 20
writei2c	750,("#31 p1500 ")
pause 20
writei2c	760,("T2000",13)
pause 20

' *** 2nd line of command
writei2c   766,("#13 p2166 ")
pause 20     
writei2c   776,("#29 p2116 ")
pause 20
writei2c   786,("#14 p2083 ")
pause 20
writei2c   796,("#30 p2083 ")
pause 20
writei2c   806,("#15 p1500 ")
pause 20
writei2c   816,("#31 p1500 ")
pause 20
writei2c   826,("T2000",13)
pause 20

' *** 3rd line of command
writei2c   832,("#13 p2166 ")
pause 20     
writei2c   842,("#29 p2116 ")
pause 20
writei2c   852,("#14 p2083 ")
pause 20
writei2c   862,("#30 p2083 ")
pause 20
writei2c   872,("#15 p1166 ")
pause 20
writei2c   882,("#31 p1266 ")
pause 20
writei2c   892,("T2000",13)
pause 20

' *** 4th line of command
writei2c   898,("#13 p0883 ")
pause 20     
writei2c   908,("#29 p2116 ")
pause 20
writei2c   918,("#14 p0916 ")
pause 20
writei2c   928,("#30 p2083 ")
pause 20
writei2c   938,("#15 p1166 ")
pause 20
writei2c   948,("#31 p1266 ")
pause 20
writei2c   958,("T2000",13)
pause 20

' *** 5th line of command
writei2c   964,("#13 p0883 ")
pause 20     
writei2c   974,("#29 p2116 ")
pause 20
writei2c   984,("#14 p0916 ")
pause 20
writei2c   994,("#30 p2083 ")
pause 20
writei2c   1004,("#15 p1733 ")
pause 20
writei2c   1014,("#31 p1833 ")
pause 20
writei2c   1024,("T2000",13)
pause 20

' *** 6th line of command
writei2c   1030,("#13 p0883 ")
pause 20     
writei2c   1040,("#29 p0883 ")
pause 20
writei2c   1050,("#14 p0916 ")
pause 20
writei2c   1060,("#30 p0916 ")
pause 20
writei2c   1070,("#15 p1733 ")
pause 20
writei2c   1080,("#31 p1833 ")
pause 20
writei2c   1090,("T2000",13)
pause 20

end

And finally the BOW sequence:

'
'
' 152 BYTE PICAXE-18X BRAT
'
'
'
'*** SSC-32 pin assignment
'
' SSC-32 pin #13 =  LH hip
' SSC-32 pin #14 =  LH knee
' SSC-32 pin #15 =  LH ankle
' SSC-32 pin #29 =  RH hip
' SSC-32 pin #30 =  RH knee
' SSC-32 pin #31 =  RH ankle
'
' SSC-32 set @ 2400 baud rate
'
'*** 24C65 memory usage
'	
'	reset	(1 line)		@ 	24C65 location 0000-0064 (decimal)
'	walk (4 lines)		@	24C65 location 0100-0363 (decimal)
'	backup (4 lines)	@	24C65 location 0400-0663 (decimal)
'	turn LH (6 lines)	@	24C65 location 0700-1095 (decimal)
'	bow (1 line)		@	24C65 location 1100-1165 (decimal)
'
'
'WRITE 24C65 @ LOCATION 1100-1165 BOW SEQUENCE
main:

i2cslave %10100000, i2cfast, i2cword

' *** 1st line of command
writei2c    1100,("#13 P1800 ")
pause 20     
writei2c    1110,("#29 P1200 ")
pause 20
writei2c	1120,("#14 P1500 ")
pause 20
writei2c	1130,("#30 P1500 ")
pause 20
writei2c	1140,("#15 P1500 ")
pause 20
writei2c	1150,("#31 P1500 ")
pause 20
writei2c	1160,("T1000",13)
pause 20

end

Now that the 24C65 is programmed, the PICAXE-18X needs to be connected to the
SSC-32. You may refer to the following document for connector positions:

lynxmotion.com/images/data/ssc-32.pdf

In this example, pin 6 (output 0) of the PICAXE-18X is connected to the RX pin of the 3 pin header side of connector 13. Ground also has to be connected, but in this case, I did not use the TX pin.

Example of SSC-32 connector 13:

N/C —……---------------------- to PICAXE-18X pin 6 (output 0)
………|……|
………|……|
……0……0……0------ground

………0…….0
………TX……RX

Also make sure to setup the SSC-32 @ a 2400 baud rate by removing both jumpers of connector 10 for proper communication speed with the PICAXE-18X.

The following is the walking demo program:

'
'
' 152 BYTE PICAXE-18X BRAT
'
'
'*** SSC-32 pin assignment
'
' SSC-32 pin #13 =  LH hip
' SSC-32 pin #14 =  LH knee
' SSC-32 pin #15 =  LH ankle
' SSC-32 pin #29 =  RH hip
' SSC-32 pin #30 =  RH knee
' SSC-32 pin #31 =  RH ankle
'
' SSC-32 set @ 2400 baud rate
'
'*** 24C65 memory usage
'	
'	reset	(1 line)		@ 	24C65 location 0000-0064 (decimal)
'	walk (4 lines)		@	24C65 location 0100-0363 (decimal)
'	backup (4 lines)	@	24C65 location 0400-0663 (decimal)
'	turn LH (6 lines)	@	24C65 location 0700-1095 (decimal)
'	bow (1 line)		@	24C65 location 1100-1165 (decimal)
'
'
'
'
'***** Constants/Variables *****
symbol 	reset 		= 	0
symbol 	reset_end	=	64
symbol 	walk		= 	100
symbol 	walk_end	=	363
symbol	   	backup		=	400
symbol		backup_end	=	663
symbol		turn		=	700
symbol		turn_end	=	1095
symbol		bow		=	1100
symbol		bow_end	=	1165


' ***** Main *****
main:

i2cslave %10100000, i2cfast, i2cword	' Initialize 24C65 I2C

gosub brat_reset						
						
gosub brat_bow

gosub brat_reset						

for b6 = 1 to 3				' BRAT takes 3 forward steps							
gosub brat_walk
next

gosub brat_reset						

for b6 = 1 to 3				' BRAT takes 3 backward steps						
gosub brat_backup
next

gosub brat_reset						

for b6 = 1 to 5				' BRAT turn slightly to the left
gosub brat_turnleft
next

gosub brat_reset

end


' ***** Sub Routines *****
brat_reset:					' BRAT resets to neutral upright position
w0 = reset
w1 = reset_end
gosub sequencer
pause 1000					' Pause 1 second
return

brat_bow:					' BRAT bows
w0 = bow							
w1 = bow_end
gosub sequencer
pause 1000					' Pause 1 second
return

brat_walk:					' BRAT goes forward
w0 = walk							
w1 = walk_end
gosub sequencer
return


brat_backup:					' BRAT backups
w0 = backup
w1 = backup_end
gosub sequencer
return

brat_turnleft:					' BRAT turns slightly towards the left
w0 = turn
w1 = turn_end
gosub sequencer
return

sequencer:
for w2 = w0 to w1		'Loops from 24C65 "w0" location to
readi2c w2,(b7)		' 24C65 "w1" locations reading previously
				' stored step sequences.
serout 0,t2400,(b7)		' Sends read steps to SSC-32
				' including CR (carriage return) to output 0
				' @ 2400 baud rate
				' Un-comment next 2 lines of code to get optional
				' PICAXE programming editor terminal 
				' window 24C65 read values.			
'sertxd ("The value of ",#w2," is ",b7,13,10)
'pause 500
next
return

This is only a starting point of course, the rest is up to you and want you want your BRAT to do. Once programmed with the above demo your PICAXE-18X will have used up only 152 of its 2048 bytes available which should leave enough programming space for more elaborate behaviour.

I haven’t tried using Parallax’s BS2 module in the same way, but I’m certain it could be done. Other size I2C memories from Microchip could also be used in this case. Just don’t forget to re-program accordingly!

Hopefully, this will help somebody try out their BRATs in a different way!

Good luck! :smiley: