Skip to content

Commit 1f58c70

Browse files
committed
add module rs232 example
1 parent 1f4a884 commit 1f58c70

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

examples/Modules/RS232/RS232.ino

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
*******************************************************************************
3+
* Copyright (c) 2023 by M5Stack
4+
* Equipped with M5Core sample source code
5+
* 配套 M5Core 示例源代码
6+
* Visit for more information:
7+
*https://docs.m5stack.com/en/module/RS232F%Module%13.2 获取更多资料请访问:
8+
*https://docs.m5stack.com/zh_CN/module/RS232F%Module%13.2
9+
*
10+
* Describe: RS232.
11+
* Date: 2023/3/23
12+
*******************************************************************************
13+
*/
14+
15+
#include <M5Stack.h>
16+
17+
/* Define your pin here */
18+
/* And should be the same as you module setup */
19+
#define RX_PIN 16
20+
#define TX_PIN 17
21+
22+
void setup() {
23+
M5.begin();
24+
M5.Power.begin();
25+
M5.Lcd.setTextSize(1);
26+
M5.Lcd.drawString("Module RS232 test", 75, 3, 4);
27+
Serial2.begin(
28+
115200, SERIAL_8N1, RX_PIN,
29+
TX_PIN); // Set the baud rate of serial port 2 to 115200,8 data bits,
30+
// no parity bits, and 1 stop bit, and set RX to 16 and TX
31+
// to 17.
32+
// 设置串口二的波特率为115200,8位数据位,没有校验位,1位停止位,并设置RX,TX引脚
33+
}
34+
35+
void loop() {
36+
Serial2.write("Hello\n");
37+
38+
if (Serial2.available()) {
39+
M5.Lcd.print(char(Serial2.read()));
40+
}
41+
delay(100);
42+
}

0 commit comments

Comments
 (0)