QRCodeX is a fork of QRCode and has only been slightly adapted. The files /scr/qrcodex.c
and /scr/qrcodex.h
were edited / renamed.
This bypasses the error message error: 'QRCode' was not declared in this scope.
A simple library for generating QR codes in C, optimized for processing and memory constrained systems.
Features:
- Stack-based (no heap necessary; but you can use heap if you want)
- Low-memory foot print (relatively)
- Compile-time stripping of unecessary logic and constants
- MIT License; do with this as you please
To install this library, download and save it to your Arduino libraries directory.
Rename the directory to QRCode (if downloaded from GitHub, the filename may be qrcode-master; library names may not contain the hyphen, so it must be renamed)
Generate a QR Code
// The structure to manage the QR code
QRCode qrcode;
// Allocate a chunk of memory to store the QR code
uint8_t qrcodeBytes[qrcode_getBufferSize()];
qrcode_initText(&qrcode, qrcodeBytes, 3, ECC_LOW, "HELLO WORLD");
Draw a QR Code
How a QR code is used will vary greatly from project to project. For example:
- Display on an OLED screen (128x64 nicely supports 2 side-by-side version 3 QR codes)
- Print as a bitmap on a thermal printer
- Store as a BMP (or with a some extra work, possibly a PNG) on an SD card
The following example prints a QR code to the Serial Monitor (it likely will not be scannable, but is just for demonstration purposes).
for (uint8 y = 0; y < qrcode.size; y++) {
for (uint8 x = 0; x < qrcode.size; x++) {
if (qrcode_getModule(&qrcode, x, y) {
Serial.print("**");
} else {
Serial.print(" ");
}
}
Serial.print("\n");
}
A QR code is composed of many little squares, called modules, which represent encoded data, with additional error correction (allowing partially damaged QR codes to still be read).
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
.
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 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
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 |
A HUGE thank you to Project Nayuki for the QR code C++ library which was critical in development of this library.
MIT License.