Shellminator V3.0.1
Simple Terminal
Loading...
Searching...
No Matches
Example 101 QR Code

Table of Contents

Fortunately, today, every smartphone is capable of scanning QR codes. This can be really useful when you’re out in the field and need to display an error code via a QR code, or even generate a unique link to a configuration portal for wireless devices. Luckily, we've implemented this feature for you—just provide a C string, and the QR code will be generated automatically.

Live Demo

The library is built on the Nayuki QR code generation codebase, which is a widely used solution in the industry. We specifically use the C implementation, as it is the most memory-efficient.

And speaking of memory efficiency, unfortunately, this feature does require a relatively large amount of memory. The recommendation is to use it on platforms with at least 16kBytes of dynamic memory. Because of this, the Arduino Uno R3, unfortunately, isn't suitable. But the good news is that platforms like the ESP32, Raspberry Pi Pico, and Arduino Uno R4 can easily handle this limitation.

First, you’ll need to include the library:

Then, create an object that handles memory management:

Finally, all you need to do is specify which channel the output should go to and what text it should contain:

qrCode.generate( &Serial, "https://www.shellminator.org/html/index.html" );
void generate(Stream *channel_p, const char *text, enum qrcodegen_Ecc ecc=qrcodegen_Ecc_MEDIUM)
Generates a QR-Code.

Whole Code

/*
* Created on Aug 10 2020
*
* Copyright (c) 2023 - Daniel Hajnal
* hajnal.daniel96@gmail.com
* This file is part of the Shellminator project.
* Modified 2023.05.13
*/
#include "Shellminator.hpp"
// Create a Shellminator object, and initialize it to use Serial
Shellminator shell( &Serial );
// System init section.
void setup(){
Serial.begin(115200);
// Clear the terminal
shell.clear();
Serial.println( "Shellminator webpage:" );
Serial.println();
// Generate a link to the Github repo.
qrCode.generate( &Serial, "https://www.shellminator.org/html/index.html" );
// Initialize shell object.
shell.begin( "arnold" );
}
// Infinite loop.
void loop(){
// Process the new data.
shell.update();
}
Shellminator object.

You can optionally specify the level of error correction to be included in the QR code.

ECC Setting Definition Tolerance
qrcodegen_Ecc_LOW 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

By default, the medium setting is used, which allows for about 15% error tolerance. However, if you'd like to increase that to 30%, all you need to do is look up the setting name for 30% in the table, which is qrcodegen_Ecc_HIGH, and then modify the previous code like this:

// Generate a link to the Github repo with 30% ECC
qrCode.generate( &Serial, "https://www.shellminator.org/html/index.html", qrcodegen_Ecc_HIGH );