Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify Image Conversion #23

Open
Ayush4441 opened this issue Jul 15, 2024 · 0 comments
Open

Simplify Image Conversion #23

Ayush4441 opened this issue Jul 15, 2024 · 0 comments

Comments

@Ayush4441
Copy link

Hi,
I am using a webpage to convert images to C-style header files: File to C Array Converter. It easily converts images to arrays of bytes. I use this method for projects on NodeMCU boards, but I'm facing issues with Raspberry Pi Pico. The bin2c tool doesn't properly convert my BMP files, and ssd1306_bmp_show_image_with_offset doesn’t display my image.

Is there a way to draw my image using the output from the File to C Array Converter?

My Example:

#include <hardware/i2c.h>

#define DISPLAY_SCL 11
#define DISPLAY_SDA 10
#define DISPLAY_I2C i2c1
#define DISPLAY_ADD 0x3C
#define DISPLAY_HZ 800000

#include "Driver/ssd1306.h"

#define IMG_HEIGHT 64
#define IMG_WIDTH 64

// array size is 512
uint8_t *IMG = (uint8_t[]){
    0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 
    0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 
    0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 
    0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 
    0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 
    0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 
    0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 
    0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 
    0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 
    0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 
    0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0111110, 0b0000000, 0b0000000, 
    0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000001, 0b1000001, 0b1100000, 0b0000000, 
    0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000110, 0b0111110, 0b0011000, 0b0000000, 
    0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0011001, 0b1111111, 0b1100100, 0b0000000, 
    0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b1100111, 0b1111111, 0b1111010, 0b0000000, 
    0b0000000, 0b0000000, 0b0000000, 0b0000001, 0b0011111, 0b1111111, 0b1111010, 0b0000000, 
    0b0000000, 0b0000000, 0b0000000, 0b0000010, 0b1111111, 0b1111111, 0b1111101, 0b0000000, 
    0b0000000, 0b0000000, 0b0000000, 0b0001101, 0b1111111, 0b1111111, 0b1111101, 0b0000000, 
    0b0000000, 0b0000000, 0b0000000, 0b0010011, 0b1101111, 0b1111111, 0b1111101, 0b0000000, 
    0b0000000, 0b0000000, 0b0000000, 0b0101111, 0b1110111, 0b1111111, 0b1111101, 0b0000000, 
    0b0000000, 0b0000000, 0b0000000, 0b1011111, 0b1110111, 0b1111111, 0b1111101, 0b1000000, 
    0b0000000, 0b0000000, 0b0110001, 0b0111111, 0b1111011, 0b1111111, 0b1111101, 0b1000000, 
    0b0000000, 0b0000000, 0b0111000, 0b1111111, 0b1111011, 0b0001110, 0b1111101, 0b1000000, 
    0b0000000, 0b0000000, 0b0011101, 0b0111111, 0b1111011, 0b1111110, 0b1111101, 0b1000000, 
    0b0000000, 0b0000000, 0b0001110, 0b1001111, 0b1111011, 0b1111110, 0b1111011, 0b1000000, 
    0b0000000, 0b0000000, 0b0000111, 0b1110011, 0b1111111, 0b1111101, 0b1111011, 0b1000000, 
    0b0000000, 0b0000000, 0b0100011, 0b0111100, 0b1111111, 0b1111101, 0b0111011, 0b1000000, 
    0b0000000, 0b0000000, 0b1010001, 0b1011111, 0b0111111, 0b1111011, 0b0111010, 0b1000000, 
    0b0000000, 0b0000000, 0b0110000, 0b1100111, 0b1001111, 0b1111011, 0b1010101, 0b1000000, 
    0b0000000, 0b0000000, 0b0111000, 0b1110001, 0b1110011, 0b1111111, 0b1010111, 0b1000000, 
    0b0000000, 0b0000001, 0b1111000, 0b0111010, 0b1111100, 0b1111111, 0b1001101, 0b1000000, 
    0b0000000, 0b0000010, 0b1111100, 0b0011101, 0b0011111, 0b1111111, 0b1101111, 0b1000000, 
    0b0000000, 0b0000101, 0b1111101, 0b0001110, 0b1100111, 0b0111111, 0b1010111, 0b0000000, 
    0b0000000, 0b0001011, 0b1111110, 0b1010111, 0b1110001, 0b0011111, 0b1011111, 0b0000000, 
    0b0000000, 0b0001011, 0b1111110, 0b0101011, 0b0100000, 0b0111111, 0b0111101, 0b0000000, 
    0b0000000, 0b0010111, 0b1111011, 0b1001101, 0b1000001, 0b1011110, 0b0111111, 0b0000000, 
    0b0000000, 0b0010111, 0b1110111, 0b0100110, 0b1100010, 0b0011111, 0b1111111, 0b0000000, 
    0b0000000, 0b0101111, 0b1110111, 0b0010111, 0b1110101, 0b0010001, 0b1111111, 0b0000000, 
    0b0000000, 0b0101111, 0b1101111, 0b0111010, 0b0111010, 0b0111010, 0b1111111, 0b0000000, 
    0b0000000, 0b1011111, 0b1111111, 0b1011010, 0b0011100, 0b1111001, 0b1111110, 0b0000000, 
    0b0000000, 0b1011011, 0b1011111, 0b1011100, 0b0001100, 0b0110011, 0b1111110, 0b0000000, 
    0b0000000, 0b0111100, 0b0111111, 0b1101100, 0b0000001, 0b1110111, 0b1111100, 0b0000000, 
    0b0000000, 0b0111111, 0b0111111, 0b1101100, 0b0000010, 0b1110111, 0b1111100, 0b0000000, 
    0b0000001, 0b1111111, 0b1000000, 0b1110000, 0b0000001, 0b0101111, 0b1111000, 0b0000000, 
    0b0000001, 0b1111111, 0b1111111, 0b1110000, 0b0000111, 0b1011111, 0b1111000, 0b0000000, 
    0b0000001, 0b1111111, 0b1111111, 0b1110000, 0b0000110, 0b0111111, 0b1111000, 0b0000000, 
    0b0000001, 0b1111111, 0b1111111, 0b1110010, 0b0001011, 0b1011101, 0b1110000, 0b0000000, 
    0b0000010, 0b1111111, 0b1111111, 0b1110001, 0b0100110, 0b1111111, 0b1100100, 0b0000000, 
    0b0000010, 0b1111111, 0b1111111, 0b1110010, 0b0001001, 0b1110111, 0b1000100, 0b0000000, 
    0b0000010, 0b1111111, 0b1111111, 0b1010010, 0b1010111, 0b1111111, 0b0000100, 0b0000000, 
    0b0000010, 0b1111111, 0b1111111, 0b0110000, 0b1101101, 0b1011101, 0b0000100, 0b0000000, 
    0b0000010, 0b1111111, 0b0111111, 0b1110001, 0b1011010, 0b1111110, 0b0000100, 0b0000000, 
    0b0000010, 0b1111111, 0b1011110, 0b1110011, 0b0110101, 0b1010100, 0b0010100, 0b0000000, 
    0b0000010, 0b1111111, 0b1111100, 0b0111110, 0b1101011, 0b1111000, 0b0000100, 0b0000000, 
    0b0000010, 0b1111111, 0b1110011, 0b1111001, 0b1000101, 0b1010000, 0b0111100, 0b0000000, 
    0b0000001, 0b1111111, 0b1001111, 0b1100110, 0b0101010, 0b1100000, 0b0000010, 0b0000000, 
    0b0000001, 0b1111110, 0b0111111, 0b0011000, 0b0010101, 0b0000000, 0b1000010, 0b0000000, 
    0b0000000, 0b0011111, 0b1111110, 0b1101010, 0b0101110, 0b0000000, 0b0000110, 0b0000000, 
    0b0000000, 0b1100001, 0b1110001, 0b0000000, 0b0010000, 0b0000001, 0b1111100, 0b0000000, 
    0b0000000, 0b0111110, 0b0001110, 0b0001000, 0b1100000, 0b0000111, 0b1111100, 0b0000000, 
    0b0000000, 0b0001111, 0b1110000, 0b0001111, 0b0000000, 0b0000000, 0b0000110, 0b0000000, 
    0b0000000, 0b0000000, 0b1111111, 0b1111000, 0b0000000, 0b0000010, 0b1000010, 0b0000000, 
    0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b1111111, 0b1111110, 0b0000000, 
    0b0000000, 0b0000000, 0b0000000, 0b0001111, 0b1111111, 0b1111111, 0b1111110, 0b0000000
};

int main() 
{
    ssd1306_t display;

    i2c_init(DISPLAY_I2C, DISPLAY_HZ);
    gpio_set_function(DISPLAY_SCL, GPIO_FUNC_I2C);
    gpio_set_function(DISPLAY_SDA, GPIO_FUNC_I2C);
    gpio_pull_up(DISPLAY_SCL);
    gpio_pull_up(DISPLAY_SDA);

    if(!ssd1306_init(&display, 128, 128, DISPLAY_ADD, DISPLAY_I2C))
        return 1;

    ssd1306_poweron(&display);
    ssd1306_clear(&display);

    while (true)
    {
        ssd1306_clear(&display);
        ssd1306_bmp_show_image(&display, IMG, 512);
        ssd1306_show(&display);
    }

    ssd1306_poweroff(&display);

    return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant