ikoth

Hi all,

I'm a complete novice when it comes to PLCs, Ladder Logic, etc. However for reasons that don't matter, I need to create a simple OpenPLC based system to demonstrate the basic principles of Modbus based industrial control systems.

My plan is to run a RasPi based Master unit, controlling one ESP8266 running a temperature sensor, and a second one controlling a small fan that switches on when a set temperature is reached.

The system will be include a HMI (either ScadaBR, or myPRO), and I'll be using NodeRed to capture Modbus messages and send them to another application via JSON.

My question to you OpenPLC gurus is - is the system capable of meeting this requirement:

RaPi Master pulling in temperature data from one ESP, comparing that to a threshold and switching on a fan controlled by a second ESP board, when the threshold is exceeded?

Thanks,

I.

 

 

Quote 0 0
thiagoralves
You can finish this project (except the NodeRed -> JSON piece) in 5 minutes using OpenPLC. Just follow this guide to install OpenPLC on your Raspberry Pi, and then follow this guide to setup your slave ESP8266 devices. Have fun!
Quote 0 0
ikoth
Brilliant. Thank you!
Quote 0 0
ikoth

I've got the Pi Master running and have followed the basic project with the two push buttons and an LED. It's working well, and I'm seeing the status changes in Node-Red.

I've also got one ESP8266 Slave hooked up to a DS18B20 temperature sensor. And this is where I'm stuck.

I've followed Thiago's video, I have my sensor defined and I'm using a DIV block to convert the raw sensor data into degrees C. But I don't know to store the calculated temperature value. I've tried creating a variable for it, buy them I can't add a power rail and the compilation fails.

So, how do I get OpenPLC to store the temperature value, so I can read it out please?

 

PLCError.png   

 

Quote 0 0
thiagoralves
You put the name of the variable in the box, but never declared it. First you need to declare the variable you're going to use on the top panel. Just click on the green "+" sign to declare another variable, name it "Result" of type INT and you should be good
Quote 0 0
ikoth

Sorry for the late reply - life gets in the way sometimes, and thanks for the suggestion. I've made a little progress, but still not getting anywhere.

I have the DPS18B20 hooked up to my slave ESP8266 on pin D5 / GPIO14 / %IX100.1

I've created a variable for the sensor value, as suggested, and am storing the result in a writable holding register %QW100.0 (I've also tried %QW100.1 and just %QW100 with the same result)

OpenPLCError.png 

The code compiles correctly in the editor now, but when I try to upload it I get the following error:

Optimizing ST program...
Generating C files...
./st_files/872166.st:3-6..3-33: error: Bit size of data type is incompatible with bit size of location.
1 error(s) found. Bailing out!
Error generating C files
Compilation finished with errors!

I'm guessing the problem is something to do with trying to store the calculated temperature value, but I have no idea how to fix it.

Cheers,

I.

Quote 0 0
thiagoralves
%IX100.0 is a bit location (X is for bit, W is for word). This location must be BOOL, not INT for that location, which means that you can only read the state of the pin, either TRUE or FALSE. Just to clarify further, you can't read your sensor like that. This type of sensor requires a certain protocol (a lot of pulses) to be able to read data from it. You will have to modify the ESP8266 firmware to be able to read that temperature and make it available in a register for OpenPLC to read. This is not straightforward, but it is not hard either if you know a little bit of C. The other option would be to use an analog sensor (instead of a digital one like yours). You can grab a PTC 10K thermistor and connect to the analog input of the ESP8266 (%IW100). With the right calculations (Steinhart equation) you can convert the analog reading into Celsius and do whatever you want with it.
Quote 0 0
ikoth

Doh! Now who feels stupid?

Sorry, for some reason I just assumed the sensor you used in your Internet of Things using the OpenPLC - ESP8266 video was a DPS18B20.

I'll acquire an analog sensor and try again.

Many thanks,

I

Quote 0 0