Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Hackster is hosting Impact Spotlights: Industrial Automation. Watch the stream live on Thursday!Hackster is hosting Impact Spotlights: Industrial Automation. Stream on Thursday!
cbk2604
Published © MIT

QRCode on ILI9341 TFT Touch Display

A tutorial on display QRCode using ILI9341 2.4 inch SPI TFT LCD colour screen module (i. e Pixel resolution: 240 x 320).

IntermediateFull instructions provided2,504
QRCode on ILI9341 TFT Touch Display

Things used in this project

Hardware components

ILI9341
×1
Arduino UNO
×1

Software apps and online services

Arduino IDE
Arduino IDE
LCDWIKI Library
ricmoo/QRCode Library

Story

Read more

Schematics

tft-lcd-with-arduino-schematic-768x394_xoArxZvkzP.png

Code

qrcode_ILI9341.ino

Arduino
#include <LCDWIKI_GUI.h> //Core graphics library
#include <LCDWIKI_SPI.h> //Hardware-specific library
#include "qrcode.h"

//paramters define
#define MODEL ILI9341
#define CS    A5    
#define CD    A3
#define RST   A4
#define MOSI  11
#define MISO  12
#define SCK   13
#define LED   A0   //if you don't need to control the LED pin,you should set it to -1 and set it to 3.3V

//the definiens of software spi mode as follow:
//if the IC model is known or the modules is unreadable,you can use this constructed function
LCDWIKI_SPI mylcd(MODEL,CS,CD,MISO,MOSI,RST,SCK,LED); //model,cs,dc,miso,mosi,reset,sck,led
//if the IC model is not known and the modules is readable,you can use this constructed function
//LCDWIKI_SPI mylcd(240,320,CS,CD,MISO,MOSI,RST,SCK,LED); //width,height,cs,dc,miso,mosi,reset,sck,led

//define some colour values
#define  BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

int16_t xaxis=0, yaxis=0, w, h;

void setup() {
  Serial.begin(9600);
  mylcd.Init_LCD();
  w = mylcd.Get_Display_Width();
  h = mylcd.Get_Display_Height();
  xaxis = w/2;
  yaxis = h/2;
  mylcd.Set_Text_Mode(0);
}

void loop() {
  mylcd.Fill_Screen(BLACK);
  generateQRCode();
}

void generateQRCode() {
  // Create the QR code
    QRCode qrcode;
    String amount = "https://youtu.be/jDbdt7-aDDE";
    uint32_t str_len = amount.length() + 1;
    char am[str_len];
    amount.toCharArray(am, str_len);
    char *data = am;
    
    const uint8_t ecc = 0;  //lowest level of error correction
    const uint8_t version = 3;

    uint8_t qrcodeData[qrcode_getBufferSize(version)];
    qrcode_initText(&qrcode, 
                    qrcodeData, 
                    version, ecc, 
                    data);
    const int xy_scale = 6;
    int xmax = w/2;
    int ymax = h/2;
    int offset = (xy_scale*qrcode.size);
    int x1 = xmax - (offset/2);
    int y1 = ymax - (offset/2);

    int px1 = x1;
    int py1 = x1;
    int px2 = px1;
    int py2 = py1;
    
//    // Top quiet zone
    for (uint8_t y = 0; y < qrcode.size; y++) {
        for (uint8_t x = 0; x < qrcode.size; x++) {
            bool mod = qrcode_getModule(&qrcode, x, y);
            px1 = x1 + x * xy_scale;
            py1 = x1 + y * xy_scale;
            px2 = px1 + xy_scale;
            py2 = py1 + xy_scale;
            if(mod){   
              mylcd.Set_Draw_color(CYAN);   
              mylcd.Fill_Rectangle(px1, py1, px2, py2);
            }
        }
    }
    
}

Credits

cbk2604
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.