2015-03-15

Raspberry Pi Camera Module and 1-Wire

I had a small project for my kids, to create a timelapse video of growing plants. So I bought a Camera Module for my Raspberry Pi, and let it take a snapshot every 15 minutes. So far so good.

Then came the idea to also record the temperature as well. At first I thought 'no problem', I had a DS18B20 digital temperature sensor lying around. Simply attaching pin 3 to GPIO pin 1 (3.3V), pin 1 to GPIO pin 6 (GND), and pin 2 to GPIO pin 7 (GPIO4), and then a pull-up resistor 4.7K Ohm between pin 2 and 3 (See the Adafruit lesson for the details).

And then...

...Nothing

Hmmm, maybe the sensor is broken. Let's try another one.

And then...

...Still nothing

After a lot of Googling, I discovered that the Camera Module uses GPIO 4 somehow which conflicts with the 1-Wire module, which uses GPIO 4 by default. So the fix for this is to let the 1-Wire module use a different GPIO pin. E.g. pin 18. This can easily be configured by adding the following to /boot/config.txt:

dtoverlay=w1-gpio-pullup,gpiopin=18

(See https://github.com/raspberrypi/firmware/tree/master/boot/overlays).

After this, both the DS18B20 worked fine, as well as the camera module.