0

Sorry if there is information missing, im new to the topic.

I have an ESP32 connected to a Waveshare 7,5" RWB display, and i can display images by converting them to .xbm and including the hex code in the sketch. So far, so good.

But heres my question: What exactly are the requirements? Because when looking at the .xbm image code, i see that its a pattern like this:

0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00

But when i used a python script

import binascii
filename = 'test.png'
with open(filename, 'rb') as f:
    content = f.read()
print(binascii.hexlify(content))

to convert an image to hex code, i got this: b'89504e470d0a1a0a0000000d4948445200000280000001800802000000b2...'(continues for thousands of characters, didnt want to paste all of that here

However, when trying to run the sketch that successfully displayed the first hex code with the second image code, i got this error(cut out the big string clutter again):

...0000000049454e44ae426082};

^

C:\Users\Administrator\Desktop\SPI_test_example\SPI_test_example.ino: In function 'void loop()':

SPI_test_example:167:21: error: 'showBitmapExample' was not declared in this scope

   showBitmapExample();

                     ^

SPI_test_example:171:51: error: 'showFont' was not declared in this scope

   showFont("FreeMonoBold9pt7b", &FreeMonoBold9pt7b);

                                                   ^

exit status 1
'showBitmapExample' was not declared in this scope

So, i would like to know - does the image code have to have exactly the format i mentioned first? This is very important for me because i want to automate the process from inputting any image to using the resulting code to feed the display.

Thanks in advance!

EDIT: As far as my understanding goes, both formats are the same data, just that the first one is displaying a white pixel as 0xFF,0xFF,0xFF and the second one as FFFFFF.

2

This is not a question of image format but of what format c accepts data in.

What you have is a python representation of binary data in hexadecimal encoding. That can only be used with python.

C represents hexadecimal values by prefixing them with 0x.

You will have to change your python code to output each byte individually and prefix it with 0x and separate each one with a comma. That can then be wrapped in an array structure.

  • This makes so much sense, i didnt expect it to be bound to programming language! Converting should be easily doable - that leaves a few questions open for me: First, why does gimp, or rather the .xbm file, use C++ syntax (0x00)? Second, isnt one colored pixel displayed with 6 digits(000000 Black, FFFFFF White etc.) - how can i possible display the same range of colors with just 0x00? – Flying Thunder Oct 17 at 13:56
  • It's all just numbers. 0xFFFFFF is the same as 0xFF, 0xFF, 0xFF. Three bytes is all 0xFFFFFF is. That is, 0xFF red, 0xFF green and 0xFF blue. An XBM file is a piece of C source code. Other formats aren't. If yuo save a file as XBM you get C source code. – Majenko Oct 17 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.