Ryan
Hello,

so so I have a raspberry pi zero w and it is running openplc, I selected the option for raspberry pi on install.
the hello world program works great and I can use a physical switch turn on my led.

I cannot for the life of me work out how to use advancedhmi to reference the gpio pin with my LED so when I flick the switch the LED and the HMi virtual led light at the same time.

i uploaded a modbus config from the scada page but I have no idea if that did anything.

i tried using the gpio address %IX0.0 but it said that was wrong obviously.

Could a kind soul put me out of misery and help me out?

im still very much learning but I seem to be going in circles
Quote 0 0
thiagoralves
http://www.openplcproject.com/scada

This page relates the OpenPLC addressing (%IX, %QX stuff) with Modbus addressing
Quote 0 0
Ryan
Thank you,

so is my setup correct using the option for raspberry pi at the end of the install or should I have chosen modbus? Bearing in mind I want to use gpio

thank you 

Ryan
Quote 0 0
Ryan
Found it,

in AdvancedHMI - plcaddressvalue I entered 0001, when I test my physical switch the virtual lamp lit on the HMI.

Now to make a virtual switch!

Thanks you.

Ryan
Quote 0 0
thiagoralves
Ryan wrote:
Thank you,

so is my setup correct using the option for raspberry pi at the end of the install or should I have chosen modbus? Bearing in mind I want to use gpio

thank you 

Ryan


If you're on the Raspberry Pi and want to control the GPIO pins you should use the Raspberry Pi driver at the end of the installation. The modbus driver should only be used if you want to talk to other modbus slave devices as a modbus master (i.e. Using the modbus driver, the modbus slave devices will be controlled by your program the same way GPIO is controlled when you use the RPi driver).

OpenPLC can operate as a modbus slave device no matter which driver you chose at the end of installation
Quote 0 0
Ryan
Thank you for the reply.
After spending pretty much all day on this I cannot seem to make the HMI button operate the LED on my PI.
I added an extra line to my ladder just incase it was that but it just won't compile unless I remove the line.

My head is about to exploded now ha ha 
Quote 0 0
thiagoralves
I don't know how you're trying to achieve this, but you need to keep in mind a few things:

1. Inputs are read only. So, if your button (contact in ladder logic) that controls the LED is attached to an input (i.e. %IX0.0) you won't be able to force it to true using Modbus.

2. Outputs are read/write, so you can use Modbus to force an "output" (%QXn variable) to true, and you can use a %QXn variable as a contact in ladder logic to control your led. What you cannot do is try to force (write) to an output that is already controlled by ladder logic. In OpenPLC ladder logic prevails over Modbus, so that if ladder logic tells that the output must be false and you try to write to it using modbus forcing it to be true, it won't work.

So basically, the right way to do it would be to have a variable in the %QXn range associated with a contact that controls the LED. For example, your led is in %QX0.0, you can have a contact in %QX0.1 and a ladder diagram like this:

        %QX0.1                                 %QX0.0
|----------|  |------------------------------(  )------------|

Then your %QX0.1 "button" will be accessible on Modbus coil address 1. Whenever you write "true" to it, it will turn on your LED at %QX0.0 as per your ladder logic
Quote 0 0
Ryan
I really appreciate your patience with me and I now get what you are saying about read only!!

Here is my basic ladder then based on your diagram above.

openplcladder.png 

However when I upload I get.

optimizing ST code...
Program optimized successfully
compiling new program...

Internal compiler error in file generate_location_ list.cc at line 150
.


POUS.c
POUS.h
LOCATED_VARIABLES.h
VARIABLES.csv
Config0.c
Config0.h
Res0.c

Error compiling program. Please check console log



Thank you for your continued patience.

Ryan
Quote 0 0
Ryan
AHAAAA!!!!

Ignore me, I have managed to do it!!

You sir are a legend!

Thank you

Ryan
Quote 0 0
gecko
Hey so would you share your solution?  And please tell me, what a HMI is ? :-)
Quote 0 0
Ryan
Ok, let me type it up 😉

Won't be long
Quote 0 0
Ryan
I have always liked automation so I wanted to learn a bit of it.
The obvious start for me was PLC, I didn't want to waste money on a real PLC so when I saw this project I was very happy. (Thank you to everyone that has contributed!)

My setup is:


Raspberry Pi Zero W
Raspberry Pi 3 with touchscreen.
A Movement based PIR sensor
A relay board.
An LED
A 12v Fan
12 PSU
Batteries for the LED
Open PLC 
AdvancedHMI

I don't have a lot of space in my work area so I wanted to keep things simple.

I have two relays so I thought the easiest thing was to design a PLC that interacted with those.


Relay 1: 

Movement sensor and 12v Fan

The PLC code counts how many times the sensor detects something move and after 3 times it then switches on the LED to show this.
In my mind this was like a conveyor that counted 'widgets' being made and lights a notification light to tell the operator.
(I realise this movement sensor is not the correct sensor I would have been better with IR beams but I used what I had)

Relay 2 
This was the same thing but this time it used a fan, I did not have another IR sensor so I made a manual HMI button to simulate this.
Same thing when you press the button 3 times the fan kicks in for 5 seconds.
I also included a fan bypass button so if you wanted to manually kick the fan in you could.

A HMI is a human machine interface, so its a screen that you can interact with.

Below is my ladder code, I am still learning and this is my first project.

myladder.png 
Here is my HMI, it's sized for the Rasperry pi 3.5" screen and works great.

HMI.png 

So the picture of the fan is the bypass, when you push that the fan starts.

The issue I was having was addressing, I could not wrap my head around it until it clicked.

For inputs modbus starts 10001 (So on the Pi this would be %IX0.0)
For outputs modbus is 00001 (So on the Pi this would be %QX0.0)

fanset.png 

I was trying to change an input but obviously (now) they are read only.
You can only change an output which is Read/Write

I was advised on another forum not to control the outputs directly and I will look into this when I get a bit more experience.

So this now works as I expected and over the coming days I will look to write something else a bit more complicated.

I am also doing a couple of on line courses so hopefully my understanding will be better.

I hope this posts helps you in some small way.

Thank you to Thiagoralves for all his help which was invaluable.

Good luck

Ryan

Quote 0 0
gecko
Hey Thanks a lot for posting! I now realize that with the modbus and HMI interface you have the same addresses at the RPi that the pins have wich I am using.
Gecko
Quote 0 0
Ryan
Apparently it's not best practice to tie your input directly to output and this should be done by referencing a memory address.
Once I have figured this out I'll post again.

Ryan
Quote 0 0
thiagoralves
On OpenPLC, any output that is out of the range of your device (i.e. %QX99.0) is considered memory.
Quote 0 0