Gloworm72
Hello,

I recently found a solution to running stepper motors using the fastaccelstepper.h library as an arduino extension file that has shared variables with my ladder diagram:
https://openplc.discussion.community/post/need-help-using-2-arduino-megas-one-with-openplc-program-and-connected-to-hmi-while-13574138?trail=15

This has worked great, and I am now able to begin creating the project. The project is for a student competition that requires Factory and Site Acceptance Tests to be run. Ideally, we would like the ability to "force" internal bits "on" and "off" as part of our testing and also be able to see live readings of whether bits are being flipped "on" or "off" when they are supposed to.

My original plan was going to be having the Arduino run our PLC Program with a panel of simple switch buttons that would be tied to digital inputs of the Arduino, rather than finding a way to use an HMI.

If being able to live update the values of the ladder diagram from my laptop requires the same RTU Modbus/similar communication protocol that would lend itself well to using an HMI, I would still be open to the route of an HMI.

I'm still somewhat of a beginner, so if anyone is able to share their thoughts on what might be best for this scenario and what would be the simplest way to go about it that would be great.
Reply 0 0
thiagoralves
Enable Modbus RTU on the upload dialog, and then, click on the blue bug icon on the toolbar to debug your program running live. Once the debugger is running you can force variables on/off, monitor variable state, etc. Here is a Youtube video that explains the procedure: https://youtu.be/tCUTPTW0Zew?si=w6KovmCFFPeFBa2f
 
As a side note, beware that AVR Arduino boards (Uno, Mega, Leonardo, etc) are VERY LIMITED in resources. Once Modbus is enabled, your project will consume a significant amount of RAM. Running a fairly complex project with Modbus enabled on an Arduino Uno/Mega might make it run out of memory. If you notice your project starts crashing, failing randomly, or simply not running at all, most likely you've ran out of memory. In that case, I suggest you move into a more powerful platform. Arduino MKR, ESP32, RP2040 and RP2350 are good alternatives.
Reply 0 0
Gloworm72
Enable Modbus RTU on the upload dialog, and then, click on the blue bug icon on the toolbar to debug your program running live. Once the debugger is running you can force variables on/off, monitor variable state, etc. Here is a Youtube video that explains the procedure: https://www.youtube.com/watch?v=tCUTPTW0Zew
 
As a side note, beware that AVR Arduino boards (Uno, Mega, Leonardo, etc) are VERY LIMITED in resources. Once Modbus is enabled, your project will consume a significant amount of RAM. Running a fairly complex project with Modbus enabled on an Arduino Uno/Mega might make it run out of memory. If you notice your project starts crashing, failing randomly, or simply not running at all, most likely you've ran out of memory. In that case, I suggest you move into a more powerful platform. Arduino MKR, ESP32, RP2040 and RP2350 are good alternatives.
Thank you for the help!

I understand now, but what exactly are the limitations for modbus on an Arduino Mega? I found this website: https://autonomylogic.com/docs/2-5-modbus-addressing/

For instance, looking at this diagram, would all variables be using up spots for inputs and output or can I specify which ones I want to keep track of at the time? If I had 2 buttons and 1 PWM outputs as well as 5 LED indicators, would modbus only need 2 input spots, or do the internal variables that run the logic also count?
[203128%2F9221932%2Fmceclip0]
Reply 0 0
thiagoralves
Put in simple terms, Modbus brings a significant overhead to handle the protocol itself, the communication buffers, and of course the located variables buffer. Even if you don't declare all the located variables, the space for them will still be allocated there. The Arduino Uno has 2KB of RAM, and the Mega has 8KB of RAM, total. You're trying to fit a full IEC 61131-3 runtime, plus arduino code, plus your PLC programs, plus Modbus in just 2KB of RAM. Just for a comparison, a regular ESP32 board has 520KB of RAM.
 
If you go down to bare C, then obviously 2KB can be enough for a lot of stuff, depending on your experience in coding low-level things. But if you want to leverage all the abstraction layers OpenPLC offers, programming graphically in LD, FBD, etc, using objects, then those little 8-bit Arduino boards are just toys, and can't be used for anything larger than a traffic light example.
Reply 0 0
Reply