source: trunk/resources/arduino-opentherm/examples/master/master.ino @ 1

Last change on this file since 1 was 1, checked in by markus, 8 years ago

Initial setup

File size: 1.3 KB
Line 
1#include <opentherm.h>
2
3#define BOILER_IN 3
4#define BOILER_OUT 5
5
6OpenthermData message;
7
8void setup() {
9  pinMode(BOILER_IN, INPUT);
10  digitalWrite(BOILER_OUT, HIGH);
11  pinMode(BOILER_OUT, OUTPUT); // low output = high voltage, high output = low voltage
12
13  Serial.begin(19200);
14}
15
16/**
17 * Loop will act as thermostat (master) connected to Opentherm boiler.
18 * It will request slave configration from boiler every 100ms or so and waits for response from boiler.
19 */
20void loop() {
21  if (OPENTHERM::isIdle()) {
22    message.type = OT_MSGTYPE_READ_DATA;
23    message.id = OT_MSGID_SLAVE_CONFIG;
24    message.valueHB = 0;
25    message.valueLB = 0;
26    Serial.print("-> ");
27    OPENTHERM::printToSerial(message);
28    Serial.println();
29    OPENTHERM::send(BOILER_OUT, message); // send message to boiler
30  }
31  else if (OPENTHERM::isSent()) {
32    OPENTHERM::listen(BOILER_IN, 800); // wait for boiler to respond
33  }
34  else if (OPENTHERM::getMessage(message)) { // boiler responded
35    OPENTHERM::stop();
36    Serial.print("<- ");
37    OPENTHERM::printToSerial(message);
38    Serial.println();
39    Serial.println();
40    delay(100); // minimal delay before next communication
41  }
42  else if (OPENTHERM::isError()) {
43    OPENTHERM::stop();
44    Serial.println("<- Timeout");
45    Serial.println();
46  }
47}
Note: See TracBrowser for help on using the repository browser.