fg71
Any person who has used Arduino extension properly know that delay() couldn't be used.
We have to approach it differently so I made a example to show that.
 
Here is the main plc program that have contact (Start_Blink) and coil (OUT).
In the Arduino extension there is if statement if its True will run some code else do nothing.
 
It demonstrate how you could approach a delay in your Arduino extension without using delay() function.
 
This have been tested on Nano Esp32 with Modbus Tcp + Live Debug Remote PLC
Set Start_Blink to True, OUT become True and the if statement become True in Arduino extension.
 
You may wonder why do the LED active for 20ms that is because the default cycle is 20ms in OpenPLC.
When second cycle is active ledState is HIGH and set ledState to LOW. In other words that makes me to think
there is run loop (cycle) inside the Arduino extension void sketch_loop().
 
[203128%2F9101082%2Fmceclip0]
 
Here is Arduino extension
[203128%2F9101145%2Fmceclip0]
Reply 1 0
thiagoralves
Arduino has a good example about this on the Arduino IDE called "blink without delay". In essence, all it does is count the time using millis() like you did, instead of blocking on a delay wait.
Reply 0 0
fg71
Yes, the code was based on 'blink without delay' I thought it could be useful to know if we include Arduino code.
Reply 0 0
fg71
Do you know if void sketch_loop() has any delay ?, I wonder why would the LED only be active for 20ms when the interval is set to 2000 ms.
It looks to me the interval of 2000ms is working when the LED is LOW but not when its HIGH
Reply 0 0
thiagoralves
You shouldn’t set IOs directly from the Arduino extension, as the runtime hardware layer takes over in the very next cycle your action is overwritten by the PLC layer. The correct approach is to set a variable and let the IO assignments for the PLC side.
Reply 0 0
fg71
When you have time could you show me the correct way, I include the project file
Reply 0 0
thiagoralves
  1. Drop your digitalWrite statement in the Arduino Extension
  2. Declare ledState as external on your ladder program
  3. Use ledState on a contact to activate a coil at %QX0.3 on your ladder program
Reply 1 0
fg71
I think I got it to work here is the change
[203128%2F9101240%2Fmceclip0]
 
And here is Arduino extension
[203128%2F9101257%2Fmceclip0]
Reply 0 0
Reply