Codegineer
Hi All,

I have worked through the following example in Arduino PLC IDE and started to extend it up until hitting a road block. That focused me on getting the OpenPLC IDE running

I've got OpenPLC image (4.1.4) running, and started to work through the example in OpenPLC, but hit upon a strange issue with the input. The raw readings are 10 times smaller when running the OpenPLC version over the Arduino one.

Is this another case of needing to configure the analogue input in an arduino sketch? How do you ensure the arduino sketch runs only once and before the ladder, structural text, etc?

Thanks!
Reply 0 0
thiagoralves
I don’t know how Arduino PLC IDE works specifically, but OpenPLC scales all analog inputs to match the default 16-bit unsigned integer range (0-65535). How are you trying to read the inputs?
 
As for Arduino sketches, OpenPLC is completely independent. It does not need a separate sketch to function. When you upload an OpenPLC project it replaces everything you have uploaded before, so any Arduino sketches will be wiped. You can, however, add Arduino sketches code to your PLC project using C/C++ function blocks
Reply 0 0
Codegineer
I had a message about posts being ported over to the Autonomy server but for some reason this wasn't there.
 
Any how, I have created a C/C++ FunctionBlock and added the following line into the setup and loop sections of the supplied template. It didn't have any effect.
 
analogReadResolution(4);
 
I think however I am barking up the wrong tree here as the input reading needs to be multiplied by 10 to get a sensible answer, not 16.
 
So can you see any error in the following?
 
Device > Configuration:
    Pin mapped: A0 - "Analog Input" - %IW0 (auto completed, not adjusted) - "input_voltage_heat"
 
Resource > Global Variables:
    input_voltage_heat : uint AT %IW0; (used the table input to create this)
 
In my structured text file (with input_reading_tmp created in the variables table):
    input_reading_tmp := UINT_TO_LREAL ( input_voltage_heat );
 
I monitor the above and without correction my temperature after the following formula is ~ -16C. With * 10 on the line above it is more sensible.
 
voltage_out := ((( input_reading_tmp / 65535.0 ) * 3.3 ) / 0.3) / 4.9;
 
I'm going to repeat the debugging in Arduino's PLC to confirm if the raw input is bigger or not.
Reply 0 0
Codegineer
Just double checked the code via Arduino PLC IDE and the reading is definitely 10x larger, and presumably with greater resolution too as x 10 on the sensor input doesn't add back lost resolution.
 
So on the Arduino PLC IDE the setup is as follows:
 
Resources > Local I/O Mapping > Programmable Inputs:
    I1 | input_voltage_heat | Analog | UINT | %IW0.0 "I1 programmable input; Modbus DInp 1 /IReg1"
 
Project > I_O_mappings_ProgInp
    input_voltage_heat | UINT | %IW0.0 | No (array)
 
And in the structured text:
 
input_reading := TO_LREAL( input_voltage_heat )
Reply 0 0
Codegineer
Just noticed I pointed it to pin I0 on Arduino IDE and A0 on OpenPLC IDE. I'd be surprised if that was it, but I will check!
 
Edit: It does not compile with A0 changed to I0.
Reply 0 0
thiagoralves
Hello,
The OpenPLC forum has a new home: Autonomy Edge https://edge.autonomylogic.com. We migrated every member, profiles, topics, categories and attachments. Please redo your post on the new forum so we can continue our conversation.
Note: If you already have an Autonomy Edge account, you can simply login with your credentials to have access to your forum profile and posts. If you don't have an Autonomy Edge account, we ask you to set a fresh password on first sign-in using the same e-mail you used on this forum.
To set a fresh password, access the link https://edge.autonomylogic.com/forgot-password and insert the e-mail address used on this forum. You will receive an e-mail on your inbox with a link to choose a new password. Once you reset your password you will be able to login onedge.autonomylogic.com using your new credentials.
Reply 0 0
Reply