Challenge - bin2header.py won't work for me (yet)

128x128 pixel 1.5" full colour OLED display with MicroSD card slot. [Product page]
Post Reply
mikehains
Posts: 5
Joined: Fri Jul 26, 2013 2:17 pm

Challenge - bin2header.py won't work for me (yet)

Post by mikehains » Sat Dec 12, 2015 10:27 pm

OK ... so I've created simple 16 colour bmp files (32x34 pixels) using each of the 3 different alternatives: GIMP + ImageMagick + Paint

I've got Python 3.0 running and have attempted to use bin2header.py. The output I get is:

Code: Select all

>>> os.popen("python bin2header.py output.bmp")
<os._wrap_close object at 0x00000000025C0780>
>>> Traceback (most recent call last):
  File "bin2header.py", line 110, in <module>
    bin2header(args.input, output)
  File "bin2header.py", line 75, in bin2header
    as_hex = [ ("0x%02x" % b) for b in content ]
TypeError: %x format: a number is required, not str
Clearly I'm doing something wrong. Looking for help (Thanking You in advance)

mikehains
Posts: 5
Joined: Fri Jul 26, 2013 2:17 pm

Re: Challenge - bin2header.py won't work for me (yet)

Post by mikehains » Sun Dec 13, 2015 5:39 am

OK - so here's how I solved this ... pretty easy actually !

I simply put the images on the SD card, loaded them through the module, and wrote back via serial the data that the FTOLED will be happy with. Then I just copied and pasted this data in an "h" file mimicking the "sprite" example ... works like a charm !

The little Arduino sketch I wrote to read back the file from sd card is very simple:

Code: Select all

#include <SPI.h>
#include <SD.h>
#include <FTOLED.h>
#include <fonts/SystemFont5x7.h>

const byte pin_cs = 7;
const byte pin_dc = 2;
const byte pin_reset = 3;
const byte pin_sd_cs = 4;

OLED oled(pin_cs, pin_dc, pin_reset);

#define MSG_NOSD F("MicroSD card not found")
#define MSG_FILENOTFOUND F("Label.bmp not found")
#define MSG_BMPFAIL F("Failed to load BMP: ")

OLED_TextBox text(oled);

void setup()
{
  byte vCount =0;
  byte vReadByte;
  Serial.begin(115200);
  oled.begin();
  oled.selectFont(SystemFont5x7);

  while(!SD.begin(pin_sd_cs)) {
    Serial.println(MSG_NOSD);
    text.println(MSG_NOSD);
    delay(500);
  }
  oled.begin();  // Faster ?

  File image = SD.open("bulboff.bmp");
  if(!image) {
    text.println(MSG_FILENOTFOUND);
    Serial.println(MSG_FILENOTFOUND);
  } else {
    while (image.available()) {
      vReadByte = image.read();
      Serial.print("0x");
      Serial.print(vReadByte,HEX);
      vCount++;
      if (vCount < 16) {
         Serial.print(", ");
      }
      else {
         Serial.println(",");
         vCount = 0;        
      }
    }

    BMP_Status result = oled.displayBMP(image, 0, 0);
    if(result != BMP_OK) {
      Serial.print(MSG_BMPFAIL);
      Serial.println((int) result);
      text.print(MSG_BMPFAIL);
      text.println((int) result);
    }
  }
}

void loop()
{
}

angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: Challenge - bin2header.py won't work for me (yet)

Post by angusgr » Wed Dec 30, 2015 5:54 am

Nice solution!

To get things running with Python, try running

Code: Select all

python3 bin2header.py output.bmp
- depending on the system you're on, Python may default to Python 2 not 3.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest