Comm to Arduino

I’m building a GUI for an Arduino project I have. The GUI has some switches and sliders. My question is, What is a good method to ID which control is communicating to the Arduino at anyone time. For example suppose there is a couple of switches and a couple of slider controls. How can I tell the Arduino that a slider value #1 is coming rather than #2 slider? Must I first send some sort of control ID followed by the value? Or is there a better way? Thanks Mike

Hi @mike_z (again). I think you already have working program in the Arduino, so you can’t use Firmata which is the easiest way to make the Arduino into i.o. slave for Processing. The next choice is whether to use text values, strings e.g “27”, or binary values. I suggest using text until you want bulk data very fast. Using strings means you can see exactly what’s going on with console messages or serial monitor. I suggest you start with the serial example Examples, Serial, Simplewrite and then expand it to use longer strings. The protocol I use is a message “*AB xxx,” AB is any 2 chars, xxx is any number of digits and the comma is a terminator. (copied it from somewhere, can’t remember). A “.” would seem better than “,” but I thought I might want to use floating point sometime, not yet. Others seem to use a line of text terminated with newline “\n” combined with readUntil. Lots of useful info here.

There are lots of topics where Processing or Arduino get stuck, waiting for the other. Both must be able to continue with or without the arriving messages, and neither must send too much to the other. Tolerating reconnect is another discussion.

Thanks for responding. That is kinda what I was thinking. I’m leaning toward using strings. For example SW1, SW2 and SLDR1, SLDR2. I will need a routine that will grab character by character to build the string and stop when the terminator is found, ( Is the terminator CRLF?). The SW’s will just toggle a condition in the Arduino code, but the SLDR’s will have to wait for a number to pass to the Arduino. I’m hoping a CASE can be used to determine which string was sent and then if a slider was selected, wait for the value next. There should be no trouble getting confused. I think the value can be sent nearly immediately after the command string. Thanks. Mike
PS, my coding skills are rather ancient, I have just started to code again since I retired. I have some preconceived notions that seem to get in the way of the new thinking. Thanks for the help.

Yes, agree mostly. I use a terminator on the value not the message. In my code the arrived string keeps growing as chars arrive. The next part looks to see if it recognises anything, if so uses it and removes what it’s used (actually moves the pointer along).

I’m a lot anti toggling, learned from the industry at work. If you have toggle buttons on control-room screens the operator may accidentally push it twice. Or the system is slow and he doesn’t see the action instantly so he pushes again. IMO better to have buttons and messages for open/close.