Due to its fast communication, stability, reliability, and safety, it is an ideal choice for industrial control equipments andor applications with high communication requirements.Select the correct COM port (according to Devices Manager), set baud rate to 9600.This is one way of expanding the Industruinos number of IO pins.The registers use 16-bit integers so can be used for digital as well as analog data values.
![]() It is the resting period between requests from the master to allow a slave to enter its idle state. This is because a slave also runs on an FSM and can only start responding to a request once the idle state is reached. Rather use millis() to form some sort of crude multi-tasking. In Visuino you can also see it plotted in the Scope ( Picture 3 ). The RS485 is a very convenient way to connect the boards with just 2 wires, and can work to a distance of 1200m ( 4000 ft ). It also allows multiple boards to be connected easily to the same 2 wires. The downside is that the channel is shared between multiple devices, and only one of them can transmit at a time. There are cheap readily available, easy to use modules based on the Maxim Integrated MAX485 chip, and with the help of Visuino a graphical development environment for Arduino it is also very easy to program the communication. In this Instructable I will show you how easy it is to connect Arduino Nano and Arduino Mega with RS485, and have the Arduino Nano send data from a sensor to the Arduino Mega, and the Arduino Mega to control the LED on the Arduino Nano, while also sending the data received from the Nano to a Serial Terminal. Arduino Modbus 485 Download Step 6Make sure the wire has a good electrical connection with the metal plate in the jumper Repeat the same steps from 1 to 6 for the other RS485 Module and the Arduino Nano board Add Tip Ask Question Comment Download Step 6: Connect the Two RS485 Modules to Each Other The RS485 uses only 2 wires. Connect one end of a Female-Female jumper wire - A wire ( White wire ) to the A pin of one of the RS485 Modules ( Picture 2 and 3 ) Connect one end of another Female-Female jumper wire - B wire ( Brown wire ) to the B pin of one of the RS485 Modules ( Picture 2 and 3 ) Connect other end of a A wire ( White wire ) to the A pin of the other RS485 Module ( Picture 2 and 3 and 4 ) Connect other end of a B wire ( Brown wire ) to the B pin of the other RS485 Module ( Picture 2 and 3 and 4 ) Add Tip Ask Question Comment Download Step 7: Start Visuino, and Select the Arduino Nano Board Type To start programming the Arduino, you will need to have the Arduino IDE installed from here. Please be aware that there are some critical bugs in Arduino IDE 1.6.6. Make sure that you install 1.6.7 or higher, otherwise this Instructable will not work The Visuino: also needs to be installed. Arduino Modbus 485 Serial The ValueStart Visuino as shown in the first picture Click on the Tools button on the Arduino component ( Picture 1 ) in Visuino When the dialog appears, select Arduino Nano as shown in Picture 2 Add Tip Ask Question Comment Download Step 8: In Visuino: Add and Connect Analog Snapshot, and Clock Generator Components We will send to the serial the value of Analog Channel 0 once a second. For this we need to use Analog Snapshot component, and to clock it once a second with the Clock Generator: Type snap in the Filter box of the Component Toolbox then select the Analog Snapshot component ( Picture 1 ), and drop it in the design area Connect the Out pin of the Digital 14 AnalogIn 0 channel of the Arduino component to the In pin of the AnalogSnapshot1 component ( Picture 2 ) Connect the Out output pin of the AnalogSnapshot1 component ( Picture 3 ) to the In input pin of the Serial 0 channel of the Arduino component ( Picture 4 ) Type clock in the Filter box of the Component Toolbox then select the Clock Generator component ( Picture 5 ), and drop it in the design area Connect the Out output pin of the ClockGenerator1 component to the Snapshot input pin of the AnalogSnapshot1 component ( Picture 6 ) Add Tip Ask Question Comment Download Step 9: In Visuino: Connect the Sending Pin of the Serial to the Digital 2 Pin to Control the RS485 Direction The RS485 uses the same shared channel for both sending and receiving data. This means that the board cant send and receive data at the same time, and the RS485 module needs to be switched between transmitting and receiving mode. The Serial port of the Arduino component in Visuino has a pin indicating that the port is sending data. We will use this pin to control the direction (TransmitReceive) of the RS485 module. Connect the Sending output pin of the Serial 0 channel of the Arduino component to the Digital input pin of the Digital 2 channel of the Arduino component ( Picture 1 ) Add Tip Ask Question Comment Download Step 10: In Visuino: Add and Connect Char to Text Component We will receive 2 text commands (on and off) through the Serial port controlling the LED on pin 13. Arduino Modbus 485 Code The OnTo decode the on command we first will construct a text from the arriving characters followed by EnterNew Line by using a Char To Text component: Type char in the Filter box of the Component Toolbox then select the Char To Text component ( Picture 1 ), and drop it in the design area Connect the Out pin of the Serial 0 channel of the Arduino component to the In pin of the CharToText1 component Add Tip Ask Question Comment Download Step 11: In Visuino: Add and Connect Compare Text Value Component Now that we have the text we need to check if it is on or off. For this we need to connect the two ports: Connect the Out output pin of the Serial 1 channel of the Arduino component to the In input pin of the Serial 0 channel of the Arduino component ( Picture 4 ) Add Tip Ask Question Comment Download Step 15: In Visuino: Connect the Sending Pin of the Serial 1 to the Digital 2 Pin to Control the RS485 Direction Since the RS485 uses the same shared channel for both sending and receiving data we will use the Sending pin of the Serial Channel 1 to control the direction (TransmitReceive) of the RS485 module: Connect the Sending output pin of the Serial 1 channel of the Arduino component to the Digital input pin of the Digital 2 channel of the Arduino component ( Picture 1 ) Add Tip Ask Question Comment Download Step 16: In Visuino: Add and Connect Delay Component We want to send onoff command for the LED to flip it after every value we receive over the RS485. Since the RS485 is simplex, it is better to wait for it to properly switch before we send any data. For this we can use a Delay component set to 100 Milliseconds (100000 Microseconds): Type delay in the Filter box of the Component Toolbox then select the Delay component ( Picture 1 ), and drop it in the design area In the Object Inspector, set the value of the Interval property to 100000 ( Picture 2 ) Connect the Out pin of the Serial 1 channel of the Arduino component to the In pin of the Delay1 component ( Picture 3 ) Add Tip Ask Question Comment Download Step 17: In Visuino: Add and Connect T Flip Flop Component We want to switch between on, and off command every time a new text arrives over the serial. The most convenient for this purpose is the Toggle(T)-FlipFlop: Type flip in the Filter box of the Component Toolbox then select the Toggle(T) Flip-Flop component ( Picture 1 ), and drop it in the design area Connect the Out pin of the Delay1 to the In pin of the T FlipFlop1 ( Picture 2 ) Add Tip Ask Question Comment Download Step 18: In Visuino: Add and Connect Digital to Text Component The Flip-Flop will generate Digital(Boolean) value switching between True and False. For this we will use Digital To Text component: Type To Text in the Filter box of the Component Toolbox then select the Digital To Text component ( Picture 1 ), and drop it in the design area In the Object Inspector, set the value of the FalseValue property to off ( Picture 2 ) In the Object Inspector, set the value of the TrueValue property to on ( Picture 3 ) Connect the Out pin of the TFlipFlop1 component to the In pin of the DigitalToText1 component ( Picture 4 ) Connect the Out output pin of the DigitalToText1 component to the In input pin of the Serial 1 channel of the Arduino component ( Picture 4 ) Add Tip Ask Question Comment Download Step 19: Generate, Compile, and Upload the Arduino Code to the Arduino Mega In Visuino, Press F9 or click on the button shown on Picture 1 to generate the Arduino code, and open the Arduino IDE Connect the Arduino Mega with the USB cable to the computer In the Arduino IDE select the board type as Arduino Mega ( Picture 2 ) In the Arduino IDE select the serial port to which the Arduino Mega board is connected ( Picture 3 ) In the Arduino IDE, click on the Upload button, to compile and upload the code ( Picture 4 ) Add Tip Ask Question Comment Download Step 20: And Play. Congratulations You have implemented RS485 communication between 2 Arduino boards. Picture 1 and the Video show the connected and powered up project. If you connect to the Arduino Mega with Serial Terminal or Visuino you will see the position of the potentiometer displayed in text form ( Picture 2 ).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |