logo elektroda
logo elektroda
X
logo elektroda

Clock on ESP12 and MAX7219 display - tutorial - part 1, ArduinoOTA, basics

p.kaczmarek2 2937 31
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
📢 Listen (AI):
  • #31 21766583
    max4elektroda
    Level 21  
    I see, that's possible.
    Please choose, which way you prefer:

    1. The driver is not really handled as driver, but it's components are called
    (like the last one I made:
    DRV_Generic_Init() calls CLOCK_Init();
    DRV_AppendInformationToHTTPIndexPage() calls CLOCK_AppendInformationToHTTPIndexPage();
    DRV_OnEverySecond() calls CLOCK_OnEverySecond();
    )

    2. "Extend" the drivers to generally allow for "hidden" drivers (running, but not shown) or, a completely new idea

    3. Distinguish between started and auto-started drivers (e.g. BL0937 is also started without an explicit "startdriver BL0937").
    While thinking of it, it needs another name like "started by system" to avoid mixing with "automatically started" by startup cmd or autoexec.

    Added after 9 [hours] 38 [minutes]:

    Since I got my MAX7219 display this weekend, I tried your project (on a W800).

    Maybe you would like to use some of my changes, too?!?

    I missed "seconds" on display, but the numbers wouldn't fit on the display. So I made some changes and additions to the font used.
    Here is the changed part of the "font" in drv_max72xx_single.c

    - small digits in unused chars 10 to 19 (allows for seconds and a (two digit) year on 4 8x8 displays)
    - made "." smaller (46)
    - made digits smaller (4 columns) but same width for all (no "jump" e.g. from "0" to "1" or "1" to "2")
    Spoiler:

    
    
        0,    // 6 - Unused
       0,    // 7 - Unused
       0,    // 8 - Unused
       0,    // 9 - Unused
       3, 124, 68, 124,   // 10 - 0 mini
       3, 0, 124, 0,      // 11 - 1 mini
       3, 116, 84, 92,      // 12 - 2 mini
       3, 84, 84, 124,      // 13 - 3 mini
       3, 28, 16, 124,      // 14 - 4 mini
       3, 92, 84, 116,      // 15 - 5 mini
       3, 124, 84, 116,   // 16 - 6 mini
       3, 4, 116, 12,      // 17 - 7 mini
       3, 124, 84, 124,   // 18 - 8 mini
       3, 92, 84, 124,      // 19 - 9 mini
       0,    // 20 - Unused
       0,    // 21 - Unused
       0,    // 22 - Unused
       0,    // 23 - Unused
       0,    // 24 - Unused
       0,    // 25 - Unused
       0,    // 26 - Unused
       0,    // 27 - Unused
       0,    // 28 - Unused
       0,    // 29 - Unused
       0,    // 30 - Unused
       0,    // 31 - Unused
       2, 0, 0,                  // 32 - Space
       1, 95,                    // 33 - !
       3, 7, 0, 7,               // 34 - "
       5, 20, 127, 20, 127, 20,  // 35 - #
       5, 36, 42, 127, 42, 18,   // 36 - $
       5, 35, 19, 8, 100, 98,    // 37 - %
       5, 54, 73, 86, 32, 80,    // 38 - &
       2, 4, 3,                  // 39
       3, 28, 34, 65,            // 40 - (
       3, 65, 34, 28,            // 41 - )
       5, 42, 28, 127, 28, 42,   // 42 - *
       5, 8, 8, 62, 8, 8,        // 43 - +
       2, 128, 96,               // 44 - ,
       5, 8, 8, 8, 8, 8,         // 45 - -
    //   2, 96, 96,                // 46 - .
       1, 64,           // 46 - .   (smaller . )
       5, 32, 16, 8, 4, 2,       // 47 - /
       4, 62, 65, 65, 62,        // 48 - 0  (4-column small)
       4, 0, 66, 127, 64,        // 49 - 1  (4-column small)
       4, 114, 73, 73, 70,       // 50 - 2  (4-column small)
       4, 34, 73, 73, 62,        // 51 - 3  (4-column small)
       4, 12, 10, 127, 8,        // 52 - 4  (4-column small)
       4, 39, 73, 73, 49,        // 53 - 5  (4-column small)
       4, 62, 73, 73, 50,        // 54 - 6  (4-column small)
       4, 1, 121, 5, 3,          // 55 - 7  (4-column small)
       4, 54, 73, 73, 54,        // 56 - 8  (4-column small)
       4, 38, 73, 73, 62,     // 57 - 9  (4-column small)
       1, 20,                    // 58 - :
       2, 128, 104,              // 59 - ;
       4, 8, 20, 34, 65,         // 60 - <
       5, 20, 20, 20, 20, 20,    // 61 - =
       



    to use the "small" numbers, the string needs to be "transposed" by -38, so e.g. digit 0 is not using 48 but 10.

    In drv_max72xx_clock.c an additional function:

    void transposeString(char *input, int shift) {
        for (int i = 0; i < strlen(input); i++) {
            input[i] += shift;  // Shift each character by the specified amount
        }
    }
    


    and this output (no temperature here atm), so, just for testing, I display only time and date.
    I used sprintf to print the data, to "seperate" two chars by another empty columns, I used char "127" (this has 0 columns, so only the one after this empty char is written).
    Seconds and year are first printed to a string, which is transposed to use the small numbers I added to the font.


    
    void Clock_Send(int type) {
       char time[64];
       TimeComponents tc;
       float val;
       char *p;
       time_t ntpTime;
    
       ntpTime=(time_t)TIME_GetCurrentTime();
       // NOTE: on windows, you need _USE_32BIT_TIME_T 
       tc=calculateComponents((uint32_t)ntpTime);
    
       time[0] = 0;
       p = time;
       char tempstr[5];   // temp string for seconds or year -> converted to "small" digits
       if (type == CLOCK_TIME) {
    /*
    //      p = my_strcat(p, " ");
          p = add_padded(p, tc.hour);
          p = my_strcat(p, " ");
    //      p = my_strcat(p, ":");
          p = add_padded(p, tc.minute);
          p = my_strcat(p, " ");
    //      p = my_strcat(p, ":");
          p = add_padded(p, tc.second);
          strcat(p, "   ");
    */
          sprintf(tempstr,"%02i",tc.second);
          transposeString(tempstr, -38);      // move second digits from 48 - 57  --> 10 - 19 (small numbers)
          sprintf(time,"%02i:%02i%c%s", tc.hour,tc.minute, 127, tempstr);
       }
       else if (type == CLOCK_DATE) {
    /*
    //      p = my_strcat(p, " ");
          p = add_padded(p, tc.day);
          p = my_strcat(p, ".");
          p = add_padded(p, tc.month);
          p = my_strcat(p, ".");
          //p = add_padded(p, tc.year);
          strcat(p, "   ");
    */
          sprintf(tempstr,"%02i",(tc.year%100));
          transposeString(tempstr, -38);      // move year digits from 48 - 57  --> 10 - 19 (small numbers)      
          sprintf(time,"%02i.%02i.%c%s", tc.day,tc.month, 127, tempstr);
       }
       else if (type == CLOCK_HUMIDITY) {
          if (false==CHANNEL_GetGenericHumidity(&val)) {
             // failed - exit early, do not change string
             return;
          }
          sprintf(time, "H: %i%%   ", (int)val);
       } 
       else if (type == CLOCK_TEMPERATURE) {
          if (false == CHANNEL_GetGenericTemperature(&val)) {
             // failed - exit early, do not change string
             return;
          }
          sprintf(time, "T: %iC    ", (int)val);
       }
    
       CMD_ExecuteCommandArgs("MAX72XX_Print", time, 0);
    }
    ...
    
    // no temperature, so only show date (shorter) and time (longer)
    
    void Run_NoAnimation() {
       cycle+=4;
       if (cycle < 10) {
          Clock_SendDate();
       }
    //   else if(cycle < 20) {
       else {
          Clock_SendTime();
       }
    /*
       else if (cycle < 30) {
          Clock_SendHumidity();
       }
       else {
          Clock_SendTemperature();
       }
    */
       CMD_ExecuteCommandArgs("MAX72XX_refresh", "", 0);
       cycle %= 40;
    }


    Here's how it looks (demonstrating also the setting of the clock):



  • ADVERTISEMENT
  • #32 21767349
    p.kaczmarek2
    Moderator Smart Home
    Thank you for fixes! This is what I meant:
    max4elektroda wrote:

    1. The driver is not really handled as driver, but it's components are called
    (like the last one I made:
    DRV_Generic_Init() calls CLOCK_Init();
    DRV_AppendInformationToHTTPIndexPage() calls CLOCK_AppendInformationToHTTPIndexPage();
    DRV_OnEverySecond() calls CLOCK_OnEverySecond();
    )

    Long story short: I like your changes, but I can't allow many core obk modifications that are not necessary required by features due to our limited testing capability and due to flash size. We have so many platforms that we can't really test them all quickly, so I'd prefer to receive pull request either that are substantially helpful for core OBK, or for components that are not core (drivers).


    max4elektroda wrote:

    Maybe you would like to use some of my changes, too?!?

    Those are probably easy to merge, just what about animated mode? Still, I really like the smaller font for secnds and I have no strict requirements for MAX72XX driver - this driver is not enabled by default so there 0% risk of breaking anything.

    Just let me know which PRs are ready to merge and I'll do it.

    Here's a generic list of ideas/suggestions what can be done next:
    - in general, better MAX72XX, maybe with better scroll transition anims between displays, like there: https://kbprogram.pl/matrycowy-zegar-led-z-termometrem-i-wifi/
    - more self tests for obk, in general
    - do (probably could be done with LLM) a visual addClockEvent configurator that outputs to either autoclock.bat and call it along autoexec.bat on start, or directly to autoexec.bat
    - improve berry bindings and self tests and examples
    - consider making full max72xx clock logic in berry

    PS: you saw that, right? You can prototype on windows https://www.elektroda.com/rtvforum/topic4154322.html
    Helpful post? Buy me a coffee.
📢 Listen (AI):
ADVERTISEMENT