carol_lo
I am trying to use the structured text to collect temperature from DS18B20 sensor. Hoping the sensor information could be shown on the Factory IO (Modbus Slave 1) display. 
 
Physically, i wired the sensor to UNO (Modbus Slave 2) pin 12.
On the OpenPLC Editor, I used the library DS18B20 to program the code.
I do a simulation before putting back to the Raspberry Pi (Modbus master). The code compile without problem, the simulation result is satisfactory. 
 
[203128%2F8449010%2Fmceclip0]
 
However, when i upload the compiled program to the openplc runtime, there are weird errors. Please refer to the picture below.
 
 
I am not sure why this happens. 
Firstly, I am not sure if it is my coding problem. I have attached the st file compiled by OpenPLC Editor for your comment please. 
 
Secondly, I am not sure if it is my OpenPLC Editor problem. So, I check for any updates on OpenPLC Editor, and I updated to the latest version (just now). I run the same code again in the OpenPLC Editor , no problem in the simulation and the compilation process in OpenPLC Editor. 
 
Moreover, I am not sure if it is my OpenPLC runtime problem. I try to see if there is any OpenPLC runtime updates, but seems that no update available. 
 
Finally, I am not sure if it is my UNO problem, but i tried to setup the UNO using the General Modbus RTU Device, instead of the original template. Is there anything I have to enable in the OpenPLC Editor to allow UNO to be used as Slave of Raspberry Pi? I have previously followed your tutorial number 5 https://youtu.be/dQ8GcfpGDuA?si=_WcjxXNW-ChoaL1M and successfully turn on light wired to UNO with the Raspberry Pi button, so I guess the UNO is working normally. 
 
However, I then upload the st file Raspberry Pi again, and the compilation in the OpenPLC runtime shows error.
 
[203128%2F8449025%2Fmceclip0]
 
 
I am sorry for very long message but hope to solve it and understand the issue. 
Reply 0 0
thiagoralves
The DS18B20 block cannot be used with the Raspberry Pi, only with Arduino based boards
Reply 0 0
carol_lo
Thanks. I managed to upload the following code to UNO. However, the variable location for 'Q_FactoryTemperature' has to be converted to %QW3 instead of %QW103. I noticed that if I want to use UNO as the Modbus Slave, I have to use location %QW10X.  So, may i clarify is there any better way to extract this temperature information from UNO and pull back to another device, including Raspberry Pi (Modbus Master) and Factory IO (Modbus Slave)?  
 

TempDS18B20(
PIN := 12,
OUT => Q_FactoryTemperature);

Q_FactoryTemperatureDisplay := REAL_TO_INT(Q_FactoryTemperature);
 
 
 
It is not a must to use Temperature Sensor with UNO, but if i plug put the Temperature Sensor into Raspberry Pi, i noticed that I would have to change the hardware to PSM mode as your last YouTube tutorial, which will affect the remaining code in Raspberry Pi. So, I wonder if there is better way. If no, i will just drop the temperature sensor element from my project 🙂 
Reply 0 0
thiagoralves
You have two options:
1. Connect the Uno straight to Factory IO and have it read the temperature from the Uno
2. Place the temperature in a register, like QW3 for example, and configure your raspberry pi slave device to read (instead of write) QW3. Then your temperature sensor will appear at IW somewhere in your Pi
Reply 0 0
Reply