Copy input data to output if (RS485Serial.
println( "SerialRemote") // Can be ignored pinMode(Pin13LED, OUTPUT) Connect this unit Pins 10, 11, Gnd - To other unit Pins 11,10, Gnd (Cross over) - Pin 3 used for RS485 direction control - Pin 13 LED blinks when data is received Questions: */ /*-( Import needed libraries )-*/ } //-(end main loop )- /*-( Declare User-written Functions )-*/ //NONE //*********( THE END )*********** Remote Arduino Sketch: /* YourDuino SoftwareSerialExample1Remote - Used with YD_SoftwareSerialExampleRS485_1 on another Arduino - Remote: Receive data, loop it back.
#Serial library arduino serial#
write(byteReceived) // Show on Serial Monitor delay(10) ĭigitalWrite(Pin13LED, LOW) // Show activity
available()) //Look for data from other ArduinoĭigitalWrite(Pin13LED, HIGH) // Show activityīyteReceived = RS485Serial. write(byteReceived) // Send byte to Remote Arduino digitalWrite(Pin13LED, LOW) // Show activity delay(10) ĭigitalWrite(SSerialTxControl, RS485Receive) // Disable RS485 Transmit available())ĭigitalWrite(SSerialTxControl, RS485Transmit) // Enable RS485 Transmit } //-(end setup )- void loop() /****** LOOP: RUNS CONSTANTLY ******/ĭigitalWrite(Pin13LED, HIGH) // Show activity if ( Serial.
#Serial library arduino software#
println( "Use Serial Monitor, type in upper window, ENTER") ĭigitalWrite(SSerialTxControl, RS485Receive) // Init Transceiver // Start the software serial port, to another device println( " SoftwareSerial remote loop example") Start the built-in serial port, probably to Serial Monitor Serial. SoftwareSerial RS485Serial(SSerialRX, SSerialTX) // RX, TX /*-( Declare Variables )-*/ int byteReceived #define SSerialTxControl 3 //RS485 Direction control #define SSerialTX 11 //Serial Transmit pin #define SSerialRX 10 //Serial Receive pin *-( Declare Constants and Pin Numbers )-*/ Should see same characters echoed back from remote Arduino Questions: */ /*-( Import needed libraries )-*/
Nick Gammon has a nice library that does this here: Master Arduino Sketch: /* YourDuino SoftwareSerialExample1 - Connect to another Arduino running "YD_SoftwareSerialExampleRS485_1Remote" - Connect this unit Pins 10, 11, Gnd - Pin 3 used for RS485 direction control - To other unit Pins 11,10, Gnd (Cross over) - Open Serial Monitor, type in top window. NOTE: A working system with your application running over multiple Arduinos should have some organized data movement and error-checking. You should see the Pin13 LED on the Remote Arduino blink as the data is received and sent back. Type in the top window of the Serial Monitor and it should be echoed back as it is sent to the second Arduino and looped back. You can do this by bringing up both connected Arduinos and running the Serial Monitor on the "Master". Keep track of which Arduino is on which Serial Port!). You can run two copies of the Arduino software at once if you wish. NOTE: It is possible to run two arduinos on the same host computer they will have individual Port Addresses. That Arduino sends the same data back to the Master Arduino where it is sent back to the Serial Monitor for you, the user to view. This port sends the data to a second remote Arduino over RS485. Another serial port is created with the Software Serial library, using pins 11 and 12. The example shown here uses the Arduino serial monitor to allow you to type in data to send to the Master Arduino. This allows use of almost any Arduino pins for Serial Data connections, and allows simultaneous use of the standard Arduino USB Serial communications. The example Software Sketches below use the Software Serial library that is provided with the Arduino IDE.
#Serial library arduino full#
See details of RS-485 communications with Half and Full Duplex, network configuration and more HERE: Example Software Sketches This means it can send or receive on the same wires, but in only one direction at a time. RS485 as we show it in this example is Half-Duplex. Gnd between distant Arduinos can be in cable or local electrical ground.DE (data enable) and RE (receive enable) jumpered together and to pin 3.Also note the connection details on the right photo and refer to the pin connections shown in the software examples below: In the example these are the red and green wires connected to A and B at the bottom. It also needs Ground - but that usually can be the local electrical ground, so only the two wires (usually a twisted pair in some type of cable) are needed. It also allows multiple senders/receivers along the same cable: RS485 uses a pair of wires in a Differential configuration that allows long distance communication (up to 1.2 Km) and very high speeds.