QR code

QR code generation with LVGL. Uses QR-Code-generator by nayuki.

Get started

  • Download or clone this repository

    • Download from GitHub

    • Clone: git clone https://github.com/lvgl/lv_lib_qrcode.git

  • Include the library: #include "lv_lib_qrcode/lv_qrcode.h"

  • Test with the following code:

const char * data = "Hello world";

/*Create a 100x100 QR code*/
lv_obj_t * qr = lv_qrcode_create(lv_scr_act(), 100, lv_color_hex3(0x33f), lv_color_hex3(0xeef));

/*Set data*/
lv_qrcode_update(qr, data, strlen(data));

Notes

  • QR codes with less data are smaller, but they scaled by an integer number to best fit to the given size.

Example

Create a QR Code

C code  

 GitHub
#include "../../lv_examples.h"
#if LV_USE_QRCODE && LV_BUILD_EXAMPLES

/**
 * Create a QR Code
 */
void lv_example_qrcode_1(void)
{
    lv_color_t bg_color = lv_palette_lighten(LV_PALETTE_LIGHT_BLUE, 5);
    lv_color_t fg_color = lv_palette_darken(LV_PALETTE_BLUE, 4);

    lv_obj_t * qr = lv_qrcode_create(lv_scr_act(), 150, fg_color, bg_color);

    /*Set data*/
    const char * data = "https://lvgl.io";
    lv_qrcode_update(qr, data, strlen(data));
    lv_obj_center(qr);

    /*Add a border with bg_color*/
    lv_obj_set_style_border_color(qr, bg_color, 0);
    lv_obj_set_style_border_width(qr, 5, 0);
}

#endif








MicroPython code  

 GitHub Simulator
#!/opt/bin/lv_micropython -i
import lvgl as lv
import display_driver

bg_color = lv.palette_lighten(lv.PALETTE.LIGHT_BLUE, 5)
fg_color = lv.palette_darken(lv.PALETTE.BLUE, 4)

qr = lv.qrcode(lv.scr_act(), 150, fg_color, bg_color)
# Set data
data = "https://lvgl.io"
qr.update(data,len(data))
qr.center()
# Add a border with bg_color
qr.set_style_border_color(bg_color, 0)
qr.set_style_border_width(5, 0)

API

Functions

lv_obj_t *lv_qrcode_create(lv_obj_t *parent, lv_coord_t size, lv_color_t dark_color, lv_color_t light_color)

Create an empty QR code (an lv_canvas) object.

参数
  • parent -- point to an object where to create the QR code

  • size -- width and height of the QR code

  • dark_color -- dark color of the QR code

  • light_color -- light color of the QR code

返回

pointer to the created QR code object

lv_res_t lv_qrcode_update(lv_obj_t *qrcode, const void *data, uint32_t data_len)

Set the data of a QR code object

参数
  • qrcode -- pointer to aQ code object

  • data -- data to display

  • data_len -- length of data in bytes

返回

LV_RES_OK: if no error; LV_RES_INV: on error

void lv_qrcode_delete(lv_obj_t *qrcode)

DEPRECATED: Use normal lv_obj_del instead Delete a QR code object

参数

qrcode -- pointer to a QR code object

Variables

const lv_obj_class_t lv_qrcode_class