Seafoxc
Hi guys

I was looking to do something else then a traffic light or Factory I/O to program with OpenPLC and I started a new project: Making a Barbot. This will not be a step by step guide but more of detailed view on how to make a project. 

I made some already in the past with Arduino and it was great fun (after the countless hours of troubleshooting).

My goals for this project is:

- Making a functional PLC program using FBD and SFC and OpenPLC on Windows.
- Making an HMI interface that can also be accessed on a smartphone. 
- Making a lot of cocktails.

Optional:
- Connect it to my smart assist (Amazone Alexa). 
 
I already have the Hardware and it looks like this:

cocktailmaker.jpg
(Powersupply, Arduino Uno, 8 channel relay board, 8 membrane pumps,..)

I started by making a basic IO test by running the pumps one by one for two second in a loop.

The first problems I will cover is the fact that the standard Arduino Firmware program has only 4 outputs for the UNO.
I first have to change this in the Firmware code and add a "custom" slave device in the OpenPLC runtime.

After adding the device and testing it I'm now ready to program the Cocktail routines. 

I will make a video series on the cocktailmaker. This is Part1.

https://youtu.be/gTVzd23Ej0o

If you have question or suggestions you can let me know here.
I have no Idea what I'm doing...
Reply 1 0
thiagoralves
Pretty cool project! Why don't you try to implement this natively on the Arduino, so that you don't need to have a PC in between? This would be a great test drive for the new Arduino native support on OpenPLC Editor. As for HMI, you can still use Modbus Serial over the USB port connected to a Raspberry Pi running FUXA or something else.
Reply 1 0
Seafoxc
@thiagoralves I have no experience with the Raspberry Pi. I also have no experience with Linux. I will first try to implement it with the Arduino on Windows. I already bought a Raspberry Pi ages ago but I will first start with something simpler. Maybe if I switch to an ESP8266 slave I can operate wireless To the PC version of OpenPLC. Question, I don't understand the details with the checkbox Modbus enabled in the download dialogue.  Does this mean you can write and read data to the Modbus registers (with Fuxa for example)? 
I have no Idea what I'm doing...
Reply 0 0
thiagoralves
Seafoxc wrote:
Question, I don't understand the details with the checkbox Modbus enabled in the download dialogue.  Does this mean you can write and read data to the Modbus registers (with Fuxa for example)? 

Yes, that's exactly what it is for! With Modbus Serial you would have to read the registers through the USB (serial) port using Modbus RTU protocol. But with Modbus TCP you can have that connection over wired Ethernet or Wi-Fi. If you plan on using an esp8266, you can do the same thing with that board, running your PLC program natively and have it connected to FUXA wirelessly through Modbus TCP over Wi-Fi.
Reply 1 0
Seafoxc
@thiagoralves If I want to run the program natively on the Arduino Uno or the ESP8266 I need to change the HAL files so I have 8 outputs (like I also did for the Arduino Slave software). Is this just changing this file "X:\OpenPLC-V1-29b\editor\arduino\src\hal\uno_leonardo_nano_micro_zero.cpp"? Or is it not that simple? 
I have no Idea what I'm doing...
Reply 0 0
thiagoralves
Yup, that's all it takes! Obviously for esp8266 you will have to edit esp8266.cpp file instead. 🙂
Reply 1 0
Seafoxc
@thiagoralves It works :-)! The first time I edited the HAL file in the wrong location (I have to clean up all the old versions of OpenPLC on my PC). That makes it really easy to change the I/O's. I will now go further with Arduino to see what is possible with the tiny amount of RAM. Not that my program will be that big but it is a nice test. If it runs on the Arduino it is just a small effort to use the ESP8266 at the end of the project.
 
I have no Idea what I'm doing...
Reply 0 0
Seafoxc
@thiagoralves I was trying to set-up the connection with the serial port. I made sure the checkbox for modbus serial was enabled.
I first tried adding it in FUXA and I was not able to make connection:
Fuxa settings.jpg 
I'm not sure if I had to leave the field slave empty or 0 but I tried different combinations with the same result (no connection). 
I then fired up the Radzio MODBUS tool and here I have connection:
Radzio_No_connection.jpg 

Do you have any suggestions regarding the connection to Fuxa?
  







I have no Idea what I'm doing...
Reply 0 0
Seafoxc
@thiagoralves I found the issue with FUXA. You have to install the COM ports (looked at the closed issues in Github). 
In the server map you have to open a Windows powershell window and use the command: npm install serialport
I have no Idea what I'm doing...
Reply 0 0
thiagoralves
I'm glad you found the issue. You can also do the same with Modbus TCP on the esp8266
Reply 0 0
Seafoxc
@thiagoralves I want to add a button in the HMI screen and use that button in my PLC program (using Arduino natively and FUXA). 
As far as I know you can't access the holding input register or read Input registers in Modbus.
To make it work I used an output to write to(QX.1.0). But that means I should add extra outputs for every control element in my HMI (I would use a self declared range).

Can you just confirm that there is no other way to this? Or is there a way to access the memory of OpenPLC with Modbus?

I have no Idea what I'm doing...
Reply 1 0
thiagoralves
You can access all Modbus registers, coils and inputs as usual. The only problem with Modbus (and this is the same with any Modbus device) is that you cannot write to input status or input registers, as they are just inputs by definition. This leaves you with coils and holding registers. If you want to have a single register word to hold all your buttons, you can indeed write to holding registers that are out of range from your analog outputs. For the Arduino Uno, that would be anything greater than QW2. Maybe for the Arduino Uno it would be a better approach since it only has 2KB of RAM and doesn't have many registers and coils to spare. If you're using a full register for all buttons, you will have to find a way to split it in separate bits for each button both on FUXA and on ladder logic.

That being said, depending on how big your project is, using a bigger board like the Arduino Nano IoT, Arduino Zero, esp8266 or any other ARM based board might come in handy. They have much more RAM available and a larger Modbus address range when compared to Arduino Uno.
Reply 1 0
Seafoxc
@thiagoralves. Like predicted I ran out of memory on the Arduino 😃.Even when using 1 holding register.I think using SFC's is the issue.
I will first continue using OpenPLC on Windows with the Arduino as a slave. After I got everthing working I will upgrade to the ESP8266.
I have no Idea what I'm doing...
Reply 0 0
Seafoxc
I made a video about the final result...

https://youtu.be/SB1fZRGsZL4

As attachment, you can find in the Zip file "OpenPLC_CocktailMaker"  => The OpenPLC project and the custom Arduino Uno driver (with 8 outputs). 
"FUXA-master" => Unzip it and press on the Fuxa shortcut to start the Fuxa project. 




I have no Idea what I'm doing...
Reply 1 0
Flare09
I made a video about the final result...

https://www.youtube.com/watch?v=SB1fZRGsZL4

As attachment, you can find in the Zip file "OpenPLC_CocktailMaker" => The OpenPLC project and the custom Arduino Uno driver (with 8 outputs).
"FUXA-master" => Unzip it and press on the Fuxa shortcut to start the Fuxa project.




Hey Seafoxc, I have been going over your program and videos, I'm assuming the available upload has only a single cocktail parameter FB That needs to be duplicated and edited for pump output time? Secondly, I am wanting to set mine up with a lot more options. Wouldn't it save memory to reference an array for each time parameter? I'm not sure yet if it would be better to create one large array with everything, or smaller arrays for each cocktail.
 
You mentioned wanting to be able to change pump time through your HMI, which is why you set up individual FB and time integers? I'm not so worried about that after I calibrate each pump time.
Reply 0 0
Reply