Serial Ports
This article explores the three serial ports on the Edge101 board, detailing their functions for USB, wireless modules, and RS485 interface, along with a practical code example for reading digital input signals.
Serial Ports
The Edge101 board has three serial ports: Serial, Serial1, and Serial2.
- Serial is connected to the USB interface for program downloading and code debugging. It will output basic information about the board upon power-up.
- Serial1 is used to extend the onboard wireless module or external serial devices.
- Serial2 is used for RS485 interface to connect industrial sensors, actuators, and other devices.
Example: Serial Read of User Button State
The following code demonstrates the functionality of reading the digital input signal from pin 38 and outputting the result to the serial monitor.
Hardware Preparation:
- ESP32 IoT Programmable Controller (SKU: DFR0886)×1
Sample Code:
/* Digital Input Read Example */
int pushButton = 38;
// Initialization function (runs once on reset):
void setup() {
// Initialize serial communication at a baud rate of 115200:
Serial.begin(115200);
// Set the button pin as input:
pinMode(pushButton, INPUT);
}
// Main loop function (runs repeatedly):
void loop() {
// Read the state of the input pin:
int buttonState = digitalRead(pushButton);
// Output the button state to the serial monitor:
Serial.println(buttonState);
delay(1); // Delay to ensure stable reading
}
Result:
When the onboard user button is not pressed, the serial monitor will display 1. When the button is pressed, the serial monitor will display 0.
Was this article helpful?
