Arduino and Mango

Hi All,

I’m looking for some help using Mango with my Leonardo Arduino. I’ve looked through the various posts on the Mango site on the subject but so far I’ve been unable to find a definative Modbus library and some sample code that will work for testing. I’ve downloaded the latest modbus_rtu_slave.pde and ModbusSlave.tar.gz from JPMzometa’s website but have been unable to get the sketch to compile and work with the library. I’ve also tried following a post off Mango’s site that had some sample code and links to the latest library but that also failed to compile. Can anyone please point me at the definative Modbus library version and a compatible sample sketch that I can use to engineer my project? I’m programming with Arduino version 1.0.5-r2.

I’m fairly new to Arduino, I’m just getting into it as a hobby but I’m an industrial automation engineer so I’m familiar with automation, PLC, SCADA concepts.

Any help or pointers would be truly appreciated.

Many thanks,

Lee

Hello Lee,

The JPMzometa's Library was written for Arduino version below 1.0.1. There are some incompatibilities when performing some Serial commands. Indeed I had been using it for a long time and I had a good experience with it. Some months ago I started to move it to something more definitive and here you can find its basis:

https://dl.dropboxusercontent.com/u/53529271/libmodbus_slave_example-140325b.zip

Its main purpose is to implement either a Modbus Master or a Modbus Slave in the same library. It works as most industrial PLCs do. This link points to an Slave. You have only to refresh the Modbus poll instance and to point to the right variables, as you may do in a PLC.

Best Regads,

SUBY

Hi Suby,

Thanks for the reply, it's much appreciated!

I've unzipped your example, although winACE reported problems unzipping the files... Any chance of a fresh zip file?

Can you please give me an explanation of what you have sent and what I need to do with the .ino files.

I'm still failing to get either the "main" or the "modbus" files to compile, both are reading issues with variables:

Main gives me: main:24: error: 'Modbus' does not name a type main.ino: In function 'void setup()': main:55: error: 'slave' was not declared in this scope main.ino: In function 'void loop()': main:64: error: 'slave' was not declared in this scope

and modbus gives me: Modbus.ino: In member function 'void Modbus::begin(long int)': Modbus:265: error: cannot convert 'Serial_' to 'HardwareSerial' in assignment Modbus.ino: In member function 'void Modbus::sendTxBuffer()': Modbus:711: error: 'UCSR0A' was not declared in this scope Modbus:711: error: 'TXC0' was not declared in this scope Modbus:742: error: 'UCSR0A' was not declared in this scope Modbus:742: error: 'TXC0' was not declared in this scope

There was a "libmodbus_slave_example.ino" also in the zip but this file was empty when opening it with the arduino UI.

When I said I was new to Arduino, i really mean a novice...

Many thanks,

Lee

Dear LeeOutram,

Try this:

https://dl.dropboxusercontent.com/u/53529271/libmodbus_slave_example-140210a.zip

I use Arduino IDE to zip sketches (as most PLC IDE's do).

The way to proceed must be:

1) You must keep the "libmodbus_slave_example" folder itself; 2) Go to ARDUINO IDE and open "libmodbus_slave_example.ino" file; 3) ARDUINO IDE should automatically load this file plus two other more, called MODBUS and MAIN; 4) MODBUS.ino contains the library and it is intended for a Master or an Slave. The Master isn't complete, but the Slave is fully functional; 5) MAIN.ino contains a simple program to test a Modbus Slave with an UNO board through USB; 6) LIBMODUBS_SLAVE_EXAMPLE.ino just declares an array which is being used in MAIN.ino; 7) Compile it and try to download it to your UNO board.

Tell me if you succeed or not.

Regards,

Hi Suby,

I was doing some investigation on how to use this example as you posted so I now understand the methodology of opening up the sketch with all three tabs...

The zip file you posted now opens with no problems, with all three tabs open but I still can't get it to compile the errors are: Modbus.ino: In member function 'void Modbus::begin(long int)': Modbus:214: error: cannot convert 'Serial_' to 'HardwareSerial' in assignment Modbus.ino: In member function 'void Modbus::sendTxBuffer()': Modbus:591: error: 'UCSR0A' was not declared in this scope Modbus:591: error: 'TXC0' was not declared in this scope Modbus:622: error: 'UCSR0A' was not declared in this scope Modbus:622: error: 'TXC0' was not declared in this scope

These declaration problems look to be the similar issues I had with PMzometa's examples, am I missing a library or something?

Thanks again for your help!

Best Regards,

Lee

Suby,

Noted that your example is for an UNO, I'm using a Leonardo. As a trial i changed the board type to UNO and it compiled without a problem. I guess there are differences between the Leonardo and UNO that won't let it compile for my board. Is there a workaround or some sections I can remove to get it working with the Leonardo?

Best Regards,

Lee

Lee,

I'm suprised to watch that it fails whenever the IDE tries to compile this code for a Leonardo based board. It's the first time I see it. :astonished:

As far I can understand, the IDE doesn't understand Serial pointer and there are some bytes used for RS-485 which aren't declared for the Leonardo.

Modbus.ino implements the Modbus library code and it is based on HardwareSerial instance, which allows to handle all the Arduino UARTs. I'm afraid that there may be something different regarding its UART implementation. The Leonardo Serial0 is the USB itself, while Serial1 is commonly Serial0 in the UNO.

http://arduino.cc/en/Main/ArduinoBoardLeonardo

We all should investigate a little more with the Leonardo.

Regards,

Hi Suby,

Thanks for the clarification!

After a little reading up on the boards between posts and investigation with the code, I’ve come to the conclusion that it doesn’t look like it will work - at least without someone more experienced than me having a look (and I really don’t want to get in that deep!) It looks one of the differences between the Leonardo and the UNO is the communications with the Leonardo being more addaptive for use as a USB peripheral and it looks like some of the functionality that the UNO possesses has been lost with this functionality.

No matter! They are cheep enough at the moment and there are plenty of people in the office that won’t take any persuading to take the Leo off my hands so i can replace it with an Uno.

Many thanks for taking the time to reply.

Best Regards,

Lee