DS18B20

Everything about programming the platform and using the Waspmote API
Jareth
Posts: 3
Joined: Mon Mar 24, 2014 6:07 pm

DS18B20

Post by Jareth » Mon Mar 24, 2014 6:27 pm

Good Afternoon,

First of all thanks for your invaluable help.

I was trying to read a DS18B20 using your library. I always receive a -1000, so I guess that I didn´t connected right the sensor. I was checking your document and I put the conecxions like that:

Image

This is that I understood from your documentation:

“This temperature sensor also needs a simple hardware modification to be directly plugged to Waspmote. Three pins come out of the sensor: Red (3V3), Black (GND) and White (Output pin). A 4K7 resistor must be connected between the red and white pins. The Sensor output can be plugged in any Waspmote digital pin. When reading the sensor the output pin is selected as input parameter: “

Thanks

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: DS18B20

Post by libelium-dev » Tue Mar 25, 2014 8:44 am

Hi Jareth,

Could you tell us what library are you using? Could you post the uploaded code to the Waspmote?

Regards.

Jareth
Posts: 3
Joined: Mon Mar 24, 2014 6:07 pm

Re: DS18B20

Post by Jareth » Wed Mar 26, 2014 12:37 pm

Good morning:

This is the the code. AS you can see, I copied in my file your library in order to change the return value.

Could you confirm that the conexions, which I sent in the initial messages, are ok?

Thanks!

/*
* ------ [BS_05] Waspmote reading DS1820 temperature sensor --------
*
* Explanation: This example shows how to read the DS1820 temperature sensor
*
* Copyright (C) 2012 Libelium Comunicaciones Distribuidas S.L.
* http://www.libelium.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Version: 0.1
* Design: David Gascón
* Implementation: Marcos Yarza
*/

// Variables

float temp = 0;


void setup()
{
// Init USB
USB.ON();

}


float _readTempDS1820(uint8_t pin)
{

delay(10);

WaspOneWire OneWireTemp(pin);

byte data[12];
byte addr[8];

if ( !OneWireTemp.search(addr))
{
//no more sensors on chain, reset search
OneWireTemp.reset_search();
return -1020;
}

if ( WaspOneWire::crc8( addr, 7) != addr[7])
{
return -1030;
}

if ( addr[0] != 0x10 && addr[0] != 0x28)
{
return -1040;
}
OneWireTemp.reset();
OneWireTemp.select(addr);
OneWireTemp.write(0x44,0); // start conversion, with parasite power on at the end
delay(750);

OneWireTemp.reset();
OneWireTemp.select(addr);
OneWireTemp.write(0xBE); // Read Scratchpad
for (int i = 0; i < 9; i++) // we need 9 bytes
{
data = OneWireTemp.read();
}

OneWireTemp.reset_search();

byte MSB = data[1];
byte LSB = data[0];

float tempRead = ((MSB << 8) | LSB); //using two's compliment
float TemperatureSum = tempRead / 16;


return TemperatureSum;
}


void loop()
{
// Reading the DS1820 temperature sensor connected to DIGITAL8
PWR.setSensorPower(SENS_3V3,SENS_ON);
temp = _readTempDS1820(DIGITAL8);
PWR.setSensorPower(SENS_3V3,SENS_OFF);
USB.print(F("DS1820 Temperature: "));
USB.print(temp);
USB.println(F(" degrees"));
delay(1000);
}

Jareth
Posts: 3
Joined: Mon Mar 24, 2014 6:07 pm

Re: DS18B20

Post by Jareth » Mon Mar 31, 2014 5:33 pm

Hola Libelium,

Any answer for this question?

Thanks!

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: DS18B20

Post by libelium-dev » Tue Apr 01, 2014 10:20 am

Hi Jareth,

Are you sure that you are connecting your device with the DIGITAL8?In this cases is very useful the use of an oscilloscope to view if the signal is been sending properly.

Regards.

Herrero
Posts: 11
Joined: Fri Sep 19, 2014 4:14 pm

Re: DS18B20

Post by Herrero » Fri Sep 19, 2014 4:19 pm

I have similar problem with DS18b20. Sometimes I receive some strange value.

Code: Select all

DS1820 Temperature: -0.0625000000 degrees
DS1820 Temperature: -0.0625000000 degrees
DS1820 Temperature: 27.0625000000 degrees
DS1820 Temperature: 27.0625000000 degrees
DS1820 Temperature: 27.0625000000 degrees
DS1820 Temperature: 27.0625000000 degrees
DS1820 Temperature: 27.0625000000 degrees
DS1820 Temperature: -0.0625000000 degrees
DS1820 Temperature: 27.0000000000 degrees
DS1820 Temperature: -0.0625000000 degrees
DS1820 Temperature: 27.1250000000 degrees
DS1820 Temperature: 27.1250000000 degrees
Could you help me with this problem? I have only one sensor connected to waspmote board. Here is my code:

Code: Select all

float readTempDS1820(uint8_t pin)
{
   PWR.setSensorPower(SENS_3V3,SENS_ON);
   delay(10);
   
   WaspOneWire OneWireTemp(pin);
   
   byte data[12];
   byte addr[8];

   long timeout;

   timeout = millis();
   while ( !OneWireTemp.search(addr) )
   {
      //no more sensors on chain, reset search
      OneWireTemp.reset_search();
      if ( millis() < timeout )
      {
         timeout = millis();
      }
      if ( millis() - timeout > 5000)
      {
         return -1000;
      }
   }
   
   if ( WaspOneWire::crc8( addr, 7) != addr[7])
   {
      return -2000;
   }

   if ( addr[0] != 0x10 && addr[0] != 0x28)
   {
      return -3000;
   }
   
   OneWireTemp.reset();
   OneWireTemp.select(addr);
   OneWireTemp.write(0x44,0); // start conversion, with parasite power on at the end
    delay(750);
   
   byte present = OneWireTemp.reset();
   OneWireTemp.select(addr);   
   OneWireTemp.write(0xBE); // Read Scratchpad

     for (int i = 0; i < 9; i++)  // we need 9 bytes
   {
      data[i] = OneWireTemp.read();
   }
 
   OneWireTemp.reset_search();
 
   byte MSB = data[1];
   byte LSB = data[0];

   float tempRead = ((MSB << 8) | LSB); //using two's compliment
   float TemperatureSum = tempRead / 16;
   
    PWR.setSensorPower(SENS_3V3,SENS_OFF);
   
   return TemperatureSum;
}

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: DS18B20

Post by libelium-dev » Mon Sep 22, 2014 8:58 am

Herrero,

your problem can be easily fixed by a software filter.

Just read a few times the sensor and apply a median filter or a similar one. You will filter these glitches. It will not suppose a big delay on your code.

mfv
Posts: 24
Joined: Tue Jul 15, 2014 1:32 pm

Re: DS18B20

Post by mfv » Thu Sep 25, 2014 9:54 am

Hi!
We encounter problems with output from the DS1820 tmp sensor after upgrading from API v09 to v11.

Output with API v09 (correct output):
DS1820 Temperature: 22.0625000000 degrees
DS1820 Temperature: 22.0625000000 degrees
DS1820 Temperature: 22.0625000000 degrees
DS1820 Temperature: 22.0625000000 degrees
DS1820 Temperature: 22.0625000000 degrees
DS1820 Temperature: 22.0625000000 degrees
DS1820 Temperature: 22.1250000000 degrees
DS1820 Temperature: 22.1250000000 degrees
DS1820 Temperature: 22.0625000000 degrees
DS1820 Temperature: 22.1250000000 degrees
DS1820 Temperature: 22.1250000000 degrees
DS1820 Temperature: 22.1250000000 degrees
Output with API v11 (NOT correct):
DS1820 Temperature: -0.0625000000 degrees
DS1820 Temperature: 85.0000000000 degrees
DS1820 Temperature: 85.0000000000 degrees
DS1820 Temperature: -1000.0000000000 degrees
DS1820 Temperature: -1000.0000000000 degrees
DS1820 Temperature: 22.2500000000 degrees
DS1820 Temperature: 22.2500000000 degrees
DS1820 Temperature: -1000.0000000000 degrees
DS1820 Temperature: -1000.0000000000 degrees
DS1820 Temperature: -1000.0000000000 degrees
DS1820 Temperature: -1000.0000000000 degrees
DS1820 Temperature: -1000.0000000000 degrees
DS1820 Temperature: -1000.0000000000 degrees
DS1820 Temperature: -0.0625000000 degrees
Code used to read:
float temp = 0;
int tmp_pin = DIGITAL5;
int tmp_power_pin = DIGITAL6;

void setup()
{
// Init USB
USB.ON();
pinMode(tmp_pin, INPUT);
pinMode(tmp_power_pin, OUTPUT);
}

void loop()
{
digitalWrite(tmp_power_pin, HIGH);
delay(100);
temp = Utils.readTempDS1820(tmp_pin);
USB.print(F("DS1820 Temperature: "));
USB.print(temp);
USB.println(F(" degrees"));
digitalWrite(tmp_power_pin, LOW);
delay(1000);
}
Any advices from libelium-dev (or others)?

Herrero
Posts: 11
Joined: Fri Sep 19, 2014 4:14 pm

Re: DS18B20

Post by Herrero » Thu Sep 25, 2014 1:05 pm

I think, that Libelium API have errors. When I was using their API I had the same problem like you. To best way to partially eliminate error -1000 (which is connected with searching for DS18B20) is to modify API with code which I have put into forum. I case of this code there is only sporadic problem with reading temp 0.0625 :)

Herrero
Posts: 11
Joined: Fri Sep 19, 2014 4:14 pm

Re: DS18B20

Post by Herrero » Thu Sep 25, 2014 1:07 pm

mfv wrote: digitalWrite(tmp_power_pin, HIGH);
digitalWrite(tmp_power_pin, LOW);
You don't have to touch pin configuration ;)

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest