sertxd and PIXY CMUcam5

SolidWorksMagi

Senior Member
Hi,

I have a program that passes data to the PICAXE 28X2 module to react to colors seen in the PIXY CMUcam5. That program works. Now I'm trying to retrieve data from the PICAXE 28X2 module to the PC terminal to see if I can sort out how the PIXY CMUcam5 might drive a robot base to stay following a line. Problem is the program halts at the point after "sertxd("The 3rd Send Data",13,10)" ... I never see any of the PIXY CMUcam5 data ... you can see my results in the attached image below. I hope somebody can tell me how to fix the program.

; 28X2+PIXY+TerminalWindowTests.bas

#picaxe 28X2 ; Define the Processor Type
#terminal 9600
pause 10000
sertxd("The 1st Send Data",13,10)

Symbol RX_PIN = C.3
Symbol RX_BAUD = T9600

symbol WLEDs = B.4

symbol LWheel = B.1
symbol RWheel = B.0

symbol i = b0
symbol range = b15

sertxd("The 2nd Send Data",13,10)
pause 2000

do
gosub Look
pause 2000
sertxd("The 6th Send Data",13,10)
pause 2000
loop

Look:
gosub white
;gosub ChkDist ; Check the Parallx PING to be sure there is nothing in front

sertxd("The 3rd Send Data",13,10) ; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Hangs Up after this step.

; Fetch PIXY CMUcam5 data
SerIn RX_PIN, RX_BAUD, ($AA), b1, b3,b2, b5,b4, b7,b6, b9,b8, b11,b10, b13,b12
pause 5000

sertxd("The 4th Send Data",13,10)
SerTxd (#b1, #b3,#b2, #b5,#b4, #b7,#b6, #b9,#b8, #b11,#b10, #b13,#b12,13,10,13,10)
sertxd("The 5th Send Data",13,10)
return

white:
high WLEDs
return

20-PIXYGamerBot.jpg
 

inglewoodpete

Senior Member
Since you have not included the SerIn time-out, the command will wait for ever until suitable data is received.

There are five criteria that the incoming data must meet:
  1. Data must appear on the specified pin (C.3)
  2. Data polarity must conform to your specification for the SerIn command (True polarity - idle high)
  3. Data must be sent at the specified baud rate (9600 baud)
  4. The data qualifier or first (single) byte of the message must have a value of 170 decimal, $AA or %10101010
  5. There must be at least a further 13 bytes of data following the qualifier byte
Initially, I suggest you remove the data qualifier byte spec "($AA)," from the SerIn command and you should be able to see what is actually being received. Then you should be able respecify your SerIn command.
 

SolidWorksMagi

Senior Member
Hi,

I removed the "($AA)," from the program, but still I am not seeing and data in the terminal window. I have been hoping to see the data string from the PIXY CMUcam5 camera which defaults to standard 9600 baud and I have set some actions from the incoming data to light up LEDs in the bot before. So the problem seems not so much the "serin", but getting the data sent to the terminal screen.

; 28X2+PIXY+TerminalWindowTests.bas

#picaxe 28X2 ; Define the Processor Type
#terminal 9600
pause 10000
sertxd("The 1st Send Data",13,10)

Symbol RX_PIN = C.3
Symbol RX_BAUD = T9600

symbol WLEDs = B.4

symbol LWheel = B.1
symbol RWheel = B.0

symbol i = b0
symbol range = b15

sertxd("The 2nd Send Data",13,10)
pause 2000

do
gosub Look
pause 2000
sertxd("The 6th Send Data",13,10)
pause 2000
loop

Look:
gosub white
;gosub ChkDist ; Check the Parallx PING to be sure there is nothing in front

sertxd("The 3rd Send Data",13,10)

; Fetch PIXY CMUcam5 data
;SerIn RX_PIN, RX_BAUD, ($AA), b1, b3,b2, b5,b4, b7,b6, b9,b8, b11,b10, b13,b12
SerIn RX_PIN, RX_BAUD, b1, b3,b2, b5,b4, b7,b6, b9,b8, b11,b10, b13,b12
pause 5000

sertxd("The 4th Send Data",13,10)
SerTxd (#b1, #b3,#b2, #b5,#b4, #b7,#b6, #b9,#b8, #b11,#b10, #b13,#b12,13,10,13,10)
sertxd("The 5th Send Data",13,10)
return

white:
high WLEDs
return
 

inglewoodpete

Senior Member
Hi,

I removed the "($AA)," from the program, but still I am not seeing and data in the terminal window. I have been hoping to see the data string from the PIXY CMUcam5 camera which defaults to standard 9600 baud and I have set some actions from the incoming data to light up LEDs in the bot before. So the problem seems not so much the "serin", but getting the data sent to the terminal screen.
Looking at your code, the only "blocking" command is the SerIn command. So the problem is still related to one or more of the 5 criteria that I listed above.

If you connect a LED+resistor (better still a logic probe or oscilloscope) on pin C.3, does data appear on that pin (Leg 14)? Does C.3 idle high? Temporarily reduce the number of byte variables in the SerIn command - does execution then proceed?
 

hippy

Technical Support
Staff member
Perhaps start with a simple program. This will check whether any $AA bytes are being received -

Code:
#Picaxe 28X2
#Terminal 9600

Symbol RX_PIN  = C.3
Symbol RX_BAUD = T9600

Pause 2000
SerTxd("Started",CR,LF)

Do
  SerTxd( "Wait for $AA ... ")
  SerIn RX_PIN, RX_BAUD, ($AA)
  SerTxd( "Got it", CR,LF )
Loop
 

SolidWorksMagi

Senior Member
Perhaps start with a simple program. This will check whether any $AA bytes are being received -

Code:
#Picaxe 28X2
#Terminal 9600

Symbol RX_PIN  = C.3
Symbol RX_BAUD = T9600

Pause 2000
SerTxd("Started",CR,LF)

Do
  SerTxd( "Wait for $AA ... ")
  SerIn RX_PIN, RX_BAUD, ($AA)
  SerTxd( "Got it", CR,LF )
Loop

Hi,

I gave that a try, the bot just sat there looking at a piece of red plastic triggering the recognition in the PIXY CMUcam5, but never sending any data to the PC other than "3 Wait for $AA data ..." 23-PIXYGamerBot.jpg
 

sages

Member
Maybe it is waiting to receive $AA ;)
Change the code to accept any incoming character and see what it displays.
Looking like you have a mineral or electron problem. ie missing connection between o/p of camera and pic, incorrect voltage or levels, or device isn't sending o/p code.
 

hippy

Technical Support
Staff member
As sages says it's waiting for the $AA and isn't receiving it. Perhaps the CMUcam5 isn't sending data, the baud rate, polarity or voltage is wrong, it's connected to a different pin, or there's a 0V connection missing.

I would go back to the program which did work and check that still works. If so post that code and we may be able to determine what is going wrong.

It could be that you have to send something to get the CMUcam5 to start sending data.
 

SolidWorksMagi

Senior Member
Hi,

I did remove the $AA and replaced it with b1 to see if I could see b1 but got nothing on the terminal screen, however using the original program (I copied the variable setup and initializations for the serin/sertxd from the program (hippy gave me a long time ago) I was using before so none of that has been changed and it and that program still works perfect!

PIXYbot Sees a Big Fat Belly

I'm going to redo that video one day when I can setup better lighting so people can actually see my big fat belly in the camera view on the PC screen.

The only changes were to remove the "Case" statements so I could just see the data coming back from the PIXY CMUcam5 to see if I can setup more functions based on vision.
 

SolidWorksMagi

Senior Member
Hi,

Okay, here's the FatBelly code;

; 28X2+PIXYcam5-Serial-FatBellyMaster.bas

#picaxe 28X2 ; type chip used
#terminal 9600

; Declare and Initialize Variables and Constants * * * * * * * * * * * * * * *
symbol RWheel = B.0
symbol LWheel = B.1

symbol RLED = B.7
symbol GLED = B.6
symbol BLED = B.5

; Serial IN = PIN 8 of 28X2 module to PIN 1 of PIXY CMUcam5 Grey Cable
; SerialOUT = PIN 9 of 28X2 module to PIN 4 of PIXY CMUcam5 Grey Cable

Symbol RX_PIN = C.3
Symbol RX_BAUD = T9600
pause 2000
SerTxd(CR, LF)

; hserout pin = C.6
hsersetup B9600_8, %00000 ; 9600 baud, non-inverted polarity

init: servo RWheel,150
servo LWheel,150

; BEGIN Main Body * * * * * * * * * * * * * * *
;pause 5000

gosub Cntr
gosub Speech1

Do
;debug
SerIn RX_PIN, RX_BAUD, ($AA), b1, b3,b2, b5,b4, b7,b6, b9,b8, b11,b10, b13,b12

sertxd ("The 1st data is ",#b1,13,10)
SerTxd (#b1, #b3,#b2, #b5,#b4, #b7,#b6, #b9,#b8, #b11,#b10, #b13,#b12)

Select Case b1
Case $55 : SerTxd( "Normal")
Case $56 : SerTxd( "Color")
Else : SerTxd( "Unknown")
End Select
SerTxd( " Checksum=" , #w1 )
SerTxd( " Signature=" , #w2 )
SerTxd( " X=" , #w3 )
SerTxd( " Y=" , #w4 )
SerTxd( " Width=" , #w5 )
SerTxd( " Height=" , #w6 )
SerTxd( CR, LF )

IF w3<90 then gosub Left
IF w3>110 then gosub Right

IF w2 = 257 then gosub RWarn
IF w2 = 258 then gosub GWarn
IF w2 = 259 then gosub BWarn

gosub Cntr
gosub Fun
pause 1000
gosub Learn

Loop

; BEGIN SpeakJet Talking & Singing Subroutines * * * * * * * * * * * * * * *
Vocal: ; Vocal Test, second vocal test
; \PITCH \100 \VV \OW \KE \AW \LE Test , , second , \PITCH \95 \VV \OW \KE \AW \LE \PITCH \100 test
gosub red
pause 500
gosub green
pause 500
gosub blue
pause 500
gosub Orange
gosub Cntr
hserout 0,(20, 96, 21, 114, 22, 88, 23, 5, 22, 100, 166, 137, 194, 135, 145, 191, 131, 8, 187, 191, 2, 2, 8, 187, 131, 195, 133, 141, 177, 2, 22, 95, 166, 137, 194, 135, 145, 22, 100, 191, 131, 8, 187, 191)
pause 3500
return

Speech1:
; Hello, My name is Turner
; Hello, My name is pick see Bot
gosub green
hserout 0,(20, 96, 21, 114, 22, 88, 23, 5, 183, 7, 159, 146, 164, 2, 140, 155, 141, 154, 140, 8, 129, 167, 8, 191, 151, 141, 148)
pause 3500

; I am a PIXYbot
; I am a pick see Bot
gosub green
hserout 0,(20, 96, 21, 114, 22, 88, 23, 5, 157, 132, 132, 140, 154, 128, 198, 129, 195, 187, 187, 128, 128, 6, 171, 8, 136, 191)
pause 3500

; I have a RoboGuts circuit board
; I have a \RR \OW \BO \OW \GE \AW \TT \Slow \SE \SE \RR \KE \EH \TT \BO \OW \RR \DE
gosub Teal
hserout 0,(20, 96, 21, 114, 22, 88, 23, 5, 157, 183, 8, 132, 166, 154, 128, 148, 137, 171, 137, 178, 135, 191, 8, 187, 187, 148, 194, 131, 191, 171, 137, 148, 174)
pause 3500

; I have a PICAXE 28X2 module
; I have a pick ax twenty eight X two \MM \AW \JH \UH \LE
gosub Teal
hserout 0,(20, 96, 21, 114, 22, 88, 23, 5, 157, 183, 8, 132, 166, 154, 128, 198, 129, 195, 132, 132, 196, 187, 8, 7, 191, 7, 147, 131, 141, 7, 191, 128, 154, 4, 191, 131, 131, 195, 187, 8, 191, 162, 140, 135, 165, 138, 145)
pause 4000

; I have a PIXY CMUcam5 camera
; I have a pick see C M U \KE \AY \MM five \KE \AY \MM \RR \AW
gosub Pink
hserout 0,(20, 96, 21, 114, 22, 88, 23, 5, 157, 183, 8, 132, 166, 154, 128, 198, 129, 195, 187, 187, 128, 128, 6, 187, 187, 128, 128, 6, 131, 131, 140, 6, 8, 160, 6, 194, 132, 140, 6, 186, 157, 166, 6, 194, 132, 140, 148, 135)
pause 5000

; Shall we play a game
; \PITCH \90 Shall \PITCH \95 we \PITCH \90 play \PITCH \85 a \PITCH \100 game
gosub green
hserout 0,(20, 96, 21, 114, 22, 88, 23, 5, 22, 90, 189, 8, 132, 8, 146, 22, 95, 147, 8, 128, 22, 90, 199, 7, 145, 131, 154, 22, 85, 154, 128, 22, 100, 8, 178, 154, 140)
pause 3500
return

Attack:
; Attack, attack, attack
; \AW \TT \AY \KE \AW \TT \AY \KE \AW \TT \AY \KE
hserout 0,(20, 96, 21, 114, 22, 88, 23, 5, 135, 191, 132, 194, 135, 191, 132, 194, 135, 191, 132, 194)
pause 2000
return

Fun:
; This is fun, give me another color
;
gosub red
hserout 0,(20, 96, 21, 114, 22, 88, 23, 5, 8, 169, 8, 129, 187, 8, 129, 167, 186, 8, 134, 141, 2, 8, 178, 8, 129, 7, 166, 140, 128, 128, 134, 141, 134, 169, 151, 195, 8, 134, 146, 7, 151)
pause 2000
return

RWarn:
; I see red
;
gosub red
;hserout 0,(20, 96, 21, 114, 22, 88, 23, 5, 157, 187, 187, 128, 128, 148, 8, 131, 176)
pause 1000

sertxd ("Red Data is ",b1, #b3,#b2, #b5,#b4, #b7,#b6, #b9,#b8, #b11,#b10, #b13,#b12,13,10)
return

GWarn:
; I see green
;
gosub green
;hserout 0,(20, 96, 21, 114, 22, 88, 23, 5, 157, 187, 187, 128, 128, 8, 179, 7, 148, 8, 128, 141)
pause 1000

sertxd ("Green Data is ",b1, #b3,#b2, #b5,#b4, #b7,#b6, #b9,#b8, #b11,#b10, #b13,#b12,13,10)
return

BWarn:
; I see blue
;
gosub blue
;hserout 0,(20, 96, 21, 114, 22, 88, 23, 5, 157, 187, 187, 128, 128, 171, 7, 146, 162)
pause 1000

sertxd ("Blue Data is ",b1, #b3,#b2, #b5,#b4, #b7,#b6, #b9,#b8, #b11,#b10, #b13,#b12,13,10)
return

Learn: ; Learn to be a Geek
; \PITCH \100 \LE \Slow \RR \PITCH \90 \NE to \BE \IY a \PITCH \100 \GE \IY \KE
gosub blue
gosub FWD
hserout 0,(20, 96, 21, 114, 22, 88, 23, 5, 22, 100, 145, 8, 148, 22, 90, 141, 6, 8, 191, 162, 170, 128, 154, 128, 22, 100, 178, 128, 194)
pause 3000
return
; END SpeakJet Talking & Singing Subroutines * * * * * * * * * * * * * * * *
end

; BEGIN Standard Servo Subroutines * * * * * * * * * * * * * * * * * * * * * *
; PWMOUT pin, period, duty cycles
; Wheels
Cntr:
servopos RWheel, 150
servopos LWheel, 150
return

FWD:
servopos RWheel, 130
servopos LWheel, 170
return

BAK:
servopos RWheel, 165
servopos LWheel, 135
return

Right:
servopos RWheel, 125
servopos LWheel, 125
return

Left:
servopos RWheel, 175
servopos LWheel, 175
return
; END Standard Servo Subroutines * * * * * * * * * * * * * * * * * * * * * **
end
; BEGIN RGB LED subroutines * * * * * * * * * * * * * * *
LEDsOFF:
high RLED
high GLED
high BLED
return

red:
low RLED
high GLED
high BLED
return

green:
high RLED
low GLED
high BLED
return

blue:
high RLED
high GLED
low BLED
return

Pink:
low RLED
high GLED
low BLED
return

Orange:
low RLED
low GLED
high BLED
return

Teal:
high RLED
low GLED
low BLED
return
; END RGB LED subroutines * * * * * * * * * * * * * * * *
end
 

hippy

Technical Support
Staff member
Okay, here's the FatBelly code
If that code works as expected with the setup you are currently using there is no obvious reason why your code in post #1 and the simpler code in post #5 does not.

For the FatBelly code to run the CMUCam5 has to be putting out $AA bytes and checking for those is all the post #5 code does.

There is no obvious reason why the $AA bytes would be produced with the FatBelly code but not with the post #5 code. In fact it would not seem unreasonable to say that would be impossible.

But things sometimes can be weird. I would suggest running the FatBelly code and checking that works as expected. Then take code out a chunk at a time and check that everything else still works. Keep trimming it back until you are down to the bare minimum, have the equivalent of what Post #5 is.

That will either have post #5 work as it would have been expected to, or reveal what was removed which causes things to stop working.
 

SolidWorksMagi

Senior Member
If that code works as expected with the setup you are currently using there is no obvious reason why your code in post #1 and the simpler code in post #5 does not.

For the FatBelly code to run the CMUCam5 has to be putting out $AA bytes and checking for those is all the post #5 code does.

There is no obvious reason why the $AA bytes would be produced with the FatBelly code but not with the post #5 code. In fact it would not seem unreasonable to say that would be impossible.

But things sometimes can be weird. I would suggest running the FatBelly code and checking that works as expected. Then take code out a chunk at a time and check that everything else still works. Keep trimming it back until you are down to the bare minimum, have the equivalent of what Post #5 is.

That will either have post #5 work as it would have been expected to, or reveal what was removed which causes things to stop working.

Hi,

Essentially that's what I did. All I did was change out the "robot body and face plastic parts" for new plastic parts to allow the camera to tilt up 'n down and cut out the "case statement, LEDs and motor subroutines" for testing.

When I didn't see anything, I reprogrammed the FatBelly program into the bot and watched as I change different color pieces in front of the camera and the appropriate color LED turned ON and the robot voiced out the correct color too.

Which is why I opened up this thread ... something is wrong and I don't understand enough.
 

hippy

Technical Support
Staff member
something is wrong and I don't understand enough.
I don't think anyone else will know any more. What you did should have worked.

We know going from what you had to what you have hasn't worked, so make that a smaller jump.

Take out a chunk and check if it works or doesn't. If it works then you are okay so far, carry on removing something else.

If it stops working, add what was removed back in, take out a smaller chunk, repeat until it comes down to adding or removing a single line.

It might be a long and laborious process but depends on how big the chunks are which can be removed without things failing. First thing to do is put a SERTXD after the SERIN so you know it's working. Then you can tear out the speech stuff, then the LED stuff. That should reduce things quit quickly.

Unfortunately I cannot think of any other approach. It's what I have had to do myself at times.

If you have a scope I guess you could put that on the serial line, see if the $AA's are being sent to the PICAXE, check they are arriving on the C.3 pin. If they are and post#5 doesn't work, we may be able to figure that out more easily.
 

SolidWorksMagi

Senior Member
Hi,

All I did was add the terminal setup and one line to send the data from the FatBelly program to the terminal;

SerTxd (#b1, #b3,#b2, #b5,#b4, #b7,#b6, #b9,#b8, #b11,#b10, #b13,#b12)

Still no data comes from the PICAXE 28X2 to the terminal other than some basic text in the lines before the data collection serin command.
 
Last edited:

SolidWorksMagi

Senior Member
I don't think anyone else will know any more. What you did should have worked.

We know going from what you had to what you have hasn't worked, so make that a smaller jump.

Take out a chunk and check if it works or doesn't. If it works then you are okay so far, carry on removing something else.

If it stops working, add what was removed back in, take out a smaller chunk, repeat until it comes down to adding or removing a single line.

It might be a long and laborious process but depends on how big the chunks are which can be removed without things failing. First thing to do is put a SERTXD after the SERIN so you know it's working. Then you can tear out the speech stuff, then the LED stuff. That should reduce things quit quickly.

Unfortunately I cannot think of any other approach. It's what I have had to do myself at times.

If you have a scope I guess you could put that on the serial line, see if the $AA's are being sent to the PICAXE, check they are arriving on the C.3 pin. If they are and post#5 doesn't work, we may be able to figure that out more easily.

Hi,

I tried adding lines to the FatBelly program but never get anything back on sertxd after the serin line ??? You can see the various lines I used trying to get data to the terminal window below;

Do
SerIn RX_PIN, RX_BAUD, ($AA), b1, b3,b2, b5,b4, b7,b6, b9,b8, b11,b10, b13,b12

sertxd ("The 1st data is ",13,10)
;SerTxd ($AA),(#b1, #b3,#b2, #b5,#b4, #b7,#b6, #b9,#b8, #b11,#b10, #b13,#b12)
;SerTxd (#b1, #b3,#b2, #b5,#b4, #b7,#b6, #b9,#b8, #b11,#b10, #b13,#b12,13,10,13,10)
SerTxd (b1, b3,b2, b5,b4, b7,b6, b9,b8, b11,b10, b13,b12, 13,10,13,10)

loop
 

hippy

Technical Support
Staff member
I tried adding lines to the FatBelly program but never get anything back on sertxd after the serin line ???
That seems to suggest the modified FatBelly program isn't working.

It is getting unclear what does work and what does not. Does the original, unmodified, FatBelly program work as expected using your current hardware ?

If not then the CMUcam5 is not sending $AA or the PICAXE is not seeing that.

If it does work but adding a SERTXD stops it working then I am not sure what is going on. Perhaps power-cycle, hard reset, everything including the CMUcam5.
 

SolidWorksMagi

Senior Member
That seems to suggest the modified FatBelly program isn't working.

It is getting unclear what does work and what does not. Does the original, unmodified, FatBelly program work as expected using your current hardware ?

If not then the CMUcam5 is not sending $AA or the PICAXE is not seeing that.

If it does work but adding a SERTXD stops it working then I am not sure what is going on. Perhaps power-cycle, hard reset, everything including the CMUcam5.


Hi,

The original FatBelly program only gets the color ID number from the camera. The PIXY CMUcam5 documentation seems to imply that all sorts of data about the color besides color ID is sent though the serial port, so far it seems only the color ID is sent which is what the FatBelly program uses.

I'm giving up on that for now, but trying to read the two Pan&Tilt servos connected to the PICAXE 28X2 module instead. This might work for the project instead. But when using the following program I only get "0" for the two results?

#picaxe 28X2 ; type chip used
#terminal 9600
pause 1000
sertxd ("Terminal Initiated ",#b1,13,10)

; Declare and Initialize Variables and Constants * * * * * * * * * * * * * * *
symbol RWheel = B.0
symbol LWheel = B.1

init: servo RWheel,150
servo LWheel,150

do
pulsin RWheel,1,w1
pulsin LWheel,1,w2

sertxd (" Pan/LServo = ",#w1, 13,10)
sertxd (" Tilt/RServo = ",#w2 ,13,10)

loop
 

SolidWorksMagi

Senior Member
Presumably because no pulses are being seen on the B.0 and B.1 pins.

Hi,

But servo motors on B.0 and B.1 are spinning as I move a color dot around in front of the PIXY CMUcam5 now I get a ton of directional data that I can use. I just have to sort it out a little.
 
Last edited:
Top