Hi all,
I've searched here and googled but not found anything similar to what I'm seeing. Apologies if I've missed it.
I'm trying to connect 15 DS18B20's (each with a 3m cable) to a UNO with WiFi R2.
It all works until I attach sensor number eight when I get no valid information.
I've tried different sensors, I've tried a power supply instead of USB, no improvement. I've tested sensor number eight alone and it's fine.
So I think I've ruled out lack of power and dodgy sensor haven't I?
I've seen comments saying you can have loads of DS18B20's on one wire, is that true?
Any help gratefully received.
Relevant part of the output is:
Sensor 1: 0.00 Sensor 2: 0.00 Sensor 3: 0.00 Sensor 4: 0.00 Sensor 5: 0.00 Sensor 6: 0.00 Sensor 7: 0.00 Sensor 8: 0.00
Code is work in progress so please forgive the sloppy programming ![]()
#include <SPI.h>
#include <WiFiNINA.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#define ONE_WIRE_BUS 7
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int deviceCount = 0;
float tempC;
String lcdText;
float prevTemp[9];
float lastTemp;
float difTemp;
DeviceAddress Thermometer;
uint8_t sensor1[8] = {0x28, 0x40, 0x18, 0x30, 0x27, 0x19, 0x01, 0x8F};
uint8_t sensor2[8] = {0x28, 0xD5, 0x62, 0x32, 0x27, 0x19, 0x01, 0x02};
uint8_t sensor3[8] = {0x28, 0xC5, 0x27, 0x24, 0x27, 0x19, 0x01, 0x53};
uint8_t sensor4[8] = {0x28, 0x38, 0xCD, 0x2A, 0x27, 0x19, 0x01, 0x19};
uint8_t sensor5[8] = {0x28, 0x25, 0x3E, 0x2C, 0x27, 0x19, 0x01, 0xE9};
uint8_t sensor6[8] = {0x28, 0x2A, 0x8B, 0x33, 0x27, 0x19, 0x01, 0xF2};
uint8_t sensor7[8] = {0x28, 0x0B, 0x78, 0x29, 0x27, 0x19, 0x01, 0xB8};
uint8_t sensor8[8] = {0x28, 0x9E, 0x9D, 0x25, 0x27, 0x19, 0x01, 0xF8};
uint8_t sensorx[8] = {0x28, 0x2D, 0xA6, 0x26, 0x27, 0x19, 0x01, 0xDA};
char ssid[] = "********"; // your network SSID (name)
char pass[] = "********"; // your network password
int status = WL_IDLE_STATUS;
WiFiServer server(80);
void setup() {
sensors.begin();
Serial.begin(9600);
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
delay(10000);
}
server.begin();
printWifiStatus();
}
void loop() {
// listen for incoming clients
WiFiClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
sensors.requestTemperatures();
//client.println(sensors.getTempCByIndex(0));
//Serial.println(sensors.getTempCByIndex(0));
sensors.getAddress(Thermometer, 0);
printAddress(Thermometer);
// Serial.print("Sensor 1: ");
// printTemperature(sensor1);
client.print("Sensor 1: ");
client.println(sensors.getTempC(sensor1));
client.print("Sensor 2: ");
client.println(sensors.getTempC(sensor2));
client.print("Sensor 3: ");
client.println(sensors.getTempC(sensor3));
client.print("Sensor 4: ");
client.println(sensors.getTempC(sensor4));
client.print("Sensor 5: ");
client.println(sensors.getTempC(sensor5));
client.print("Sensor 6: ");
client.println(sensors.getTempC(sensor6));
client.print("Sensor 7: ");
client.println(sensors.getTempC(sensor7));
client.print("Sensor 8: ");
client
.println(sensors.getTempC(sensor8));
client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disonnected");
}
sensors.requestTemperatures();
Serial.println(sensors.getDeviceCount());
for (int i = 0; i <= sensors.getDeviceCount() - 1; i++)
{
sensors.getAddress(Thermometer, i);
// Serial.println(i);
printAddress(Thermometer);
}
delay(5000);
}
void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
void printAddress(DeviceAddress deviceAddress)
{
for (uint8_t i = 0; i < 8; i++)
{
Serial.print("0x");
if (deviceAddress[i] < 0x10) Serial.print("0");
Serial.print(deviceAddress[i], HEX);
if (i < 7) Serial.print(", ");
}
Serial.println("");
}
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
Serial.print(tempC);
Serial.print((char)176);
Serial.print("C | ");
Serial.print(DallasTemperature::toFahrenheit(tempC));
Serial.print((char)176);
Serial.println("F");
}