Hell yeah! it worked! After changing it to bcm 4 it showed the correct address and temp.
Finally!
Now, how do I change the default pin, and secondly, how do I connect two sensors if I can’t change the gpio pin by default…
Also, after only two readings, it stops working, not showing more temps, this is my current code:
var W1Temp = require('/usr/local/lib/node_modules/w1temp');
var blynkLib = require('blynk-library');
var AUTH = 'token';
// Setup Blynk (SSL)
var blynk = new blynkLib.Blynk(AUTH);
// Automatically update sensors value every 5 seconds
setInterval(function() {
W1Temp.getSensor('28-051684c0d6ff').then(function (sensor) {
// print actual temperature
var temp = sensor.getTemperature();
console.log('Actual temp:', temp, '°C');
//Report it to server
blynk.virtualWrite(0, temp);
});
}, 5000);
@raul good that you have at least had some readings from the sensor.
We tried with the timed interval and in the end went with the “on change” script. Not ideal but we have additional code to cover the permanently updating temperature readings and formatting to 1 decimal place etc.
I suspect you can change the default pin by making the entry in the file on the SD card and then modprobe. Don’t know if you need to remove the existing “default” but I suspect not.
With these sensors you should be able to wire 10 sensors up to the same pin as they use the chip ID’s. If I were you I would leave it where it is and just wire in the second sensor to the same pin.
Yeah, the easiest way is to connect them in series, as I read in some other projects, the only problem is that I am not sure of the way I should connect them, since one has a built in resistor and the other does not
In fact for Your realization this one build in resistor is sufficient for whole bus. Cause I assume the length is in meters. My bus is like star with resistor on RPi and sensors from one meter to five, If You end Your “serial” bus by second resistor, nothing should happens.
you can also read temperatures from command line to identify sensors:
cat /sys/bus/w1/devices/28-000002da51d5/w1_slave
Or you can use BASH script like this to read whole temperatures:
temperatures()
{
W1DIR="/sys/bus/w1/devices"
#exit if no one wire sensor exists
if [ ! -d $W1DIR ]
then
echo "There is no sensors!"
exit 1
fi
#list of sensors
DEVICES=$(ls $W1DIR)
#Output sting
OUTPUT=""
#cycle across all founded sensors
for DEVICE in $DEVICES
do
#ignor master
if [ $DEVICE != "w1_bus_master1" ]
then
#read sensor
ANSWER=$(cat $W1DIR/$DEVICE/w1_slave)
#Check answer and CRC; because if sensor disapear its address will be 9x00 but CRC will be valid
echo -e "$ANSWER" | grep -e "00 00 00 00 00 00 00 00 00" >&2
if [ $? -ne 0 ]
then
#Temp is valid if CRC is valid
echo -e "$ANSWER" | grep -q "YES" >&2
if [ $? -eq 0 ]
then
#temp is OK
#Get only temp from two line answer
TEMP=$(echo -e "$ANSWER" | grep "t=" | cut -f 2 -d "=")
INTEGER=$(($TEMP/1000)) #integers
FRAC=$(($TEMP%1000)) #decimals
#handle minus frac! int (-1,0)°C
if [ "$FRAC" -lt "0" ] #is rest minus?
then
FRAC=$(($FRAC * -1)) #del minus
if [ "$INTEGER" -ge "0" ] #is INTEGER 0 and more?
then
INTEGER="-0" #this write minus to result, zero will be add next
fi
fi
#Handle one or two cyfer result - int (-1, 1)°C
if [ "$FRAC" -lt "100" ] #is result less than 100?
then
if [ "$FRAC" -lt "10" ] #is result less than 10?
then
FRAC="00"$FRAC #add two zeros
else
FRAC="0"$FRAC #add one zero
fi
fi
#This will print the integer part to output, it can be commented out
echo $INTEGER >&2
#store result
OUTPUT=`echo "$OUTPUT":"$INTEGER.$FRAC"`
else
#CRC is invalid - error
echo "$DEVICE=CRC ERROR" >&2
fi
fi
fi
done
echo $OUTPUT
}
Thanks for the script mate! I think that in a future I will make something like that, will help me as a guide.
As for the connections, could you please make a little sketch with the wires? Since even after your explanation, I don’t really get how to connect them
Cheers!
Allright, the only problem is that i have two types of sensors, one with a built in resistor and one like yours, so I don’t know how to connect them using only one gpio pin…
Thanks for the pics and explanation, really appreciate it
Script is a function which should be included to other scripts. So remove from the begging temperatures(){ and from end } and than You will see the result. I use this to get temperatures for my log in RRD database see fisero.eu.
1 wire bus should work with 1K resistor if it is not so long (max 10 meters). So He can use as many sensors with build in resistor until he do not reach this paralel value. Question is now, what value of resistor is used? If 4K7 than max 4 sensors can be used (+ others without resistors).
It looks like the first condition not catch the device master… I see… There is a string w1_bus_master instead of w1_bus_master1 I’ve to update the script above.
So you have 10K resistor and You can use up to 10 sensors like this on one bus like it is on pictures I posted before. D1 is for indicate power and D2 should indicate communication without influence on dominant state on bus.
Allright, have them connnectyed and reading temps correctly, now I face other problems:
Temp changed on the inside: 23.875 °C
Connecting to: blynk-cloud.com 8441
Temp changed on the outside: 23 °C
Temp changed on the outside: 23.062 °C
Temp changed on the inside: 23.812 °C
Temp changed on the outside: 23 °C
Temp changed on the outside: 23.062 °C
Temp changed on the inside: 23.75 °C
Connecting to: blynk-cloud.com 8441
As you can see, raspi never connects to the server, I will investigate and post my results here
Thank you two for your work and interest, I will post a guide as soon as I have all functioning
This is my code btw
var W1Temp = require('/usr/local/lib/node_modules/w1temp');
var blynkLib = require('/usr/local/lib/node_modules/blynk-library');
var AUTH = 'aa46fedd9fcf42e4b7983939647db885';
//Setup Blynk (SSL)
var blynk = new blynkLib.Blynk(AUTH);
//Get IDs fo the sensors connected
//W1Temp.getSensorsUids().then(function (sensorsUids) {
// console.log(sensorsUids);
//});
//28-051684c0d6ff built-in temp
//28-041692675aff ds18b20 temp
W1Temp.getSensor('28-041692675aff').then(function (sensor) {
var tempInside = sensor.getTemperature();
sensor.on('change', function (tempInside) {
console.log('Temp changed on the inside:', tempInside,'°C');
//Report it to server
blynk.virtualWrite(0, tempInside);
});
});
W1Temp.getSensor('28-051684c0d6ff').then(function (sensor){
var tempOutside = sensor.getTemperature();
sensor.on('change', function (tempOutside) {
console.log('Temp changed on the outside:', tempOutside,'°C');
//Report it to server
blynk.virtualWrite(1, tempOutside);
});
});
I know it could be more stylish, but I will let this things for a future
var blynk = new blynkLib.Blynk(AUTH, options = {
connector : new blynkLib.TcpClient()
});
equivalent output
Connecting to TCP: blynk-cloud.com 8442
Connecting to TCP: blynk-cloud.com 8442
Connecting to TCP: blynk-cloud.com 8442
Connecting to TCP: blynk-cloud.com 8442
Connecting to TCP: blynk-cloud.com 8442
Temp changed on the outside: 23.125 °C
Connecting to TCP: blynk-cloud.com 8442
Temp changed on the outside: 23.062 °C
Temp changed on the outside: 23.125 °C
Connecting to TCP: blynk-cloud.com 8442