We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm looking to send some integers from Processing to Arduino. One set will be 0 to 359, the other numbers will be a max of of 10,000. Once working the Arduino doesn't need to respond, but for testing wold like to get a confirmation that what I'm sending is getting there.
I have a Serial Object 'motorctl' which will send the numbers to Arduino. I use:
motorctl.write(number);
Then I wait for the reply from Arduio:
if(motorctl.avaiable > 0) { motorCtlMsg = motorctl.readStringUntil('\n); }
I'm not sure if the readStringUntil... is the right option to use - and in the reference I haven't found an example explicitly for sending numbers. It would seem with the above I'd have to convert that String to an int. So far all I get is 0, no matter what I send from Ard.
On the Arduino side, I'm using: if (Serial.available()) { string Msg = Serial.readStringUntil('\n'); } and when something is received i send a reply via println statement which shows in the processing consol. Currently I'm sending a number: Serial.println(250); - but processing gets a 0. In all cases.
I've got the link set up ok - just need some help with the correct usage of the Serial functions.
Answers
https://processing.org/reference/libraries/serial/Serial_write_.html
I don't think sending out a number type some
\n
would be appended to its end.Perhaps you should convert it to String before sending it out:
https://processing.org/reference/strconvert_.html
Although it doesn't necessarily mean an
\n
would be automatically appended as well.If it doesn't, append it yourself:
motorctl.write(number + "\n");
Thanks - I'll give that a go.