lc625

Hi all together.
I´m trying to use a PT Sensor with OpenPLC. Well knowing, that it might be not the easiest way to connect a temperature probe to OpenPLC I would like to stay with these sensors because they are some kind of industrial standard in those projects I´m going to realise. My setup: Raspi, Arduino Mega, PT 100 connected to the Mega via MAX31865 board using SPI. In terms of accuracy I think this way should be the best one. To get it run I used the Mega firmware provided on the OpenPLC website for Arduino Mega. I added some code to it to write data into the holding registers via modbus. Unfortunately, I failed so far. I can´t find any data written to the registers The modbus task seems to run. I can use the digital pins and the analog ones as well. With using "serial.print" I can confirm that the MAX31865 and the PT are connected the right way.
I attached the Arduino sketch, the log file and my very tiny test program. Perhaps someone could take a look. My skills came to an end and I can´t see why it is not working.

Log:
OpenPLC Runtime starting...
Interactive Server: Listening on port 43628
Device Mega is disconnected. Attempting to reconnect...
Warning: Persistent Storage file not found
Connected to MB device Mega
Issued start_modbus() command to start on port: 502
Server: Listening on port 502
Server: waiting for new client...
Issued start_dnp3() command to start on port: 20000
DNP3 ID manager: Starting thread (0)
DNP3 ID DNP3_Server: Listening on: 0.0.0.0:20000
Issued start_enip() command to start on port: 44818
Server: Listening on port 44818
Server: waiting for new client...
Issued stop_pstorage() command

OpenPLC_Slave.png 
OpenPLC_Monitoring.png  OpenPLC_Program.png 

Quote 0 0
thiagoralves
There are a couple of things wrong in your approach. First, %MW0 reads from memory, there isn't any IO data in there. Second, you're storing the data read from the sensor on Holding Register 1024 in the Mega. This register does not exist in the Mega. There are only 14 Holding Registers on the Mega, and they are used for analog outputs, not inputs. The right way to do this would be to increase the number of Input Registers to 17 and then add an if clause to the for loop for the NUM_INPUT_REGISTERS so that if i=16 then you store the data read from the PT100 on modbus.Ireg[i]. This is just half of the problem solved. The other half is to modify the parameters of the slave settings on OpenPLC Runtime so that it reads 17 input registers instead of 16 (just increase the size to 17). Now your PT100 data will be available on %IW116
Quote 0 0
lc625
Thanks for assitance. Due to holidays I had a bit more free time. Now I get the things running. I can read the data from the MAX31865 an wirte them into an analog input register. I attached my skatches to this post. One scetch is for Arduino MEGA, the other one is for Arduino UNO. I have proved them working. For all who want´s to read temperatures with an MAX31865 feel free to use them. If you make improvements, please let me know. 
There are two questions coming up: Forcing variables using the new monitoring option in the runtime seems not to be working. Is this true?
I failed to write %MDx and %MLx with UDINT resp. ULINT data. Writing %MWx with UINT data causes no problems. Do the 32 and 64 bit registers simply not exist or did I get something wrong?
At the moment I have to use the windows runtime because my raspi had blown up and here I´ve got no option of buying a new one.
Thanks in advance
Quote 0 0
thiagoralves
Forcing variables is still a work in progress feature. I should finish implementing it soon. %MDx and %MLx should work fine with read and write over Modbus. Are you sure you're using the correct Modbus addresses? Check http://www.openplcproject.com/scada
Quote 0 0
lc625
Thank´s, I am looking forward to your implementation. iI will be a greate help. Allow me to show you a few pictures what I meant according to the %MDx and %MLx thing:

Setup global variables for writing into %MWx:
OpenPLC1.png 
Program:

OpenPLC2.png  
Monitor (Results are correct):


OpenPLC3.png 
Variables for %MDx Register

OpenPLC4.png 
Program:
OpenPLC5.png 
Monitor:
OpenPLC6.png  As you can see, it works with %MW0 but not with %MD0. Looking to the Mapping table, the address should exist. 
Quote 0 0
thiagoralves
As I said, %MDx and %MLx should work fine with read and write over Modbus. The monitoring page is still a work in progress. Given that %MDx are 32-bit registers, it will require more work to have them displaying on the monitoring page properly. Same thing for %MLx. Keep an eye on the updates, I might finish the monitoring page soon.
Quote 0 0
lc625
Well, thank you for the answer. You kept me away from going mad while searching a fault in my attempts.
Quote 0 0