Timeline for How to send non char variables over serial
Current License: CC BY-SA 4.0
10 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Dec 17, 2021 at 18:12 | comment | added | Zhelyazko Grudov | Thank you very much for taking the time to respond again Edgar. I really, really appreciate it. | |
| Dec 17, 2021 at 14:59 | comment | added | Edgar Bonet |
@ZhelyazkoGrudov: Your Processing code is sending an escape character (ASCII code 127) instead of "127". The Arduino expects an ASCII string: try sending '1', then '2', then '7'. I don't know Processing, but it is more than likely that it has a method similar to Arduino's print() that would format a number in ASCII for you. You may then write something like serialConnection.serialPort.print(127);. I don't know the exact name of the method. If you have to ask, look for some forum relevant to Processing (not here).
|
|
| Dec 17, 2021 at 14:32 | comment | added | Zhelyazko Grudov | Sorry to bother you again Edgar, I run into the "could not parse value" error, even though from what I understand I'm sending the data in the correct format. I edited the question to include the processing code I'm using. | |
| Dec 17, 2021 at 12:41 | comment | added | Zhelyazko Grudov | Great to know! Thank you for the explanation. | |
| Dec 17, 2021 at 12:34 | comment | added | Edgar Bonet |
@ZhelyazkoGrudov: Re “If I understand what's happening correctly, you're passing by address the buffer array”: Exactly. Whenever you pass an array to a function in C or C++, it “decays” to a pointer to its first element. This “decay to pointer” behavior is generic: it affects all arrays whenever you do mostly anything with them. The str*() functions all expect a pointer to the first element of a NUL-terminated array of char. What is specific about them is that they interpret the first null char they find as the end of the string.
|
|
| Dec 17, 2021 at 11:42 | comment | added | Zhelyazko Grudov | Finally, I love how elegant this code is, lots to learn here! | |
| Dec 17, 2021 at 11:33 | comment | added | Zhelyazko Grudov | Also these functions have double pointers. That's crazy. | |
| Dec 17, 2021 at 11:33 | comment | added | Zhelyazko Grudov | Thank you for the answer, Edgar! Sorry for the delay in responding, wanted to go through everything. I really appreciate the code example. Also, didn't even know these functions existed. If I understand what's happening correctly, you're passing by address the buffer array to the process function, which dereferences it, and is then fed into the str functions? What confuses me is, it looks like the process function takes a single char as argument, but it actually processes the whole buffer array. Is that normal C behavior when using pointers to arrays, or is specific to the str.. functions? | |
| Dec 17, 2021 at 11:33 | vote | accept | Zhelyazko Grudov | ||
| Dec 16, 2021 at 20:53 | history | answered | Edgar Bonet | CC BY-SA 4.0 |