Distance Sensor HC-SR04 to Arduino to IMP to COSM - Formatting Data Issues

Hi,

I have successfully got serial data from an ardunio and HC-SR04 distance meter running into COSM.

The issue I’m facing is when I check the ‘server log’ in the ‘code’ window, I see the following data. My computer serial monitor retuurns the correct serial values with proper formatting, however when I check the ‘server log’ in the ‘code’ window, I see this;

4/26/2013 2:15:14 AM: 2
4/26/2013 2:15:14 AM: 7
4/26/2013 2:15:14 AM: 6
4/26/2013 2:15:14 AM: 2
4/26/2013 2:15:14 AM: 7
4/26/2013 2:15:14 AM: 6
4/26/2013 2:15:15 AM: 2
4/26/2013 2:15:15 AM: 7
4/26/2013 2:15:15 AM: 5

When what I would like to be seeing is; (copied from Arduino IDE serial monitor);
Note:

276
276
276
276
277
276
276
277
276
286

What’s strange however is that the ‘Show Input’ node in the planner (which is linked to the correct output node) is returning values of;

50
54
55
53
54
55

These values are then being sent to COSM.

When I put my hand over the ultrasonic sensor the ‘Show Input Values’ drop to values like these;

43
47
45
42

The IMP code I’m using is listed in this tutorial. https://www.sparkfun.com/tutorials/397

Any hints as to what I should modify?
How can I format the data appropriately.
I.e 11234 instead of
1
1
2
3
4

For reference, my ultimate goal is to have, as realtime as possible, a live stream of distance data feeding into COSM and then read by Max/Msp. I’f I can get the formatting right, then everything else is a doddle.

Many thanks.

You’re logging each individual character. You need to format them into strings (an array of characters). I’m assuming there is a delimiter you can look for. You may also need tointeger() after you’ve created the string.

As each character arrives, stuff it into the array. When the delimiter is detected, print it, and if want to process it as a number rather than a string, use tointeger().

To find your delimiter, you may need to format("%02x",ch), since it may be a non-printable character.

And,

50 dec = 32 hex = ascii 2
54 dec = 36 hex = ascii 6
55 dec = 37 hex = ascii 7

Thanks sjm,

I will give this a try.