Black diamond question marks in serial monitor

Hi all!

I'm using the arduino ide 1.8.1 with an arduino uno. Through the ide's sketch>include library>manage libraries.. option, I installed the ricmoo/QRCode library: GitHub - ricmoo/QRCode: QR code generation library in C, optimized for low-power devices, such as Arduino.

With the library install, an example QRCode example sketch is installed. Here's the code:

/**
 *  QRCode
 *
 *  A quick example of generating a QR code.
 *
 *  This prints the QR code to the serial monitor as solid blocks. Each module
 *  is two characters wide, since the monospace font used in the serial monitor
 *  is approximately twice as tall as wide.
 *
 */

#include "qrcode.h"

void setup() {
    Serial.begin(115200);

    // Start time
    uint32_t dt = millis();
  
    // Create the QR code
    QRCode qrcode;
    uint8_t qrcodeData[qrcode_getBufferSize(3)];
    qrcode_initText(&qrcode, qrcodeData, 3, 0, "HELLO WORLD");
  
    // Delta time
    dt = millis() - dt;
    Serial.print("QR Code Generation Time: ");
    Serial.print(dt);
    Serial.print("\n");

    // Top quiet zone
    Serial.print("\n\n\n\n");

    for (uint8_t y = 0; y < qrcode.size; y++) {

        // Left quiet zone
        Serial.print("        ");

        // Each horizontal module
        for (uint8_t x = 0; x < qrcode.size; x++) {

            // Print each module (UTF-8 \u2588 is a solid block)
            Serial.print(qrcode_getModule(&qrcode, x, y) ? "\u2588\u2588": "  ");

        }

        Serial.print("\n");
    }

    // Bottom quiet zone
    Serial.print("\n\n\n\n");
}

void loop() {

}

And here's the output from the serial monitor:

        █████████���████    ██    ████    █���██    ██  █████████���████
        ██          ██      ██████  ██████  █��████  ██          ██
        ██  ██████  ██  ██████  ██████  ██████  ██  ██  ██████  ██
        ██  ██████  ██    ███���██  ██████  ██████    ██  ██████  ██
        ��█  ██████  ██      ██      ██      ██      ██  ████��█  ██
        ██          ██    ���█      ██      ██        ██          ██
        █████████���████  ██  ██  ██  ██  ██  ██  ██  ██████████████
                        ██████  ██████  ████��█  ██                
        ███��██  ██████████  ██���█    ████    ████  ████      ██    
            █████���██    ██  ████    ████    ████      ██          
          ██  ██  ██████  ██      ██      ██      ██  █████���    ██
        ██  ██          ██    ██      ██      ██  ██████  ██      
                ██  ██  ██      ██      ██      █��██    ██    ██  
        ███���████      ██      █████���  ██████  ██████    ��█  ████  
        ████      ���█████      ████  ███��██  ██████  ██    ████    
        ██    ██████    ���█████  ██████  ██████  ██      ██  ██  ██
        ██    ██████████��█  ████    ████    ███���    ██████  ██████
            ████              ██    ████    ████      ██        █���
        ██    ██  ████            ██      ██      ██  ███��  ██    
          ██  █████���      ██████      ██      █���  ██████    ████  
        ██  ██  ██  ████  ████  ██      ██      ██████��███████  ██
                        ██    ██████  ███��██  ████      ██      ██
        ██████████████  ██  ██████  ██████  ██  ██  ██  ██  ██    
        ██          ██  ██  ██  █���████  ██████  ██      ████      
        ██  ████���█  ██  ████████    █��██    ████████████���███  ████
        ██  ██████  ██    ██████    ��███    ██████  ████      ██  
        ██  ██████  ██  ██        ██      ██  ██    ████    ██  ██
        █��          ██  ████  ██      ██          ██  ██████  ██���█
        ███████████���██  ██      ██      ██      ████████    ██  ██

The QR code appears to be ok, other than the added question marks,...

I understand strange data from the serial monitor is often the result of a baud rate mismatch. My serial monitor is set to 115200 as required.

Additionally, if I replace this line in the sketch:
Serial.print(qrcode_getModule(&qrcode, x, y) ? "\u2588\u2588": "  ");

with this line:

Serial.print(qrcode_getModule(&qrcode, x, y) ? "**": "  ");

I get a proper looking QR code in the serial monitor, just made up of astericks instead of blocks:

QR Code Generation Time: 914




        **************    **    ****    ****    **  **************
        **          **      ******  ******  ******  **          **
        **  ******  **  ******  ******  ******  **  **  ******  **
        **  ******  **    ******  ******  ******    **  ******  **
        **  ******  **      **      **      **      **  ******  **
        **          **    **      **      **        **          **
        **************  **  **  **  **  **  **  **  **************
                        ******  ******  ******  **                
        ******  **********  ****    ****    ****  ****      **    
            ********    **  ****    ****    ****      **          
          **  **  ******  **      **      **      **  ******    **
        **  **          **    **      **      **  ******  **      
                **  **  **      **      **      ****    **    **  
        ********      **      ******  ******  ******    **  ****  
        ****      ******      ****  ******  ******  **    ****    
        **    ******    ******  ******  ******  **      **  **  **
        **    ************  ****    ****    ****    ******  ******
            ****              **    ****    ****      **        **
        **    **  ****            **      **      **  ****  **    
          **  ******      ******      **      **  ******    ****  
        **  **  **  ****  ****  **      **      **************  **
                        **    ******  ******  ****      **      **
        **************  **  ******  ******  **  **  **  **  **    
        **          **  **  **  ******  ******  **      ****      
        **  ******  **  ********    ****    ****************  ****
        **  ******  **    ******    ****    ******  ****      **  
        **  ******  **  **        **      **  **    ****    **  **
        **          **  ****  **      **          **  ******  ****
        **************  **      **      **      ********    **  **

So why am I seeing the question marks?

Thanks for any help,
Randy

Works fine for me on Arduino IDE 1.8.5, Uno, QRCode library 0.0.1:

        ██████████████    ██    ████    ████    ██  ██████████████
        ██          ██      ██████  ██████  ██████  ██          ██
        ██  ██████  ██  ██████  ██████  ██████  ██  ██  ██████  ██
        ██  ██████  ██    ██████  ██████  ██████    ██  ██████  ██
        ██  ██████  ██      ██      ██      ██      ██  ██████  ██
        ██          ██    ██      ██      ██        ██          ██
        ██████████████  ██  ██  ██  ██  ██  ██  ██  ██████████████
                        ██████  ██████  ██████  ██                
        ██████  ██████████  ████    ████    ████  ████      ██    
            ████████    ██  ████    ████    ████      ██          
          ██  ██  ██████  ██      ██      ██      ██  ██████    ██
        ██  ██          ██    ██      ██      ██  ██████  ██      
                ██  ██  ██      ██      ██      ████    ██    ██  
        ████████      ██      ██████  ██████  ██████    ██  ████  
        ████      ██████      ████  ██████  ██████  ██    ████    
        ██    ██████    ██████  ██████  ██████  ██      ██  ██  ██
        ██    ████████████  ████    ████    ████    ██████  ██████
            ████              ██    ████    ████      ██        ██
        ██    ██  ████            ██      ██      ██  ████  ██    
          ██  ██████      ██████      ██      ██  ██████    ████  
        ██  ██  ██  ████  ████  ██      ██      ██████████████  ██
                        ██    ██████  ██████  ████      ██      ██
        ██████████████  ██  ██████  ██████  ██  ██  ██  ██  ██    
        ██          ██  ██  ██  ██████  ██████  ██      ████      
        ██  ██████  ██  ████████    ████    ████████████████  ████
        ██  ██████  ██    ██████    ████    ██████  ████      ██  
        ██  ██████  ██  ██        ██      ██  ██    ████    ██  ██
        ██          ██  ████  ██      ██          ██  ██████  ████
        ██████████████  ██      ██      ██      ████████    ██  ██

Try changing line 15 of your sketch from:

Serial.begin(115200);

to:

Serial.begin(9600);

Upload the sketch, open Serial Monitor, then set the baud rate menu in Serial monitor to 9600. It could be that some of the serial data is being corrupted at the higher speed, though 115200 should usually be well supported.

1 Like

Hey pert, thanks for the response!

Actually, changing the baud rate to 9600 made the problem worse. The amount of black diamond question marks tripled at 9600!

However, upgrading to IDE 1.8.5 fixed the problem. I'm now getting a QR code without any extra characters in the serial monitor at both 9600 and 115200 baud rates.

Thanks for posting your results/software versions, that pushed me in the right direction!

Randy