A collection of utilities for the Pimoroni Badger 2040W, including a battery level indicator, Wi-Fi network manager, and weather display using the Open Meteo API.
Displays the current battery level as a percentage and a visual bar. Automatically detects USB power and shows a plug icon when connected.
- Measures the battery voltage using the ADC (Analog-to-Digital Converter).
- Calculates the battery level as a percentage based on the voltage range (4.2V = 100%, 2.8V = 0%).
- Renders a battery icon, a progress bar, and the percentage value.
- Detects USB power and displays a plug icon if the device is charging.
Allows users to select and save Wi-Fi networks from a list. Networks are stored in a text file (wifi_networks.txt) and can be edited manually.
- Displays a scrollable list of Wi-Fi networks.
- Supports navigation using the Badger 2040W buttons (A, B, C, Up, Down).
- Saves the selected network to
WIFI_CONFIG.pyfor use in other applications. - Persists the selected item and scroll position between reboots.
- Loads networks from
wifi_networks.txt(format:SSID|PSK|COUNTRY). - Renders a list with scrollable items and interactive buttons.
- Updates the configuration file when a network is selected.
Fetches and displays current weather data, air quality, and pollen information for a specified location using the Open Meteo API.
- Current Weather: Shows temperature, weather conditions, wind speed, and wind direction.
- Forecast: Displays a 2-day weather forecast with icons.
- Sunrise/Sunset: Shows sunrise and sunset times.
- Air Quality: Displays PM10, PM2.5, and UV index.
- Pollen Levels: Shows pollen counts for alder, birch, grass, mugwort, ragweed, and olive.
- Automatic Theme: Switches between day and night themes based on sunrise/sunset times.
- Power Management: Updates every 20 minutes when connected to USB power, and enters deep sleep mode when running on battery.
- Fetches weather data from the Open Meteo API.
- Displays weather icons based on current conditions.
- Updates the display automatically or on button press.
- Hardware: Pimoroni Badger 2040W
- Firmware: MicroPython (pre-installed on Badger 2040W)
- Libraries:
badger2040,badger_os,machine,binascii,urequests,jpegdec - Icons: Weather icons in the
/icons/directory (e.g.,icon-sun.jpg,icon-rain.jpg, etc.).
- Copy the provided Python scripts to your Badger 2040W.
- Edit
wifi_networks.txtto add your Wi-Fi networks (one per line, format:SSID|PSK|COUNTRY). - Ensure the
/icons/directory contains the required weather icons. - Run the script using the Badger 2040W's built-in tools.
Call the draw_battery_usage(x) function in your main loop to display the battery level at position x.
- Navigate the list using the Up/Down buttons.
- Press Button A to scroll up a page.
- Press Button C to scroll down a page.
- Press Button B to select a network and save it to
WIFI_CONFIG.py.
- The weather display updates automatically every 20 minutes when connected to USB power.
- Press any button to wake the device from deep sleep when running on battery.
Adjust the full_battery and empty_battery values in the draw_battery_usage() function if your battery has a different voltage range.
Edit wifi_networks.txt to add or remove networks.
- Change the latitude (
LAT) and longitude (LNG) inweather.pyto display weather data for a different location. - Replace the icons in the
/icons/directory to customize the visual style.
This project is open-source and available under the MIT License.
- Original weather display concept inspired by chrissyhroberts.
- Weather data provided by Open Meteo.