Using UNO script to OPTA

Hello everyone

I have a question about the Opta arduino; Can a script initially created for a UNO work with OPTA? (of course changing the names of the inputs and outputs)?

because I tried my script which works on UNO on OPTA and nothing happens...

I used ARDUINO IDE 2.3.2


unsigned long tempsDebut;  // passage précédent de l'aimant

int etatPrecedent;  // lors de du dernier passage dans le loop,
                    
const int rel_0 = D0;


// niveau du seuil de vitesse (km/h) pour le déclenchement de la sortie output 7

const int seuil5 = 3000;


void setup() {
  pinMode(A0, INPUT);      // interrupteur Reed à la pin 8
  pinMode(rel_0, OUTPUT);  // configure la broche ledPin en sortie
  
  pinMode(LED_D0, OUTPUT);
  
  Serial.begin(9600);               // moniteur série
  etatPrecedent = digitalRead(A0);  // on vérifie si l'aimant est là ou pas
}

void loop() {

  int etat, delai;
  unsigned long tempsFin;
  int valeurCapteur = digitalRead(A0);
  etat = digitalRead(A0);  // on vérifie si l'aimant est là ou pas
  
  if ((etat) && (!etatPrecedent)) {   // l'aimant vient d'arriver
    if (tempsDebut > 0) {             // nous connaissons le moment du début de ce tour
      tempsFin = millis();            
      delai = tempsFin - tempsDebut;  // durée du tour qui vient de se terminer


      if (delai <= seuil5)  
      {
        digitalWrite(rel_0, HIGH);
        digitalWrite(LED_D0,HIGH);
      } 
      else {
        digitalWrite(rel_0, LOW);
        digitalWrite(LED_D0,LOW);
      }
      
    }

    tempsDebut = tempsFin;  // mise à jour de la variable
  }

  etatPrecedent = etat;  // mise à jour de la variable
}

here is the pinout

show us your circuit and what was connected where and how things are powered.

PS/ You need a while (!Serial); after your Serial.begin(9600); if you want to print anything out quickly but that's not your issue here

here is the script for the tests.
I don't use relays.
I just want to turn on or off the D0 LED, if it works I will put the relays on.

unsigned long tempsDebut;  // passage précédent de l'aimant

int etatPrecedent;  // lors de du dernier passage dans le loop,
                    
//const int rel_0 = D0;   //not useful for testing


const int seuil5 = 3000;


void setup() {
  pinMode(BTN_USER, INPUT);      // user button for testing
  //pinMode(rel_0, OUTPUT);      // not useful for testing
  pinMode(LED_D0, OUTPUT);
  
  etatPrecedent = digitalRead(BTN_USER);  // on vérifie si l'aimant est là ou pas
}

void loop() {

  int etat, delai;
  unsigned long tempsFin;
  int valeurCapteur = digitalRead(BTN_USER);
  etat = digitalRead(BTN_USER);  // on vérifie si l'aimant est là ou pas
  
  if ((etat) && (!etatPrecedent)) {   // l'aimant vient d'arriver
    if (tempsDebut > 0) {             // nous connaissons le moment du début de ce tour
      tempsFin = millis();            
      delai = tempsFin - tempsDebut;  // durée du tour qui vient de se terminer


      if (delai <= seuil5)  
      {
        //digitalWrite(rel_0, HIGH);   //not useful for testing
        digitalWrite(LED_D0,HIGH);
      } 
      else {
        //digitalWrite(rel_0, LOW);    //not useful for testing
        digitalWrite(LED_D0,LOW);
      }
      
    }

    tempsDebut = tempsFin;  // mise à jour de la variable
  }

  etatPrecedent = etat;  // mise à jour de la variable
}

I use the BTN_USER to simulate a proximity sensor

I am not a great programmer and i don’t understand local variables. I always use global variables cause I understand doing it this way. What comes to my mind is

Has never been declared to a pin maybe? But I can be way off on this…

etat & etatPrecedent are supposed to be Boolean’s i believe ,,, i do not think this will behave in the way you suspect.

this is part of that board's environment

image


its poorly written (should compare with HIGH and LOW rather than treat those as implicit 1 and 0) but should work

Gotcha :+1:t3:… 1 is true/HIGH and 0 is false/LOW, i see. Did not know that would work. thanks! Hey OP, listen to this guy ^ … lol.

I guess when you say it is part of the environment. There is no other option so it (what pin) does not need to be declared. Correct?

thank you friends .
for my part I have just tested my script by removing the line

if (tempsDebut > 0) {  }

and it works.... :thinking:

my opta is powered by 12v,
then I connect the + of the opta to an input I1,I2,I3.....

what is the maximum admissible voltage on an input, 10v or 24v

The Datasheet says Analog Input has a 10v maximum, but I'm running my as "digital" and they work fine with a 12v input. The Datasheet also says the Digital Input pins can handle up to 24V, but according to the pin-out, there are no "digital inputs," so, I'm a little confused by what they mean...
They may be talking about the 12-24v input from the power supply, but that doesn't work for me as the "digital Input" says a power range of: "0v...24v," which emplys a 2v input would be fine...

The datasheet also says the OPTA has "over-volt protection," on each pin, so you can (theoretically) use any voltage and not destroy the machine - it may not work, but you won't kill it by trying.