Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 8 of 8

Thread: Play Music and Move Multiple Servos to The BPM

  1. #1
    Junior Member
    Join Date
    Jan 2020
    Posts
    3

    Play Music and Move Multiple Servos to The BPM

    Hi,

    I'd like to use a Teensy 4 or 3.6 (if it's better) to play music and coordinate multiple
    servo's movements with the BPM (tempo) or the peak of the music that is being heard.
    I know this is hard to do with fast music due to the latency of servos but
    maybe I could use slow BPM music ?
    Do I need FFT ?

    Appreciate your help.

  2. #2
    Senior Member
    Join Date
    Feb 2016
    Location
    Australia
    Posts
    271
    You could run your audio through the audio sheild and use the audio library to delay the music dynamically based on the bpm of the music to overcome the servo delay.
    You could use the audio library for fft and do beat detection.

  3. #3
    Junior Member
    Join Date
    Jan 2020
    Posts
    3
    Thanks, sounds good.
    Could you please elaborate your idea?
    Any articles or links a rookie like me can refer to for the hardware and software ?

  4. #4
    Senior Member
    Join Date
    Feb 2016
    Location
    Australia
    Posts
    271
    Teensy audio design tool and library info and best place to start:
    https://www.pjrc.com/teensy/td_libs_Audio.html

    Here’s what I did for beat and bpm detection:
    https://github.com/gibbedy/BeatDetec...ster/README.md

    Adding a delay to the audio and servo driving should be easy enough.

  5. #5
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,887
    In terms of the servos, it might be simpler to move the majority of the servo processing off to a secondary board that handles the low level details of doing the pulse management, so it doesn't interfere with the sound processing.

    For example:


    If you wanted the simplest way the servo controller, you can use the Adafruit feather adapter, and their i2c featherwing. Note, the longer Teensy 3.6 means you have to mount the Teensy underneath the feather adapter:

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,069
    The Audio and Servo libraries should work together well on Teensy 3.x and 4.0.

    Interrupt priority levels are used, so the Servo library gets the low latency interrupt response it needs to create accurate pulses. Audio processing runs at a lower priority level.

    You can also use PWMServo, to avoid any use of interrupts for the servo pulses.

  7. #7
    Junior Member
    Join Date
    Jan 2020
    Posts
    3
    Thank you all for your replies.

    My servos are already connected and controlled by an Arduino Uno and two PCA9685 - 16 channel boards.
    I thought of using Teensy 4 for playing the music and doing FFT, or maybe better to use a Teensy 3 since it has a SD card reader.

    I'm really a newbie, need to find out first if I should play the music through powered speakers then pick up the sound with a
    sound sensor module (no good since it will pick up any surrounding noise) or I can have my cake and it it too i.e. have a line for speakers and one for sound analysis.

  8. #8
    Junior Member
    Join Date
    Jan 2020
    Posts
    4
    Very few modification to the .ino file and I got beat detection library working with teensy 4.0.

    Thank you Gibbedy!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •