0

Running Audio FX Sound Board through Trinket Pro 5V
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Running Audio FX Sound Board through Trinket Pro 5V

by knoxvilles_Joker on Wed Mar 22, 2017 10:46 pm

I have this board:
https://www.adafruit.com/products/2220
with this for an external speaker:
https://www.adafruit.com/product/987
and this for a main power switch:
https://www.adafruit.com/products/1400
and am attempting to pipe it through a Trinket Pro 5V ( have a 3V model if that is neccessary)
https://www.adafruit.com/products/2000


In the end this code base is what I am trying to get working
https://github.com/outcry27/crybabyFX/b ... .0.ino#L57
and in action like this:
https://www.youtube.com/watch?v=OA59IY1iFHg

To start with I have time t the LED counter and triggers with that to work through the Trinket, no real issues there.
Safety and Trigger buttons work with that piece. For the sake of argument and discussion here this piece is a none issue and not even hooked up.

Taking it one step at a time I focused on the FX board. going through your walk through step by step I can GPIO trigger the sounds. I did verify that it will work with the MAX98306 amplifier.

I also verified that it will detect if the headphone is plugged in and cut off the external speaker outs if a head phone is plugged in. Good design feature, I like it.

Your sound pack was a veritible big helper. This allowed me to verify everything works when it is not in UART mode.

To test things I downloaded the adafruit soundboard library.
I then uploaded the menu commands sketch to the trinket.

I have designated these pinouts on the sketch:
// 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 5

On trinket:
Bat+ > out on power switch
GND > GND on power switch
5 > RST on FX board
TX > RX on fx board
RX > RX on fx board (have tried reversing with no change

On FX board:
RST > 5 on Trinket
VIN > out on power switch
GND > GND
UG > GND
TX > RX on Trinket
RX > TX on Trinket
GND > L- on amp
L > L+ on amp
R > R+ on amp
GND > R- on amp

On Amplifier Board:
VDD > Out on Power Switch
GND > Gnd
r+ > R on FX board
r- > GND next to R on FX board
l+ > L on FX board
l- > GND next to L on FX board

rout- > speaker -
rout+ > speaker +

on Power switch:
Out:
VIN on FX Board
Bat+ on Trinket
VDD on amplifier
In:
Battery + lead
G:
Battery - lead
main ground bar on breadboard
G on Trinket
GND on FX board

The issue I am having is that I am not able to get the UART mode to work correctly. Does anyone have any thoughts on any settings that might be at fault here?

knoxvilles_Joker
 
Posts: 96
Joined: Wed Mar 01, 2017 9:15 pm

Re: Running Audio FX Sound Board through Trinket Pro 5V

by knoxvilles_Joker on Wed Mar 22, 2017 10:49 pm

With the FTDI connected I am not getting FX board dedected message. I will occasionally get Board dedected message and then it lists how many files are there, and then it stops.

At least I know how I am going to get my predator sound board working so the time spent thus far is not a loss at all.

knoxvilles_Joker
 
Posts: 96
Joined: Wed Mar 01, 2017 9:15 pm

Re: Running Audio FX Sound Board through Trinket Pro 5V

by knoxvilles_Joker on Thu Mar 23, 2017 4:42 am

I changed rx and tx to 5 and 6 and didn't swap rx-tx. Then I got communication. I think it has something to do with 0 and 1 being used with USB and FTDI communications.

I have suspicions that rx and tx on the trinket pro 5V are not usable for serial communications in the needed manner here.

knoxvilles_Joker
 
Posts: 96
Joined: Wed Mar 01, 2017 9:15 pm

Re: Running Audio FX Sound Board through Trinket Pro 5V

by adafruit_support_mike on Thu Mar 23, 2017 5:02 am

The hardware Serial port on a Pro Trinket does connect to the TX/RX signals used by an FTDI Friend.

If you're using the FTDI Friend to program the Pro Trinket, or to handle communication with the Arduino IDE's Serial Monitor, pins 0 and 1 won't be free to communicate with the FX Board.

If the Pro Trinket is running as a standalone device (no connection to the Serial Monitor), pins 0 and 1 will be free for other uses.

adafruit_support_mike
 
Posts: 59401
Joined: Thu Feb 11, 2010 2:51 pm

Re: Running Audio FX Sound Board through Trinket Pro 5V

by knoxvilles_Joker on Thu Mar 23, 2017 6:09 am

OK, I can get the boards connected. Still trying to figure out a good way to serial trigger individual sounds. IN the old code base I am using this is commented out:

//this needs to be fixed... commented out for now
/*void playSound(int s);
void playSound(char *name) {
pinMode(s, OUTPUT);
delay(100);
pinMode(s, INPUT);
//Serial.print("P"name"\n");
}*/

and references to it are seen periodically
such as here:
//playSound(clickSoundPin);
and are commented out.

If I go through the menu sounds example it looks like this invokes playing a file directly:
Serial.print(name); Serial.print("\"");

I go through soundboard.h and find this:
boolean playTrack(uint8_t n);
boolean playTrack(char *name);
boolean pause(void);
boolean unpause(void);
boolean stop(void);
private:
Stream *stream; // -> sound board, e.g. SoftwareSerial or Serial1
Stream *debug; // -> host, e.g. Serial

and soundboard.cpp:
boolean Adafruit_Soundboard::playTrack(char *name) {
while (stream->available())
boolean Adafruit_Soundboard::playTrack(uint8_t n) {
while (stream->available())
stream->read();

stream->print("#"); stream->println(n);


And per the walkthrough write up:
All Adafruit Soundboards can be used in either UART mode or GPIO (button) mode - but not at the same time!
Basically it stands alone, or is a slave.


So I am thinking if I do playTrack(T00.wav); will invoke playing T00.wav
I try that and get:
T00 was not declared in scope

Any thoughts on an easy way to invoke playing of sounds from the FX board in UART mode from button triggers coming from the Trinket Pro?

knoxvilles_Joker
 
Posts: 96
Joined: Wed Mar 01, 2017 9:15 pm

Re: Running Audio FX Sound Board through Trinket Pro 5V

by knoxvilles_Joker on Thu Mar 23, 2017 6:11 am

adafruit_support_mike wrote:The hardware Serial port on a Pro Trinket does connect to the TX/RX signals used by an FTDI Friend.

If you're using the FTDI Friend to program the Pro Trinket, or to handle communication with the Arduino IDE's Serial Monitor, pins 0 and 1 won't be free to communicate with the FX Board.

If the Pro Trinket is running as a standalone device (no connection to the Serial Monitor), pins 0 and 1 will be free for other uses.


To say it another way if you are using the FTDI port for serial monitoring RX and TX (0 and 1) are not available for use with UART mode. A very important note if you want to see what is occurring to troubleshoot and keep your rig running.

knoxvilles_Joker
 
Posts: 96
Joined: Wed Mar 01, 2017 9:15 pm

Re: Running Audio FX Sound Board through Trinket Pro 5V

by knoxvilles_Joker on Thu Mar 23, 2017 7:39 pm

OK, for starters if one ever gets frustrated, sleep on the issue. Often times the lack of progress is due to stress and lack of sleep.

Second once you wake up think of a different way to search the forums.

I found how to trigger the sound files that tests OK in compiling:
sfx.playTrack("T00 WAV");
Serial.print("#3\n");

Now compiling and application are separate things.
The code had to be updated to read as this
Serial.print("#3\n");
has to be
ss.println("#3\n");
then it hits the sound board.

knoxvilles_Joker
 
Posts: 96
Joined: Wed Mar 01, 2017 9:15 pm

Re: Running Audio FX Sound Board through Trinket Pro 5V

by knoxvilles_Joker on Thu Mar 23, 2017 8:31 pm

I got serial.print to work, I just had to redo things to the original board specs in the blueprint. I have to disconnect tx and rx while uploading the blueprint to the device otherwise it will give a communications error.

knoxvilles_Joker
 
Posts: 96
Joined: Wed Mar 01, 2017 9:15 pm

Re: Running Audio FX Sound Board through Trinket Pro 5V

by knoxvilles_Joker on Thu Mar 23, 2017 8:32 pm

knoxvilles_Joker wrote:OK, for starters if one ever gets frustrated, sleep on the issue. Often times the lack of progress is due to stress and lack of sleep.

Second once you wake up think of a different way to search the forums.

I found how to trigger the sound files that tests OK in compiling:
sfx.playTrack("T00 WAV");
Serial.print("#3\n");

Now compiling and application are separate things.
The code had to be updated to read as this
Serial.print("#3\n");
has to be
ss.println("#3\n");
then it hits the sound board.


You have to use this if you are setting tx and rx as something other than pins 0 and 1. The advantage to doing this is it allows you to see if things are communicating properly.

knoxvilles_Joker
 
Posts: 96
Joined: Wed Mar 01, 2017 9:15 pm

Re: Running Audio FX Sound Board through Trinket Pro 5V

by knoxvilles_Joker on Thu Mar 23, 2017 9:34 pm

the code I am running right now if anyone is interested

Code: Select all | TOGGLE FULL SIZE
/*
CryBaby FX Kit v1.0, written by Sean Maio (outcry27@gmail.com)
Designed for use with the Adafruit Pro Trinket and Adafruit audio FX board
Credit and many thanks to the writers of the numerous tutorials available on both the Arduino
and Adafruit websites, without which this project could never have been completed!
-Pin Map-
  Pro Trinket:
  0. Serial RX, connect to Audio FX Serial TX
  1. Serial TX, connect to Audio FX Serial RX
  3. Fire Switch -> GND
  4. Safety toggle switch -> GND
  9. Muzzle LED, connect this to the GATE pin on the muzzle strobe MOSFET
 
  Audio FX board:
  TX. Connect to Trinket Pin 2 (labeled RX)
  RX. Connect to Trinket Pin 1 (labeled TX)
  UG. Jumper to GND to enable UART mode.
 
  !-- DEPRECATED: the following have been replaced by Serial triggering --!
  0. Firing sound
  1. Firing "tail"
  2. "Click" sound (out of ammo/safety on)
  3. "Boot-up" sound
  4. Music clip 1 (wired to a physical switch)
  5. Music clip 2 (wired to a physical switch)
 
*/

#include <Wire.h>
#include <SoftwareSerial.h>
#include "Adafruit_Soundboard.h"
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"

// pins used for Serial communication with the audio board
#define SFX_TX 1
#define SFX_RX 0

SoftwareSerial ss = SoftwareSerial(SFX_TX, SFX_RX);
Adafruit_Soundboard sfx = Adafruit_Soundboard(&ss, NULL, NULL);
Adafruit_AlphaNum4 alpha4 = Adafruit_AlphaNum4();

// constants:
const int triggerPin = 3;     // the number of the firing trigger pin
const int safetyPin = 4; // pin for the "safety" toggle
const int fireSoundPin = 6; // pin for the firing sound
const int muzzlePin =  9;      // the number of the LED pin
const int startSoundPin = 10; // pin for the "boot-up" sound
const int clickSoundPin = 11; // pin for the bolt "click" sound
const int fireTailSoundPin = 12; // pin for the firing "tail" sound
const int fireDelay = 50; // duration in milliseconds for each "shot"

// variables:
boolean safetyOn = false;
int triggerState = 0;         // variable for reading the trigger status
int safetyState = 0;          // variable for reading the safety switch status
int lastTriggerState = 0;     // previous state of the trigger
int lastSafetyState = 0;      // previous state of the safety switch
int ammoCount = 299;
String ammoDisp = String(ammoCount);

void setup() {
  // initialize the LED pin as an output:
  pinMode(muzzlePin, OUTPUT);
  // initialize the trigger and safety pins as input:
  pinMode(triggerPin, INPUT);
  pinMode(safetyPin, INPUT);
  // initialize the audio pins
  pinMode(startSoundPin, INPUT);
  pinMode(clickSoundPin, INPUT);
  pinMode(fireTailSoundPin, INPUT);
  pinMode(fireSoundPin, INPUT);
  pinMode(triggerPin, INPUT);
  pinMode(safetyPin, INPUT);

  // set up the audio trigger pins to give a path to GND when set to OUTPUT
  digitalWrite(muzzlePin, LOW);
  digitalWrite(triggerPin, HIGH);
  digitalWrite(safetyPin, HIGH);
  digitalWrite(startSoundPin, LOW);
  digitalWrite(clickSoundPin, LOW);
  digitalWrite(fireTailSoundPin, LOW);
  digitalWrite(fireSoundPin, LOW);

  Serial.begin(9600);
  ss.begin(9600);
  alpha4.begin(0x70);  // pass in the address

  delay(200);  //give the audio board time to power up; otherwise bootup sound will be called before audio board is ready

  Serial.print("#0\n");

  alpha4.writeDigitAscii(0, '0');
  alpha4.writeDigitAscii(1, '2');
  alpha4.writeDigitAscii(2, '9');
  alpha4.writeDigitAscii(3, '9');
  alpha4.writeDisplay();
  delay(500);
   
  for (int x = 4; x > 0; x--) {
    updateAmmoCounter();
    ammoCount--;
    delay(50);         
  }
  updateAmmoCounter();
}

// this function calls the current value of ammoCount and writes it to the LED display
void updateAmmoCounter() { 
  String ammoDisp = String(ammoCount);
  if (ammoCount < 10) {
            alpha4.writeDigitAscii(0, '0');
            alpha4.writeDigitAscii(1, '0');
            alpha4.writeDigitAscii(2, '0');
            alpha4.writeDigitAscii(3, ammoDisp[0]);
          }
          else if (ammoCount < 100) {
            alpha4.writeDigitAscii(0, '0');
            alpha4.writeDigitAscii(1, '0');
            alpha4.writeDigitAscii(2, ammoDisp[0]);
            alpha4.writeDigitAscii(3, ammoDisp[1]);
          }
          else if (ammoCount < 1000) {
            alpha4.writeDigitAscii(0, '0');
            alpha4.writeDigitAscii(1, ammoDisp[0]);
            alpha4.writeDigitAscii(2, ammoDisp[1]);
            alpha4.writeDigitAscii(3, ammoDisp[2]);
          }
          else if (ammoCount < 10000) {
            alpha4.writeDigitAscii(0, ammoDisp[0]);
            alpha4.writeDigitAscii(1, ammoDisp[1]);
            alpha4.writeDigitAscii(1, ammoDisp[2]);
            alpha4.writeDigitAscii(1, ammoDisp[3]);
          }
          alpha4.writeDisplay();
}

void setSafe() {
  safetyOn = true;
  alpha4.clear();
  alpha4.writeDisplay();
  delay(50);
  alpha4.writeDigitAscii(0, 'S');
  alpha4.writeDigitAscii(1, 'A');
  alpha4.writeDigitAscii(2, 'F');
  alpha4.writeDigitAscii(3, 'E');
  alpha4.writeDisplay();
  delay(50);
  alpha4.clear();
  alpha4.writeDisplay();
  delay(50);
  alpha4.writeDigitAscii(0, 'S');
  alpha4.writeDigitAscii(1, 'A');
  alpha4.writeDigitAscii(2, 'F');
  alpha4.writeDigitAscii(3, 'E');
  alpha4.writeDisplay();
}

void setArm() {
  safetyOn = false;
  alpha4.writeDigitAscii(0, ' ');
  alpha4.writeDigitAscii(1, 'A');
  alpha4.writeDigitAscii(2, 'R');
  alpha4.writeDigitAscii(3, 'M');
  alpha4.writeDisplay();
  delay(50);
  alpha4.clear();
  alpha4.writeDisplay();
  delay(50);
  alpha4.writeDigitAscii(0, ' ');
  alpha4.writeDigitAscii(1, 'A');
  alpha4.writeDigitAscii(2, 'R');
  alpha4.writeDigitAscii(3, 'M');
  alpha4.writeDisplay();
  delay(50);
  alpha4.clear();
  alpha4.writeDisplay();
  delay(50);
  alpha4.writeDigitAscii(0, ' ');
  alpha4.writeDigitAscii(1, 'A');
  alpha4.writeDigitAscii(2, 'R');
  alpha4.writeDigitAscii(3, 'M');
  alpha4.writeDisplay();
  delay(50);
  alpha4.clear();
  alpha4.writeDisplay();
  delay(50);
  alpha4.writeDigitAscii(0, ' ');
  alpha4.writeDigitAscii(1, 'A');
  alpha4.writeDigitAscii(2, 'R');
  alpha4.writeDigitAscii(3, 'M');
  alpha4.writeDisplay();
  delay(300);
  updateAmmoCounter();
}

//this needs to be fixed... commented out for now
/*void playSound(int s);
void playSound(char *name) {
  pinMode(s, OUTPUT);
  delay(100);
  pinMode(s, INPUT);
  //Serial.print("P"name"\n"); 
}*/

// --MAIN LOOP STARTS HERE--
void loop() {
  safetyState = digitalRead(safetyPin);
  if (safetyState != lastSafetyState) {
    if (safetyState == LOW) {
      if (safetyOn == false) {
        setSafe();
      }
      else if (safetyOn == true) {
        setArm();       
      }
    }
  }
  triggerState = digitalRead(triggerPin);
  if (triggerState != lastTriggerState) {
    if (triggerState == HIGH) {
      // turn muzzle strobe off:
      digitalWrite(muzzlePin, LOW);
    }
   
    while (triggerState == LOW) {
    if (safetyOn == true) {
      //playSound(clickSoundPin);
      Serial.print("#2\n");
      triggerState = digitalRead(triggerPin);
      return;
    }
    if (ammoCount <= 0) {
      //playSound(clickSoundPin);
      triggerState = digitalRead(triggerPin);
      return;
    }
    if (safetyOn == false) {
      if (ammoCount > 0) {
        // turn muzzle strobe on:
        //pinMode(fireSoundPin, OUTPUT);
        Serial.print("#3\n");
        digitalWrite(muzzlePin, HIGH);
        ammoCount--;
       
        // update the ammo counter
        updateAmmoCounter();
         
        // cleanup (TAIL SOUND IS CURRENTLY COMMENTED OUT)
        delay(10);
        digitalWrite(muzzlePin, LOW);
        delay(39);
        triggerState = digitalRead(triggerPin);
        if (triggerState == HIGH) {
          // turn muzzle strobe off:
          digitalWrite(muzzlePin, LOW);
          //pinMode(fireSoundPin, INPUT);
          Serial.print("q\n");
          //delay(10);
          //playSound(fireTailSoundPin);
          //Serial.print("#1\n");
          //delay(400);
        }
        if (ammoCount == 0){
          digitalWrite(muzzlePin, LOW);
          pinMode(fireSoundPin, INPUT);
          //playSound(clickSoundPin);
          Serial.print("q\n");
          delay(10);
          Serial.print("#2\n");
        }
      }
    }
    else {
      return;
    }
    }
  lastTriggerState = triggerState;
  }
  lastSafetyState = safetyState; 
}


Credits to Sean Maio for the original code.

I will comment it more heavily and make the code more noob friendly.

I am right now trying to tweak the sounds to get things to play properly, but otherwise it is running as designed.

knoxvilles_Joker
 
Posts: 96
Joined: Wed Mar 01, 2017 9:15 pm

Re: Running Audio FX Sound Board through Trinket Pro 5V

by knoxvilles_Joker on Thu Mar 23, 2017 9:40 pm

And the board, sorry for the spam, if this helps anyone doing something similar the disruption might be worth it.
Attachments
IMG_1666.jpg
the current iteration
IMG_1666.jpg (250.13 KiB) Viewed 1882 times

knoxvilles_Joker
 
Posts: 96
Joined: Wed Mar 01, 2017 9:15 pm

Re: Running Audio FX Sound Board through Trinket Pro 5V

by knoxvilles_Joker on Fri Mar 24, 2017 4:52 pm

OK, I found out the trick on sounds. On MACOS with Audacity: set your default as 16-bit wav and the rate as 41000. Once you copy and delete files empty your trash. OSX has always been weird with flash devices and things will be there that are not if you don't empty the trash.

T00.wav is the startup sound
T02.wav click/safety/empty sound
T03.wav gun sound I think

knoxvilles_Joker
 
Posts: 96
Joined: Wed Mar 01, 2017 9:15 pm

Re: Running Audio FX Sound Board through Trinket Pro 5V

by knoxvilles_Joker on Sat Apr 01, 2017 6:45 am

To help out the community more I would ask if there are any suggested additional information pieces that would help make this thread useful to anyone in the future. I merely wish to return the favor to the community and make the forums more helpful as a whole for others that wish to undertake this endeavor in the future.

knoxvilles_Joker
 
Posts: 96
Joined: Wed Mar 01, 2017 9:15 pm

Re: Running Audio FX Sound Board through Trinket Pro 5V

by MasterFoust on Tue Sep 19, 2017 12:26 pm

Greetings, Knoxvilles_Joker! I am running a haunted attraction at the school where I teach, and we are trying to learn arduino in my tech class in order to enhance our prop-making. I am going to be using your sketch and guidance, as well as that found over on Aliens Legacy to make pulse-rifle props for my students. I would appreciate any advice that you might have above and beyond what is found here.

I am ordering my adafruit parts this week, and will be building in the weeks to come. I would love to correspond with you in regard to this project as it shapes up. :^)

Thanks for posting all of your hard work so openly so that we noobs and teachers of noobs can join the amazing world of electronics.

MasterFoust
 
Posts: 8
Joined: Tue Sep 19, 2017 12:10 pm

Re: Running Audio FX Sound Board through Trinket Pro 5V

by knoxvilles_Joker on Wed Mar 21, 2018 5:00 pm

MasterFoust wrote:Greetings, Knoxvilles_Joker! I am running a haunted attraction at the school where I teach, and we are trying to learn arduino in my tech class in order to enhance our prop-making. I am going to be using your sketch and guidance, as well as that found over on Aliens Legacy to make pulse-rifle props for my students. I would appreciate any advice that you might have above and beyond what is found here.

I am ordering my adafruit parts this week, and will be building in the weeks to come. I would love to correspond with you in regard to this project as it shapes up. :^)

Thanks for posting all of your hard work so openly so that we noobs and teachers of noobs can join the amazing world of electronics.


I also have the motion tracker build documented, and am working on a predator animatronic cannon updating the Honus 2002 codebase. I am still working out the servo pieces with weight/inertia pieces to minimize breakage from shock force loads as the market has changed substantially the past few years alone. I have to update the motion tracker to incorporate the changed compass accelerometer combo (old part is discontinued now), but I digress.

I would also recommend looking at using just the fx sound board with momentary push button switches. Much easier to manage just files with it and great for halloween decorations with sounds. Message me over at AL and I will respond we are all here to help out in some way.

Also my writeup on making your own motion tracker. This would be far more fun and weaponless of a prop for the children:
http://forum.alienslegacy.com/viewtopic.php?f=3&t=16829

knoxvilles_Joker
 
Posts: 96
Joined: Wed Mar 01, 2017 9:15 pm

Please be positive and constructive with your questions and comments.