Problems with Color Sensor Programs

fierojo

New Member
Hello All,

I'm new to this forum, so please excuse any potential errors in protocol.

I'm having two problems with a color sensing project. Both programs are standrd, already tried and true programs for the PicAxe. I'm running Windows 7 on my PC, and the Color sensor is from Taos as purchased through Parallax. I'm also using the Parallax cable and adaptor to a Kiwi Patch Board. I'm using an 8M2, running off of a 6 VDC battery pack. The program loads into the PicAxe, and the 2 LEDs on the color sensor flash once per second (assume while its taking a reading), but the information on the serial terminal is jibberish. I've tried all possibile baud settings, including the special one for the USB to serial cable (PixAxe part 027).

********************************************
‘ PICAXE-08M2 input/output pins
symbol LED = 0 ‘ Color sensor white LEDs (output 0)
symbol S2 = 1 ‘ Color sensor select S2 (output 1)
symbol ser = 2 ‘ Servo or serial LCD (output 2)
symbol CSI = 3 ‘ Color sensor pulse (input 3)
symbol S3 = 4 ‘ Color sensor select S3 (output 4)
‘ ********************************************
‘ Variables
symbol red_value = w4 ‘ Color sensor red content
symbol blue_value = w5 ‘ Color sensor blue content
symbol green_value = w6 ‘ Color sensor green content
‘ Remember w4-w6 uses b8-b13!
‘ ********************************************
‘ scan and display every second
main:
gosub color ‘ scan the colour
sertxd ("Red =", 9, #red_value, 9)
sertxd ("Blue =", 9, #blue_value, 9)
sertxd ("Green =", 9, #green_value, CR, LF)
pause 1000
goto main
‘ ********************************************
‘ sub to scan colors
color:
high LED ‘ LED on
low S2 ‘ read red into w4
low S3
count 3, 50, red_value
high S3 ‘ read blue into w5
count 3, 50, blue_value
high S2 ‘ read green into w6
count 3, 50, green_value
low LED ‘ LED off
return

My second problem is another PicAxe color program where I want to hook up a serial LCD to the project. The problem is a syntax error that I can't get by. The program is below:

********************************************
‘ PICAXE-08M input/output pins
symbol LED = 0 ‘ Colour sensor white LEDs (output 0)
symbol S2 = 1 ‘ Colour sensor select S2 (output 1)
symbol ser = 2 ‘ Servo or serial LCD (output 2)
symbol CSI = 3 ‘ Colour sensor pulse (input 3)
symbol S3 = 4 ‘ Colour sensor select S3 (output 4)
‘ ********************************************
‘ Variables
symbol red_value = w4 ‘ Color sensor red content
symbol blue_value = w5 ‘ Color sensor blue content
symbol green_value = w6 ‘ Color sensor green content
‘ Remember w4-w6 uses b8-b13!
‘ ********************************************
‘ scan and display every second
main:
gosub color ‘ scan the colour
serout 2,N2400,(254,128"R=",#red_value, " ")
serout 2,N2400,(254,136"B=",#blue_value, " ")
serout 2,N2400,(254,192"G=",#green_value, " ")
pause 1000
goto main
‘ ********************************************
‘ sub to scan colours
color:
high LED ‘ LED on
low S2 ‘ read red into w4
low S3
count 3, 50, red_value
high S3 ‘ read blue into w5
count 3, 50, blue_value
high S2 ‘ read green into w6
count 3, 50, green_value
low LED ‘ LED off
return

The Syn tax error is a compile error: serout 2,N2400,(254,128"R=",#red_value, " ")

The "^" symbol is below the comma just before the # symbol

Error: Syntax error in this line!

Any help for either problem would be appreciated.

Sincerely,

Fierojo
 

Haku

Senior Member
So the USB-serial setup you're using will happily program the 08m2 but the terminal window within the Picaxe Programming editor shows gibberish no matter what baud you select in that window?


The 2nd problem is a just case of a missing comma after the 2nd number, fixed:

serout 2,N2400,(254,128,"R=",#red_value, " ")
serout 2,N2400,(254,136,"B=",#blue_value, " ")
serout 2,N2400,(254,192,"G=",#green_value, " ")
 

srnet

Senior Member
I'm using an 8M2, running off of a 6 VDC battery pack
6V is too much, from manual1;

Power Supply:
4.5V or 5V DC is recommended. Do not use 6V, 7.2V or 9V battery packs, these
could permanently damage the chip. For trouble-shooting use 3xAA cells only..
 

fierojo

New Member
Thanks Haku,

The comma's solved the second program issue I had. Much appreciated.

Yes, I'm able to program the 8M2 with the same serial cable, and I'm getting bursts of data, about once per second, as the program states to the terminal program, its just in non-readable characters. This gibberish is for all possible Terminal settings.

To Srnet: the kiwi board has a diode to drop the input voltage about 0.5 VDC, and then fed into a 7805 voltage regulator, so the 8M2 sees a solid 5 VDC. I measured the voltage and it is 5.01 VDC.

Let me know if anyone has another suggestion for the Terminal Gibberish issue I'm having.

Fierojo
 

John West

Senior Member
A 7805 needs a bit over 2 volts overhead (depending on load) in order to regulate properly at 5V. When there are tiny loads and no significant load fluctuations you can get away with the setup you're using, but as soon as you add peripheral devices such as relays things may get out of hand.

It's best to supply 5V via the regulator after dropping it down from seven and a half, or more. Otherwise, just keep things down to a 3 cell AA battery pack.

If a large 6V battery is a necessary part of your design, I'd suggest you use a low-dropout regulator between the battery and the PICAXE circuit. If you can operate the circuit at less than 5V, giving the regulator a bit more overhead for it to regulate in and for the battery voltage to drop as it discharges, so much the better.
 

srnet

Senior Member
To Srnet: the kiwi board has a diode to drop the input voltage about 0.5 VDC, and then fed into a 7805 voltage regulator, so the 8M2 sees a solid 5 VDC. I measured the voltage and it is 5.01 VDC
Something is not right then, a 7805 is unlikley to produce a proper 5V output with only 5.5V at its input, and 5.5V is a struggle for even a low drop out regulator.
 

fierojo

New Member
Tried Isolating the program

Took some addtional step today, besides the last advise provided. I also have a PicAxe proto board. It has its own 8M2 on it. It is running directly from a 4.5 VDC Battery pack. No sensors or anything else hooked up to it. I tried the orginal program and have the same gibberish. I then inserted a new program that just displayed the words: "Hello World". Still getting the gibberish. Could the 027 cable or driver have an issue? Is there a different driver for Windows 7? The PicAxe program editor indicates that the program is laoded correctly, but I'm not sure how it is verifiied? Is there two way commincation?

Once again any help would be appreciated.

Thanks.

Fierojo
 

hippy

Ex-Staff (retired)
I then inserted a new program that just displayed the words: "Hello World". Still getting the gibberish.
What baud rate have you selected for the Terminal display ? Try the following in its entirety ...

Code:
#Picaxe 08M2
#Terminal 4800
Do
  SerTxd( ">UUU Working UUU<", CR, LF )
  Pause 1000
Loop
 

fierojo

New Member
It Works!!!

Hippy,

Changing the baud rate to 4800 fixed it! I'm curious as to what's going on then?

Also, should I set the serial output for the AXE133 dislplay to 4800 as well?

Thanks for the answer!

Fierojo
 

eclectic

Moderator
Until hippy replies, I'll come in as a poor second :)

Add the following starter lines to both programs
and modify the Serouts for the Picaxe operating frequency.
The AXE033/133 both work at n2400

It's not always required
but I'm following the Brit adage of
"belt and braces".

Code:
;Add at start

#Picaxe 08M2
setfreq M4
#terminal 4800

serout 2, N2400_4, (254,1) ; clear screen
Pause 500 ; initialisation pause

;The Serouts takes the form
serout 2,N2400_4,(254,128,"R=",#red_value, " ") 

; See Manual 2, page 208
e
 
Top