# HalloWing Magic 9 Ball

## Overview

https://youtu.be/6yjc_LfplKk

Making difficult decisions can be tricky and stressful. This project will help you take off some of the pressure, instead letting your HalloWing-based Magic 9 Ball do the heavy lifting of your decision making!

By harnessing the HalloWing's accelerometer to detect when the ball is turned upside down and right side up (or shaken), we'll then run a highly mysterious algorithm (OK, it's just a random number generator, sorry) to choose an image file to show on the TFT display.

A stylish housing filled with swirly mystery fluid completes the effect. Will you love building this project?

INDICATIONS SAY YES

### Part: Adafruit HalloWing M0 Express
quantity: 1
Skull-shaped ATSAMD21 board w 1.44" 128x128 TFT display
[Adafruit HalloWing M0 Express](https://www.adafruit.com/product/3900)

### Part: Lithium Ion Polymer Battery
quantity: 1
3.7v 500mAh
[Lithium Ion Polymer Battery](https://www.adafruit.com/product/1578)

### Part: DIY Snow Globe Kit
quantity: 1
108mm Diameter
[DIY Snow Globe Kit](https://www.adafruit.com/product/3722)

### Part: Black Nylon Screw and Stand-off Set
quantity: 1
M2.5 Thread
[Black Nylon Screw and Stand-off Set](https://www.adafruit.com/product/3299)

## Materials & Tools

In addition to the above parts, you will want the following:

- Food dye
- Water
- Glycerin (optional)
- Super Pearl Dust (used in baking to add shimmer, [thanks to Epbot for the tip](http://www.epbot.com/2016/10/diy-pensieve-punch-glowing-shimmering.html)!)
- E6000 glue (optional)
- Double stick foam tape
- Optional: 3D printed cap, mounting plate, and HalloWing case (if you don't have a 3D printer, you can send the files to be printed, or simply double-stick tape your HalloWing to the regular snow globe cap)

# HalloWing Magic 9 Ball

## Build the Magic 9 Ball

![](https://cdn-learn.adafruit.com/assets/assets/000/062/247/medium800/sensors_IMG_5011_2k.jpg?1537501563)

## Mix the Mystery Fluid

The Magic 9 Ball derives much of its power from the mysterious roiling fluid contained within the orb. Here, for the very first time, we shall reveal the secrets of the unfathomable fluid!

![](https://cdn-learn.adafruit.com/assets/assets/000/062/248/medium800/sensors_IMG_4913_2k.jpg?1537501658)

Get ready for the secrets to be revealed! -- We'll mix water with super pearl dust (also called shimmer dust), food coloring, and optional glycerin. The dye gives the mix its color, while the pearl dust provides the moving, glittering view into the complex fluid dynamics going on in there while it is thinking.

Add a very small amount of the pearl dust to the empty globe.

&nbsp;

Fill halfway with water, then add dye and swirl it around. I used five drops of yellow to two drops of red here.

&nbsp;

Fill the rest of the way with water, up to the level of the stopper cap.

&nbsp;

Press the stopper cap into place. You can glue this in with silicone sealant or E6000 glue if you like, for extra safety.

![sensors_IMG_4920_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/062/249/medium640/sensors_IMG_4920_2k.jpg?1537501976)

![sensors_IMG_4921_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/062/250/medium640/sensors_IMG_4921_2k.jpg?1537501988)

![sensors_IMG_4922_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/062/251/medium640/sensors_IMG_4922_2k.jpg?1537501996)

![sensors_IMG_4925_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/062/252/medium640/sensors_IMG_4925_2k.jpg?1537502014)

![sensors_IMG_4928_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/062/253/medium640/sensors_IMG_4928_2k.jpg?1537502022)

![sensors_IMG_4939_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/062/254/medium640/sensors_IMG_4939_2k.jpg?1537502043)

This is a fun time to test it out -- screw on the original cap and swirl the orb to see the intricate fluid motion!

![](https://cdn-learn.adafruit.com/assets/assets/000/062/257/medium800/sensors_IMG_4942_2k.jpg?1537506247)

## HalloWing Prep
![](https://cdn-learn.adafruit.com/assets/assets/000/062/269/medium800/sensors_IMG_4948_2k.jpg?1537507831)

The HalloWing will be the brains and display of our Magic 9 Ball.

## Ready the Battery

&nbsp;

Plug your Lipoly battery's JST plug into the battery port on the HalloWing.

&nbsp;

Use double-stick foam tape to affix the battery to the board as shown.

![sensors_IMG_4949_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/062/261/medium640/sensors_IMG_4949_2k.jpg?1537507715)

![sensors_IMG_4950_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/062/262/medium640/sensors_IMG_4950_2k.jpg?1537507723)

![sensors_IMG_4951_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/062/263/medium640/sensors_IMG_4951_2k.jpg?1537507738)

![sensors_IMG_4952_2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/062/264/medium640/sensors_IMG_4952_2k.jpg?1537507797)

## Prepare the Cap and Mount
![](https://cdn-learn.adafruit.com/assets/assets/000/062/272/medium800/sensors_IMG_4968_2k.jpg?1537508163)

The cap, spacer and mount are all 3D printed. I modified these parts that were created by the Ruiz Bros. More info on the [HalloWing M0 Express Wearable Case here](https://www.thingiverse.com/thing:3108276), and the threaded ring came from their excellent [Automatic Dice Roller project](https://learn.adafruit.com/automatic-dice-roller/3d-printing).

Below are the model files you'll need. These were printed in PLA plastic with 0.2mm layer height.

[nine_ball_models.zip](https://cdn-learn.adafruit.com/assets/assets/000/062/273/original/nine_ball_models.zip?1537508374)
You'll also need two 10mm long M2.5 nylon screws and nuts to affix the HalloWing case bottom to the spacer.

## Assemble

Snap the HalloWing into place in the bottom mount, then place the spacer into the cap as shown.

Screw the mount into place, thread on the nuts and tighten them. Then trim the screws flush with diagonal cutters. This prevents the screws from interfering with the fluid cap.

![](https://cdn-learn.adafruit.com/assets/assets/000/062/306/medium800/sensors_IMG_4989_2k.jpg?1537510446)

## Screw Cap onto Globe

Now, we can screw the cap onto the globe -- just make sure the stopper is securely in place!

Finally, snap the HalloWing case cover into place.

![](https://cdn-learn.adafruit.com/assets/assets/000/062/310/medium800/sensors_IMG_4997_2k.jpg?1537512139)

Plug in a USB cable and next we'll program it!

![](https://cdn-learn.adafruit.com/assets/assets/000/062/324/medium800/sensors_IMG_5019_2k.jpg?1537512235)

# HalloWing Magic 9 Ball

## Code with CircuitPython

## Image Player Firmware

This project requires CircuitPython version 4.0 or higher. Refer to the [HalloWing CircuitPython page](https://learn.adafruit.com/adafruit-hallowing/circuitpython) for ensuring you upload the HalloWing version of CircuitPython 4.0 or greater.

To load the CircuitPython firmware, plug in the HalloWing over a known good USB cable to your computer and then double-click the reset button on the HalloWing. This will put it into bootloader mode, allowing you to change the firmware. You'll see a USB drive appear called **HALLOWBOOT.**

Drag the .uf2 file you downloaded onto the **HALLOWBOOT** drive. Once it copies over, it will automatically restart and show a flash drive named **CIRCUITPY**. Then you are ready to load a CircuitPython program that can take advantage of the display capabilities.

[Download the latest version of CircuitPython for this board via CircuitPython.org](https://circuitpython.org/board/hallowing_m0_express/)
## File Format

To prepare your graphics for the HalloWing, you'll need to size them to 128 x 128 pixels. You can do this in nearly any graphics program, such as Photoshop, GIMP, Preview on osx, ImageMagik, MS Paint, you name it!

Save your file as a 24-bit .bmp file. Here you can see some example graphics.

Here is the full set of answers for your Magic 9 Ball. Download the file and then unzip it.

Drag the .bmp files onto your **CIRCUITPY** drive as shown.

[nine_ball_answers.zip](https://cdn-learn.adafruit.com/assets/assets/000/062/680/original/nine_ball_answers.zip?1538157010)
![](https://cdn-learn.adafruit.com/assets/assets/000/062/332/medium800/sensors_drag.jpg?1537543689)

Info: 

## Magic 9 Ball Code

This program is pretty simple in what it does -- it loads a random image onto the screen using `displayio.TileGrid` while fading the backlight up with&nbsp; `board.DISPLAY.brightness`

Then, whenever the HalloWing's accelerometer detects the board has been turned upside down or shaken, it dims the backlight, selects and displays a new image, and brings the backlight up again.

Adafruit really likes using the Mu editor to edit the CircuitPython code.&nbsp;[See this guide on loading and using Mu](https://learn.adafruit.com/welcome-to-circuitpython/installing-mu-editor).

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

Copy the code and then paste it into Mu. Save the file to your **CIRCUITPY** board as **code.py**.

The board will restart and then play an image. Try turning the Magic 9 Ball upside down and then back up -- you'll see a new image appear!

## Answer Any Question

You can now unplug the USB cable (plug it back in any time to charge the battery) and use the Magic 9 Ball!

Ask it a yes or no question, such as "Have we reached the mother ship yet?", then turn the ball over (or give it a shake), then turn it right side up and the answer will present itself in all of its wisdom!

![](https://cdn-learn.adafruit.com/assets/assets/000/062/329/medium800/sensors_IMG_5007_2k.jpg?1537513174)

![](https://cdn-learn.adafruit.com/assets/assets/000/062/330/medium800/sensors_IMG_5004_2k.jpg?1537513185)

![](https://cdn-learn.adafruit.com/assets/assets/000/062/331/medium800/sensors_IMG_5011_2k.jpg?1537513201)

https://youtu.be/6yjc_LfplKk

# HalloWing Magic 9 Ball

## Microcontroller Selection Oracle

![](https://cdn-learn.adafruit.com/assets/assets/000/062/361/medium800/sensors_oracle.jpg?1537557684)

Here's another interesting use of the Magic 9 Ball code -- you can create a random microcontroller selector for all those times you just aren't sure which amazing CircuitPython-capable Adafruit board to get from [Digi-Key, who are going all-in on CircuitPython](https://www.digikey.com/en/maker/blogs/2018/python-on-hardware?utm_source=online&utm_medium=vanity&utm_campaign=python)!

This will display a randomly selected board and show the product name, image, and Digi-Key product number!

Simply load these images linked below onto the board (you can place the Magic 9 Ball images into a folder you make on the HalloWing and they won't be selected for viewing).

[dk_quest.zip](https://cdn-learn.adafruit.com/assets/assets/000/062/362/original/dk_quest.zip?1537557910)
![](https://cdn-learn.adafruit.com/assets/assets/000/062/369/medium800/sensors_feather_m0_express.bmp?1537558051)

This is just an example we created for our friends at Digi-Key, but we hope it also serves as a leaping off point for you to come up with your own creative uses for the image randomization of the Magic 9 Ball!


## Featured Products

### Adafruit HalloWing M0 Express

[Adafruit HalloWing M0 Express](https://www.adafruit.com/product/3900)
[This is Hallowing..this is Hallowing... Hallowing! Hallowing!&nbsp;](https://www.youtube.com/watch?v=kGiYxCUAhks&t=39s)

Are you the kind of person who doesn't like taking down the skeletons and spiders until after January? Well, we've got the development board for...

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

[AdaBox009 - HalloWing](https://www.adafruit.com/product/3956)
Are you the kind of person who doesn't like taking down the skeletons and spiders until after January? Well, we've got the ADABOX for you. This is electronics at its&nbsp;_most spooky!_&nbsp;ADABOX 009 is Halloween themed, for all of us who love scares, costumes,&nbsp;and (of...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/3956)
[Related Guides to the Product](https://learn.adafruit.com/products/3956/guides)
### Lithium Ion Polymer Battery - 3.7V 350mAh

[Lithium Ion Polymer Battery - 3.7V 350mAh](https://www.adafruit.com/product/2750)
Lithium-ion polymer (also known as 'lipo' or 'lipoly') batteries are thin, light, and powerful. The output ranges from 4.2V when completely charged to 3.7V. This battery has a capacity of 350mAh for a total of about 1.3 Wh. If you need a larger (or smaller!) battery, <a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/2750)
[Related Guides to the Product](https://learn.adafruit.com/products/2750/guides)
### DIY Snow Globe Kit

[DIY Snow Globe Kit](https://www.adafruit.com/product/3722)
Not merely a snow globe, but a _show_ globe! This custom container is durable, clear and round, with a large flat screw-on top and a press-fit rubber stopper. The stopper makes a nice seal, and is also _hollow_ which means you can put (you guessed it...) electronics inside! This...

In Stock
[Buy Now](https://www.adafruit.com/product/3722)
[Related Guides to the Product](https://learn.adafruit.com/products/3722/guides)
### Black Nylon Machine Screw and Stand-off Set – M2.5 Thread

[Black Nylon Machine Screw and Stand-off Set – M2.5 Thread](https://www.adafruit.com/product/3299)
Totaling 380 pieces, this **M2.5 Screw Set** &nbsp;is a must-have for your workstation.&nbsp;You'll have enough screws, nuts, and hex standoffs to fuel your maker tendencies&nbsp;for days on end! M2.5 size screws fit almost all of the Adafruit breakout/dev board mounting holes...

In Stock
[Buy Now](https://www.adafruit.com/product/3299)
[Related Guides to the Product](https://learn.adafruit.com/products/3299/guides)
### PLA Filament for 3D Printers - 2.85mm Diameter - Black - 1.0Kg

[PLA Filament for 3D Printers - 2.85mm Diameter - Black - 1.0Kg](https://www.adafruit.com/product/3751)
_“Black is modest and arrogant at the same time. Black is lazy and easy – but mysterious. But above all black says this: 'I don’t bother you – don’t bother me'.” –_&nbsp;Yohji Yamamoto

Having a 3D printer without filament is sort...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/3751)
[Related Guides to the Product](https://learn.adafruit.com/products/3751/guides)
### PLA Filament for 3D Printers - 2.85mm Diameter - Lilac - 1 Kg

[PLA Filament for 3D Printers - 2.85mm Diameter - Lilac - 1 Kg](https://www.adafruit.com/product/3733)
Having a 3D printer without filament is sort of like having a regular printer without paper or ink. And while a lot of printers come with some filament there's a good chance you've been printing up a storm and want something new. &nbsp;That's why we&nbsp;carry 3D printing...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/3733)
[Related Guides to the Product](https://learn.adafruit.com/products/3733/guides)

## Related Guides

- [Adafruit Hallowing M0](https://learn.adafruit.com/adafruit-hallowing.md)
- [32x32 Square Pixel Art Animation Display](https://learn.adafruit.com/32x32-square-pixel-display.md)
- [HalloWing Light Paintstick](https://learn.adafruit.com/hallowing-light-paintstick.md)
- [MP3 Playback in CircuitPython with Lars the Sloth Puppet](https://learn.adafruit.com/mp3-circuitpython-lars.md)
- [Computer Space Mini Arcade](https://learn.adafruit.com/computer-space-mini-arcade.md)
- [USB to Eurorack Power Supply](https://learn.adafruit.com/usb-to-eurorack-power-supply.md)
- [Walkmp3rson: Personal MP3 'Tape' Player](https://learn.adafruit.com/walkmp3rson-personal-mp3-tape-player.md)
- [Planetary Gear Dreidels](https://learn.adafruit.com/planetary-gear-dreidels.md)
- [Personal and Portable ESP32-S2 Web Server](https://learn.adafruit.com/wordle-personal-esp32-s2-web-server.md)
- [CircuitPython Trombone Champ Controller](https://learn.adafruit.com/circuitpython-trombone-champ-controller.md)
- [The Great Seal Mask](https://learn.adafruit.com/the-great-seal-mask.md)
- [Adabot Operation Game](https://learn.adafruit.com/adabot-operation-game.md)
- [Light Up Prop with Prop-Maker](https://learn.adafruit.com/prop-maker-light-wand.md)
- [3D Printed Case for Adafruit Feather](https://learn.adafruit.com/3d-printed-case-for-adafruit-feather.md)
- [Feather Scorpio Snap Fit Case](https://learn.adafruit.com/feather-scorpio-snap-fit-case.md)
- [HalloWing Flapping Bat](https://learn.adafruit.com/hallowing-flapping-bat.md)
