sending multiple integers over serial.

hello all, ive finally come here out of desperation. i have two Arduino Megas and im trying to use their serial3 to send sensor inputs to the other. One is being used as a large Input/Output and the other a controller. im usually very good at learning as i go along or figuring it out with using others examples, but at serial ive hit a wall.

heres what i have one mega has 4 proximity sensor inputs on it and has 10 total relay outputs, the other has a touch screen and control coding for managing the relays. my biggest question, or help me get on the right path (even understand it) is how can i send the variables from the IO Mega to the Control Mega? once i know how to send a variable i can work on top of what ever ive been shown..
i saw that it has to be sent in a string or a byte, but how do i send&&recieve..(more on the recieve end i dont get)

thanks for any help.. any will help

how can i send the variables from the IO Mega to the Control Mega?

Just like you send to the Serial Monitor.

Serial.print(someVariable);

Of course, if you send more than one variable, you’ll need some way to know where one value ends and the next one begins. That typically involves using a delimiter (unless you’re zoomkat, in which case it involves a delay()).

There are plenty of examples around of sending and receiving serial data. I suspect that “Hey, I’ll just ask someone to write the code for me” sounded easier than actually trying to learn something. But, it won’t work.

I would suggest you send the data values textually, and comma separated value is the most obvious format to use. I would also suggest using a line break to separate the messages. There are plenty of examples showing how to send and receive textual data, but in terms of formatting and parsing I suggest that printf() and scanf() would be good places to start your research.

One advantage of a textual encoding scheme is that you can use the serial monitor to test it.

PaulS:
(unless you're zoomkat, in which case it involves a delay()).

And using a String. :slight_smile:

originalgoon:
i saw that it has to be sent in a string or a byte, but how do i send&&recieve..(more on the recieve end i dont get)

originalgoon:
hello all, ive finally come here out of desperation. i have two Arduino Megas and im trying to use their serial3 to send sensor inputs to the other. One is being used as a large Input/Output and the other a controller. im usually very good at learning as i go along or figuring it out with using others examples, but at serial ive hit a wall.

heres what i have one mega has 4 proximity sensor inputs on it and has 10 total relay outputs, the other has a touch screen and control coding for managing the relays. my biggest question, or help me get on the right path (even understand it) is how can i send the variables from the IO Mega to the Control Mega? once i know how to send a variable i can work on top of what ever ive been shown..
i saw that it has to be sent in a string or a byte, but how do i send&&recieve..(more on the recieve end i dont get)

thanks for any help.. any will help

I'd break your setup into two test setups (sending mega and receiving mega) and use the serial monitor to aide in developing the code for each. First, your description of your relays is not clear as you say they are controlled by the receiving mega, but you also say they are attached to the sending arduino with the sensor inputs (I assume the relays are actually connected to the receiving mega). You will first need to determine what type of output your sensors have (got a link to the sensors?). Then take the sensor data and format it for sending to the receiving mega preferably using a data delimiter to make things easier. On the receiving mega, you will need to explain how you expect to use the received data. The relays will probably be just on/off control, but what are you expecting to do with the touch screen? More info needed to be able to make code suggestions along with what you have successfully done so far.

thank you all for your input and i, through examples got alot better at understanding the send and receive ideas.
i am now sending it over UDP instead and if any one could help me on my new conundrum that would be awesome!

here is my new attempt