How To Make a Raspberry Pi Pico W Resistor Clock
resistor color code An integral part of maker education. The color code system has been in continuous use since the 1930s and was introduced by the Radio Manufacturers Association as a compact way to mark numbers on small components. Although the code only contains 10 colors, it can be difficult to remember the color values unless you use them every day.
This project will help you tell the time using a resistance cord every day. Raspberry Pi Pico W Connect to a NTP (Network Time Protocol) server for the current time over Wi-Fi. Once this is done, the Pico W uses a WS2812B Neopixel strip to display the current time in the color of the register code. Seeing your code running every day will help you decode resistance values faster right in your sleep!
For this project you will need
Connecting the NeoPixel strip
The WS2812B’s individually addressable RGB LEDs, commonly known as “NeoPixels”, are extremely bright and easily controllable to any color LED. It is often used to add mood lighting to projects and can also be used for cosplay costumes and props.
Adafruit’s Neopixel Strip requires 5V to drive the LEDs, but can accept 3.3V logic signals on the data lines.
wire color | Raspberry Pi Pico GPIO | neo pixel |
---|---|---|
red | VBUS | 5V |
blue | GPIO0 | data in |
black | earth | earth |
Wiring the resistor clock is simple and all you need to connect the NeoPixel to the Pico W is GND, data and power. Connecting the wires to fit inside the 3D printed case can be a little tricky.
1. start with pipiko When With the NeoPixel stick facing up, bring the input end of the NeoPixel closer to the USB socket.
2. Connect the wires as shown in the schematic, leaving enough cables to fold the entire display assembly to the back of the Raspberry Pi Pico W. The wires will need to be soldered, which is an easy task for most manufacturers. Be careful here, because Neopixel strips have connections on both ends that allow them to be chained together. One end of the strip is the input and the other end is the output. You will need to solder a wire to the input end.
3. Fold the display assembly to the back of the Pi Pico W, aligning the row of LED lights with the midline of the Pico.
Four. Use a small square of double-sided foam tape to hold the LED strip in place. The foam allows the NeoPixel strip to sit parallel to the Raspberry Pi Pico W with room underneath for extra cables.
Assembling the enclosure
For most projects, the box you put everything in isn’t all that important. Resistor clocks are slightly different. Because you have to do a little trickery to get all the colors you want. Resistor cords are designed to be marked with paint and use colors that are a little more difficult to obtain by mixing the light from the LEDs. Most notably, black, brown, and gray are not the colors you get from LEDs. If you put a black colored plastic in front of an LED, the plastic will be black when the LED is off, but will show color as soon as the LED is on. A darker tint reduces the luminosity of the LED, making it easier to distinguish colors such as browns and oranges.
1. 3D printing the case part of Raspberry Pi Pico. The outside of the case can be sanded, painted or finished.
2. Insert the Pico-W with the USB socket in the case notch so that the Pico and NeoPixel fit inside the printed case.
3. Cut two pieces of colored acrylic to fit the top and bottom of the 3D printed case. If you have access to a laser cutter, you can use it to cut and etch plastic.
Four. Put a drop of superglue on the top (side with the LED) corner of the 3D printed case and glue the colored plastic in place. If you used a Sharpie to color the plastic, the side with the Sharpie ink should face the inside of the case.
Five. Glue the other piece of plastic to the back of the 3D printed case. If necessary, you can use low temperature hot glue on this side of the case to make removing the Pico W easier in the future.
Setting up the Raspberry Pi Pico W
The Raspberry Pi Pico uses MicroPython to control the Neopixel stick and connect to an NTP server via a Wi-Fi connection.
1. follow this guide Download and install the MicroPython firmware on the Raspberry Pi Pico W and set up Thonny.
2. Create a new file with Thonny. Call it wifidetails.py. This file is used to store connection details for wireless networks.
3. add the following line In wifidetails.py, replace MYSSID and MYPASS with your wireless network’s SSID and password.
ssid = ‘MYSSID’
password = ‘MYPASS’
Four. Save the file to your Raspberry Pi Pico W.
Five. Create a new file in Thonny and name it main.py. This is the file that runs when the clock is connected. MicroPython is configured to run main.py when the board powers up.
6. Import module for connecting to NTP serverThis includes the login details from the wifidetails.py file we created.
import time
import ntptime
import network
from wifidetails import ssid, password
7. Import the module to access the GPIO pins and control the NeoPixels.
from machine import pin
Import neopixel
8. Create a Python dictionary containing RGB values Each color of resistor color code. You may need to tweak these values to get the best values for the colored plastic you are using. A dictionary is a data storage object that uses keys to retrieve values. In this case, we are using the numbers 0-9 as keys to get the corresponding values.
rc = {0:(0,0,0),
1:(36,12,0),
2:(255,0,0),
3:(255, 65, 0),
4:(255,255,0),
5:(0,255,0),
6:(0,0,255),
7:(255,0,255),
8:(2,2,2),
9:(255,255,255),
}
9. Create an object np to tell the code that the NeoPixels are connected to pin 0 of the Raspberry Pi Pico W.
np = neopixel.NeoPixel(Pin(0),8)
np = neopixel.NeoPixel(Pin(0),8)
Ten. Use the ssid and password details from wifidetails.py to set up and initiate a connection to your Wi-Fi network.
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
11. Wait for the Wi-Fi network connection to complete.
max_wait = 10
while max_wait > 0:
if wlan.status() < 0 or wlan.status() >= 3:
break
max_wait -= 1
print('waiting for connection...')
time.sleep(1)
12. It verifies that the network is well connected and fails gracefully if there is a problem. If the network connection is good, the clock’s IP address will be printed to the Python shell.
if wlan.status() != 3:
raise RuntimeError('network connection failed')
else:
status = wlan.ifconfig()
print(status[0]) #print the IP address of the clock
13. Use the ntptime module to get the time from an NTP server and reset the Pico W’s RTC (real time clock) accordingly.
ntptime.settime()
14. Create a loop that reads the time from the real-time clock and stores it in variable ct.Then use the string format to store the time as a 6 digit string You can iterate over the NeoPixel RGB values.
while True:
ct = time.localtime()
timestring = '{:0>2}{:0>2}{:0>2}'.format(ct[3], ct[4], ct[5])
15. The timestring variable is now a string in “HHMMSS” format. Iterates over this string, sets the RGB values stored in the rc dictionary to the first 6 NeoPixels of the strip, and writes the changes to the NeoPixels. Since this is the end of the main loop, we add a delay to ‘tick’ the clock and lighten the load on the Pico W.
for i in range(6):
np[i] = rc[int(timestring[i])]
# update the neopixels
np.write()
time.sleep(1)
16. Save the code to Raspberry Pi Pico W,[実行]Click to get started. The project gets the current time and the NeoPixels change color to indicate the time. When you power on Pico, it will automatically run the code stored in main.py.
complete code listing
import time
import ntptime
import network
from wifidetails import ssid,password
from machine import Pin
import neopixel
# setup neopixel colors
rc = {0:(0,0,0),
1:(36,12,0),
2:(255,0,0),
3:(255, 65, 0),
4:(255,255,0),
5:(0,255,0),
6:(0,0,255),
7:(255,0,255),
8:(2,2,2),
9:(255,255,255),
}
#connect the neopixel
np = neopixel.NeoPixel(Pin(0),8)
# activate the Wireless
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
# Wait for connect
max_wait = 10
while max_wait > 0:
if wlan.status() < 0 or wlan.status() >= 3:
break
max_wait -= 1
print('waiting for connection...')
time.sleep(1)
if wlan.status() != 3:
# Failed to connect
raise RuntimeError('network connection failed')
else:
# print the ip address
status = wlan.ifconfig()
print(status[0])
# Get and set the time from ntp
ntptime.settime()
while True:
# get the time and format it as a string of 6 digits
ct = time.localtime()
timestring = '{:0>2}{:0>2}{:0>2}'.format(ct[3], ct[4], ct[5])
# assign the resistor code color to each neopixel based on timestring
for i in range(6):
np[i] = rc[int(timestring[i])]
# update the neopixels
np.write()
time.sleep(1)