DS1820, DS18B20 single and multi sensor OS6 compliant. Based on Erik's original code. Tested on ST's F767, L152RE and H743 platforms. Using single and multiple sensors up to 15 meters of cable length.
Dependencies: LCD_i2c_GSOE ESP8266WebserverGSOE DS1820
main.cpp
- Committer:
- jack1930
- Date:
- 2021-08-07
- Revision:
- 3:e8f1dc9131eb
- Parent:
- 2:2c947079aae0
File content as of revision 3:e8f1dc9131eb:
//basiert auf dem DS1820-Example von Paul Staron
#include "mbed.h"
#include "DS1820.h"
#include "LCD.h"
DigitalOut led(LED1);
lcd mylcd;
#define DATA_PIN PB_0 //Anschluss S
//GND Anschluss -
//3,3V mittlerer Anschluss
#define MAX_PROBES 16
DS1820* probe[MAX_PROBES];
Timer t;
int DS;
float Temp[16];
int main(){
mylcd.clear();
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++;
}
mylcd.cursorpos(0x40);
mylcd.printf("%3.1f ",Temp[i]);
}
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));
}
}