Skip to content

Commit 97913d9

Browse files
authored
Merge pull request #310 from Forairaaaaa/master
add module rs232 example
2 parents 1f4a884 + 807a1fd commit 97913d9

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

examples/Modules/RS232/RS232.ino

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

0 commit comments

Comments
 (0)