audio, servos, leds and sequencing

Status
Not open for further replies.

5shekel

Member
NOTE: there is a typo in the audio addon page "SCLK and MOSI are used at alternate locatoins"

TLDR : can i serial read (one time) from the audio addon SD card to the teensy AND stream music to the encoder chip?

im setting up a show control teensy. which controls
1 x serial pololu maestro servo controller
7 x i2c neopixel rings.
1 x SD wav audio

to get the various trigger timings right im using Vixen* (windows) light sequencer i got of Akibha's lighting guide.sequencer (vixen) send a stream of serial and i want to play it back from the teensy. im getting the audio board for the audio encoder and the SDcard

*vixen is ok, but windows and i rather use linux for the dev. any options?
something that i can slap audio channel and triger stuff easliy > vixen gui > http://i.imgur.com/L9IfAO6.png
 
Yes, you can use Serial1 while the audio and SD card are in use.

But Serial2 and Serial3 are unusable, because the audio shield requires pin 7 (conflicting with Serial3) and the SD card chip select is wired to pin 10 (conflicting with Serial2).

Neopixels are tricky. If you use Adafruit_Neopixel, that library disables all interrupts. If you update only a short strip of LEDs, it can work. But a long strip will require turning interrupts off for too long, which can disrupt the audio. Short strips can usually work.

Also, please be aware a 3 to 5V buffer chip is usually needed. Most Neopixels can't work with a 3V signal when they run from 5V power.
 
Yes, you can use Serial1 while the audio and SD card are in use.
i'll clarify my question. i want to read from the SD card and pass that into an int array on the teensy.
to store my sequence on the sd card and read it on startup. i think ill just hardcode it in an the array.

Neopixels are tricky. If you use Adafruit_Neopixel, that library disables all interrupts. If you update only a short strip of LEDs, it can work. But a long strip will require turning interrupts off for too long, which can disrupt the audio. Short strips can usually work.

Also, please be aware a 3 to 5V buffer chip is usually needed. Most Neopixels can't work with a 3V signal when they run from 5V power.

your comments about the audio+LEDs came just as my audio board addon arrived. i'm afraid its true...
my WS2812B stutter with fast fades on 32pcs. im currently not using the neopixel rings but just some noname breakouts http://i.imgur.com/nXHc4Y4.png.

so i guess i'm limited to on/off signals to the LEDs. or i might go for a cheapy serial controlled mp3 module. i actually just need to play a tune, no FFT or anything. but im not sure those cheap mp3 controllers will tell me when the track is ready to loop...

Code:
//here is the fastled.io cycle example laced + the audio board wav tester

#include "FastLED.h"

//uncomment all for audio
/*
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

AudioPlaySdWav           playSdWav1;
AudioOutputI2S           i2s1;
AudioConnection          patchCord1(playSdWav1, 0, i2s1, 0);
AudioConnection          patchCord2(playSdWav1, 1, i2s1, 1);
AudioControlSGTL5000     sgtl5000_1;
*/

#define NUM_LEDS 32
#define DATA_PIN 2
CRGB leds[NUM_LEDS];

void setup() {
  Serial.begin(57600);
  Serial.println("resetting");
  LEDS.addLeds<WS2812B, DATA_PIN>(leds, NUM_LEDS);
  LEDS.setBrightness(84);
/*
  AudioMemory(8);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.5);
  SPI.setMOSI(7);
  SPI.setSCK(14);
  if (!(SD.begin(10))) {
    while (1) {
      Serial.println("Unable to access the SD card");
      delay(500);
    }
  }
  delay(1000);
*/
}

void fadeall() {
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i].nscale8(250);
  }
}

void loop() {
  /*
  if (playSdWav1.isPlaying() == false) {
    playSdWav1.play("sosimple.wav");
    delay(10); // wait for library to parse WAV info
  }
*/
  static uint8_t hue = 0;
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = CHSV(hue++, 255, 255);
    // Show the leds
    FastLED.show();
    fadeall();
    delay(10);
  }
  for (int i = (NUM_LEDS) - 1; i >= 0; i--) {
    leds[i] = CHSV(hue++, 255, 255);
    FastLED.show();
    fadeall();
    delay(10);
  }
}
 
Last edited:
actually neopixel library fades with no stutter (finger crossed for 204 leds)

Code:
// neopixel lib starndtest + audio board tester for teensy
//uncomment all for audio
/*
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

AudioPlaySdWav           playSdWav1;
AudioOutputI2S           i2s1;
AudioConnection          patchCord1(playSdWav1, 0, i2s1, 0);
AudioConnection          patchCord2(playSdWav1, 1, i2s1, 1);
AudioControlSGTL5000     sgtl5000_1;
*/
#include <Adafruit_NeoPixel.h>
#define PIN 2
Adafruit_NeoPixel strip = Adafruit_NeoPixel(32, PIN, NEO_GRB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.



void setup() {
  /*
  AudioMemory(8);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.5);
  SPI.setMOSI(7);
  SPI.setSCK(14);
  if (!(SD.begin(10))) {
    while (1) {
      Serial.println("Unable to access the SD card");
      delay(500);
    }
  }
  delay(1000);
*/
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  /*
  if (playSdWav1.isPlaying() == false) {
    playSdWav1.play("sosimple.wav");
    delay(10); // wait for library to parse WAV info
  }
  */
  rainbow(20);
}


void rainbow(uint8_t wait) {
  uint16_t i, j;

  for (j = 0; j < 256; j++) {
    for (i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for (j = 0; j < 256 * 5; j++) { // 5 cycles of all colors on wheel
    for (i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}


// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if (WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if (WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
 
Status
Not open for further replies.
Back
Top