Itsy Bitsy M0 Express + Soundboard Help

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
BH32794
 
Posts: 63
Joined: Mon Nov 13, 2017 8:15 pm

Re: Itsy Bitsy M0 Express + Soundboard Help

Post by BH32794 »

Ok, by commenting out the 115200 baud and the reset, the trigger works and my lights work. I'm just having a hard time now triggering the audio files. What is the correct way to call the sound names? I thought it would be:

Serial1.print("T05.wav");


Code: Select all

#include "Adafruit_Soundboard.h"
#include <Adafruit_NeoPixel.h>


#define PIXEL_PIN     5   // Pin connected to neo pixels
#define FIREPIN       7   // Fire button 
#define PIXEL_COUNT   30  // Count of neo pixels
#define SWITCHPIN1    15  // Analog
#define SWITCHPIN2    16  // Analog
#define SWITCHPIN3    17  // Analog
#define SWITCHPIN4    18  // Analog


#define SFX_TX        1
#define SFX_RX        0
#define SFX_RST       3

Adafruit_Soundboard sfx = Adafruit_Soundboard(&Serial1, NULL, 3);

int buttonState = 0;
int modeState1 = 0;
int modeState2 = 0;
int modeState3 = 0;

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);



void setup() {
  
Serial1.begin(9600);

//  if (!sfx.reset()) {
//    Serial.println("Not found");
//    while (1);
//  }
//  Serial.println("SFX board found");
//  

strip.begin();
  strip.show();

pinMode(FIREPIN, INPUT_PULLUP);
pinMode(SWITCHPIN1, INPUT_PULLUP);
pinMode(SWITCHPIN2, INPUT_PULLUP);
pinMode(SWITCHPIN3, INPUT_PULLUP);
pinMode(SWITCHPIN4, INPUT_PULLUP);


  
}

void loop() {

uint8_t  i;

//Button Check
buttonState = digitalRead(FIREPIN);


  
//////////////////MODE1//////////////////////
  
if (buttonState == HIGH)
  {    
Serial1.print("T05.wav");

// Nice flash and fade out over about 3/4 of a second:
  animate_gradient_fill(strip,         
                      255, 255, 255,
                      255, 0, 0,
                      150);
  // Then flash from purple to nothing over a longer period.
  animate_gradient_fill(strip,         
                      255, 0, 0,
                      20, 0, 0,
                      150);
  animate_gradient_fill(strip,         
                      20, 0, 0,
                      0, 0, 0,
                      150);
                      

 
  
  } 
  
  else {
     strip.setPixelColor(i, 0,0,0); //Button not pressed, turn off pixels
     strip.show(); //Show no pixels
   
  }


//////////////////MODE2//////////////////////





//////////////////MODE3//////////////////////




  
 

}



// Linear interpolation of y value given min/max x, min/max y, and x position.
float lerp(float x, float x0, float x1, float y0, float y1)
{
  // Clamp x within x0 and x1 bounds.
  x = x > x1 ? x1 : x;
  x = x < x0 ? x0 : x;
  // Calculate linear interpolation of y value.
  return y0 + (y1-y0)*((x-x0)/(x1-x0));
}

// Get the color of a pixel within a smooth gradient of two colors.
uint32_t color_gradient(uint8_t start_r, // Starting R,G,B color
                        uint8_t start_g,
                        uint8_t start_b, 
                        uint8_t end_r,   // Ending R,G,B color
                        uint8_t end_g,
                        uint8_t end_b,
                        float pos)       // Position along gradient, should be a value 0 to 1.0
{
  // Interpolate R,G,B values and return them as a color.  
  uint8_t red   = (uint8_t) lerp(pos, 0.0, 1.0, start_r, end_r);
  uint8_t green = (uint8_t) lerp(pos, 0.0, 1.0, start_g, end_g);
  uint8_t blue  = (uint8_t) lerp(pos, 0.0, 1.0, start_b, end_b);
  return Adafruit_NeoPixel::Color(red, green, blue);
}

// Set all pixels to the specified color.
void fill_pixels(Adafruit_NeoPixel& pixels, uint32_t color)
{
  for (int i=0; i < pixels.numPixels(); ++i) {
    pixels.setPixelColor(i, color);
  }
  strip.show();
}

void animate_gradient_fill(Adafruit_NeoPixel& pixels, // NeoPixel strip/loop/etc.
                           uint8_t start_r,           // Starting R,G,B color
                           uint8_t start_g,
                           uint8_t start_b, 
                           uint8_t end_r,             // Ending R,G,B color
                           uint8_t end_g,
                           uint8_t end_b,
                           int duration_ms)           // Total duration of animation, in milliseconds
{
  unsigned long start = millis();
  // Display start color.
  fill_pixels(pixels, Adafruit_NeoPixel::Color(start_r, start_g, start_b));
  // Main animation loop.
  unsigned long delta = millis() - start;
  while (delta < duration_ms) {
    // Calculate how far along we are in the duration as a position 0...1.0
    float pos = (float)delta / (float)duration_ms;
    // Get the gradient color and fill all the pixels with it.
    uint32_t color = color_gradient(start_r, start_g, start_b, end_r, end_g, end_b, pos);
    fill_pixels(pixels, color);
    // Update delta and repeat.
    delta = millis() - start;
  }
  // Display end color.
  fill_pixels(pixels, Adafruit_NeoPixel::Color(end_r, end_g, end_b));
}

User avatar
BH32794
 
Posts: 63
Joined: Mon Nov 13, 2017 8:15 pm

Re: Itsy Bitsy M0 Express + Soundboard Help

Post by BH32794 »

I have also tried sfx.playTrack(“T05.wav”), sfx.playTrack(“T05WAV”) and sfx.playTrack(“T05”)

No luck yet. I feel like I’m close. Thoughts?

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Itsy Bitsy M0 Express + Soundboard Help

Post by adafruit_support_carter »

Have you wired the UG pin to GND to enable serial mode?
https://learn.adafruit.com/adafruit-aud ... ge-1512191

User avatar
BH32794
 
Posts: 63
Joined: Mon Nov 13, 2017 8:15 pm

Re: Itsy Bitsy M0 Express + Soundboard Help

Post by BH32794 »

Yes. I didn’t at first, but they are wired now. UG on the soundboard to a G on the itsy bitsy.

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Itsy Bitsy M0 Express + Soundboard Help

Post by adafruit_support_carter »

The menucommands example:
https://github.com/adafruit/Adafruit_So ... mmands.ino
has an option to "List files". If you run that sketch and list files, do the expected file names show up?

User avatar
BH32794
 
Posts: 63
Joined: Mon Nov 13, 2017 8:15 pm

Re: Itsy Bitsy M0 Express + Soundboard Help

Post by BH32794 »

Hi Carter,
You’ve sent this example before and I’ve looked at it several times. I need help identifying the exact code I need to include.

Do I need the whole code? Remember, this is not via a terminal - I will not be typing these commands in and working through serial monitor.

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Itsy Bitsy M0 Express + Soundboard Help

Post by adafruit_support_carter »

You would run the example as is.

It provides a menu interface for running the various commands for talking to the sound board over serial.

It would allow you to test basic functionality, like list the files, etc.

EDIT - actually not 100% as is, since you'll need to modify it slightly to use hardware serial.

Code: Select all

// pass the software serial to Adafruit_soundboard, the second
// argument is the debug port (not used really) and the third 
// arg is the reset pin
//Adafruit_Soundboard sfx = Adafruit_Soundboard(&ss, NULL, SFX_RST);
// can also try hardware serial with
Adafruit_Soundboard sfx = Adafruit_Soundboard(&Serial1, NULL, SFX_RST);

User avatar
BH32794
 
Posts: 63
Joined: Mon Nov 13, 2017 8:15 pm

Re: Itsy Bitsy M0 Express + Soundboard Help

Post by BH32794 »

I will test the example to make sure it’s working properly, but I will not be using a keyboard to call the menu commands. My trigger should be calling the sounds.

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Itsy Bitsy M0 Express + Soundboard Help

Post by adafruit_support_carter »

For testing, you can use the keyboard attached to the same PC used for programming the board. You'll interact through the Arduino's Serial Monitor.

User avatar
BH32794
 
Posts: 63
Joined: Mon Nov 13, 2017 8:15 pm

Re: Itsy Bitsy M0 Express + Soundboard Help

Post by BH32794 »

When testing the soundboard example, I cannot get the soundboard to show up in the serial monitor. It just says "Not Found."

Here is the code:

Code: Select all

/* 
  Menu driven control of a sound board over UART.
  Commands for playing by # or by name (full 11-char name)
  Hard reset and List files (when not playing audio)
  Vol + and - (only when not playing audio)
  Pause, unpause, quit playing (when playing audio)
  Current play time, and bytes remaining & total bytes (when playing audio)

  Connect UG to ground to have the sound board boot into UART mode
*/

//#include <SoftwareSerial.h>
#include "Adafruit_Soundboard.h"


// Choose any two pins that can be used with SoftwareSerial to RX & TX
#define SFX_TX 1
#define SFX_RX 0

// Connect to the RST pin on the Sound Board
#define SFX_RST 3

// You can also monitor the ACT pin for when audio is playing!

// we'll be using software serial
//SoftwareSerial ss = SoftwareSerial(SFX_TX, SFX_RX);

// pass the software serial to Adafruit_soundboard, the second
// argument is the debug port (not used really) and the third 
// arg is the reset pin
//Adafruit_Soundboard sfx = Adafruit_Soundboard(&ss, NULL, SFX_RST);
// can also try hardware serial with

Adafruit_Soundboard sfx = Adafruit_Soundboard(&Serial1, NULL, SFX_RST);

void setup() {
//  Serial.begin(115200);
Serial.println("Adafruit Sound Board!");
  
  // softwareserial at 9600 baud
Serial1.begin(9600);
  // can also do Serial1.begin(9600)

  if (!sfx.reset()) {
    Serial.println("Not found");
    while (1);
  }
  Serial.println("SFX board found");
}


void loop() {
  flushInput();
  
  Serial.println(F("What would you like to do?"));
  Serial.println(F("[r] - reset"));
  Serial.println(F("[+] - Vol +"));
  Serial.println(F("[-] - Vol -"));
  Serial.println(F("[L] - List files"));
  Serial.println(F("[P] - play by file name"));
  Serial.println(F("[#] - play by file number"));
  Serial.println(F("[=] - pause playing"));
  Serial.println(F("[>] - unpause playing"));
  Serial.println(F("[q] - stop playing"));
  Serial.println(F("[t] - playtime status"));
  Serial.println(F("> "));
  
  while (!Serial.available());
  char cmd = Serial.read();
  
  flushInput();
  
  switch (cmd) {
    case 'r': {
      if (!sfx.reset()) {
        Serial.println("Reset failed");
      }
      break; 
    }
    
    case 'L': {
      uint8_t files = sfx.listFiles();
    
      Serial.println("File Listing");
      Serial.println("========================");
      Serial.println();
      Serial.print("Found "); Serial.print(files); Serial.println(" Files");
      for (uint8_t f=0; f<files; f++) {
        Serial.print(f); 
        Serial.print("\tname: "); Serial.print(sfx.fileName(f));
        Serial.print("\tsize: "); Serial.println(sfx.fileSize(f));
      }
      Serial.println("========================");
      break; 
    }
    
    case '#': {
      Serial.print("Enter track #");
      uint8_t n = readnumber();

      Serial.print("\nPlaying track #"); Serial.println(n);
      if (! sfx.playTrack((uint8_t)n) ) {
        Serial.println("Failed to play track?");
      }
      break;
    }
    
    case 'P': {
      Serial.print("Enter track name (full 12 character name!) >");
      char name[20];
      readline(name, 20);

      Serial.print("\nPlaying track \""); Serial.print(name); Serial.print("\"");
      if (! sfx.playTrack(name) ) {
        Serial.println("Failed to play track?");
      }
      break;
   }

   case '+': {
      Serial.println("Vol up...");
      uint16_t v;
      if (! (v = sfx.volUp()) ) {
        Serial.println("Failed to adjust");
      } else {
        Serial.print("Volume: "); Serial.println(v);
      }
      break;
   }

   case '-': {
      Serial.println("Vol down...");
      uint16_t v;
      if (! (v=sfx.volDown()) ) {
        Serial.println("Failed to adjust");
      } else { 
        Serial.print("Volume: "); 
        Serial.println(v);
      }
      break;
   }
   
   case '=': {
      Serial.println("Pausing...");
      if (! sfx.pause() ) Serial.println("Failed to pause");
      break;
   }
   
   case '>': {
      Serial.println("Unpausing...");
      if (! sfx.unpause() ) Serial.println("Failed to unpause");
      break;
   }
   
   case 'q': {
      Serial.println("Stopping...");
      if (! sfx.stop() ) Serial.println("Failed to stop");
      break;
   }  

   case 't': {
      Serial.print("Track time: ");
      uint32_t current, total;
      if (! sfx.trackTime(&current, &total) ) Serial.println("Failed to query");
      Serial.print(current); Serial.println(" seconds");
      break;
   }  

   case 's': {
      Serial.print("Track size (bytes remaining/total): ");
      uint32_t remain, total;
      if (! sfx.trackSize(&remain, &total) ) 
        Serial.println("Failed to query");
      Serial.print(remain); Serial.print("/"); Serial.println(total); 
      break;
   }  

  }
}






/************************ MENU HELPERS ***************************/

void flushInput() {
  // Read all available serial input to flush pending data.
  uint16_t timeoutloop = 0;
  while (timeoutloop++ < 40) {
    while(Serial1.available()) {
      Serial1.read();
      timeoutloop = 0;  // If char was received reset the timer
    }
    delay(1);
  }
}

char readBlocking() {
  while (!Serial.available());
  return Serial.read();
}

uint16_t readnumber() {
  uint16_t x = 0;
  char c;
  while (! isdigit(c = readBlocking())) {
    //Serial.print(c);
  }
  Serial.print(c);
  x = c - '0';
  while (isdigit(c = readBlocking())) {
    Serial.print(c);
    x *= 10;
    x += c - '0';
  }
  return x;
}

uint8_t readline(char *buff, uint8_t maxbuff) {
  uint16_t buffidx = 0;
  
  while (true) {
    if (buffidx > maxbuff) {
      break;
    }

    if (Serial.available()) {
      char c =  Serial.read();
      //Serial.print(c, HEX); Serial.print("#"); Serial.println(c);

      if (c == '\r') continue;
      if (c == 0xA) {
        if (buffidx == 0) {  // the first 0x0A is ignored
          continue;
        }
        buff[buffidx] = 0;  // null term
        return buffidx;
      }
      buff[buffidx] = c;
      buffidx++;
    }
  }
  buff[buffidx] = 0;  // null term
  return buffidx;
}
/************************ MENU HELPERS ***************************/

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Itsy Bitsy M0 Express + Soundboard Help

Post by adafruit_support_carter »

Make sure connections are:
Itsy TX to Soundboard RX
Itsy RX to Soundboard TX

Can't tell for sure from photos, but look like maybe you have TX to TX and RX to RX.

Could just swap connections on your blue/green wires.

User avatar
BH32794
 
Posts: 63
Joined: Mon Nov 13, 2017 8:15 pm

Re: Itsy Bitsy M0 Express + Soundboard Help

Post by BH32794 »

HI Carter,

Good eye. Yes, they were mismatched.

However, after putting them in their proper pins, I still get "not found" :(

Is UG to ground, the ground of the itsy or the ground of the soundboard? Currently it's with the itsy.

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Itsy Bitsy M0 Express + Soundboard Help

Post by adafruit_support_carter »

Looks like you are not connecting the Itsy power to the Sound Board? In general, the GNDs should be connected between the two (as well as the PAM). And since you are targeting battery power for usage, the BAT pin should go to Vin on the Sound Board.

User avatar
BH32794
 
Posts: 63
Joined: Mon Nov 13, 2017 8:15 pm

Re: Itsy Bitsy M0 Express + Soundboard Help

Post by BH32794 »

I'm using the JST pads on the bottom as directed in the tutorial. I guess that's no longer correct?

JST + on Itsy to JST + on soundboard
JST - on Itsy to JST - on soundboard

The soundboard powers up when powered by a battery, but not when connected via usb

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Itsy Bitsy M0 Express + Soundboard Help

Post by adafruit_support_carter »

Ah, OK. Wires are underneath. Like here:
https://learn.adafruit.com/ray-gun-blas ... ard-977891

With that arrangement, the sound board will only be powered by battery. Do you have a battery connected while also connecting USB?

Locked
Please be positive and constructive with your questions and comments.

Return to “Itsy Bitsy Boards”