Jump to content
Ultimaker Community of 3D Printing Experts
Sign in to follow this  

Poking around in the firmware and I'm stuck.

Recommended Posts

Tried StackOverflow (good luck getting noticed in that avalanche of questions...) and another forum without luck so now I'm here.

Basically I'm trying to modify lcd_lib_draw_stringP and since I've never touched Arduino code before I'm flailing around in the dark even more than usual. The problem is that a variable doesn't seem to hold the value I'm expecting even though printing it out on the screen suggests it does... :)

The array I'm trying to get data from:


static const uint16_t f_04b036ptDescriptors[95][3] PROGMEM =
{2, 7, 0}, //
{1, 7, 2}, // !
{3, 7, 3}, // "

Snippet of the function:


void lcd_lib_draw_small_stringP(uint8_t x, uint8_t y, const char* pstr)
uint16_t offset;
uint8_t index;
for(char c = pgm_read_byte(pstr); c; c = pgm_read_byte(++pstr))
index = c - ' ';
offset = f_04b036ptDescriptors[index][2];

How I'm calling it:


lcd_lib_draw_small_stringP(15, 10, PSTR("M"));

Now, the trouble I'm having is with the c variable. If I print it out on the screen using the helper function int_to_string I get the expected result (77 for 'M'). index also shows the expected value after subtracting ' ' if I print it out (45). However, I can't seem to use index to get the correct item from the array into offset. I get back "weird" values like -8467 instead of the expected 1-300 range.

If I set index = 45 and/or set c = 'M' manually inside the function everything works just fine.

What am I missing?


Share this post

Link to post
Share on other sites


offset = f_04b036ptDescriptors[index][2];

That's not valid for accessing program memory. You have to use the pgm_read_word() function like this:


offset = (uint16_t)pgm_read_word(&f_04b036ptDescriptors[index][2]);

Or alternatively you should be able to do (but above syntax better and I may have the ptr math all wrong here):


offset = (uint16_t)pgm_read_word(f_04b036ptDescriptors+index*3+2);


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Our picks

    • Ultimaker Cura | a new interface
      We're not only trying to always make Ultimaker Cura better with the usual new features and improvements we build, but we're also trying to make it more pleasant to operate. The interface was the focus for the upcoming release, from which we would already like to present you the first glance. 
        • Like
      • 86 replies
    • "Back To The Future" using Generative Design & Investment Casting
      Designing for light-weight parts is becoming more important, and I’m a firm believer in the need to produce lighter weight, less over-engineered parts for the future. This is for sustainability reasons because we need to be using less raw materials and, in things like transportation, it impacts the energy usage of the product during it’s service life.
        • Like
      • 12 replies

Important Information

Welcome to the Ultimaker Community of 3D printing experts. Visit the following links to read more about our Terms of Use or our Privacy Policy. Thank you!