I'm currently trying (for a few hours) to display the temperature got from a DS18B20 on my Adafruit LEDBackpack. But hen I try to init the display in the setup (matrix.begin(0x070)), the temperature returned by the sensor is always -127.

Could you please help me understand what I did wrong ?

Use cases

  1. Only temp sensor: Temperature is correct
  2. Only screen: Screen works as expected
  3. Both: Screen works and displays what's expected BUT temperature returned is always -127.

Components:

  • Adafruit LEDBackpack is using I2C so it's connected to SCL, SDA, 5v, GND
  • Temp sensor is DS18B20 (1-Wire bus). It's connected to D#2, 5v, GND

Code

#include <OneWire.h>
#include <DallasTemperature.h>
#include <Bridge.h>
#include <Wire.h> // Enable this line if using Arduino Uno, Mega, etc.
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"

#define ONE_WIRE_BUS 2
#define TEMP_DELAY 2000 // Request temp every two seconds

Adafruit_7segment matrix = Adafruit_7segment();

unsigned long time, lastTempCheck = 0;
float temp = 0;
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

void setup(void)
{
  // start serial port
  Serial.begin(9600);

  // Start up the library
  sensors.begin(); 
  matrix.begin(0x70); // If I comment this and do not use the matrix, the temperature is correct.
}

void loop(void)
{ 
  time = millis();

  if((time - lastTempCheck) > TEMP_DELAY){
    lastTempCheck = time;
    processTemp();
  }else { 
  matrix.print(100);
  matrix.writeDisplay();
  }
}

void processTemp(void){
  sensors.requestTemperatures(); // Send the command to get temperatures
  temp = sensors.getTempCByIndex(0);
  Serial.print("Temperature: ");
  Serial.println(temp);
}

Schema

Schema

2

There are 2 answers

1
Aphire On

Try giving each component its own power supply (i.e LED - 3V and sensor - 5v). Each pin can only output so much power to stop damage to the board. The LED may be drawing power from the sensor and the sensor may not have enough power to work correctly.

0
Kingsley On

Your circuit diagram shows a short-circut over the (+) and (-) pins (legs) of the DS18B20 - that short horizontal wire below the resisitor. The value -127.0 indicates there is a problem with your temperature sensor too.

So if that's an actual problem (not just in the diagram), remove that wire to fix it. Also, in your setup(), you may want to add some kind of check that your sensors are A-OK before looping:

#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS    2  // Arduino pin D2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

setup()
{
    Serial.begin(115200);
    Serial.println("setup() runs ...");

    sensors.begin();
    if (sensors.getDeviceCount() < 1)
    {
        Serial.println("DS18B20 Error - No sensors found");
    }
}

// ... rest of code