ColorPal doubt
Hi everyone, am I new to the forum and I have a doubt about ColorPal sensor. After reading ColorPal´s datasheet I understand that the following command will perform a RGB reading (subtracting ambient light):
SEROUT sio, baud, ["= (00 $ m) !"]
But I don´t understand how should I receive data from sensor. Should I wait for character $ to arrive and then data? How many bytes will the sensor send to the microcontroler?
I will be pleased if you help me.
Regards
SEROUT sio, baud, ["= (00 $ m) !"]
But I don´t understand how should I receive data from sensor. Should I wait for character $ to arrive and then data? How many bytes will the sensor send to the microcontroler?
I will be pleased if you help me.
Regards

Comments
Welcome to the Parallax forum! Let's break that line down into its component parts:
= Begin a program sequence.
(00 Start an infinite (since the count is zero) loop.
$ Send a dollar sign character. Any character that's not a command is sent as-is.
m Perform a multi-color acquisition, subtract the ambient light reading form each component, and transmit the data as nine hex digits in the order RRRGGGBBB
) End the loop.
! Begin execution of the program sequence. This starts the loop, which outputs $RRRGGGBBB$RRRGGGBBB$RRRGGGBBB... continuously.
So, to answer your question, you wait for a dollar sign ($), then read three 3-digit hexadecimal numbers.
-Phil
SEROUT sio, baud, ["= $ m !"] or
SEROUT sio, baud, ["= (01 $ m) !"]
I think the first one is more convenient because a one-time loop has not sense. But am I not sure about syntax.
Regards,
-Phil
Regards,
http://forums.parallax.com/showthread.php?118435-ColorPAL-Object-and-ColorPAL-VGA-Demo&highlight=colorpal
Regards,
Regards,
' ========================================================================= ' ' File...... ColorPAL_sense_wh_bal.bs2 ' Purpose... Demonstrate white balance for ColorPAL ' Author.... Phil Pilgrim -- Bueno Systems, Inc. ' Started... 4 Dec 2011 ' ' {$STAMP BS2} ' {$PBASIC 2.5} ' ' ========================================================================= ' -----[ Program Description ]--------------------------------------------- ' This program drives the Parallax ColorPAL color sensor and provides ' white-balanced color data to the DEBUG terminal. ' -----[ I/O Definitions ]------------------------------------------------- sio PIN 15 ' Serial I/O com pin for ColorPAL. ' -----[ Constants ]------------------------------------------------------- ' Baudrate definitions. Serial I/O must be open-drain. The ColorPAL includes ' a pullup internally. #SELECT $STAMP #CASE BS2, BS2E, BS2PE baud CON 119 + 32768 #CASE BS2SX, BS2P baud CON 327 + 32768 #CASE BS2PX baud CON 536 + 32768 #ENDSELECT ' -----[ Variables ]------------------------------------------------------- red VAR Word ' Received RGB values from ColorPAL. grn VAR Word blu VAR Word sred VAR Word ' White balance scaling factors. sgrn VAR Word sblu VAR Word char VAR Byte i VAR Nib ' -----[ Initialization ]-------------------------------------------------- GOSUB Reset ' Reset the ColorPAL and enter direct command mode. ' -----[ Program Code ]---------------------------------------------------- SEROUT sio, baud, ["= (00 $ m) !"] 'Program ColorPAL to send $ then color data. DEBUG "Place the ColorPAL on a white target, click in the box above, and press Enter.", 13 DO : DEBUGIN char : LOOP UNTIL char = 13 GOSUB ReadRGB ' Read the white sample. FOR i = 0 TO 2 ' Compute scaling factors. sred(i) = $ff80 / red(i) NEXT DEBUG "Ready to sample other colors.", 13 DO GOSUB ReadRGB ' Read the color components. FOR i = 0 TO 2 ' Scale to white values and saturate to 255 if necessary. red(i) = red(i) */ sred(i) MAX 255 NEXT DEBUG "R", DEC3 red, " G", DEC3 grn, " B", DEC3 blu, CR ' Output it. LOOP ' -----[ Subroutines ]----------------------------------------------------- ' ReadRGB: Get RGB response from ColorPAL ReadRGB: SERIN sio, baud, [WAIT("$"), HEX3 red, HEX3 grn, HEX3 blu] ' Receive RGB data back. RETURN ' Reset: Sends a long break to reset ColorPAL and enter direct command mode. Reset: LOW sio 'Pull sio low to eliminate any residual charge. INPUT sio 'Return pin to input. DO UNTIL sio : LOOP 'Wait for pin to be pulled high by ColorPAL. LOW sio 'Pull pin low. PAUSE 80 'Keep low for 80ms to enter Direct mode. INPUT sio 'Return pin to input. PAUSE 10 'Pause another 10ms RETURN-Phil
Regards,