Bitmap to Byte array for e-ink display

Published on Saturday 28 April 2018
Categories: Home Automation | Programming and Code |

e-paper display

Over the past few months Andrew has been working on a new circuit for a custom home alarm system to replace our current hardwired commercial alarm.

For the display panel on the new alarm we are going to be using a e-ink display to show the status of the alarm and the sensor status for each door and window.

We sourced a basic 2.9 inch e-ink display from ebay and it is a 296x128 pixel back and white display and a SPI interface from https://www.waveshare.com/wiki/2.9inch_e-Paper_Module

The display uses an array of bytes to write to the display panel with each byte controlling 8 pixels. You can either write the entire display each time or select a starting x and y location and write the data as required.

The manufacturer has a windows application to convert images into the data format required but it is all in Chinese and we couldn’t get it to work.

I wrote a simple Windows form application which opens a bitmap file and then loops though each row and column and gets the hex value for each pixel. If the pixel is black it then returns “0” for a black pixel or “1” for a white pixel.

Each row is then combined into a series of 1’s and 0’s  and converted into a byte array which is then saved into a StringBuilder and formatted as HEX values with comma separators.

The resulting text output can then be saved into text file and used on the panels control software to write to the display via the SPI bus.

e-paper display with image loaded

Converting the above 16px x 16px image results in the following code with each row of pixels being converted into two byte values per line.

{
0x9C,0xE7,
0x08,0x43,
0x08,0x43,
0x9C,0xE7,
0xFF,0xFF,
0xCF,0x39,
0x86,0x10,
0x86,0x10,
0xCF,0x39,
0xFF,0xFF,
0xF9,0xFF,
0xF0,0xE7,
0xF0,0xC3,
0xF9,0xC3,
0xFF,0xE7,
0xFF,0xFF,
};

The image below shows a converted photo of me into a 1 bit BMP file and then converted into the byte array for the display.

e-paper display with image loaded

The source code for the app can be downloaded from https://github.com/briandorey/BitmapToByteArrayConverter

Permalink


1 Comments


John Waalkes

18 December 2019 at 8:46 pm

That explains why the CrystalFontz converter is giving me trouble. :)

Thanks!


Leave a comment

About Me

Brian Dorey

Welcome to my blog, here you will find my projects and other things.
I make websites and manufacturer and sell expansion boards for the Raspberry Pi range of computers.

AB Electronics Raspberry Pi shop

Social Media

Popular Posts

Small image for Raspberry Pi Zero W external antenna mod

Raspberry Pi Zero W external antenna mod
04 MARCH 2017
89,361 views

Small image for Ford Sync 3 USB Drive Music Playlists

Ford Sync 3 USB Drive Music Playlists
22 OCTOBER 2016
60,332 views

Small image for Echo Dot 3rd Gen Smart speaker Teardown

Echo Dot 3rd Gen Smart speaker Teardown
21 JULY 2019
57,553 views

Small image for DIY Pick and Place V2 Project Complete

DIY Pick and Place V2 Project Complete
23 NOVEMBER 2013
35,176 views