Jump to content

Using MODBUS IP to get values from sensors through Visilogic to Raspberry Pi


Recommended Posts

Hello,

I'm very new to PLC programming. This is my first practice. I'm doing a small project for my university. We have a Vision430 controller that is already connected to a temperature sensor and an ultrasonic sensor for level measurement. I have to program the V430 and a Raspberry Pi, so that the RPi can access the sensor values via MODBUS IP. I have watched the tutorial videos and tried to write the ladder logic myself but am not sure if it's correct and I haven't had the chance to go to the university lab to test it with the controller yet because of Covid-19. Could you please check the program I wrote?

 

And about the program for Raspberry Pi. I have to write the register addresses of the V430. I use MI1 and MI2 for the values from both sensors. Does that mean that the register addresses are 40002 and 40003 respectively?

 

Thank you for your advice in advance.

ATP16.vlp

Link to comment
Share on other sites

  • MVP 2023
7 hours ago, petchpetals said:

I use MI1 and MI2 for the values from both sensors. Does that mean that the register addresses are 40002 and 40003 respectively?

Yes that is MODBUS convention. Assuming your Raspberry Pi follows that convention, it should work. Did you try it to see?

When in unfamiliar territory I like to Store Direct SI 30 into an MI just above the vector being read (MI 0 in your case). This will immediately tell me if I have an "off by one" problem.

  • Like 1
Link to comment
Share on other sites

Thank you for your reply :) 

 

I just had the chance to test it at the university today but I had quite a few problems and could not connect the PLC to the RPi via Ethernet yet.

1. Could you tell me how to assign the IP address to the PLC in  "TCP/IP - Carn Init" block. How can I know what I should insert for IP Address, Subnet Mask and Default Gateway?

2. When you pair an analog input with a register in "Hardware Configuration", how do you know which Nummer belongs to which input? In my case, my sensors are connected with input 9 and input 10.  There are four rows for analog inputs in the "Hardware Configuration". The first two are for temperature sensors (T/C, nV, PT100, Omhs) and the other two are for regular inputs (4-20mA,...)

Link to comment
Share on other sites

  • MVP 2023

There are a number of example program that came with you VisiLogic installation. Take a look at those to see how to code your program for ethernet communications.

1) When you assign and IP address to the PLC, it needs to be on the same subnet as your Raspberry Pi. In other words, whatever the address is of the Raspberry Pi, the PLC needs to have the first 3 numbers the same. The last number can be anything between 0 & 255 as long as it's unique to the network it's on. Subnet Mask should be set to 255.255.255.0 and default gateway is only important if you are trying to communicate over the internet. Just set it for the same subnet with the last number 0 or 255.

2) Do you know how to set up your HW Configuration? That must be done in order for your PLC to collect data from the I/O. When assigning an MI to the analog input in the HW Config, it should be obvious which input you are assigning. The 4 rows are for analog inputs 0-3.

I'm not sure what you mean by inputs 9 & 10. You only have 4 analog inputs, which will be labeled something like AN0 - AN3. Perhaps you're confusing them with digital inputs?

Also, unless you are connecting your PLC through a hub, router, or switch, you may need to use a crossover ethernet cable.

Link to comment
Share on other sites

I used an ethernet cable to connect the PLC with the Raspberry Pi. I will try with the new IP Address setting next time I go to the university.

I have set up the HW configuration and paired each analog input with an MI but I wasn't sure about the wiring. I have just found this data sheet about the wiring of V430 model (in attachment). My collegue told me that the level sensor is wired with input 9 and the temperature sensor is wired with input 10. Does that make sense ? because according to the data sheet, it looks like inputs 9 and 10 are only for digital input or temperature sensor and it looks like both input 9 and 10 are supposed to be wired with only one analog sensor, which would be AN0 in the HW configuration (if I understand correctly that #0, #1, #2, #3 on the data sheet correspend to AN0, AN1, AN2, AN3 in the HW configuration?) or am I misunderstanding something? I didn't take a look at the wiring myself. I will have a look again next time I go to the university.

Analog Input - Wiring.JPG

Link to comment
Share on other sites

  • MVP 2023
6 hours ago, petchpetals said:

My collegue told me that the level sensor is wired with input 9 and the temperature sensor is wired with input 10. Does that make sense ?

Yes, I don't have a V430 here in my office and it's been awhile since I used one so I didn't realize how they had it labeled. You are correct. I had forgotten that some of the smaller Unitronics PLCs with built-in I/O have some digital inputs that can be jumpered and wired as analog inputs. Yes, inputs 9 & 10 can be wired with a thermocouple (negative to 9 & positive to 10). That will be T/C 0 and will be assigned analog input 0 in VisiLogic. Inputs 7 & 8 can be wired for T/C 1, which will be assigned analog input 1. Analog inputs 2 & 3 can be wired to I6 & I5, respectively.

Sorry if I led you astray earlier - the V430 is a bit different in some respects than most other Unitronics I/O.

For the temp sensors, the MI assigned will hold the temperature reading to the tenth of a degree (i.e. 98.6 F will be 986 in the MI). For the analog inputs, the MI will hold the analog to digital conversion of the mA measurement to a resolution of 14-bits, so it will be a number between 0 & 16383 (3277 - 16383 for 4-20mA).

Link to comment
Share on other sites

The connection with Modbus was successful today! Thank you for your help!

 

In case it might help someone, I used PyModbus library for the Modbus communication between my Raspberry Pi and the PLC.

To read a 5-register long vector starting at MI3, I use the command  

client = ModbusTcpClient(host= '#IP address of the slave PLC#' , port=502)

rr = client.read_holding_registers(3, 5, unit=2)

print(rr.registers)

So the address you have to write in the command is simply 3 for MI3. I don't know what unit=2 means but the programs will have an error if this part is left out. Other numbers for example unit=1 seemed to work too.

 

As for the inputs, I noticed another picture on the same data sheet today. I thought that numbers 1-15 on the PLC are numbers of the inputs but I misunderstood. I though my sensors are wired with inputs 9 und 10 but they are actually wired with Inputs I6 and I5, which correspond to AN2 and AN3 respectively.

IO.JPG.39c0869b208f81d8d94509568b2ac1e5.JPG

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...