6

So, basically, I've been trying to get my raspberry pi to get the room temperature from a DS18B20 1-wire temperature sensor.

I've read only GPIO 4 is capable of this, and I think for some reason GPIO 4 is not working.

I've tried connecting the sensor there, it is connected as it should, I've been checking the connections since I connected the sensor and couldn't read it...

I've tried connecting an led (using the proper resitor) to GPIO 4 and using wiringpi to turn it on and off, but I got nothing...

My question is, is there a way I can know for sure if the pin is okay and it is just some software issue?

NOTE: I don't really know how this is supposed to work, but when I do:

~ $ cd /sys/class/gpio
~ $ ls

What I get is:

export  gpio17  gpio18  gpio21  gpio22  gpio23  gpio24  gpio25  gpiochip0  unexport

The GPIO 4 doesn't show up... Now, I don't know if only the pins in use show, but if that's the case, none of the above should show, because i'm not using any pins right now...

EDIT: I have connected the DS18B20 like it says in the datasheet, like in this picture: DS18B20 Pinout

For the modules I have loaded:

modprobe w1-gpio
modprobe w1-therm

Superuser privileges, obviously.

I also tried:

modprobe w1-gpio pullup=1
modprobe w1-therm super_pullup=1

When I try:

sudo echo "4" > /sys/class/gpio/export

I get:

echo: write error: Device or resource busy

Just tried the pigpio test program and the results are:

Skipped non-user gpios: 0 1 28 29 30 31 
Tested user gpios: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 
Failed user gpios: None

I assume it is supposed to skip those non-user pins, right? Other than that I have no doubts about all the pins working... Which intrigues me, because I still can't read temperature...

I'm at work, I will take the pi home and test it there again with a simple LED turning on and OFF, if I discover anything, I will post it here...

I've been experimenting a lot with the pi, it is probably cluttered with stuff I wanted to test but never really used, do you think it would be wise to try a fresh Raspbian install?

Ghanima
  • 15,958
  • 17
  • 65
  • 125
Antero Duarte
  • 171
  • 1
  • 2
  • 12

3 Answers3

3

I had the same problem when working on a friend's model-B pi. We tried simply turning on an LED with GPIO 4 as you did and nothing happened. Fortunately, we found a solution here.

We ended up having to edit the /boot/config.txt file and added the line at the bottom of it:

dtoverlay=w1-gpio,gpiopin=4

Then rebooted, and were able to find the sensor and read from it. Hope this helps!

Ghanima
  • 15,958
  • 17
  • 65
  • 125
tdan1101
  • 31
  • 2
1

I guess you have loaded the kernel modules for 1-wire: sudo modprobe w1-gpio pullup=1 and sudo modprobe w1-therm.

GPIO4 should show up if you export that pin: echo β€œ4” > /sys/class/gpio/export and echo β€œin” > /sys/class/gpio/gpio4/direction.

Path to 1-wire data is something like /sys/bus/w1/devices/xx-xxxxxxxxxx/w1_slave.

user236012
  • 670
  • 5
  • 10
1

Problem solved.

I found online that I had to change the raspi.list file to read "deb http://archive.raspberrypi.org/debian/ wheezy main untested" and then run apt-get update and apt-get upgrade.

Then running:

sudo modprobe w1-gpio
sudo modprobe w1-therm
cd /sys/bus/w1/devices
ls
:devices listed here, serial number should be something started with 28-0000:

After trying this, I was successful and I can read the 3 sensors.

I'm posting this answer as a reference if someone bumps into this question, thank you all for your help anyway :)

Antero Duarte
  • 171
  • 1
  • 2
  • 12