Hi. I've 2 arduinos (nano and Leonardo) connected with mySerial. Here is the code from the first one (sends values). The values are read with Wire and then stored in the variable c[X]. "c" has position 0 to 9 so 10 positions. Each c[X] position is a byte (stores numbers from 0 to 255). Then, the variable c is sent to the second arduino using mySerial.
void loop() {
Wire.requestFrom(4,10); //RECIBIR INFORMACION DEL CONTROLADOR
while(Wire.available()){
for(i=0;i<=9;i++){
c[i] = Wire.read(); //GUARDAR LECTURA EN VARIABLE C
Serial.println(c[i],DEC); //MOSTRAR LECTURA EN MONITOR SERIAL (A DECIMAL)
}}
Serial.print("\n");
mySerial.write(c,10);
}
I receive correctly the values of the variable "numero" but I only want the values that are in the c[2],c[3],c[4],c[5] from the first arduino. How can I store only this positions?
Welcome to the Forum. Please read the two posts at the top of this Forum by Nick Gammon on guidelines for posting here, especially the use of code tags which make the code looklike thiswhen posting source code files. Also, before posting the code, use Ctrl-T in the IDE to reformat the code in a standard format, which makes it easier for us to read.
If you have already posted without using code tags, open your message and select "modify" from the pull down menu labelled, "More", at the lower left corner of the message. Highlight your code by selecting it (it turns blue), and then click on the "</>" icon at the upper left hand corner. Click on the "Save" button.
When you have it open, you should be able to see the italics tags and remove them. Or just delete and copy directly from your program source.
I think now is correct. My program is working but when I am storing each C[x] value it appears without order. I mean C[0] for example in write appears as C[4] when read. How can I syncronize it???
I mean C[0] for example in write appears as C[4] when read
Not if your code is correct.
One thing you need to understand is that serial data is NOT guaranteed to be delivered. The process follows the United States Post Office policy, where the guarantee only to try, not to succeed.
You MUST be prepared to deal with data loss, which generally means not sending binary data over the serial port.