Introduction: Enigma QR Clock
Inspired by this article: http://hackaday.com/2012/10/29/qr-clock-is-unreadable-by-humans-and-computers-alike/
A QR generation library was ported to the Arduino UNO and Seeed LCD touchscreen platform. Originally the generation time was 6 seconds, making the display of seconds impossible. As @ch00ftech suggested, eliminating the search for the optimal QR mask and instead applying a fixed mask, drops the generation time to less than one second. Using a fast TFT display library by @Xark allows seconds to be displayed. This library was modified to comply with the calling convention for @seeedstudio libraries, making it a drop in replacement in an existing sketch. By changing a compiler directive, this library can also control an @adafruit LCD. As a further optimization, the last QR code generated is stored in a bitmap so only the pixels that change are painted.
Download a QR app. I like QR Droid Private and scan the images in this article. After receiving user feedback that some apps require a white background for the QR code to read, an option to invert the colors was added to the program.
Step 1: Assembling the Hardware
To make this project you will need:
- Arduino Uno
- Seeed Studios 2.8'' TFT Touch Shield V2.0 (SLD10261P).
- USB cable to program the arduino
Optionally, you will need a 9V battery and a power plug to power the clock without a computer.
Assembly is easy, just plug the TFT touch shield on top of the Arduino.
Step 2: Download the Fast TFT Library
This project uses a very fast library PDQ_ILI9341 LCD controller by XarkLabs, modified to it is a drop in replacement for the Seeed TFT library..
To install this library
Launch the Arduino IDE
go to Sketch -> Include Library -> Add .ZIP Library and browse to the location where the zip file above was saved.
Now your Arduino sketches can use the FastTftILI9341.h library
Step 3: Download the QR Clock Program
Now you need to get the Arduino sketch for the QR clock.
- Download https://github.com/arduinoenigma/EnigmaQRClock/archive/master.zip
- Go to your Arduino Sketch folder
- Create a folder named EnigmaQRClock.
- Unzip the contents of the zip file into that folder.
- Double click the EnigmaQRClock.ino file and the Arduino IDE will open
Step 4: Upload the Clock Sketch and Set the Time
Uploading the clock program to the Arduino is easy.
After double clicking the EnigmaQRClock.ino file, make sure the Arduino IDE shows 3 tabs, EnigmaQRClock, SerialMenu and choofQR
If so, you are good to go. Otherwise, make sure all of the files in the ZIP file were extracted to the same sketch folder.
If you have an Adafruit screen, add // in front of #define TFTSeed to comment it out and remove the // in front of //#define TFTAdafruit
#define TFTSeed<br>//#define TFTAdafruit
To upload the QR clock:
- Tools -> Board:... -> Arduino / Genuino Uno
- Tools -> Port:... -> Ensure your Arduino is listed here and select the correct port number.
- Select Sketch -> Upload or just press Crl + U
If everything went well, the Arduino IDE will compile and upload the sketch to your Arduino. It will soon start showing rapidly changing QR codes.
To set the time:
- Tools -> Monitor or just press Ctrl + Shift + M
- Ensure the speed is set to 9600 baud.
- Type the following command
The command to set the time can be broken down into the following individual commands:
i0 sets the normal color scheme, i1 inverts the colors.
r1 sets rotation so plug is to the right. Any rotation is fine, setting is for purists
h15 sets hours to 15
m22 sets minutes to 22
s10 sets seconds to 25
u10 sets update rate to 10 seconds, 1,5,10,15,20,30,60 are valid
d shows the time
x starts the clock now
if a command with a two digit parameter is sent with two digits, the semicolon can be omitted
the following are valid strings
Step 5: Running It and Setting the Time Automatically
Your QR clock can be set automatically to the computer time.
There is a file called setclock.cmd that will do that when double clicked. Before this file will work, it must be told where to find the Arduino. To do that, edit the setclock.cmd file, find the line
Make sure the number at the end matches the Serial Port shown in the Arduino IDE.
You can also edit the following line and set your preferred background color (i1), rotation (r1), and
To set the time:
- Open a Serial Monitor in the Arduino IDE (Ctrl+Shift+M) and then close it. This opens the port and lets the setclock.cmd file write to it.
- Double click the setclock.cmd file. The QR clock will immediately start showing the current time.
Step 6: Theory of Operation.
The EnigmaQRClock.ino file:
- Contains the global strings needed for operation.
- Builds the time string to display according to the update speed.
- Advances the time.
- Initializes the LCD screen
- Clears the previous QR code and clears the screen.
- Contains the setup and loop routines.
- The setup routine executes once. It initializes the screen, sets default values, shows the first time on the screen, and pre-computes the next time to be shown.
- The loop routine read the serial port and updates the time when the desired update interval has elapsed.
The SerialMenu.ino file:
- Implements a Finite State Machine that polls the serial port for available characters. If one is available it will read it.
- In the initial state, the first character read will be interpreted as a command.
- If a valid command is found (H,M,S,R,U,P). The routine will be set to expect the appropriate number of numerical characters for that parameter value. Once enough characters have been collected, the parameter will be set to that value.
The choofQR file:
- Prints a QR code to the screen. It will only update pixels that have changed since the last drawing.
- Generates a QR code. The penalty code has been deactivated since it added time to the QR code generation. Instead a fixed mask (0) is added.
Step 7: Add a Protective Case to Your Project.
This is an optional step, but it protects your project. Once assembled, the Arduino and LCD screen cannot be removed from the case.
Get a case at the link below:
Follow the instructions in this link to glue the case together: