Hallo erstmals, bin ein Neuling in Sachen Arduino habe aber sehr gefallen daran gefunden aber stehe nun vor einen Problem und hoffe Ihr könnt mir dabei weiterhelfen ![]()
Ich habe 2 Stk DS18B20 Sensoren auf einen Arduino Uno samt Ethernet Shield,
Im Seriellen Monitor funktioniert die Richtige Temperatur Ausgabe,
lade ich jedoch die beiden Senordaten auf Thingspeak rauf kommen ganz andere Werte drauf,
denke es jat mit:
int sensor1Value = (Temp1);
int sensor2Value = (Temp2);
zu tun, hab mehrere Varianten bis jz durchprobiert komme aber nicht auf die Lösung.
Z.b Anzeige auf den Seriellen Monitor : 21,75
Anzeige auf Thingspeak 265
Hier noch der ProgrammCode:
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Ethernet.h>
#include "secrets.h"
#include "ThingSpeak.h"
byte mac[] = SECRET_MAC;
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 188, 53);
IPAddress myDns(192, 168, 188, 1);
EthernetClient client;
unsigned long myChannelNumber = SECRET_CH_ID;
const char * myWriteAPIKey = SECRET_WRITE_APIKEY;
// Data wire is plugged into port 5 on the Arduino
#define ONE_WIRE_BUS 5
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Addresses of 2 DS18B20s
DeviceAddress Temp1 = { 0x28, 0xC5, 0xB0, 0x99, 0x53, 0x22, 0x08, 0x5A };
DeviceAddress Temp2 = { 0x28, 0x9B, 0xF8, 0x82, 0x54, 0x22, 0x09, 0x38 };
void setup(void){
Serial.begin(115200); //Initialize serial
Ethernet.init(10); // Most Arduino Ethernet hardware
sensors.begin();
sensors.setResolution(Temp1, 10);
sensors.setResolution(Temp2, 10);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo native USB port only
}
// start the Ethernet connection:
Serial.println("Initialize Ethernet with DHCP:");
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
while (true) {
delay(1); // do nothing, no point running without Ethernet hardware
}
}
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
}
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, ip, myDns);
} else {
Serial.print(" DHCP assigned IP ");
Serial.println(Ethernet.localIP());
}
// give the Ethernet shield a second to initialize:
delay(1000);
ThingSpeak.begin(client); // Initialize ThingSpeak
}
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
Serial.print("Error getting temperature");
} else {
Serial.print(" C: ");
Serial.print(tempC);
}
}
void loop(){
sensors.requestTemperatures();
// delay(100);
Serial.print("\Temp 1 ist");
printTemperature(Temp1);
Serial.println("");
Serial.print("\Temp 2 ist");
printTemperature(Temp2);
Serial.println("");
//And Update the ThingSpeak Channel
int sensor1Value = (Temp1);
int sensor2Value = (Temp2);
long timeRead = millis();
ThingSpeak.setField(1, sensor1Value);
ThingSpeak.setField(2, sensor2Value);
ThingSpeak.setField(3, timeRead);
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
Serial.print("Data Uploaded to Cloud...\n\r");
Serial.print("\n\r");
delay(60000);
}
Danke fürs drüber schauen ![]()