# Solderless Robot Toy Xylophone

## Overview

https://youtube.com/shorts/vjC2v32BPyQ

Robot instrument builds are always fun, but the wiring can be cumbersome. However, this robot friend, built around a toy piano xylophone, requires zero soldering. It runs CircuitPython code on a Metro RP2350 with an I2C to 8 Channel Solenoid Driver breakout connected with a STEMMA QT cable. The 8 solenoids screw into the breakout terminal blocks.

The xylophone has two modes: live MIDI and music box. For live MIDI, it can listen to incoming MIDI messages over USB. For music box mode, it can playback MIDI files (.mid) on the **CIRCUITPY** drive.

![top view of the xylophone](https://cdn-learn.adafruit.com/assets/assets/000/136/985/medium640/robotics___cnc_edited_P1470770.jpg?1747763834)

3D printed parts help to position the solenoids so that they are perfectly centered above the keys and have enough height to strike the keys. The entire assembly slides over the xylophone so it can return to its non-robotic form easily.

![close up of the solenoids positioned over the keys](https://cdn-learn.adafruit.com/assets/assets/000/136/986/medium640/robotics___cnc_edited_P1470776.jpg?1747764428)

Warning: The solenoids require 12V. For this project to work, you will need to provide 12V via the Metro RP2350 DC jack. This is detailed in the Circuit Diagram.

## Toy Piano Xylophone
This [toy piano xylophone](https://www.amazon.com/dp/B08XB6LCT9) was used for this project. It seems to be a popular white label product at the time of writing, so it should hopefully be available for quite some time.

![the toy xylophone](https://cdn-learn.adafruit.com/assets/assets/000/136/943/medium640/robotics___cnc_edited_P1470651.jpg?1747749442)

## Parts
### Adafruit Metro RP2350

[Adafruit Metro RP2350](https://www.adafruit.com/product/6003)
Choo! Choo! This is the RP2350 Metro Line, making all station stops at "Dual Cortex M33 mountain", "528K RAM round-about" and "16 Megabytes of Flash town". This train is piled high with hardware that complements the Raspberry Pi RP2350 chip to make it an excellent...

In Stock
[Buy Now](https://www.adafruit.com/product/6003)
[Related Guides to the Product](https://learn.adafruit.com/products/6003/guides)
![Angled shot of black, credit card-sized microcontroller with stacking headers.](https://cdn-shop.adafruit.com/640x480/6003-06.jpg)

### Adafruit I2C to 8 Channel Solenoid Driver

[Adafruit I2C to 8 Channel Solenoid Driver](https://www.adafruit.com/product/6318)
Solenoids are a little like cats: if your project has one solenoid you'll probably stick with just one and in such cases our [single MOSFET driver will work well](https://www.adafruit.com/product/5648). But if you have more than one solenoid, it's going to be anywhere from 2...

In Stock
[Buy Now](https://www.adafruit.com/product/6318)
[Related Guides to the Product](https://learn.adafruit.com/products/6318/guides)
![Video of breakout board connected to eight solenoids, which pulse on and off.](https://cdn-shop.adafruit.com/product-videos/640x480/6318-05.jpg)

#### 8x Solenoids
### Small  Push-Pull Solenoid - 12VDC

[Small  Push-Pull Solenoid - 12VDC](https://www.adafruit.com/product/412)
Solenoids are basically electromagnets: they are made of a big coil of copper wire with an armature (a slug of metal) in the middle. When the coil is energized, the slug is pulled into the center of the coil. This makes the solenoid able to pull (from one end) or push (from the other)  
<br...></br...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/412)
[Related Guides to the Product](https://learn.adafruit.com/products/412/guides)
![Small  Push-Pull Solenoid](https://cdn-shop.adafruit.com/640x480/412-00.jpg)

### STEMMA QT / Qwiic JST SH 4-pin Cable - 100mm Long

[STEMMA QT / Qwiic JST SH 4-pin Cable - 100mm Long](https://www.adafruit.com/product/4210)
This 4-wire cable is a little over 100mm / 4" 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/4210)
[Related Guides to the Product](https://learn.adafruit.com/products/4210/guides)
![Angled shot of STEMMA QT / Qwiic JST SH 4-pin Cable.](https://cdn-shop.adafruit.com/640x480/4210-00.jpg)

### 12V 5A switching power supply

[12V 5A switching power supply](https://www.adafruit.com/product/352)
This is a beefy switching supply, for when you need a lot of power! It can supply 12V DC up to 5 Amps, running from 110V or 220V power (the plug it comes with is for US/Canada/Japan but you can use any plug adapter for your country, or just replace the cable with a standard 'figure-8'...

In Stock
[Buy Now](https://www.adafruit.com/product/352)
[Related Guides to the Product](https://learn.adafruit.com/products/352/guides)
![Power brick with coiled cables.](https://cdn-shop.adafruit.com/640x480/352-07.jpg)

### Premium Male/Male Jumper Wires - 40 x 6" (150mm)

[Premium Male/Male Jumper Wires - 40 x 6" (150mm)](https://www.adafruit.com/product/758)
Handy for making wire harnesses or jumpering between headers on PCB's. These premium jumper wires are 6" (150mm) long and come in a 'strip' of 40 (4 pieces of each of ten rainbow colors). They have 0.1" male header contacts on either end and fit cleanly next to each other...

Out of Stock
[Buy Now](https://www.adafruit.com/product/758)
[Related Guides to the Product](https://learn.adafruit.com/products/758/guides)
![Angled shot of Premium Male/Male Jumper Wires - 40 x 6 (150mm)](https://cdn-shop.adafruit.com/640x480/758-04.jpg)

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

### Part: M3 Thread Screws
quantity: 1
Black Nylon Machine Screw and Stand-off Set
[M3 Thread Screws](https://www.adafruit.com/product/4685)

### Part: USB A to C Cable
quantity: 1
2 meters long
[USB A to C Cable](https://www.adafruit.com/product/5044)

### Part: Small Screwdrivers
quantity: 1
Precision screwdriver set
[Small Screwdrivers](https://www.adafruit.com/product/424)

# Solderless Robot Toy Xylophone

## Circuit Diagram

![fritzing diagram for the project](https://cdn-learn.adafruit.com/assets/assets/000/136/753/medium800/robotics___cnc_toyXyloFritz_bb.jpg?1747058568 )

The breakout connects to the Metro RP2350 over I2C with a STEMMA QT cable. Each solenoid connects to the breakout with the screw block terminals. The solenoids are powered by 12V via **Vin** and **GND** on the Metro from the **DC jack input**.

- **Solenoid 0 positive** to **breakout + (red wire)**
- **Solenoid 0 negative** to **breakout 0 (black wire)**
- **Solenoid 1 positive** to **breakout + (red wire)**
- **Solenoid 1 negative** to **breakout 1 (black wire)**
- **Solenoid 2 positive** to **breakout + (red wire)**
- **Solenoid 2 negative** to **breakout 2 (black wire)**
- **Solenoid 3 positive** to **breakout + (red wire)**
- **Solenoid 3 negative** to **breakout 3 (black wire)**
- **Solenoid 4 positive** to **breakout + (red wire)**
- **Solenoid 4 negative** to **breakout 4 (black wire)**
- **Solenoid 5 positive** to **breakout + (red wire)**
- **Solenoid 5 negative** to **breakout 5 (black wire)**
- **Solenoid 6 positive** to **breakout + (red wire)**
- **Solenoid 6 negative** to **breakout 6 (black wire)**
- **Solenoid 7 positive** to **breakout + (red wire)**
- **Solenoid 7 negative** to **breakout 7 (black wire)**
- **Breakout STEMMA QT** to **Metro STEMMA QT**
- **Breakout terminal power +** to **Metro Vin (red wire)**
- **Breakout terminal power -** to **Metro GND (black wire)**
- **12V power supply** to **Metro DC In**

# Solderless Robot Toy Xylophone

## 3D Printing

![the 3d printed parts laid out](https://cdn-learn.adafruit.com/assets/assets/000/136/944/medium800/robotics___cnc_edied_P1470665.jpg?1747749853 )

You can 3D print all of the parts for this project. They are designed to fit over the keys on this [toy piano xylophone](https://www.amazon.com/dp/B08XB6LCT9), which at the time of writing appears to be a popular design available from multiple vendors.

The STL files can be downloaded directly here or from Printables.

[Printables Download](https://www.printables.com/model/1302184)
[toyRobotXylophoneCAD.zip](https://cdn-learn.adafruit.com/assets/assets/000/136/947/original/toyRobotXylophoneCAD.zip?1747750103)
Print two of the columns and then one each of the electronics mount, front solenoid mount and back solenoid mount. All of the parts print without supports.

The solenoid mounts are spaced to have the solenoid motors be centered over each key.

![the columns and rails over the piano](https://cdn-learn.adafruit.com/assets/assets/000/136/945/medium640/robotics___cnc_edited_P1470671.jpg?1747749889)

The Metro RP2350 and solenoid breakout have their own electronics mount that attaches to the front solenoid mount.

![the metro and breakout on the electronics mount](https://cdn-learn.adafruit.com/assets/assets/000/136/946/medium640/robotics___cnc_edited_P1470677.jpg?1747749940)

# Solderless Robot Toy Xylophone

## 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_metro_rp2350/)
 **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/135/292/medium800/adafruit_products_boot_reset_btn_highlights.png?1739467365)

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 RP2350 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 **RP2350**.

&nbsp;

Drag the **adafruit-circuitpython-_boardname_-_language_-_version_.uf2** file to **RP2350.**

![install_circuitpython_on_rp2350_Screenshot_2024-09-11_111518.png](https://cdn-learn.adafruit.com/assets/assets/000/132/253/medium640/install_circuitpython_on_rp2350_Screenshot_2024-09-11_111518.png?1726067809)

![install_circuitpython_on_rp2350_Screenshot_2024-09-11_111742.png](https://cdn-learn.adafruit.com/assets/assets/000/132/254/medium640/install_circuitpython_on_rp2350_Screenshot_2024-09-11_111742.png?1726067866)

The **RP2350** drive will disappear and a new disk drive called **CIRCUITPY** will appear.

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

![install_circuitpython_on_rp2350_Screenshot_2024-09-11_111843.png](https://cdn-learn.adafruit.com/assets/assets/000/132/255/medium640/install_circuitpython_on_rp2350_Screenshot_2024-09-11_111843.png?1726067932)

## 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 RP2350. 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 for RP2350](https://cdn-learn.adafruit.com/assets/assets/000/132/526/original/rp2350_flash_nuke.uf2)
# Solderless Robot Toy Xylophone

## Code the Xylophone

Once you've finished setting up your Metro RP2350 with CircuitPython, you can access the code, MIDI files and necessary libraries by downloading the Project Bundle.

To do this, click on the **Download Project Bundle** button in the window below. It will download to your computer as a zipped folder.

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

## Upload the Code and Libraries to the Metro RP2350

After downloading the Project Bundle, plug your Metro RP2350 into the computer's USB port with a known good USB data+power cable. You should see a new flash drive appear in the computer's File Explorer or Finder (depending on your operating system) called **CIRCUITPY**. Unzip the folder and copy the following items to the Metro RP2350's **CIRCUITPY** drive.

- **lib** folder
- **code.py**
- **song\_1.mid**
- **song\_2.mid**
- **song\_3.mid**
- **song\_4.mid**

Your Metro RP2350 **CIRCUITPY** drive should look like this after copying the **lib** folder, MIDI files and **code.py** file:

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

## How the Code Works

At the top of the code is the `music_box` variable. This determines the mode for the robot xylophone. If `music_box` is set to `True`, then it will playback MIDI files (.mid) files on the **CIRCUITPY** drive. If it is set to `False`, then it will act as a USB MIDI output device. The MIDI note numbers assigned to each solenoid are defined in the `notes` array.

```python
# music_box plays back MIDI files on CP drive
# set to false for live MIDI over USB control
music_box = True
# define the notes that correspond to each solenoid
notes = [48, 50, 52, 53, 55, 57, 59, 60]
```

### Button and I2C

The&nbsp; **BOOT** button is passed as a `keypad` button. Then, the MCP23017 is instantiated over I2C and the 8 solenoid pins are created and added to the `noids` array.

```python
key = keypad.Keys((board.BUTTON,), value_when_pressed=False, pull=True)

i2c = board.STEMMA_I2C()
mcp = MCP23017(i2c)
noids = []
for i in range(8):
    noid = mcp.get_pin(i)
    noid.switch_to_output(value=False)
    noids.append(noid)
```

### Live MIDI Mode

If&nbsp;`music_box` is `False`, then the Metro is setup as a USB MIDI device.

```python
if not music_box:
    midi = adafruit_midi.MIDI(
        midi_in=usb_midi.ports[0], in_channel=0, midi_out=usb_midi.ports[1], out_channel=0
    )
```

### Music Box Mode

If&nbsp;`music_box` is `True`, then the Metro is setup to playback MIDI files on the **CIRCUITPY** drive. First, all of the **.mid** files on the drive are found and added to the `midi_files` array. Then, a `MIDIPlayer` class is created to define what is done in the code when certain MIDI messages are read from a MIDI file. In the case of the xylophone, if a NoteOn message is received, the solenoid is triggered. When a NoteOff message is received, the solenoid retracts. At the end of the MIDI file, all solenoids are set to `False` to make sure none of them are stuck on.

```python
else:
    midi_files = []
    for filename in os.listdir('/'):
        if filename.lower().endswith('.mid') and not filename.startswith('.'):
            midi_files.append("/"+filename)
    print(midi_files)

    class Custom_Player(adafruit_midi_parser.MIDIPlayer):
        def on_note_on(self, note, velocity, channel):  # noqa: PLR6301
            for z in range(len(notes)):
                if notes[z] == note:
                    print(f"Playing note: {note}")
                    noids[z].value = True

        def on_note_off(self, note, velocity, channel):  # noqa: PLR6301
            for z in range(len(notes)):
                if notes[z] == note:
                    noids[z].value = False

        def on_end_of_track(self, track):  # noqa: PLR6301
            print(f"End of track {track}")
            for z in range(8):
                noids[z].value = False

        def on_playback_complete(self):  # noqa: PLR6301
            global now_playing
            now_playing = False
            for z in range(8):
                noids[z].value = False
    parser = adafruit_midi_parser.MIDIParser()
    parser.parse(midi_files[randint(0, (len(midi_files) - 1))])
    player = Custom_Player(parser)
    new_file = False
    now_playing = False
```

### The Loop

When you press the&nbsp;BOOT button in music box mode, a MIDI file on the **CIRCUITPY** drive is chosen and queued up to be parsed. As it is read back, the file is played on the xylophone.

```python
while True:
    if music_box:
        event = key.events.get()
        if event:
            if event.pressed:
                now_playing = not now_playing
                if now_playing:
                    new_file = True
        if new_file:
            parser.parse(midi_files[randint(0, (len(midi_files) - 1))])
            print(f"Successfully parsed! Found {len(parser.events)} events.")
            print(f"BPM: {parser.bpm:.1f}")
            print(f"Note Count: {parser.note_count}")
            new_file = False
        if now_playing:
            player.play(loop=False)
```

In live MIDI mode, whenever a NoteOn or NoteOff message is received, the solenoids strike a note.

```python
else:
        msg = midi.receive()
        if msg is not None:
            for i in range(8):
                noid_output = noids[i]
                notes_played = notes[i]
                if isinstance(msg, NoteOn) and msg.note == notes_played:
                    noid_output.value = True
                elif isinstance(msg, NoteOff) and msg.note == notes_played:
                    noid_output.value = False
```

# Solderless Robot Toy Xylophone

## Assembly

![a group image with all of the electronics and 3d printed parts](https://cdn-learn.adafruit.com/assets/assets/000/136/942/medium800/robotics___cnc_edited_P1470656.jpg?1747688735 )

## Solenoid Mounts
Attach four solenoid motors to the back solenoid mount with M3 screws and nuts. Leave the solenoid on the right end's top mounting hole unattached.

![four solenoids with the back mount](https://cdn-learn.adafruit.com/assets/assets/000/136/948/medium640/robotics___cnc_edited_P1470681.jpg?1747750508)

![four solenoids attached to the back mount](https://cdn-learn.adafruit.com/assets/assets/000/136/949/medium640/robotics___cnc_edited_P1470683.jpg?1747750530)

Attach one of the columns to the back mount with an M3 screw and nut. The screw should go through the last solenoid's mounting hole.

![the column attached to the back mount](https://cdn-learn.adafruit.com/assets/assets/000/136/950/medium640/robotics___cnc_edited_P1470691.jpg?1747750617)

Attach four solenoid motors to the top solenoid mount with M3 screws and nuts. Leave the solenoid on the right end's top mounting hole unattached.

![four solenoids with the front mount](https://cdn-learn.adafruit.com/assets/assets/000/136/951/medium640/robotics___cnc_edited_P1470695.jpg?1747750775)

![four solenoids attached to the mount](https://cdn-learn.adafruit.com/assets/assets/000/136/952/medium640/robotics___cnc_edited_P1470697.jpg?1747750791)

Attach the second column to the front mount with an M3 screw and nut. The screw should go through the last solenoid's mounting hole.

![column attached to the front mount](https://cdn-learn.adafruit.com/assets/assets/000/136/953/medium640/robotics___cnc_edited_P1470703.jpg?1747750839)

## Electronics Mount
Attach M2.5 standoffs and nuts to the electronics mounting holes on the electronics mount.

![electronics mount with M2.5 hardware](https://cdn-learn.adafruit.com/assets/assets/000/136/954/medium640/robotics___cnc_edited_P1470705.jpg?1747750883)

![standoffs attached to the electronics mount](https://cdn-learn.adafruit.com/assets/assets/000/136/955/medium640/robotics___cnc_edited_P1470707.jpg?1747750900)

Use three 20 mm long M3 screws to attach the electronics mount to the front solenoid mount.&nbsp;

![electronics mount in with the front solenoid mount](https://cdn-learn.adafruit.com/assets/assets/000/136/956/medium640/robotics___cnc_edited_P1470711.jpg?1747751017)

![the electronics mount attached to the front solenoid mount](https://cdn-learn.adafruit.com/assets/assets/000/136/957/medium640/robotics___cnc_edited_P1470713.jpg?1747751037)

![the back view of the front mount assembly](https://cdn-learn.adafruit.com/assets/assets/000/136/958/medium640/robotics___cnc_edited_P1470714.jpg?1747751057)

Use M2.5 screws to attach the Metro RP2350 and solenoid breakout to the M2.5 standoffs on the electronics mount.

![the metro and breakout in front of the solenoid assembly](https://cdn-learn.adafruit.com/assets/assets/000/136/959/medium640/robotics___cnc_edited_P1470716.jpg?1747751175)

![the electronics mounted to the assembly](https://cdn-learn.adafruit.com/assets/assets/000/136/960/medium640/robotics___cnc_edited_P1470719.jpg?1747751190)

## Bring It All Together
The two solenoid mounts allow the solenoid motors to nest together. Both solenoid mounting plates are held up with the columns.&nbsp;

Slide the two mounts to nest the solenoids while inserting the ends of the mounts into the columns.

![the two solenoid mounts](https://cdn-learn.adafruit.com/assets/assets/000/136/961/medium640/robotics___cnc_edited_P1470721.jpg?1747751239)

![the two solenoid mounts nesting together](https://cdn-learn.adafruit.com/assets/assets/000/136/962/medium640/robotics___cnc_edited_P1470723.jpg?1747751254)

![the two solenoid mounts nested together](https://cdn-learn.adafruit.com/assets/assets/000/136/963/medium640/robotics___cnc_edited_P1470726.jpg?1747751272)

Use M3 screws and nuts to each solenoid mount to the columns.

![the M3 screw attaching the solenoid mounts to the columns](https://cdn-learn.adafruit.com/assets/assets/000/136/964/medium640/robotics___cnc_edited_P1470730.jpg?1747751600)

That finishes the assembly! Next up: wiring.

![the assembled parts](https://cdn-learn.adafruit.com/assets/assets/000/136/965/medium640/robotics___cnc_edited_P1470734.jpg?1747751661)

# Solderless Robot Toy Xylophone

## Wiring

![the solenoid wires being inserted into the terminal blocks](https://cdn-learn.adafruit.com/assets/assets/000/136/983/medium800thumb/robotics___cnc_wiringSolenoids.jpg?1747759443 )

[You can reference the Fritzing diagram for a more detailed look at the wiring](https://learn.adafruit.com/solderless-robot-toy-xylophone/circuit-diagram)
## Solenoid Wire Haircut

The solenoids have fairly long wires, approximately 11 inches each. You can leave them as-is, but it can make for messy wiring. To neaten things up, you can cut each solenoid's wires to the following lengths:

- Solenoids 1 and 2 (far left): 7 inches/17.78 cm
- Solenoids 3 and 4: 6 inches/15.24 cm
- Solenoids 5 and 6: 5 inches/12.7 cm
- Solenoids 7 and 8 (far right): 3 inches/7.62 cm

After cutting the wires, splice them to insert into the terminal blocks on the breakout.

![the solenoids with trimmed wires](https://cdn-learn.adafruit.com/assets/assets/000/136/966/medium800/robotics___cnc_edited_P1470740.jpg?1747751749 )

## Solenoid Terminal Blocks
Attach each solenoid's black wire into one of the numbered terminal blocks and each solenoid's red wire into one of the + terminal blocks:

- Solenoid 1 black wire (far left) to terminal block 0
- Solenoid 1 red wire to terminal block +
- Solenoid 2 black wire to terminal block 1
- Solenoid 2 red wire to terminal block +
- Solenoid 3 black wire to terminal block 2
- Solenoid 3 red wire to terminal block +
- Solenoid 4 black wire to terminal block 3
- Solenoid 4 red wire to terminal block +
- Solenoid 5 black wire to terminal block 4
- Solenoid 5 red wire to terminal block +
- Solenoid 6 black wire to terminal block 5
- Solenoid 6 red wire to terminal block +
- Solenoid 7 black wire to terminal block 6
- Solenoid 7 red wire to terminal block +
- Solenoid 8 black wire (far right) to terminal block 7
- Solenoid 8 red wire to terminal block +

![the solenoid wires inserted into the terminal blocks](https://cdn-learn.adafruit.com/assets/assets/000/136/967/medium640/robotics___cnc_edited_P1470760.jpg?1747751957)

## Solenoid Power
Insert wires into the center power terminal block on the breakout. Attach the GND (-) wire to GND on the Metro. Attach the + wire to Vin on the Metro. This will allow the DC jack input on the Metro to power the solenoids with 12V.

![the power wires](https://cdn-learn.adafruit.com/assets/assets/000/136/968/medium640/robotics___cnc_edited_P1470763.jpg?1747752153)

## STEMMA QT
Plug a 100 mm STEMMA QT cable into the STEMMA QT port on the Metro. Plug in the other end into the breakout.

![stemma cable connecting the metro and breakout](https://cdn-learn.adafruit.com/assets/assets/000/136/969/medium640/robotics___cnc_edited_P1470765.jpg?1747752260)

## Wired for Sound
That completes the wiring. You're ready to start up your robot band.

![the assembly with the xylophone](https://cdn-learn.adafruit.com/assets/assets/000/136/970/medium640/robotics___cnc_edited_P1470768.jpg?1747752309)

# Solderless Robot Toy Xylophone

## Use

https://youtu.be/G-UXVCxeu4Y

Warning: The solenoids require 12V. For this project to work, you will need to provide 12V via the Metro RP2350 DC jack.

Plug a 12V power supply into the DC jack on the Metro RP2350 to power up the toy robot xylophone. The xylophone has two modes: live MIDI mode and music box mode. The mode is defined by the variable&nbsp;`music_box` at the top of the code.

Live MIDI mode lets you send MIDI messages over USB MIDI to the xylophone. If you're using this mode, you'll also need a data USB C cable for MIDI input.

Music box mode lets you load MIDI files (.mid) onto the **CIRCUITPY** drive and play them back with the xylophone. You don't need a USB cable for this mode to work.

Info: The xylophone only has the notes of a C major scale, so any notes that are sent to it outside of C major will not play.

A few simple MIDI files are included in the project bundle for music box mode. To play a file, press the **BOOT** button on the Metro. A file will be randomly chosen and played back on the xylophone. The code adapts to however many MIDI files you have on the **CIRCUITPY** drive, so you can create your own files for playback.

![the xylophone playing a midi file](https://cdn-learn.adafruit.com/assets/assets/000/136/977/medium640thumb/robotics___cnc_musicBox.jpg?1747757542)

For live MIDI mode, you can connect the xylophone to your computer or a USB host device and send it MIDI messages to playback.

![a c scale being played on the midi keyboard](https://cdn-learn.adafruit.com/assets/assets/000/136/978/medium640thumb/robotics___cnc_scaleMIDI.jpg?1747757754)


## Featured Products

### Adafruit Metro RP2350

[Adafruit Metro RP2350](https://www.adafruit.com/product/6003)
Choo! Choo! This is the RP2350 Metro Line, making all station stops at "Dual Cortex M33 mountain", "528K RAM round-about" and "16 Megabytes of Flash town". This train is piled high with hardware that complements the Raspberry Pi RP2350 chip to make it an excellent...

In Stock
[Buy Now](https://www.adafruit.com/product/6003)
[Related Guides to the Product](https://learn.adafruit.com/products/6003/guides)
### Adafruit I2C to 8 Channel Solenoid Driver

[Adafruit I2C to 8 Channel Solenoid Driver](https://www.adafruit.com/product/6318)
Solenoids are a little like cats: if your project has one solenoid you'll probably stick with just one and in such cases our [single MOSFET driver will work well](https://www.adafruit.com/product/5648). But if you have more than one solenoid, it's going to be anywhere from 2...

In Stock
[Buy Now](https://www.adafruit.com/product/6318)
[Related Guides to the Product](https://learn.adafruit.com/products/6318/guides)
### Small  Push-Pull Solenoid - 12VDC

[Small  Push-Pull Solenoid - 12VDC](https://www.adafruit.com/product/412)
Solenoids are basically electromagnets: they are made of a big coil of copper wire with an armature (a slug of metal) in the middle. When the coil is energized, the slug is pulled into the center of the coil. This makes the solenoid able to pull (from one end) or push (from the other)  
<br...></br...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/412)
[Related Guides to the Product](https://learn.adafruit.com/products/412/guides)
### 12V 5A switching power supply

[12V 5A switching power supply](https://www.adafruit.com/product/352)
This is a beefy switching supply, for when you need a lot of power! It can supply 12V DC up to 5 Amps, running from 110V or 220V power (the plug it comes with is for US/Canada/Japan but you can use any plug adapter for your country, or just replace the cable with a standard 'figure-8'...

In Stock
[Buy Now](https://www.adafruit.com/product/352)
[Related Guides to the Product](https://learn.adafruit.com/products/352/guides)
### STEMMA QT / Qwiic JST SH 4-pin Cable - 100mm Long

[STEMMA QT / Qwiic JST SH 4-pin Cable - 100mm Long](https://www.adafruit.com/product/4210)
This 4-wire cable is a little over 100mm / 4" 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/4210)
[Related Guides to the Product](https://learn.adafruit.com/products/4210/guides)
### Premium Male/Male Jumper Wires - 40 x 6" (150mm)

[Premium Male/Male Jumper Wires - 40 x 6" (150mm)](https://www.adafruit.com/product/758)
Handy for making wire harnesses or jumpering between headers on PCB's. These premium jumper wires are 6" (150mm) long and come in a 'strip' of 40 (4 pieces of each of ten rainbow colors). They have 0.1" male header contacts on either end and fit cleanly next to each other...

Out of Stock
[Buy Now](https://www.adafruit.com/product/758)
[Related Guides to the Product](https://learn.adafruit.com/products/758/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)
### Black Nylon Machine Screw and Stand-off Set – M3 Thread

[Black Nylon Machine Screw and Stand-off Set – M3 Thread](https://www.adafruit.com/product/4685)
Totaling **420 pieces** , this **M3 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! M3 size screws fit a number of&nbsp;Adafruit breakout/dev board...

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

## Related Guides

- [Adafruit Metro RP2350](https://learn.adafruit.com/adafruit-metro-rp2350.md)
- [Adafruit I2C to 8 Channel Solenoid Driver](https://learn.adafruit.com/adafruit-i2c-to-8-channel-solenoid-driver.md)
- [Generating Text with ChatGPT, Pico W & CircuitPython](https://learn.adafruit.com/generating-text-with-chatgpt-pico-w-circuitpython.md)
- [USB to Eurorack Power Supply](https://learn.adafruit.com/usb-to-eurorack-power-supply.md)
- [16x16 NeoPixel Matrix Square Pixel Display](https://learn.adafruit.com/16x16-neopixel-matrix-square-pixel-display.md)
- [Remote Effects Trigger Box](https://learn.adafruit.com/remote-effects-trigger.md)
- [NeoPixel Menorah](https://learn.adafruit.com/neopixel-menorah.md)
- [eInk FeatherWing Display Stand](https://learn.adafruit.com/eink-featherwing-display-stand.md)
- [Mini LED Matrix Audio Visualizer](https://learn.adafruit.com/mini-led-matrix-audio-visualizer.md)
- [3D Print Ratcatcher 2 Controller Device](https://learn.adafruit.com/3d-print-ratcatcher-2-controller-device-wand.md)
- [PyPortal Weather Station](https://learn.adafruit.com/pyportal-weather-station.md)
- [USB C Power Delivery Monitor](https://learn.adafruit.com/usb-c-benchtop-power-supply.md)
- [Split Ortho Keyboard with TCA8418 Matrix Expanders](https://learn.adafruit.com/split-ortho-keyboard.md)
- [Breakout Game on the Metro RP2350 and Fruit Jam](https://learn.adafruit.com/breakout-game-on-metro-rp2350-and-fruit-jam.md)
- [Servo Boss](https://learn.adafruit.com/servo-boss.md)
- [Espresso Water Tank Meter](https://learn.adafruit.com/espresso-water-tank-meter.md)
