arduino and PWM outputs

Jan 15, 2009 at 1:17am

arduino and PWM outputs

Hi all,
I need some guidance from some Adruino gurus here. I am trying to both read sensor data from the inputs and send data to control the PWM outputs at the same time on my little Arduino Pro mini. Reading is straightforward…I am simply send it an ‘r’ to read the data, and the arduino graciously sends me back the data I need. For output, I’m sending it a ‘w’ followed by pin # and value (0-255) for that pin. My little program on the arduino recognizes the ‘w’, but can’t seem to parse the values that come after it. For example, in max I’ll send the message ‘w 6 123′, which after converting to ints becomes “119 32 54 32 49 50 51″, which is the message that is sent to the arduino (via serial object). My arduino code sees 119 = w just fine, but can’t make any sense out of numbers that follow. Clearly I’m doing something wrong on the other end … perhaps an “itoa” on the Arduino side? I’m scouring the arduino forum in the meantime, too, but wanted to check here first since all the control happens in Max.

Thanks in advance for any advice.

Cheers,
David

#41689
Jan 16, 2009 at 7:38pm

Quote: David Beaudry wrote on Wed, 14 January 2009 19:17
—————————————————-
> Hi all,
> I need some guidance from some Adruino gurus here. I am trying to both read sensor data from the inputs and send data to control the PWM outputs at the same time on my little Arduino Pro mini. Reading is straightforward…I am simply send it an ‘r’ to read the data, and the arduino graciously sends me back the data I need. For output, I’m sending it a ‘w’ followed by pin # and value (0-255) for that pin. My little program on the arduino recognizes the ‘w’, but can’t seem to parse the values that come after it. For example, in max I’ll send the message ‘w 6 123′, which after converting to ints becomes “119 32 54 32 49 50 51″, which is the message that is sent to the arduino (via serial object). My arduino code sees 119 = w just fine, but can’t make any sense out of numbers that follow. Clearly I’m doing something wrong on the other end … perhaps an “itoa” on the Arduino side? I’m scouring the arduino forum in the meantime, too, but wanted to check here first since all the control happens in Max.
>
> Thanks in advance for any advice.
>
> Cheers,
> David
—————————————————-

I recall struggling with this. Some combination of itoa or atoi on the Max side and using “BYTE” in the Arduino code worked, though I think I was sending things the other way. So, use serialRead(x, BYTE)* to describe the kind of formatting you want the code to use. You might need to filter the 32 (spaces) and/or any 13 or 10 (CR/LF) too.

*not totally sure about the exact formatting or function name, but you get the idea.

#148585
Jan 16, 2009 at 8:17pm

Hey Seejay,
Thanks for you help. I had a bit of a breakthru last night and was getting ready to report back. On the max side I ended up converting only the “a” or “w” or whatever to an int, but left the rest of the numbers as is since my max value to the arduino was 255 (e.g. sending “6 123″ vs. “119 32 54 32 49 50 51″, and then reading everything on the arduino side as an int. I also added a header ($) and footer (carriage return) to make sure I was reading from the beginning of the message, which helped quiet a bit. The other thing that proved to be a big factor was the baud rate. I was using 115200 but saw that the values reaching the adruino were pretty inconsistent. Switching to 57600 made life much happier. This, btw, was with an Arduino Pro Mini…a pretty amazing little digitizer.

Thanks again for your input!

Best,
David

#148586

You must be logged in to reply to this topic.