• Hi there,

    I wonder if anyone has tried to handle the dot (".") LED for displaying floating numbers, using this piece of HW? https://www.espruino.com/MAX7219

    In the MAX7219 datasheet, page 7 ( https://www.espruino.com/datasheets/MAX7­219.pdf ) , it says

    When the code B decode mode is used, the decoder
    looks only at the lower nibble of the data in the digit
    registers (D3–D0), disregarding bits D4–D6. D7, which
    sets the decimal point (SEG DP), is independent of the
    decoder and is positive logic (D7 = 1 turns the decimal
    point on)
    

    Which seems to allow handling the dot (DP).
    Do you guys think the MAX7219 module could be upgraded in order to support displaying floating numbers?

  • Hi - yes, it could definitely be tweaked. I guess you'd want 1.234 to effectively put the dot on the 1 digit?

    Can you try adding this code after you have initialised the MAX7219 and trying again?

    disp.set = function(val) {
      spi.write([0x9,0xff],cs); // decode all as numbers
      var map = "0123456789-EHLP ";
      var a = new Array(8);
      a.fill(15); // all off
      val = val.toString();
      var hadDot = false;
      var j = 7;
      for (var i=val.length-1;i>=0;i--) {
        if (val[i]!=".") {
          if (j>=0) 
            a[j--] = map.indexOf(val[i]) | (hadDot?128:0);
          hadDot = false;
        } else hadDot = true;
      }
      for (i=0;i<8;i++)
        spi.write([8-i,a[i]],cs);
      spi.write([0x0c,1],cs); // no shutdown
    };
    
  • @Gordon, I had to wait less than 16 minutes to read the solution from you... You are by far the most brilliant support ever! :)

    I don't have the module on hand right now but I will try your code tomorrow morning.
    Again, thank you for the excellence of the support!

  • No problem! Let me know if it works for you and I'll update the module's code with the new function :)

  • it works like a charm! tested with

    disp.set("HH");
    disp.set("H------H");
    disp.set(3);
    disp.set(3.1);
    disp.set(3.14);
    disp.set(3.14159);
    disp.set(3.14159+"H");
    disp.set("3.14159H");
    

    Everything is working as expected. Thank you very much @Gordon !!

    Regarding the above testing, I think the module can be upgraded :)

  • Whoops, I spoke a little quickly. I did not test a specific case when there is not sufficient digits to print the value:
    disp.set(99999999.1)
    On the display, the value 99999403is displayed instead.

  • I just tested that, and it's to be expected. Because of rounding, 99999999.1 ends up turning into 99999999.09999999403 when converted to a string with toString, and it's the last few digits that get shown.

    If you want full control over it, convert it to a string manually yourself and pass the string in - eg: disp.set((99999999.1).toFixed(1))

    I'll update the library with the new code :)

  • I just tested that, and it's to be expected. Because of rounding, 99999999.1 ends up turning into 99999999.09999999403 when converted to a string with toString, and it's the last few digits that get shown.

    I didn't even thought this far. This seems to make sense. Thanks!

  • It's all updated now, so using disp.set without that extra bit of code I gave you should work fine :)

  • It's all updated now, so using disp.set without that extra bit of code I gave you should work fine :)

    Thank you very much, it works well!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

[SOLVED] 7 Segment driver MAX7219 : handling the dot on floating numbers

Posted by Avatar for Jean-Philippe_Rey @Jean-Philippe_Rey

Actions