Code Monkey home page Code Monkey logo

qrcode's Introduction

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 and constants
  • 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 Project Nayuki for the QR code C++ library which was critical in development of this library.

License

MIT License.

qrcode's People

Contributors

per1234 avatar ricmoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

qrcode's Issues

How to Store as a BMP?

I have some code!try save to a BMP!
but can't scan!
can you help me?




typedef struct tagBITMAPINFOHEADER {
	unsigned int  biSize;
	int   biWidth;
	int   biHeight;
	unsigned short   biPlanes;
	unsigned short   biBitCount;
	unsigned int  biCompression;
	unsigned int  biSizeImage;
	int   biXPelsPerMeter;
	int   biYPelsPerMeter;
	unsigned int  biClrUsed;
	unsigned int  biClrImportant;
} BITMAPINFOHEADER, *PBITMAPINFOHEADER;

typedef struct tagBITMAPFILEHEADER {
	unsigned short    bfType;
	unsigned int   bfSize;
	unsigned short    bfReserved1;
	unsigned short    bfReserved2;
	unsigned int   bfOffBits;
} BITMAPFILEHEADER, *PBITMAPFILEHEADER;

typedef struct tagRGBQUAD {
	unsigned char rgbBlue;
	unsigned char rgbGreen;
	unsigned char rgbRed;
	unsigned char rgbReserved;
}RGBQUAD;

typedef struct tagBITMAPINFO {
	BITMAPINFOHEADER    bmiHeader;
	RGBQUAD             bmiColors[1];
} BITMAPINFO, *PBITMAPINFO;
PBITMAPINFO BuildBitmapInfo(int biBitCount, int width, int height)
{
	PBITMAPINFO pInfo = 0;
	if (biBitCount == 1)
	{
		pInfo =	(PBITMAPINFO)malloc(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 2);
		int i = 0;
		for ( ; i < 2 ; i ++)
		{
			pInfo->bmiColors[i].rgbBlue = (unsigned char)(i*255);
			pInfo->bmiColors[i].rgbRed  = (unsigned char)(i*255);
			pInfo->bmiColors[i].rgbGreen = (unsigned char)(i*255);
			pInfo->bmiColors[i].rgbReserved = 0;
		}
	}
	else
		if (biBitCount == 8)
		{
			pInfo = (PBITMAPINFO)malloc(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256);
			int i = 0;
			for (; i < 256 ; i ++)
			{
				pInfo->bmiColors[i].rgbBlue = (unsigned char)i;
				pInfo->bmiColors[i].rgbRed =  (unsigned char)i;
				pInfo->bmiColors[i].rgbGreen = (unsigned char)i;
				pInfo->bmiColors[i].rgbReserved = 0;
			}
		}
		else if (biBitCount == 24)
		{
			pInfo = (PBITMAPINFO)malloc(sizeof(BITMAPINFOHEADER));
		}
		else
			return NULL;

		pInfo->bmiHeader.biSizeImage = (width*biBitCount+31)/32*4*height;
		pInfo->bmiHeader.biBitCount = biBitCount;
		pInfo->bmiHeader.biClrImportant = 0;
		pInfo->bmiHeader.biClrUsed = 0;
		pInfo->bmiHeader.biCompression = 0;
		pInfo->bmiHeader.biHeight = height;
		pInfo->bmiHeader.biWidth = width;
		pInfo->bmiHeader.biPlanes = 1;
		pInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
		pInfo->bmiHeader.biXPelsPerMeter = 0;
		pInfo->bmiHeader.biYPelsPerMeter = 0;

		return pInfo;
}

PBITMAPFILEHEADER  BuildBitmapFileHeader(unsigned int bfSize,unsigned int bfOffBits)
{
	PBITMAPFILEHEADER pHeader = (PBITMAPFILEHEADER)malloc(sizeof(BITMAPFILEHEADER));
	pHeader->bfOffBits = bfOffBits;
	pHeader->bfReserved1 = 0;
	pHeader->bfReserved2 = 0;
	pHeader->bfSize = bfSize;
	pHeader->bfType = 'M'*0X100+'B';
	return pHeader;
}

int SaveDIB(PBITMAPINFO pInfo,unsigned char * pData,char * FileName)
{
	FILE *file = fopen(FileName,"wb");
	if(file == 0)
		return 0;

	PBITMAPFILEHEADER	pFileHeader;

	unsigned int	FileLen =0,bfOffBits =0;
	if( pInfo->bmiHeader.biBitCount==1 )
	{
		FileLen=(pInfo->bmiHeader.biWidth+31)/32*4 * pInfo->bmiHeader.biHeight;
		bfOffBits=0x3E;
	}
	else if( pInfo->bmiHeader.biBitCount==8 )
	{
		FileLen=(pInfo->bmiHeader.biWidth+3) /4 *4 * pInfo->bmiHeader.biHeight;
		bfOffBits=0x436;
	}
	else if( pInfo->bmiHeader.biBitCount==24 )
	{
		FileLen=(pInfo->bmiHeader.biWidth*3+3)/4*4 * pInfo->bmiHeader.biHeight;
		bfOffBits=sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);//0x36;
	}
	printf("FileLen = %d  bfOffBits = %d",FileLen,bfOffBits);
	pFileHeader=BuildBitmapFileHeader(FileLen,bfOffBits);

	fwrite(&(pFileHeader->bfType),1,2,file);
	fwrite(&(pFileHeader->bfSize),1,4,file);
	fwrite(&(pFileHeader->bfReserved1),1,2,file);
	fwrite(&(pFileHeader->bfReserved2),1,2,file);
	fwrite(&(pFileHeader->bfOffBits ),1,4,file);
	//fwrite(pFileHeader,1,14,file);


	if( pInfo->bmiHeader.biBitCount==1 )
	{
		fwrite(pInfo,1,0x30,file);

	}

	if( pInfo->bmiHeader.biBitCount==8 )
	{
		fwrite(pInfo,1,0x428,file);

	}
	if( pInfo->bmiHeader.biBitCount==24 )
	{
		fwrite(pInfo,1,sizeof(BITMAPINFOHEADER),file);

	}
	fwrite(pData,1,pInfo->bmiHeader.biSizeImage,file);//dW*h

	fclose(file);

	if( pFileHeader )
		free(pFileHeader);

	pFileHeader = 0;
	return 1;
}

no border

no white border for rows, and lot's scanner can not find the generated qrcode.

Hard Fault for versions bigger than 4

Hi
I face hard fault error for versions bigger than 4.
I debugged the code step by step and I see that Micro goes to hard fault in this lines

uint8_t result[data->capacityBytes];
memset(result, 0, sizeof(result));

I checked result address and it is 0x00000002 which is not a valid RAM address

Unable to print version 8 or higher on a display!

I'm using a NodeMCU (ESP12-E) with an I2C display 128x128px.
I'm able to print QR codes with versions up to 7 without any issue, but when I choose version 8 or higher nothing happens, the display stays black and ESP8266 blinks the LED constantly (even though I haven't declared it as output or done anything with it!)

Interleave the data in-place.

Just an idea for optimizing codeword memory allocation, but run the interleave in-place, so we don't need to allocate a new block of memory.

Not working with bigger string

Hello

I am using ESP8266 and E paper display
Problem is when I want to generate qr code from bigger string, here is my function that generate qr code:

void qrCard(const char *code)
{
  display.fillRect(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, GxEPD_WHITE);
  display.update();

  byte box_x = 33;
  byte box_y = 33;
  byte box_s = 4.5;
  byte init_x = box_x;

  display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, false);

  // Create the QR code
  QRCode qrcode;
  uint8_t qrcodeData[qrcode_getBufferSize(4)];
  qrcode_initText(&qrcode, qrcodeData, 4, 0, code);

  for (uint8_t y = 0; y < qrcode.size; y++)
  {
    // 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": "  ");
      if (qrcode_getModule(&qrcode, x, y))
      {
        //Serial.println(py+ps);
        display.fillRect(box_x, box_y, box_s, box_s, GxEPD_BLACK);
      }
      else
      {
        //Serial.println(py+ps);
        display.fillRect(box_x, box_y, box_s, box_s, GxEPD_WHITE);
      }
      box_x = box_x + box_s;
    }
    display.updateWindow(0, box_y, 200, box_s, true);
    box_y = box_y + box_s;
    box_x = init_x;
  }
}

This is string which I try to use to generate qr code:

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb2RlIjoiYjdlODg2NzAtNjJiNi0xMWU5LThlODEtYzk4YzQxODQwMzg4IiwiaWF0IjoxNTYzODAwMDQ0fQ.06H2CZHUoDdezXBFPk4kocK8Qqjgy3zmAR-OgMk4AH0

In console I get this error:

HTTPS Connecting
ets Jan 8 2013,rst cause:4, boot mode:(3,6)

wdt reset
load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v8b899c12
~ld
D�Done

Found out that this function creating error:
qrcode_initText

When I use smaller string it works. Any solution for this? Also is it possible to update qr code at once not part by part?

#EDIT: Did little debuging, first time error occure here:

bb_initGrid(&modulesGrid, modules, size); in this function qrcode_initBytes

Order of entries NUM_ERROR_CORRECTION_BLOCKS

Hi

Is the order of the elements in NUM_ERROR_CORRECTION_BLOCKS correct?
Currently it is written in the comment that it is Medium, Low, High, Quartile.

However they are accessed using the ecc value as index. In the header, the ECC values are defined as

#define ECC_LOW 0
#define ECC_MEDIUM 1
#define ECC_QUARTILE 2
#define ECC_HIGH 3

The same seem to be the case for NUM_ERROR_CORRECTION_CODEWORDS?

Precomputing the QR codes

Hi!

First of all thanks for this amazing library. It helped a lot to display QR codes on an OLED using Arduino.

I have a question that might be too simple. I want to precompute the QR codes in order to save time.
Is it possible to precompute and store them inside an array-like structure and draw them immediately.

The code works fine when I compute the QR code, i.e. call the qrcode_initText, and draw the image inside the same function call. But I failed to draw the QR codes properly with precomputing.
For precomputing, I tried computing them inside the setup() function and then print them after a button press inside the loop().

Below are the code snippets.

setup():

...
QRCode qrcode;



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

  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    for (;;); // Don't proceed, loop forever
  }
  display.display();
  delay(2000);
  display.clearDisplay();
  display.setTextSize(3);             // Normal 1:1 pixel scale
  display.setTextColor(WHITE);        // Draw white text
  display.display();
  
  uint8_t qrcodeBytes[qrcode_getBufferSize(QR_VERSION)];
  qrcode_initText(&qrcode, qrcodeBytes, QR_VERSION, 0, "hello");

}

loop():

void loop() {

  if (Serial.available() > 0) {

    const uint8_t y0 = 10;
    const uint8_t x0 = 10;
    char data = Serial.read();
    if (data == 'Q') {
      display.clearDisplay();
      for (uint8_t y = 0; y < qrcode.size; y++)
      {
        for (uint8_t x = 0; x < qrcode.size; x++)
        {
          uint8_t pixel = 0;
          if (qrcode_getModule(&qrcode, x, y) )
          {
            /*Put black pixel*/
            pixel = 1;
          }
          else
          {
            /*White pixel*/
            pixel = 0;
          }

          display.drawPixel(x0 + 2 * x, y0 + y, pixel);
          display.drawPixel(x0 + 2 * x + 1, y0 + y, pixel);
        }
      }
      for (uint8_t y = 0; y < qrcode.size; y++) {
        for (uint8_t x = 0; x < qrcode.size; x++) {
          if (qrcode_getModule(&qrcode, x, y)) {
            Serial.print("**");
          } else {
            Serial.print("  ");
          }
        }
        Serial.print("\n");
      }

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

  display.display();
  delay(1000);
}

However, I get a broken QR (image below) when I do this. I suspect the values inside the qrCodeBytes get changed between setup and loop.

IMG_0035

error: 'QRCode' was not declared in this scope

wondering what I am doing wrong, I am attempting to compile the example in my Arduino UI

https://github.com/ricmoo/QRCode/blob/master/examples/QRCode/QRCode.ino

I have installed the library using the Library Manager...

image

also check that it is installed...

libraries$ ls -al
total 28
drwxrwxr-x 7 clay clay 4096 Nov 20 22:32 .
drwxrwxr-x 4 clay clay 4096 Nov 20 22:26 ..
drwxrwxr-x 4 clay clay 4096 Nov 20 19:10 Base64
drwxrwxr-x 4 clay clay 4096 Nov 20 19:10 Keypad
drwxrwxr-x 5 clay clay 4096 Nov 20 22:32 QRCode
drwxrwxr-x 9 clay clay 4096 Nov 20 19:10 TFT_eSPI

and when I try to compile the example,

image

/home/clay/data/github.com/ricmoo/QRCode/examples/QRCode/QRCode.ino: In function 'void setup()':
QRCode:21:5: error: 'QRCode' was not declared in this scope
     QRCode qrcode;
     ^~~~~~
QRCode:22:24: error: 'qrcode_getBufferSize' was not declared in this scope

shouldn't it be able to find QRCode? If it is inappropriate to post this here and its not a bug happy to close and move the conversation.

ChatGPT proposed code, refering to function in this library, which does not exist

Hi, Code ChatGPT suggested:

String generateQRCode(const String& data) {
QRCode qrcode;
uint8_t qrcodeData[qrcode_getBufferSize(3)];
qrcode_initText(&qrcode, qrcodeData, 3, 0, data.c_str());

String qrCodeHtml = "<img src="data:image/png;base64,";
qrCodeHtml += qrcode_getQRCode(&qrcode);
qrCodeHtml += "">";

return qrCodeHtml;
}

But..."qrcode_getQRCode" is not declared in qrcode.h!:
How comes that ChatGPT thinks this is part of Richard Moore's library??

QR to Bitmap

I'm trying to create a BMP of the QR code to display on a 128x64 OLED screen like you mentioned in the readme.
Is there an example for this?

I have tried using your for loop to generate the bits, but that did not work.

Missing Alignment and finder patterns

I am using the library to plot the QR code on an monochrome 8 bit lcd display. I am able to plot the QR directly from the buffer. The code I am using is as below:


#define __width 41
#define __height 41
#define __input_size (__width +7)/8 * __width

....

int main() {
// 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");
 ...
  for(int i=0; i<__input_size; i++){
      LCD_putByte(qrcodeBytes[i]);
     }
...
}

But the resulting QR code is not scannable and lacks finder/alignment patterns. Any guess why?

Thanks in advance

generate wifi QRCode

Hello,

Did you thinks that it's possible to generate qrCode for wifi access ?

Thanks a lot for the librarie.

Cannot build with MSVC

MSVC doesn't support VLA and #pragma mark.
Winsdk headers includes #define min/max, which generates lots of errors.
Hope for some workround.

The code consumes a significant amount of Stack and Heap memory!

I'm using this library on STM32 and Keil. I encountered an issue when trying to generate QR codes above version 8. After some experimentation, I discovered that it requires additional Heap and Stack memory.
Currently, with 12KB of Stack and 4KB of Heap memory allocated, I am able to generate QR codes up to version 13. However, for higher versions, more memory is needed, which I currently lack. I attempted to set LOCK_VERSION to 14, but it did not resolve the issue.
Is there a way to optimize memory usage and reduce consumption?

photo_2024-03-16_12-45-38
This image is for version 13 on a thermal printer.

cpp warning

Hi, just want to say that with my new Arduino IDE I got some warnings about constants.

This code:

uint8_t qrcodeBytes[qrcode_getBufferSize(2)];

should create a new array. But since the qrcode_getBufferSize function is not a constant, I get some warnings.

Moving the 2 functions to the header and declaring them with defines, it works like expected:

#define bb_getGridSizeBytes(_size) ((_size * _size + 7) / 8)
#define qrcode_getBufferSize(_ver) bb_getGridSizeBytes((4 * _ver + 17))

Display it to Webserver

i tried using this library and display it to website. But i dont know which one from the script that make summon the QR Code.
Can you help me ?
If i cant put it to website, can you give me an explain how to make the QR Code save to Micro SD as BMP / PNG
Thank you

QR Text being padded with 'ec 11' which doesn't allow for smaller versions.

Encoded Text: WIFI:S:*MyWifi-B0B5;T:nopass;P:;;

Encoded Bytes: 42 15 74 94 64 93 a5 33 a2 a4 d7 95 76 96 66 92 d4 23 04 23 53 b5 43 a6 e6 f7 06 17 37 33 b5 03 a3 b3 b0 ec 11 ec 11 ec 11 ec 11 ec 11 ec 11 ec 11 ec 11 ec 11 ec 11

For some reason it's padding with ec 11, which is now allowing me to use a smaller version

QR code type 10 or higher not scanable

The qr codes generated and displayed on a 320x480 TFT / Arduino MEGA can be scanned using an average qr-code scanner app, up to type 9. Using type 10 or higher, the app does not scan the code.

qrcode_initText retruns 0 (zero). Seems to be ok.

See code below, including the output: type 9 is working and type 10 is not working

Not sure if it is something I did wrong, or any other reason.
Help is greatly appreciated!

Kind regards

#include "qrcode.h"
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
#include <SPI.h>          // f.k. for Arduino-1.5.2
#include "Adafruit_GFX.h"// Hardware-specific library
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#define BLACK   0x0000
#define WHITE   0xFFFF

void setup() {
    int qr_return;
    // Create the QR code
    QRCode qrcode;
    uint8_t qrcodeData9[qrcode_getBufferSize(9)]; 
    
    qrcode_initText(&qrcode, qrcodeData9, 9, 0, "https://a.nl?b=HelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHel0123456789");
    
    uint16_t ID = tft.readID(); //
    tft.begin(ID);
    tft.fillScreen(WHITE);

    uint8_t qr_size = 5;
    uint8_t qr_top = 20;
    uint8_t qr_left = (320 / 2) - int((qrcode.size * qr_size) / 2);  // Center

    // Each line of modules
    for (uint8_t y = 0; y < qrcode.size; y++) {
        // Each horizontal module
        for (uint8_t x = 0; x < qrcode.size; x++) {
          if (qrcode_getModule(&qrcode, x, y)) {
            
            tft.fillRect(qr_left + (qr_size * x), qr_top + (qr_size * y), qr_size, qr_size, BLACK);
          }
        }
    }
   
    uint8_t qrcodeData10[qrcode_getBufferSize(10)]; 
    qrcode_initText(&qrcode, qrcodeData10, 10, 0, "https://a.nl?b=HelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHelloworldHel0123456789");

    qr_left = (320 / 2) - int((qrcode.size * qr_size) / 2);  // Center
    tft.fillScreen(WHITE);
    // Each line of modules
    for (uint8_t y = 0; y < qrcode.size; y++) {
        // Each horizontal module
        for (uint8_t x = 0; x < qrcode.size; x++) {
          if (qrcode_getModule(&qrcode, x, y)) {
            
            tft.fillRect(qr_left + (qr_size * x), qr_top + (qr_size * y), qr_size, qr_size, BLACK);
          }
        }
    }
}

void loop() {

}

Type 9 is working
typ9-works

Type 10 is not working
type10-not-working

How can I put more characters on the QR code?

I am trying to put +- 100 characters on the QR code. But I am having problems, because it need to be converted on array. What type of variable can I use to storage +- 100 characters?

When I try to put a char, a erro appears: " int8_t qrcode_initText(QRCode *qrcode, uint8_t *modules, uint8_t version, uint8_t ecc, const char *data);"

`String str;
ptos ++;
ptos ++;
e = horas;
total = ptos10000 + e100 + minutos;
Serial.println(total);
Serial.print(" = ");
str = String(total);
str.toCharArray(a,160);
Serial.print(a);
Serial.print("\n");

Serial.print("\n");
// Start time
uint32_t dt = millis();

// Create the QR code
QRCode qrcode;
uint8_t qrcodeNumeric[qrcode_getBufferSize(3)];
qrcode_initText(&qrcode, qrcodeNumeric, 3, ECC_LOW, total); `

Thanks for all

Cannot scan qrcodes for version 2 and 3 with android qrdroid reader

Hello,
I want to report that I'm having issues with qr codes version 2 and 3.
I tried to scan qr code generated with this versions and qr droid for android is not able to detect them. I tried to generate qrcodes version 4 and 5 and I can scan them without any issue.
This sound strange, maybe a qr droid issue but I want to report the problem anyway to better investigate and check if other people noticed the same thing.
Thanks for this software,
Regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.