What sensor would be best for my project

Only need to declare serial.begin once, and whatever you set needs to be compatible with all devices.
It sets the speed of the TX/RX lines for the UART on the Arduino. (pins D0 & D1)

Most of the time I only use serial as a program debug; printing stuff to the Arduino Console window.
Once I did use it to send commands between a UNO and a Pi Zero, worked pretty good.

Regards
Jim

3 Likes

Thanks thought only once was needed.

3 Likes

Thanks guys, got it all working, light and distance sensor on I2C all working. Just need to get the Adafruit Sound FX module working.
I found this helpful:

4 Likes

Hi Kevin,

Thanks for posting resources you find helpful, you may save someone in the future a lot of stress with a similar problem.
Andreas Spiess does have some excellent tutorials so it’s worth checking out his other videos.
Good luck with the Sound FX module, let us know how you go with it.

2 Likes

I have been working on the adafruit sound fx, I just wanted ask about the SoftwareSerial.h library it asks for. It say it is a arduino included library, which I can’t find, nor can I find where to download it from anywhere. It isn’t included in the adafruit sound fx board files either.

Can you suggest where to find it, I can’t go further with the board otherwise. I thought I’d ask you first before going to Adafruit direct as there will be a few days delay in replies.

Thanks Kev

Will this be of any help? Or this github page?

Thanks, that is the missing file.

This is the Adafruit Sound FX board example file.

> /* 
>   Menu driven control of a sound board over UART.
>   Commands for playing by # or by name (full 11-char name)
>   Hard reset and List files (when not playing audio)
>   Vol + and - (only when not playing audio)
>   Pause, unpause, quit playing (when playing audio)
>   Current play time, and bytes remaining & total bytes (when playing audio)
> 
>   Connect UG to ground to have the sound board boot into UART mode
> */
> 
> #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);
> 
> void setup() {
>   Serial.begin(115200);
>   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() {
>   flushInput();
>   
>   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 ***************************/

Can anyone explain what this part of the code does and is it necessary?

>  
> > /************************ 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 ***************************/

After compiling I get this error:

> Arduino: 1.8.16 (Windows Store 1.8.51.0) (Windows 10), Board: "Arduino Nano 33 BLE"
> 
> 
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:362:2: error: #error This version of SoftwareSerial supports only 20, 16 and 8MHz processors
> 
>  #error This version of SoftwareSerial supports only 20, 16 and 8MHz processors
> 
>   ^~~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp: In member function 'bool SoftwareSerial::listen()':
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:418:23: error: 'SREG' was not declared in this scope
> 
>      uint8_t oldSREG = SREG;
> 
>                        ^~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:418:23: note: suggested alternative: 'SING'
> 
>      uint8_t oldSREG = SREG;
> 
>                        ^~~~
> 
>                        SING
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:419:5: error: 'cli' was not declared in this scope
> 
>      cli();
> 
>      ^~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp: In member function 'void SoftwareSerial::setTX(uint8_t)':
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:593:22: error: 'digitalPinToBitMask' was not declared in this scope
> 
>    _transmitBitMask = digitalPinToBitMask(tx);
> 
>                       ^~~~~~~~~~~~~~~~~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:593:22: note: suggested alternative: 'digitalPinToPinName'
> 
>    _transmitBitMask = digitalPinToBitMask(tx);
> 
>                       ^~~~~~~~~~~~~~~~~~~
> 
>                       digitalPinToPinName
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:595:27: error: 'portOutputRegister' was not declared in this scope
> 
>    _transmitPortRegister = portOutputRegister(port);
> 
>                            ^~~~~~~~~~~~~~~~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:595:27: note: suggested alternative: '_transmitPortRegister'
> 
>    _transmitPortRegister = portOutputRegister(port);
> 
>                            ^~~~~~~~~~~~~~~~~~
> 
>                            _transmitPortRegister
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp: In member function 'void SoftwareSerial::setRX(uint8_t)':
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:604:21: error: 'digitalPinToBitMask' was not declared in this scope
> 
>    _receiveBitMask = digitalPinToBitMask(rx);
> 
>                      ^~~~~~~~~~~~~~~~~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:604:21: note: suggested alternative: 'digitalPinToPinName'
> 
>    _receiveBitMask = digitalPinToBitMask(rx);
> 
>                      ^~~~~~~~~~~~~~~~~~~
> 
>                      digitalPinToPinName
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:606:26: error: 'portInputRegister' was not declared in this scope
> 
>    _receivePortRegister = portInputRegister(port);
> 
>                           ^~~~~~~~~~~~~~~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp: In member function 'void SoftwareSerial::begin(long int)':
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:617:31: error: 'table' was not declared in this scope
> 
>    for (unsigned i=0; i<sizeof(table)/sizeof(table[0]); ++i)
> 
>                                ^~~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:617:31: note: suggested alternative: 'tanl'
> 
>    for (unsigned i=0; i<sizeof(table)/sizeof(table[0]); ++i)
> 
>                                ^~~~~
> 
>                                tanl
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:633:9: error: 'digitalPinToPCICR' was not declared in this scope
> 
>      if (digitalPinToPCICR(_receivePin))
> 
>          ^~~~~~~~~~~~~~~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:633:9: note: suggested alternative: 'digitalPinToPort'
> 
>      if (digitalPinToPCICR(_receivePin))
> 
>          ^~~~~~~~~~~~~~~~~
> 
>          digitalPinToPort
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:635:46: error: 'digitalPinToPCICRbit' was not declared in this scope
> 
>        *digitalPinToPCICR(_receivePin) |= _BV(digitalPinToPCICRbit(_receivePin));
> 
>                                               ^~~~~~~~~~~~~~~~~~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:635:46: note: suggested alternative: 'digitalPinToPort'
> 
>        *digitalPinToPCICR(_receivePin) |= _BV(digitalPinToPCICRbit(_receivePin));
> 
>                                               ^~~~~~~~~~~~~~~~~~~~
> 
>                                               digitalPinToPort
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:635:42: error: '_BV' was not declared in this scope
> 
>        *digitalPinToPCICR(_receivePin) |= _BV(digitalPinToPCICRbit(_receivePin));
> 
>                                           ^~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:635:42: note: suggested alternative: '_B'
> 
>        *digitalPinToPCICR(_receivePin) |= _BV(digitalPinToPCICRbit(_receivePin));
> 
>                                           ^~~
> 
>                                           _B
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:636:8: error: 'digitalPinToPCMSK' was not declared in this scope
> 
>        *digitalPinToPCMSK(_receivePin) |= _BV(digitalPinToPCMSKbit(_receivePin));
> 
>         ^~~~~~~~~~~~~~~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:636:8: note: suggested alternative: 'digitalPinToPort'
> 
>        *digitalPinToPCMSK(_receivePin) |= _BV(digitalPinToPCMSKbit(_receivePin));
> 
>         ^~~~~~~~~~~~~~~~~
> 
>         digitalPinToPort
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:636:46: error: 'digitalPinToPCMSKbit' was not declared in this scope
> 
>        *digitalPinToPCMSK(_receivePin) |= _BV(digitalPinToPCMSKbit(_receivePin));
> 
>                                               ^~~~~~~~~~~~~~~~~~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:636:46: note: suggested alternative: 'digitalPinToPort'
> 
>        *digitalPinToPCMSK(_receivePin) |= _BV(digitalPinToPCMSKbit(_receivePin));
> 
>                                               ^~~~~~~~~~~~~~~~~~~~
> 
>                                               digitalPinToPort
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp: In member function 'void SoftwareSerial::end()':
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:651:7: error: 'digitalPinToPCMSK' was not declared in this scope
> 
>    if (digitalPinToPCMSK(_receivePin))
> 
>        ^~~~~~~~~~~~~~~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:651:7: note: suggested alternative: 'digitalPinToPort'
> 
>    if (digitalPinToPCMSK(_receivePin))
> 
>        ^~~~~~~~~~~~~~~~~
> 
>        digitalPinToPort
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:652:45: error: 'digitalPinToPCMSKbit' was not declared in this scope
> 
>      *digitalPinToPCMSK(_receivePin) &= ~_BV(digitalPinToPCMSKbit(_receivePin));
> 
>                                              ^~~~~~~~~~~~~~~~~~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:652:45: note: suggested alternative: 'digitalPinToPort'
> 
>      *digitalPinToPCMSK(_receivePin) &= ~_BV(digitalPinToPCMSKbit(_receivePin));
> 
>                                              ^~~~~~~~~~~~~~~~~~~~
> 
>                                              digitalPinToPort
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:652:41: error: '_BV' was not declared in this scope
> 
>      *digitalPinToPCMSK(_receivePin) &= ~_BV(digitalPinToPCMSKbit(_receivePin));
> 
>                                          ^~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:652:41: note: suggested alternative: '_B'
> 
>      *digitalPinToPCMSK(_receivePin) &= ~_BV(digitalPinToPCMSKbit(_receivePin));
> 
>                                          ^~~
> 
>                                          _B
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp: In member function 'virtual size_t SoftwareSerial::write(uint8_t)':
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:687:21: error: 'SREG' was not declared in this scope
> 
>    uint8_t oldSREG = SREG;
> 
>                      ^~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:687:21: note: suggested alternative: 'SING'
> 
>    uint8_t oldSREG = SREG;
> 
>                      ^~~~
> 
>                      SING
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:688:3: error: 'cli' was not declared in this scope
> 
>    cli();  // turn off interrupts for a clean txmit
> 
>    ^~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:692:26: error: 'XMIT_START_ADJUSTMENT' was not declared in this scope
> 
>    tunedDelay(_tx_delay + XMIT_START_ADJUSTMENT);
> 
>                           ^~~~~~~~~~~~~~~~~~~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp: In member function 'virtual void SoftwareSerial::flush()':
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:735:21: error: 'SREG' was not declared in this scope
> 
>    uint8_t oldSREG = SREG;
> 
>                      ^~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:735:21: note: suggested alternative: 'SING'
> 
>    uint8_t oldSREG = SREG;
> 
>                      ^~~~
> 
>                      SING
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:736:3: error: 'cli' was not declared in this scope
> 
>    cli();
> 
>    ^~~
> 
> exit status 1
> 
> Error compiling for board Arduino Nano 33 BLE.

Is it possible that this code won’t work on a Nano33BLE format. I found this earlier:
SoftwareSerial.h Library not found - Using Arduino / Installation & Troubleshooting - Arduino Forum

As you discovered, there is no SoftwareSerial library for the SAMD architecture of the Nano 33 IoT. However, there is no need for one. The Nano 33 IoT has an unused hardware serial port named Serial1 on pins 0 and 1, so just use that. It's also possible to get more if you need it, but you most likely don't so we won't worry about that.

Note that the Nano 33 IoT is different from the classic Nano because the serial port on pins 0 and 1 (Serial) on the classic Nano is also used for uploading sketches and other communication with the computer (e.g., Serial Monitor), so it's not really convenient to use Serial for other purposes on the classic Nano. This is why you will often see people using SoftwareSerial library with the Nano, Uno, Pro Mini, etc. But the Nano 33 IoT is different because the Serial1 serial port on pins 0 and 1 is not used for anything, so you are free to use those pins for your own purposes.

If so, I take it if I do as this guy was instructed?

Two more questions. I wan’t the Sound FX board to be triggered to play “Power is ON” when the unit is turned on. What can I use as the trigger?

Is there a need to calibrate the Nano33BLE IMU(I use to measure movement and angles, Piico Distance sensor, Piico Light Sensor? If so, when(eg, every time on start up, once when first using? Is this the same with the other modules? If so how do I do it, as it will need to be easy to do for someone that has no idea on this sort of stuff.

You’re most welcome, Kevin. Would not hurt to try the suggestions in that thread. Nobody there reported any holy smoke coming out of the boards.

Regarding the calibration, Adafruit has a page.

Regarding coding, Jim will be a better help. My expertise with codes stop at filling in the postal codes on mail.

cheers G

I have been trying to get the Adafruit SoundFX board working via TX/RX on Nano33BLE which I have found out is Serial1. here isn’t much info on this as it is different to other Arduino modules. I am having trouble with the code, it says I have not declared in the scope:

Arduino: 1.8.16 (Windows Store 1.8.51.0) (Windows 10), Board: “Arduino Nano 33 BLE”

> CyclopsV2_I2C_coding_light:52:48: error: 'Serial1' was not declared in this scope
> 
>  Adafruit_Soundboard sfx = Adafruit_Soundboard(&Serial1, NULL, SFX_RST);
> 
>                                                 ^~~~~~~
> 
> C:\Users\KevB\Documents\Arduino\CyclopsV2_I2C_coding_light\CyclopsV2_I2C_coding_light.ino:52:48: note: suggested alternative: 'serial_s'
> 
>  Adafruit_Soundboard sfx = Adafruit_Soundboard(&Serial1, NULL, SFX_RST);
> 
>                                                 ^~~~~~~
> 
>                                                 serial_s
> 
> C:\Users\KevB\Documents\Arduino\CyclopsV2_I2C_coding_light\CyclopsV2_I2C_coding_light.ino: In function 'void setup()':
> 
> CyclopsV2_I2C_coding_light:129:4: error: 'Serial1' was not declared in this scope
> 
>  {  Serial1.begin(9600);
> 
>     ^~~~~~~
> 
> C:\Users\KevB\Documents\Arduino\CyclopsV2_I2C_coding_light\CyclopsV2_I2C_coding_light.ino:129:4: note: suggested alternative: 'serial_s'
> 
>  {  Serial1.begin(9600);
> 
>     ^~~~~~~
> 
>     serial_s
> 
> C:\Users\KevB\Documents\Arduino\CyclopsV2_I2C_coding_light\CyclopsV2_I2C_coding_light.ino: At global scope:
> 
> CyclopsV2_I2C_coding_light:140:1: error: expected unqualified-id before '{' token
> 
>  {
> 
>  ^
> 
> CyclopsV2_I2C_coding_light:168:1: error: expected unqualified-id before '{' token
> 
>  {
> 
>  ^
> 
> CyclopsV2_I2C_coding_light:193:1: error: expected declaration before '}' token
> 
>  }
> 
>  ^
> 
> exit status 1
> 
> 'Serial1' was not declared in this scope

Arduino forum explanation, but no example. OK for someone experienced but not for a nubie

Can someone simply explain how to declare and setup Serial1 to write(TX) to the adafruitSFX(RX) and read SFX(RX) to (BLE)TX?

This is the example given by Adafruit:

> /* 
>   Menu driven control of a sound board over UART.
>   Commands for playing by # or by name (full 11-char name)
>   Hard reset and List files (when not playing audio)
>   Vol + and - (only when not playing audio)
>   Pause, unpause, quit playing (when playing audio)
>   Current play time, and bytes remaining & total bytes (when playing audio)
> 
>   Connect UG to ground to have the sound board boot into UART mode
> */
> 
> #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);
> 
> void setup() {
>   Serial.begin(115200);
>   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() {
>   flushInput();
>   
>   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 ***************************/

Means the compiler does not know what “Serial1” is and therefore does not know what to do with it.

The Arduino has a built-in hardware USART to send and receive serial data. This is also used to load programs and for debugging making it hard to use a serial port for a project. The “Software Serial” library was developed to over come this problem. It sends serial data via two PWM pins on the Arduino. This is what the Adafruit example is doing.

“Serial1” is just a way of differentiating between the built-in hardware serial port and one that use a software approach. “Serial” is defined in the core compiler libraries. “Serial1” is also used in relation to the Atmega 2560 board, the processor on that board has 4 hardware USARTs. Would steer away from using “Serial1”.

The processor on the Nano33BLE (SAM D21/DA1) is quite powerful and configurable. But pretty sure the Nano interface is just like a normal Arduino. Most Arduino libraries should work ok.

Suggest you use the Adafruit example to get the connection between the Nano and Sound FX board working. The code defines D4 Reset, D5 TX, D6 RX. Actual pins on the Nano are 22, 23, 24 respectively.

So connect …
Nano pin 22 to RST on Sound board.
Nano pin 23 (TX) to TX on Sound board.
Nano pin 22 (RX) to RX on Sound board.

The Adafruit web page for the Sound board defines TX as an output and RX as an input; normally you would connect TX to RX. (output to input).
But the Adafruit example swaps the TX & RX definitions in:
SoftwareSerial ss = SoftwareSerial(SFX_TX, SFX_RX);
The built-in Software Serial example defines it as:
SoftwareSerial mySerial(10, 11); // RX, TX

Maybe Adafruit thought it would help to just connect TX to TX but for people like me having worked in serial communications all my life, we would naturally connect TX to RX and wonder why it does not work. This kind of confusion has happened many times in the past.

Once you get the Adafruit example to work you can incorporate it into your other code.
Apologies for not keeping abreast of your development, I have been busy on Raspberry Pi stuff.

Regards
Jim

2 Likes

To do this, in void setup() make the last step sending a command to the Sound board to play the track where you have recorded “Power is ON”.
sfx.playTrack("name");
name would be whatever the file is called.
You may need to add a delay while the track is played and then pause the Sound board.
delay(2000); // wait 2 seconds.
sfx.pause();

Regards
Jim

2 Likes

I have been trying for the last week. SoftwareSerial.h doesn’t work with Nano33BLE board which I found others have found as the TX(1)/RX(3) ports on the board are hardware based as Serial1.
Also get the following error with the Adafruit code for the SFX

> 
> Arduino: 1.8.16 (Windows Store 1.8.51.0) (Windows 10), Board: "Arduino Nano 33 BLE"
> 
 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:362:2: error: #error This version of SoftwareSerial supports only 20, 16 and 8MHz processors
> 
>  #error This version of SoftwareSerial supports only 20, 16 and 8MHz processors
> 
>   ^~~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp: In member function 'bool SoftwareSerial::listen()':
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:418:23: error: 'SREG' was not declared in this scope
> 
>      uint8_t oldSREG = SREG;
> 
>                        ^~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:418:23: note: suggested alternative: 'SING'
> 
>      uint8_t oldSREG = SREG;
> 
>                        ^~~~
> 
>                        SING
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:419:5: error: 'cli' was not declared in this scope
> 
>      cli();
> 
>      ^~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp: In member function 'void SoftwareSerial::setTX(uint8_t)':
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:593:22: error: 'digitalPinToBitMask' was not declared in this scope
> 
>    _transmitBitMask = digitalPinToBitMask(tx);
> 
>                       ^~~~~~~~~~~~~~~~~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:593:22: note: suggested alternative: 'digitalPinToPinName'
> 
>    _transmitBitMask = digitalPinToBitMask(tx);
> 
>                       ^~~~~~~~~~~~~~~~~~~
> 
>                       digitalPinToPinName
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:595:27: error: 'portOutputRegister' was not declared in this scope
> 
>    _transmitPortRegister = portOutputRegister(port);
> 
>                            ^~~~~~~~~~~~~~~~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:595:27: note: suggested alternative: '_transmitPortRegister'
> 
>    _transmitPortRegister = portOutputRegister(port);
> 
>                            ^~~~~~~~~~~~~~~~~~
> 
>                            _transmitPortRegister
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp: In member function 'void SoftwareSerial::setRX(uint8_t)':
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:604:21: error: 'digitalPinToBitMask' was not declared in this scope
> 
>    _receiveBitMask = digitalPinToBitMask(rx);
> 
>                      ^~~~~~~~~~~~~~~~~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:604:21: note: suggested alternative: 'digitalPinToPinName'
> 
>    _receiveBitMask = digitalPinToBitMask(rx);
> 
>                      ^~~~~~~~~~~~~~~~~~~
> 
>                      digitalPinToPinName
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:606:26: error: 'portInputRegister' was not declared in this scope
> 
>    _receivePortRegister = portInputRegister(port);
> 
>                           ^~~~~~~~~~~~~~~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp: In member function 'void SoftwareSerial::begin(long int)':
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:617:31: error: 'table' was not declared in this scope
> 
>    for (unsigned i=0; i<sizeof(table)/sizeof(table[0]); ++i)
> 
>                                ^~~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:617:31: note: suggested alternative: 'tanl'
> 
>    for (unsigned i=0; i<sizeof(table)/sizeof(table[0]); ++i)
> 
>                                ^~~~~
> 
>                                tanl
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:633:9: error: 'digitalPinToPCICR' was not declared in this scope
> 
>      if (digitalPinToPCICR(_receivePin))
> 
>          ^~~~~~~~~~~~~~~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:633:9: note: suggested alternative: 'digitalPinToPort'
> 
>      if (digitalPinToPCICR(_receivePin))
> 
>          ^~~~~~~~~~~~~~~~~
> 
>          digitalPinToPort
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:635:46: error: 'digitalPinToPCICRbit' was not declared in this scope
> 
>        *digitalPinToPCICR(_receivePin) |= _BV(digitalPinToPCICRbit(_receivePin));
> 
>                                               ^~~~~~~~~~~~~~~~~~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:635:46: note: suggested alternative: 'digitalPinToPort'
> 
>        *digitalPinToPCICR(_receivePin) |= _BV(digitalPinToPCICRbit(_receivePin));
> 
>                                               ^~~~~~~~~~~~~~~~~~~~
> 
>                                               digitalPinToPort
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:635:42: error: '_BV' was not declared in this scope
> 
>        *digitalPinToPCICR(_receivePin) |= _BV(digitalPinToPCICRbit(_receivePin));
> 
>                                           ^~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:635:42: note: suggested alternative: '_B'
> 
>        *digitalPinToPCICR(_receivePin) |= _BV(digitalPinToPCICRbit(_receivePin));
> 
>                                           ^~~
> 
>                                           _B
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:636:8: error: 'digitalPinToPCMSK' was not declared in this scope
> 
>        *digitalPinToPCMSK(_receivePin) |= _BV(digitalPinToPCMSKbit(_receivePin));
> 
>         ^~~~~~~~~~~~~~~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:636:8: note: suggested alternative: 'digitalPinToPort'
> 
>        *digitalPinToPCMSK(_receivePin) |= _BV(digitalPinToPCMSKbit(_receivePin));
> 
>         ^~~~~~~~~~~~~~~~~
> 
>         digitalPinToPort
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:636:46: error: 'digitalPinToPCMSKbit' was not declared in this scope
> 
>        *digitalPinToPCMSK(_receivePin) |= _BV(digitalPinToPCMSKbit(_receivePin));
> 
>                                               ^~~~~~~~~~~~~~~~~~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:636:46: note: suggested alternative: 'digitalPinToPort'
> 
>        *digitalPinToPCMSK(_receivePin) |= _BV(digitalPinToPCMSKbit(_receivePin));
> 
>                                               ^~~~~~~~~~~~~~~~~~~~
> 
>                                               digitalPinToPort
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp: In member function 'void SoftwareSerial::end()':
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:651:7: error: 'digitalPinToPCMSK' was not declared in this scope
> 
>    if (digitalPinToPCMSK(_receivePin))
> 
>        ^~~~~~~~~~~~~~~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:651:7: note: suggested alternative: 'digitalPinToPort'
> 
>    if (digitalPinToPCMSK(_receivePin))
> 
>        ^~~~~~~~~~~~~~~~~
> 
>        digitalPinToPort
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:652:45: error: 'digitalPinToPCMSKbit' was not declared in this scope
> 
>      *digitalPinToPCMSK(_receivePin) &= ~_BV(digitalPinToPCMSKbit(_receivePin));
> 
>                                              ^~~~~~~~~~~~~~~~~~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:652:45: note: suggested alternative: 'digitalPinToPort'
> 
>      *digitalPinToPCMSK(_receivePin) &= ~_BV(digitalPinToPCMSKbit(_receivePin));
> 
>                                              ^~~~~~~~~~~~~~~~~~~~
> 
>                                              digitalPinToPort
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:652:41: error: '_BV' was not declared in this scope
> 
>      *digitalPinToPCMSK(_receivePin) &= ~_BV(digitalPinToPCMSKbit(_receivePin));
> 
>                                          ^~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:652:41: note: suggested alternative: '_B'
> 
>      *digitalPinToPCMSK(_receivePin) &= ~_BV(digitalPinToPCMSKbit(_receivePin));
> 
>                                          ^~~
> 
>                                          _B
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp: In member function 'virtual size_t SoftwareSerial::write(uint8_t)':
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:687:21: error: 'SREG' was not declared in this scope
> 
>    uint8_t oldSREG = SREG;
> 
>                      ^~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:687:21: note: suggested alternative: 'SING'
> 
>    uint8_t oldSREG = SREG;
> 
>                      ^~~~
> 
>                      SING
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:688:3: error: 'cli' was not declared in this scope
> 
>    cli();  // turn off interrupts for a clean txmit
> 
>    ^~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:692:26: error: 'XMIT_START_ADJUSTMENT' was not declared in this scope
> 
>    tunedDelay(_tx_delay + XMIT_START_ADJUSTMENT);
> 
>                           ^~~~~~~~~~~~~~~~~~~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp: In member function 'virtual void SoftwareSerial::flush()':
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:735:21: error: 'SREG' was not declared in this scope
> 
>    uint8_t oldSREG = SREG;
> 
>                      ^~~~
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:735:21: note: suggested alternative: 'SING'
> 
>    uint8_t oldSREG = SREG;
> 
>                      ^~~~
> 
>                      SING
> 
> C:\Users\KevB\Documents\Arduino\libraries\SoftwareSerial-master\SoftwareSerial.cpp:736:3: error: 'cli' was not declared in this scope
> 
>    cli();
> 
>    ^~~
> 
> exit status 1
> 
> Error compiling for board Arduino Nano 33 BLE.
> ```

Being hardware Serial, I found allot of people saying to just create a simple sketch like the following(it took me a bit to get it to compile as I wasn’t declaring things correctly(like Serial1 and incomingByte). I got the following to compile. I haven’t run it with my main code yet so crossing fingers:

#include <Arduino_LSM9DS1.h>
char incomingByte = 0;
void setup() {
   Serial1.begin(9600);
}

 void loop() {
   // put your main code here, to run repeatedly:
 if (Serial1.available() > 0) 
 {
   incomingByte = Serial1.read();        //read the incoming byte
   Serial1.print("Received: ");          
   Serial1.println(incomingByte, DEC);   //send the byte to the terminal in decimal format
 
 Serial1.write("SFX Board recieved loud and clear");
}
  
 }

Is this working in the right direction or am going down the wrong path?

1 Like

@Kevin79611 Thought just occurred to me.
The Nano33BLE is programmed via the USB interface. And further reading of the Arduino help page states the TX1 RX0 pins are defined as Serial1. The instructions on the page detail installing a Board driver which would then allow use of Serial1. Arduino Mbed OS Nano Boards.

YES !!! It is the right direction as long as you have loaded the Board driver as per the web page.

.
Pretty much my last 2 posts are useless, deleted them. I am just working through the problem and trying to understand the board without having one in front of me.

Use Serial1 in your code to send commands to the Sound board using the Adafruit Library.
Connect TX1 (output) on the Nano33BLE to RX (input)on the Sound board.
Connect RX0 (input) on the Nano33BLE to TX (output) on the Sound board.

Adafruit example changed to use Serial1, compiles ok. Code below.

Sorry, some of my help has been useless, the path I have taken is what would have happened anyway if it was my project.
Hope this helps.
Regards
Jim

#include "Adafruit_Soundboard.h"
// Connect to the RST pin on the Sound Board
#define SFX_RST 4

Adafruit_Soundboard sfx = Adafruit_Soundboard(&Serial1, NULL, SFX_RST);
 
void setup() {
  Serial.begin(115200);
  Serial.println("Adafruit Sound Board!");
  
  Serial1.begin(9600);

  if (!sfx.reset()) {
    Serial.println("Not found");
    while (1);
  }
  Serial.println("SFX board found");
}


void loop() {
  flushInput();
  
  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(Serial1.available()) {
      Serial1.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 ***************************/
3 Likes

Thanks Jim

Any help is help. I will give it a try tomorrow, just had a nice feed out for the first time in a year thanks to covid. I’ll post how I go and once I get it right I will try and compile a simple “How too” as I like the Nano33BLE and would like to try the Sense, there is just lacking tutorials at the moment.

Cheers

Kev

3 Likes

In the Adafruit tutorial on Serial triggering:

Serial Audio Control | Adafruit Audio FX Sound Board | Adafruit Learning System

It says you can call for a track to play by name using the following format:

(PT09 WAV\n);

But I get the following error, can anyone explain why:

stray \ in program

1 Like

“\n” is like pressing the ‘enter’ key, newline etc.
Possible you don’t need it anymore. Or it might be sent automatically.

Try without the “\n”.
Adafruit’s tutorial is pretty old now.
Regards
Jim

2 Likes