DJ Darcy: Real-Time Python Music Adaptation Through Physiological Feedback
by sigold26 in Circuits > Arduino
225 Views, 1 Favorites, 0 Comments
DJ Darcy: Real-Time Python Music Adaptation Through Physiological Feedback

Welcome to our DJ Darcy Instructable! In this guide, we’ll show you how to build DJ Darcy, an interactive robot DJ that selects music and dances based on real-time biometric feedback. Using a NAO V6 robot, a wearable sensor that tracks heart rate and motion, and a custom Python program, DJ Darcy responds to user activity to create an adaptive entertainment experience. This project combines robotics, programming, and sensor integration to explore how machines can dynamically engage with humans. Follow along to learn how to set up the hardware, code the system, and run your own responsive robot DJ!
Supplies

Pulse Sensor
https://www.amazon.com/Pulsesensor-Sensor-Arduino-Hardware-Development/dp/B0CJ83B2C6
- Power (+): Connect to 3.3V or 5V
- Ground (-): Connect to GND
- Signal (S): Connect to Analog Pin A0
$12.99
Adafruit Triple-Axis Accelerometer - MMA8451
https://www.adafruit.com/product/2019
- VIN: Connect to 3.3V or 5V power supply
- GND: Connect to Ground (GND)
- SCL: Connect to I2C Clock (SCL)
- SDA: Connect to I2C Data (SDA)
- INT1: Optional, connect to a digital I/O pin for interrupts
- INT2: Optional, connect to a digital I/O pin for interrupts
- ADDR: Connect to GND for I2C address 0x1C; leave unconnected or pull to 3.3V for address 0x1D
$7.95
Adafruit Feather 32u4 Bluefruit LE with Headers
https://www.adafruit.com/product/3379
- Microcontroller: ATmega32u4 running at 8MHz, 3.3V logic/power
- Power Supply: USB or 3.7V Lithium polymer battery (LiPo)
- Digital I/O Pins: 20
- Analog Input Pins: 10
- PWM Channels: 7
- Serial Communication: 1x UART, 1x SPI, 1x I2C
- USB Native Support: Includes built-in USB bootloader and serial debugging
- Battery Monitoring: Built-in 100mA LiPo charger with battery voltage monitoring
- Bluetooth Module: Nordic nRF51822, supports UART RX/TX communication over BLE
$31.95
Adafruit Bluefruit LE UART Friend
https://www.adafruit.com/product/2479
- Microcontroller: ARM Cortex M0 running at 16MHz
- Flash Memory: 256KB
- SRAM: 32KB
- Transport: UART @ 9600 baud with HW flow control (CTS+RTS required)
- Voltage Compatibility: 5V-safe inputs, operates at 3.3V logic
- Bootloader: Supports OTA firmware updates
- Pins:
- VIN: Connect to 3.3V or 5V power supply
- GND: Connect to Ground (GND)
- RXI: Connect to TX (Transmit) pin of microcontroller
- TXO: Connect to RX (Receive) pin of microcontroller
- CTS: Connect to Clear to Send (CTS) pin of microcontroller (optional, for flow control)
- RTS: Connect to Ready to Send (RTS) pin of microcontroller (optional, for flow control)
- MODE: Connect to a digital I/O pin for mode switching (optional)
- DFU: Connect to a digital I/O pin for firmware updates (optional)
$17.50
Adafruit Tactile Button Switch
https://www.adafruit.com/product/367?gQT=1
- One leg: Connect to a digital I/O pin
One leg: Connect to GND
- Third leg: Connect to - 5V through a pull-up resistor (1k) or use INPUT_PULLUP in code
- Optional: External resistor can be replaced by using the internal pull-up (pinMode(pin, INPUT_PULLUP))
$2.50
Also need: Softbank Robotics NAO robot, 1k resistor, wires, prototyping board, soldering iron and solder
Software Requirements

Downloading the Wheel:
- Download wheel → in group project classroom folder’s subfolder: libqi-python
https://drive.google.com/file/d/113uFfjsrl3hIYrZJcEhSqdDVW9Axn5Wp/view?usp=drive_link
- Install python 3.9
- Download python 3.9: https://www.python.org/downloads/
- Use VSCode to determine where it is installed
- Create a virtual environment
#use the correct path above for creating the virtual environment
pip install virtualenv
python -m virtualenv --python=/usr/bin/python3 darcy39
python -m virtualenv --python=/usr/local/bin/python3 darcy39 #kat
- Activate virtual environment and install wheel
- put wheel in same folder as virtual environment
source darcy39/bin/activate
pip3 install qi-3.1.5-cp39-cp39-macosx_14_0_arm64.whl
- check install in python interpreter
python3
import qi
exit()
- Deactivate virtual environment
Deactivate
Creating the Wheel:
- Clone your libraries and install cmake
git clone https://github.com/aldebaran/libqi-python.git
git clone https://github.com/aldebaran/libqi.git
brew install cmake
- Setup conan
#cd into virtual environment folder
source [YOUR_VENV]/bin/activate
pip install --upgrade conan
conan profile detect
conan export "$HOME/libqi" --version "4.0.1"
# [YOUR_PATH] is whatever directory you put libqi in (step 1)
- Conan Install
cd libqi-python
conan install . --build=missing -s build_type=Debug
- Cmake build
cmake --list-presets
#above line gets conan_string and string
cmake --preset [conan_string]
cmake --build --preset [conan_string]
- Test build (passed 79/80 tests?)
deactivate
source build/[string]/generators/conanrun.sh
ctest --preset [conan_string] --output-on-failure
source build/[string]/generators/deactivate_conanrun.sh
- Install project
cd ..
#reactivate your venv
source [YOUR_VENV]/bin/activate
cd libqi-python
cmake --install build/[string] \
--component Module --prefix ~/my-libqi-python-install
- Make wheel
conan install . --build=missing -c tools.build:skip_test=true
pip install -U build
cmake --list-presets
#gets conan_release_string & release_string
python -m build --config-setting cmake.define.CMAKE_TOOLCHAIN_FILE=$PWD/build/[release_string]/generators/conan_toolchain.cmake
- Install wheel
cd dist
pip3 install qi-3.1.5-cp39-cp39-macosx_14_0_arm64.whl
- Check install in python interpreter
python3
import qi
exit()
After Creating the Wheel:
(Install these in the same virtual environment)
pip install pyserial
pip install qi
Create Python Program:
Write a python program to connect to the robot using its IP address (you can find the IP address by pressing the robots chest button once).
Downloading Arduino IDE Software:
https://www.arduino.cc/en/software/
Adafruit Bluefruit Libraries:
Adafruit_BluefruitLE_nRF51
Adafruit_BLE
Adafruit_Sensor
SoftwareSerial
Download these from same link as IDE software
Circuit Assembly

- Image of final circuit diagram.
- Explanation of how to wire the circuit on a breadboard.
- Break it down into wiring each component individually
- Include test code to check that the component is wired correctly and working.
- Include images of the circuit and the circuit diagram after each step.
**Note: Could not take pictures of circuit itself because I already soldered it**
Pulse sensor
const int heartPin = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
int signal = analogRead(heartPin);
Serial.println(signal);
delay(10); // small delay for readability
}
Accelerometer
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_Accel.h>
Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(12345);
void setup() {
Serial.begin(9600);
if (!accel.begin()) {
Serial.println("Accelerometer not detected.");
while (1);
}
}
void loop() {
sensors_event_t event;
accel.getEvent(&event);
Serial.print("X: "); Serial.print(event.acceleration.x); Serial.print(" m/s^2 ");
Serial.print("Y: "); Serial.print(event.acceleration.y); Serial.print(" m/s^2 ");
Serial.print("Z: "); Serial.print(event.acceleration.z); Serial.println(" m/s^2");
delay(500);
}
Button
const int buttonPin = 3;
void setup() {
Serial.begin(9600);
pinMode(buttonPin, INPUT); // external pull-down resistor used
}
void loop() {
int buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
Serial.println("Button pressed");
} else {
Serial.println("Button not pressed");
}
delay(200);
}
Bluetooth
#include <SPI.h>
#include "Adafruit_BLE.h"
#include "Adafruit_BluefruitLE_SPI.h"
#include "BluefruitConfig.h"
Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);
void setup() {
Serial.begin(115200);
if (!ble.begin(VERBOSE_MODE)) {
Serial.println("Couldn't find Bluefruit module. Check wiring!");
while (1);
}
ble.factoryReset();
ble.echo(false);
ble.info();
}
void loop() {
}
3D Printing

- Images of the 3D model
- Image of the print
- List any setup process required with step by step instructions on how to configure the printer to print your objects
- Open PrusaSlicer on computer
- Import design by uploading the .stl file
- Arrange all components on virtual print bed
- Under Print Settings, enable:
- Organic supports
- Proper layer height
- Adequate infill for strength
- Select PLA as the filament type
- Choose your print quality
- Click Slice Now to generate the G-code
- Save the G-code file to a USB drive
- Insert the USB drive into the printer
- Load PLA filament:
- Use the printer's menu to select Load Filament
- Insert PLA spool into the extruder
- Start the print:
- Navigate to Print from USB
- Select file and begin printing
Soldering the Prototyping Board

- Images and instructions explaining step by step how to move the electronic components from the breakout board to the prototyping board, testing the code again after each step
Here is the breakout board prior to moving components to the prototyping board.
I started by soldering the microcontroller to the top of the prototyping board using two 14 pin headers.
I soldered an 8 pin header to the prototyping board for the accelerometer, leaving the sensor itself unconnected at this stage. I soldered wires from the appropriate header pins to the Arduino: SCL to A5, SDA to A4, GND to GND, and VIN to 5V. I created solder joints underneath the board between each header pin and its corresponding wire. (I did this for each pin/wire connection moving forward)
I soldered a 9 pin header to the prototyping board for the Bluetooth module, again leaving the component itself unconnected at this stage. I soldered wires from the appropriate header pins to the Arduino: IRQ to D7, CS to D8, MOSI to D11, MISO to D12, SCK to D13, GND to GND, and VIN to 5V.
For the button, I used two 5 pin headers, although only 3 pins were necessary. I soldered one leg (terminal 1) to D3 on the Arduino. The diagonal leg (terminal 3) was soldered to a 1k resistor, which was then connected to GND. The adjacent leg on the same side (terminal 4) was connected to 5V.
For the pulse sensor, I did not use headers (there were no single pin headers). I soldered GND to GND, VIN to 5V, and the signal pin to A0 on the Arduino.
Finally, I cleaned up any excess solder, connected the accelerometer and Bluetooth module to their respective headers and attached the prototyping board to the wearable device.
Operating Instructions

- Step by step explanation of how to setup the system, how it works, and how it would be used
Plug in Arduino to Power Bank.
Connect to the computer via bluetooth then put your cursor in the terminal and run the python program. This will play songs and have the robot dance based on user input.
- Follow software requirement steps to make sure you have the correct software downloaded to be able to run the rest of these instructions.
- Plug Nao V6 robot into your computer
- Turn on Nao V6 robot by holding down the chest button until it lights up
- Plug arduino circuit board into your computer
- Open Arduino IDE file and upload it to the board
- Connect arduino bluetooth to your computer in your computers bluetooth settings
- Once connected, you open your python file that will control the robot
- Once the robot is woken up and makes a noise, click its chest button once and it will tell you the IP address. You then need to edit the IP address in your python file to be able to connect to the robot
- Once the robot is on and the arduino is connected, place your cursor in the terminal where you CD into the correct folder and the virtual environment is still on
- Strap the arduino wearable device onto your arm (microcontroller on the inside of your arm) with the finger piece (and pulse sensor) on your index finger. This will collect your biometric data
- Run the file
- Listen to songs and dance with robot until you are finished where you will end the trial after 10 minutes
- Shut down robot and unplug from computer
- Unplug arduino from power
- Pack up robot and put arduino away
Potential Improvements

- Use wearable device wirelessly
- Refine song selection algorithm and dance moves
- Implement modes (calm vs energetic)
- Redesign/reprint parts of wearable device