STM32F103C8T6_WIFI_Heating_system
Dependencies: mbed mbed-STM32F103C8T6 eeprom_flash Watchdog PinDetect DS1820
- Bluepill STM32F103C8T6 Heating system
- _This project is core part of bigger heating system project!_
Features
- Reading temperature from four DS18B20 sensors
- Making a decision about switching on/off heater and pomp
- Executing simple user commands from UART
- Storing state parameters to program memory (EEPROM emulation)
Diff: main.cpp
- Revision:
- 19:74f78a777ffa
- Parent:
- 18:9434e06223c7
- Child:
- 20:4f3a45fd4bbb
--- a/main.cpp Wed Sep 12 17:40:02 2018 +0000 +++ b/main.cpp Wed Sep 12 19:32:17 2018 +0000 @@ -1,6 +1,7 @@ #include "stm32f103c8t6.h" #include "mbed.h" #include "DS1820.h" +#include <string> char a[128] = ""; // RX command buffer char i = 0; // RX char pointer @@ -34,31 +35,38 @@ confSysClock(); //Configure system clock (72MHz HSE clock, 48MHz USB clock) DigitalOut myled(LED1); + + string labels[5] = { + "OUTDOOR", + "LITOS", + "MEBEL", + "HOT WATER", + "BACK WATER" + }; - DS1820 ds1820(PA_9); // substitute PA_9 with actual mbed pin name connected to the DS1820 data pin - DS1820 ds1820_2(PA_8); // substitute PA_9 with actual mbed pin name connected to the DS1820 data pin - + DS1820 ds1820[5] = { + DS1820(PA_9), // substitute PA_9 with actual mbed pin name connected to the OUTDOOR + DS1820(PA_8), // substitute PA_8 with actual mbed pin name connected to the INDOOR LITOS + DS1820(PA_7), // substitute PA_7 with actual mbed pin name connected to the INDOOR MEBEL + DS1820(PA_6), // substitute PA_6 with actual mbed pin name connected to the HOT WATER + DS1820(PA_5) // substitute PA_6 with actual mbed pin name connected to the HOT WATER + }; + float temp = 0; int error = 0; pc.attach(&rxCallback, Serial::RxIrq); pc.baud(115200); - pc.printf("Hello world! Mbed version\r\n"); - - if(ds1820.begin()) { - pc.printf("DS1820 sensor1 found!\r\n"); - } else { - pc.printf("No DS1820 sensor1 found!\r\n"); + pc.printf("Hello world! Mbed version\r\n"); + + for ( int j=0; j < 5; j++ ) { + if(ds1820[j].begin()) { + pc.printf("%s sensor present!\r\n", labels[j].c_str()); + } else { + pc.printf("No %s sensor found!\r\n", labels[j].c_str()); + }; }; - - if(ds1820_2.begin()) { - pc.printf("DS1820 sensor2 found!\r\n"); - } else { - pc.printf("No DS1820 sensor2 found!\r\n"); - }; - - while(1) { // The on-board LED is connected, via a resistor, to +3.3V (not to GND). // So to turn the LED on or off we have to set it to 0 or 1 respectively @@ -75,34 +83,27 @@ myled = 1; // turn the LED off + // start temperature conversion from analog to digital + for ( int j=0; j < 5; j++ ) { + ds1820[j].startConversion(); + }; + - ds1820.startConversion(); // start temperature conversion from analog to digital - ds1820_2.startConversion(); // start temperature conversion from analog to digital - - wait(0.750); // let DS1820 complete the temperature conversion - error = ds1820.read(temp); // read temperature from DS1820 and perform cyclic redundancy check (CRC) + wait(0.750); // let DS1820 complete the temperature conversion + + for ( int j=0; j < 5; j++ ) { + error = ds1820[j].read(temp); // read temperature from DS1820 and perform cyclic redundancy check (CRC) switch(error) { case 0: // no errors -> 'temp' contains the value of measured temperature - pc.printf("sensor1 temp = %3.1fC\r\n", temp, 176); + pc.printf("temp%d = %3.1fC \r\n", j, temp); break; case 1: // no sensor present -> 'temp' is not updated - pc.printf("no sensor1 present\n\r"); + pc.printf("no sensor%d present \r\n", j); break; case 2: // CRC error -> 'temp' is not updated - pc.printf("sensor1 CRC error\r\n"); + pc.printf("sensor%d CRC error \r\n", j); }; - - error = ds1820_2.read(temp); // read temperature from DS1820 and perform cyclic redundancy check (CRC) - switch(error) { - case 0: // no errors -> 'temp' contains the value of measured temperature - pc.printf("sensor2 temp = %3.1fC\r\n", temp, 176); - break; - case 1: // no sensor present -> 'temp' is not updated - pc.printf("no sensor2 present\n\r"); - break; - case 2: // CRC error -> 'temp' is not updated - pc.printf("sensor2 CRC error\r\n"); - } + };