Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

8
  • 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? Commented Dec 17, 2021 at 11:33
  • Also these functions have double pointers. That's crazy. Commented Dec 17, 2021 at 11:33
  • Finally, I love how elegant this code is, lots to learn here! Commented Dec 17, 2021 at 11:42
  • 1
    @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. Commented Dec 17, 2021 at 12:34
  • 1
    @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). Commented Dec 17, 2021 at 14:59