Skip to content

Instantly share code, notes, and snippets.

@openopen114
Created September 23, 2016 03:36
Show Gist options
  • Save openopen114/122bf596badfe6c58818a4d2829bddeb to your computer and use it in GitHub Desktop.
Save openopen114/122bf596badfe6c58818a4d2829bddeb to your computer and use it in GitHub Desktop.
/*-----( Import needed libraries )-----*/
#include <SoftwareSerial.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define SSerialRX 10 //Serial Receive pin RO (receive out)
#define SSerialTX 11 //Serial Transmit pin DI (data in)
#define SSerialTxControl 3 //RS485 Direction control (DE&RE jump together to pin3)
#define RS485Transmit HIGH // status : send data via 485
#define RS485Receive LOW // status: Rcv data via 485
#define Pin13LED 13
/*-----( Declare objects )-----*/
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX
/*-----( Declare Variables )-----*/
char rcvData;
char sendData;
void setup() /****** SETUP: RUNS ONCE ******/
{
// Start the built-in serial port, probably to Serial Monitor
Serial.begin(9600);
Serial.println("SerialRemote"); // Can be ignored
pinMode(Pin13LED, OUTPUT);
pinMode(SSerialTxControl, OUTPUT);
digitalWrite(SSerialTxControl, RS485Receive); // Init Transceiver
// Start the software serial port, to another device
RS485Serial.begin(4800); // set the data rate
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
//digitalWrite(Pin13LED, HIGH); // Show activity
//Copy input data to output
// digitalWrite(SSerialTxControl, RS485Transmit);
if (RS485Serial.available()>0)
{
digitalWrite(Pin13LED, HIGH);
rcvData = RS485Serial.read(); // Read the byte
Serial.println("inbyteReceived:");
Serial.println(rcvData);
//digitalWrite(Pin13LED, LOW);
delay(1000);
digitalWrite(SSerialTxControl, RS485Transmit);
RS485Serial.write(rcvData);
digitalWrite(SSerialTxControl, RS485Receive);
}// End If RS485SerialAvailable
}//--(end main loop )---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment