monteslu / node-red-contrib-gpio

A set of node-red nodes for connecting to johnny-five IO Plugins
MIT License
41 stars 31 forks source link

Reading from a I2C device #2

Closed Harald-U closed 9 years ago

Harald-U commented 9 years ago

On a Raspi running Node-Red I am trying to read a TMP102 Temperature Sensor connected via I2C.

I installed wiringpi and can read the sensor in a shell with: i2cget -y 1 0x48 0x00 w

I then installed raspi-io and node-red-contrib-gpio in Node-RED. I see a gpio input and a gpio output node. In addition I still have three rpi-gpio nodes in the Raspberry Pi section of the Node-RED pallette.

I use a gpio output node, set it to using raspi-io, type I2C Read Request. But then the questions begin: Is the I2C address of the device set in the node or sent as payload? Is it sent as 0x48 or just 48? What do I send to node? In your example I see an inject node ... no matter what I try, I don't see any results in the debug node.

I tried to find more information but couldn't.

Thanks for any help!

This is my little experiment: [{"id":"8713befb.882078","type":"nodebot","name":"","username":"","password":"","boardType":"raspi-io","serialportName":"","connectionType":"local","mqttServer":"","pubTopic":"","subTopic":"","tcpHost":"","tcpPort":"","sparkId":"","sparkToken":"","beanId":"","impId":""},{"id":"f52482cc.67585","type":"inject","name":"","topic":"","payload":"0x48","payloadType":"string","repeat":"","crontab":"","once":false,"x":227.0833282470703,"y":253.08334350585938,"z":"4fe27726.5da9d8","wires":[["6240c18d.f6d168"]]},{"id":"6240c18d.f6d168","type":"gpio out","name":"","state":"I2C_READ_REQUEST","pin":"","i2cDelay":"0","i2cAddress":"","i2cRegister":"0","outputs":1,"board":"8713befb.882078","x":417.08331298828125,"y":255.08334350585938,"z":"4fe27726.5da9d8","wires":[["2d12dfcf.b62588"]]},{"id":"2d12dfcf.b62588","type":"debug","name":"","active":true,"console":"false","complete":"true","x":599.0833282470703,"y":254.0833282470703,"z":"4fe27726.5da9d8","wires":[]}]

monteslu commented 9 years ago

Thanks for reporting this. The readme could definitely use some more documentation around this.

For your example, i think you want to translate 0x48 and use 72 as the value in the gpio node for address. It requires an integer in decimal format.

The payload value you send the node from the inject node is the number of bytes you want to read. I'm not familiar with the TMP-102, but my guess after looking at https://www.sparkfun.com/datasheets/Sensors/Temperature/tmp102.pdf is that we want to ask for 2 bytes.

Give that a shot and let me know if you're getting any response.

[{"id":"8713befb.882078","type":"nodebot","name":"","username":"","password":"","boardType":"raspi-io","serialportName":"","connectionType":"local","mqttServer":"","pubTopic":"","subTopic":"","tcpHost":"","tcpPort":"","sparkId":"","sparkToken":"","beanId":"","impId":""},{"id":"9f2c6379.60d3a","type":"inject","name":"","topic":"","payload":"2","payloadType":"string","repeat":"","crontab":"","once":false,"x":174,"y":237,"z":"e8e4e5c5.171b18","wires":[["c49b5e3e.3b64a"]]},{"id":"c49b5e3e.3b64a","type":"gpio out","name":"","state":"I2C_READ_REQUEST","pin":"","i2cDelay":"0","i2cAddress":"72","i2cRegister":"0","outputs":1,"board":"8713befb.882078","x":363.99998474121094,"y":239,"z":"e8e4e5c5.171b18","wires":[["a81cbf8b.57e34"]]},{"id":"a81cbf8b.57e34","type":"debug","name":"","active":true,"console":"false","complete":"true","x":546,"y":237.99998474121094,"z":"e8e4e5c5.171b18","wires":[]}]
Harald-U commented 9 years ago

Luis, that was it! I am receiving results and they match with i2cget only that they are decimal :-) Thank you so much for your help!

Prashanthikrishnan commented 9 years ago

hello sir, I am using an SHT21 temperature and humidity sensor in a raspberry pi and i am having the same issue?? i am unable to read the temperature data..?? please help me out here

PiroozMB commented 5 years ago

hi @Prashanthikrishnan did you ever manage to solve your issue? i'm trying to get the temperature from my sensor sht21 on rpi via node red but I can't figure it out how to get it on node red. any tips is appreciated. thnx