Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 14 of 14

Thread: Rotary encoder find

  1. #1

    Rotary encoder find

    Hi everyone, i found this rotary encoder at work and would like to attempt to read it.

    The details i can make out are:

    Matsushita ER24 (from research i believe is panasonic)
    AER12122

    The instructions i will post a photo, but they are all in what i assume is Japanese.

    My fist issue is, does anyone know how to wire this thing up? With unreadable instructions and i cant seem to find anything online, its a pretty big first hurdle!

    Second, any advice on which teensy would be best used? I think from memory the 3.6 could count seperatly to the main code? Is that correct? And if so do they all do that?

  2. #2

  3. #3

  4. #4
    From what i can see on the instructions, it says 12v-24v. I'm assuming that is the red wire? I also am assuming that the others are signal wires and that they wouldn't need 12v?

  5. #5
    Senior Member vjmuzik's Avatar
    Join Date
    Apr 2017
    Posts
    509
    Based on some other forum post I found from Russia

    The outputs are open collector so they just need pulled up to the appropriate voltage for the microcontroller, in this case 3.3v for the Teensy 3.6
    Red: 12v-24v
    Black: 0v or Ground
    Shield: Ground
    White: A
    Green: B
    Yellow: Z (optional)

  6. #6
    Senior Member
    Join Date
    Feb 2016
    Location
    Australia
    Posts
    254
    With a crisp image, google translate is helpful for this sort of stuff.

  7. #7
    Hi Guys, thanks for your replys. I have had a go at connecting it to a teensy 3.6 using the wiring vjmuzik gave above.

    It appears to be counting, however only counting upwards. If i spin it either way then it goes up. Any thoughts on why? I will post the code in my next reply.

  8. #8
    #define ENCODER_OPTIMIZE_INTERRUPTS
    #include <Encoder.h>

    // Change these pin numbers to the pins connected to your encoder.
    // Best Performance: both pins have interrupt capability
    // Good Performance: only the first pin has interrupt capability
    // Low Performance: neither pin has interrupt capability
    Encoder knobLeft(9, 10);
    // avoid using pins with LEDs attached

    void setup() {
    Serial.begin(9600);
    while (!Serial) {}
    Serial.println("Encoder Test:");
    }

    long positionLeft = -999;

    void loop() {
    long newLeft;
    newLeft = knobLeft.read();
    if (newLeft != positionLeft) {
    Serial.print("Left = ");
    Serial.print(newLeft);
    Serial.println();
    positionLeft = newLeft;
    }

    if (Serial.available()) {
    Serial.read();
    Serial.println("Reset both knobs to zero");
    knobLeft.write(0);
    }
    }

  9. #9
    I put a 10k pullup resistor to pins 9 and 10, which really smoothed it out, otherwise it was going crazy counting when it wasnt even spinning. But only counts up.

  10. #10
    Senior Member
    Join Date
    Oct 2015
    Location
    Roma (IT, EU)
    Posts
    312
    Do you have access to a logic analyzer or a 2-channel oscilloscope?
    It would be useful to see the waveform on A and B while rotating in the two directions.

  11. #11
    Senior Member
    Join Date
    Feb 2016
    Location
    Australia
    Posts
    254
    You could use the teensy and the arduino IDE serial plotter as a logic analyser.
    Turn the encoder and take a photo. It's not ideal but here you can see two good channels.
    Reversing the encoder will show reversed color order.

    Code:
    //wire channels a and b to inputs 0 and 1
    void setup() {
      
     pinMode(0,INPUT_PULLUP);
     pinMode(1,INPUT_PULLUP);
    }
    
    void loop() {
      
      Serial.print(digitalRead(0));
      Serial.print(",");
      Serial.println(digitalRead(1));
    }
    Although I expect you will only be getting one channel.
    Note my cheapy encoder here uses White for VCC and Red as A signal. If I were to wire it up incorrectly I expect at the least I would blow one of the channels.

    Edit: You could wire your channels to an analog pin and then you have a teensy oscilloscope.
    Code:
    //wire channels a and b to inputs 14 and 15
    void setup() {
      
     pinMode(14,INPUT_PULLUP);
     pinMode(15,INPUT_PULLUP);
    }
    
    void loop() {
      
      Serial.print(analogRead(14));
      Serial.print(",");
      Serial.println(analogRead(15));
    }
    Click image for larger version. 

Name:	teensyScope.jpg 
Views:	5 
Size:	45.2 KB 
ID:	20131
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	1.jpg 
Views:	3 
Size:	110.7 KB 
ID:	20129   Click image for larger version. 

Name:	3 (.jpg 
Views:	3 
Size:	107.5 KB 
ID:	20130  

    Last edited by Gibbedy; 05-16-2020 at 03:38 PM.

  12. #12
    Thanks for the replys guys,

    I played around a bit longer yesterday and was able to get it reading both ways by putting a capacitor in the line with a pullup resiter as well, however i wouldn't say it was a reliable read, every turn i could get different results and going backwards read about 20% less than going forwards.

    So today I tryed the make your own oscilloscope idea, and my results definitely look different to the ones you posted. I will post pictures. It was going crazy just sitting there, so i put a delay(100) in there to try and see what was happening. The photos have the delay.

    This pic the encoder was just sitting still
    Click image for larger version. 

Name:	20200517_175035.jpg 
Views:	7 
Size:	155.6 KB 
ID:	20161

    This pic i rotated it slightly and then let it sit still
    Click image for larger version. 

Name:	20200517_175111.jpg 
Views:	6 
Size:	132.8 KB 
ID:	20162

    There was no capacitor or pullups when i ran this test.

    Jason

  13. #13
    Senior Member
    Join Date
    Oct 2015
    Location
    Roma (IT, EU)
    Posts
    312
    So in the first picture, the encoder was not moving? And yet, there's a pulse on one of the 2 lines (A or B)...!?
    That's odd. I have no idea, have to pass.

  14. #14
    Yeh its going crazy, after i put the delay on there it showed that pattern.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •