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

QR to Bitmap #3

Open
jjjrmy opened this issue Aug 23, 2017 · 17 comments
Open

QR to Bitmap #3

jjjrmy opened this issue Aug 23, 2017 · 17 comments

Comments

@jjjrmy
Copy link

jjjrmy commented Aug 23, 2017

I'm trying to create a BMP of the QR code to display on a 128x64 OLED screen like you mentioned in the readme.
Is there an example for this?

I have tried using your for loop to generate the bits, but that did not work.

@yifanshu02
Copy link

some days ago,i had try it.
core code is:
for (uint8_t y = 0; y < qrcode.size; y++) {
for (uint8_t x = 0; x < qrcode.size; x++) {
if (qrcode_getModule(&qrcode, x, y)) {
u8g.setColorIndex(1);
}else{
u8g.setColorIndex(0);
}
u8g.drawPixel(x0+x,y0+y);
}
}
but it work slowly...T_T

@jjjrmy
Copy link
Author

jjjrmy commented Aug 23, 2017

what is variable u8g?

@yifanshu02
Copy link

@jjjrmy
Copy link
Author

jjjrmy commented Aug 23, 2017

where is x0 and y0 defined?
without it the QR code is half as wide as it is tall.

@yifanshu02
Copy link

x0,and y0 is the beginning coordinates of QRcode picture...
i use a 12864LCD, and i want to show the QRcode in the center,code is:

#define Lcd_X  128
#define Lcd_Y  64
void EncodeDataInLCDAtCenter(uint8_t version,uint8_t ecc,const char *lpsSource){
    _ToBeUpdatedFlag = 0;
    
    uint8_t BufferSize = qrcode_getBufferSize(version);
    uint8_t qrcodeData[BufferSize];
    qrcode_initText(&qrcode, qrcodeData, version, ecc, lpsSource);
    //qrcode_initText(QRCode *qrcode, uint8_t *modules, uint8_t version, uint8_t ecc, const char *data)

    uint8_t x0 = (Lcd_X-qrcode.size)/2;
    uint8_t y0 = (Lcd_Y-qrcode.size)/2;

    for (uint8_t y = 0; y < qrcode.size; y++) {
        for (uint8_t x = 0; x < qrcode.size; x++) {
            if (qrcode_getModule(&qrcode, x, y)) {
              u8g.setColorIndex(1);
            }else{
              u8g.setColorIndex(0);
            }
            u8g.drawPixel(x0+x,y0+y);
        }
    }
}

@ricmoo
Copy link
Owner

ricmoo commented Aug 23, 2017

It depends on the LCD or OLED display you use, but @yifanshu02 code looks good.

I usually use the Adafruit Library, but it is similar.

I will be posting a more in depth example soon.

This library is what I used in my Firefly Hardware Wallet. Once I post the source code for that, I'll link to it from the README as an example.

@ricmoo
Copy link
Owner

ricmoo commented Aug 23, 2017

One other note on using the 128x64 monochrome OLED; "on" modules in the QR code are black and "off" modules are white, so you will need to take this into account when using the display (since "on" pixels are white and "off" pixels are black).

@umanayana
Copy link

Has anyone got this to display on a OLED which is 128 x 64. I am trying to do the something without any luck?

@nielsnl68
Copy link

I used it with a different lcd and it did work fine for me. Can you show what you already have done?

@umanayana
Copy link

` HI_GFX_Clear(1);

static uint8_t buffer[QR_VERSION_BUFFER_SIZE(7)] = { 0 };

QRCode qrcode = { 0 };
const int8_t error = qrcode_initText(&qrcode, buffer, 7, 0, "1245");
ASSERT_DEBUG_MODE(0 == error);

const uint8_t y0 = 10;
const uint8_t x0 = 10;

for (uint8_t y = 0; y < qrcode.size; y++)
{
    for (uint8_t x = 0; x < qrcode.size; x++)
    {
        uint8_t pixel = 0;
        if(qrcode_getModule(&qrcode, x, y) )
        {
            /*Put black pixel*/
            pixel = 1;
        }
        else
        {
            /*White pixel*/
            pixel = 0;
        }

        HI_GFX_Draw_Pixel(x0 + x, y0 + y, pixel);

    }

}`

mvimg_20180613_150802

@ricmoo
Copy link
Owner

ricmoo commented Jun 13, 2018

Can you try:

QRCode qrcode;

Rather than initializing it to { 0 }?

@umanayana
Copy link

That won't do anything. I am just clearing the memory because qrcode is initialised on the stack.
Is a single module equivalent to 1 pixel?

@ricmoo
Copy link
Owner

ricmoo commented Jun 13, 2018

Yes, a single module is 1 pixel.

I don't think that is clearing the stack correctly. You shouldn't need to do either = { 0 }. I always use the QR codes on the stack.

But here is a working use of it:
https://github.com/firefly/wallet/blob/master/source/firefly/firefly_display.cpp#L411

And here is the initialization:
https://github.com/firefly/wallet/blob/master/source/firefly/firefly.ino#L325

The only other thing I can think of is that the HI_GFX_Draw_Pixel isn't working, because other than that it looks fine to me.

@nielsnl68
Copy link

nielsnl68 commented Jun 13, 2018 via email

@umanayana
Copy link

The pixel draw works because I used it for many other things.
Also If I remove qrcode_getModule() the code should just draw a black square on a white surface which is does.

It seems that the buffer is encoded incorrectly. I will start digging through the library.

Thanks for the help.

@ricmoo
Copy link
Owner

ricmoo commented Jun 13, 2018

The function grid is used to determine is a given module is a function module, which is not subject to masking.

Can you try running the test cases? You should be able to modify them to use your "12345", which will compare this library against the known-correct CPP library.

@pradeepngupta
Copy link

some days ago,i had try it.
core code is:
for (uint8_t y = 0; y < qrcode.size; y++) {
for (uint8_t x = 0; x < qrcode.size; x++) {
if (qrcode_getModule(&qrcode, x, y)) {
u8g.setColorIndex(1);
}else{
u8g.setColorIndex(0);
}
u8g.drawPixel(x0+x,y0+y);
}
}
but it work slowly...T_T

Yup, I am experiencing the same. Printing point by point make it slow printing (it takes around 3-4 second to print the QR code of version 8, while version 3 will be printed within a sec).

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

6 participants