Introduction: Arduino Atmega644/1284 Clone+ethernet Shield+advancedHMI+VB NET+MODBUS TCP

This project is a way to control an Arduino or my Arduino atmega644/1284 clone via a PC or a human machine interface connected to the arduino ethernet shield. You will create a SCADA system to control your system from a long distance.

Why did i create this clone of arduino? Just to have more inputs/outputs pins to control more complicated systems. These are the correlation beetween arduino uno pins and my atmega644/1284 clone pins:

D2 - Ethernet interrupt (optional with solder bridge "INT") (clone pin D10)
D4 - SD SPI CS (clone pin D0 )

D10 - Ethernet SPI CS (clone pin D4 )

D11 - Not connected (but should be SPI MOSI) (clone pin D5)

D12 - Not connected (but should be SPI MISO) ( clone pin D6)

D13 - SPI SCK ( clone pin D7 )

A0 - SD Write Protect (clone pin A0)

A1 - SD Detect (clone pin A1)

These pins are used for the communication beetween the clone and the ethernet, so you do not have to use it for anything else.

Why using MODBUS TCP communication? Because it's an easy and secured way to communicate with distant systems. The open source and free project AdvancedHmi has a driver wich provide this communication and arduino library to use is the "mudbus library" only. The others doesn't work because AdvancedHMI provide a MODBUS TCP not a MODBUS RTU OVER TCP nor a MODBUS RTU (serial com, but now with the new version of advancedHMI, not tested here). For more information on MODBUS go on http://www.simplymodbus.ca/TCP.htm.

The site for mudbus library:

https://code.google.com/p/mudbus/

The site for AdvancedHMI, a very catchy HMI go on:

http://www.advancedhmi.com

(you need to install Visual Basic Express 2010 or higher before running AdvancedHMI)

Ce projet va permettre de piloter un Arduino Uno ou l'Arduino atmega644/1284 clone que j'ai fabriqué dans un précédent article à l'aide d'une interface PC ou HMI via un ethernet shield sous le protocole MODBUS TCP. Cela permettra de réaliser un système de supervision ou SCADA.

Pourquoi le faire sur ce clone? Le board Arduino Uno possède un certain nombre d'entrées/sorties mais le fait de rajouter l'ethernet shield mobilise encore des bornes qui sont du coup inutilisables pour d'autres applications. Ces bornes sont pour l'arduino UNO (correspondance de l'arduino atmega644/1284 clone entre parenthèse) :

D2 - Ethernet interrupt (optional with solder bridge "INT") (D10 du clone)
D4 - SD SPI CS (D0 du clone)

D10 - Ethernet SPI CS (D4 du clone)

D11 - Not connected (but should be SPI MOSI) (D5 du clone)

D12 - Not connected (but should be SPI MISO) (D6 du clone)

D13 - SPI SCK (D7 du clone)

A0 - SD Write Protect (A0 du clone)

A1 - SD Detect (A1 du clone)

L'arduino clone avec ethernet shield me permettra de bénéficier de plus d'entrées/sorties. Ces bornes ne pourront être utilisées pour autres choses.

Pourquoi utiliser le modbus TCP? C'est un protocole de communication facile à mettre en oeuvre, robuste et très répandu dans l'industrie. L'interface du projet advancedHMI possède un driver qui gère ce protocole, de son côté l'Arduino reconnaît les trames grâce à la librairie "mudbus" à télécharger. Attention: ce n'est pas du modbus RTU over TCP (consulter la documentation suivante: http://www.simplymodbus.ca/TCP.htm).

Le site de la librairie mudbus pour arduino 1.0.5:

https://code.google.com/p/mudbus/

Le site AdvancedHMI (vous devez installer au préalable le logiciel gratuit Visual Basic Express 2010):

http://www.advancedhmi.com/

Step 1: Le Programme De L'arduino Atmega644/1284 Clone

The modbus TCP communication is done by read registers and written registers of 16 bits each that you have to create under the mudbus library in the arduino program like this:

Mb.R[0] to Mb.R[255] for example (for 16 bits registers)
Mb.C[0] to Mb.C[255] for example (for 1 bit registers)

You can use the register you want Mb.R[i] or Mb.C[i].

You can't reach directly the input or output pin of the clone so you need to use these registers.

In the progromed supplied for the clone, you need to know there is a different pin adressing beetween the arduino uno and the clone:

Exemple: Arduino Uno pin D8: connexion pin 20 of the atmega644/1284 clone :so address 14 (D14) (see the previous table in my arduino clone project).

In my simple program you 've got the way to use these register with inputs and outputs.

With the ethernet, remenber that you need to give an IP adresse to the shield. In my exemple:

uint8_t ip[] = { 192, 168, 1, 244};
uint8_t gateway[] = { 192, 168, 1, 1 };

uint8_t subnet[] = { 255, 255, 255, 0 };

See the supplied example.

Next, the link beetween arduino clone registers and AdvancedHMI widgets.

La communication modbus TCP se fera par l'intermédiaire de lecture ou d'écriture de registre 16 bits créés par la librairie mudbus de l'arduino et portant les noms de:

Mb.R[0] à Mb.R[255] par exemple

Mb.C[0] à Mb.C[255] par exemple

On peut utiliser indifféremment l'un ou l'autre de ces registres.

Les entrées/sorties de l'arduino ne peuvent pas être directement pilotable ou supervisées. Il faut obligatoirement passer par ces registres.

Dans le programme fourni pour l’arduino clone penser à prendre en compte le changement de pin :

Arduino Uno pin D8: connexion pin 20 atmega644/1284: d'où adresse 14 (D14).

L'exemple fourni vous donne la structure de base à employer pour gérer ces registres de communication.

Pour paramétrer l'ethernet shield, vous n'avez qu'à modifier les rubriques suivantes en fonction de votre réseau:

uint8_t ip[] = { 192, 168, 1, 244};
uint8_t gateway[] = { 192, 168, 1, 1 };

uint8_t subnet[] = { 255, 255, 255, 0 };

Je joins l'exemple.

Step 2: Aspect De L'interface AdvancedHMI

In this prototype HMI or SCADA, I just used:

-a switch button to control pin D8 arduino uno (or pin D14 atmega644/1284 clone). This output is control via the register Mb.R[8] (for example) and the link with the AdvancedHMI widget is the adress 40009 (for arduino uno) or 40015 (for atmega644/1284 clone).

-a 4 digits display with displays the value of the Mb.R[5] (for example) in the arduino program and the link with the AdvancedHMI widget is the adress 40006 (for arduino uno or for atmega644/1284 clone).

In AdvancedHMI remember you have to give to the ModbusTcpCom1 driver the IP adress of the arduino ethernet shield so 192.168.1.244 in my example.

Je me suis contenté seulement:

-un afficheur 4 digits affichant la valeur du registre Mb.R[5] (choisi arbitrairement) côté arduino et dont la correspondance est l'adresse 40006 vue par la HMI.

Penser à paramétrer le driver ModbusTcpCom1 avec l'adresse de votre shield (fixée par votre programme sous arduino 1.0.5).

Step 3: Modification De La Librairie Mudbus Pour Atmega 644p Et 1284p

WARNING: to adapt the mudbus library to the atmega644/1284 clone you need to modify the file arduino/libraries/Ethernet/utility/w5100.h and add this line:

… || defined(__AVR_ATmega1284P__) || defined (__AVR_ATmega644P__)

Now it's up to you.

ATTENTION: si vous utilisez la librairie mudbus pour l'arduino atmega644/1284 clone vous devez impérativement modifier le fichier arduino/libraries/Ethernet/utility/w5100.h sinon rien ne fonctionne.

Il suffit d'ajouter les lignes suivantes à un moment dans le programme:

… || defined(__AVR_ATmega1284P__) || defined (__AVR_ATmega644P__)

Maintenant vous pouvez essayer.

Step 4: Remerciements Et Perspectives:

A very small thanx to Arlindo Astyzem who runned this before me and never replied to my mails and never gave me any explanation:

Very big thanx and kisses to:

http://forum.arduino.cc/index.php?PHPSESSID=tm5f16...

I don't have tested the SD card using for the moment. I tested another HMI called UNIGO free version under android tab or phone and it runs very well on my SCADA controlled systems of my company.

Good instructables everybody!!!

Un petit remerciement pour Arlindo Astyzem qui a mis en place avant moi cette communication mais a toujours donnés des informations très lacunaires (il n'a jamais répondu à mes mails):

http://www.youtube.com/watch?v=LYPmNPIY4IY

Un super remerciement avec big kisses au forum suivant:

http://forum.arduino.cc/index.php?PHPSESSID=tm5f16dcvq0q8it99qno4mtl44&topic=192115.msg1419867#msg1419867

Je n'ai pas testé l'utilisation de la carte SD.

J'ai testé la librairie MODBUSslave pour arduino en tentant d'avoir la communication entre advancedHMI et l'arduino via un module TCP/serial RS232 mais c'est du modbus RTU et cela ne fonctionne pas. Cela m'aurait affranchi du shield Ethernet. En revanche cette communication a très bien fonctionné avec l'application UNIGO pour android qui elle, propose MODBUS TCP ou MODBUS RTU over TCP. J'attends avec impatience la nouvelle version du projet advancedHMI qui je l'espère intègrera cette fonctionnalité. Pour l'instant mon plancher en chêne est toujours aussi impeccable.

Bon instructable à tous!

Comments

author
hendi+afriyan made it!(author)2017-02-08

Sir why i can't upload your source code to my arduino mega2560.

error compiling: Wprogram.h: no such file or directory

author
Pixel_MNB made it!(author)2016-03-25

Bon travail manu4371 ! Je vais utiliser votre instructable comme un guide pour construire un système SCADA j'ai besoin! Puis-je vous demander si j'ai des questions?

Merci!

author
manu4371 made it!(author)2016-07-05

Hello Pixel_MNB,

Désolé pour ce retard de correspondance: j'ai été dépassé par certains instructables bientôt à paraitre. Merci de l'intérêt porté à ce projet qui peut donner des idées de pilotage à distance de plein de trucs automatisés. Si vous avez des questions, j'y répondrai volontiers dans la mesures du possible et cette fois je suivrai de près les commentaires de mes projets.

A bientôt and good instructables!!!

author
irinak1 made it!(author)2016-07-04

Hi,

I’m irinakim and I’m work in the Wiznet.

Thank you for using our product.

We are collecting so much data using ourproduct.

And I will post the this project on our Web site.( http://wiznetmuseum.com)

Can I post your product on our Web site?

author
manu4371 made it!(author)2016-07-05

Hi Irinak1!!!

You can do what you want with my project and I thank you to provide such a product so easy to use and connect with the arduino. It gives me a lot of idea to control automation systems like, a garage door, a thief detector, a robot... soon on Instructables.

Happy instructables!!

author
joko0124 made it!(author)2014-11-04

hello! even i don't understand this explanations/tutorials, i am so interested with this instructables. would you mind if i ask you to translate this in English? im a filipino and interested with your post. please if you can teach me about this, i will really apreciate it. thanks in advanced...

author
manu4371 made it!(author)2014-11-09

Hi Joko. Thanks for your interest. I'll translate all my instructables ASAP. For the moment, I try to post many explicit schematic and program to begin to wire and program your system controller. This project doesn't need too many codes to run: that an advantage of MODBUS TCP with advancedHMI (a very catchy SCADA, isn't it). Another advantage is the distance to control your system over ethernet.

To build this you have to read too my article about the arduino atmega 1284 clone.

I'll keep you in touch in the next month.

Best regards. Manu

author
joko0124 made it!(author)2014-11-10

tnx for your reply, if you don't mind, may you help me on my research on how to automate/computerized our manual system regarding pump operation? i'm a software developer on a water utility in our city and the biggest challenge on my part is to have a system that will not need personnel to manual check the water level system and etc. i hope you do understand what i'm trying to stress out. best regard my friend... thank you so much...

author
manu4371 made it!(author)2014-11-11

I think the best way to automate in a very cheap solution is obviously to use this kind of microcontroller. You have to check first how many input/output/logic or analog you need to choose atmega328 or 644 or 1284. Then you have design an interface beetween the atmega and the system to control this microcontroller because it runs under 5V max (i have some schematics i'll put on instructables), and then the program: the more suitable way to control is to use the FSM (finite state machine) library. It's like a sort of SFC (sequence functional chart): i'll do it recently with a light dimmer system simulating sunrise and sunset for exotic birds (soon on instructable).

FSM organises your different actions you want to do, conditioned by sensor to make automatic control.

And at the end perhaps you want to remote control or supervise with your phone in WIFI or bluetooth or over internet with vb.net (with modbus TCP or RS232 over IP for example). Your project is very interesting and usefull.

Let me know your solution you'll keep.

Best regards. Manu

author
stanleyaley made it!(author)2016-01-12

Hi manu4371!

I'm really thankful to find your post here. I've tried using your code, with an arduino UNO rev3 and also the w5100 Ethernet shield.

Unfortunately, I can't get any data on the VB. can you please help me? It's really crucial for me. If by anyhow you can send me the VB program, it'll be very helpful. thanks a bunch!

Best regards. Stanley

author
manu4371 made it!(author)2016-01-14

Hello Stanley,

I have just received your message. The code should run and i think perhaps it's due to wrong settings on your IP adress under advncedHMI project or on your PC.

You need also to use the port 502. I give you the link to download the advancedHMI project (version 3.99a) that you can open with the freeware Visual Studio Express (not visual basic express 2010 only for advancedHMI 3.7 or under)

http://sourceforge.net/projects/advancedhmi/

https://www.visualstudio.com/fr-fr/products/visual...

Once installed, in the folder advancedHMI, open the vbproj file ( I remember) and then go on the main form to put on it your buttons, driver...

I hope it will usefull.

Happy instructables!!!

author
stanleyaley made it!(author)2016-01-14

Hello manu, thanks for the reply!
I've finally get this project to work! It's working when i change the code in arduino from mb.C[5] = 6666 to mb.R[5] = 6666. The project won't run if I use the address mb.R[0] or mb.R[1] and i don't know why. Anyway, the project is finally done and I'm really gratefull to find your page! Thanks a bunch!!

About This Instructable

15,121views

27favorites

License:

More by manu4371:Arduino 1.8.x Clone With Atmega 8535/32/644p/1284p: the MightycoreArduino PLC 32 I/O+State Machine+SCADA or HMIArduino-tomation part 1
Add instructable to: