arduino to arduino serial connection.


I succesfully Serial.connected an uno and a mega so that I could control a servo motor on the uno with the potentiometer on the mega. Thas was suprisingly easy. But now I attempt to control 2 servos via 1 potentiometer and switching the input wire, as I only got 1 potentionmeter, I tried everything.

Now with only 1 potentiometer I can control both servos at the same time. so I don’t think my array is getting throuh as it supposed to be. The end goal is that I can send 5 integers from one arduino to another, via the serial connection.

Later I want to do the same over I2C and SPI connections.

I also got an esplora, and what is it useless. It cannot make an I2C nor Serial connection with an other device, leaving only the SPI connection. And for that device I am doing it for.

Serial.write() with one argument just sends one byte. To send an array of bytes you have to use the two argument version of it, the second argument is the length of the array.

BTW: don't post code by making a screen shot of it. Post it directly using code tags.

last night I came with a solution and this morning it was the first thing I did. In the slave code I put a while loop: while( serial.avaible < 1) {}. this makes the code waiting until it receives something. the slave does this 2 times in a for loop, because i want two numbers. The master sends now both the integers every millisecond, whether these integers come as a 2 byte or 1 byte, it does not matter because the value does not exceed 255. In the slave I put these values into an integer array, and well be damned it actually works. I think I should try this with a number bigger than 255 and see what happens ^^.