DS1820 DS18B20 ESP01 Webserver STM32NucleoL152RE basiert auf dem DS1820-Example von Paul Staron
Dependencies: LCD_i2c_GSOE ESP8266WebserverGSOE DS1820
Diff: main.cpp
- Revision:
- 0:a3c589406dc4
- Child:
- 2:2c947079aae0
diff -r 000000000000 -r a3c589406dc4 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Dec 29 13:08:22 2020 +0000 @@ -0,0 +1,70 @@ +#include "mbed.h" +#include "DS1820.h" + +DigitalOut led(LED1); + +#define DATA_PIN A0 +#define MAX_PROBES 16 +DS1820* probe[MAX_PROBES]; + +Timer t; + +int DS; +float Temp[16]; + +int main(){ + + printf("\033[0m\033[2J\033[HInitialise...!\n\n"); + + while (DS1820::unassignedProbe(DATA_PIN)) { + probe[DS] = new DS1820(DATA_PIN); + DS++; + if (DS == MAX_PROBES) { + break; + } + } + + if (!DS) { + printf("No Sensors found!\n\n"); + ThisThread::sleep_for(chrono::milliseconds(1000)); + NVIC_SystemReset(); + } + + // set each probe resolution, default is 12bit (750ms) + probe[0]->setResolution(9); +// probe[0]->setResolution(10); +// probe[0]->setResolution(11); +// probe[0]->setResolution(12); +// probe[1]->setResolution(9); +// probe[2]->setResolution(10); + + t.start(); + + while(1) { + + printf("\033[0m\033[2J\033[HDS Sensor data..\n\n"); + + int DS_error = 0; + for (int i = 0; i < DS; i++) { + Temp[i] = probe[i]->temperature(); + if(Temp[i]==-1000) { + Temp[i] = probe[i]->temperature(); // get read temp again if error + DS_error++; + } + printf("Probe %d: %3.2f %cc\r\n",i,Temp[i],0xb0); + } + printf("\nDS errors: %d\n\n", DS_error); + + printf("Start conversion\n"); + t.reset(); + // don't wait for conversion, but do something that takes at least 750ms before reading the sensors + //if(DS>0){probe[0]->convertTemperature(0, DS1820::all_devices);} + + // wait for conversion, can take up to 750ms(12 bit mode) + if(DS>0){probe[0]->convertTemperature(1, DS1820::all_devices);} + + printf("\nConvert process time: %0.6f Seconds\n", chrono::duration<float>(t.elapsed_time()).count()); + + ThisThread::sleep_for(chrono::milliseconds(1000)); + } +}