QC

MIDI piano keyboard

Arduino meets music!

Devices and components

10 connecting wires 150 mm male

Arduino MKR WiFi 1010

Colorful round touch button switch

Materials and tools

Software and tools

Arduino IDE

Project description

Introduction

pip

pip install mido

pip3 install python-rtmidi

Introduction ~ MIDI Note Number

0

127

60

440 Hz

f = 440 * 2^((n-69)/12)

Operation ~ MIDI writing

USBMIDI_Write

read-MIDI-device.py

Operation ~ MIDI Playback

USBMIDI_Read

write-to-device.py

Operation ~ MIDI Loop

write-to-device.py

read-MIDI-device.py

USBMIDI_Loop

The project ~ MIDI keyboard

MIDI_Keyboard

write to device.py

python

Write MIDI note #60 ON and OFF to a USB device

1#!/usr/bin/env python3
2
3# ~~~ write-to-device.py ~~~
4
5import mido # pip install mido
6import time
7
8if __name__ == "__main__":
9 # get the list of all the MIDI devices conneted
10 input_names = mido.get_input_names()
11
12 # choose the name of the USB MIDI device
13 # you want to send messages to
14 usb_midi_device_name = input_names[1]
15
16 try:
17 # open the selected MIDI output port
18 with mido.open_output(usb_midi_device_name) as port:
19 print(f"Sending MIDI messages to {usb_midi_device_name}")
20
21 # send Note On message
22 note_on = mido.Message('note_on', note=60, velocity=64, channel=0)
23 port.send(note_on)
24 print(f"Note On sent: {note_on}")
25
26 # wait for a short duration
27 time.sleep(1)
28
29 # send Note Off message
30 note_off = mido.Message('note_off', note=60, velocity=64, channel=0)
31 port.send(note_off)
32 print(f"Note Off sent: {note_off}")
33
34 except KeyboardInterrupt:
35 print("Exiting...")

read-MIDI-device.py

python

Play from a MIDI device.

1#!/usr/bin/env python3
2
3# ~~~ read-MIDI-device.py ~~~
4
5import mido
6
7if __name__ == "__main__":
8 # list available MIDI ports
9 input_names = mido.get_input_names()
10 print(">>> available MIDI ports:")
11 print(input_names)
12
13 # select desired port
14 # i.e. "Arduino MKR WiFi 1010:Arduino MKR WiFi 1010 MIDI 1 20:0"
15 input_port_name = input_names[1]
16 inport = mido.open_input(input_port_name)
17
18 # loop to receive messages
19 while True:
20 for message in inport.iter_pending():
21 print(message)

Downloadable files

Project outline

Project diagram with Arduino MKR WiFi-1010

piano-clavier.png

Documentation

MIDIUSB

Allows Arduino to act as a MIDI instrument via USB.

https://github.com/arduino-libraries/MIDIUSB

Work with messages and MIDI ports.

https://github.com/mido/mido




Note: Content and images are from: https://projecthub.arduino.cc/, with some modifications.
If you want it removed due to copyright reasons, please leave a comment. Thank you.
I want to share this article more widely so that everyone knows about Arduino and your project.

SendData

Điều khiển trạng thái qua Firebase Trạng thái hiện tại: Đang tải... ĐỔI TRẠNG THÁI