This Python project:🪄✨ enables communication with an actual xylophone via a Client-Server setup. A Client sends notes to the Server and instructs it to play the music. The Server, in turn, directs the execution. Two Server modes are provided: one for a physical xylophone 🎹🎶 and another that simulates its behaviour.
https://www.youtube.com/watch?v=36S8_7kRTx4
The xylophone consists of the following components:
- 28 short mallets of wood
- 28 MicroServo 9g SG90
- 4 support leags of wood (⌀22mm x 33mm)
- 8 support leags of wood (⌀22mm x 39mm)
- 7 support leags of wood (⌀22mm x 52mm)
- 1 wood stick (⌀6mm x 655mm)
- 1 wood stick (⌀6mm x 735mm)
- 20 screws
- 3 PCA9685 16-Channel 12 Bit PWM Driver
- 2 Arduino nano (it can be others models of Arduino)
- wooden Frame Model A
- Wooden Drame Model B
- 2 DC Plug 5,5 mm
- 2 DC Female 5,5 mm
In order to use this library in another project it must be installed. This is fairly straightforward as it can be installed with pip. Execute the following steps:
- Clone the repository.
$ git clone https://github.com/udesa-ai/xylophone.git
- Get in the local repository.
$ cd /path/to/xylophone
- Install the dependencies.
$ pip install -r requirements.txt
- Install it with pip
$ pip install .
The usage is also quite easy as it requires to interact with just a few classes. First we'll show you how to write a xylophone client that can send commands to the xylophone server.
The supported notes are:
# | Note | # | b |
---|---|---|---|
1 | C7 | C#7 | Cb7 |
2 | B6 | - | Bb6 |
3 | A6 | A#6 | Ab6 |
4 | G6 | G#6 | Gb6 |
5 | F6 | F#6 | - |
6 | E6 | - | Eb6 |
7 | D6 | D#6 | Db6 |
8 | C6 | C#6 | - |
9 | B5 | - | Bb5 |
10 | A5 | A#5 | Ab5 |
11 | G5 | - | - |
12 | F5 | - | - |
13 | E5 | - | Eb5 |
14 | D5 | D#5 | Db5 |
15 | C5 | C#5 | - |
16 | B4 | - | Bb4 |
17 | A4 | A#4 | Ab4 |
18 | G4 | G#4 | - |
from xylophone.client import XyloClient
from xylophone.xylo import XyloNote
# Create and store all the notes in a single list.
notes = [
XyloNote('A4', 1.5, 90),
XyloNote('A4', 2.3, 90),
XyloNote('G#6', 5.33333, 90),
XyloNote('A4', 10.01, 90),
]
# Instantiate the client with the IP address or host, and the port.
# Take a look at the server you spun up or ask someone else for this info.
client = XyloClient(host='localhost', port=8080)
# Load the notes
client.load(notes)
# Play the song
client.play()
You can use the example in here.
This tiny library provides two servers:
- A server that connects to a real xylophone by USB.
- A mock server that has the same interface as the real one but just acknowledges the sent message.
To instantiate a mock server it's also very easy as it requires to import only one class from this library.
# Import the mock server
from xylophone.server.server import MockXyloServer
# Instantiate the mock server and specify the IP/host and port that it's going to be using.
server = MockXyloServer(host='localhost', port=8080)
# Just start the server
server.start()
It's the same but it must be connected to a real robotic xylophone by USB.
# Import the xylo server
from xylophone.server.server import XyloServer
# Instantiate the xylo server and specify the IP/host and port that it's going to be using.
server = XyloServer(host='localhost', port=8080)
# Just start the server
server.start()
Note: Keep in mind that these scripts won't terminate unless you do it.