QR Codes are two dimensional barcodes that can easily be scanned by smartphones.
In this tutorial, we'll go through how you can use Python to encode text into a QR Code and display it on your OLED Expansion.
OverviewTutorial Difficulty: Beginner
Time Required: 10 minutes
Required Materials:
- The Omega
- The Expansion Dock
- OLED Expansions
Useful Experience:
- Using the OLED Expansion
- Using Python
We will need to have support for git, Python, and the Onion OLED Expansion Python Module.
opkg update
opkg install git git-http python-light python-codecs pyOledExp
Downloading the CodeNow we need to download the Python code that actually does all the work:
cd /root
git clone https://github.com/OnionIoT/oledQrCodeGenerator.git
Running the CodeFinally, we get to make some QR codes! Navigate into the repo directory:
cd oledQrCodeGenerator
And run the program, the argument to the script is the text that will be encoded in the QR code pattern:
root@Omega-18C2:~/oledQrCodeGenerator# python main.py 'Wow, my first QR Code'
> Encoding 21 characters
> Generated QR Code: 31x31 pixels
> Doubled QR Code size: 62x62
> Initializing display
> Setting display mode to inverted
> Writing buffer data to display
This will encode the data and display the resulting QR code on the OLED Expansion:
You can use the oledQrCodeGenerator
module in your own Python projects!
Example Code
import oledQrCodeGenerator
oledQrCodeGenerator.dispQrCode('Hello!')
Note that your Python script will have to be in the same directory as oledQrCodeGenerator
in order for it to work properly.
You can now use a smartphone to read the QR code on the OLED:
- On Android, we've used the QR Code Reader and QR Barcode Scanner apps successfully
- On iOS, we've had success with the QR Reader App
Happy hacking!
AcknowledgementsThe code in the qrcode
directory is a stripped-down version of lincolnloop's python-qrcode
repo:
https://github.com/lincolnloop/python-qrcode
The rest of the code is home grown by the Onion team :)
Original Wiki PageThe original guide page is available at:
Comments
Please log in or sign up to comment.