Author Options:

Export integer from arduino to processing? Answered

How can I take an integer or float value from an arduino, and put it into processing over serial (usb), without changing it to a char or something else?  It needs to be fairly fast (within ~1/8 sec), and be able to be converted to an audio tone.  Also, how can I play an audio tone in processing?  I looked on the reference page, and couldn't find any documentation on just a basic square or sine wave output of variable frequency (except the example, which uses something weird). 

1 Replies

frollard (author)2012-11-09

You can't send a multi-byte number 'as' that number; it takes up multiple bytes in memory so you have to break it down into those bytes and send them. You need your own protocol to encode your numbers then reassemble them on the other end.

You'll need to use bitwise math to break your integer or float into its individual bytes (chars) and send those, then reassemble them on the other side. This can happen in a handful of cpu cycles, less than a millisecond for sure. at 9600 baud (default but very slow) you can get about 1200 bytes per second across, and if you're using a 2 or 4 byte number, you can get many hundreds of them across per second.

Silly question...why don't you make the arduino output the tone itself (since you seem to have your eye on building a theramin).

Select as Best AnswerUndo Best Answer