Moj program do odczytu temperatury przerób i będzie git
#include <OneWire.h>
#include <DallasTemperature.h>
// Czujnik oneWire podlaczony do wejscia nr 2 w Arduino
#define ONE_WIRE_BUS 2
#define TEMPERATURE_PRECISION 12 //
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int numberOfDevices; // Wykrywanie czujnikow
DeviceAddress tempDeviceAddress; // Bedziemy uzywać tej zmiennej aby znaleźć adres urządzenia
void setup(void)
{
// uruchomienie portu szeregowego
Serial.begin(9600);
while(!Serial);
// uruchomienie biblioteki
sensors.begin();
// Znajdowanie urzadzen na linii
numberOfDevices = sensors.getDeviceCount();
// Wykryte urzadzenia na magistrali
Serial.print("Wykrywanie czujnikow ... ");
Serial.print("wykryto ");
Serial.print(numberOfDevices, DEC);
Serial.println(" czujnikow.");
// Wykrycie trybu pracy
Serial.print("Tryb pasozytniczy: ");
if (sensors.isParasitePowerMode()) Serial.println("Tak");
else Serial.println("Nie");
// Petla dla kazdego urzadzenia i wyswietlanie opisu
for(int i=0;i<numberOfDevices; i++)
{
// Szukanie adresow czujnikow
if(sensors.getAddress(tempDeviceAddress, i))
{
Serial.print("Znaleziono ");
Serial.print(i, DEC);
Serial.print(" urzadzenie z adresem: ");
printAddress(tempDeviceAddress);
Serial.println();
Serial.print("Ustawiono rozdzielczosc ");
Serial.println(TEMPERATURE_PRECISION, DEC);
// ustawianie rozdzielczosci
sensors.setResolution(tempDeviceAddress, TEMPERATURE_PRECISION);
Serial.print("Rozdzielczosc ustawiona: ");
Serial.print(sensors.getResolution(tempDeviceAddress), DEC);
Serial.println();
}else{
Serial.print("Znaleziono urzadzenie ");
Serial.print(i, DEC);
Serial.print(" o nie zidentyfikowanym adresie. Sprawdz zasilanie i przewody");
}
}
}
// Wysiwetlanie i czytanie temperatury z czujnika
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
Serial.print(tempC);
Serial.print(" C ; ");
}
void loop(void)
{
// Zapytanie o temperature wszystkich urzadzen
sensors.requestTemperatures();
Serial.println("OK");
delay(5000);
// Petla po kazdym urzadzeniu aby odczytac czujnik
for(int i=0;i<numberOfDevices; i++)
{
// Wyszukiwanie na lini czujnikow
if(sensors.getAddress(tempDeviceAddress, i))
{
// Wyswietlenie opisu czujnika
Serial.print("T");
Serial.print(i,DEC);
Serial.print(":");
Serial.print(" ");
printTemperature(tempDeviceAddress);
}
}
}
// Wyswietlanie adresu czujnika
void printAddress(DeviceAddress deviceAddress)
{
for (uint8_t i = 0; i < 8; i++)
{
if (deviceAddress[i] < 16) Serial.print("1");
Serial.print(deviceAddress[i], HEX);
}
}
o poźniej dodaj w programie który masz dodaj sobie nasłuchiwanie aby arduino czekało na komendę aby wyświetlić pomiary.
Na samym początku programu dodaj string:
String odebraneDane = "";
przed
void setup()
i w
void loop(void)
dodaj
{
if(Serial.available() > 0) {
odebraneDane = Serial.readStringUntil('\n');
if (odebraneDane == "odczyt") {
// I tutaj już dalsza cześć twojego programu z odczytem temperatury
w tym przypadku wysłanie do arduiono tekstu odczyt spowoduje popranie i wyswietlenie temperatury
Stacja Pogody pracująca na LEDE / Openwrt + arduino.
http://dominikowice.one.pl Pomiar temperatury, ciśnienia, wilgotności online + wykresy 24 godzinne, 7 dniowe, 30 dniowe, itp. A wszystko to na Routerze NETGEAR WNDR 4300 z wgranym LEDE.