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

nao-petites-images2.jpg

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

arduino_logo.png

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

Python-logo-notext.svg.png

Downloading the Wheel:

  1. Download wheel → in group project classroom folder’s subfolder: libqi-python

https://drive.google.com/file/d/113uFfjsrl3hIYrZJcEhSqdDVW9Axn5Wp/view?usp=drive_link

  1. Install python 3.9
  2. Download python 3.9: https://www.python.org/downloads/
  3. Use VSCode to determine where it is installed
  4. 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

  1. Activate virtual environment and install wheel
  2. 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


  1. check install in python interpreter

python3

import qi

exit()

  1. Deactivate virtual environment

Deactivate

Creating the Wheel:

  1. 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

  1. 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)

  1. Conan Install

cd libqi-python

conan install . --build=missing -s build_type=Debug

  1. Cmake build

cmake --list-presets

#above line gets conan_string and string

cmake --preset [conan_string]

cmake --build --preset [conan_string]

  1. 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

  1. 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

  1. 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

  1. Install wheel

cd dist

pip3 install qi-3.1.5-cp39-cp39-macosx_14_0_arm64.whl

  1. 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

images.png
  1. Image of final circuit diagram.

  1. Explanation of how to wire the circuit on a breadboard.
  2. Break it down into wiring each component individually
  3. Include test code to check that the component is wired correctly and working.
  4. 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

960x0.jpeg
  1. Images of the 3D model

  1. Image of the print

  1. List any setup process required with step by step instructions on how to configure the printer to print your objects
  2. Open PrusaSlicer on computer
  3. Import design by uploading the .stl file
  4. Arrange all components on virtual print bed
  5. Under Print Settings, enable:
  6. Organic supports
  7. Proper layer height
  8. Adequate infill for strength
  9. Select PLA as the filament type
  10. Choose your print quality
  11. Click Slice Now to generate the G-code
  12. Save the G-code file to a USB drive
  13. Insert the USB drive into the printer
  14. Load PLA filament:
  15. Use the printer's menu to select Load Filament
  16. Insert PLA spool into the extruder
  17. Start the print:
  18. Navigate to Print from USB
  19. Select file and begin printing


Soldering the Prototyping Board

PE-Soldering-2.jpg
  1. 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

NAO V6 - TOP.jpeg
  1. 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.

  1. Follow software requirement steps to make sure you have the correct software downloaded to be able to run the rest of these instructions.
  2. Plug Nao V6 robot into your computer
  3. Turn on Nao V6 robot by holding down the chest button until it lights up
  4. Plug arduino circuit board into your computer
  5. Open Arduino IDE file and upload it to the board
  6. Connect arduino bluetooth to your computer in your computers bluetooth settings
  7. Once connected, you open your python file that will control the robot
  8. 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
  9. 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
  10. 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
  11. Run the file
  12. Listen to songs and dance with robot until you are finished where you will end the trial after 10 minutes
  13. Shut down robot and unplug from computer
  14. Unplug arduino from power
  15. Pack up robot and put arduino away


Potential Improvements

NAO-robot-lesson-motion-and-math-pose.jpeg
  1. Use wearable device wirelessly
  2. Refine song selection algorithm and dance moves
  3. Implement modes (calm vs energetic)
  4. Redesign/reprint parts of wearable device