📣📪 🚚 Adafruit will not be shipping USPS orders Monday October 14, 2019 🗓. Expedited USPS orders placed after 11am ET 🕚 Friday October 11 will go out Tuesday October 15 📣📪🚚
0

Sound board with 3x4 keypad. Is extra board needed?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Sound board with 3x4 keypad. Is extra board needed?

by danawicks on Sat Jun 29, 2019 10:12 am

Hello All. I'm newer than a newbie. I found a project on Youtube, using the Adafruit soundboard 16mb to make funny car horn sounds. I have built this project, on my own, with no extra study beyond the adafruit product description, and a few tutorial type youtube videos, using individual buttons as triggers for each of the 11 sound files. I want to INSTEAD change this project to use a 3x4 keypad instead of individual buttons, to act as the trigger. I'm not eager to jump into a lot of STUDY, but I will if I have to. My question is, concerning the CODE that is in the arduino library for keypad: "Is the adafruit sound board capable of receiving that code, to make the keypad work, OR do I have to add a second board to receive and process the code, to make the keypad work with the soundboard?" Although I'm not eager to do a lot of study, I did order and receive a Kuman UNO board, to start to learn with little projects from scratch. But, of course, I'd prefer to get a little direction and jump straight to this project that I'm interested in.

Again, here is my initial question: "Is the Adafruit sound board capable of receiving that code, to make the keypad work, OR do I have to add a second board to receive and process the code, to make the keypad work with the soundboard?"

(It's not that I'm a young guy too lazy to get the basics first. I'm an old guy with a job and a life, but a little bit of interest in this. And if there's no simple answer, please tell me where to start studying. Thanks for some help!)

danawicks
 
Posts: 17
Joined: Sat Jun 29, 2019 10:02 am

Re: Sound board with 3x4 keypad. Is extra board needed?

by adafruit_support_bill on Sat Jun 29, 2019 10:24 am

The Fx sound board won't interface directly to the keypad. You will need a processor such as the UNO to read the keyboard and send the codes to the sound board.

You can use the Arduino Keypad library to read the keypad: https://playground.arduino.cc/Code/Keypad/
And you can use our Soundboard library to send serial commands to the Fx sound board: https://learn.adafruit.com/adafruit-aud ... io-control

adafruit_support_bill
 
Posts: 74601
Joined: Sat Feb 07, 2009 10:11 am

Re: Sound board with 3x4 keypad. Is extra board needed?

by danawicks on Sat Jun 29, 2019 10:31 am

Wow! Thanks for quick response. I'm gonna start reading!

danawicks
 
Posts: 17
Joined: Sat Jun 29, 2019 10:02 am

Re: Sound board with 3x4 keypad. Is extra board needed?

by danawicks on Thu Jul 04, 2019 2:41 pm

OK, I'm worn out. I've done all of the adafruit beginner lessons up through about # 15 just to get a little back ground. And I've watched several videos about the adafruit sound board and about the 3x4 and 4x4 key pads. But, I can't make the connection between how to receive the input on the UNO and pass it to the sound board. I understand it using individual buttons as TRIGGERS, but I cannot make the leap on how to use the keypad input to send that info. I've read the keypad CODE, but don't know how to use that to pass it to the soundboard. I haven't found any existing projects using the sound board with a keypad. How do I send the EVENT from the KEYPAD from the UNO to the SOUND BOARD. I don't know which PINS to connect to, nor how to change the code. Can you help? ... thanks!

danawicks
 
Posts: 17
Joined: Sat Jun 29, 2019 10:02 am

Re: Sound board with 3x4 keypad. Is extra board needed?

by adafruit_support_bill on Thu Jul 04, 2019 3:01 pm

There are two ways to do it:

1) Connect some otherwise unused UNO pins to the Fx trigger pins. Then you can trigger sounds using digitalWrite to pull the pins LOW: https://www.arduino.cc/reference/en/lan ... italwrite/

2) Create a SoftwareSerial port using two UNO pins and send commands to the Fx serially:
https://www.arduino.cc/en/Reference/SoftwareSerial
https://learn.adafruit.com/adafruit-aud ... io-control

adafruit_support_bill
 
Posts: 74601
Joined: Sat Feb 07, 2009 10:11 am

Re: Sound board with 3x4 keypad. Is extra board needed?

by danawicks on Sat Jul 06, 2019 9:15 pm

I used the code found at http://robojax.com/learn/arduino/?vid=r ... keypad-4x3 to verify that my UNO was working with my 3x4 membrane keypad, and that far is ok. I can play sound files on the Sound Board by shorting pins 0-10, just fine, when the sound board is stand alone. And I can 'pin out' as per the diagram at https://learn.adafruit.com/adafruit-aud ... io-control . I can follow the UART code for menu commands using the serial monitor and it all works. BUT, what I don't know how to do is combine the keypad code, with the serial code to make it work. I've tried to COMBINE the code from these 2 sources, commenting out what appears to not be needed or avoid duplication, and although I can get it to COMPILE, I can't get it to work.

*** Is there anyone I can PAY to write this code for me? **** I'm ready to go back to my real life.

Just for grins, here's the code I made trying to combine the above 2 sketches.

Code: Select all | TOGGLE FULL SIZE
/*
 * Library taken : https://playground.arduino.cc/Code/Keypad
 * This is the Arduino code for 4x3 keypad.
 * watch the video for details and demo http://youtu.be/qIDzzG2LUtg
 *  *
 * Modefied by Ahmad Shamshiri for Robojax Video channel http://www.Robojax.com
 * Date: July 11, 2018 at 19:56 in Ajax, Ontario, Canada
 * Permission granted to share this code given that this
 * note is kept with the code.
 * Disclaimer: this code is "AS IS" and for educational purpose only.
 * this code has been downloaded from http://robojax.com/learn/arduino/
 * Watch video instruction for this code:
 *
 */
/* @file HelloKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | Demonstrates the simplest use of the matrix Keypad library.
|| #
*/
#include <Keypad.h>

// Connect UG to ground to have the SB boot into UART mode
#include <SoftwareSerial.h>
#include "Adafruit_Soundboard.h"

//Choose any two pins that can be used with Software Serial to RX &TX
#define SFX_TX 10
#define SFX_RX 11
#define SFX_RST 9

// 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
// argument is the rese pin
Adafruit_Soundboard sfx = Adafruit_Soundboard(&ss, NULL, SFX_RST);

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};

byte rowPins[ROWS] = {2, 3, 4, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6,7,8}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

/* ********************************************************************
     Commenting out original Keypad Test Setup
 void setup(){
  // Robojax 4x3 keypad test
  Serial.begin(9600);
  Serial.println("Robojax 4x3 keypad");
}
  ****************************************************************** */

/* ***********************************************************************
 *  Commenting out origiial Keypad Loop Test
void loop(){
  // Robojax 4x3 keypad test
  char key = keypad.getKey();
    // just print the pressed key
   if (key){
    Serial.println(key);
  }
   // this checkes if 4 is pressed, then do something. Here  we print the text but you can control something.
  if (key =='4'){
    // if key matches what you are looking for
    Serial.println("Key 4 is pressed");
  }
}
***************************************************************************  */

// adding SoundBoard code
void setup() {
  Serial.begin(115200);
 // Serial.println("Adafruit Sound Board!"); (not needed)
 
  // softwareserial at 9600 baud
  ss.begin(9600);
  // can also do Serial1.begin(9600)
/*   **************************************************************
      Commenting out the PRINTING of keypad entries
  if (!sfx.reset()) {
    Serial.println("Not found");
    while (1);
  }
  Serial.println("SFX board found");
  ***************************************************************** */
}

void loop() {
  flushInput();  // No idea what this does!!!
   // leaving out all of the PRINT commands

   while (!Serial.available()) ;
   char cmd = Serial.read(); 

   flushInput();

   switch (cmd)  {
      case 'r': {
        if (!sfx.reset() ) {
          Serial.println("Reset failed");
        }
        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 '*': {
        Serial.println("Stopping .... ");
        if (! sfx.stop() ) Serial.println ("Failed to stop");
        break;
      }
   }
}

void flushInput() {
  // Read all available serial input to flush pending data.
  uint16_t timeoutloop = 0;
  while (timeoutloop++ < 40) {
    while (ss.available()) {
      ss.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;
}

//*****************************  end ***************************
Last edited by adafruit_support_bill on Sun Jul 07, 2019 5:36 am, edited 1 time in total.
Reason: please use [code] tags when posting code to the forums.

danawicks
 
Posts: 17
Joined: Sat Jun 29, 2019 10:02 am

Re: Sound board with 3x4 keypad. Is extra board needed?

by adafruit_support_bill on Sun Jul 07, 2019 5:49 am

What you have there is code to read keycodes from the keypad and code to read keycodes from the usb/serial connection. You have nothing there that can write commands to the Fx.

In order to send serial commands to the Fx board, you need to define a SoftwareSerial serial port and use that:
https://www.arduino.cc/en/Reference/SoftwareSerial
https://learn.adafruit.com/adafruit-aud ... io-control

Or identify some spare GPIO pins and connect them directly to the Fx trigger pins so you can trigger them with a simple digitalWrite.
https://www.arduino.cc/reference/en/lan ... italwrite/

But the biggest and most important detail that is missing is a clear definition of what you want the code to do.

What happens when you press a key on the keypad?
What key codes trigger which sounds?

adafruit_support_bill
 
Posts: 74601
Joined: Sat Feb 07, 2009 10:11 am

Re: Sound board with 3x4 keypad. Is extra board needed?

by danawicks on Sun Jul 07, 2019 4:45 pm

I included the keypad sketch, so I could determine that the keypad works, and it did with that sketch.
I included the Adafruit Sound_Board sketch, so I could use the MENU to act as a trigger for the soundboard, and make sure the UNO and the Sound board connected and worked together, and they did with that sketch.

The keypad sketch uses the pinout for the keypad rowPins 2,3,4,5 and column pins 6,7,8 on the UNO.
The UNO connects to the Soundboard, with pins 9,10,11 from the UNO to RST, TX, and RX on the Soundboard, respectively.

The soundboard has 11 file locations in pins 0 - 10, and files are NAMED based on their location # and action to be taken when played (i.e. single button press for the complete file play, or play only while continuously pressed, or play random, etc.) In GPIO mode (using buttons), you short a pin to ground and that file location plays according to its name (i.e.T01.WAV would play the entire sound file found in location 01 when pressed; T02HOLDL.WAV would play location 02 only as long as the button is held down, etc.)

The Sound_Board sketch operates with UART mode and plays files according to a MENU seen through the Serial Monitor. I want to INSTEAD play files with a single button press of the keypad. ALL of my files are named for a full play of the file when accessed (i.e. T00.WAV, T01.WAV, etc). I only have 12 available buttons on the keypad (0-9, * and #). That means I have to allow for multiple presses in order to get to file location 10 and 11, and maybe I can assign some function other than PLAY to * and # of the keypad.

*** Here's the answer to your questions *****
What I want the sketch to do is: For each push of a number on the keypad, the corresponding file location number on the Soundboard will play (when I press 0, file location T00.WAV will play; when I press 1, file location T01.WAV will play). All of my file locations are of the type Tnn.WAV, so a single button push will play the contents of that file location, completely, one time. I would like for button # to STOP a file after it has begun to play. The * key can be assigned to something else. (The other options provided on the Soundboard sketch, visible through the MENU are not needed.)

Thanks for any help you can give.

danawicks
 
Posts: 17
Joined: Sat Jun 29, 2019 10:02 am

Re: Sound board with 3x4 keypad. Is extra board needed?

by adafruit_support_bill on Mon Jul 08, 2019 6:23 am

Start by getting your keypad code working:
For each push of a number on the keypad, the corresponding file location number on the Soundboard will play (when I press 0, file location T00.WAV will play; when I press 1, file location T01.WAV will play)

A switch/case statement is the way to go there. The general form should look something like:
Code: Select all | TOGGLE FULL SIZE
char key = keypad.getKey();
if (key != NO_KEY)
{
   switch(key)
   {
      case '0' :
         Serial.println("Play T00.WAV");
         break;
      case '1' :
         Serial.println("Play T01.WAV");
         break;
      case '2' :
         Serial.println("Play T02.WAV");
         break;
   }
}

Once you get that working, you can create the SoftwareSerial port and Adafruit_Soundboard objects as shown in the example code:
https://github.com/adafruit/Adafruit_So ... mmands.ino

Then you can replace the Serial.println statements with sfx commands to play the track by name:

So:
Code: Select all | TOGGLE FULL SIZE
Serial.println("Play T02.WAV");

becomes
Code: Select all | TOGGLE FULL SIZE
sfx.playTrack("T02.WAV")

adafruit_support_bill
 
Posts: 74601
Joined: Sat Feb 07, 2009 10:11 am

Re: Sound board with 3x4 keypad. Is extra board needed?

by danawicks on Tue Jul 09, 2019 12:40 am

I give up. I'll complete this project with a 10 button pad. I cannot make the Keypad work with the soundboard. I can make the Keypad work. OR I can use the Soundboard sketch and access the sound board in the menu, without the keypad. But I cannot make the keypad work with the soundboard. Thanks for you help. Here's my latest attempt ... that doesn't work.

Code: Select all | TOGGLE FULL SIZE
#include "Keypad.h"
#include <SoftwareSerial.h>
#include "Adafruit_Soundboard.h"

// Choose any two pins that can be used with SoftwareSerial to RX & TX
#define SFX_TX 5
#define SFX_RX 6
// Connect to the RST pin on the Sound Board
#define SFX_RST 4

// 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);

 
const byte ROWS = 4; // number of rows
const byte COLS = 3; // number of columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};

byte rowPins[ROWS] = {2, 3, 4, 5};
byte colPins[COLS] = {6, 7, 8};   
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
 
void setup()
{
  Serial.begin(9600);
  Serial.println("Adafruit Sound Board!");
 
  // softwareserial at 9600 baud
  ss.begin(9600);
  // can also do Serial1.begin(9600)

  if (!sfx.reset()) {
    Serial.println("Not found");
    while (1);
  }
  Serial.println("SFX board found");
}
 
void loop()
{
  char key = keypad.getKey();
  if (key != NO_KEY)
    Serial.println(key);

     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(ss.available()) {
      ss.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 ***************************
/

danawicks
 
Posts: 17
Joined: Sat Jun 29, 2019 10:02 am

Re: Sound board with 3x4 keypad. Is extra board needed?

by danawicks on Fri Jul 12, 2019 12:05 am

This will COMPILE and load, but sfx.playTrack does not play a sound file. If you substitute Serial.println ("T01.WAV") , instead of sfx.playTrack, it will PRINT that on the serial monitor, but it won't play it. I try different variations of file names on CASE 0, 1, 2 ... the other cases are just println statements. If I don't combine the key pad code with the menu driven sketch, the keypad works by itself, and the menu sketch works by itself (meaning it will play sound files). But, I can't COMBINE the two sketches to make the keypad acess and play the sound files.

Code: Select all | TOGGLE FULL SIZE
#include <SoftwareSerial.h>
#include <Adafruit_Soundboard.h>
#include <Key.h>
#include <Keypad.h>
#include <Adafruit_Keypad.h>

// Choose any two pins that can be used with SoftwareSerial to RX & TX
#define SFX_TX 5
#define SFX_RX 6
// Connect to the RST pin on the Sound Board
#define SFX_RST 4

// 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);

 
const byte ROWS = 4; // number of rows
const byte COLS = 3; // number of columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};

byte rowPins[ROWS] = {2, 3, 4, 5};
byte colPins[COLS] = {6, 7, 8};   
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

 
void setup()
{
  Serial.begin(9600);
 }


void loop()  {
 
  char key = keypad.getKey();
  if (key !=NO_KEY);
  {
   
  switch(key)
  {

    case  '0' :
        sfx.playTrack("T00.WAV");
        break;
       
    case '1':
        sfx.playTrack(key);
        break;

    case '2':
         sfx.playTrack("02.WAV");       
         break;

    case '3':
        Serial.println("03.WAV");
        break;

    case '4':
        Serial.println("04.WAV");
        break;

    case '5':
        Serial.println("05.WAV");
        break;

    case '6':
        Serial.println("06.WAV");
        break;

    case '7':
        Serial.println("07.WAV");
        break;

    case '8':
        Serial.println("08.WAV");
        break;

     case '9':
        Serial.println("09.WAV");
        break;

     case '*':
        Serial.println("10.WAV");
        break;

    case '#':
        Serial.println("11.WAV");
        break;

}
  }
}

//  ******************* Menu Helpers ********************
//  I'm not exactly sure what all the code below does BUT
//  I get more ERRORS  if I leave it out. It was originally
// at the bottom of the MENU driven sketch

void flushInput() {
  // Read all available serial input to flush pending data.
  uint16_t timeoutloop = 0;
  while (timeoutloop++ < 40) {
    while(ss.available()) {
      ss.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 ***************************/




danawicks
 
Posts: 17
Joined: Sat Jun 29, 2019 10:02 am

Re: Sound board with 3x4 keypad. Is extra board needed?

by adafruit_support_bill on Fri Jul 12, 2019 5:50 am

sfx.playTrack does not play a sound file.

You are not initializing the sound board in your setup. Use the setup from your previous post.

adafruit_support_bill
 
Posts: 74601
Joined: Sat Feb 07, 2009 10:11 am

Re: Sound board with 3x4 keypad. Is extra board needed?

by danawicks on Fri Jul 12, 2019 5:32 pm

ok, it works, for the most part. BUT, a case statement for - 0 - doesn't work. Case LABEL of '0' does not throw an error , but, on compile, the sfx.playTrack(0) throws an error "call of overloaded 'playTrack(int)'is ambiguous" . The soundboard has 11 sound storage areas, using soundboard pins 0 - 10. I can't figure out how to access that ZERO location. Here's the code:

Code: Select all | TOGGLE FULL SIZE

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

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

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

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};

byte rowPins[ROWS] = {2, 3, 4, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6,7,8}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

  // 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);

void setup(){
  // Robojax 4x3 keypad test
  Serial.begin(9600);
  Serial.println("Robojax 4x3 keypad");
  Serial.println("Adafruit Sound Board!");
// softwareserial at 9600 baud
  ss.begin(9600);
   if (!sfx.reset()) {
    Serial.println("Not found");
    while (1);
    }
  Serial.println("SFX board found");
}
 
 
void loop(){
  // Robojax 4x3 keypad test
  char key = keypad.getKey();
    // just print the pressed key
     if (key) {
       Serial.println(key);
     //  sfx.playTrack(3);  // use switch
     }
   
    switch (key) {
     
     //  case '0' :
     //  sfx.playTrack(0);
     //   break;
      case '1':
        sfx.playTrack(1);
        break; 
      case '2' :
        sfx.playTrack(2);
        break;
      case '3' :
        sfx.playTrack(3);
        break;
      case '4' :
        sfx.playTrack(4);
        break;
      case '5' :
       sfx.playTrack(5);
        break;
      case '6' :
        sfx.playTrack(6);
        break;
      case '7' :
        sfx.playTrack(7);
        break;
      case '8' :
        sfx.playTrack(8);
        break;
      case '9' :
        sfx.playTrack(9);
        break;
      case '*' :
        sfx.playTrack(10);
        break;
      case '#' :
        sfx.stop();
        break;
    }

  }


danawicks
 
Posts: 17
Joined: Sat Jun 29, 2019 10:02 am

Re: Sound board with 3x4 keypad. Is extra board needed?

by danawicks on Sat Jul 13, 2019 2:18 am

Fixed the error with "sfx.playTrack((uint8_t)0);" Thanks for your help.

Code: Select all | TOGGLE FULL SIZE
  switch (key) {
       case '0' :
        sfx.playTrack((uint8_t)0);
        break;
      case '1':
        sfx.playTrack(1);
        break; 
     case '2' :
        sfx.playTrack(2);
        break;

danawicks
 
Posts: 17
Joined: Sat Jun 29, 2019 10:02 am

Re: Sound board with 3x4 keypad. Is extra board needed?

by adafruit_support_bill on Sat Jul 13, 2019 5:35 am

Good to hear you got it working. Thanks for the update.

adafruit_support_bill
 
Posts: 74601
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.