-
Notifications
You must be signed in to change notification settings - Fork 0
/
esp32_master.ino
50 lines (41 loc) · 949 Bytes
/
esp32_master.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <Wire.h>
#define SLAVE_ADDR 9
#define I2C_SDA 21
#define I2C_SCL 22
bool heater_power = true;
bool motor_power = true;
bool pump_power = true;
double temp;
double ph;
int rpm;
void setup() {
// configure the pins
Wire.begin (I2C_SDA, I2C_SCL);
Serial.begin(9600);
}
void loop() {
// request 6 bytes from slave
Wire.requestFrom(SLAVE_ADDR, 6);
while (Wire.available()) {
temp = int(Wire.read()) * 256;
temp += int(Wire.read());
temp = temp / 100;
rpm = int(Wire.read()) * 256;
rpm += int(Wire.read());
ph = int(Wire.read()) * 256;
ph += int(Wire.read());
ph = ph / 100;
}
// debugging print statements
Serial.println(temp);
Serial.println(rpm);
Serial.println(ph);
Serial.println();
// send data to slave
Wire.beginTransmission(SLAVE_ADDR);
Wire.write(heater_power);
Wire.write(motor_power);
Wire.write(pump_power);
Wire.endTransmission();
delay(500);
}