What we have is a Arduino Mega and a ColorPal sensor.
Special for the ColorPal is the bi-directional I/O. Thus, a single I/O pin. From what I understand is that the Arduino works with tr and tx. Two pins.
So, this needs a special solution.
I tried to switch tr and tx from one pin to the other:
#include <SoftwareSerial.h>
#define rxPin 2
#define txPin 3
char colorvalue_upper;
char colorvalue_lower;
// set up a new serial port
SoftwareSerial mySerialOut = SoftwareSerial(rxPin, txPin);
SoftwareSerial mySerialIn = SoftwareSerial(txPin, rxPin);
void setup() {
}
void loop() {
// define pin modes for tx, rx:
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
// set the data rate for the SoftwareSerial port
mySerialOut.begin(7200);
mySerialOut.print("= R !");
delay(1000);
// define pin modes for tx, rx:
pinMode(rxPin, OUTPUT);
pinMode(txPin, INPUT);
mySerialOut.print("= G s !");
// set the data rate for the SoftwareSerial port
mySerialIn.begin(7200);
colorvalue_upper = mySerialIn.read();
delay(1000);
Serial.print("value = ");
Serial.print(colorvalue_upper);
Serial.print("\n");
}
Only the led commands are working fine. But, no sensor values are read.
A hardware solution is given in the parallax forum: forums.parallax.com/forums/default.aspx?f=36&m=435928
Did not try the hardware solution yet. But, is there a software solution?
However, in case it will work I have another question.
The sensor value output is in three hexadecimal digits. But a serial.read is a char. Any idea how to solve this one?