-
Notifications
You must be signed in to change notification settings - Fork 4
/
RS485ModbusACSSR.ino
58 lines (49 loc) · 1.53 KB
/
RS485ModbusACSSR.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
51
52
53
54
55
56
57
58
// Copyright (c) 2023 by GWENDESIGN. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
// https://docs.m5stack.com/en/unit/acssr
// https://github.com/m5stack/ArduinoModbus
// https://github.com/m5stack/ArduinoRS485
#include "M5Tough.h"
#include "M5_ACSSR.h"
#include <ArduinoModbus.h>
#include <ArduinoRS485.h>
RS485Class RS485(Serial2, GPIO_NUM_27, GPIO_NUM_19, -1, -1); // RX, TX, ?, ReadEnable
bool gbToggle = false;
void setup()
{
M5.begin(true, false, true, false);
M5.Lcd.setTextSize(3);
M5.Lcd.setCursor(0, 5);
M5.Lcd.println("M5Tough");
M5.Lcd.setTextSize(2);
M5.Lcd.setCursor(0, 40);
M5.Lcd.println("Modbus Test v1.0.0");
M5.Lcd.setTextSize(2);
M5.Lcd.setCursor(0, 75);
M5.Lcd.println("Touch to toggle\nrelay state.");
ModbusRTUClient.begin(RS485, 115200, SERIAL_8N1);
}
void loop()
{
M5.update();
if(M5.Touch.ispressed() == true)
{
if(gbToggle == false)
{
gbToggle = true;
// ACSSR CTL ON
ModbusRTUClient.coilWrite(ACSSR_DEFAULT_SLAVE_ID, ACSSR_RELAY_COIL_ADDR, 0x01);
// ACSSR LED CTL RED COLOR
ModbusRTUClient.holdingRegisterWrite(ACSSR_DEFAULT_SLAVE_ID, ACSSR_LED_HOLDING_ADDR, 0xF800);
}
else
{
gbToggle = false;
// ACSSR CTL OFF
ModbusRTUClient.coilWrite(ACSSR_DEFAULT_SLAVE_ID, ACSSR_RELAY_COIL_ADDR, 0x00);
// ACSSR LED CTL GREEN COLOR
ModbusRTUClient.holdingRegisterWrite(ACSSR_DEFAULT_SLAVE_ID, ACSSR_LED_HOLDING_ADDR, 0x07E0);
}
delay(800);
}
}