# Blahaj Alarm and Lamp

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/109/968/medium800thumb/circuitpython_ezgif.com-gif-maker_%281%29.jpg?1647923878)

Do you have trouble waking up? Do you keep forgetting to get in bed at a decent time? Are you impressively bad at remembering to take a certain pill twice a day? Do you keep forgetting about that one meeting for work until right before it starts? Do you have multiple stuffed sharks and no idea what to do with them?&nbsp;

If any (or all) of these seem relatable, then this project is for you! While the scientific consensus is still out on whether stuffed sharks from Ikea help with the last one, I can certainly say that it has a decent chance of helping with all the others.

In this project, you'll take an Ikea Blåhaj (technically pronounced blow-high, although I've never pronounced it like that because it's not as fun as mispronouncing it on purpose) and add a Feather RP2040 with a small speaker to play an audio reminder, and an RTC (real-time clock) to keep the time.

## Parts

In addition to the parts and tools on this list, you will need:

- [A seam ripper](https://www.amazon.com/Dritz-638-Deluxe-Seam-Ripper/dp/B0001DSIVY/ref=sr_1_5?crid=1F9AWTOYAU406&keywords=seam+ripper&qid=1647924076&sprefix=seam+rippe%2Caps%2C51&sr=8-5)
- [Sewable Velcro](https://www.amazon.com/VELCRO-Brand-Fasteners-Wide-White/dp/B001HZWF50/ref=sr_1_13?crid=MEMR7BFICPMB&keywords=sewable+velcro&qid=1647924103&sprefix=sewable+velcro%2Caps%2C51&sr=8-13)
- [A Blahaj](https://www.ikea.com/us/en/p/blahaj-soft-toy-shark-90373590/)
- [Thread](https://www.amazon.com/Gutermann-Sew-All-Thread-547yd-Copen/dp/B004BPADB6/ref=sr_1_4?crid=3QWBK72A7C6V5&keywords=light+blue+thread&qid=1647924187&sprefix=light+blue+thread%2Caps%2C58&sr=8-4)

### Adafruit Feather RP2040

[Adafruit Feather RP2040](https://www.adafruit.com/product/4884)
A new chip means a new Feather, and the Raspberry Pi RP2040 is no exception. When we saw this chip we thought "this chip is going to be awesome when we give it the Feather Treatment" and so we did! This Feather features the&nbsp; **RP2040** , and all niceties you know and...

In Stock
[Buy Now](https://www.adafruit.com/product/4884)
[Related Guides to the Product](https://learn.adafruit.com/products/4884/guides)
![Angled shot of black rectangular microcontroller "Feather RP2040"](https://cdn-shop.adafruit.com/640x480/4884-04.jpg)

### FeatherWing Proto - Prototyping Add-on For All Feather Boards

[FeatherWing Proto - Prototyping Add-on For All Feather Boards](https://www.adafruit.com/product/2884)
A Feather board without ambition is a Feather board without FeatherWings!

This is the **FeatherWing Proto** - a prototyping add-on for all Feather boards. Using our [Feather Stacking Headers](https://www.adafruit.com/products/2830) or <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/2884)
[Related Guides to the Product](https://learn.adafruit.com/products/2884/guides)
![Angled Shot of the FeatherWing Proto - Prototyping Add-on For All Feather Boards.](https://cdn-shop.adafruit.com/640x480/2884-13.jpg)

### Stacking Headers for Feather - 12-pin and 16-pin female headers

[Stacking Headers for Feather - 12-pin and 16-pin female headers](https://www.adafruit.com/product/2830)
These two **Female Stacking Headers** alone are, well, lonely. But pair them with any of our [Feather](https://www.adafruit.com/categories/777) boards and you're in business!

What do they do? They stack. Put the headers through your Feather and then you can...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2830)
[Related Guides to the Product](https://learn.adafruit.com/products/2830/guides)
![Angled shot of a Stacking Headers for Feather - 12-pin and 16-pin female headers. ](https://cdn-shop.adafruit.com/640x480/2830-08.jpg)

### Adafruit STEMMA Speaker - Plug and Play Audio Amplifier

[Adafruit STEMMA Speaker - Plug and Play Audio Amplifier](https://www.adafruit.com/product/3885)
Hey, have you heard the good news? With Adafruit STEMMA boards you can easily and safely plug sensors and devices together, like this **Adafruit STEMMA Speaker - Plug and Play Audio Amplifier**. Like the name implies, it's got a class D audio amplifier on board, and our...

Out of Stock
[Buy Now](https://www.adafruit.com/product/3885)
[Related Guides to the Product](https://learn.adafruit.com/products/3885/guides)
![Top view of a black speaker breakout board connected to a round microcontroller via alligator clips. A music note animation emits from the speaker.](https://cdn-shop.adafruit.com/product-videos/640x480/3885-05.jpg)

### JST PH 2mm 3-pin Plug to Color Coded Alligator Clips Cable

[JST PH 2mm 3-pin Plug to Color Coded Alligator Clips Cable](https://www.adafruit.com/product/4030)
This cable will let you turn a JST PH 3-pin cable port into 3 individual wires with grippy mini alligator clips. We're carrying these to match up with any of our boards or breakouts with 3-pin 'STEMMA' connectors on them such as the&nbsp;<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/4030)
[Related Guides to the Product](https://learn.adafruit.com/products/4030/guides)
![Angled shot of JST PH 3-pin Plug to Color Coded Alligator Clips Cable.](https://cdn-shop.adafruit.com/640x480/4030-04.jpg)

### Adafruit PCF8523 Real Time Clock Breakout Board

[Adafruit PCF8523 Real Time Clock Breakout Board](https://www.adafruit.com/product/5189)
This is a great battery-backed real time clock (RTC) that allows your microcontroller project to keep track of time even if it is reprogrammed, or if the power is lost. Perfect for data-logging, clock-building, time stamping, timers, and alarms, etc. Equipped...

In Stock
[Buy Now](https://www.adafruit.com/product/5189)
[Related Guides to the Product](https://learn.adafruit.com/products/5189/guides)
![Angled shot of PCF8523 Real Time Clock Breakout Board.](https://cdn-shop.adafruit.com/640x480/5189-00.jpg)

### CR1220 12mm Diameter - 3V Lithium Coin Cell Battery

[CR1220 12mm Diameter - 3V Lithium Coin Cell Battery](https://www.adafruit.com/product/380)
These are the highest quality & capacity batteries, the same as shipped with the iCufflinks,&nbsp;iNecklace, Datalogging and GPS Shields, GPS HAT, etc. One battery per order (you'll want one battery per cufflink or pendant.)  
  
Brand may vary but all battery brands are verified...

In Stock
[Buy Now](https://www.adafruit.com/product/380)
[Related Guides to the Product](https://learn.adafruit.com/products/380/guides)
![Angled shot of CR1220 12mm Diameter - 3V Lithium Coin Cell Battery - CR1220.](https://cdn-shop.adafruit.com/640x480/380-01.jpg)

### Flora RGB Smart NeoPixel version 3 - Pack of 4

[Flora RGB Smart NeoPixel version 3 - Pack of 4](https://www.adafruit.com/product/1260)
What's a wearable project without LEDs? Our favorite part of the Flora platform is these tiny smart pixels. Designed specifically for wearables, these updated Flora NeoPixels have ultra-cool technology: these ultra-bright LEDs have a constant-current driver cooked right into the LED...

In Stock
[Buy Now](https://www.adafruit.com/product/1260)
[Related Guides to the Product](https://learn.adafruit.com/products/1260/guides)
![Overhead shot of four, black, round LED breakouts.](https://cdn-shop.adafruit.com/640x480/1260-09.jpg)

### Adafruit LC709203F LiPoly / LiIon Fuel Gauge and Battery Monitor

[Adafruit LC709203F LiPoly / LiIon Fuel Gauge and Battery Monitor](https://www.adafruit.com/product/4712)
Low cost Lithium Polymer batteries have revolutionized electronics - they're thin, they're light, they can be regulated down to 3.3V and they're easy to charge. On your phone, there's a little image of a battery cell that tells you the percentage of charge - so you know when...

In Stock
[Buy Now](https://www.adafruit.com/product/4712)
[Related Guides to the Product](https://learn.adafruit.com/products/4712/guides)
![Top view of Adafruit LC709203F LiPoly / LiIon Fuel Gauge and Battery Monitor powered by a Lipoly battery and an OLED display.](https://cdn-shop.adafruit.com/640x480/4712-07.jpg)

### Stainless Medium Conductive Thread - 3 ply - 18 meter/60 ft

[Stainless Medium Conductive Thread - 3 ply - 18 meter/60 ft](https://www.adafruit.com/product/641)
After months of searching, we finally have what we consider to be the ultimate conductive thread. It's thin, strong, smooth, and made completely of 316L stainless steel. Once you start working with this thread you'll quickly agree its optimal for any wearables work!  
  
This...

In Stock
[Buy Now](https://www.adafruit.com/product/641)
[Related Guides to the Product](https://learn.adafruit.com/products/641/guides)
![Small spool of conductive thread.](https://cdn-shop.adafruit.com/640x480/641-05.jpg)

Get 2 of these

### STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long

[STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long](https://www.adafruit.com/product/4399)
This 4-wire cable is&nbsp;50mm / 1.9" long and fitted with JST SH female 4-pin connectors on both ends. Compared with the chunkier JST PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and remove.

<a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/4399)
[Related Guides to the Product](https://learn.adafruit.com/products/4399/guides)
![Angled of of JST SH 4-Pin Cable.](https://cdn-shop.adafruit.com/640x480/4399-00.jpg)

### JST-PH 2-pin Jumper Cable - 100mm long

[JST-PH 2-pin Jumper Cable - 100mm long](https://www.adafruit.com/product/4714)
We use 2 pin JST PH connectors for all our battery packs, and if you want to put a board in series, [like our LC709203F Stemma QT battery gauge](https://www.adafruit.com/product/4712), this cable will be very handy!

Both ends have a JST PH 2mm pitch 2-pin plug. Between the...

In Stock
[Buy Now](https://www.adafruit.com/product/4714)
[Related Guides to the Product](https://learn.adafruit.com/products/4714/guides)
![Angled shot of JST-PH 2-pin Jumper Cable - 100mm long](https://cdn-shop.adafruit.com/640x480/4714-01.jpg)

### Lithium Ion Battery Pack - 3.7V 6600mAh

[Lithium Ion Battery Pack - 3.7V 6600mAh](https://www.adafruit.com/product/353)
Need a massive battery for your project? This lithium-ion pack is made of 3 balanced 2200mAh cells for a total of 6600mA capacity! The cells are connected in parallel and spot-welded to a protection circuit that provides over-voltage, under-voltage, and over-current protection.

Each cell...

Out of Stock
[Buy Now](https://www.adafruit.com/product/353)
[Related Guides to the Product](https://learn.adafruit.com/products/353/guides)
![Lithium Ion Battery Pack with three round cells 3.7V 6600mAh with JST PH connector](https://cdn-shop.adafruit.com/640x480/353-03.jpg)

### Hook-up Wire Spool Set - 22AWG Solid Core - 6 x 25 ft

[Hook-up Wire Spool Set - 22AWG Solid Core - 6 x 25 ft](https://www.adafruit.com/product/1311)
Perfect for bread-boarding, free wiring, etc. This box contains 6 spools of solid-core wire. The wire is easy to solder to and when bent it keeps its shape pretty well. We like to have a few spools of this stuff around which is why this set is quite nice! We suggest picking up wire strippers...

In Stock
[Buy Now](https://www.adafruit.com/product/1311)
[Related Guides to the Product](https://learn.adafruit.com/products/1311/guides)
![Hook-up Wire Spool Set in box with 6 colorful wires coming out](https://cdn-shop.adafruit.com/640x480/1311-04.jpg)

## Tools
### Needle set - 3/9 sizes - 20 needles

[Needle set - 3/9 sizes - 20 needles](https://www.adafruit.com/product/615)
Mighty needles, sew like the wind! This needle set is the only one you'll need for any sort of hand sewing, especially using our conductive thread and wearable electronics parts.  
  
Each pack contains 20 gold-eye sharps, with eye sizes ranging from #3 (1.75" long) to #9...

Out of Stock
[Buy Now](https://www.adafruit.com/product/615)
[Related Guides to the Product](https://learn.adafruit.com/products/615/guides)
![Small blue packaging containing 20 sewing needles.](https://cdn-shop.adafruit.com/640x480/615-03.jpg)

### Solder Wire - 60/40 Rosin Core - 0.5mm/0.02" diameter - 50 grams

[Solder Wire - 60/40 Rosin Core - 0.5mm/0.02" diameter - 50 grams](https://www.adafruit.com/product/1886)
If you want to make a kit you'll need some solder. This 0.1 lb (about 50 grams) spool is a good amount, not too much (like 1 lb spools) and not too little (like those little 'pocket clip' vials).  
  
This spool of solder contains approximately 0.6mm / .02" diameter in...

Out of Stock
[Buy Now](https://www.adafruit.com/product/1886)
[Related Guides to the Product](https://learn.adafruit.com/products/1886/guides)
![Solder Wire - 60/40 Rosin Core - 0.5mm/0.02" diameter.](https://cdn-shop.adafruit.com/640x480/1886-01.jpg)

### Hakko Professional Quality 20-30 AWG Wire Strippers

[Hakko Professional Quality 20-30 AWG Wire Strippers](https://www.adafruit.com/product/527)
These are the finest wire strippers we have used, and if you have to do a lot of wiring, you will agree! They have soft rounded grips - very comfortable to use, and precision ground notches that do a perfect job every time. No more yanking or twisting to strip wires cleanly and quickly.<br...></br...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/527)
[Related Guides to the Product](https://learn.adafruit.com/products/527/guides)
![Red and black multi-size wire stripplers, closed](https://cdn-shop.adafruit.com/640x480/527-02.jpg)

### Flush diagonal cutters

[Flush diagonal cutters](https://www.adafruit.com/product/152)
These are the best diagonal cutters, large super-comfortable grip to use and have strong nippers for perfect trimming of wires and leads. I've used my pair every day for years.

In Stock
[Buy Now](https://www.adafruit.com/product/152)
[Related Guides to the Product](https://learn.adafruit.com/products/152/guides)
![Red and black diagonal flush cutters](https://cdn-shop.adafruit.com/640x480/152-02.jpg)

Primary: 

# Blahaj Alarm and Lamp

## Install CircuitPython

[CircuitPython](https://github.com/adafruit/circuitpython) is a derivative of [MicroPython](https://micropython.org) designed to simplify experimentation and education on low-cost microcontrollers. It makes it easier than ever to get prototyping by requiring no upfront desktop software downloads. Simply copy and edit files on the **CIRCUITPY** drive to iterate.

## CircuitPython Quickstart

Follow this step-by-step to quickly get CircuitPython running on your board.

[Download the latest version of CircuitPython for this board via circuitpython.org](https://circuitpython.org/board/adafruit_feather_rp2040/)
 **Click the link above to download the latest CircuitPython UF2 file.**

Save it wherever is convenient for you.

![install_circuitpython_on_rp2040_RP2040_UF2_downloaded.jpg](https://cdn-learn.adafruit.com/assets/assets/000/101/655/medium640/install_circuitpython_on_rp2040_RP2040_UF2_downloaded.jpg?1618943202)

![](https://cdn-learn.adafruit.com/assets/assets/000/102/705/medium800/adafruit_products_FeatherRP_buttons_highlighted.jpg?1623167565)

To enter the bootloader, hold down the **BOOT/**** BOOTSEL button**(highlighted in red above), and while continuing to hold it (don't let go!), press and release the**reset button**(highlighted in red or blue above).&nbsp;**Continue to hold the BOOT/BOOTSEL button until the RPI-RP2 drive appears!**

If the drive does not appear, release all the buttons, and then repeat the process above.

You can also start with your board unplugged from USB, press and hold the BOOTSEL button (highlighted in red above), continue to hold it while plugging it into USB, and wait for the drive to appear before releasing the button.

A lot of people end up using charge-only USB cables and it is very frustrating! **Make sure you have a USB cable you know is good for data sync.**

You will see a new disk drive appear called **RPI-RP2**.

&nbsp;

Drag the **adafruit\_circuitpython\_etc.uf2** file to **RPI-RP2.**

![install_circuitpython_on_rp2040_RP2040_bootloader_drive.jpg](https://cdn-learn.adafruit.com/assets/assets/000/101/656/medium640/install_circuitpython_on_rp2040_RP2040_bootloader_drive.jpg?1618943666)

![install_circuitpython_on_rp2040_RP2040_drag_UF2.jpg](https://cdn-learn.adafruit.com/assets/assets/000/101/657/medium640/install_circuitpython_on_rp2040_RP2040_drag_UF2.jpg?1618943674)

The **RPI-RP2** drive will disappear and a new disk drive called **CIRCUITPY** will appear.

That's it, you're done! :)

![install_circuitpython_on_rp2040_RP2040_CIRCUITPY.jpg](https://cdn-learn.adafruit.com/assets/assets/000/101/658/medium640/install_circuitpython_on_rp2040_RP2040_CIRCUITPY.jpg?1618943864)

## Safe Mode

You want to edit your **code.py** or modify the files on your **CIRCUITPY** drive, but find that you can't. Perhaps your board has gotten into a state where **CIRCUITPY** is read-only. You may have turned off the **CIRCUITPY** drive altogether. Whatever the reason, safe mode can help.

Safe mode in CircuitPython does not run any user code on startup, and disables auto-reload. This means a few things. First, safe mode _bypasses any code in_ **boot.py** (where you can set **CIRCUITPY** read-only or turn it off completely). Second, _it does not run the code in_ **code.py**. And finally, _it does not automatically soft-reload when data is written to the_ **CIRCUITPY** _drive_.

Therefore, whatever you may have done to put your board in a non-interactive state, safe mode gives you the opportunity to correct it without losing all of the data on the **CIRCUITPY** drive.

### Entering Safe Mode
To enter safe mode when using CircuitPython, plug in your board or hit reset (highlighted in red above). Immediately after the board starts up or resets, it waits 1000ms. On some boards, the onboard status LED (highlighted in green above) will blink yellow during that time. If you press reset during that 1000ms, the board will start up in safe mode. It can be difficult to react to the yellow LED, so you may want to think of it simply as a slow double click of the reset button. (Remember, a fast double click of reset enters the bootloader.)

### In Safe Mode

If you successfully enter safe mode on CircuitPython, the LED will intermittently blink yellow three times.

If you connect to the serial console, you'll find the following message.

```terminal
Auto-reload is off.
Running in safe mode! Not running saved code.

CircuitPython is in safe mode because you pressed the reset button during boot. Press again to exit safe mode.

Press any key to enter the REPL. Use CTRL-D to reload.
```

You can now edit the contents of the **CIRCUITPY** drive. Remember, _your code will not run until you press the reset button, or unplug and plug in your board, to get out of safe mode._

## Flash Resetting UF2

If your board ever gets into a really _weird_ state and CIRCUITPY doesn't show up as a disk drive after installing CircuitPython, try loading this 'nuke' UF2 to RPI-RP2. which will do a 'deep clean' on your Flash Memory. **You will lose all the files on the board** , but at least you'll be able to revive it! After loading this UF2, follow the steps above to re-install CircuitPython.

[Download flash erasing "nuke" UF2](https://cdn-learn.adafruit.com/assets/assets/000/101/659/original/flash_nuke.uf2?1618945856)
# Blahaj Alarm and Lamp

## Electronics Assembly

![](https://cdn-learn.adafruit.com/assets/assets/000/109/991/medium800/projects_blahaj.png?1647970130)

Danger: 

Insert the CR1220 battery into the PCF8523 with the positive side facing out. and attach a STEMMA cable to the RTC.

![circuitpython_IMG_3032.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/747/medium640/circuitpython_IMG_3032.jpg?1647462868)

![circuitpython_IMG_3031.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/748/medium640/circuitpython_IMG_3031.jpg?1647462917)

![circuitpython_IMG_3033.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/965/medium640/circuitpython_IMG_3033.jpg?1647923537)

Connect the RTC to the LC709203 and attach a JST cable and another STEMMA cable to the LC709203.

![circuitpython_IMG_3116.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/964/medium640/circuitpython_IMG_3116.jpg?1647923462)

Solder the stacking headers onto the Feather RP2040, then solder the normal headers onto the FeatherWing Proto. After this you can remove the FeatherWing proto board from the RP2040.

![circuitpython_IMG_3001.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/751/medium640/circuitpython_IMG_3001.jpg?1647463149)

![circuitpython_IMG_3006.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/752/medium640/circuitpython_IMG_3006.jpg?1647463167)

Take the JST PH 3-pin Plug and cut off the alligator clips on the end. Then strip and tin the wires. If you want to, you can add little bits of heat-shrink to the wire to make it look neater, but this isn't necessary.

![circuitpython_IMG_3037.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/754/medium640/circuitpython_IMG_3037.jpg?1647463326)

![circuitpython_IMG_3038.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/755/medium640/circuitpython_IMG_3038.jpg?1647463352)

![circuitpython_IMG_3039.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/756/medium640/circuitpython_IMG_3039.jpg?1647463362)

![circuitpython_IMG_3042.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/757/medium640/circuitpython_IMG_3042.jpg?1647463386)

Solder the leads that you just tinned onto the FeatherWing Proto. Solder the red wire to 3V, the black wire to GND, and the white wire to A0. Connect the JST wire to the STEMMA speaker.

![circuitpython_IMG_3043.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/758/medium640/circuitpython_IMG_3043.jpg?1647464355)

![circuitpython_IMG_3044.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/759/medium640/circuitpython_IMG_3044.jpg?1647464369)

![projects_IMG_3052.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/992/medium640/projects_IMG_3052.jpg?1647970220)

Cut, strip, and tin 3 equal lengths of different colored wire. Here I'm using the red wire for power, the black wire for ground, and the yellow wire for data. Solder the red wire to the pad marked +, the black wire to the pad marked -, and the yellow wire to the pad marked with an arrow pointing towards the LED.

![circuitpython_IMG_3045.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/760/medium640/circuitpython_IMG_3045.jpg?1647464395)

Solder the red wire to 3V, the black wire to GND, and the yellow wire to A1.

Before doing this you may want to put some heat-shrink around the 3 wires to make them a bit neater.

![circuitpython_IMG_3046.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/761/medium640/circuitpython_IMG_3046.jpg?1647464512)

![circuitpython_IMG_3049.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/762/medium640/circuitpython_IMG_3049.jpg?1647464570)

Now, cut, strip, and tin the wires from the NeoPixels.&nbsp;

![circuitpython_IMG_3074.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/956/medium640/circuitpython_IMG_3074.jpg?1647922692)

![circuitpython_IMG_3077.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/958/medium640/circuitpython_IMG_3077.jpg?1647922723)

![circuitpython_IMG_3080.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/959/medium640/circuitpython_IMG_3080.jpg?1647922739)

Solder the red wire to 3V, the middle wire to A2, and the outer wire to GND.

![circuitpython_IMG_3084.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/960/medium640/circuitpython_IMG_3084.jpg?1647922779)

Cut the excess bits of wire from the underside of the proto-board.

![circuitpython_IMG_3048.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/763/medium640/circuitpython_IMG_3048.jpg?1647464615)

Attach the battery to the empty JST jack on the LC709203 and plug the unconnected STEMMA cable and 2-pin JST from the LC709203 into the feather. Don't forget to put the proto FeatherWing back on it.

![circuitpython_IMG_3117.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/962/medium640/circuitpython_IMG_3117.jpg?1647923372)

![circuitpython_IMG_3051.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/963/medium640/circuitpython_IMG_3051.jpg?1647923424)

# Blahaj Alarm and Lamp

## Code the Blahaj

Download a zip of the project by clicking **Download Project Bundle** &nbsp;below.

After unzipping the file, you'll need to edit&nbsp; **code.py**. I'll explain the edits that need to be made below.

Before you do that though, you should copy the required libraries over:

- **adafruit\_bus\_device**
- **adafruit\_register**
- **adafruit\_lc709203f.mpy**
- **adafruit\_pcf8523.mpy**
- **adafruit\_pixelbuf.mpy**
- **neopixel.mpy**
- **simpleio.mpy**
- **adafruit\_led\_animation**

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/blahaj/code.py

## Setting the time
Set all the variables circled below to the current date and time.

![](https://cdn-learn.adafruit.com/assets/assets/000/109/776/medium800/circuitpython_Screenshot_2022-03-16_18-30-56.png?1647469983)

Now that you have the time set in the code, copy **cody.py**** &nbsp; **to the&nbsp;** CIRCUITPY** drive which appears in your operating system File Explorer or Finder when the Feather is connected to your computer via a USB cable that is known to work for data transfer.

You'll now want to set the&nbsp;`SET_DATE` variable to `False` and copy it over to the **CIRCUITPY** drive again.

![circuitpython_Screenshot_2022-03-16_18-34-39.png](https://cdn-learn.adafruit.com/assets/assets/000/109/777/medium640/circuitpython_Screenshot_2022-03-16_18-34-39.png?1647470161)

After you've copied all that over, your&nbsp; **CIRCUITPY&nbsp;** drive should look something like this:

![CIRCUITPY](https://adafruit.github.io/Adafruit_Learning_System_Guides/blahaj.png)

## Code run-through

In this section I'll go through how the code works and what does what. I'd recommend reading this if you're planning on modifying the code but it's also very useful to read since part of this project involves setting the time and day for your alarms to go off.

First, the code makes the required imports.

```python
import time

import board
from adafruit_lc709203f import LC709203F
import adafruit_pcf8523
from simpleio import tone
import neopixel
from adafruit_led_animation.animation.rainbow import Rainbow
```

Next, the code sets up the RTC, the LiPo charge indicator, the LED indicator, and the LED strip.

```python
rtc = adafruit_pcf8523.PCF8523(board.I2C())
battery = LC709203F(board.I2C())
indicator = neopixel.NeoPixel(board.A1, 1)

LEDs = neopixel.NeoPixel(board.A2, 20)
LEDs.fill((0, 0, 0))
rainbow = Rainbow(LEDs, speed=0.1, period=2)
```

This next section is where the alarms are defined. The list titled&nbsp;`days` is used to make printing the day easier and shouldn't be changed.

The dictionary titled `sleep` is intended to be used as a reminder for the evening, and the dictionary titled `wake` is intended to be used as a reminder in the morning.

You set the alarm by setting it as a tuple in the value of the dict item. The key (0, 1, 2, etc.) denotes the day, with 0 being Sunday. The first item in the tuple is the hour, and the second item is the minute.

If you don't want an alarm to ring on that day, set the value of the dict item for that day to&nbsp;`None`.

![circuitpython_Screenshot_2022-03-16_18-13-27.png](https://cdn-learn.adafruit.com/assets/assets/000/109/775/medium640/circuitpython_Screenshot_2022-03-16_18-13-27.png?1647469131)

```auto
days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
sleep = {
    0: (22, 50),
    1: (22, 50),
    2: (22, 50),
    3: (22, 50),
    4: (22, 50),
    5: None,
    6: None,
}
wake = {
    0: (11, 30),
    1: (9, 50),
    2: (9, 50),
    3: (9, 50),
    4: (9, 50),
    5: (9, 50),
    6: (11, 30),
}
```

Next, the BPM that the alarm sound will play in is set and the alarm itself is set as well. Each tuple in the list is a note. The first item in the tuple is the frequency, and the second item is the duration, in beats. If you'd like to change this, one website I found very handy was [this tone generator](https://www.szynalski.com/tone-generator/). It has a list of notes and their frequencies if you click the box next to the music note.

```python
BPM = 160

ringtone = [
    (330, 0.5),
    (294, 0.5),
    (185, 1),
    (208, 1),
    (277, 0.5),
    (247, 0.5),
    (147, 1),
    (165, 1),
    (247, 0.5),
    (220, 0.5),
    (139, 1),
    (165, 1),
    (220, 2),
]
```

This next section sets up the RTC. The first time you run the code, make sure to edit all the values (`YEAR`,&nbsp;`MONTH`, etc.) to the current date and time. After you first copy this over to the RP2040, you'll want to set&nbsp;`SET_DATE` to&nbsp;`False` and copy it over again. This ensures that the RTC won't get incorrectly set accidentally.

```python
SET_DATE = True
if SET_DATE:
    # Make sure to set this to the current date and time before using
    YEAR = 2022
    MONTH = 3
    DAY = 10
    HOUR = 22
    MINUTE = 49
    SEC = 55
    WDAY = 0  # 0 Sunday, 1 Monday, etc.
    t = time.struct_time((YEAR, MONTH, DAY, HOUR, MINUTE, SEC, WDAY, -1, -1))

    print("Setting time to:", t)  # uncomment for debugging
    rtc.datetime = t
    print()
```

The code then sets a few variables and enters the main loop. First, the code updates the animation if that is set to be always on, then checks if enough time has passed to run the alarm logic again. If it has, the code gets the datetime from the RTC and the battery percentage from the LiPo meter. It then sets the color of the indicator LED to a gradient between red and green (full red being 0%, and full green being 100%).&nbsp;

If the battery is below 15%, the indicator LED will flash on and off.

```auto
on_always = True  # Set to False for animation only to be on when alarm rings

indicate = True

start = time.monotonic()
wait = 1

while True:
    if on_always:
        rainbow.animate()
    if time.monotonic() - start &gt; wait:
        start = time.monotonic()
        wait = 1
        t = rtc.datetime
        bat = min(max(int(battery.cell_percent), 0), 100)

        g = int((bat / 100) * 255)
        r = int((1 - (bat / 100)) * 255)
        if bat &gt;= 15:
            indicator.fill([r, g, 0])

        if bat &lt; 15:
            if indicate:
                indicator.fill([0, 0, 0])
                indicate = False
            else:
                indicator.fill([r, g, 0])
                indicate = True
```

For the second part of the main loop, the code prints a bunch of information that's useful for when you're connected to the RP2040 from a serial console and sets two variables that are the alarm times in the&nbsp;`sleep` and&nbsp;`wake` lists.

```auto
⠀   print(f"The date is {days[t.tm_wday]} {t.tm_mday}/{t.tm_mon}/{t.tm_year}")
	print(f"The time is {t.tm_hour}:{t.tm_min}:{t.tm_sec}")
	print(f"Battery: {bat}%")

	night = sleep[t.tm_wday]
	morning = wake[t.tm_wday]
```

The code then checks each of the two variables defined above to see if the user wants an alarm to be rung today. If so it then checks to see if it's time to ring that alarm. If it is, it plays the notes from the alarm sound and waits 60 seconds to ensure the alarm doesn't go off for the entire minute.

The code then waits for a second and runs the loop again.

```python
⠀       if night:
            if night[0] == t.tm_hour and night[1] == t.tm_min:
                for i in ringtone:
                    print(i[0])
                    tone(board.A0, i[0], i[1] * (60 / BPM))
                wait = 60
                if not on_always:
                    while time.monotonic() - start &lt; 5:
                        rainbow.animate()
                    rainbow.fill([0, 0, 0])

        if morning:
            if morning[0] == t.tm_hour and morning[1] == t.tm_min:
                for i in ringtone:
                    print(i[0])
                    tone(board.A0, i[0], i[1] * (60 / BPM))
                wait = 60
                if not on_always:
                    while time.monotonic() - start &lt; 5:
                        rainbow.animate()
                    rainbow.fill([0, 0, 0])
```

# Blahaj Alarm and Lamp

## Assemble the Blahaj

Take your seam-rippers and cut a hole in the fin. large enough to fit your hand in comfortably.&nbsp;

![circuitpython_IMG_3091.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/946/medium640/circuitpython_IMG_3091.jpg?1647922115)

Take the cotton out of the fin so it'll be easier to sew the velcro in and insert the electronics.

![circuitpython_IMG_3093.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/950/medium640/circuitpython_IMG_3093.jpg?1647922266)

Cut two lengths of velcro long enough to fill the hole you just created. Sew the velcro into the hole.

![circuitpython_IMG_3092.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/947/medium640/circuitpython_IMG_3092.jpg?1647922216)

![circuitpython_IMG_3094.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/948/medium640/circuitpython_IMG_3094.jpg?1647922231)

![circuitpython_IMG_3096.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/949/medium640/circuitpython_IMG_3096.jpg?1647922241)

Start to insert the LEDs. At this point it wouldn't be a bad idea to connect the battery and set the code to the mode where the LED animation is always on so you can see what the LEDs look like in the Blahaj.

![circuitpython_IMG_3097.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/951/medium640/circuitpython_IMG_3097.jpg?1647922315)

Insert the rest of the electronics and put the indicator LED somewhere it is easily visible through the fabric.

![circuitpython_IMG_3100.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/953/medium640/circuitpython_IMG_3100.jpg?1647922441)

![circuitpython_IMG_3099.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/955/medium640/circuitpython_IMG_3099.jpg?1647922484)

Seal the blahaj up with the velcro and it should be good to go!

![circuitpython_IMG_3102.jpg](https://cdn-learn.adafruit.com/assets/assets/000/109/966/medium640/circuitpython_IMG_3102.jpg?1647923589)

![](https://cdn-learn.adafruit.com/assets/assets/000/109/969/medium800thumb/circuitpython_ezgif.com-gif-maker.jpg?1647924583)


## Featured Products

### Adafruit Feather RP2040

[Adafruit Feather RP2040](https://www.adafruit.com/product/4884)
A new chip means a new Feather, and the Raspberry Pi RP2040 is no exception. When we saw this chip we thought "this chip is going to be awesome when we give it the Feather Treatment" and so we did! This Feather features the&nbsp; **RP2040** , and all niceties you know and...

In Stock
[Buy Now](https://www.adafruit.com/product/4884)
[Related Guides to the Product](https://learn.adafruit.com/products/4884/guides)
### FeatherWing Proto - Prototyping Add-on For All Feather Boards

[FeatherWing Proto - Prototyping Add-on For All Feather Boards](https://www.adafruit.com/product/2884)
A Feather board without ambition is a Feather board without FeatherWings!

This is the **FeatherWing Proto** - a prototyping add-on for all Feather boards. Using our [Feather Stacking Headers](https://www.adafruit.com/products/2830) or <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/2884)
[Related Guides to the Product](https://learn.adafruit.com/products/2884/guides)
### Stacking Headers for Feather - 12-pin and 16-pin female headers

[Stacking Headers for Feather - 12-pin and 16-pin female headers](https://www.adafruit.com/product/2830)
These two **Female Stacking Headers** alone are, well, lonely. But pair them with any of our [Feather](https://www.adafruit.com/categories/777) boards and you're in business!

What do they do? They stack. Put the headers through your Feather and then you can...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2830)
[Related Guides to the Product](https://learn.adafruit.com/products/2830/guides)
### Adafruit STEMMA Speaker - Plug and Play Audio Amplifier

[Adafruit STEMMA Speaker - Plug and Play Audio Amplifier](https://www.adafruit.com/product/3885)
Hey, have you heard the good news? With Adafruit STEMMA boards you can easily and safely plug sensors and devices together, like this **Adafruit STEMMA Speaker - Plug and Play Audio Amplifier**. Like the name implies, it's got a class D audio amplifier on board, and our...

Out of Stock
[Buy Now](https://www.adafruit.com/product/3885)
[Related Guides to the Product](https://learn.adafruit.com/products/3885/guides)
### JST PH 2mm 3-pin Plug to Color Coded Alligator Clips Cable

[JST PH 2mm 3-pin Plug to Color Coded Alligator Clips Cable](https://www.adafruit.com/product/4030)
This cable will let you turn a JST PH 3-pin cable port into 3 individual wires with grippy mini alligator clips. We're carrying these to match up with any of our boards or breakouts with 3-pin 'STEMMA' connectors on them such as the&nbsp;<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/4030)
[Related Guides to the Product](https://learn.adafruit.com/products/4030/guides)
### Adafruit PCF8523 Real Time Clock Breakout Board

[Adafruit PCF8523 Real Time Clock Breakout Board](https://www.adafruit.com/product/5189)
This is a great battery-backed real time clock (RTC) that allows your microcontroller project to keep track of time even if it is reprogrammed, or if the power is lost. Perfect for data-logging, clock-building, time stamping, timers, and alarms, etc. Equipped...

In Stock
[Buy Now](https://www.adafruit.com/product/5189)
[Related Guides to the Product](https://learn.adafruit.com/products/5189/guides)
### CR1220 12mm Diameter - 3V Lithium Coin Cell Battery

[CR1220 12mm Diameter - 3V Lithium Coin Cell Battery](https://www.adafruit.com/product/380)
These are the highest quality & capacity batteries, the same as shipped with the iCufflinks,&nbsp;iNecklace, Datalogging and GPS Shields, GPS HAT, etc. One battery per order (you'll want one battery per cufflink or pendant.)  
  
Brand may vary but all battery brands are verified...

In Stock
[Buy Now](https://www.adafruit.com/product/380)
[Related Guides to the Product](https://learn.adafruit.com/products/380/guides)
### Flora RGB Smart NeoPixel version 3 - Pack of 4

[Flora RGB Smart NeoPixel version 3 - Pack of 4](https://www.adafruit.com/product/1260)
What's a wearable project without LEDs? Our favorite part of the Flora platform is these tiny smart pixels. Designed specifically for wearables, these updated Flora NeoPixels have ultra-cool technology: these ultra-bright LEDs have a constant-current driver cooked right into the LED...

In Stock
[Buy Now](https://www.adafruit.com/product/1260)
[Related Guides to the Product](https://learn.adafruit.com/products/1260/guides)

## Related Guides

- [Adafruit STEMMA Speaker](https://learn.adafruit.com/adafruit-stemma-speaker.md)
- [Adafruit LC709203F LiPoly / LiIon Fuel Gauge and Battery Monitor](https://learn.adafruit.com/adafruit-lc709203f-lipo-lipoly-battery-monitor.md)
- [Introducing Adafruit Feather RP2040](https://learn.adafruit.com/adafruit-feather-rp2040-pico.md)
- [NeoTrellis MIDI Feedback Controller](https://learn.adafruit.com/neotrellis-midi-feedback-controller.md)
- [Flying Faders](https://learn.adafruit.com/flying-faders.md)
- [FFT: Fun with Fourier Transforms](https://learn.adafruit.com/fft-fun-with-fourier-transforms.md)
- [Feather Freezer Door Alarm](https://learn.adafruit.com/feather-door-alarm.md)
- [BLE Synth with the Feather nRF52840 and Circuit Playground Bluefruit](https://learn.adafruit.com/ble-synth-with-the-feather-nrf52840-and-circuit-playground-bluefruit.md)
- [Motorized POV LED Display](https://learn.adafruit.com/motorized-pov-led-display.md)
- [Adafruit NeoPixel Überguide](https://learn.adafruit.com/adafruit-neopixel-uberguide.md)
- [Mini GIF Players](https://learn.adafruit.com/mini-gif-players.md)
- [Digital Clock with CircuitPython](https://learn.adafruit.com/digital-clock-with-circuitpython.md)
- [Circuit Playground Bluefruit Pumpkin with Lights and Sounds ](https://learn.adafruit.com/pumpkin-with-circuit-playground-bluefruit.md)
- [RPi Stock Alert Alarm](https://learn.adafruit.com/rpi-stock-alert-alarm.md)
- [PianoGlove](https://learn.adafruit.com/pianoglove.md)
- [3D Printed Frame for Adafruit IS31FL3741 LED Glasses](https://learn.adafruit.com/3d-printed-frame-for-led-glasses-is31fl3741.md)
