Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: LCD_i2c_GSOE ESP8266WebserverGSOE DS1820
main.cpp@3:e8f1dc9131eb, 2021-08-07 (annotated)
- Committer:
- jack1930
- Date:
- Sat Aug 07 18:57:33 2021 +0000
- Revision:
- 3:e8f1dc9131eb
- Parent:
- 2:2c947079aae0
Vorbereitet fuer Webserver
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| jack1930 | 2:2c947079aae0 | 1 | //basiert auf dem DS1820-Example von Paul Staron |
| jack1930 | 2:2c947079aae0 | 2 | |
| star297 | 0:a3c589406dc4 | 3 | #include "mbed.h" |
| star297 | 0:a3c589406dc4 | 4 | #include "DS1820.h" |
| jack1930 | 2:2c947079aae0 | 5 | #include "LCD.h" |
| star297 | 0:a3c589406dc4 | 6 | |
| star297 | 0:a3c589406dc4 | 7 | DigitalOut led(LED1); |
| jack1930 | 2:2c947079aae0 | 8 | lcd mylcd; |
| star297 | 0:a3c589406dc4 | 9 | |
| jack1930 | 3:e8f1dc9131eb | 10 | #define DATA_PIN PB_0 //Anschluss S |
| jack1930 | 3:e8f1dc9131eb | 11 | //GND Anschluss - |
| jack1930 | 3:e8f1dc9131eb | 12 | //3,3V mittlerer Anschluss |
| jack1930 | 3:e8f1dc9131eb | 13 | |
| star297 | 0:a3c589406dc4 | 14 | #define MAX_PROBES 16 |
| star297 | 0:a3c589406dc4 | 15 | DS1820* probe[MAX_PROBES]; |
| star297 | 0:a3c589406dc4 | 16 | |
| star297 | 0:a3c589406dc4 | 17 | Timer t; |
| star297 | 0:a3c589406dc4 | 18 | |
| star297 | 0:a3c589406dc4 | 19 | int DS; |
| star297 | 0:a3c589406dc4 | 20 | float Temp[16]; |
| star297 | 0:a3c589406dc4 | 21 | |
| star297 | 0:a3c589406dc4 | 22 | int main(){ |
| jack1930 | 2:2c947079aae0 | 23 | mylcd.clear(); |
| star297 | 0:a3c589406dc4 | 24 | printf("\033[0m\033[2J\033[HInitialise...!\n\n"); |
| star297 | 0:a3c589406dc4 | 25 | |
| star297 | 0:a3c589406dc4 | 26 | while (DS1820::unassignedProbe(DATA_PIN)) { |
| star297 | 0:a3c589406dc4 | 27 | probe[DS] = new DS1820(DATA_PIN); |
| star297 | 0:a3c589406dc4 | 28 | DS++; |
| star297 | 0:a3c589406dc4 | 29 | if (DS == MAX_PROBES) { |
| star297 | 0:a3c589406dc4 | 30 | break; |
| star297 | 0:a3c589406dc4 | 31 | } |
| star297 | 0:a3c589406dc4 | 32 | } |
| star297 | 0:a3c589406dc4 | 33 | |
| star297 | 0:a3c589406dc4 | 34 | if (!DS) { |
| star297 | 0:a3c589406dc4 | 35 | printf("No Sensors found!\n\n"); |
| star297 | 0:a3c589406dc4 | 36 | ThisThread::sleep_for(chrono::milliseconds(1000)); |
| star297 | 0:a3c589406dc4 | 37 | NVIC_SystemReset(); |
| star297 | 0:a3c589406dc4 | 38 | } |
| star297 | 0:a3c589406dc4 | 39 | |
| star297 | 0:a3c589406dc4 | 40 | // set each probe resolution, default is 12bit (750ms) |
| star297 | 0:a3c589406dc4 | 41 | probe[0]->setResolution(9); |
| star297 | 0:a3c589406dc4 | 42 | // probe[0]->setResolution(10); |
| star297 | 0:a3c589406dc4 | 43 | // probe[0]->setResolution(11); |
| star297 | 0:a3c589406dc4 | 44 | // probe[0]->setResolution(12); |
| star297 | 0:a3c589406dc4 | 45 | // probe[1]->setResolution(9); |
| star297 | 0:a3c589406dc4 | 46 | // probe[2]->setResolution(10); |
| star297 | 0:a3c589406dc4 | 47 | |
| star297 | 0:a3c589406dc4 | 48 | t.start(); |
| star297 | 0:a3c589406dc4 | 49 | |
| star297 | 0:a3c589406dc4 | 50 | while(1) { |
| star297 | 0:a3c589406dc4 | 51 | |
| star297 | 0:a3c589406dc4 | 52 | printf("\033[0m\033[2J\033[HDS Sensor data..\n\n"); |
| star297 | 0:a3c589406dc4 | 53 | |
| star297 | 0:a3c589406dc4 | 54 | int DS_error = 0; |
| star297 | 0:a3c589406dc4 | 55 | for (int i = 0; i < DS; i++) { |
| star297 | 0:a3c589406dc4 | 56 | Temp[i] = probe[i]->temperature(); |
| star297 | 0:a3c589406dc4 | 57 | if(Temp[i]==-1000) { |
| star297 | 0:a3c589406dc4 | 58 | Temp[i] = probe[i]->temperature(); // get read temp again if error |
| star297 | 0:a3c589406dc4 | 59 | DS_error++; |
| star297 | 0:a3c589406dc4 | 60 | } |
| jack1930 | 3:e8f1dc9131eb | 61 | |
| jack1930 | 3:e8f1dc9131eb | 62 | mylcd.cursorpos(0x40); |
| jack1930 | 3:e8f1dc9131eb | 63 | mylcd.printf("%3.1f ",Temp[i]); |
| star297 | 0:a3c589406dc4 | 64 | } |
| star297 | 0:a3c589406dc4 | 65 | printf("\nDS errors: %d\n\n", DS_error); |
| star297 | 0:a3c589406dc4 | 66 | |
| star297 | 0:a3c589406dc4 | 67 | printf("Start conversion\n"); |
| star297 | 0:a3c589406dc4 | 68 | t.reset(); |
| star297 | 0:a3c589406dc4 | 69 | // don't wait for conversion, but do something that takes at least 750ms before reading the sensors |
| star297 | 0:a3c589406dc4 | 70 | //if(DS>0){probe[0]->convertTemperature(0, DS1820::all_devices);} |
| star297 | 0:a3c589406dc4 | 71 | |
| star297 | 0:a3c589406dc4 | 72 | // wait for conversion, can take up to 750ms(12 bit mode) |
| star297 | 0:a3c589406dc4 | 73 | if(DS>0){probe[0]->convertTemperature(1, DS1820::all_devices);} |
| star297 | 0:a3c589406dc4 | 74 | |
| star297 | 0:a3c589406dc4 | 75 | printf("\nConvert process time: %0.6f Seconds\n", chrono::duration<float>(t.elapsed_time()).count()); |
| star297 | 0:a3c589406dc4 | 76 | |
| star297 | 0:a3c589406dc4 | 77 | ThisThread::sleep_for(chrono::milliseconds(1000)); |
| star297 | 0:a3c589406dc4 | 78 | } |
| star297 | 0:a3c589406dc4 | 79 | } |