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?

  • How have you connected the DS18B20? Which modules have you loaded to read the sensor?
    – joan
    Oct 22, 2014 at 11:42
  • The connections seem to be correct. wiringPi has a pintest program which should be in the installation directory somewhere. pigpio has a similar gpio test script. DISCONNECT everything from the gpios for these tests.
    – joan
    Oct 22, 2014 at 16:55

3 Answers 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:


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

  • 1
    I know thanks comments are poo-poo'ed by this did this worked for me. THANKS! I had everything working before, without doing this, but after fiddling with things with the power on, it stopped reading them, and I thought I'd fried my pins. Phew! Sep 29, 2015 at 19:10

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.

  • It is probably better to use an external pull-up to 3V3. I think 4K7 is normally used. The internal pull-ups are quite weak at circa 50K.
    – joan
    Oct 22, 2014 at 16:44
  • I will try this. @joan I have used the external pull up, 4k7 resistor Oct 22, 2014 at 16:52
  • I get this when i try that echo: echo: write error: Device or resource busy as for the diection, i get: -bash: /sys/class/gpio/gpio4/direction: No such file or directory Oct 22, 2014 at 16:53

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
: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 :)

  • 1
    The file to edit is located at /etc/apt/sources.list.d/raspi.list, and the first line should read (after editing) deb http://archive.raspberrypi.org/debian/ wheezy main untested. However, this didn't solve the original issue for me :( Feb 8, 2015 at 22:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.