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

About: Interest in PUNK/HARDCORE/METAL/HIGHLAND BAGPIPES

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!