1. Do not share user accounts! Any account that is shared by another person will be blocked and closed. This means: we will close not only the account that is shared, but also the main account of the user who uses another person's account. We have the ability to detect account sharing, so please do not try to cheat the system. This action will take place on 04/18/2023. Read all forum rules.
    Dismiss Notice
  2. For downloading SimTools plugins you need a Download Package. Get it with virtual coins that you receive for forum activity or Buy Download Package - We have a zero Spam tolerance so read our forum rules first.

    Buy Now a Download Plan!
  3. Do not try to cheat our system and do not post an unnecessary amount of useless posts only to earn credits here. We have a zero spam tolerance policy and this will cause a ban of your user account. Otherwise we wish you a pleasant stay here! Read the forum rules
  4. We have a few rules which you need to read and accept before posting anything here! Following these rules will keep the forum clean and your stay pleasant. Do not follow these rules can lead to permanent exclusion from this website: Read the forum rules.
    Are you a company? Read our company rules

my encoder dosn't work with arduino leonardo...

Discussion in 'DIY Motion Simulator Building Q&A / FAQ' started by serhatsoylu, Jan 27, 2023.

  1. serhatsoylu

    serhatsoylu New Member

    Joined:
    Jan 27, 2023
    Messages:
    3
    Balance:
    37Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    DC motor, Arduino
    hi,

    i have a ffb wheel project working with an arduino leonardo and an encoder.
    it was working perfect but now it is not. (i disassembled leonardo and encoder and didn't use for 1 year and i assembled again).

    the problem is;
    leonardo can't read my encoder.



    [​IMG]
    image1561×903 145 KB



    i was using this encoder1.

    i thought that it is broken down and bought a new one (encoder2)...

    and they are not working...

    then i tried an other one (encoder3)...

    and it is working.

    it means, my arduino leonarda and my circuit works. (i think)

    i tried my old encoder with an other circuit and an other arduino code.

    volatile unsigned int temp, counter = 0; //Bu değişkenleri encoder hareket ederken ve daha önceki konumu ile karşılaştırmak için kullanacağız

    void setup() {
    Serial.begin (9600);
    pinMode(18, INPUT_PULLUP); // Encoderden çıkan yeşil yada sarı kabloyu Arduinonun 2. pinine
    pinMode(19, INPUT_PULLUP); // Encoderden çıkan yeşil yada sarıdan hangisikaldıysa kabloyu Arduinonun 3. pinine

    /* Aşağıda "interrupt" dediğimiz bölme,araya girme anlamları olan fonksiyonları tanımlıyoruz burada temel mantık şu;

    • Bu pinlerdeki sinyalde değişiklik olduğu anda işlemci yaptığı işi yarım bırakıp bu pine bağlı fonksiyonu yapıp normal işlemlerine geri dönecek.
    • Bu işlemi yaptırtabilemek için bu pinlere interrupt koyduğumuzu belirten kodu yazıyoruz.
      */
    //Burada 2 numaralı pinde sinyal seviyesi yükselidinde "Interrupt_fonksiyonu1" i çalıştır diyoruz
    attachInterrupt(digitalPinToInterrupt(18), Interrupt_fonksiyonu1, RISING);

    //Burada 3 numaralı pinde sinyal seviyesi yükselidinde "Interrupt_fonksiyonu2" i çalıştır diyoruz
    attachInterrupt(digitalPinToInterrupt(19), Interrupt_fonksiyonu2, RISING);
    }

    //Yukarıdaki kodda "Interrupt_fonksiyonu1" ve "Interrupt_fonksiyonu2" içerisinde ne olacağını en aşağıda belirledik

    void loop() {
    // Aşağıdaki if kodunda elimizdeki "counter" değeri ile kayıtlı olan "temp" değeri aynı mı onu kontrol ediyoruz aynı ise işlem yapmıyoruz fakat farklı
    // ise "counter" değerimizi serial porta yazdırıyoruz ve yeni counter değerimizi "temp" değerine kayıt ediyoruz

    if( counter != temp ){
    Serial.println (counter);
    temp = counter;
    }
    }

    void Interrupt_fonksiyonu1() {
    // bu fonksiyon 2 numaralı pinde sinyal değerimiz yükseldiğinde çalışıyor diğer pinin sinyaline bakıp saat yönünde yada tersine döndüğünü tayin ediyoruz
    // dönüş yönüne göre değeri arttırıp azaltıyoruz
    if(digitalRead(19)==LOW) {
    counter++;
    }else{
    counter--;
    }
    }

    void Interrupt_fonksiyonu2() {
    // bu fonksiyonda aynı üsteki fonksiyon gibi 3 numaralı pinde sinyal değerimiz yükseldiğinde çalışıyor diğer pinin sinyaline bakıp saat yönünde yada tersine döndüğünü tayin ediyoruz
    // dönüş yönüne göre değeri arttırıp azaltıyoruz
    if(digitalRead(18)==LOW) {
    counter--;
    }else{
    counter++;
    }
    }

    all encoders (3 of them) are working with this code so i think that, my all encoders are working.

    if i am true, why my old encoder and the one which i bought new dosn't work?
    why the big encoder work?

    what is the problem i can't see???

    my circuit has an switch between pin6 and GND (as you can see in the picture).

    thanks [​IMG]
  2. serhatsoylu

    serhatsoylu New Member

    Joined:
    Jan 27, 2023
    Messages:
    3
    Balance:
    37Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    DC motor, Arduino
    I found the mistake. I had pull-down resistors for pin0 and pin1 (encoder phase a and phase b)... They should be pull-up...

    I corrected them and working now...
  3. Gadget999

    Gadget999 Well-Known Member

    Joined:
    Dec 27, 2015
    Messages:
    1,897
    Location:
    London
    Balance:
    11,610Coins
    Ratings:
    +458 / 9 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, 6DOF
    Do you need a pullup / pulldown resistor ??
  4. serhatsoylu

    serhatsoylu New Member

    Joined:
    Jan 27, 2023
    Messages:
    3
    Balance:
    37Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    DC motor, Arduino
    Yes, encoder needs pull-up resistors for phase a and phase b pins...