Created
October 26, 2015 16:19
-
-
Save Justasic/7d41d1af7bd6d825d2d3 to your computer and use it in GitHub Desktop.
An arduino program that will bridge a UART and USB serial interface using an Arduino and software serial.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This is a basic Arduino program to read the UART serial interface on an old | |
SpeedStream 5360 DSL modem I have. The code sets up a UART software serial | |
interface using the Arduino's 2 and 3 pins as RX and TX. | |
This program bridges the serial interfaces between USB and the UART software | |
serial. This will allow communication between the 3 devices. | |
This example code is in the public domain. | |
*/ | |
#include <SoftwareSerial.h> | |
// These constants won't change. They're used to give names | |
// to the pins used: | |
const int TX = 3; // Transmit | |
const int RX = 2; // Receive | |
SoftwareSerial myserial(RX, TX); | |
void setup() { | |
Serial.begin(9600); | |
while (!Serial) { | |
; // wait for serial port to connect. Needed for native USB port only | |
} | |
// initialize serial communications at 9600 bps: | |
myserial.begin(9600); | |
Serial.println("Hello from Arduino"); | |
} | |
void serialEvent() | |
{ | |
String TXData = Serial.readStringUntil('\n'); | |
if (TXData.length()) | |
{ | |
Serial.println(""); | |
Serial.print("<- "); | |
Serial.print(TXData); | |
Serial.println(""); | |
myserial.print(TXData); | |
} | |
} | |
void loop() { | |
myserial.listen(); | |
// Receive data | |
while (myserial.available() > 0) | |
Serial.write(myserial.read()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment