Hi everyone. First post on the forums and yes I have searched extensively on this problem via google and on this site. Nothing I have tried from what I have read has solved the problem.
What I am trying to do:
I am building a "Light Tree" for my sons cub scout pack pinewood derby race track. It has a microwizard "Finish Line" timer that communicates via a 9 pin serial cable to a computer program that records race times.
The leonardo is going to receive a signal on an alternate, non serial tx/rx pin, set to high to notify "Start Race" and when that signal is received the program will trigger a series of LED's to flash like a racing light sequence in front of each lane and then activate a solenoid via relay to open the gate and start the race. I have all that code worked out down to using an amp circuit to drive the LED's because their are 8 per output pin. My original plan was once the race started I was going to wait for the "End of Race" high signal to flash the green start LED's when the race ended.
Where things are going wrong is that I had to go and think "What if I could tell who won the race and blink just their green leds at the end? There is an end of race signal on another pin and then a serial string is sent to the computer with race data including a special character for the winner.
How I thought I could make this happen:
My plan was simple. Use pins 0 and 1 on the leonardo to receive the timer serial TX coms on the RX pin on the arduino, read the stream and replay it back out the TX pin and back out to the computer. Sort of a man in the middle. Once I had successfully set up my man in the middle position I was going to then build a string of the input chars and search for the special character to know who won and blink the appropriate LED group.
Where things are going wrong:
I have captured a sample end of race string sent to the computer without the arduino in the middle via a terminal emulator and it looks like this:
A=0.992! B=1.164 C=1.237 D=1.383 E=0.000 F=0.000
When I put the arduino in the middle this is what I get:
PO2J92! B=1.164 C=1.237 D=1.383 E=0.000 F=0.000
If I do it 5 times in a row it is inconsistent. At least one of those times has more going on at the start of the string.
I can take out the timer all together and just hook the arduino directly to the computers com port, open a terminal and send that string and what I get back is exactly as above. I can change the string to say: This is a test of the serial coms and it changes the first 4 characters every time. If I use a serial terminal that I can just "free type" in the window not one single character comes back as what I type. Q goes out and comes back as G etc...
I have two leonardos. One that is 2 years old and one I received 2 days ago that I was going to give to the scout pack once programmed. They both behave exactly the same!
Serial Coms Test Sketch and what I have tried:
int led = 13;
byte byteRead;
void setup() {
// initialize both serial ports:
Serial1.begin(9600);
if (!Serial1) {}
pinMode(led,OUTPUT);
}
void loop() {
while (Serial1.available() > 0) {
byteRead = Serial1.read();
Serial1.write(byteRead);
digitalWrite(led, HIGH);
digitalWrite(led, LOW);
}
}
The sketch above is pretty much exactly what I am testing. I had to remove some added code this morning for other tests to make this post and could not try it on the arduino ![]()
I have tried using the softserial class and it behaves exactly the same way. I have tried different data types, different sketches that build the whole string before re transmitting it but in the end, the above should do the job right? I have tried different types of wires, twisted, untwisted pair etc... It always does the same thing.
There just seems to be some inherent action at the start of a string with the arduino that causes this behavior. I have tried sending/receiving the string via the serial monitor com port via USB and it comes back just fine.
The connections are:
Arduino powered via USB
Pin 0 (RX) to TX on the computers serial port
Pin 1 (TX) to RX on the computers serial port
Arduino ground to pin 5 on the serial port (also ground)
If anyone can shed any light on this I would truly appreciate it. Thanks!