how to send 2 analog inputs values over serial

Hello, im new to arduino and im trying to make communication from arduino to arduino,

the problem is that im reading 2 analog inputs in one arduino and im trying to send their values over the serial port using the apc220 and read it on another arduino and make a led fade, but i dont know how to send the 2 inputs data and make it readable for a determined output, let's say this

1 2
arduino that reads pot send over serial arduino that writes to led
A0 attached to Pin 9
A1 attached to Pin 7

i just dont know how to mark the data for the serial port to tell the arduino how to send and read a byte to make a determined output pin to work,

i have 2 arduino mega 2560 and the apc220

i know how to send one input to control one output, but need to send 2 inputs to control 2 ouputs

thanks for any help given

look at write, print and println. Any of them will work

Mark

holmes4:
look at write, print and println. Any of them will work

Mark

like i said im new to arduino and checked the sketches and manage to send 1 input over serial and control 1 output, but need for 2, those commands are used to send the data but i didnt see in any how to do handle 2 or more inputs

Don't try to eat your elephant all at once.

Write a short sketch that sends the data to the Serial Monitor.

Write another short sketch that takes 2 numbers from the Serial Monitor and causes you leds to fade.

When both of them work then modify both programs so that they talk to each other instead of the serial monitor.

...R

i dont know how to send the 2 inputs data and make it readable for a determined output

I take it that you want to determent witch data gos to witch LED?
I would send a code or marker with the data, so the receiver can put the data to the correct LED.
Like: A147 and B201. The receiving micro then sends 147 to one LED and 201 to the other.

You need to create a protocol that the two Arduinos can agree on. I'm a fan of the preamble/length/data/checksum method, but it's probably easier to send delimited ASCII, such as:

"<a522,b325>"

The < and > characters are the start/stop packets. The a and b character identify which value is which, and the numbers represent the arguments.

the problem is that im reading 2 analog inputs in one arduino and im trying to send their values over the serial port using the apc220 and read it on another arduino and make a led fade, but i dont know how to send the 2 inputs data and make it readable for a determined output, let's say this

When you read the AD value, you have a number between 0 and 1023. When you read the second AD value, you have a second number, 0 - 1023. Both are integers.

Arduino has a special integer read function that you can use that will "parse" the data from the serial input stream. It's that easy.

So, as long as there is a "delimiter" in the serial stream which can be a "comma" or a "space" (CR/LF,etc.) then you can just read the first value and then read the second value. The only requirement is the sender must always send two values, which it will... that is, read A0 and read A1 and serial print them with a delimiter between both.

Pseudocode for send:
Serial.print(valueA0) ;
Serial.print(",") ;
Serial.print(valueA1) ;
Serial.print(",") ;

Pseudocode for receive:
valueA0 = Serial.ParseInt() ;
valueA1 = Serial.ParseInt() ;

You 'can' use Serial.ParseFloat() for integers, too, and it will cover both data types.

Program to use the serial terminal as a calculator to demonstrate the above (which may have typos!)
http://www.hackster.io/rayburne/scientific-calculator
or Don't Cross The Streams (FP scientific calculator serial co-processor) - Exhibition / Gallery - Arduino Forum
or http://www.instructables.com/id/Arduino-Scientific-Calculator/?ALLSTEPS

Good luck,

Ray

thank you so much for this info :smiley: