# MIDI Controlled Robot Lyre with CircuitPython

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/119/527/medium800thumb/robotics___cnc_hornsUpClose.jpg?1679341250)

What they don't tell you about starting a band is that the hardest part is organizing the people. So, why not skip that step and build a bunch of MIDI controlled robots to play music with?

In this project, you'll mount servo motors over the strings of a [lyre](https://en.wikipedia.org/wiki/Lyre). The servos will pluck those strings when they receive MIDI NoteOn messages via a Feather RP2040 running CircuitPython. You can control the lyre with an eternal MIDI controller or by sending MIDI out from your favorite DAW program.

https://youtube.com/shorts/62yba-iYM6g?feature=share

The entire build sits on a plate of acrylic with some 3D printed parts. The servos have 3D printed horn extenders to pleasantly pluck the strings.

![robotics___cnc_edited_P1400292.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/525/medium640/robotics___cnc_edited_P1400292.jpg?1679340575)

The servos are driven by the PCA9685 servo driver breakout. The driver board has an external 5V power input and connects to the Feather RP2040 over I2C.

![robotics___cnc_edited_P1400285.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/526/medium640/robotics___cnc_edited_P1400285.jpg?1679340684)

## A Note on Robotic Instruments

All acoustic instruments are slightly different and, as a result, if you build this project, you may need to do some fine tuning to the mechanical aspects of the design for best results. [This lyre](https://www.amazon.com/gp/product/B08L3FJZD7) was used for the build because it seems to be a common shape for budget lyres and is from a known budget music brand (Donner).

The parts that were the most finicky to dial in were the servo horns and the acrylic pegs that lift the acrylic base. It's important to achieve a proper balance between these two measurements for the best timbre from the lyre, with less than a millimeter often making a difference. All of the design files are included and _should_ work as-is, but the source files are also available if you find you need to adjust things.

## Parts
### 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)

### Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface

[Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface](https://www.adafruit.com/product/815)
You want to make a cool robot, maybe a hexapod walker, or maybe just a piece of art with a lot of moving parts. Or maybe you want to drive a lot of LEDs with precise PWM output. Then you realize that your microcontroller has a limited number of PWM outputs! What now? You could give up OR you...

In Stock
[Buy Now](https://www.adafruit.com/product/815)
[Related Guides to the Product](https://learn.adafruit.com/products/815/guides)
![Adafruit 16-Channel 12-bit PWM/Servo Driver with I2C interface](https://cdn-shop.adafruit.com/640x480/815-05.jpg)

### Micro Servo - MG90D High Torque Metal Gear

[Micro Servo - MG90D High Torque Metal Gear](https://www.adafruit.com/product/1143)
Add more power to your robot with this metal-geared MG90D&nbsp;servo. The tiny little servo can rotate approximately 90 degrees (45 in each direction) and works just like the standard kinds you're used to but _smaller_. You can use any servo code, hardware, or library to control...

Out of Stock
[Buy Now](https://www.adafruit.com/product/1143)
[Related Guides to the Product](https://learn.adafruit.com/products/1143/guides)
![High Torque Metal Gear Micro Servo  with three pin cable](https://cdn-shop.adafruit.com/640x480/1143-08.jpg)

### 5V 10A switching power supply

[5V 10A switching power supply](https://www.adafruit.com/product/658)
This is a beefy switching supply, for when you need a lot of power! It can supply 5V DC up to 10 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 computer/appliance...

Out of Stock
[Buy Now](https://www.adafruit.com/product/658)
[Related Guides to the Product](https://learn.adafruit.com/products/658/guides)
![5V 10A switching power supply brick with IEC power port.](https://cdn-shop.adafruit.com/640x480/658-07.jpg)

### Slotted Aluminum Extrusion - 20mm x 20mm - 610mm long

[Slotted Aluminum Extrusion - 20mm x 20mm - 610mm long](https://www.adafruit.com/product/1221)
Oh boy, now you have no excuse for not building that robot! Nothing is easier or faster than building with extrusion and we've added 20mm square aluminum extrusion and components to our catalog. This product is the extrusion itself. Made of aluminum, its exactly 20x20mm square and has...

In Stock
[Buy Now](https://www.adafruit.com/product/1221)
[Related Guides to the Product](https://learn.adafruit.com/products/1221/guides)
![Angled Shot of the Slotted Aluminum Extrusion - 20mm x 20mm - 610mm long.](https://cdn-shop.adafruit.com/640x480/1221-02.jpg)

### Part: STEMMA QT cable
quantity: 1
50 mm
[STEMMA QT cable](https://www.adafruit.com/product/4399)

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

### Part: Pack of M4 screws
quantity: 1
10 mm long
[Pack of M4 screws](https://www.adafruit.com/product/1159)

### Part: Pack of M4 T-Nuts
quantity: 1
for 20x20 extrusion
[Pack of M4 T-Nuts](https://www.adafruit.com/product/1157)

### Part: M2 screws
quantity: 1
M2 hardware
[M2 screws](https://www.amazon.com/dp/B07W5HBRMP)

### Part: 16 String Lyre Harp
quantity: 1
Donner 16 string lyre harp
[16 String Lyre Harp](https://www.amazon.com/gp/product/B08L3FJZD7)

# MIDI Controlled Robot Lyre with CircuitPython

## Circuit Diagram

![](https://cdn-learn.adafruit.com/assets/assets/000/119/512/medium800/robotics___cnc_roboHarpFritz_bb.png?1679089146)

- **Feather 3.3V** to **PCA9685 VCC (red wire)**
- **Feather GND** to **PCA9685 GND (black wire)**
- **Feather SCL** to **PCA9685 SCL (yellow wire)**
- **Feather SDA** to **PCA9685 SDA (blue wire)**

## Servos

The servos have header plugs that can plug into the headers on the PCA9685. You will plug in a servo to each of the 16 (0-15) inputs on the PCA9685. Only one servo is shown in the Fritzing diagram to keep the diagram uncluttered.

# MIDI Controlled Robot Lyre with CircuitPython

## 3D Printing

![](https://cdn-learn.adafruit.com/assets/assets/000/119/453/medium800/robotics___cnc_edited_P1400114.jpg?1678904013)

The project may be assembled with a few 3D printed parts, described below. The parts can print with no supports. You'll need to print multiples of some parts:

Servo Rack

- 1x **servoRack\_base.stl**
- 1x **servoRack\_top.stl**
- 1x **servoRack\_topBrace.stl**

Aluminum Extrusion

- 3x **extrusionMount.stl**
- 1x **electronicsMount.stl**

Acrylic - 3 mm thick

- 1x **acrylicBrace.stl**
- 4x **acrylicPegs.stl**

Servo Horns

- 16x **servoHorn.stl**

The STL files can be downloaded directly here or from Printables. Also included is a **.DXF** file for the acrylic base. More details on that file can be found on the [Assembly page](https://learn.adafruit.com/midi-controlled-robot-lyre-with-circuitpython/assembly) in this guide.

[Printables Download](https://www.printables.com/model/428834-robot-lyre)
[finalRobotLyreCADparts.zip](https://cdn-learn.adafruit.com/assets/assets/000/119/520/original/finalRobotLyreCADparts.zip?1679323944)
### Servo Rack

Three parts hold and mount the servos so that they sit on a curve directly above the lyre strings.

![robotics___cnc_edited_P1400133.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/454/medium640/robotics___cnc_edited_P1400133.jpg?1678904217)

### Aluminum Extrusion Mounts

The Feather and servo driver are mounted to a piece of aluminum extrusion with a 3D printed plate. The piece of extrusion slides onto three mounts that are secured to an acrylic plate. The extrusion also counter balances the weight of the servos.

![robotics___cnc_edited_P1400127.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/455/medium640/robotics___cnc_edited_P1400127.jpg?1678904283)

### Acrylic Pegs

Four pegs are mounted to the acrylic plate to raise it to the correct height for the servo motors.

![robotics___cnc_edited_P1400129.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/456/medium640/robotics___cnc_edited_P1400129.jpg?1678904378)

### Servo Picks

The servo horns are used to pluck the lyre strings with these 3D printed picks. You'll need to print one for each servo.

![robotics___cnc_edited_P1400262.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/498/medium640/robotics___cnc_edited_P1400262.jpg?1679070478)

# MIDI Controlled Robot Lyre with CircuitPython

## 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)
# MIDI Controlled Robot Lyre with CircuitPython

## Code the Robot Lyre

Once you've finished setting up your Feather RP2040 with CircuitPython, you can access the code 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 as a zipped folder.

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

## Upload the Code and Libraries to the Feather RP2040

After downloading the Project Bundle, plug your Feather RP2040 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 Feather RP2040's **CIRCUITPY** drive.

- **lib** folder
- **code.py**

Your Feather RP2040 **CIRCUITPY** drive should look like this after copying the **lib** folder and the **code.py** file:

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

## How the CircuitPython Code Works

The code begins by creating a `midi` object over USB as a MIDI input. This means that the Feather will _take in_, or receive, MIDI messages from another source. The source could be your computer or an external MIDI device.

```python
#  MIDI input setup
midi = adafruit_midi.MIDI(midi_in=usb_midi.ports[0], in_channel=0)
```

## Servos Over I2C

The STEMMA QT port on the Feather is setup as the default `i2c` object. The PCA9685 servo driver is instantiated over I2C. Then, the servo objects are created and added to the `servos` array with a Python [list comprehension](https://www.w3schools.com/python/python_lists_comprehension.asp).

```python
# i2c PCA9685 setup
i2c = board.STEMMA_I2C()
pca = PCA9685(i2c)

pca.frequency = 50

servos = [servo.Servo(pca.channels[i]) for i in range(16)]
```

## Arrays of Servos and Notes

An array is created for the MIDI note numbers. This array will correspond with the `servos` array. Both will be iterated through in the loop. If you want to change which MIDI notes are assigned to each servo, you can edit the `midi_notes` array. By default, it lists a C major scale.

```python
# array of midi notes, high to low
midi_notes = [83, 81, 79, 77, 76, 74, 72, 71, 69, 67, 65, 64, 62, 60, 59, 57]
```

## Angles

The servos will move back and forth between two set angles. These angles are defined with `angle0` and `angle1`. Before the loop, all of the servos are set to `angle1`. This makes it easier to adjust the servo horns if needed.

```python
angle0 = 20
angle1 = 70

# set servos to the same angle on boot
# easier to adjust angles of the horns if needed
print("setting servos")
for i in range(16):
    s = servos[i]
    s.angle = angle1
    time.sleep(0.05)
print("servos set")
```

## The Loop

In the loop, the Feather listens for incoming MIDI messages with `midi.receive()`. If a `NoteOn` message comes in containing a note number that is defined in the `midi_notes` array, then the corresponding servo will move to either `angle0` or `angle1` depending on the current angle of the servo.

```python
while True:
    # msg holds MIDI messages
    msg = midi.receive()

    for i in range(16):
        # iterate through servos array &amp; midi notes array
        servo = servos[i]
        note_played = midi_notes[i]

        # if a noteon msg comes in that matches a note in the midi notes array..
        if isinstance(msg, NoteOn) and msg.note == note_played:
            # print(servo)
            # print(note_played)
            # servo moves
            # angle alternates between angle0 and angle1
            if servo.angle &lt;= angle0:
                servo.angle = angle1
            else:
                servo.angle = angle0
            # print(servo.angle)
```

# MIDI Controlled Robot Lyre with CircuitPython

## Wiring

![](https://cdn-learn.adafruit.com/assets/assets/000/119/513/medium800/robotics___cnc_edited_P1390429.jpg?1679089366)

The PCA9685 requires a little bit of soldering to prepare it for the robot lyre. You'll solder a STEMMA QT cable, 4x3 headers and a terminal block to the PCA9685. You'll also prepare the DC power input cable.

Cut and splice one end of a STEMMA QT cable. Then, solder the wires to the PCA9685 inputs:

- **STEMMA red wire** to **VCC**
- **STEMMA black wire** to **GND**
- **STEMMA blue wire** to **SDA**
- **STEMMA yellow wire** to **SCL**

This will allow you to plug the PCA9685 into the Feather STEMMA QT port.

![robotics___cnc_edited_P1390432.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/514/medium640/robotics___cnc_edited_P1390432.jpg?1679089377)

Solder the four sets of 4x3 headers to the PCA9685. These headers will be used to plug the servo motors into the PCA9685. You can use a breadboard to secure the headers while you solder.

![robotics___cnc_edited_P1390435.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/515/medium640/robotics___cnc_edited_P1390435.jpg?1679089494)

Solder the included terminal block to the power input on the PCA9685.

![robotics___cnc_edited_P1390443.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/516/medium640/robotics___cnc_edited_P1390443.jpg?1679089586)

Cut off the alligator clips on the DC to alligator clip cable. Then, splice each of those wires. These wires can be inserted into the terminal block to power the PCA9685 with a DC power supply.

![robotics___cnc_edited_P1390445.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/517/medium640/robotics___cnc_edited_P1390445.jpg?1679089635)

# MIDI Controlled Robot Lyre with CircuitPython

## Assembly

![](https://cdn-learn.adafruit.com/assets/assets/000/119/457/medium800/robotics___cnc_edited_P1400124.jpg?1678904556)

## Cutting Acrylic and Aluminum

The robot lyre is made of multiple parts, some of them moving, but the core of the build rests (literally) on a piece of acrylic and a piece of aluminum extrusion.

There are many ways to get this acrylic shape with the various mounting holes. You could use a CNC, laser cutter or you could cut it using your preferred power tool. The DXF file is available on Printables or directly below.

![robotics___cnc_edited_P1400139.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/458/medium640/robotics___cnc_edited_P1400139.jpg?1678904840)

[finalRobotLyreCADparts.zip](https://cdn-learn.adafruit.com/assets/assets/000/119/521/original/finalRobotLyreCADparts.zip?1679323964)
[Printables Download](https://www.printables.com/model/428834-robot-lyre/files)
The piece of aluminum extrusion serves two purposes: to mount the electronics and to counter balance the servo motors. You'll want to cut your piece of extrusion to 13.5 inches (34.29 cm). Aluminum can be cut easily with a miter saw.

![robotics___cnc_IMG_8207.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/459/medium640/robotics___cnc_IMG_8207.jpg?1678905038)

# MIDI Controlled Robot Lyre with CircuitPython

## Prep and Attach the Servo Horns

![](https://cdn-learn.adafruit.com/assets/assets/000/119/494/medium800/robotics___cnc_edited_P1400253.jpg?1679070239)

The lyre strings are plucked by 3D printed picks that are attached to the stock servo horn with an M2 screw.

Use a pin vise to tap the third hole from the bottom of the horn so that it will accept an M2 screw.

![robotics___cnc_edited_P1400258.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/495/medium640/robotics___cnc_edited_P1400258.jpg?1679070283)

Slot the pick over the horn and secure it with an M2 screw.

![robotics___cnc_edited_P1400271.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/496/medium640/robotics___cnc_edited_P1400271.jpg?1679070343)

Attach the horn pick to the servo with its point facing away from the purple label.

Repeat this process for all 16 servos.

![robotics___cnc_edited_P1400275.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/497/medium640/robotics___cnc_edited_P1400275.jpg?1679070368)

# MIDI Controlled Robot Lyre with CircuitPython

## Mount the Servos

![](https://cdn-learn.adafruit.com/assets/assets/000/119/460/medium800/robotics___cnc_edited_P1400108.jpg?1678905480)

The base of the servo cage has staggered mounting holes for each servo motor. You'll attach the servos to the cage with an M2 screw.

Begin by mounting the first servo on the left. This servo is located in the back row of the servo cage. Attach it with an M2 screw.

![robotics___cnc_edited_P1400141.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/461/medium640/robotics___cnc_edited_P1400141.jpg?1678905490)

Next, mount the second servo in the next mounting hole on the servo cage with an M2 screw. This is the first servo in the front row of the cage.

![robotics___cnc_edited_P1400145.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/462/medium640/robotics___cnc_edited_P1400145.jpg?1678905621)

Continue mounting the servos until all 16 are mounted on the cage.

![robotics___cnc_edited_P1400105.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/463/medium640/robotics___cnc_edited_P1400105.jpg?1678905698)

# MIDI Controlled Robot Lyre with CircuitPython

## Mount the Electronics

Attach M2.5 nuts and stand-offs to the board mounting holes on the electronics mount. Then, attach three M4 screws with t-nuts in the three center holes.

![robotics___cnc_edited_P1400152.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/464/medium640/robotics___cnc_edited_P1400152.jpg?1678906242)

Slide the mount onto the aluminum extrusion using the t-nuts. Secure the mount by tightening the M4 screws.

![robotics___cnc_edited_P1400154.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/465/medium640/robotics___cnc_edited_P1400154.jpg?1678906349)

Attach the Feather and servo driver to the M2.5 stand-offs with M2.5 screws. Plug the servo driver STEMMA cable into the Feather STEMMA QT port.

![robotics___cnc_edited_P1400157.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/466/medium640/robotics___cnc_edited_P1400157.jpg?1678906392)

# MIDI Controlled Robot Lyre with CircuitPython

## Attach the Servos to the Acrylic

![](https://cdn-learn.adafruit.com/assets/assets/000/119/467/medium800/robotics___cnc_edited_P1400159.jpg?1678906914)

The servos are mounted to the edge of the acrylic using M3 screws and nuts.&nbsp;

Attach the side of the servo cage to the acrylic using M3 screws and nuts.

![robotics___cnc_edited_P1400163.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/468/medium640/robotics___cnc_edited_P1400163.jpg?1678906942)

Attach the opposite side with M3 screws and nuts.

![robotics___cnc_edited_P1400162.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/469/medium640/robotics___cnc_edited_P1400162.jpg?1678906980)

Complete the attachment by mounting the nine mounting holes on the servo cage to the acrylic with M3 screws and nuts.

![robotics___cnc_edited_P1400168.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/470/medium640/robotics___cnc_edited_P1400168.jpg?1678907123)

# MIDI Controlled Robot Lyre with CircuitPython

## Acrylic Risers

![](https://cdn-learn.adafruit.com/assets/assets/000/119/474/medium800/robotics___cnc_edited_P1400176.jpg?1678907524)

A 3D printed brace is attached to the center of the acrylic to try and prevent bowing. The riser pieces that raise the acrylic above the lyre strings mount to the corners of the brace.

Attach the brace to the three center mounting holes with M3 screws and nuts. You'll notice that they are arranged in a triangle.

![robotics___cnc_edited_P1400173.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/472/medium640/robotics___cnc_edited_P1400173.jpg?1678907389)

Attach each of the risers to the four corners of the brace with long M3 screws. The riser holes are sized so that the screws will tap the riser.

![robotics___cnc_edited_P1400174.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/473/medium640/robotics___cnc_edited_P1400174.jpg?1678907435)

# MIDI Controlled Robot Lyre with CircuitPython

## Attach the Aluminum Extrusion to the Acrylic

![](https://cdn-learn.adafruit.com/assets/assets/000/119/477/medium800/robotics___cnc_edited_P1400192.jpg?1678907693)

Take the three extrusion mounts and attach them to the mounting holes on the acrylic using long M3 screws. The holes of the mounts are sized so that the screws will tap them.

![robotics___cnc_edited_P1400194.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/476/medium640/robotics___cnc_edited_P1400194.jpg?1678907684)

Insert M4 screws into the holes on the back of the extrusion mounts. Attach t-nuts to the M4 screws.

![robotics___cnc_edited_P1400195.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/478/medium640/robotics___cnc_edited_P1400195.jpg?1678907701)

Slide the aluminum extrusion onto the mounts so that the bottom side and t-nuts slot into the extrusion. The electronics should be facing up with the DC jack facing away from the servo motors.

![robotics___cnc_edited_P1400201.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/479/medium640/robotics___cnc_edited_P1400201.jpg?1678907754)

# MIDI Controlled Robot Lyre with CircuitPython

## Plug in the Servos

Plug the servo furthest to the left into port 15 on the servo driver. Make sure that the yellow wire is plugging into the PWM pin.

![robotics___cnc_edited_P1400208.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/480/medium640/robotics___cnc_edited_P1400208.jpg?1678907924)

Continue plugging in the servos in order from ports 15-0.

![robotics___cnc_edited_P1400213.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/482/medium640/robotics___cnc_edited_P1400213.jpg?1678908017)

The build is now in a state where you can test it with the lyre.

![](https://cdn-learn.adafruit.com/assets/assets/000/119/483/medium800/robotics___cnc_edited_P1400215.jpg?1678908142)

# MIDI Controlled Robot Lyre with CircuitPython

## Hot Glue!

![](https://cdn-learn.adafruit.com/assets/assets/000/119/501/medium800/robotics___cnc_edited_P1400226.jpg?1679088052)

Align the servos so that they are directly above the lyre strings. Once you are happy with the placement, use some masking tape to temporarily hold the apparatus in place.

Before deciding on a final placement, you may want to do a test run playing the lyre to make sure that the servos are striking the strings evenly.

Then, take some hot glue and tack the acrylic stand-offs in place.

![robotics___cnc_edited_P1400228.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/502/medium640/robotics___cnc_edited_P1400228.jpg?1679088146)

# MIDI Controlled Robot Lyre with CircuitPython

## Enclose the Servos

The final step in securing the servos is installing the top of the servo cage. Begin by press fitting the main piece behind the front row of servos.

![robotics___cnc_edited_P1400231.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/504/medium640/robotics___cnc_edited_P1400231.jpg?1679088296)

Secure the main piece to the bottom base with an M3 screw and nut.

![robotics___cnc_edited_P1400232.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/505/medium640/robotics___cnc_edited_P1400232.jpg?1679088360)

Attach the first servo with an M2 screw. There are mounting holes for the entire front row of servos that align with the servos' top mounting hole.

![robotics___cnc_edited_P1400234.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/506/medium640/robotics___cnc_edited_P1400234.jpg?1679088397)

Attach the rest of the front row of servos with M2 screws to the main piece.

![robotics___cnc_edited_P1400238.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/507/medium640/robotics___cnc_edited_P1400238.jpg?1679088446)

Press fit the back piece behind the back row of servos.

![robotics___cnc_edited_P1400239.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/508/medium640/robotics___cnc_edited_P1400239.jpg?1679088507)

Attach the back piece to the bottom piece with M3 screws and nuts.

![robotics___cnc_edited_P1400242.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/509/medium640/robotics___cnc_edited_P1400242.jpg?1679088542)

Secure the back row of servos to the back piece with M2 screws. The screw will thread through the back piece, servo mounting hole and the mounting hole on the main piece.

![robotics___cnc_edited_P1400243.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/510/medium640/robotics___cnc_edited_P1400243.jpg?1679088570)

Secure the remaining servos in the back row with M2 screws.

![robotics___cnc_edited_P1400247.jpg](https://cdn-learn.adafruit.com/assets/assets/000/119/511/medium640/robotics___cnc_edited_P1400247.jpg?1679088687)

# MIDI Controlled Robot Lyre with CircuitPython

## Use

![](https://cdn-learn.adafruit.com/assets/assets/000/119/524/medium800/robotics___cnc_edited_P1400305.jpg?1679340101)

After you're finishing assembling, plug a 5V DC power supply into the power input on the PCA9685. Then, connect the Feather RP2040 via USB to either your computer or USB MIDI host. There are two ways to control the robot lyre: with a DAW or with a hardware MIDI controller.

https://youtu.be/Ar_2cEkGkng

## Using with a DAW

A digital audio workstation (DAW) is any computer program that lets you work with audio on your computer. Some examples include Logic, Reason and Ableton Live.

You can set the Feather RP2040 as a MIDI output to send MIDI data to it from a DAW. This is usually done with a MIDI track or with a MIDI plugin. The Feather will usually show up as a device called **CircuitPython Audio**.

![robotics___cnc_extMidi.png](https://cdn-learn.adafruit.com/assets/assets/000/119/522/medium640/robotics___cnc_extMidi.png?1679327419)

## Using with a MIDI Controller

You can control the robot lyre directly with another hardware MIDI controller. This can be accomplished with the use of a [USB MIDI host](https://www.perfectcircuit.com/signal/usb-midi-hosts). A USB MIDI host lets two USB MIDI devices talk to each other directly, with one sending MIDI messages and the other receiving those MIDI messages.

There are hardware USB MIDI host solutions (including DIY ones, like this [Raspberry Pi project](https://neuma.studio/rpi-midi-complete.html)) and software solutions like [MIDIberry](https://apps.microsoft.com/store/detail/midiberry/9N39720H2M05?hl=en-us&gl=us&rtc=1) on Windows and [MIDI Studio](https://support.apple.com/guide/audio-midi-setup/set-up-midi-devices-ams875bae1e0/mac) on macOS.

After configuring your MIDI controller as the MIDI input and the robot lyre as the MIDI output on your MIDI host, you can play melodies and sequences with your controller to directly pluck the robot lyre.

![robotics___cnc_P1400294_1.gif](https://cdn-learn.adafruit.com/assets/assets/000/119/523/medium640thumb/robotics___cnc_P1400294_1.jpg?1679339858)


## 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)
### Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface

[Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface](https://www.adafruit.com/product/815)
You want to make a cool robot, maybe a hexapod walker, or maybe just a piece of art with a lot of moving parts. Or maybe you want to drive a lot of LEDs with precise PWM output. Then you realize that your microcontroller has a limited number of PWM outputs! What now? You could give up OR you...

In Stock
[Buy Now](https://www.adafruit.com/product/815)
[Related Guides to the Product](https://learn.adafruit.com/products/815/guides)
### Micro Servo - MG90D High Torque Metal Gear

[Micro Servo - MG90D High Torque Metal Gear](https://www.adafruit.com/product/1143)
Add more power to your robot with this metal-geared MG90D&nbsp;servo. The tiny little servo can rotate approximately 90 degrees (45 in each direction) and works just like the standard kinds you're used to but _smaller_. You can use any servo code, hardware, or library to control...

Out of Stock
[Buy Now](https://www.adafruit.com/product/1143)
[Related Guides to the Product](https://learn.adafruit.com/products/1143/guides)
### 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...>

In Stock
[Buy Now](https://www.adafruit.com/product/4399)
[Related Guides to the Product](https://learn.adafruit.com/products/4399/guides)
### 2.1mm DC Barrel Jack to Alligator Clips

[2.1mm DC Barrel Jack to Alligator Clips](https://www.adafruit.com/product/1328)
Turn a wall adapter into a mini power supply with this incredibly useful adapter. A high quality molded 2.1mm DC barrel jack is brought out to red (center positive) & black (ring negative) alligator clips. Works with just about every wall adapter, good for about 2 or 3 Amps of current and...

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

[5V 10A switching power supply](https://www.adafruit.com/product/658)
This is a beefy switching supply, for when you need a lot of power! It can supply 5V DC up to 10 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 computer/appliance...

Out of Stock
[Buy Now](https://www.adafruit.com/product/658)
[Related Guides to the Product](https://learn.adafruit.com/products/658/guides)
### Slotted Aluminum Extrusion - 20mm x 20mm - 610mm long

[Slotted Aluminum Extrusion - 20mm x 20mm - 610mm long](https://www.adafruit.com/product/1221)
Oh boy, now you have no excuse for not building that robot! Nothing is easier or faster than building with extrusion and we've added 20mm square aluminum extrusion and components to our catalog. This product is the extrusion itself. Made of aluminum, its exactly 20x20mm square and has...

In Stock
[Buy Now](https://www.adafruit.com/product/1221)
[Related Guides to the Product](https://learn.adafruit.com/products/1221/guides)
### Aluminum Extrusion Slim T-Nut for 20x20 - M4 Thread - pack of 50

[Aluminum Extrusion Slim T-Nut for 20x20 - M4 Thread - pack of 50](https://www.adafruit.com/product/1157)
An essential for working with slotted aluminum extrusion, these slim metal nuts slide into the side-slot of the extrusion. The slightly oval shape means that as they screwed-into the nut jams against the slot.  
  
This product comes as a bag of 50 slim T-nuts, with M4 threads. If you...

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

## Related Guides

- [Introducing Adafruit Feather RP2040](https://learn.adafruit.com/adafruit-feather-rp2040-pico.md)
- [32x32 Square Pixel Art Animation Display](https://learn.adafruit.com/32x32-square-pixel-display.md)
- [Adafruit 16 Channel Servo Driver with Raspberry Pi](https://learn.adafruit.com/adafruit-16-channel-servo-driver-with-raspberry-pi.md)
- [DeviceScript, TypeScript for Microcontrollers](https://learn.adafruit.com/devicescript.md)
- [Driving TM1814 addressable LEDs](https://learn.adafruit.com/driving-tm1814-addressable-leds.md)
- [MIDI Laser Harp with Time of Flight Distance Sensors](https://learn.adafruit.com/midi-laser-harp-time-of-flight-sensors.md)
- [Disconnected CO2 Data Logger](https://learn.adafruit.com/disconnected-co2-data-logger.md)
- [Motorized POV LED Display](https://learn.adafruit.com/motorized-pov-led-display.md)
- [Raspberry Pi Wifi-Controlled Cat Laser Toy](https://learn.adafruit.com/raspberry-pi-wifi-controlled-cat-laser-toy.md)
- [Deco Two-Key Feather Macro Pad](https://learn.adafruit.com/deco-two-key-keypad-macropad-circuitpython-feather.md)
- [Neocontroller Color Grading Input Box](https://learn.adafruit.com/neocontroller-color-grading-input-box.md)
- [LED Tricks: Gamma Correction](https://learn.adafruit.com/led-tricks-gamma-correction.md)
- [Cooperative Multitasking in CircuitPython with asyncio](https://learn.adafruit.com/cooperative-multitasking-in-circuitpython-with-asyncio.md)
- [CircuitPython Hardware: PCA9685 PWM & Servo Driver](https://learn.adafruit.com/micropython-hardware-pca9685-pwm-and-servo-driver.md)
- [Digital Clock with CircuitPython](https://learn.adafruit.com/digital-clock-with-circuitpython.md)
- [Desk Calculator with CircuitPython](https://learn.adafruit.com/desk-calculator-with-circuitpython.md)
