How to Master Raspi receive FLOAT value from Arduino Slave
339 views
Skip to first unread message
Pham Dinh
unread,
Jul 5, 2016, 7:15:55 AM7/5/16
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Quick2Wire Users
Dear all,
I am using quick2wire library to communicate between Raspi B+ (Master) with Arduino (Slave). Arduino read value Temp/HUM from DHT22 sensor and send to Raspi. I want to send float data. Could you please, help me how can Raspi receive float data from Arduino. Here the code from Arduino:
So you need to write a python-side equivalent of I2C_readAnything to
convert the bytes sent over i2c back into a float value.
https://docs.python.org/2/library/struct.html might help you with
that.
Other approaches would be to convert the float into an integer, by
multiplying it by some suitable multiplier (e.g. 10 or 100) and then
sending and reading the integer value to python, and then dividing (by
10 or 100) to get back to a floating-point number. Or you could
convert the float to a string by using sprintf, and then send the
string bytes over i2c, and assembling the individual bytes back into a
string on the python side.
BTW I wouldn't recommend using the quick2wire code for anything (no
matter which approach you end up going with) - it's effectively an
abandoned dead-end (it's had no updates in over 3 years!).
https://duckduckgo.com/?q=python+smbus+raspberry+pi seems like a much
better-supported alternative.
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Quick2Wire Users
Dear Andrew Scheller,
Yes, I am using library of Nick Gammon edited by Chuck Todd. I use value temperature of DHT for my goal is send float value via I2C. Arduino to arduino is ok with I2C_anything library. I want to try Arduino to Raspberry. With beginner Python i need few days to try your recommended.
I appreciated your reply. Thank you for your consider.