SO ive got the code from the colorpal / parallax site and all running fine on arduino uno rev3 board wired at 5v as per instructions and using the default code supplied (bit wierd serial stuffs but hey) and am i right in thinking the internal led is rgb and should strobe through all colours. Mine seems stuck on green and when testing i get no flux in the red value, but some on green and blue - even with a bright red bit of fabric in front.
Does this code work with newer Arduino 1 + serial and if not does anyone know any mods - or is my sensor perhaps a bit duff ?
If anyone knows how i could poll the internal rgb on the sensor i could manually make it blink red, green blue i could test if it worked.
Yeah,colour sensing.. quite tricky
/* ColorPal Sensor Example for Arduino
Author: Martin Heermance, with some assistance from Gordon McComb
This program drives the Parallax ColorPAL color sensor and provides
serial RGB data in a format compatible with the PC-hosted
TCS230_ColorPAL_match.exe color matching program.
*/
#include <SoftwareSerial.h>
const int sio = 2; // ColorPAL connected to pin 2
const int unused = 255; // Non-existant pin # for SoftwareSerial
const int sioBaud = 4800;
const int waitDelay = 200;
// Received RGB values from ColorPAL
int red;
int grn;
int blu;
// Set up two software serials on the same pin.
SoftwareSerial serin(sio, unused);
SoftwareSerial serout(unused, sio);
void setup() {
Serial.begin(9600);
reset(); // Send reset to ColorPal
serout.begin(sioBaud);
pinMode(sio, OUTPUT);
serout.print("= (00 $ m) !"); // Loop print values, see ColorPAL documentation
serout.end(); // Discontinue serial port for transmitting
serin.begin(sioBaud); // Set up serial port for receiving
pinMode(sio, INPUT);
}
void loop() {
readData();
}
// Reset ColorPAL; see ColorPAL documentation for sequence
void reset() {
delay(200);
pinMode(sio, OUTPUT);
digitalWrite(sio, LOW);
pinMode(sio, INPUT);
while (digitalRead(sio) != HIGH);
pinMode(sio, OUTPUT);
digitalWrite(sio, LOW);
delay(80);
pinMode(sio, INPUT);
delay(waitDelay);
}
void readData() {
char buffer[32];
if (serin.available() > 0) {
// Wait for a $ character, then read three 3 digit hex numbers
buffer[0] = serin.read();
if (buffer[0] == '
) {for(int i = 0; i < 9; i++) {
while (serin.available() == 0); // Wait for next input character
buffer[i] = serin.read();
if (buffer[i] == '
![Screen shot 2014-02-25 at 22.23.12.png|1280x800](upload://wrzJ0K3LkK8Wmhcv0RDlvR1BknB.png)) // Return early if $ character encountered
return;
}
parseAndPrint(buffer);
delay(50);
}
}
}
// Parse the hex data into integers
void parseAndPrint(char * data) {
sscanf (data, "%3x%3x%3x", &red, &grn, &blu);
char buffer[32];
sprintf(buffer, "R%4.4d G%4.4d B%4.4d", red, grn, blu);
Serial.println(buffer);
}