Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 3552

Automation, sensing and robotics • Re: Using a ds18b20 on pins 27-40

$
0
0
Over 1000 views with no response? Fortunately I'm pretty good at figuring stuff out myself. So to answer my own question, yes it works and no I didn't fry my pi.

In case anyone else wants to know how to reconfigure the gpio pins for a one wire connection, here is what I did.

1. Add one wire functionality with the following command:

sudo raspi-config. Select option 3, interface option. Select I7, enable one-wire interface. Select yes to enable one-wire. Select finish and save. Reboot.

This will add one line to the end of config.txt in /boot with the following:

dtoverlay=w1-gpio,gpiopin=4

Gpio4 is the default control pin for the one-wire interface but I couldn't use that due to a screen device already using gpiopin 4.

2. Use the built-in gpio python library to reconfigure the power pin. Should come preinstalled on your pi but if not use pip install gpiozero to install it. For my application, I decided to use pin 39 for ground, pin 37 for signal, and pin 36 for power(3.3v). These are the physical pin numbers but you will need to use the gpio pin # with the command in the boot file and the physical pin # with the python gpio lib commands. Here is a good page with all of that info.

https://randomnerdtutorials.com/raspber ... out-gpios/

So the signal pin is gpio26 and the power pin is gpio16. For the signal pin, go to the last line in the config.txt file in /boot and change that value to the new pin using the gpio pin #. I changed gpiopin=4 to gpiopin=26.

Lastly, you need to run the following to reconfigure a gpio pin to be a 3.3v power pin. Here are the commands I used in a script to do that. For these commands you will be using the physical pin position, not the gpio pin #. The setwarnings line is optional but I added it to suppress output when running my script.

import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(36, GPIO.OUT, initial = GPIO.HIGH)

No changes are required for the ground pin.

3. Verify it works. Turn off your pi, hook up the wires, boot up. For the ds18b20 waterproof sensor I am using, I cd'd to /sys/bus/w1/devices and listed the contents. You should see a new device starting with 28-, like this. That is the ds18b20 sensor.

lrwxrwxrwx 1 root root 0 Jan 16 18:35 28-0b23571ea723 -> ../../../devices/w1_bus_master1/28-0b23571ea723
lrwxrwxrwx 1 root root 0 Jan 16 18:34 w1_bus_master1 -> ../../../devices/w1_bus_master1

To get data from the sensor there is a cool script on the following page that works well.

https://randomnerdtutorials.com/raspber ... 20-python/

Statistics: Posted by petebvbc — Wed Jan 17, 2024 6:33 am



Viewing all articles
Browse latest Browse all 3552

Trending Articles