Question about using multiple bitmaps

Sorry, I'm not sure if this is the right place for this question (seems to fit in between a few things), just figured this is the most likely place that others have experience dealing with this particular thing...

But I was wondering, is there any way to use multiple bitmap arrays in PROGMEM in a way that's a little neater than just putting all of the bitmaps higher up in my program? Im just using two 128x64 OLEDs to display one of three bitmaps depending on sensor input (using between 4-6 sensors) and my program is already fairly large, I would just hate to have to add such large amounts of code if I could somehow call it indirectly (such as in a header or cpp file).

And sorry if this question is answered elsewhere, I tried looking as best I could but didn't come up with anything, and have yet to actually start using progmem to display anything, just trying to plan a little in advance and get the bitmap portion working on its own first. Thanks!

128x64 monochrome bitmaps are 1024 bytes. You can store several of these in Uno Flash memory.

Yes, I would put them into separate Tabs. Large data arrays would clutter up your main .INO file.

You can store the arrays in a .H file which you include from the main .INO
Or you store in separately compilable .C or .CPP files

H files are easier.

David.

Oh alright, thanks so much!

Alright, so I made all three of my bitmaps and made sure they work by testing each one individually following the format of the example program from the library I'm using (olikraus's u8g2 library), however I'm just a little bit confused how to proceed with combining all three into one file, only because I've never made a header file myself before, sorry.

In the example program I see where it defines the bitmap and puts the array into progmem, then simply uses the library's functions to access it when called in the loop, so if I were to omit the part in loop (because it would be irrelevant) would I then simply put all three sets of bitmap data in the file, save it as a header file, call it back into my main program, and it should recognise the bitmap objects when called?

Sorry again, I know the answer may seem obvious, I just want to be sure I'm following along correctly so I don't make a mess of my own program because I'm still not quite proficient. Thanks!

You have obviously generated XBM format C arrays with a PC program. You will have 3 arrays looking something like this:

//online conversion e.g. https://convertio.co/bmp-xbm/

//#define 40ba0ad0a77044e589873766d925d5f3_width 128
//#define 40ba0ad0a77044e589873766d925d5f3_height 64
//static char 40ba0ad0a77044e589873766d925d5f3_bits[] = {
static const uint8_t tractor2_128x64_xbm[] PROGMEM = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 
  ...
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x1F, 0x06, 0xFF, 
  0x01, 0x00, 0x00, 0x00, };

Just put them all in one H file in your project Tabs and #include "xbm_bitmaps.h"

Or you could use individual H files. In which case I suggest that you use the same name for the H file as the C array e.g. #include "tractor2_128x64_xbm.h"

David.

I was looking to put them all three into one file, I just wasn't sure if it was really as simple as just calling them from that (which again, I know is more just common sense, I just doubt my own understanding and wanted to be sure, sorry). But thanks a lot for the help!

Haha so it turns out it wasn't quite as simple as it seemed :stuck_out_tongue_winking_eye: I went ahead and added a new tab and named it with the file extension .h, which did appear to make the IDE recognize it as a header file (and save a header file in the project folder along with my sketch file), however when I try to upload it returns an error "C:\Users... Bitmap test.ino:8:18: fatal error: Bitmap.h: No such file or directory".

I made sure the IDE saved a copy of the header file in my project folder, but is there a different directory I should be checking (or might manually add the header file to myself)?

Sorry, if there is another directory I should find then I don't want to take up your time/energy in helping me find it, I can just do my fair share of searching myself elsewhere online first, I just want to be sure I know what I should be looking for.

Aha, sorry, that was my mistake, I had the syntax for the bitmap file header as '#include <Bitmap.h>' when it should have been '#include "Bitmap.h" ' as you had said above. Sorry, didn't think the syntax for that would be different but good to know. Thanks again!

The Arduino IDE is forgiving.

If you use quotes it will look in your local sketch tabs first. Then try the libraries folders.
If you use wedges it will only look in the libraries folder.

I presume that you have "clicked" about renaming gobbledygook arrays generated by the online tool.
Once you have put them in a H file you can just forget about them. They should just work (as long as you get the spelling correct)

Don't worry about unused bitmaps. The Linker will only use the ones that you reference in your sketch.

David.