S7 200 Modbus Slave Library Download
I have seen a few posts lately on MODBUS so I thought I might post what I use with arduino. The library I use is located here: I have multiple slaves running.
Download siemens s7 200 programming software for free. Development Tools downloads - STEP 7 MicroWIN by Automation Siemens and many more programs are available for instant and free download.
I use the code posted below on ALL of them, all I change is the slave ID. I keep all the pins the same, that way when I upload this code onto ANY arduino, it works.
You should not have to change ANYTHING ELSE! I also have this running over Xbee's through a Digi Connectport X4, which converts it to TCP. I then use Mango M2M as my SCADA package. How to speed up torch torrent. I can now get my Analog and digital data from anywhere in the world, or open and close my roller doors, anything.
I can even write Analog values. All my logic is done in Mango. You could probably do a mesh with a Xbee as a coordinator on a PC, transmitting to all the MODBUS slaves,(leave all destination addresses as zero's and set the slave Xbees to routers), but have not tried it because I have an X4 I DO NOT think you need to use RS485 for this. Just connect a PC straight up to your freshly programmed arduino, and run some sort of MODBUS master or test software, using the register number as listed in the code. Remember, in the SCADA software do not use the whole address number, for instance, to access pin 2, you would be reading a COIL on Slave 1 at address 2, not address 10002. Some SCADA packages use ZERO offsets, so subtract 1, so the address for pin 2 would be 1. Sorry for the belated reply.
The code and library above is for Modbus RTU over RS485. It is just the Digi Connectport that converts the RTU to TCP. You should be able to use this code with ANY SCADA system or HARDWARE that supports STANDARD MODBUS RTU registers and addressing.
Get an Arduino, ANY arduino. Load up the code as above. Add a RS-485 shield, and add a button to pin 2. Get a PC, and load up SCADA/HMI software that supports MODBUS RTU. Connect a RS232 to 485 converter OR a USB to RS485 converter. Connect it to the Arduino shield. In the SCADA software, add a data source as Com port(USB-485), Baud rate(9600), Slave Number(As per arduino code) and a 'TAG' or 'point' as an 'Input status',address(try 1 or 2) 7.
Go live with the SCADA software and press the button. It should be read in the software. Do the same with other arduino inputs, except for the data type. MODBUS DATA types: (Yea, I know there are others, but these are all we need) Input status = Read a arduino input (1 or 0) Coil status = Write a arduino output (1 or 0) Input register = Read adruino analog input (0 to 1023) Use 2 byte unsigned integer in TAG settings Holding register = Write arduino analog output (0 to 255) Use 2 byte unsigned integer in TAG settings Remember, get rid of the RS-485 if you only have one slave!, it is used because 485 supports multidrop, this is where the slave ID's come in.
You can do SO MUCH with MODBUS and ARDUINO. I have soil moisture, voltage, lux, temperature, humidity values all coming in flawlessly. I can open and close roller doors, lights on and off, set lights to a certain brightness.what next.imagine.
As far as the Siemens PLC goes, you can't use arduino with it unless you use the arduino as a master, and I don't see the point. H PS If I have missed anything, I apologise. For anyone interested in an AWESOME SCADA package, I recommend MANGO M2M. Google Mango M2M to get to the Mango webpage, where you will find details on installing and downloading. Use this link to download because the links on the page direct you to Mango Automation, which is the commercial version, easily the best value for money or those wishing a bit more.
It uses DGLux, a state of the art graphical dashboard. I use 1.12.4, as it is the latest version that I can get to work. Follow the install instructions to the LETTER on the website.
If 1.12.4 does not work, substitute the '4' in the link above with another version. I have got Modbus working with a arduino mega as a master using the modbus master lib. I have changed the lib so it can address more than one slave and am using it to communicate with two flow meters.
This is done using RS485. The fact that is is RS485 and not RS232 seems to make no difference as i just use a converter on the cable i haven't need to change any code at all.
Well not quite true i did have problems at first with coms being fine to one or the other but not both i solved this with some 'delay(11);' statements ( 11 was arrived at by trial and error) in between slave change and also making sure i emptied the transmit and receive buffers seemed to help. All in all it wasn't to difficult to get working. Thank for your reply EVP My goal is simple,I want to communicate to arduino via RS485 not USB port and arduino as a slave my PC as a master I use modscan32 as my SCADA.OZ_Willy's code work perfectly via USB, I can read write arduino in modscan32. But when I want to connect arduino via RS485 modscan32 told me time out(no response). I follow this picture to make a max485 wiring.