Hi guys
So I have decided to connect my Teensys together with RS-485. I have made a start but not all is working smoothly.
The stuff I have read up on are:
RS 485 Wiring
Connections and circuitry needed
What the whole circuit should look like
Info about the RS85 transceiver
Teensy pins to use
I think I have the circuit set up correctly
See image:
(Ignore the loose wires on the left hand side of the top board)
Power (+ and -) is going from the Meanwell LRS-350-5(5V,60A) to 4 places.
1 - to the Master Teensy
2 - to the Slave Teensy
3 - to the top breadboard rail
4 - to the bottom breadboard rail
The top breadboard has the master Teensy(with the blue USB cable going into it/out) connected to the receiver
The transceiver has wires going to these pins on both of the Teensys (same for Master & Slave).
DI - Teensy pin 9
DE - Teensy pin 5
RE - connected to DE
RO - Teensy pin 10
The slave Teensy is the bottom one.
The transceivers are connected from A to A, and from B to B
Regarding the connections and wiring, does this all seem correct? Is there anything that needs changing?
I have not used any resistors because I think the transceivers already have 120R included so there is no need to attach further resistors, that is correct?
Second part, the coding
This is the current code I have:
My user declared fuction bit of the code I have just done blink,
however, how would I tell the slave to blink?
there is a slave code as well which I have not really touched, it is like this:
All in all, I think the wiring is fine, but I am struggling with the code now
What do I need to do to make the Master tell the slave to operate blink for 1s intervals. I will expand upon that, but I feel this is a good start point.
I am decent with coding, but I have never communicated with another device before so this is new territory for me
So I have decided to connect my Teensys together with RS-485. I have made a start but not all is working smoothly.
The stuff I have read up on are:
RS 485 Wiring
Connections and circuitry needed
What the whole circuit should look like
Info about the RS85 transceiver
Teensy pins to use
I think I have the circuit set up correctly
See image:
(Ignore the loose wires on the left hand side of the top board)
Power (+ and -) is going from the Meanwell LRS-350-5(5V,60A) to 4 places.
1 - to the Master Teensy
2 - to the Slave Teensy
3 - to the top breadboard rail
4 - to the bottom breadboard rail
The top breadboard has the master Teensy(with the blue USB cable going into it/out) connected to the receiver
The transceiver has wires going to these pins on both of the Teensys (same for Master & Slave).
DI - Teensy pin 9
DE - Teensy pin 5
RE - connected to DE
RO - Teensy pin 10
The slave Teensy is the bottom one.
The transceivers are connected from A to A, and from B to B
Regarding the connections and wiring, does this all seem correct? Is there anything that needs changing?
I have not used any resistors because I think the transceivers already have 120R included so there is no need to attach further resistors, that is correct?
Second part, the coding
This is the current code I have:
Code:
#include <SoftwareSerial.h>
#define SSerialRX 9 //Serial Receive pin
#define SSerialTX 10 //Serial Transmit pin
#define SSerialTxControl 5 //RS485 Direction control
#define RS485Transmit HIGH
#define RS485Receive LOW
#define Pin13LED 13
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX
int byteReceived;
int byteSend;
void setup()
{
// Start the built-in serial port, probably to Serial Monitor
Serial.begin(9600);
Serial.println("YourDuino.com SoftwareSerial remote loop example");
Serial.println("Use Serial Monitor, type in upper window, ENTER");
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
}
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
digitalWrite(Pin13LED, HIGH); // Show activity
if (Serial.available())
{
byteReceived = Serial.read();
digitalWrite(SSerialTxControl, RS485Transmit); // Enable RS485 Transmit
RS485Serial.write(byteReceived); // Send byte to Remote Arduino
digitalWrite(Pin13LED, LOW); // Show activity
delay(10);
digitalWrite(SSerialTxControl, RS485Receive); // Disable RS485 Transmit
}
if (RS485Serial.available()) //Look for data from other Arduino
{
digitalWrite(Pin13LED, HIGH); // Show activity
byteReceived = RS485Serial.read(); // Read received byte
Serial.write(byteReceived); // Show on Serial Monitor
delay(10);
digitalWrite(Pin13LED, LOW); // Show activity
}
/*-----( Declare User-written Functions )-----*/
{
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
}
//*********( THE END )***********
My user declared fuction bit of the code I have just done blink,
however, how would I tell the slave to blink?
there is a slave code as well which I have not really touched, it is like this:
Code:
#include <SoftwareSerial.h>
#define SSerialRX 9 //Serial Receive pin
#define SSerialTX 10 //Serial Transmit pin
#define SSerialTxControl 5 //RS485 Direction control
#define RS485Transmit HIGH
#define RS485Receive LOW
#define Pin13LED 13
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX
int byteReceived;
int byteSend;
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 ******/
{
//Copy input data to output
if (RS485Serial.available())
{
byteSend = RS485Serial.read(); // Read the byte
digitalWrite(Pin13LED, HIGH); // Show activity
delay(10);
digitalWrite(Pin13LED, LOW);
digitalWrite(SSerialTxControl, RS485Transmit); // Enable RS485 Transmit
RS485Serial.write(byteSend); // Send the byte back
delay(10);
digitalWrite(SSerialTxControl, RS485Receive); // Disable RS485 Transmit
// delay(100);
}// End If RS485SerialAvailable
}//--(end main loop )---
/*-----( Declare User-written Functions )-----*/
//NONE
//*********( THE END )***********
All in all, I think the wiring is fine, but I am struggling with the code now
What do I need to do to make the Master tell the slave to operate blink for 1s intervals. I will expand upon that, but I feel this is a good start point.
I am decent with coding, but I have never communicated with another device before so this is new territory for me