Skip to content

Instantly share code, notes, and snippets.

@aguegu
Created November 5, 2013 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aguegu/7321376 to your computer and use it in GitHub Desktop.
Save aguegu/7321376 to your computer and use it in GitHub Desktop.
get temperature from ds18b20 on RPi in Bash
#!/bin/bash
modprobe w1-gpio
modprobe w1-therm
if [ -d /sys/bus/w1/devices ]; then
id=$(ls /sys/bus/w1/devices/ | head -n 1);
temperature=$(tail -n 1 /sys/bus/w1/devices/$id/driver/$id/w1_slave | grep -o "[-0-9]*$")
echo "scale=3;" $temperature "/ 1000.0" | bc
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment