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

Itsy Bitsy M0 Express + Soundboard Help

Post by BH32794 »

Hi there,

After hours of trying to rummage through tutorials and other websites, I think I've finally reached my point where I need to ask for help.

I'm trying to replicate the ray gun tutorial found here:
https://learn.adafruit.com/ray-gun-blaster

Taking what I've learned in this tutorial, I'm trying to apply it to an E11 stormtrooper blaster.

I have an Itsy Bitsy M0 Express with a lipo backpack (not a pro trinket as per the tutorial), and a 16mb audio FX soundboard.

Originally I was going to use the trigger pins on the soundboard to create sounds, however, I have the opportunity to get more in depth with different fire modes, and I'd like to use serial communication to trigger the sounds instead of running individual wires to each pin on the soundboard.

First off - I'm hoping that this is how serial communication works. I haven't used it much. It's possible for the itsy bitsy to tell the soundboard which files to play (similar to a DFplayer mini) correct? Otherwise, I'll just use a DFplayer.

My main issue is that I've run into is that the sketch example for the soundboard calls on SoftwareSerial.h, and I'm getting the error "No such file or directory." I read somewhere that I needed a different library for SAMD boards, but I can't find it. What do I need to include to run softwareserial.h on an itsy bitsy?


Thanks for you help! Much appreciated.

Cheers,
Aaron

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 »

Try switching the code to use hardware serial.

Connect to TX/RX pins on the Itsy:
https://learn.adafruit.com/introducing- ... m0/pinouts
and comment out the software serial part of the sketch and uncomment the hardware serial:
https://github.com/adafruit/Adafruit_So ... ds.ino#L33

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

Re: Itsy Bitsy M0 Express + Soundboard Help

Post by BH32794 »

Thanks Carter,

I’ll give that a shot and report back.

Will that allow me to command the soundboard from the itsy bitsy? Is there a library of actions to command the sound board? I’ve only seen the serial commands.

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 »

Will that allow me to command the soundboard from the itsy bitsy?
Yes
Is there a library of actions to command the sound board? I’ve only seen the serial commands.
The serial commands are how you control the sound board. There's info here on the various commands:
https://learn.adafruit.com/adafruit-aud ... io-control

The Arduino library wraps those lower level serial commands into more convenient methods, like playTrack().
https://github.com/adafruit/Adafruit_So ... mmands.ino

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

Re: Itsy Bitsy M0 Express + Soundboard Help

Post by BH32794 »

Thanks Carter,

I’ve seen the example before, but the commands are for printing into the serial monitor, correct?

So to command the playback, I would just need to write:

sfx.playTrack(name)

No serial.print or anything like that.


Reporting back might be a bit later…..have to order another board as the jst pads fell off from the bottom of the board. Ugh.

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 »

Serial.print() will print to the Serial Monitor.
Serial1.print() will output on the hardware serial port - which is how you talk to the sound board. But the Arduino library does that communication for you behind the scenes. The library knows to use Serial1, as you pass it in when setting things up:

Code: Select all

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 »

Hi Carter,

Sorry for the late report - had family visiting for vacation.

Ok, so I removed:
#include <SoftwareSerial.h>

...Which was giving me the issue before, and I hardwired the the TX and RX pins from the Itsy Bitsy to the Soundboard. They are on jumper pins so that I can easily disconnect.

However, when trying to compile the code, I continue to get errors:

On this line:
SoftwareSerial ss = SoftwareSerial(SFX_TX, SFX_RX);
I get the error:
'SoftwareSerial' does not name a type; did you mean 'HardwareSerial'?

And if I remove that line, I get another error.

On this line:
Adafruit_Soundboard sfx = Adafruit_Soundboard(&Serial1, NULL, SFX_RST);
I get the error:
'SFX_RST' was not declared in this scope; did you mean 'SFX_RX'?

I am working in Arduino IDE. Am I supposed to be coding in CircuitPython? I'm really unsure why the code is not working. It's my first time working with an Itsy Bitsy and I'm regretting not going with the Nanos that I'm more familiar with.

Here is my code:

Code: Select all

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


#define PIXEL_PIN     5   // Pin connected to neo pixels
#define FIREPIN       19  // Fire button (Analog)
#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

SoftwareSerial ss = SoftwareSerial(SFX_TX, SFX_RX);
Adafruit_Soundboard sfx = Adafruit_Soundboard(&Serial1, NULL, SFX_RST);

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() {
....
cont.

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 »

Comment out that line by adding // in front like this:

Code: Select all

// SoftwareSerial ss = SoftwareSerial(SFX_TX, SFX_RX);

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

Re: Itsy Bitsy M0 Express + Soundboard Help

Post by BH32794 »

Commented out the line requested. It seems to compile now, but nothing triggers.

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 »

Would need to see complete code listing to investigate further.

Are you using the library example?
https://github.com/adafruit/Adafruit_So ... mmands.ino

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,

Please see the attached code. Currently, the code only needs the blaster to fire based on the trigger, and then cue the neopixels, and soundboard. Once I get this down, I want to have different modes that fire different types of neopixels and different sounds. This will be via a 3 way rotary switch - one of those weird ones that doesn't have a common ground. On the M0, they will be A1-A4. Essentially I just took the code from the ray gun tutorial.

I got it working before, but that was before I wanted to switch to serial communication to the soundboard.

Everything powers up, and if I trigger the soundboard manually, it does play sound through the amp/speaker.


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() {
  
  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");
  
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 (modeState1 == HIGH && buttonState == HIGH)
if (buttonState == LOW)
  {    
// 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//////////////////////




  
 
  // More complex flash between two colors and fade out using multiple calls.
  // First flash from red to purple over a short period
  //animate_gradient_fill(strip,         // NeoPixel strip/loop/etc. object.
  //                      255, 128, 128, // Starting R,G,B color.
  //                      0, 0, 0,       // Ending R,G,B color (0,0,0 for black or off).
  //                      500);          // Total duration of the animation in milliseconds.
  //
  //animate_gradient_fill(strip,         
  //                    255, 0, 0,
  //                    128, 0, 255,
  //                    200);
  // Then flash from purple to nothing over a longer period.
  //animate_gradient_fill(strip,         
  //                      128, 0, 255,
  //                      0, 0, 0,
  //                      400);                  
  // Delay to see different animations.
  //delay(1000);
}



// 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));
}
Last edited by BH32794 on Tue Aug 02, 2022 6:41 pm, edited 1 time in total.

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

Re: Itsy Bitsy M0 Express + Soundboard Help

Post by BH32794 »

Please see the enclosed images of my wiring.
Attachments
image2.jpeg
image2.jpeg (364.15 KiB) Viewed 223 times
image1.jpeg
image1.jpeg (445.63 KiB) Viewed 223 times
image0.jpeg
image0.jpeg (735.51 KiB) Viewed 223 times

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 »

There's nothing in the code doing anything with the Sound Board other than calling reset. See the library example linked above for a more complete example of how to make the various calls for controlling the board over serial.

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

Re: Itsy Bitsy M0 Express + Soundboard Help

Post by BH32794 »

My neopixels are not lighting up which tells me the trigger is not activating. I removed the call to the file (T05.wav) to make sure it wasn’t interfering.

As I’ve said before, I don’t know how to work serial (clearly). So I’m not sure what I’m supposed to include or not include. I’ve looked at your example several times - am I to include all of this?

When I started using serial, my trigger stopped working. Any help getting that fixed first would be appreciated. Is there something wrong with my wiring?

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 wondering if I have my trigger wired correctly. As per the tutorial, I had it connected to the soundboard. But as I’m now going serial, I have a ground connected from the itsy to the trigger, and another going to the fire pin (7). There is a third cable - should I be connecting this to 5v?

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

Return to “Itsy Bitsy Boards”