
Darren360 (Customer) asked a question.
I am beginning to learn C/C++ (Arduino) after programing in LAD for over 20+ years. Really want to move my projects over to the P1AM so I have chosen to dive into the Arduino language set and I have some newbie questions. I expect there will be more, but this is where I am at today…
At the simplest level, in LAD we use the NO ‘| |’ and NC ‘|/|’ instructions to create the logic flow working to the right side of the rung. Many lines end in a coil ‘( )’. A simple example would be ‘this’ push button wired to my input card and ‘not that’ e-stop button will ‘turn on’ the motor.
In Arduino would the equivalent to a NO or NC instruction be the ‘if’, ‘else’, if else’ statements? Or would we use bool operators and/or compare functions?
I may be able to understand/visualize this more clearly if someone would be willing to create the traditional latching circuit in Arduino using a P1AM, a P1-08SIM card in slot 2, and a P1-08TD1 in slot 1.
I have studied the examples but would like to see an example that combines both input and output cards. The traditional latching circuit has been used for years as a teaching tool in LAD courses might be a great example to compare the two languages.
As I am beginning to think through some of my upcoming projects I will be creating using the P1AM, it seems like the program will be mostly worked out using a lot of ‘if’ statements but just not sure… I know in LAD there would be a lot of NO and NC logic.
I know I will be asking more LAD -> Arduino questions later, but I think getting this fundamental down would be great.
I also have the GPIO shield with me, so as a bonus I would like to request a sketch showing what that same latching circuit would look like using just the GPIO shield and not the I/O modules...
Cheers,
Darren
Just curious, are you looking to move away from ladder to make things easier? What kinds of projects do you normally get involved with?
Hi Adisharr,
Short answer: I am expanding my programming knowledge into Arduino (C/C++) because I discovered the P1AM and really want to include that hardware in my systems. I will also include Circuit Python in my learning soon but starting with Arduino for now.
Long Answer: I was an industrial automation systems engineer for over 20 years and my focus was Siemens Step7, S7-300/400 PLC’s, Profibus, AS-Bus, Drives, HMI etc. Resigned when my son was born in 2010 to focus on being a dad. Started a mobile RV service business (www.myrvworks.com) about 10 years ago.
Today I am using my extensive automation background and my extensive RV tech knowledge and together with my son (and a few of our Trail Life boys) we are developing diagnostic systems for RV’s. Raising up the next generation of control engineers! We plan on using the P1AM and Arduino to feed this data to the cloud for remote diagnostic capabilities for our customers. We will then roll it out to the masses, buy and island and watch sunsets every night. 😁
I have developed several prototype systems using PLCs and PLRs but the price point for that hardware is too high and we need to get that at a cost our customers can afford. P1AM checks a lot of boxes for our system and adds the MKR shields that will really open up some options for us. But we need to learn how to take our ladder logic and recreate it in C/C++.
Anyone with an RV can chip in and be a beta tester LOL. 😉
"In Arduino would the equivalent to a NO or NC instruction be the ‘if’, ‘else’, if else’ statements? Or would we use bool operators and/or compare functions?"
TRUE, you used "or" the answer to one or more of those questions is true (it is both, BTW)
if (X1) do something ;
if( (X1 && X2 && !X3) || X4) do something ;
One thing to keep in mind that writing to an output acts like SET and RST, there is no automatic equivalent to RLL "OUT"
If (X) P1.writeDiscrete(HIGH,2,2); // will turn a discrete output on if X is true, but it will not turn said output off if it is already on and X is false. One could use an else statement and a call to P1.writeDiscrete(LOW,2,2) to get the effect but it is not automatic
Hey Tinker,
Thanks for your answer. When you made the statement that the outputs act like SET and RST that was a huge lightbulb for me. Your sample code instructions were very helpful.
So, like you said I use ‘if’ and then within that structure compare my Bool inputs it really helps to clarify the bridge between RLL and Arduino. Then use the ‘else’ to further manipulate the output. So, there will be a lot of that type of instruction going on in my scripts it seems.
I was reading about Arrays and pointers and can perhaps make use of that to monitor all I/O on a single card at once to bring things in that way but that is still an early learning step to dabble with.
I am having fun learning all this stuff! Thanks for being there for us newbies!!! 😵
Cheers,
Darren
A lone IF behaves like SET/RST. If you want more of the pure rung feel you can use direct assignment.
Output = (Start || Output) && Stop;
Also can construct your IF/ELSE statements to be like a LAD rung.
IF (Start || Output) && Stop {
Output = 1;
}ELSE{
Output = 0;
}
Or break it out if you prefer.
IF !Stop {
Output = 0;
}ELSE IF Start {
Output = 1;
}ELSE IF Output {
Output = 1;
} ELSE{
Output = 0;
}
Apologies if my syntax is off, been in ST world and haven't been in C for a minute.
Good luck with pointers, many people struggle very hard with pointers in C.
Hey Darren, thanks for sharing! Very cool you're able to get the kids involved in your projects and new career!
You're spot on about the hardware costs - even the low cost PLC's are lacking in capability compared to what you can do with an Arduino these days.