I’m working on my first nerves project. (I got a Raspberry Pi 3 for Christmas. ) The project is mainly working but I’m having trouble with the DHT11 sensor. These ones specifically: Amazon.com I’ve been following this: Elixir Nerves for measuring temperature from a DS18B20 sensor on a Raspberry Pi · Carsten's Blog to see how to setup the project. I’ve tried a lot of different pins for the wiring and data out line. I never get a file that starts with 28- The closest is 00-. And they are in /sys/bus/w1/devices/
For wiring I have + to pin 1, gnd to pin 6 and data to pin 7 on the gpio connector.
Nice! It’s fun but getting past the initial hardware setup can be a bit tricky. Unfortunately some sensors use custom protocols and require more precise timing than is easy to get in linux. 1Wire is built into the Linux kernel so it works well. However, the DHTxx sensor seem to use their own custom protocol according to a tutorial for one here.
It’s not clear if the DHT11 is able to be used with 1wire or not, but if not you’d have to try and port the Arduino library or Adafruit Python library to Elixir using Circtuis.GPIO. However, Adafruit deprecated their Python library on Linux. Arduino’s have more consistent timing so it’s easier to interface to these custom data protocols. Nerves relies on Linux which has much less precise timing for “custom bitbanging” protocols unless you write custom c code or better a Linux kernel module .
My suggestion would be to switch to an I2C or SPI based temp sensor (or I2C adc wired up to an analog temp sensor). There are a few on Amazon like Adafruit MCP9808 or the BME280. The BME280 part also includes barometric pressure! They also both likely have higher precision temperature than the DHT11.
If you are interested in an inexpensive sensor that works well with Nerves, I wrote an Elixir library to interface with the Bosch BME680 (that measures humidity, temperature, pressure, and gas resistance, correlated to air quality):
Looking at the source for nerves_dht it only supports Raspberry Pi and Pi 2 and is based on a deprecated library. I have a Raspberry Pi 3 B. It might work, but I may have to add Raspberry Pi 3 support.
I may give a BME680 a try since I’m not willing to invest a lot of time on a deprecated library to make a $10 part work. Or maybe I’ll try to get a BME280 to work. I’ll have to have a look at the code for https://github.com/lucaong/elixir_bme680.
Thanks for all the help and pointers guys. This really helpful. I won’t be able to do much for a while. Heading out on a business trip tomorrow.
believe nerves_dht should just work on any rpi… but for numerous reasons it might be better going with a bme* - was more if you just wanted to get going instead of waiting for parts…
That’s really amazing @baldmountain ! Thanks for your PR! Tomorrow I will have a look at it and merge it I am waiting for a BME280 so I will be able to test it too
I merged your pull request and released version 0.2.0 with support for the BME280. In a few days I will receive a BME280 in addition to my BME680 so I’ll be able to maintain it and test it. Thanks again!