Resistor shade codes are an important a part of maker schooling. The colour code system has been in steady use because the 1930’s and was launched by the Radio Producer’s Affiliation as a compact methodology for marking numerical values on small elements. The code incorporates solely 10 colours, however it might nonetheless be a problem to recollect their values until you utilize them each day.
This undertaking helps you utilize the resistor code each day to inform the time, and makes use of a Raspberry Pi Pico W to hook up with an NTP (Community Time Protocol) server over Wi-Fi for the present time. As soon as that is performed, the Pico W makes use of the WS2812B Neopixel strip to show the present time as resistor code colours. By wanting on the code in motion each day, you’ll quickly be decoding resistor values sooner in your sleep!
For this undertaking you will have
Connecting the NeoPixel Strip
WS2812B individually addressable RGB LEDs, generally known as “NeoPixels” are super-bright and simply controllable LEDS that may be any shade. They’re typically used so as to add temper lighting to a undertaking and so they may also be utilized in cosplay costumes and props.
Adafruit’s Neopixel Strip wants 5V to drive the LEDs, however can settle for a 3.3V logic sign on the information line.
Wire Coloration | Raspberry Pi Pico GPIO | NeoPixel |
---|---|---|
Pink | VBUS | 5V |
Blue | GPIO0 | Knowledge In |
Black | GND | GND |
The wiring for the resistor clock is straightforward, with solely GND, Knowledge and Energy required to attach the NeoPixel to the Pico W. Connecting the wire in order that they match throughout the 3D printed case could be a little bit difficult.
1. Start with the Pi Pico and the Neopixel stick face upwards, with the enter finish of the NeoPixel close to to the USB socket.
2. Join the wires as proven within the circuit diagram, leaving simply sufficient cable to fold the entire show meeting onto the again of the Raspberry Pi Pico W. The wires will must be soldered, a simple process for many makers. Watch out right here, as a result of the Neopixel strip has connections on each ends in order that they are often chained collectively. One finish of the strip is the enter, whereas the opposite is the output. You ought to be soldering wires to the enter finish.
3. Fold the show meeting onto the again of the Pi Pico W, in order that the row of LED lights is aligned with the midline of the Pico.
4. Repair the LED strip in place utilizing a small sq. of double sided foam tape. The froth allows the NeoPixel strip to sit down parallel to the Raspberry Pi Pico W with room beneath to tuck any extra cable.
Assembling the Enclosure
For many tasks, the field you place all the pieces into isn’t too vital. The Resistor clock is a bit totally different as a result of we have to do one thing slightly bit artful to get the entire colours we’d like. The resistor code is designed for marking with paint, and it makes use of some colours which can be a bit difficult to get by mixing the sunshine from LEDs. Most notably, black, brown, and grey aren’t the kind of colours you will get from an LED. Putting a bit of black tinted plastic in entrance of the LEDs helps right here, in order that when the LED is off, the plastic shall be black, however as quickly because the LED is on, you will note the colours. The darkish tint will scale back the luminosity of the LEDs, making it simpler to distinguish between colours like brown and orange.
1. 3D print the Raspberry Pi Pico case half. You possibly can sand, fill, and end the surface of the case nonetheless you assume is finest.
2. Insert the Pico-W with the USB socket positioned within the notch on the case, in order that the Pico and NeoPixel match contained in the printed case.
3. Trim two items of tinted acrylic to suit the highest and backside of the 3D printed case. In case you have entry to a laser cutter, you should utilize this to chop and etch the plastic.
4. Add a drop of superglue to the highest (the facet the place the LEDs are) corners of the 3D printed case, and glue the tinted plastic in place. If you happen to’ve used a Sharpie to paint the plastic, put the facet with the Sharpie ink in the direction of the within of the case.
5. Glue the opposite plastic into place on the rear of the 3D printed case. You need to use low temperature hot-glue on this facet of the case in case you desire, in order that the Pico W may be eliminated extra simply in future.
Setting Up the Raspberry Pi Pico W
The Raspberry Pi Pico makes use of MicroPython to manage the Neopixel stick and to hook up with NTP servers by way of a Wi-Fi connection.
1. Comply with this information to obtain and set up the MicroPython firmware to the Raspberry Pi Pico W, after which setup Thonny
2. Create a brand new file in Thonny and name it wifidetails.py. This file shall be used to retailer the connection particulars for the wi-fi community.
3. Add the next traces to the wifidetails.py, changing the MYSSID and MYPASS with the SSID and password in your wi-fi community.
ssid = ‘MYSSID’
password = ‘MYPASS’
4. Save the file to the Raspberry Pi Pico W.
5. Create a brand new file in Thonny and name it essential.py. That is the file that can run when the clock is plugged in. MicroPython is configured to run essential.py when the board is powered on.
6. Import the modules that can get you linked to the NTP server, together with the login particulars from the wifidetails.py file that you just simply created.
import time
import ntptime
import community
from wifidetails import ssid, password
7. Import the modules to entry the GPIO pins and management the NeoPixels.
from machine import pin
Import neopixel
8. Create a Python dictionary containing RGB values for every shade within the resistor shade code. You would possibly must tweak these values to get one of the best match from the tinted plastic you might be utilizing. A dictionary is a knowledge storage object that makes use of a key to retrieve a worth, on this case we’re utilizing a quantity, 0 to 9, as the important thing to retrieve the corresponding worth.
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 inform our code that the NeoPixels are linked to pin 0 on the Raspberry Pi Pico W.
np = neopixel.NeoPixel(Pin(0),8)
np = neopixel.NeoPixel(Pin(0),8)
10. Setup and start the connection to the Wi-Fi community utilizing the ssid and password particulars from wifidetails.py.
wlan = community.WLAN(community.STA_IF)
wlan.energetic(True)
wlan.join(ssid, password)
11. Look ahead to the Wi-Fi community to complete connecting.
max_wait = 10
whereas max_wait > 0:
if wlan.standing() < 0 or wlan.standing() >= 3:
break
max_wait -= 1
print('ready for connection...')
time.sleep(1)
12. Test that the community linked efficiently, and fail gracefully if there’s a downside. If the community connection is sweet, the IP handle of the clock is printed to the Python shell.
if wlan.standing() != 3:
elevate RuntimeError('community connection failed')
else:
standing = wlan.ifconfig()
print(standing[0]) #print the IP handle of the clock
13. Get the time from an NTP server utilizing the ntptime module, and reset the Pico W’s RTC (actual time clock) to match it.
ntptime.settime()
14. Create a loop to learn the time from the true time clock and retailer it in a variable, ct. Then use string formatting to retailer the time as a 6 digit string we will iterate via to set the NeoPixel RGB values.
whereas 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 with the format “HHMMSS”. We iterate via this string to set the RGB values saved within the rc dictionary to the primary 6 NeoPixels on the strip, then we write the adjustments to the NeoPixels. That is the top of the principle loop, so we add a delay to ‘tick’ the clock and scale back the load on the Pico W.
for i in vary(6):
np[i] = rc[int(timestring[i])]
# replace the neopixels
np.write()
time.sleep(1)
16. Save the code to the Raspberry Pi Pico W and click on Run to start out. The undertaking will get the present time and the NeoPixels will change shade to point the time. Each time the Pico is powered up, the code saved in essential.py will routinely run.
Full Code Itemizing
import time
import ntptime
import community
from wifidetails import ssid,password
from machine import Pin
import neopixel
# setup neopixel colours
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),
#join the neopixel
np = neopixel.NeoPixel(Pin(0),8)
# activate the Wi-fi
wlan = community.WLAN(community.STA_IF)
wlan.energetic(True)
wlan.join(ssid, password)
# Look ahead to join
max_wait = 10
whereas max_wait > 0:
if wlan.standing() < 0 or wlan.standing() >= 3:
break
max_wait -= 1
print('ready for connection...')
time.sleep(1)
if wlan.standing() != 3:
# Failed to attach
elevate RuntimeError('community connection failed')
else:
# print the ip handle
standing = wlan.ifconfig()
print(standing[0])
# Get and set the time from ntp
ntptime.settime()
whereas 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 shade to every neopixel primarily based on timestring
for i in vary(6):
np[i] = rc[int(timestring[i])]
# replace the neopixels
np.write()
time.sleep(1)