edwardo388
Hi,

I'm new to OpenPLC. I've attached some code which I believe contains a hello world to flash some LEDs and some code to measure distance using a common Adafruit ultrasonic sensor with a trigger and an echo pin. I want to place the distance into a Modbus register after measuring the distance to an object with the sensor. I've tried both the memory holding registers and the analog output registers and I get a compiler error "glueVars.cpp: In function ‘void glueVars()’:
glueVars.cpp:68:18: warning: invalid conversion from ‘INT* {aka short int*}’ to ‘IEC_UINT* {aka short unsigned int*}’ [-fpermissive]
int_output[0] = __QW0;"

I'm also relatively new to ladder logic, I believe that the sensor works by triggering the sensor, which sets the echo pin high for the length of time it takes for the sensor to measure the distance. I wasn't sure how long this would be, but 500ms is far longer than the length of time it would take to measure the distance to the object I have in mind, so I used a timer with a preset of 500ms and am looking at the elapsed time. I know this isn't exactly the correct way to use the sensor, but for now I'm just struggling to get a time datatype cast into a 16-bit integer accessible by Modbus. 

I was hoping someone would be able to tell me what I'm doing wrong, I've attached my .st file and program file. This will be running on a Raspberry Pi 3B+.
Reply 0 0
edwardo388
I should also mention that I had similar errors using the int to usint block.
Reply 0 0
thiagoralves
These are not errors, they are warnings, and you shouldn't worry about them. They are related to OpenPLC internal coding. Your application should work even if there are warnings.

About the ultrasonic sensor, you won't be able to use it with OpenPLC. These sensors require precise timing in the range of microseconds to work. OpenPLC tasks run in the range of milliseconds. Usually, to work with ultrasonic sensors you need to set the trigger pin and then measure the time it takes for the echo pin to be triggered. The distance is based on the time delay between the trigger pin and the response from the echo pin. To make it work with OpenPLC you would have to edit the hardware layer driver for your raspberry pi (OpenPLC_v2/core/hardware_layer.cpp) and put the measurement code in it.
Reply 0 0
edwardo388
Thanks for the quick response! I will be working on this over the next few weeks and will post code/updates as I make progress. I am familiar with C++ and should be able to make the necessary code modifications to make this work for my application.

I am using OpenPLC for automation of a fully automated Aquaponics garden. I am both new to Aquaponics and OpenPLC, but as I regularly work with Schneider and Allen-Bradley products in the water/wastewater industry as an HMI application engineer, OpenPLC seemed like a great choice for a personal project involving water and automation. I am very excited to see where the OpenPLC project goes and for the Version 3 release. 
Reply 0 0
Reply