Photon - Arduino communication

Hi guys, I was wondering what would be the best way to send a lot of variable and maybe if possible function from a Photon to an Arduino Mega or Uno.
If I’m right with the serial communication you always need to have the variable in the same order, and you can’t send value bigger than 255.
I have seen yesterday that maybe Master/Slave communication could be an other option.

So, what do you think would be the more flexible and faster way to send data.

Thanks !

There are several ways, but in all of them both sides have to know the order in which the information is passed from one to the other, in order to make sense of it.
And all of these ways the maximum value for a byte will be 255, but there is virtually no limit to the number of bytes you exchange.

But I don’t quite understand what you mean here

Well I don’t know how much it would slow down the communication, but for exemple if you send the name and the value of a variable, the variable doesn’t necessarily need to be in the same order every time (like JSON).

What can I do if I want to send exemple 3000 to an arduino ?

Well I mean more like sending a char array (witch would contain a piece of code that I want the arduino to run I some point in the loop) to the arduino.
More clear ?

It depends very much on your protocol how much or little time you’ll need for your communication (how much overhead).

But you can easily calculate the required time.
e.g. with a 9600 baud serial you could consider each byte as roughly 10bit (including start and stop bit), so you could transport roughly 1kB/s.
If you introduce overhead (e.g. numbers as string instead of binary, you will need at least six byte to transport 65535\0 instead of only two - and going for JSON even more).

You could send some “function” code via serial, but on the other side you’ll need a parser/interpreter, since your Arduino won’t be able to compile the function to run it.

Okay, but witch method you think would be the best ? UART, SPI or I2C ?

If it’s not timing-sensitive (like microsecond-sensitive), UART may be the easiest way to go.

I did a quick write-up on it a while back:

1 Like

I’d agree with @wgbartley the most straight forward and easiest to understand and debug.
And from the fact that you asked this question, I’d get the idea that these might be important factors in this decission.

From there you can gradually move forward - e.g. incorporate CTS/RTS-like handshaking, …

Perfect Thanks I’ll go forward with serial and see how it goes !