library to generate the bitmap array of qrcode on esp32.
- About The QR code
- Generating QR code
- Bitmap
- Example Usage
- Data Capacities
- Acknowledgements and Resources
A QR code is a machine-readable matrix barcode and it stands for “quick response” code.You can use the camera app on any phone to scan a QR code. It can store the data of about 4kb.
The version of a QR code is a number between 1 and 40 (inclusive), which indicates
the size of the QR code. The width and height of a QR code are always equal (it is
square) and are equal to 4 * version + 17
. To get more information on size refer Data Capacities
The level of error correction is a number between 0 and 3 (inclusive), or can be one of the symbolic names ECC_LOW, ECC_MEDIUM, ECC_QUARTILE and ECC_HIGH. Higher levels of error correction sacrifice data capacity, but allow a larger portion of the QR code to be damaged or unreadable. The level of Error correction supported are listed below
qrcodegen_Ecc_LOW = 0 , // The QR Code can tolerate about 7% erroneous codewords
qrcodegen_Ecc_MEDIUM , // The QR Code can tolerate about 15% erroneous codewords
qrcodegen_Ecc_QUARTILE, // The QR Code can tolerate about 25% erroneous codewords
qrcodegen_Ecc_HIGH , // The QR Code can tolerate about 30% erroneous codewords
The mode of a QR code is determined by the data being encoded. Each mode is encoded internally using a compact representation, so lower modes can contain more data.
- NUMERIC: numbers (
0-9
) - ALPHANUMERIC: uppercase letters (
A-Z
), numbers (0-9
), the space ($
), percent sign (%
), asterisk (*
), plus (+
), minus (-
), decimal point (.
), slash (/
) and colon (:
). - BYTE: any character The modes supported are as follows
qrcodegen_Mode_NUMERIC = 0x1,
qrcodegen_Mode_ALPHANUMERIC = 0x2,
qrcodegen_Mode_BYTE = 0x4,
The Qr code can be generated by using the following functions
bool qrcodegen_encodeText(const char *text, uint8_t tempBuffer[], uint8_t qrcode[],enum qrcodegen_Ecc ecl, int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl)
- Arguments
text
: text to be encoded in the qrcodetempBuffer
: temporary buffer to hold qrcode Dataqrcode
: buffer that will contain the qrcode Dataecl
: Error Correction levelminVersion
: minimum version of QR codd to generatemaxVersion
: maximum version of QR codd to generatemask
: masking of QR code, for automatic implementation put mask=-1boostEcl
: boost error correction level if true
The bitmap is the type of image formating like png, jpeg etc.. In embedded systems to display the QR code on the displays like Oled , led, we need to have the bitmap array of the qrcode. To get the bitmap array we used this function:-
void qrcode_to_bitmap(const uint8_t qrcode[],uint8_t *arr_bitmap,uint8_t version)
- Arguments
qrcode
:buffer that contains the qrcode Dataarr_bitmap
: The array that will contain the bitmap dataversion
: The version of the QR code
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "esp_log.h"
#include "qrcodegen.h"
#include "bitmap.h"
#define TAG "QRCODE"
int app_main()
{
// Text to be written as QRcode
const char *text = "http:192.168.1.1";
// setting the error correction level
enum qrcodegen_Ecc errCorLvl = qrcodegen_Ecc_LOW;
// setting the version of the qrcode
uint8_t version = 1;
// creating the qrcode buffer
uint8_t qrcode[qrcodegen_BUFFER_LEN_FOR_VERSION(version)];
uint8_t tempBuffer[qrcodegen_BUFFER_LEN_FOR_VERSION(version)];
// creating the QR code
bool ok = qrcodegen_encodeText(text, tempBuffer, qrcode, errCorLvl, version, version, qrcodegen_Mask_AUTO, true);
if (ok)
{
ESP_LOGI(TAG, "QRcode successfully created");
}
uint8_t size = qrcodegen_getSize(qrcode);
uint8_t arr_bitmap[(size * ((2 * size + 7) / 8))];
memset(arr_bitmap, 0, sizeof(arr_bitmap));
// converting the qrcode buffer to bitmap array
qrcode_to_bitmap(qrcode, (uint8_t *)&arr_bitmap, version);
// printing the bitmap array
printf("Bitmap Array:-\n");
for (int i = 0; i < sizeof(arr_bitmap); i++)
{
printf("%d ,", arr_bitmap[i]);
}
return 0;
}
Version | Size | Error Correction | Mode | ||
---|---|---|---|---|---|
Numeric | Alphanumeric | Byte | |||
1 | 21 x 21 | LOW | 41 | 25 | 17 |
MEDIUM | 34 | 20 | 14 | ||
QUARTILE | 27 | 16 | 11 | ||
HIGH | 17 | 10 | 7 | ||
2 | 25 x 25 | LOW | 77 | 47 | 32 |
MEDIUM | 63 | 38 | 26 | ||
QUARTILE | 48 | 29 | 20 | ||
HIGH | 34 | 20 | 14 | ||
3 | 29 x 29 | LOW | 127 | 77 | 53 |
MEDIUM | 101 | 61 | 42 | ||
QUARTILE | 77 | 47 | 32 | ||
HIGH | 58 | 35 | 24 | ||
4 | 33 x 33 | LOW | 187 | 114 | 78 |
MEDIUM | 149 | 90 | 62 | ||
QUARTILE | 111 | 67 | 46 | ||
HIGH | 82 | 50 | 34 | ||
5 | 37 x 37 | LOW | 255 | 154 | 106 |
MEDIUM | 202 | 122 | 84 | ||
QUARTILE | 144 | 87 | 60 | ||
HIGH | 106 | 64 | 44 | ||
6 | 41 x 41 | LOW | 322 | 195 | 134 |
MEDIUM | 255 | 154 | 106 | ||
QUARTILE | 178 | 108 | 74 | ||
HIGH | 139 | 84 | 58 | ||
7 | 45 x 45 | LOW | 370 | 224 | 154 |
MEDIUM | 293 | 178 | 122 | ||
QUARTILE | 207 | 125 | 86 | ||
HIGH | 154 | 93 | 64 | ||
8 | 49 x 49 | LOW | 461 | 279 | 192 |
MEDIUM | 365 | 221 | 152 | ||
QUARTILE | 259 | 157 | 108 | ||
HIGH | 202 | 122 | 84 | ||
9 | 53 x 53 | LOW | 552 | 335 | 230 |
MEDIUM | 432 | 262 | 180 | ||
QUARTILE | 312 | 189 | 130 | ||
HIGH | 235 | 143 | 98 | ||
10 | 57 x 57 | LOW | 652 | 395 | 271 |
MEDIUM | 513 | 311 | 213 | ||
QUARTILE | 364 | 221 | 151 | ||
HIGH | 288 | 174 | 119 | ||
11 | 61 x 61 | LOW | 772 | 468 | 321 |
MEDIUM | 604 | 366 | 251 | ||
QUARTILE | 427 | 259 | 177 | ||
HIGH | 331 | 200 | 137 | ||
12 | 65 x 65 | LOW | 883 | 535 | 367 |
MEDIUM | 691 | 419 | 287 | ||
QUARTILE | 489 | 296 | 203 | ||
HIGH | 374 | 227 | 155 | ||
13 | 69 x 69 | LOW | 1022 | 619 | 425 |
MEDIUM | 796 | 483 | 331 | ||
QUARTILE | 580 | 352 | 241 | ||
HIGH | 427 | 259 | 177 | ||
14 | 73 x 73 | LOW | 1101 | 667 | 458 |
MEDIUM | 871 | 528 | 362 | ||
QUARTILE | 621 | 376 | 258 | ||
HIGH | 468 | 283 | 194 | ||
15 | 77 x 77 | LOW | 1250 | 758 | 520 |
MEDIUM | 991 | 600 | 412 | ||
QUARTILE | 703 | 426 | 292 | ||
HIGH | 530 | 321 | 220 | ||
16 | 81 x 81 | LOW | 1408 | 854 | 586 |
MEDIUM | 1082 | 656 | 450 | ||
QUARTILE | 775 | 470 | 322 | ||
HIGH | 602 | 365 | 250 | ||
17 | 85 x 85 | LOW | 1548 | 938 | 644 |
MEDIUM | 1212 | 734 | 504 | ||
QUARTILE | 876 | 531 | 364 | ||
HIGH | 674 | 408 | 280 | ||
18 | 89 x 89 | LOW | 1725 | 1046 | 718 |
MEDIUM | 1346 | 816 | 560 | ||
QUARTILE | 948 | 574 | 394 | ||
HIGH | 746 | 452 | 310 | ||
19 | 93 x 93 | LOW | 1903 | 1153 | 792 |
MEDIUM | 1500 | 909 | 624 | ||
QUARTILE | 1063 | 644 | 442 | ||
HIGH | 813 | 493 | 338 | ||
20 | 97 x 97 | LOW | 2061 | 1249 | 858 |
MEDIUM | 1600 | 970 | 666 | ||
QUARTILE | 1159 | 702 | 482 | ||
HIGH | 919 | 557 | 382 | ||
21 | 101 x 101 | LOW | 2232 | 1352 | 929 |
MEDIUM | 1708 | 1035 | 711 | ||
QUARTILE | 1224 | 742 | 509 | ||
HIGH | 969 | 587 | 403 | ||
22 | 105 x 105 | LOW | 2409 | 1460 | 1003 |
MEDIUM | 1872 | 1134 | 779 | ||
QUARTILE | 1358 | 823 | 565 | ||
HIGH | 1056 | 640 | 439 | ||
23 | 109 x 109 | LOW | 2620 | 1588 | 1091 |
MEDIUM | 2059 | 1248 | 857 | ||
QUARTILE | 1468 | 890 | 611 | ||
HIGH | 1108 | 672 | 461 | ||
24 | 113 x 113 | LOW | 2812 | 1704 | 1171 |
MEDIUM | 2188 | 1326 | 911 | ||
QUARTILE | 1588 | 963 | 661 | ||
HIGH | 1228 | 744 | 511 | ||
25 | 117 x 117 | LOW | 3057 | 1853 | 1273 |
MEDIUM | 2395 | 1451 | 997 | ||
QUARTILE | 1718 | 1041 | 715 | ||
HIGH | 1286 | 779 | 535 | ||
26 | 121 x 121 | LOW | 3283 | 1990 | 1367 |
MEDIUM | 2544 | 1542 | 1059 | ||
QUARTILE | 1804 | 1094 | 751 | ||
HIGH | 1425 | 864 | 593 | ||
27 | 125 x 125 | LOW | 3517 | 2132 | 1465 |
MEDIUM | 2701 | 1637 | 1125 | ||
QUARTILE | 1933 | 1172 | 805 | ||
HIGH | 1501 | 910 | 625 | ||
28 | 129 x 129 | LOW | 3669 | 2223 | 1528 |
MEDIUM | 2857 | 1732 | 1190 | ||
QUARTILE | 2085 | 1263 | 868 | ||
HIGH | 1581 | 958 | 658 | ||
29 | 133 x 133 | LOW | 3909 | 2369 | 1628 |
MEDIUM | 3035 | 1839 | 1264 | ||
QUARTILE | 2181 | 1322 | 908 | ||
HIGH | 1677 | 1016 | 698 | ||
30 | 137 x 137 | LOW | 4158 | 2520 | 1732 |
MEDIUM | 3289 | 1994 | 1370 | ||
QUARTILE | 2358 | 1429 | 982 | ||
HIGH | 1782 | 1080 | 742 | ||
31 | 141 x 141 | LOW | 4417 | 2677 | 1840 |
MEDIUM | 3486 | 2113 | 1452 | ||
QUARTILE | 2473 | 1499 | 1030 | ||
HIGH | 1897 | 1150 | 790 | ||
32 | 145 x 145 | LOW | 4686 | 2840 | 1952 |
MEDIUM | 3693 | 2238 | 1538 | ||
QUARTILE | 2670 | 1618 | 1112 | ||
HIGH | 2022 | 1226 | 842 | ||
33 | 149 x 149 | LOW | 4965 | 3009 | 2068 |
MEDIUM | 3909 | 2369 | 1628 | ||
QUARTILE | 2805 | 1700 | 1168 | ||
HIGH | 2157 | 1307 | 898 | ||
34 | 153 x 153 | LOW | 5253 | 3183 | 2188 |
MEDIUM | 4134 | 2506 | 1722 | ||
QUARTILE | 2949 | 1787 | 1228 | ||
HIGH | 2301 | 1394 | 958 | ||
35 | 157 x 157 | LOW | 5529 | 3351 | 2303 |
MEDIUM | 4343 | 2632 | 1809 | ||
QUARTILE | 3081 | 1867 | 1283 | ||
HIGH | 2361 | 1431 | 983 | ||
36 | 161 x 161 | LOW | 5836 | 3537 | 2431 |
MEDIUM | 4588 | 2780 | 1911 | ||
QUARTILE | 3244 | 1966 | 1351 | ||
HIGH | 2524 | 1530 | 1051 | ||
37 | 165 x 165 | LOW | 6153 | 3729 | 2563 |
MEDIUM | 4775 | 2894 | 1989 | ||
QUARTILE | 3417 | 2071 | 1423 | ||
HIGH | 2625 | 1591 | 1093 | ||
38 | 169 x 169 | LOW | 6479 | 3927 | 2699 |
MEDIUM | 5039 | 3054 | 2099 | ||
QUARTILE | 3599 | 2181 | 1499 | ||
HIGH | 2735 | 1658 | 1139 | ||
39 | 173 x 173 | LOW | 6743 | 4087 | 2809 |
MEDIUM | 5313 | 3220 | 2213 | ||
QUARTILE | 3791 | 2298 | 1579 | ||
HIGH | 2927 | 1774 | 1219 | ||
40 | 177 x 177 | LOW | 7089 | 4296 | 2953 |
MEDIUM | 5596 | 3391 | 2331 | ||
QUARTILE | 3993 | 2420 | 1663 | ||
HIGH | 3057 | 1852 | 1273 |
- nayuki for qrcode library