The Smell of Molten Projects in the Morning

Ed Nisley's Blog: Shop notes, electronics, firmware, machinery, 3D printing, laser cuttery, and curiosities. Contents: 100% human thinking, 0% AI slop.

The New Hotness

  • Arduino: Remember the Ampersand with PROGMEM Variables!

    Got burned by this one again…

    The pgm_read_whatever() functions/macros require the address of the variable stored in PROGMEM (the program Flash ROM), not the variable’s value. More on that in the Arduino doc there.

    So, for example, this does not work, no matter how easy it might be to type:

    #include <avr/pgmspace.h>
    #define TZ_INDEX     3     // hardcoded for simplicity
    PROGMEM prog_char TimeZone[8] = {0,-3,-4,-5,-6,-7,-9,-10};
    char TZOffset;
    TZOffset = pgm_read_byte(TimeZone[TZ_INDEX]);
    

    What you really want looks like this:

    TZOffset = pgm_read_byte(&TimeZone[TZ_INDEX]);
    

    See the difference?

    Maybe next time I’ll remember that…