I recently fell victim to the perils of my own laziness. Rather than gracefully shut down my Raspberry Pi in order to move it, I pulled the power cord. I had done this dozens of times in the past with no ill-effects but today was my unlucky day. The Pi did not come back!
Unfortunately, this snowballed from a simple file corruption issue into a full reinstall, which ended up using a different kernel version that broke my custom 1-wire bus setup. Great.
To find out what happened to the Pi, I needed to hook it up to composite video. Not even HDMI was running. There were a bunch of messages about kernel panics and unable to mount the root filesystem. That is enough of a clue in itself, but as a post-mortem I plugged the micro-SD card into my PC and ran fsck on it using a linux VM. There were a lot of errors. Rather than try and recover this I copied the SD card contents into a directory on the VM (as a backup) and then reimaged the SD card using a fresh Raspbian image.
Repeating the steps from Adafruit’s LCD guide I had my LCD working relatively quickly. I also remembered I had already written an article about the DS18B20. Great, I’ll just follow that! However, the Python script failed trying to read my DS18B20’s temperature. It didn’t see the DS18B20 at all.
Since I had the Adafruit LCD plate taking up the main GPIO header, I had remapped my 1-Wire pin to use the P5 header as this made wiring in a temperature sensor a lot neater. However, I found that the module was still loading with the default GPIO pin instead of my custom one:
root@rpi:~# dmesg | grep w1 [ 5.617317] w1-gpio onewire@0: gpio pin 4, external pullup pin -1, parasitic power 0
The new Raspbian image is now a 3.18 kernel, and it has changed the way it supports the RPi peripherals. I found this forum post on the RPi forums that discusses this. The 1-Wire bus now uses device trees, and the way you reconfigure the GPIO pins has changed.
My /boot/config.txt file now has the following in it:
#Add 1-wire support dtoverlay=w1-gpio,gpiopin=31
And my /etc/modules has the same information as before:
#Enable GPIO on pin 31 (P5 header) for DS18B20 w1-gpio w1-gpio-custom bus0=0,31,0 w1-therm
rebooting now shows the 1-wire bus has moved to pin 31:
root@rpi:~# dmesg | grep w1 [ 5.617317] w1-gpio onewire@0: gpio pin 31, external pullup pin -1, parasitic power 0 [ 5.801345] w1_add_master_device: set_pullup requires write_byte or touch_bit, disabling
..and I’m getting temperatures again!
Serves me right for being lazy. Next step is to make one of the LCD plate buttons perform a graceful shutdown. I can then easily move my Pi without having to SSH into it.
11,037 total views, 1 views today