Using the RS232 PAL with Arduino involves wiring up the breakout to your Arduino-compatible microcontroller with an external RS-232 device and running the provided example code.
Wiring
Wire as shown for a 5V board like an Uno. If you are using a 3V board, like an Adafruit Feather, wire the board's 3V pin to the breakout VIN.
Here is an Adafruit Metro wired up to the breakout with an external RS-232 connection:
- Metro 5V to breakout Vin (red wire)
- Metro GND to breakout GND (black wire)
- Metro pin 2 to breakout low voltage R1 (green wire)
- Metro pin 3 to breakout low voltage T1 (blue wire)
- Breakout high voltage R1 to RS-232 RXD [pin 2 on DE-9] (white wire)
- Breakout high voltage T1 to RS-232 TXD [pin 3 on DE-9] (yellow wire)
- Breakout GND to RS-232 GND [pin 5 on DE-9] (black wire)
Here is an Adafruit Metro wired up using a solderless breadboard:
- Metro 5V to breakout Vin (red wire)
- Metro GND to breakout GND (black wire)
- Metro pin 2 to breakout low voltage R1 (green wire)
- Metro pin 3 to breakout low voltage T1 (blue wire)
- Breakout high voltage R1 to RS-232 RXD [pin 2 on DE-9] (white wire)
- Breakout high voltage T1 to RS-232 TXD [pin 3 on DE-9] (yellow wire)
- Breakout GND to RS-232 GND [pin 5 on DE-9] (black wire)
There are no additional libraries needed for this example.
Example Code
You can change the baud rate for your RS-232 device at the top of the code by editing the baud
define:
#define baud 38400
// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries // // SPDX-License-Identifier: MIT #include <SoftwareSerial.h> // update this for your RS-232 device baud rate #define baud 38400 // define RX and TX pins for the software serial port #define RS232_RX_PIN 2 #define RS232_TX_PIN 3 SoftwareSerial rs232Serial(RS232_RX_PIN, RS232_TX_PIN); void setup() { Serial.begin(115200); while ( !Serial ) delay(10); rs232Serial.begin(baud); Serial.println("Enter commands to send to the RS-232 device."); Serial.println(); } void loop() { if (Serial.available() > 0) { String userInput = Serial.readStringUntil('\n'); userInput.trim(); // remove any trailing newlines or spaces if (userInput.length() > 0) { // send the command with a telnet newline (CR + LF) rs232Serial.print(userInput + "\r\n"); Serial.print("Sent: "); Serial.println(userInput); } } // check for incoming data from RS-232 device while (rs232Serial.available() > 0) { char response = rs232Serial.read(); // print the incoming data Serial.print(response); } delay(50); }
Upload the sketch to your board and open up the Serial Monitor (Tools -> Serial Monitor) at 115200 baud. You can send commands to your RS-232 device via the Serial Monitor. If any messages are received from the RS-232 device, they will print to the Serial Monitor.
The commands that you send will vary by the RS-232 device that you connect to the RS232 Pal. The output above was sent to a StarTech HDMI switcher. The AVI=n
commands switch the selected HDMI port and the VS
command gives a current status of the device.
Text editor powered by tinymce.