Skip to content

Commit b91cbca

Browse files
committed
Updated examples
- Updated examples for ESP32, ESP8266 and RP2040.
1 parent c1b5e18 commit b91cbca

File tree

13 files changed

+463
-99
lines changed

13 files changed

+463
-99
lines changed

.vscode/arduino.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"board": "esp8266:esp8266:generic",
2+
"board": "esp8266:esp8266:nodemcuv2",
33
"sketch": "examples\\ESP8266\\RS485_Sender\\RS485_Sender.ino",
44
"port": "COM3",
5-
"configuration": "xtal=80,vt=flash,exception=disabled,stacksmash=disabled,ssl=all,mmu=3232,non32xfer=fast,ResetMethod=nodemcu,CrystalFreq=26,FlashFreq=40,FlashMode=dout,eesz=1M64,led=2,sdk=nonosdk_190703,ip=lm2f,dbg=Disabled,lvl=None____,wipe=none,baud=115200"
5+
"configuration": "xtal=80,vt=flash,exception=disabled,stacksmash=disabled,ssl=all,mmu=3232,non32xfer=fast,eesz=4M2M,led=2,ip=lm2f,dbg=Disabled,lvl=None____,wipe=none,baud=115200"
66
}

.vscode/c_cpp_properties.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
"includePath": [
2020
"C:\\Users\\vishn\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\3.1.2\\tools\\sdk\\include",
2121
"C:\\Users\\vishn\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\3.1.2\\tools\\sdk\\lwip2\\include",
22-
"C:\\Users\\vishn\\AppData\\Local\\Temp\\arduino\\sketches\\93DA6431728478CA0980B676E26021A8\\core",
22+
"C:\\Users\\vishn\\AppData\\Local\\arduino\\sketches\\93DA6431728478CA0980B676E26021A8\\core",
2323
"C:\\Users\\vishn\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\3.1.2\\cores\\esp8266",
24-
"C:\\Users\\vishn\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\3.1.2\\variants\\generic",
24+
"C:\\Users\\vishn\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\3.1.2\\variants\\nodemcu",
2525
"D:\\Code\\Arduino\\libraries\\CSE_ArduinoRS485\\src",
2626
"C:\\Users\\vishn\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\3.1.2\\libraries\\SoftwareSerial\\src",
2727
"c:\\users\\vishn\\appdata\\local\\arduino15\\packages\\esp8266\\tools\\xtensa-lx106-elf-gcc\\3.1.0-gcc10.3-e5f9fec\\xtensa-lx106-elf\\include\\c++\\10.3.0",
@@ -50,12 +50,12 @@
5050
"LWIP_FEATURES=1",
5151
"LWIP_IPV6=0",
5252
"ARDUINO=10607",
53-
"ARDUINO_ESP8266_GENERIC",
53+
"ARDUINO_ESP8266_NODEMCU_ESP12E",
5454
"ARDUINO_ARCH_ESP8266",
55-
"ARDUINO_BOARD=\"ESP8266_GENERIC\"",
56-
"ARDUINO_BOARD_ID=\"generic\"",
55+
"ARDUINO_BOARD=\"ESP8266_NODEMCU_ESP12E\"",
56+
"ARDUINO_BOARD_ID=\"nodemcuv2\"",
5757
"LED_BUILTIN=2",
58-
"FLASHMODE_DOUT",
58+
"FLASHMODE_DIO",
5959
"__DBL_MIN_EXP__=(-1021)",
6060
"__cpp_attributes=200809L",
6161
"__UINT_LEAST16_MAX__=0xffff",

Changes.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
Changelog for the `CSE_ArduinoRS485` library. Latest entries are at the top.
55

66

7+
#
8+
### **+05:30 10:41:11 PM 20-03-2025, Thursday**
9+
10+
- Updated examples for ESP32, ESP8266 and RP2040.
11+
712
#
813
### **+05:30 10:26:50 PM 27-10-2024, Sunday**
914

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,75 @@
1-
/*
2-
RS-485 Passthrough.
3-
4-
This sketch relays data sent and received between the Serial port and the RS-485 interface.
51

6-
Originally created by Sandeep Mistry, on 4 July 2018.
7-
Modified by @vishnumaiea for CIRCUITSTATE Electronics (@circuitstate).
2+
//===================================================================================//
3+
/*
4+
Filename: RS485_Passthrough.ino [ESP32]
5+
Description: Example Arduino program from the CSE_ArduinoRS485 Arduino library.
6+
Acts as a passthrough to send and receive data to and from an RS485 port.
87
8+
This example was written for and tested with the FireBeetle-ESP32E (ESP32).
9+
10+
Framework: Arduino, PlatformIO
11+
Author: Vishnu Mohanan (@vishnumaiea, @vizmohanan)
12+
Maintainer: CIRCUITSTATE Electronics (@circuitstate)
13+
Version: 1.0.14
14+
License: MIT
915
Source: https://github.com/CIRCUITSTATE/CSE_ArduinoRS485
10-
*/
16+
Last Modified: +05:30 21:54:37 PM 20-03-2025, Thursday
17+
*/
18+
//===================================================================================//
1119

1220
#include <CSE_ArduinoRS485.h>
1321

22+
//===================================================================================//
23+
// Macros and constants
24+
25+
// You can define the serial port pins here.
26+
#define PIN_RS485_DE 16
27+
#define PIN_RS485_RE 17
28+
#define PIN_RS485_RX 9
29+
#define PIN_RS485_TX 10
30+
31+
//===================================================================================//
32+
// Globals
33+
1434
// Declare the RS485 interface here with a hardware serial port.
15-
RS485Class RS485 (Serial1, 2, 3, 4); // DE, RE, TX
35+
RS485Class RS485 (Serial1, PIN_RS485_DE, PIN_RS485_RE, PIN_RS485_TX); // DE, RE, TX
1636

1737
/* // If you want to use a software serial port, declare it here,
1838
// comment out the previous declaration, and uncomment this section.
1939
#include <SoftwareSerial.h>
2040
21-
SoftwareSerial mySerial (10, 11); // RX, TX
22-
RS485Class RS485 (mySerial, 2, 3, 4); // DE, RE, TX */
41+
SoftwareSerial mySerial (PIN_RS485_RX, PIN_RS485_TX); // RX, TX
42+
RS485Class RS485 (mySerial, PIN_RS485_DE, PIN_RS485_RE, PIN_RS485_TX); // DE, RE, TX */
43+
44+
//===================================================================================//
2345

2446
void setup() {
2547
Serial.begin (9600);
2648
RS485.begin (9600);
2749

50+
// // Optional for ESP32. Set the serial port pins here.
51+
// // SetPins can be called after or before begin() for ESP32.
52+
// Serial1.setPins (PIN_RS485_RX, PIN_RS485_TX);
53+
2854
// Enable transmission. Can be disabled with: RS485.endTransmission();
2955
RS485.beginTransmission();
3056

3157
// Enable reception. Can be disabled with: RS485.noReceive();
3258
RS485.receive();
3359
}
3460

61+
//===================================================================================//
62+
3563
void loop() {
64+
// Read from the default serial port and send the data to the RS485 port.
3665
if (Serial.available()) {
3766
RS485.write (Serial.read());
3867
}
3968

69+
// Read from the RS485 port and send the data to the default serial port.
4070
if (RS485.available()) {
4171
Serial.write (RS485.read());
4272
}
4373
}
74+
75+
//===================================================================================//
Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,70 @@
11

22
//===================================================================================//
3-
/**
4-
* @file RS485_Sender.ino
5-
* @brief RS-485 Sender for ESP8266 series boards.
6-
*
7-
* This sketch prints any data received from the RS-485 interface to the Serial port.
8-
*
9-
* @date +05:30 08:56:13 PM 27-10-2024, Sunday
10-
* @author Vishnu Mohanan (@vishnumaiea)
11-
* @par GitHub Repository: https://github.com/CIRCUITSTATE/CSE_ArduinoRS485
12-
* @par MIT License
13-
*
14-
*/
3+
/*
4+
Filename: RS485_Receiver.ino [ESP32]
5+
Description: Example Arduino program from the CSE_ArduinoRS485 Arduino library.
6+
Receives data from the RS485 port and sends it to the default serial port.
7+
8+
This example was written for and tested with the FireBeetle-ESP32E (ESP32).
9+
10+
Framework: Arduino, PlatformIO
11+
Author: Vishnu Mohanan (@vishnumaiea, @vizmohanan)
12+
Maintainer: CIRCUITSTATE Electronics (@circuitstate)
13+
Version: 1.0.14
14+
License: MIT
15+
Source: https://github.com/CIRCUITSTATE/CSE_ArduinoRS485
16+
Last Modified: +05:30 21:56:25 PM 20-03-2025, Thursday
17+
*/
1518
//===================================================================================//
1619

1720
#include <CSE_ArduinoRS485.h>
1821

22+
//===================================================================================//
23+
// Macros and constants
24+
1925
// You can define the serial port pins here.
20-
#define PIN_RS485_RX 16
21-
#define PIN_RS485_TX 17
26+
#define PIN_RS485_DE 16
27+
#define PIN_RS485_RE 17
28+
#define PIN_RS485_RX 9
29+
#define PIN_RS485_TX 10
30+
31+
//===================================================================================//
32+
// Globals
33+
34+
// Declare the RS485 interface here with a hardware serial port.
35+
RS485Class RS485 (Serial1, PIN_RS485_DE, PIN_RS485_RE, PIN_RS485_TX); // DE, RE, TX
36+
37+
/* // If you want to use a software serial port, declare it here,
38+
// comment out the previous declaration, and uncomment this section.
39+
#include <SoftwareSerial.h>
2240
23-
// // Use the software serial port for the RS485 interface and the hardware serial port for
24-
// // the debugging output.
25-
// SoftwareSerial softSerial (PIN_RS485_RX, PIN_RS485_TX, false); // RX, TX
41+
SoftwareSerial mySerial (PIN_RS485_RX, PIN_RS485_TX); // RX, TX
42+
RS485Class RS485 (mySerial, PIN_RS485_DE, PIN_RS485_RE, PIN_RS485_TX); // DE, RE, TX */
2643

27-
// Use the software serial port to create a new RS485 object.
28-
RS485Class RS485 (Serial1, -1, -1, PIN_RS485_TX); // DE, RE, TX
44+
//===================================================================================//
2945

3046
void setup() {
3147
Serial.begin (9600);
32-
while (!Serial);
33-
3448
RS485.begin (9600);
3549

50+
// // Optional for ESP32. Set the serial port pins here.
51+
// // SetPins can be called after or before begin() for ESP32.
52+
// Serial1.setPins (PIN_RS485_RX, PIN_RS485_TX);
53+
54+
// Enable transmission. Can be disabled with: RS485.endTransmission();
55+
RS485.beginTransmission();
56+
3657
// Enable reception. Can be disabled with: RS485.noReceive();
3758
RS485.receive();
3859
}
3960

61+
//===================================================================================//
62+
4063
void loop() {
64+
// Read from the RS485 port and send the data to the default serial port.
4165
if (RS485.available()) {
4266
Serial.write (RS485.read());
4367
}
4468
}
4569

70+
//===================================================================================//
Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,61 @@
1-
/*
2-
RS-485 Sender
3-
4-
This sketch periodically sends a string over the RS-485 interface
51

6-
Originally created by Sandeep Mistry, on 4 July 2018.
7-
Modified by @vishnumaiea for CIRCUITSTATE Electronics (@circuitstate).
2+
//===================================================================================//
3+
/*
4+
Filename: RS485_Sender.ino [ESP32]
5+
Description: Example Arduino program from the CSE_ArduinoRS485 Arduino library.
6+
Periodically sends "Hello" string to the RS485 port.
87
8+
This example was written for and tested with the FireBeetle-ESP32E (ESP32).
9+
10+
Framework: Arduino, PlatformIO
11+
Author: Vishnu Mohanan (@vishnumaiea, @vizmohanan)
12+
Maintainer: CIRCUITSTATE Electronics (@circuitstate)
13+
Version: 1.0.14
14+
License: MIT
915
Source: https://github.com/CIRCUITSTATE/CSE_ArduinoRS485
10-
*/
16+
Last Modified: +05:30 22:39:26 PM 20-03-2025, Thursday
17+
*/
18+
//===================================================================================//
1119

1220
#include <CSE_ArduinoRS485.h>
1321

14-
int counter = 0;
22+
//===================================================================================//
23+
// Macros and constants
24+
25+
// You can define the serial port pins here.
26+
#define PIN_RS485_DE 16
27+
#define PIN_RS485_RE 17
28+
#define PIN_RS485_RX 9
29+
#define PIN_RS485_TX 10
30+
31+
//===================================================================================//
32+
// Globals
33+
34+
// Declare the RS485 interface here with a hardware serial port.
35+
RS485Class RS485 (Serial1, PIN_RS485_DE, PIN_RS485_RE, PIN_RS485_TX); // DE, RE, TX
1536

16-
// If you want to use a software serial port, uncomment the following line.
17-
// SoftwareSerial Serial1 (10, 11); // RX, TX
37+
/* // If you want to use a software serial port, declare it here,
38+
// comment out the previous declaration, and uncomment this section.
39+
#include <SoftwareSerial.h>
1840
19-
// For using Hardware serial ports, the following line is enough. The port should already exist in the board definitions.
20-
RS485Class RS485 (Serial1, 2, 3, 4); // DE, RE, TX
41+
SoftwareSerial mySerial (PIN_RS485_RX, PIN_RS485_TX); // RX, TX
42+
RS485Class RS485 (mySerial, PIN_RS485_DE, PIN_RS485_RE, PIN_RS485_TX); // DE, RE, TX */
43+
44+
int counter = 0;
45+
46+
//===================================================================================//
2147

2248
void setup() {
23-
// Initialize the RS485 interface
49+
Serial.begin (9600);
2450
RS485.begin (9600);
51+
52+
// // Optional for ESP32. Set the serial port pins here.
53+
// // SetPins can be called after or before begin() for ESP32.
54+
// Serial1.setPins (PIN_RS485_RX, PIN_RS485_TX);
2555
}
2656

57+
//===================================================================================//
58+
2759
void loop() {
2860
RS485.beginTransmission();
2961
RS485.print ("Hello ");
@@ -34,3 +66,5 @@ void loop() {
3466

3567
delay (1000);
3668
}
69+
70+
//===================================================================================//
Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,44 @@
11

22
//===================================================================================//
3-
/**
4-
* @file RS485_Passthrough.ino
5-
* @brief RS-485 Passthrough for ESP8266 series boards.
6-
*
7-
* This sketch relays data sent and received between the default Serial port and
8-
* the RS-485 interface.
9-
*
10-
* @date +05:30 08:58:44 PM 27-10-2024, Sunday
11-
* @author Vishnu Mohanan (@vishnumaiea)
12-
* @par GitHub Repository: https://github.com/CIRCUITSTATE/CSE_ArduinoRS485
13-
* @par MIT License
14-
*
15-
*/
3+
/*
4+
Filename: RS485_Passthrough.ino [ESP8266]
5+
Description: Example Arduino program from the CSE_ArduinoRS485 Arduino library.
6+
Acts as a passthrough to send and receive data to and from an RS485 port.
7+
8+
This example was written for and tested with the NodeMCU-ESP12E (ESP8266).
9+
10+
Framework: Arduino, PlatformIO
11+
Author: Vishnu Mohanan (@vishnumaiea, @vizmohanan)
12+
Maintainer: CIRCUITSTATE Electronics (@circuitstate)
13+
Version: 1.0.14
14+
License: MIT
15+
Source: https://github.com/CIRCUITSTATE/CSE_ArduinoRS485
16+
Last Modified: +05:30 22:36:11 PM 20-03-2025, Thursday
17+
*/
1618
//===================================================================================//
1719

1820
#include <CSE_ArduinoRS485.h>
1921

22+
//===================================================================================//
23+
// Macros and constants
24+
2025
// You can define the serial port pins here.
26+
// #define PIN_RS485_DE 16
27+
// #define PIN_RS485_RE 17
2128
#define PIN_RS485_RX 14
2229
#define PIN_RS485_TX 12
2330

31+
//===================================================================================//
32+
2433
// Use the software serial port for the RS485 interface and the hardware serial port for
2534
// the debugging output.
2635
SoftwareSerial softSerial (PIN_RS485_RX, PIN_RS485_TX, false); // RX, TX
2736

2837
// Use the software serial port to create a new RS485 object.
2938
RS485Class RS485 (softSerial, -1, -1, PIN_RS485_TX); // DE, RE, TX
3039

40+
//===================================================================================//
41+
3142
void setup() {
3243
Serial.begin (9600);
3344
RS485.begin (9600);
@@ -39,12 +50,18 @@ void setup() {
3950
RS485.receive();
4051
}
4152

53+
//===================================================================================//
54+
4255
void loop() {
56+
// Read from the default serial port and send the data to the RS485 port.
4357
if (Serial.available()) {
4458
RS485.write (Serial.read());
4559
}
4660

61+
// Read from the RS485 port and send the data to the default serial port.
4762
if (RS485.available()) {
4863
Serial.write (RS485.read());
4964
}
5065
}
66+
67+
//===================================================================================//

0 commit comments

Comments
 (0)