asapp / one_wire

ruby One Wire binding using w1-gpio linux module.
MIT License
3 stars 2 forks source link

Unable to reach the sensor value #1

Closed Damaotimlin closed 8 years ago

Damaotimlin commented 8 years ago

Do I need to put require 'sysfs_one_wire' into my rb code for OneWire to work ?

I'm sorry, I have no idea about how to use this gem... please gives me some examples, thanks!!

elmatou commented 8 years ago

Hi, It works as any gem. You 'require' it in your code or you use bundler for it. On Mar 13, 2016 8:20 AM, "Damao Tim Lin" notifications@github.com wrote:

Do I need to put require 'sysfs_one_wire' into my rb code for OneWire to work ?

I'm sorry, I have no idea about how to use this gem... please gives me some examples, thanks!!

— Reply to this email directly or view it on GitHub https://github.com/asapp/one_wire/issues/1.

Damaotimlin commented 8 years ago

Hi @elmatou I couldn't get the value from Thermometer Below is my code, can you help me to take a look ?

OneWire.load('/sys/bus/w1/devices/28-031581efbaff')
current_soil_temp = OneWire::Thermometer.new.last_value

puts "value = #{OneWire::Thermometer.new.last_value}"

value = There are no data been called.

I checked the sensor and it works fine :

pi@cvproto01:/sys/bus/w1/devices/28-031581efbaff $ cat w1_slave 62 01 4b 46 7f ff 0c 10 92 : crc=92 YES 62 01 4b 46 7f ff 0c 10 92 t=22125

Below is how the OneWire output after OneWire.load('/sys/bus/w1/devices/28-031581efbaff')

OneWire.slaves ["/sys/bus/w1/devices/28-031581efbaff"]; OneWire.devices [# OneWire::Thermometer:0x1778eb0 @path="/sys/bus/w1/devices/28-031581efbaff"]

Please advise how to reach the value, thanks!!!

elmatou commented 8 years ago

Ok, with OneWire.devices we can see your sensor is well recognized. You have to get the Thermometer object, with :

soil_sensor = OneWire.devices.first
# or 
soil_sensor = OneWire.load('/sys/bus/w1/devices/28-031581efbaff')

then you have access to some methods such as :

current_soil_temp = soil_sensor.value                  # current temperature in °C
soil_sensor.last_value          # last checked temperature, return nil if you didn't called value before
soil_sensor.id                       # 1wire device uniqe id
soil_sensor.name                 # device uniqe name
soil_sensor.w1_slave           # return the w1_slave file, as in 'cat'
soil_sensor.dump                 # return an array which can be stored in database for later loading

I'll add it to the readme for easier usage. clear enough ?

Damaotimlin commented 8 years ago

It works very very good! Thanks!!!!! @elmatou

By the way, I want to contribute to this project for extend it to other sensors, what can I do for give a hand ?

elmatou commented 8 years ago

Nice ! Of course you can contribute. As I only have a DS18B20 in my project I cannot test with other devices/sensor.

It would be very helpful to have the "dump" of cat w1_slave of other sensors you have by you. Or some intel on any other device (eprom, ibutton, switch) you can have a hand on.

Damaotimlin commented 8 years ago

@elmatou I trying to test soil moisture, by using capacitor not resistance. Do you have any recommendation sensor or maybe diy one ?

And also I looking forward to add some water flow sensors, https://www.adafruit.com/products/828 Not sure how to read the data, do you have any thoughts ? I thinking to try 2 bit counter but not sure if it works. Still learning....

elmatou commented 8 years ago

I'm not familiar with the device... maybe you can get the pulse with PiPiper. maybe you should optoisolate the pulse signal to protect the raspi...