Build the Ultimate DIY Smart Clock with Raspberry Pi Pico W - GrokClok Tutorial!
GrokClok: A Multifunctional Clock with Raspberry Pi Pico W
Project Overview
The GrokClok is a feature-rich clock project built on the Raspberry Pi Pico W microcontroller, developed as a collaboration between NeverCode (YouTube: NeverCode) and Grok (xAI). It combines precise timekeeping, environmental sensing, and user interaction into a compact, DIY-friendly package. Key features include:
- Dual LCD Displays: Time and temperature on the top LCD, menu and status on the bottom LCD.
- DS3231 RTC: Accurate timekeeping with battery backup.
- DHT11 Sensor: Temperature monitoring in Fahrenheit.
- 4x4 Keypad: Intuitive menu navigation and settings input.
- Wi-Fi & NTP Sync: Internet connectivity for automatic time updates.
- Buzzer: Audible alerts for timers and alarms.
- Modes: Timer, stopwatch, alarm, stats display, and timezone adjustment.
This documentation provides everything you need to build, program, and use the GrokClok, including hardware connections, software setup, and operational instructions.
Hardware Requirements
To build the GrokClok, gather the following components:
- Raspberry Pi Pico W
Microcontroller with Wi-Fi capability.
Purchase: Raspberry Pi Store or electronics retailers. - DS3231 RTC Module
Real-time clock with I2C interface and optional CR2032 battery for time retention.
Example: Adafruit DS3231. - DHT11 Temperature Sensor
Basic temperature sensor (upgradeable to DHT22 for humidity).
Example: Adafruit DHT11. - Two 16x2 I2C LCD Displays
16 characters x 2 lines, typically with PCF8574 I2C backpack (default address: 0x27).
Example: Amazon 16x2 LCD with I2C. - 4x4 Keypad
16-key matrix keypad for user input.
Example: Adafruit 4x4 Keypad. - Buzzer (Active or Passive)
PWM-compatible for alerts (e.g., 5V active buzzer).
Example: Amazon Buzzer. - Breadboard or PCB
For prototyping or permanent assembly.
Example: Amazon Breadboard. - Jumper Wires
Male-to-male and male-to-female Dupont wires.
Example: Amazon Jumper Wires. - Optional: Pull-Up Resistors
4.7kΩ resistors for I2C lines if not included in LCD modules. - Power Supply
Micro USB cable (5V) to power the Pico W.
Physical Connections
Wire the components to the Raspberry Pi Pico W as follows (GP = GPIO pin):
Pinout Table
Component | Pico W Pin | Notes |
---|---|---|
Top LCD (I2C0) | ||
- SCL | GP1 (Pin 2) | I2C clock line |
- SDA | GP0 (Pin 1) | I2C data line |
- VCC | 3.3V (Pin 36) | Power |
- GND | GND (Pin 38) | Ground |
Bottom LCD & RTC (I2C1) | ||
- SCL | GP27 (Pin 32) | Shared I2C clock line |
- SDA | GP26 (Pin 31) | Shared I2C data line |
- VCC | 3.3V (Pin 36) | Power |
- GND | GND (Pin 38) | Ground |
DHT11 Sensor | ||
- Data | GP15 (Pin 20) | Pull-up enabled internally |
- VCC | 3.3V (Pin 36) | Power |
- GND | GND (Pin 38) | Ground |
Keypad (4x4) | ||
- Row 1 | GP2 (Pin 4) | Output |
- Row 2 | GP3 (Pin 5) | Output |
- Row 3 | GP4 (Pin 6) | Output |
- Row 4 | GP5 (Pin 7) | Output |
- Col 1 | GP6 (Pin 9) | Input with pull-up |
- Col 2 | GP7 (Pin 10) | Input with pull-up |
- Col 3 | GP8 (Pin 11) | Input with pull-up |
- Col 4 | GP9 (Pin 12) | Input with pull-up |
Buzzer | ||
- Positive (PWM) | GP16 (Pin 21) | PWM signal |
- Negative | GND (Pin 23) | Ground |
Power | ||
- VBUS | 5V (Pin 40) | USB power input |
- GND | GND (e.g., Pin 3) | Multiple GND pins available |
I2C Address Configuration
Default Addresses:
- Both LCDs should use the default I2C address of
0x27
, set by the PCF8574 backpack. The DS3231 RTC uses0x68
, which is its standard address. - Verify with
i2c0.scan()
(Top LCD) andi2c1.scan()
(Bottom LCD & RTC) in MicroPython’s REPL if issues occur.
Why Same Addresses Are Okay:
- The GrokClok uses two separate I2C buses on the Pico W:
- I2C0 (GP0/GP1) for the Top LCD.
- I2C1 (GP26/GP27) for the Bottom LCD and RTC.
- Since each bus is independent, devices on different buses can share the same address (e.g.,
0x27
for both LCDs) without conflict. The RTC on I2C1 has a unique address (0x68
), avoiding overlap with the Bottom LCD. - If your LCDs have different addresses (e.g.,
0x3F
), modify the code inGrokClok_pico_w.py
:TOP_LCD_ADDR = 0x27
(line ~140)BOTTOM_LCD_ADDR = 0x27
(line ~144)
Notes
- Pull-Up Resistors: Add 4.7kΩ resistors between SDA/SCL and VCC if your I2C modules lack them.
- Breadboard Layout: Place the Pico W centrally, with LCDs on opposite sides, keypad below, and DHT11/buzzer to the right for easy access.
Software Requirements
The GrokClok runs on MicroPython and requires the following files:
Main Program
GrokClok_pico_w.py
The core program file.
Download Link
Library Files
lcd_api.py
Base LCD API for I2C communication.
Download Linkpico_i2c_lcd.py
I2C LCD driver for Pico.
Download Linkds3231.py
DS3231 RTC driver.
Download Link
Configuration File
secrets.py
Stores Wi-Fi credentials and timezone offset. Download the sample file and edit it with your details:
Download Sample Link
Create or edit this file with the following content:wifi_ssid = "YourWiFiSSID" # Replace with your Wi-Fi SSID wifi_password = "YourPassword" # Replace with your Wi-Fi password timezone_offset = -5 # Optional: UTC offset (e.g., -5 for EST)
Software Setup
- Install MicroPython:
- Download the latest MicroPython UF2 file for Pico W from micropython.org.
- Hold the BOOTSEL button on the Pico W, connect it to your computer via USB, and release BOOTSEL.
- Drag the UF2 file onto the Pico W’s drive (e.g., RPI-RP2). It will reboot into MicroPython.
- Install Thonny:
- Use Thonny IDE (thonny.org) to manage files and run code on the Pico W.
- Set interpreter to “MicroPython (Raspberry Pi Pico)” under Tools > Options > Interpreter.
- Upload Files:
- Connect the Pico W to your computer via USB.
- In Thonny, go to “File > Open” and select the Pico W device.
- Upload the following files:
- Download
secrets.py
, edit it with your Wi-Fi details, and upload it (right-click in Thonny’s file explorer > New File to create manually if preferred).
- Run the Program:
- Open
GrokClok_pico_w.py
in Thonny and click Run (F5), or rename it tomain.py
for auto-run on boot.
- Open
Assembly Instructions
- Prepare the Breadboard: Place the Pico W in the center of the breadboard, straddling the gap.
- Connect the Top LCD: Wire SDA to GP0, SCL to GP1, VCC to 3.3V, and GND to a ground pin.
- Connect the Bottom LCD and RTC: Share I2C1: SDA to GP26, SCL to GP27, VCC to 3.3V, GND to ground. Insert a CR2032 battery into the DS3231 if desired.
- Wire the DHT11: Data to GP15, VCC to 3.3V, GND to ground. No external pull-up resistor is needed (internal pull-up enabled).
- Attach the Keypad: Rows to GP2-GP5, columns to GP6-GP9. Ensure proper orientation (check pin 1).
- Connect the Buzzer: Positive to GP16, negative to GND.
- Power Up: Connect the Pico W to a USB power source (e.g., computer or 5V adapter).
- Test Connections: Power on the Pico W. The startup screen should display:
Top LCD: The GrokClok a Collab by: Bottom LCD: Grok of xAI NeverCode
After 3 seconds, it proceeds to RTC detection.
Usage Guide
Startup
On boot, the GrokClok displays credits for 3 seconds, then checks for the RTC and attempts Wi-Fi/NTP sync. If online, it syncs time via NTP; if offline, it uses the RTC (or falls back to system time if RTC fails).
Normal Mode
- Top LCD: Shows current time (12-hour format with blinking colon) and temperature (°F, updated every 5 minutes).
- Bottom LCD: Displays alarm status ("ALARM: OFF" or "ALARM: HH:MM AM/PM") and menu prompt ("#=Menu Net:GOOD/BAD").
Menu Navigation
Press #
to enter the menu. Options:
- Timer: Set a countdown timer.
- Stopwatch: Run a stopwatch with hundredths precision.
- Alarm: Set or disable an alarm.
- Stats: View system stats (IP, signal, etc.).
- Timezone: Adjust UTC offset.
Use #
to cycle options, *
to select. Exits to normal mode after 5 seconds of inactivity.
Setting the Timer
- Select "1 - TIMER" (
*
). - Enter MM:SS (e.g., "0130" for 1 minute 30 seconds) using 0-9 keys.
- Press
*
to start,#
to cancel.
Using the Stopwatch
- Select "2 - STOPWATCH" (
*
). *
starts/stops,#
clears (when stopped) or exits (after clearing).
Setting the Alarm
- Select "3 - ALARM" (
*
). - If off:
*
to enable and set,#
to exit. - If on:
*
to disable,#
to edit,0
to exit. - Enter HH:MM (e.g., "1222" for 12:22), then
*
for AM or#
for PM.
Viewing Stats
- Select "4 - STATS" (
*
). - Cycle through stats (IP, signal strength, etc.) with
*
, exit with#
.
Adjusting Timezone
- Select "5 - TIMEZONE" (
*
). - Press
#
to cycle offsets (-12 to +12),*
to save. Saved tosecrets.py
.
Alerts
- Timer Done: "TIMES UP" with buzzer; press
*
to reset,#
to exit. - Alarm Triggered: "ALARM!" with buzzer; press
*
to silence and disable.
Troubleshooting
- No Display: Check I2C connections and addresses (use
i2c.scan()
). Ensure LCDs are at0x27
or update the code. - Wi-Fi Fails: Verify
secrets.py
credentials; ensure Pico W is in range. - RTC Not Found: Check wiring to GP26/GP27; replace DS3231 if defective.
- Keypad Issues: Confirm row/column pins match code; test with a simple script.
Download Links
All files are available here:
Credits
- NeverCode: Hardware design, testing, and video production (YouTube: NeverCode).
- Grok (xAI): Software development, debugging, and documentation.
Build your own GrokClok and enjoy a blend of retro hardware and modern functionality!
Comments
Post a Comment