ColorPAL arduino problem >.<
Komuri
Posts: 4
Hi! I am trying to get a ColorPAL working with my Arduino Nano. Basically I connected the pins 2 and 3 to the signal pin in the ColorPAL and use this code to display colors to test:
First it didn´t do anything, but then I read somewhere that powering the ColorPAL with 5V was wrong, instead it should be with 3.3V, so I changed it and the code above worked. The ColorPAL started flashing violet and red. Next I tried to put the ColorPAL to constantly measure a color with the following code:
But that didn´t work at all . In some other webpages people said it did worked with them. Basically the serial monitor only showed Pass 1 and Pass 2. I tried other reading codes across the web but none worked . Help please!!
#include <SoftwareSerial.h> SoftwareSerial Color90(2, 3); /*==================================================== / Connect ColorPAL SIG signal to Arduino pin 2 and 3 / Baud Rate = 9600 kbps / /====================================================*/ void setup() { Serial.begin(9600); Color90.begin(4800); pinMode(2,INPUT); pinMode(3,INPUT); digitalWrite(2,HIGH); // Enable the pull-up resistor digitalWrite(3,HIGH); // Enable the pull-up resistor pinMode(2,OUTPUT); pinMode(3,OUTPUT); digitalWrite(2,LOW); digitalWrite(3,LOW); pinMode(2,INPUT); pinMode(3,INPUT); Serial.println("Pass 1"); while( digitalRead(2) != HIGH || digitalRead(3) != HIGH ) { Serial.println("In the loop"); delay(50); } Serial.println("Pass 2"); pinMode(2,OUTPUT); pinMode(3,OUTPUT); digitalWrite(2,LOW); digitalWrite(3,LOW); delay(80); pinMode(2,INPUT); pinMode(3,OUTPUT); delay(100); } //--------------------------------- void loop() { char rByte[9]; Color90.begin(4800); Color90.print("= V !"); delay(500); Color90.print("= R !"); delay(500); }
First it didn´t do anything, but then I read somewhere that powering the ColorPAL with 5V was wrong, instead it should be with 3.3V, so I changed it and the code above worked. The ColorPAL started flashing violet and red. Next I tried to put the ColorPAL to constantly measure a color with the following code:
#include <SoftwareSerial.h> SoftwareSerial Color90(2, 3); /*==================================================== / Connect ColorPAL SIG signal to Arduino pin 2 and 3 / Baud Rate = 9600 kbps / /====================================================*/ void setup() { Serial.begin(9600); Color90.begin(4800); pinMode(2,INPUT); pinMode(3,INPUT); digitalWrite(2,HIGH); // Enable the pull-up resistor digitalWrite(3,HIGH); // Enable the pull-up resistor pinMode(2,OUTPUT); pinMode(3,OUTPUT); digitalWrite(2,LOW); digitalWrite(3,LOW); pinMode(2,INPUT); pinMode(3,INPUT); Serial.println("Pass 1"); while( digitalRead(2) != HIGH || digitalRead(3) != HIGH ) { Serial.println("In the loop"); delay(50); } Serial.println("Pass 2"); pinMode(2,OUTPUT); pinMode(3,OUTPUT); digitalWrite(2,LOW); digitalWrite(3,LOW); delay(80); pinMode(2,INPUT); pinMode(3,OUTPUT); delay(100); } //--------------------------------- void loop() { char rByte[9]; Color90.begin(4800); Color90.print("= (00 $ m) !"); pinMode(3,INPUT); rByte[0] = Color90.read(); if( rByte[0] == '$' ) { for(int i=0; i<9; i++) { rByte[i] = Color90.read(); Serial.print(rByte[i]); } Serial.println(); } delay(500); }
But that didn´t work at all . In some other webpages people said it did worked with them. Basically the serial monitor only showed Pass 1 and Pass 2. I tried other reading codes across the web but none worked . Help please!!
Comments
-Phil
The documentation states that the module needs 5V to operate:
I'm not sure it will work at 3.3V. Although the Sensor and ATtiny are speced at a lower voltages, The LED's may not operate at 3.3V.
I'd stick to the documentation.
Jim
EDIT: Phil got to it before me again! He must not be typing with the broken foot.
-Phil
I hooked it up to a single pin and I'm using the software serial object to transmit and receive on the same pin. I did a line by line translation of PBASIC to C and I think I am close.
Still the sensor only works with 3.3V. I've made many tests but with 5V it never ever worked.
Being that aside, a quick question: The 9 hex values represent RGB html hex like colors? I got readings like 0470A2032, so red would be 047, green 0A2 and blue 032. But it doesn't matter what color I put it to read, those values never pass the 0FF value. So is that 0 just for separating the values?
Thanks for the help .
-Phil
Your use of the two software serials is a bit unusual. I've found a single SoftwareSerial and Phil's circuit to always work with these open drain single-line jobbies.
-- Gordon
I'm definitely getting data back, but instead of a $ it looks like a y with an umlaut over it. Almost what you would expect if the baud rate didn't match.
Update! Got it working!
The sketch demonstrates a couple of ways to play the SoundPAL's built-in tunes, but the general idea is there for you.
-- Gordon
BTW I've been doing a lot of BS2 work lately and have gotten spoiled by its IDE. It files and works really smoothly. The Arduino IDE is a tad cumbersome by comparison.
Since your code indicates that you're not using the "serout" serial port after you've set up serin, you could try simply ending that port -- serout.end(). Do that first, then start serin. This is because ending a serial port will reset its pins to inputs.
A problem I see here is that by having serin and serout virtual serial ports tied to the same physical pins, but in reverse, one pin has to be an OUTPUT and the other pin has to be an INPUT. It seems to me the pin direction is set by the last serial.begin() you've set for those pins. Therefore, kill the port you no longer need. With the new SoftwareSerial, the Arduino will capture bytes from the software serial port most recently defined, or the one toggled to with the listen method.
-- Gordon
Yes, I do that, too. Only it tends to make me look like these guys:
-- Gordon
Doing this exercise really made me appreciate the Basic Stamp 2. The serin command is really powerful and my sscanf is something CS majors would be comfortable doing, but not the average non-programmer.
-Phil
The new SoftwareSerial in Arduino 1.0 handles serial.available, so you can use that to check for, and as necessary wait for, the serial buffer to start filling up. That's an overall better approach than hard-coded delays.
You might try a variation where you stay in a loop first checking if the buffer has anything, then checking if whatever that is is a $. Then begin reading each byte in the for loop. In a sketch that does more than this you'd put in a timeout if nothing is ever received, but that can be left out for basic demo code.
-- Gordon
Lots of little buglets with can get squashed if you put the receiver code in a fairly tight loop, using available() to test if there's anything in the buffer, then read (and as necessary discard bytes) until the $, and then collect the array. You can put in a timeout with the usual construct if there's a chance the ColorPAL will ever be unresponsive. That all depends on what else the sketch is supposed to do. And of course be sure that serin is the currently active software serial port; that allows it to trigger the proper interrupts for background buffering.
I'll have to get one of these ColorPAL jobbies someday to try it out. Looks interesting.
-- Gordon
BTW, do you really spell your name with four e's? That's a lot of vowels!
-- Gordon
Thanks for pointing out that spelling error. The triple e should have been a double e for a total of three. It's a Dutch surname and they go overboard with vowels. I'm just glad there is no umlaut I have to deal with.
In Holy Grail Monty Python had some fun during the opening credits with all those funny accented characters. Who could forget "Als
does not show me anything, this is my code, could someone help me please
#include <SoftwareSerial.h>
#define rxPin 2
#define txPin 3
SoftwareSerial colorPal = SoftwareSerial(rxPin, txPin);
void setup() {
Serial.begin(9600);
colorPal.begin(4800);
pinMode(rxPin,INPUT);
pinMode(txPin,INPUT);
digitalWrite(rxPin,HIGH); // Enable the pull-up resistor
digitalWrite(txPin,HIGH); // Enable the pull-up resistor
pinMode(rxPin,OUTPUT);
pinMode(txPin,OUTPUT);
digitalWrite(rxPin,LOW);
digitalWrite(txPin,LOW);
pinMode(rxPin,INPUT);
pinMode(txPin,INPUT);
Serial.println("Pass 1");
while( digitalRead(rxPin) != HIGH || digitalRead(txPin) != HIGH ) {
Serial.println("In the loop");
delay(50);
}
Serial.println("Pass 2");
pinMode(rxPin,OUTPUT);
pinMode(txPin,OUTPUT);
digitalWrite(rxPin,LOW);
digitalWrite(txPin,LOW);
delay(80);
pinMode(rxPin,INPUT);
pinMode(txPin,OUTPUT);
delay(100);
}
//
void loop() {
colorPal.print("= $ m !");
char rByte[9];
rByte[0] = colorPal.read();
if(rByte[0] == '$'){
for(int i=0; i < 9; i++){
rByte = colorPal.read();
Serial.print(rByte);
}
Serial.println();
}
delay(500);
}
A few post up is code I posted which works with the colorPal and Arduino, and only uses a single pin. You might want to try that.