Moving analog data over serial

Did you remember to connect the grounds of the two Arduino boards ?

If you are using two standard Arduinos with on-board USB hardware, it does not work to connect an additional TX input to the RX pin. It fights with the existing connection to the USB hardware on that pin.

You can use another pin as a serial input on the receiving unit with the SoftSerial library. Search the forum and playground for examples.

Good luck with your project,

-br

Yes grounds are connected. The boards I am using do not have USB on them.

Does the receiver work as expected when you type the expected input to it in the serial monitor while it's connected to a PC?

-br

Edit: an additional question: doesn't parseInt() leave the delimiter as the next available character in the serial buffer? If so, wouldn't you have to eat the comma with Serial.read() after parseInt() to move on past the comma?

Yes it does. Apparently the voltage levels on the pins 0 and 1 do not work for ttl. Rs232. When I jumper the tx pin on the header going to the Macintosh USB cable header on the arduino board to the Rex pin on the programming port on the reciever board the signal get there okay.

What kind of circuit do I have to use to get the pins 0 and 1 to have the correct voltage levels to communicate.

If the two arduinos are running at the same +VCC, a direct connection from TX on Arduino 1 to Rx on Arduino 2 should "just work" for 9600 baud serial, provided nothing else is connected to the either pin in question, and the grounds are good.

A puzzler...

-br

billroy:
If you are using two standard Arduinos with on-board USB hardware, it does not work to connect an additional TX input to the RX pin. It fights with the existing connection to the USB hardware on that pin.

You can use another pin as a serial input on the receiving unit with the SoftSerial library. Search the forum and playground for examples.

Good luck with your project,

-br

No, the arduino boards uses two 1K ohm 'isolation' resistors on the send and rec lines from pins 0 and 1 to the USB serial converter chip. As long as you are not receiving data from the PC via USB (or better yet not plugged into USB) you can directly connect pins 0 and 1 to another arduino boards pin 1 and 0 and exchange serial data with each other.

Lefty

Thanks, Lefty. Happy to know that.

-br

while (Serial.available() > 0)
  {
    red = Serial.parseInt();
    green = Serial.parseInt();
    blue = Serial.parseInt();
    amber = Serial.parseInt();
    pink = Serial.parseInt();

So if there is only one byte in the serial buffer you happily go off and read lots of data from the serial port. Spot your error?

No. I don't even understand this. I am using an exact copy of a way to read a serial buffer from an example on the auduino web site.

jlefevre1:
No. I don't even understand this. I am using an exact copy of a way to read a serial buffer from an example on the auduino web site.

Which example?

Exactly because either you are missunderstanding it or it is wrong.
Serial data takes a long time to arrive, just because one byte has arrived does not mean that all the bytes have arrived. FACT.

Change your sender:
void serialoutput ()
{
Serial.print("<");
Serial.print(red);
Serial.print(",");
Serial.print(green);
Serial.print(",");
Serial.print(blue);
Serial.print(",");
Serial.print(amber);
Serial.print(",");
Serial.print(pink);
Serial.print(",");
Serial.print(valuecmd);
Serial.println(">");
}

Use code like this on the receiver:

#define SOP '<'
#define EOP '>'

bool started = false;
bool ended = false;

char inData[80];
byte index;

void setup()
{
   Serial.begin(57600);
   // Other stuff...
}

void loop()
{
  // Read all serial data available, as fast as possible
  while(Serial.available() > 0)
  {
    char inChar = Serial.read();
    if(inChar == SOP)
    {
       index = 0;
       inData[index] = '\0';
       started = true;
       ended = false;
    }
    else if(inChar == EOP)
    {
       ended = true;
       break;
    }
    else
    {
      if(index < 79)
      {
        inData[index] = inChar;
        index++;
        inData[index] = '\0';
      }
    }
  }

  // We are here either because all pending serial
  // data has been read OR because an end of
  // packet marker arrived. Which is it?
  if(started && ended)
  {
    // The end of packet marker arrived. Process the packet

    // Reset for the next packet
    started = false;
    ended = false;
    index = 0;
    inData[index] = '\0';
  }
}

Where it says "Process the packet", use strtok() and atoi() to get the numbers from inData.

void output64 ()
{
  if (valuecmd > 637)

Novel.
Can I recommend you revise your binary arithmetic?

The example I was using is from the web site.

Yep looks like crap code in that link.

It isn't partuclarly crap. "parseInt()" sits there trying to read in values from the Serial port until it either times out (and returns 0), or another character arrives in and it sits there trying to read the next. That means that it doesn't need for Serial.available() to be any more than 1 when you first call it for it to work.

Granted the implementation could be improved, for example, if you send "12-34" it will detect it as -1234, and if it takes too long for the 2nd, 3rd, and so on characters to arrive after each other it will just give up and return.
Also that example doesn't account for the fact that you should wait until Serial.available()>0 in between each of the calls to parseInt().

Grumpy_Mike:
Exactly because either you are missunderstanding it or it is wrong.
Serial data takes a long time to arrive, just because one byte has arrived does not mean that all the bytes have arrived. FACT.

LOL, otherwise they wouldn't be allowed to call it serial data as it would be a violation of truth in advertising. Not unlike the fundamental difference between a serial killer and a mass killer, unless you are a victim where the difference is somewhat moot.

Lefty

I found the binary math problem later. Doesn't help the speed any but did fix the logic.