PyBadger Event Badge
2024-06-04 | By Adafruit Industries
License: See Original Project
Courtesy of Adafruit
Guide by Kattni Rembor
Overview
Download PyBadge FeatherWing Snapfit Case
You're headed to the next big conference or event. They'll likely provide a badge with your name on it, but what if you could have something better?
That's where PyBadger and PyBadge (or PyGamer or CLUE) come in! Use CircuitPython to easily create an interactive conference or event badge. You can display a "Hello My Name Is"-style badge that you can quickly add your name to or customise it entirely. You can generate and display a custom QR code to direct people to your website. You can also display a "business card" with an image, such as your face or company logo, and a string of text, such as your email address.
PyBadger also gives you access to the other features on the board, such as the buttons, NeoPixels, light sensor, and accelerometer. You can easily add all kinds of features to your badge if you choose to.
CircuitPython's own Blinka is headed to the next Circuit Playground conference and wants to have the coolest badge there. This guide will walk you through Blinka creating an interactive conference badge. Follow along and customise it to fit your needs!
All you need to follow along is a PyBadge, battery and lanyard, we have a few options for each, so you can deck out in the fanciest style, or go for an affordable-yet-stylish look.
- Adafruit PyBadge for MakeCode Arcade, CircuitPython, or Arduino
- Adafruit PyBadge LC - MakeCode Arcade, CircuitPython, or Arduino
- Lithium-Ion Polymer Battery with Short Cable - 3.7V 350mAh
- Lithium-Ion Polymer Battery with Short Cable - 3.7V 420mAh
- Adafruit Circuit Playground Lanyard
- Double-Hook Lanyard in Adafruit Black
Prepare Your Badge
Adafruit CircuitPython PyBadger makes it easy to create an interactive conference or event badge with PyBadge or PyGamer. Blinka is headed to a fun conference and is excited to create a badge. Let's take a look!
Download PyBadger
Adafruit CircuitPython PyBadger requires the latest CircuitPython and a number of libraries to work.
To download CircuitPython, visit the following link for CLUE, PyBadge or PyGamer, depending on what you're using, and download the latest CircuitPython version for your board.
Download CircuitPython for CLUE from circuitpython.org
Download CircuitPython for PyBadge from circuitpython.org
Download CircuitPython for PyGamer from circuitpython.org
Next visit the following link and download the library bundle that matches your CircuitPython version.
Download the CircuitPython Library Bundle from circuitpython.org
PyBadger requires the following libraries to work. Download the library bundle and unzip the file. Open the folder, find the lib folder within, and open the lib folder. Copy the following folders and files to the lib folder on your CIRCUITPY drive:
- adafruit_bitmap_font
- adafruit_bus_device
- adafruit_display_shapes
- adafruit_display_text
- adafruit_miniqr.mpy
- adafruit_pybadger
- neopixel.mpy
If you are using PyBadge or PyGamer, copy the following library:
- adafruit_lis3dh.mpy
If you are using CLUE, copy the following library:
- adafruit_lsm6ds.mpy
- adafruit_register
Once you have the listed files and folders copied to the lib folder on your CIRCUITPY drive, you're ready to go!
Using PyBadger
Using PyBadger
Using the PyBadger library is easy. Simply import the library.
from adafruit_pybadger import pybadger
Now you have access to all the features PyBadger has to offer, including badge, business card, and QR code creation.
Hello My Name Is...
First, we'll create a "Hello My Name Is" style badge to display initially.
pybadger.show_badge(name_string="Blinka", hello_scale=2, my_name_is_scale=2, name_scale=3)
To change the badge to display your name, set name_string="Your Name" when you create the badge object.
Each of the scales applies to a different line on the badge, e.g., hello_scale applies to the HELLO string on the badge. When using the default font, the above values for hello_scale and my_name_is_scale are ideal. Depending on the length of your name, you'll want to tweak name_scale to allow it to fit properly.
Auto-Dim the Display
The display is the part of the badge that uses up the most battery. To help mitigate that, PyBadger includes the ability to auto-dim the display if the badge isn't moving. If you set it down somewhere, it'll use less battery.
while True:
pybadger.auto_dim_display()
It defaults to dimming after 5 seconds and brightening up again on a fairly small movement threshold of 1.5. If you would like to change either of those, you can do so when adding the auto_dim_display() function to your code. For example, to change it to wait 10 seconds before dimming, and require more movement to brighten up again, you would add the following:
pybadger.auto_dim_display(delay=10, movement_threshold=20)
The higher the movement_threshold, the more movement it takes to cause the display to return to full brightness.
Business Card
Everyone exchanges business cards at conferences. But it means carrying extra things around and trying to remember who gave you the card in the first place. Not anymore! Now you can display a simple business card with your picture, name, and email address. Someone can snap a quick picture of it and have your face and info available for later.
Blinka wants to display her name, email and image when pressing button A.
if pybadger.button.a:
pybadger.show_business_card(image_name="Blinka.bmp", name_string="Blinka", name_scale=2,
email_string_one="blinka@", email_string_two="adafruit.com")
The show_business_card function requires you to provide a bitmap image name as a string. You can optionally add your name as a string, and up to two lines of an email address (or any other info you'd like to provide!).
The badge will continue to display the business card until you tell it to display something else by pressing another button.
Images must be in 16-bit or 24-bit BMP format, and ideally 160x128 pixels. Here's the blinka.bmp file if you need to see what the format is:
QR Code
Blinka wants to direct other conference attendees to her website. She can easily do that by generating a QR code and having it display when pressing button B.
elif pybadger.button.b:
pybadger.show_qr_code(data="https://circuitpython.org")
The show_qr_code function allows you to set its target by setting data= a string with the target info in it. For example, Blinka wants to point to circuitpython.org and so she sets data="https://circuitpython.org".
The badge will continue to display the QR code until you tell it to display something else by pressing another button.
Return to Hello My Name Is...
Blinka needs a way to display the Hello My Name Is part of the badge again after showing off her business card and QR code. So, the last thing included is assigning the start button to display it.
elif pybadger.button.start:
pybadger.show_badge(name_string="Blinka", hello_scale=2, my_name_is_scale=2, name_scale=3)
That's all there is to creating a fun, interactive conference or event badge!
Full Example Code
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
from adafruit_pybadger import pybadger
pybadger.show_badge(
name_string="Blinka", hello_scale=2, my_name_is_scale=2, name_scale=3
)
while True:
pybadger.auto_dim_display(
delay=10
) # Remove or comment out this line if you have the PyBadge LC
if pybadger.button.a:
pybadger.show_business_card(
image_name="Blinka.bmp",
name_string="Blinka",
name_scale=2,
email_string_one="blinka@",
email_string_two="adafruit.com",
)
elif pybadger.button.b:
pybadger.show_qr_code(data="https://circuitpython.org")
elif pybadger.button.start:
pybadger.show_badge(
name_string="Blinka", hello_scale=2, my_name_is_scale=2, name_scale=3
)
Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.
Visit TechForum