Go Down

Topic: Adafruit Sound FX board on Arduino Due (Read 804 times) previous topic - next topic

nonlinearmind

Hello,

I'm trying to get the Adafruit sound FX board on the Arduino Due and I'm not able to because the sample sketch requires the use of SoftwareSerial, which I assume doesn't work on Due. Is there any way of simply replacing lines of code in the sketch so that it will use the hardware serial on the board instead? Thanks.
Code: [Select]

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


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

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


SoftwareSerial ss = SoftwareSerial(SFX_TX, SFX_RX);

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

void setup() {
  Serial.begin(115200);
  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() {

 fx.playTrack("18      WAV");
 delay(4000);
}




jdelcamp11

I don't have a sound board, but I had a similar issue with my adafruit camera.
I solved this by using one of the hardware serials available on the Due.
A similar approach might work for your sound board.
       camera on Serial3 (on Due 14, 15)
and initialized it as 
Due_VC0706 cam = Due_VC0706(&Serial3);  
I had to modify the library   

1) I made a copy of the library - calling it DueVC0706 and renaming the h file and cpp file . 
Then edited the VC07060.cpp as follows:
   (Note there might be multiple references to softserial and all have to be changed.)
old file


#include "Adafruit_VC0706.h"

// Initialization code used by all constructor types
void Adafruit_VC0706::common_init(void) {
  swSerial  = NULL;
  hwSerial  = NULL;
  frameptr  = 0;
  bufferLen = 0;
  serialNum = 0;
}

// Constructor when using SoftwareSerial or NewSoftSerial
#if ARDUINO >= 100
Adafruit_VC0706::Adafruit_VC0706(SoftwareSerial *ser) {
#else
Adafruit_VC0706::Adafruit_VC0706(NewSoftSerial *ser) {
#endif
  common_init();  // Set everything to common state, then...
  swSerial = ser; // ...override swSerial with value passed.
}

// Constructor when using HardwareSerial
Adafruit_VC0706::Adafruit_VC0706(HardwareSerial *ser) {
  common_init();  // Set everything to common state, then...
  hwSerial = ser; // ...override hwSerial with value passed.
}

and changed it to: (Also block changed all reference to Adafrui_VC0706 to Due_VC0706)


#include "Due_VC0706.h"

// Initialization code used by all constructor types
void Due_VC0706::common_init(void) 
  {
   
    hwSerial  = NULL;
    frameptr  = 0;
    bufferLen = 0;
    serialNum = 0;
  }

// Constructor when using HardwareSerial
Due_VC0706::Due_VC0706(HardwareSerial *ser) 
  {
    common_init();  // Set everything to common state, then...
    hwSerial = ser; // ...override hwSerial with value passed.
  }


Then edited the VC0706.h file as follows:
portion of old file
class Adafruit_VC0706 {
 public:
#if ARDUINO >= 100
  Adafruit_VC0706(SoftwareSerial *ser); // Constructor when using SoftwareSerial
#else
  Adafruit_VC0706(NewSoftSerial  *ser); // Constructor when using NewSoftSerial
#endif
  Adafruit_VC0706(HardwareSerial *ser); // Constructor when using HardwareSerial


changed to 

class Due_VC0706 {
 public:
  Due_VC0706(HardwareSerial *ser); // Constructor when using HardwareSerial




Go Up