
stevehaze

Hi,
I've been using the following tutorial and code to get data from an Arduino for a battery of sensors...
>> Using Arduino as Encoder
One of my sensors is a Barometer and is sending the pressure....but the value falls outside of the 255 that this tutorial seems to accept.
The number for the pressure on my arduino is a float of currently 998.10 - but I don't mind losing the decimal and just having an integer.
Could one of you kind folks give me some advice on what script / command I can use to read this number?
Thanks
Steve Haze
a float, or an int, or a decimal, or a short, etc... all consist of many bytes.
so an int16 is 2 bytes
an int32 is 4 bytes
a long (int64) is 8 bytes
the bytes are assembled together using bitwise operators to recreate the original intended value.
I don’t know what’s compatible with a float between windows an Arduino, since floats are considerably platform dependent. An int16, however, is easy
you’ll need to send your in on the Arduino as two bytes
and receive it on the ezb or what ever the receiver is, as two bytes
(i don't use ezscript anymore :))
First, initialize your hardware UART...
Code:
Now, send your data from the Arduino...
Code:
Code:
Code:
but, JavaScript is more powerful and faster
oh, the new roomba plugin I just finished reads sensor data. And has variable turning and such. It’s real great. I’ll publish it this week with the new arc.
Cheers
Time to buy JavaScript for Dummies then?
Assuming I do switch to JavaScript....Is there a similar ControlCommand function in JavaScript to control the other plugins?
So with that code.... (DJ's code)...sending the number 1021....the code gives me the value 65021 at the end.
*scratches head confused*
so like, on the sender. Change the order to be...
Serial.write(value & 0xFF00 >> 8);
Serial.write(value & 0x00FF);
SO....
I did some googling and learning and this is what worked for me for sending the Float...SORT OF.....
I'm cheating a bit....but for the 1 decimal place that I need for this sensor reading, I'm happy.
(PS: I know the Ezb could poll this particular sensor itself...but my arduino is handling all my sensors and then sending to Ezb.)
On the Arduino...
Code:
Then in ARC....JavaScript (modified from what DJ Sures posted)....
Code:
Thank you so much DJ for your ALWAYS quick replies and sharing of knowledge.
If that range is acceptable for your application, it's golden :). Otherwise, use a signed Int 32 (4 bytes)
I had the arduino variable that's being sent as a Long and the following...
Code:
I'm only just learning about shifting...
So I'm guessing after receiving 4 bytes and not 2....the Javascript line here would need to be different.....but I'm not sure how. Can you advise?
Code:
On the Arduino...
Code:
Then in ARC....JavaScript (modified from what DJ Sures posted)....
Code:
I'm getting 'int32' was not declared in this scope but if I use LONG then it works.
Namaste!