Results 1 to 10 of 10
  1. #1
    New Member
    Join Date
    Nov 2014
    Location
    Portugal
    Posts
    4
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Smile Help counting with MAX7219 and rotary

    Hello
    first, sorry for my bad english!

    I'm trying to do a AP Altitude set, without any connection with link2fs. Is only de rotary encoder with a TM1640 tube and a MAX7219. This will work regardless from FSX.

    With code that took from this forum, I could make it work with the TM1640. The code that work with TM1640 is:
    Code:
    #define ENC_1_A A0#define ENC_1_B A1
    
    #include // required because the way arduino deals with libraries
    #include 
    TM1640 module(3, 2);
    
    int encoder_1_value = 0;
    static int8_t enc_states[] = {0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0};
    
    void setup() {
    /* Setup encoder pins as inputs */
    pinMode(ENC_1_A, INPUT);
    digitalWrite(ENC_1_A, HIGH);
    pinMode(ENC_1_B, INPUT);
    digitalWrite(ENC_1_B, HIGH);
    
    
    char text[17];
      sprintf(text, "0000%u", encoder_1_value);
      module.setDisplayToString(text);
    
    
    Serial.begin (115200);
    Serial.println("************ Start *************");
    }
    
    /* returns change in encoder state (-1,0,1) */
    int8_t read_encoder1() {
    static uint8_t old_AB = 0;
    
    old_AB <<= 2;
    old_AB |= ((digitalRead(ENC_1_B))?(1<<1):0) | ((digitalRead(ENC_1_A))?(1<<0):0);
    return ( enc_states[( old_AB & 0x0f )]);
    }
    
    
    void loop() {
      
    int8_t encoderdata1;
    
    encoderdata1 = read_encoder1();
    if ( encoderdata1 ) {
    encoder_1_value += encoderdata1;
    
    Serial.print("Encoder 1: ");
    Serial.println(encoder_1_value);
    
    char text[17];
      sprintf(text, "%u", encoder_1_value);
      module.setDisplayToString(text);
    }
    }




    But with MAX71219 I get stuck. I do not know how to do. Already tried several times and the only thing i get is this:




    I'm working with this code for MAX7219:

    Code:
    #define ENC_1_A A0#define ENC_1_B A1
    
    
    #include "LedControl.h"
    LedControl lc=LedControl(12,11,10,1);
    
    
    int encoder_1_value = 0;
    static int8_t enc_states[] = {0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0};
    
    
    void setup() {
        /*
       The MAX72XX is in power-saving mode on startup,
       we have to do a wakeup call
       */
      lc.shutdown(0,false);
      /* Set the brightness to a medium values */
      lc.setIntensity(0,8);
      /* and clear the display */
      lc.clearDisplay(0);
      
      
    /* Setup encoder pins as inputs */
    pinMode(ENC_1_A, INPUT);
    digitalWrite(ENC_1_A, HIGH);
    pinMode(ENC_1_B, INPUT);
    digitalWrite(ENC_1_B, HIGH);
    
    
    char text[17];
      sprintf(text, "0000%u", encoder_1_value);
      module.setDisplayToString(text);
    
    
    Serial.begin (115200);
    Serial.println("************ Start *************");
    }
    
    
    /* returns change in encoder state (-1,0,1) */
    int8_t read_encoder1() {
    static uint8_t old_AB = 0;
    
    
    old_AB <<= 2;
    old_AB |= ((digitalRead(ENC_1_B))?(1<<1):0) | ((digitalRead(ENC_1_A))?(1<<0):0);
    return ( enc_states[( old_AB & 0x0f )]);
    }
    
    
    void loop() {  
    int8_t encoderdata1;
    
    
    encoderdata1 = read_encoder1();
    if ( encoderdata1 ) {
    encoder_1_value += encoderdata1;
    
    
     lc.setDigit(0,0,encoder_1_value,false);
    
    
    }
    }
    How can I do to show the other digits.
    I appreciate any help

  2. #2
    25+ Posting Member
    Join Date
    Mar 2014
    Location
    France
    Posts
    27
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Help counting with MAX7219 and rotary

    Hello m2snd
    This is normal that you have only 1 digit switch on because you only set 1 digit with this line of code :
    lc.setDigit(0,0,encoder_1_value,false);
    and it prints in hex format (0 to f)

    You need to modify your variable encoder_1_value to match the max7219 format
    ie : to print value 2015, need to print "2" on digit 3, "0" on digit 2, "1" on digit 1 and "5" on digit 0

    setdigit parameters are
    1)witch number of max7219 do you use (in case of multiple chained max7219)
    2)witch digit do you want to operate (0 is the more left one, 7 is the more right one)
    3)your value to print for this digit
    4)do you want to print the "point"

    I'm using modulo math to convert my variable to number of digit I want to display
    in decimal format
    so to print 4 digits you need to make 4 lines of code (one per digit)
    For example in your case:

    lc.setDigit(0,3,(encoder_1_value/1000) % 10,false);
    lc.setDigit(0,2,(encoder_1_value/100) % 10,false);
    lc.setDigit(0,1,(encoder_1_value/10) % 10,false);
    lc.setDigit(0,0,encoder_1_value % 10,false);

    hope this help
    Cheers, ryan

  3. #3
    New Member
    Join Date
    Nov 2014
    Location
    Portugal
    Posts
    4
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Help counting with MAX7219 and rotary

    Hello Ryan007!!!

    Thanks for your fast reply.
    These four lines of code were magic !!! THAT'S IT !!!!


    Thanks again for your help


    Cheers, m2snd

  4. #4
    New Member
    Join Date
    Nov 2014
    Location
    Portugal
    Posts
    4
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Help counting with MAX7219 and rotary

    Hello Ryan007

    setdigit parameters are
    1)witch number of max7219 do you use (in case of multiple chained max7219)
    2)witch digit do you want to operate (0 is the more left one, 7 is the more right one)
    3)your value to print for this digit
    4)do you want to print the "point"

    Please, can you tell me were did you find this useful informatiom?

  5. #5
    25+ Posting Member
    Join Date
    Mar 2014
    Location
    France
    Posts
    27
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Help counting with MAX7219 and rotary

    Hi m2snd
    You can study the library you use for your sketch : ledcontrol (I think)
    look at ledcontrol.h for description of all the fonctions that library provides
    You can also look at examples given with this lib
    cheers, ryan

  6. #6
    New Member
    Join Date
    Nov 2014
    Location
    Portugal
    Posts
    4
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Help counting with MAX7219 and rotary

    Thanks again !

  7. #7
    New Member
    Join Date
    Feb 2015
    Location
    Grecce
    Posts
    2
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Help counting with MAX7219 and rotary

    Hello Ryan007
    I work on the same code but the count only CW Ho can i do it, when i turn the encoder CCW
    the 7 seg display to count CCW and display -0000001

    thank you

  8. #8
    25+ Posting Member
    Join Date
    Mar 2014
    Location
    France
    Posts
    27
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Help counting with MAX7219 and rotary

    Hello Takis,
    Many things to verify...
    -Is your rotary encoder correctly hardwired ? There're multiple sort of rotary encoder: different pinout or/and how they work (x1, x2 ,x4). The sketch from M2snd may be not suitable to your rotary encoder...try using the quadrature library
    -have you print your variables to the console to see if you really have the right value that you expect to ? (debuging phase). encoderdata1 must return -1(if turned to one side) or 0(no move) or 1(if turned to the other side), and encoder_1_value must return your count
    -try to print manualy differents values to your 7 segments display to see how it reacts

    With these simple verifications I think you can point where your code(or hardware) produces error

    ryan

  9. #9
    New Member
    Join Date
    Feb 2015
    Location
    Grecce
    Posts
    2
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Help counting with MAX7219 and rotary

    thank you Ryan
    i shall try and play with different verifications i hope i can make it work
    i just uploaded a small video http://youtu.be/bPioTk8miP0

  10. #10
    25+ Posting Member
    Join Date
    Mar 2014
    Location
    France
    Posts
    27
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Help counting with MAX7219 and rotary

    Hello Takis,
    Thanks for your video, now I clearly see (I think) what is your trouble : printing negative value
    if you test a little sketch to print a negative value, I think you point the trouble
    so this is how I treat that in my project (pseudo code)

    value : signed int

    if your value < 0
    print '-' on the last left digit //set negative sign if negative value
    value_to_print=abs(value) //absolute value
    else
    print ' ' on the last left digit //remove negative sign if exists
    value_to_print=value // no change
    end if

    print each digits of value_to_print //print result