How to Use Modbus With Arduino (2024)

How to Use Modbus With Arduino (1)

By Zihatec in CircuitsArduino

106,335

22

3

Introduction: How to Use Modbus With Arduino

Modbus is a serial communication standard and has become a de facto standard communication protocol and is now a commonly available means of connecting industrial electronic devices. In Modbus RTU and Modbus ASCII RS485 is used as the physical layer. Its possible to use an Arduino as Slave (and with some restrictions also as Master) in Modbus applications, but a RS485 interface is needed. Our RS422 / RS485 Serial Shield is a fully galvanic isolated serial communication HAT designed for use with the Arduino UNO and other compatible boards like Arduino 101, STM Nucleo ... This shield the perfect choice for such kind of applications.
The objective of this document is to show how to create together with an Arduino UNO a simple Modbus slave device. We will use a PC as Modbus master.

Check out our too!

Step 1: Tools & Software

Tools & Materials

Optional:

  • Breadboard
  • push button
  • Red LED
  • 220 Ohm Resistor
  • 10k Resistor
  • Jumper wires

Software

Step 2: Wiring RS485

The wiring is very simple. You have to connect only the A and B terminals of the HAT with the A and B line of the Modbus system. Y and Z terminals are not used for this kind of application. For long distances it is recommend to use twisted pairs for A and B.

Step 3: Wiring Arduino (optional)

It's recommend to add a LED and a button to the Arduino to see some effects of the MODBUS communication. It's optional and not necessary needed.

Step 4: DIP Switch Settings

Our RS422/RS485 Shield comes with 3 DIP switch banks. You have to set these DIP switches for Modbus as shown in the picture above.


Switch 1:1-OFF 2-ON 3-ON 4-OFF

Switch 2: 1-OFF 2-OFF 3-ON 4-ON

Switch 3: 1-OFF or ON* 2-OFF 3-OFF 4-OFF

*Depending of the position of the RS422/RS485 Shield in the Modbus line you have to switch the terminating resistor ON or OFF. Please switch the resistor to ON position only if the Shield is on one end of the bus line. In all other cases switch the terminating resistor OFF:

Step 5: Jumper Settings

You can find 3 different jumper areas on the shield. Very important is the Jumper JP1 for the power supply voltage. The Arduino UNO works with 5V internally. You have to set this Jumper to the 5V position (for 3.3V boards for example Arduino 101 to the 3.3V position).

Furthermore set the jumpers for the communication ports in the upper left corner as in the picture above. The internal UART on port 0 and 1 will be connected in this case to the RS485 interface of the shield.

Last but not least we have to set Jumper for the RX/TX control port.We don't use this Jumper, because the automatic RX/TX switching is configured.

Step 6: Install MODBUS Tester Software

We will use in this example the PC as MODBUS master. You've to download Modbustester. Please unpack the zip archive to a new directory on your harddisk. Open the software and change the marked fields as in the picture above. You have to connect the USB-RS485-adaptor bevore- Please choose the right COM-port for this adaptor in Modbustester.

Step 7: Arduino Software

We have 3 sample programs for Arduino UNO, Genuino 101 and STM Nucleo. Please load them into the Arduino IDE for compiling and programming.

These programs are very simple and give you an idea about the basic function of the MODBUS communication. You can add further function if you want.

Don't forget to install the library SimpleModbus before compiling:

https://github.com/angeloc/simplemodbusng

Attachments

  • SimpleModbusSlaveExampleUNO.zip

    Download

  • SimpleModbusSlaveExampleSTM.zip

    Download

  • SimpleModbusSlaveExample101.zip

    Download

Step 8: Test Your Work

Now its time to test your work!

You can press the Read button in Modbustester. This command will read 8 bytes of the memory of our new slave device. In address 400008 you can find the status of the button. The address 400001 - 400006 contains values of the ADC ports.

With the write button you can manipulate registers in the slave. You can enter in address 400007 a 0 or 1 to switch the LED ON or OFF.

Good luck!

Test of new rs422 / rs485 usb adaptor and Arduino shield with Modbus protocol www.hwhardsoft.de #modbus #RS485 #rs422 #arduino #usb #zihatec #dinrailmounting #dinrail

How to Use Modbus With Arduino (2024)
Top Articles
Social Media Marketing: Qué es y cómo implementarlo
Organigrama Empresarial de Jumex 2021: Elementos, Funciones, Características y plantilla
Blorg Body Pillow
Camera instructions (NEW)
Mychart Mercy Lutherville
Big Y Digital Coupon App
Jefferson County Ky Pva
Optum Medicare Support
Craigslistdaytona
Southland Goldendoodles
Gina's Pizza Port Charlotte Fl
Bernie Platt, former Cherry Hill mayor and funeral home magnate, has died at 90
979-200-6466
The Largest Banks - ​​How to Transfer Money With Only Card Number and CVV (2024)
Michigan cannot fire coach Sherrone Moore for cause for known NCAA violations in sign-stealing case
Ess.compass Associate Login
라이키 유출
Nick Pulos Height, Age, Net Worth, Girlfriend, Stunt Actor
Noaa Ilx
No Hard Feelings - Stream: Jetzt Film online anschauen
Lakers Game Summary
U Of Arizona Phonebook
Talkstreamlive
UMvC3 OTT: Welcome to 2013!
Craigslist Illinois Springfield
683 Job Calls
Mini Handy 2024: Die besten Mini Smartphones | Purdroid.de
Black Panther 2 Showtimes Near Epic Theatres Of Palm Coast
Taktube Irani
Xfinity Outage Map Lacey Wa
De beste uitvaartdiensten die goede rituele diensten aanbieden voor de laatste rituelen
About Us | SEIL
Santa Cruz California Craigslist
Indiefoxx Deepfake
Taylor University Baseball Roster
How Many Dogs Can You Have in Idaho | GetJerry.com
Obituaries in Hagerstown, MD | The Herald-Mail
Weather Underground Cedar Rapids
Traumasoft Butler
Rush Copley Swim Lessons
Exam With A Social Studies Section Crossword
Sapphire Pine Grove
Bedbathandbeyond Flemington Nj
Craigslist Pets Charleston Wv
Pilot Travel Center Portersville Photos
Superecchll
Strange World Showtimes Near Century Federal Way
Glowforge Forum
BYU Football: Instant Observations From Blowout Win At Wyoming
Denys Davydov - Wikitia
683 Job Calls
Latest Posts
Article information

Author: Mrs. Angelic Larkin

Last Updated:

Views: 5645

Rating: 4.7 / 5 (47 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Mrs. Angelic Larkin

Birthday: 1992-06-28

Address: Apt. 413 8275 Mueller Overpass, South Magnolia, IA 99527-6023

Phone: +6824704719725

Job: District Real-Estate Facilitator

Hobby: Letterboxing, Vacation, Poi, Homebrewing, Mountain biking, Slacklining, Cabaret

Introduction: My name is Mrs. Angelic Larkin, I am a cute, charming, funny, determined, inexpensive, joyous, cheerful person who loves writing and wants to share my knowledge and understanding with you.