Wav Trigger + Arduino Mega

Hello Arduino Community!

I am working on a cool project at the moment, using an Arduino Mega and a Wav Trigger to play sounds for a DIY pinball machine!

I am using 22 pins to connect to switches in the pinball machine. 0 thru 17 are connected to bumpers that will make sounds, and pins 18-21 are used to switch between banks of sounds.

All the pins are connected to ground with a 10 ohm resistor, except pin 46 which is being used to communicate to the RX pin on the Wav trigger.

Right now I am having some bugs with my set up.
My main problem is not all samples are being played when triggered! The wiring seems to be ok. I was hoping you could see if there are any errors in my code that you think would be causing this.

#include <AltSoftSerial.h>

#include <wavTrigger.h>
wavTrigger wTrig;

//2D array for holding the track numbers. each bank is each song
int songBank[4][18] = {
  {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18},
  {19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36},
  {37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 51, 51, 52, 53, 54},
  {55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72}
};

int bank = 0; //what bank we are tunes from

//bank pins are the last 4 in the row
//declare pins 
int triggerPin[22] = {0 ,1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22}; 

//
int pinState[22] = {0};
int prevPinState[22] = {0};

void setup() {
  //start talking with the wav trigger
  wTrig.start();

  //read the pins to see if they have made contact
  for (int i = 0; i < 22; i++)
  {
    pinMode(triggerPin[i], INPUT);
  }
  Serial.begin(9600);
  Serial.print("Starting Program");  
}

void loop() {
  // put your main code here, to run repeatedly:

  for (int i = 0; i < 22; i++)
  {
    pinState[i] = digitalRead(triggerPin[i]);
    if (i < 18 )//song pins
    {
      if (pinState[i] == HIGH && prevPinState[i] == LOW)
      {
        wTrig.trackPlayPoly(songBank[bank][i]);
        Serial.print("Pin connected ");  
        Serial.println(i);  
      }
    }
    prevPinState[i] = pinState[i];

  }
  if (pinState[18] == HIGH )
    bank = 0;
  if (pinState[19] == HIGH)
    bank = 1;
  if (pinState[20] == HIGH)
    bank = 2;
  if (pinState[21] == HIGH)
    bank = 3;
}

Another issue I am facing is that I can’t upload code the the Arduino Mega while the Protoshield Mega is connected or I am faced with the “avrdude: stk500v2_ReceiveMessage(): timeout” error reported on this forum post

When the shield is connected I also can’t see any serial prints on my computer, which makes debugging hard.

Thank you very much for your help, let me know if you would like me to clarify something more! :sunglasses:

audiotest.ino (1.81 KB)

All the pins are connected to ground with a 10 ohm resistor, e

I hope you mean 10K otherwise you are going to have trouble getting it to work reliably.

To detect an input you really need to wire a switch between input and ground and enable the internal pull up resistors.

Using pins 0&1 for anything is going to bugger up serial communications.

Hi Grumpy_Mike
Thanks for the reply.
The resistors I am using are Brown Black Black Gold - which the online calculator says is 10 ohms and 5 % tolerance.

Can you please clarify what you mean by

enable the internal pull up resistors.

Thanks

You want brown black orange for the first three bands. And always check the value of any component before you install it: that can save a lot of frustration chasing down problems.

int triggerPin[22] = {0 ,1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22};

As Grumpy Mike says, using pins 0 and 1 will get in the way of Serial communication to the Mega.

I'm not sure what you intend for pin 12. If you really meant to include it in the array of pins, then you will need to make triggerPin[23] to cover all pins 0-22.

If you really intended to leave pin 12 out of the inputs, then I'm not sure how you will handle the missing track numbers in songBank[4][18].

Enable the interna pull up resistors

pinMode(pin,INPUT_PULLUP);

Do not use those value of resistors remove them compleatly. Invert your logic that means a switch press will return a LOW and a not press will return a HIGH.