kooroshtux
Hello,

I discovered your software a few days ago, and I am trying to test it by setting up a simple program which is to light an LED with a push button.

here is my program:
Capture.png 
If someone could help me,
Regards,
Quote 0 0
thiagoralves
Nice program. What is the problem with it?
Quote 0 0
kooroshtux
the problem is during compilation, the software puts me "does not respond" and I am forced to stop all by closing the process "ctrl + alt + supp". Capture.png  Capture2.png 
Do you have a solution ? otherwise how I could program in SFC without the inline technique because it looks like the software does not really like this way of doing things.

EDIT:

Capture.png 

I tried to reduce another way of programming in sfc by deleting "inline" for action "LED" but my problem continues as soon as I use the "inline" functionality.

I also have another software to program in ladder my arduino which is Ldmicro. On this software, I installed in relay mode the lamp then I installed a cyclic state of 2 bits, and it works! now, for your software, I don't know how to do it because in addition when compiling this last bug. If you have a solution, I am interested but for now I will stay on the ldmicro software. Regards,

Capture.png 
Quote 0 0
thiagoralves
Took a little while for me to find your little mistake, but once I tried to reproduce your program I figured it out. There is no issue in using inline expressions on OpenPLC Editor, but you need to keep in mind that if you're using an inline expression for a transition, it should not have semi-colon neither assignments (the ":="  operator) since a transition is an evaluation expression. When you used an assignment operation on a transition, you locked the compiler in an infinite loop. It is fine to use assignments and semi-colon for action blocks though, as that's precisely their purpose.
Capture.png    
From this picture, you need to correct both your transitions to:
BP = 1

and
BP = 0


Once you fix that, your code will compile just fine.
Quote 0 0
kooroshtux
First of all, thank you for devoting your time to me, it gives me great pleasure. In simulation on openPLC, it works perfectly BUT the LED on my arduino does not light up. I got an arduino.ino script to see if my wiring is correct and yes I made no wiring error because the led lights up well with the .ino script so my problem comes from my openplc program.

Here is the .ino script that I got from the openclassroom site:
/*
le bouton poussoir est connecté au pin 2 pour un mode INPUT_PULLUP
la Led est connectée au pins 4 avec une résistance de 220Ω
*/
//déclaration des variables
int pinBouton, pinLed;
boolean etatAllumage;
void setup()
{
  //initialisation des variables
  Serial.begin(9600);
  pinBouton = 2;
  pinLed = 4;
  etatAllumage=0;
  //définition des modes
  pinMode(pinBouton, INPUT_PULLUP);
  pinMode(pinLed, OUTPUT);
}
void loop()
{
  Serial.print(etatAllumage);
  
  if (etatAllumage) //on teste si etatAllumage est à 1
  {
    digitalWrite(pinLed, HIGH);//on allume la LED
  }
  else //sinon
  {
    digitalWrite(pinLed, LOW); //on éteint la LED
  }
  //lecture de l'état du bouton et stockage dans etatBouton
  boolean etatPinBouton = digitalRead(pinBouton);
  Serial.println(etatPinBouton);
  //test des conditions
  if (!etatPinBouton)//si bouton appuyé (donc le pin indique 0 car il est en mode INPUT_PULLUP)
  {
    if (etatAllumage) //si etatAllumage à 1
    {
      etatAllumage=0; //on le passe à 0
    }
    else //sinon
    {
      etatAllumage=1; //on le passe à 1
    }
  }
  delay(200);
}


My goal is to program in SFC because I bought a book that teaches how to program in SFC grafcet. I have the impression that the program does not communicate with my push button, what do you say?

Edit : I have attached my wiring plan and a video of the arduino bug while testing your patch.
        Vidéo =  https://drive.google.com/open?id=1YdDXs-gj58QVjPPJzNTuSQuKHY-vmw-B

small precision, I installed openPLC on my PC and my arduino card is plugged in USB, And if I tried su a raspberry directly, did you think it would work?
Here are the logs displayed in openPLC dashboard:
OpenPLC Runtime starting...
Interactive Server: Listening on port 43628
Device Arduino official is disconnected. Attempting to reconnect...
Warning: Persistent Storage file not found
Connected to MB device Arduino official
Modbus Read Discrete Input Registers failed on MB device Arduino official: Connection timed out
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
Issued start_enip() command to start on port: 44818
Server: Listening on port 44818
Server: waiting for new client...
Issued stop_pstorage() command
Quote 0 0
thiagoralves
Have you followed all instructions from here: https://www.openplcproject.com/getting-started-arduino

I have the impression you're missing something on your setup.
Quote 0 0
kooroshtux
yet I followed the instructions. My version of openplc editor is v1, the openplc runtime version, I don't know where to look. I will install the whole solution on my raspberry pi3 to see the result.
Quote 0 0
thiagoralves
Can you provide a screenshot of your slave devices configuration? Is your Rx/Tx leds blinking constantly on your Arduino board when the PLC program is running?
Quote 0 0
kooroshtux
yes, the lights are flashing well, here are the screenshots of my config in attachment.
log with current program:
OpenPLC Runtime starting...
Interactive Server: Listening on port 43628
Device Arduino ITALIA is disconnected. Attempting to reconnect...
Warning: Persistent Storage file not found
Connected to MB device Arduino ITALIA
Modbus Read Discrete Input Registers failed on MB device Arduino ITALIA: Connection timed out
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
Issued start_enip() command to start on port: 44818
Server: Listening on port 44818
Server: waiting for new client...
Issued stop_pstorage() command
Modbus Write Coils failed on MB device Arduino ITALIA: Connection timed out
Server: Client accepted! Creating thread for the new client ID: 8...
Server: waiting for new client...
Server: Thread created for client ID: 8
Modbus Server: client ID: 8 has closed the connection
Terminating Modbus connections thread
Server: Client accepted! Creating thread for the new client ID: 8...
Server: waiting for new client...
Server: Thread created for client ID: 8
Modbus Server: client ID: 8 has closed the connection
Terminating Modbus connections thread
Server: Client accepted! Creating thread for the new client ID: 8...
Server: waiting for new client...
Server: Thread created for client ID: 8

Quote 0 0
thiagoralves
Well.. your setup seems correct from the screenshots, but when I revisited your circuit, it seems that your button is in the wrong pin. You're using %IX100.2 on your program, and that's pin 4 of your Arduino board (check here:https://www.openplcproject.com/getting-started-arduino 😉.
Quote 0 0
kooroshtux
I corrected the pine config but still the same bug. The LED does not respond to the push button but it blinks randomly or not see at all. Very strange, could you share with me an example of programming in LD language so that I can check if the problem comes from this SFC language or not.
Quote 0 0
thiagoralves
You can use the Hello World program from the website. Also, check the monitoring page to make sure it is capturing your button presses correctly

Edit: one more thing, it seems that your button is missing a pull down resistor. Without it the readings will fluctuate when the button is not pressed. This should explain the random LED blinks
Quote 0 0
kooroshtux
I succeeded, my error was a wiring problem because I had not put a resistance of 10K ohms BUT, I would like me to press the light stays on and when I re-press the light stops. But the I do not arrive, I know that I have to play on a variable "State" and to add a negation but I cannot manage to do it on this software.

currently, here is my diagram:
Capture.png    
at the beginning, I press once and the light stays on (that's good) BUT I can't seem to make the return.
Quote 0 0
thiagoralves
I suggest you get a good book in PLC programming to level up your skills. Your program is not doing what you want because you didn't program it do to what you want. Your code is precisely turning the LED on only when the button is pressed. That's the transition from Step0 (LED off) to Step1 (LED on). If you want the same button to turn off the LED, you need to create two more transitions in your program: Step2 (transition when BP = 0, nothing happens, LED should stay on), and transition back to Step0 (transition when BP = 1, should go back to Step0 turning the LED off).
Quote 0 0
kooroshtux
Yes I ordered a book on amazon, I am looking forward to it. Basic, I'm used to programming in Python v3 language and C language but out of curiosity, I wanted to program in the automatician way in order to have a new approach. For the program, I followed your advice by adding a step 2 but it still doesn't work.
Quote 0 0