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
- Only temp sensor: Temperature is correct
- Only screen: Screen works as expected
- 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);
}
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.