In this demo sketch a counter which should run between 0 and 1 runs amok. I have put in a debug 'println' just to see where it'st going and it's going haywild.
Sketch code:
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
int ledColumns = 16;
int ledRows = 2;
#define ONE_WIRE_BUS 2
#define PRECISION 9 // precision
//Setup a onwWire instance to communicate with any OneWire devices
// (not just Maxim/Dallas temprerature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass out OneWire reference to DAllas Temperature
DallasTemperature sensors(&oneWire);
DeviceAddress DevAddr;
LiquidCrystal_I2C lcd(0x27, ledColumns, ledRows);
void setup()
{
// setup for LCD
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
// Start serial port
Serial.begin(9600);
delay(500);
Serial.println("Dallas Temperature IC Control Library Demo");
lcd.print("Dallas Temp Test");
sensors.begin(); // Start up library
// Locate devices on the bus
Serial.print("Found ");
Serial.print(sensors.getDeviceCount(), DEC);
Serial.print(" devices.");
Serial.println();
// Report parasite power requirements
String busMode = "OFF";
if (sensors.isParasitePowerMode()) busMode = "ON";
Serial.println("Parasite power is " + busMode);
// Search for devices on the bus and assign based on index.
Serial.println("Start SEARCH");
for (int k = 0; k < sensors.getDeviceCount(); k++)
{
// Debug line ***************************************************************
Serial.println(k);
if (!sensors.getAddress(DevAddr[k], k))
{
Serial.println("Not found sensor " + k);
}
}
Serial.println("End SEARCH");
// Show addresses found on the bus and set resolution
Serial.println("Start ShOW");
for (int k = 0; k < sensors.getDeviceCount(); k++)
{
Serial.print("Sensor ");
Serial.print(k + 1);
Serial.print(". Address: "); // Print addresses
printAddress(DevAddr[k]);
Serial.println();
sensors.setResolution(DevAddr[k], PRECISION); // set resolution
}
Serial.println("End SHOW");
// Print sensor resolutions
for (int k = 0; k < sensors.getDeviceCount(); k++)
{
Serial.print("Sensor " + (k + 1) + sensors.getResolution(DevAddr[k]));
}
}
// Function to print a device address
void printAddress(DeviceAddress DevAddr)
{
for(uint8_t i = 0; i < 8; i++)
{
if (DevAddr[i] < 16) Serial.print("0");
Serial.print(DevAddr[i], HEX);
}
}
// Function to print temperatures
void printTemperature(DeviceAddress DevAddr)
{
float tempC = sensors.getTempC(DevAddr);
Serial.println("Temp: ");
Serial.print(tempC);
Serial.print(" C");
// Serial.println("Temp: " + sensors.toFarenheit(tempC) + " F");
}
// Function to print a device's resolution
void printResolution(DeviceAddress DevAddr)
{}
void loop()
{
// Call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
sensors.requestTemperatures();
for (int k = 0; k < sensors.getDeviceCount(); k++)
{
lcd.setCursor(0, 0);
lcd.print("Sensor nr " + DevAddr[k]);
lcd.print(sensors.getTempC(DevAddr[k]));
lcd.print(" C" + char(223)); // Hex(DF)
//
Serial.print("Sensor nr " + DevAddr[k]);
Serial.print(sensors.getTempC(DevAddr[k]));
Serial.print(" C" + char(223));
Serial.println();
delay(5000);
}
}
Serial Monitor output: This is just a small part of it but it looks the same further on.
Dallas Temperature IC Control Library Demo
Found 2 devices.
Parasite power is OFF
Start SEARCH
0
1N!⸮
2N!⸮
3N!⸮
4N!⸮
5N!⸮
6N!⸮
7N!⸮
8N!⸮
9N!⸮
AN!⸮
BN!⸮
CN!⸮
DN!⸮