Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.
/ QRCode-esp32 Public archive
forked from mzyy94/QRCode-esp32

QR code generation library in C, optimized for low-power devices, such as Arduino.

License

Notifications You must be signed in to change notification settings

bobbycar-graz/QRCode-esp32

 
 

Repository files navigation

QRCode

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
  • MIT License; do with this as you please

Installing

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)

API

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");
}

What is Version, Error Correction and Mode?

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 ( ), dollar sign ($), percent sign (%), asterisk (*), plus (+), minus (-), decimal point (.), slash (/) and colon (:).
  • BYTE: any character

Data Capacities

Version Size Error Correction Mode
Numeric Alphanumeric Byte
1 21 x 21 LOW412517
MEDIUM342014
QUARTILE271611
HIGH17107
2 25 x 25 LOW774732
MEDIUM633826
QUARTILE482920
HIGH342014
3 29 x 29 LOW1277753
MEDIUM1016142
QUARTILE774732
HIGH583524
4 33 x 33 LOW18711478
MEDIUM1499062
QUARTILE1116746
HIGH825034
5 37 x 37 LOW255154106
MEDIUM20212284
QUARTILE1448760
HIGH1066444
6 41 x 41 LOW322195134
MEDIUM255154106
QUARTILE17810874
HIGH1398458
7 45 x 45 LOW370224154
MEDIUM293178122
QUARTILE20712586
HIGH1549364
8 49 x 49 LOW461279192
MEDIUM365221152
QUARTILE259157108
HIGH20212284
9 53 x 53 LOW552335230
MEDIUM432262180
QUARTILE312189130
HIGH23514398
10 57 x 57 LOW652395271
MEDIUM513311213
QUARTILE364221151
HIGH288174119
11 61 x 61 LOW772468321
MEDIUM604366251
QUARTILE427259177
HIGH331200137
12 65 x 65 LOW883535367
MEDIUM691419287
QUARTILE489296203
HIGH374227155
13 69 x 69 LOW1022619425
MEDIUM796483331
QUARTILE580352241
HIGH427259177
14 73 x 73 LOW1101667458
MEDIUM871528362
QUARTILE621376258
HIGH468283194
15 77 x 77 LOW1250758520
MEDIUM991600412
QUARTILE703426292
HIGH530321220
16 81 x 81 LOW1408854586
MEDIUM1082656450
QUARTILE775470322
HIGH602365250
17 85 x 85 LOW1548938644
MEDIUM1212734504
QUARTILE876531364
HIGH674408280
18 89 x 89 LOW17251046718
MEDIUM1346816560
QUARTILE948574394
HIGH746452310
19 93 x 93 LOW19031153792
MEDIUM1500909624
QUARTILE1063644442
HIGH813493338
20 97 x 97 LOW20611249858
MEDIUM1600970666
QUARTILE1159702482
HIGH919557382
21 101 x 101 LOW22321352929
MEDIUM17081035711
QUARTILE1224742509
HIGH969587403
22 105 x 105 LOW240914601003
MEDIUM18721134779
QUARTILE1358823565
HIGH1056640439
23 109 x 109 LOW262015881091
MEDIUM20591248857
QUARTILE1468890611
HIGH1108672461
24 113 x 113 LOW281217041171
MEDIUM21881326911
QUARTILE1588963661
HIGH1228744511
25 117 x 117 LOW305718531273
MEDIUM23951451997
QUARTILE17181041715
HIGH1286779535
26 121 x 121 LOW328319901367
MEDIUM254415421059
QUARTILE18041094751
HIGH1425864593
27 125 x 125 LOW351721321465
MEDIUM270116371125
QUARTILE19331172805
HIGH1501910625
28 129 x 129 LOW366922231528
MEDIUM285717321190
QUARTILE20851263868
HIGH1581958658
29 133 x 133 LOW390923691628
MEDIUM303518391264
QUARTILE21811322908
HIGH16771016698
30 137 x 137 LOW415825201732
MEDIUM328919941370
QUARTILE23581429982
HIGH17821080742
31 141 x 141 LOW441726771840
MEDIUM348621131452
QUARTILE247314991030
HIGH18971150790
32 145 x 145 LOW468628401952
MEDIUM369322381538
QUARTILE267016181112
HIGH20221226842
33 149 x 149 LOW496530092068
MEDIUM390923691628
QUARTILE280517001168
HIGH21571307898
34 153 x 153 LOW525331832188
MEDIUM413425061722
QUARTILE294917871228
HIGH23011394958
35 157 x 157 LOW552933512303
MEDIUM434326321809
QUARTILE308118671283
HIGH23611431983
36 161 x 161 LOW583635372431
MEDIUM458827801911
QUARTILE324419661351
HIGH252415301051
37 165 x 165 LOW615337292563
MEDIUM477528941989
QUARTILE341720711423
HIGH262515911093
38 169 x 169 LOW647939272699
MEDIUM503930542099
QUARTILE359921811499
HIGH273516581139
39 173 x 173 LOW674340872809
MEDIUM531332202213
QUARTILE379122981579
HIGH292717741219
40 177 x 177 LOW708942962953
MEDIUM559633912331
QUARTILE399324201663
HIGH305718521273

Special Thanks

A HUGE thank you to nayuki for the QR code C++ library which was critical in development of this library.

License

MIT License.

About

QR code generation library in C, optimized for low-power devices, such as Arduino.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 57.1%
  • C 37.1%
  • Python 4.9%
  • Other 0.9%