Is Sound Board serial control "playTrack" blocking?

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
cosined
 
Posts: 30
Joined: Tue Sep 22, 2015 8:05 pm

Is Sound Board serial control "playTrack" blocking?

Post by cosined »

Hi Adafruit team,

I am using an Adafruit M4 Feather Express (PID# 3857) to serially control a 16MB 2x2W Soundboard (PID# 2217). I know that the ACT activity pin of the Sound Board goes LOW while a sound is being played. However, is this playTrack() activity blocking on the Feather end? Immediately after using the playTrack() function, I try to read the Sound Board ACT pin using one of the Feather's digital I/O pins to see if it reads LOW (so I can queue another action) but either the Feather continues reading HIGH the entire time or the Feather isn't able to read the pin at the time. At least that's what I'm guessing according the Serial console. Measuring the I/O pin in question using a multimeter does show the voltage physically dips down to ~0V from ~3.3V while a sound is being played.

Below is the code I've whipped up for testing this. Basically the idea was for the Serial console to output an upward count from 0 as soon as it detects the pin goes LOW while the sound is still actively playing. The sound loops as expected, and the physical voltage reading is what is expected, but the count never begins. It just continues printing the "loop start" statement. Something could be wrong with my code. I wouldn't be too shocked if that was the case. Any help is appreciated! Thanks!

Code: Select all

#include "Adafruit_Soundboard.h"

const int SFX_RST = 4;
const int soundboardActive = 11;          // GPIO pin to read whether soundboard is currently playing an audio file. LOW when file being played.
Adafruit_Soundboard sfx = Adafruit_Soundboard(&Serial1, NULL, SFX_RST);
int x = 0;

void setup() {
  Serial1.begin(9600);
  pinMode(soundboardActive, INPUT_PULLUP);
}

void loop() {
  Serial.println("loop start");
  char soundToPlayChar[21];
  String soundToPlayString = "10000000OGG";
  soundToPlayString.toCharArray(soundToPlayChar, 20);
  sfx.playTrack(soundToPlayChar);
  //delay(100);
  while(digitalRead(soundboardActive) == LOW){
    Serial.println(x);
    x = x + 1;
  }
  x = 0;
}

User avatar
dastels
 
Posts: 15658
Joined: Tue Oct 20, 2015 3:22 pm

Re: Is Sound Board serial control "playTrack" blocking?

Post by dastels »

Looking at the code https://github.com/adafruit/Adafruit_So ... dboard.cpp playTrack doesn't block.

I don't see anything wrong with your code. Hardware is another issue. Can you post clear photos of your connections/wiring?

Dave

User avatar
cosined
 
Posts: 30
Joined: Tue Sep 22, 2015 8:05 pm

Re: Is Sound Board serial control "playTrack" blocking?

Post by cosined »

Thank you for the quick response Dave! I have a feeling we might be in for a bit of an adventure here if you ask me to make a complete circuit diagram after this. I am trying to make a modified toy to gift to someone that plays custom sound effects, so bear with me when it comes to the wiring pictures.

The purple wire connects Sound Board ACT pin to Feather M4 Express I/O #11. I verified that the wire itself isn't broken internally by doing a continuity test with the multimeter on both those pins/pads. Maybe pin #11 of the Feather doesn't work anymore for reading voltages? I might try switching the wire to another available I/O pin instead of #11. What do you think?
Attachments
sound board
sound board
sound board.png (344.94 KiB) Viewed 282 times
feather
feather
feather.png (342.76 KiB) Viewed 282 times

User avatar
dastels
 
Posts: 15658
Joined: Tue Oct 20, 2015 3:22 pm

Re: Is Sound Board serial control "playTrack" blocking?

Post by dastels »

I find myself wondering about your power/ground wiring between the Feather and audio board. You seem to have both BUS (connected to the USB 5v line) and Vin connected. You also appear to have most of the Gnd pins connected (unnecessary as they all connect together on the board... the multiple GND pins are for convenience). Anyway, some detail on your power wiring would help.

Dave

User avatar
cosined
 
Posts: 30
Joined: Tue Sep 22, 2015 8:05 pm

Re: Is Sound Board serial control "playTrack" blocking?

Post by cosined »

Hi Dave, I figured you were going to ask that. I was putting off making the circuit diagram for a while but this motivated me to finally do it. Thank you for continuing to help! I'm using an Adafruit LiPoly backpack as well as an Adafruit 1200mAh 3.7V LiPo battery. I split how the power is delivered to the components, with a schottky diode in one path. The idea was to prevent the Sound Board from possibly drawing current through my USB ports (via the Feather) while I am programming and testing the Feather M4 Express. I wasn't sure if the Feather's Bat pin could allow a connecting component to draw current through it, when the Feather is powered through the USB port while programming.

Some of the wires in the diagram are the same color even though they aren't connected to each other, just because in real life I didn't have more colors to work with. I tried to use the same color wires in the diagram as I did with the physical thing, just for my reference.

About the grounds, I did use a lot of the ground pins just because of all the components that needed to be connected to ground. I leveraged the fact that they all are connected together internally on the boards. It's hard to have a bunch of wires go to the same pin, and I didn't want to keep using more perfboard space since I wanted to keep things compact. In the diagram, the ground connections are simple and clean but in physical circuit there's tons of ground wires running amuck. :^)

Anyways, in my opinion, there's lots of extra stuff in my complete circuit diagram that doesn't really relate to the problem. What do you think I should do? If playTrack() is not blocking, then there's gotta be something else that's the issue. Maybe that particular I/O pin on the Feather is damaged like I was considering earlier?
Attachments
complete-circuit
complete-circuit
complete-circuit.png (71.15 KiB) Viewed 270 times

User avatar
cosined
 
Posts: 30
Joined: Tue Sep 22, 2015 8:05 pm

Re: Is Sound Board serial control "playTrack" blocking?

Post by cosined »

Ooh I didn't include this on the circuit diagram but the Sound Board of course has a speaker (8 ohm, 1/4W) connected to one of the channels. I arbitrarily picked the Right speaker channel screw terminals to hook up the speaker positive and minus leads to.

User avatar
dastels
 
Posts: 15658
Joined: Tue Oct 20, 2015 3:22 pm

Re: Is Sound Board serial control "playTrack" blocking?

Post by dastels »

Since there's no regulator on the audio board, I'm wondering if powering from the 3v output of the Feather would work better.

I'm also not sure what purpose D4 serves.

Dave

User avatar
cosined
 
Posts: 30
Joined: Tue Sep 22, 2015 8:05 pm

Re: Is Sound Board serial control "playTrack" blocking?

Post by cosined »

Dave, thank you again for bearing with me.

I did a terrible job explaining why I put the Schottky diode (D4) there. I was being cautious. The idea was to try to prevent the Sound Board + speaker from drawing lots of current through the BAT pin of the Feather when I have the Feather plugged into my computer for programming. I'm not sure if the Feather BAT pin can even serve as an output, to be honest. I might have been paranoid. Anyways, the speaker is actually a 8 ohm, 2W speaker (I just realized I swapped the 1/4W one out at some point). Using P = (I^2)*R, the max current going through the speaker is:

2W = (I^2)*8ohm
0.25A = I^2
0.50A = I


Right? Hopefully I am using that formula correctly here. Half an Amp is the highest current a USB port can supply. And looking at the Feather page on the Adafruit Learning System, the 3V (3.3V regulator output) pin can also supply half an Amp peak. That's just exactly at the upper limit of what the speaker draws at max load. I wanted some current cushion without sacrificing the loudness of the speaker.

At the same time, I also didn't want to power the Sound Board + speaker through my laptop USB port while programming the Feather. Was this actually not a problem after all? Maybe the BAT pin on the Feather is in fact only an input. I don't know.

BUT if that's the case, and you still recommend going with your idea of connecting the 3V regulated pin of the Feather to the Vin pin of the Sound Board, won't the Sound Board definitely be on and making noises according to the Arduino code when I have the Feather plugged in to the USB port? That's what I wanted to avoid since the 0.5A USB supply limit is the same as the 0.5A peak current draw of the speaker.

Just so we don't lose sight of what the original question was: will changing this voltage connection address the "blocking" issue I'm seeing with reading the LOW state of the Sound Board ACT pin while a sound is playing?

Appreciate your help Dave! :^)

User avatar
dastels
 
Posts: 15658
Joined: Tue Oct 20, 2015 3:22 pm

Re: Is Sound Board serial control "playTrack" blocking?

Post by dastels »

The Vbat on the Feather is directly connected to the + side of the battery connector so it's not really an input or output.

As for power, my thought is that the Feather uses 3.3v logic, so having the audio board running at 3.3v might (should?) make communication with it more reliable.

As for the blocking.. I don't see that happening in the library code. After sending the play command, it waits for the play response. When the clip ends the audio board sends "done", but the library isn't waiting for that:

Code: Select all

boolean Adafruit_Soundboard::playTrack(char *name) {
  while (stream->available())
    stream->read();

  stream->print("P");
  stream->println(name);

  readLine(); // eat return
#ifdef DEBUG
  Serial.print("\n\r<--- ");
  Serial.println(line_buffer);
#endif

  readLine();

#ifdef DEBUG
  Serial.print("\n\r<--- ");
  Serial.println(line_buffer);
#endif

  // check we got "play" back
  if (strstr(line_buffer, "play") == 0) {
    return false;
  }
  return true;
}
Maybe try turning debug on (in the Arduino Tools menu) and rebuild/run. That should give you some insight into what's going on in the library.

Dave

User avatar
cosined
 
Posts: 30
Joined: Tue Sep 22, 2015 8:05 pm

Re: Is Sound Board serial control "playTrack" blocking?

Post by cosined »

Hi Dave, thanks for continuing to bear with me. Sorry for the late reply.

I made the change you suggested of connecting one of the 3V pins on the Feather M4 Express board to the VIN pin of the Sound Board (replacing the previous connection from there to the battery switch). I also went into the Arduino IDE Tools tab and selected Debug: On. It didn't really say much. I pasted what the IDE said below:

Code: Select all

Sketch uses 12168 bytes (2%) of program storage space. Maximum is 507904 bytes.
Device       : ATSAMD51x19
Version      : v1.1 [Arduino:XYZ] May 17 2020 17:56:23
Address      : 0x0
Pages        : 1024
Page Size    : 512 bytes
Total Size   : 512KB
Planes       : 1
Lock Regions : 32
Locked       : none
Security     : false
BOD          : false
BOR          : true
Write 12424 bytes to flash (25 pages)
[==============================] 100% (25/25 pages)
Done in 0.203 seconds
Verify 12424 bytes of flash
[==============================] 100% (25/25 pages)
Verify successful
Done in 0.073 seconds
Prior to making these changes, I switched the connection (purple wire from before) to be from SoundBoard Act pin to Feather D12 instead of to Feather D11 how it was before. I reuploaded the same exact program then and the behavior of the circuit stayed exactly the same: sound file plays on loop and Serial Monitor keeps printing loop start. One thing I should mention is that it prints loop start twice for every one time the sound plays.

Anyways, I made that change first, then the changes you suggested. The circuit behavior didn't change at all EXCEPT for that when I plug the Feather in to program it, the SoundBoard is also powered on and is playing the looped sound as per the Arduino code. This is regardless of whether the power button I wired in is switched on or not. This is an unwanted behavior, but I'll keep this for now during testing since I think you made a good point about the power voltage.

Do you have any ideas of what I should do next? Any thoughts about how I can test to see whether playSound() is blocking or not? It seems like you're saying it isn't, but I'm stumped as to why my test code isn't counting while the sound plays. Thanks again for your help so far! Everything is so close to working correctly that I am admittedly a bit frustrated at the moment.

User avatar
dastels
 
Posts: 15658
Joined: Tue Oct 20, 2015 3:22 pm

Re: Is Sound Board serial control "playTrack" blocking?

Post by dastels »

What gets output in the serial monitor? There was some debug code in the library I'd hoped would get enabled by turning "debug" on.

One thing to try (to get more information) is to Serial.println(millis()) before and after the call to playTrack. That will tell you how long it's spending in the call. Specifically if it's returning right away or after the track plays.

Dave

User avatar
cosined
 
Posts: 30
Joined: Tue Sep 22, 2015 8:05 pm

Re: Is Sound Board serial control "playTrack" blocking?

Post by cosined »

!! That is such a good (and obvious to do) idea! Good thinking. I did just that. I've attached three files to this post. "serial-out-before" shows what the console has been spitting out up until now. "serial-out-after" shows what adding in the time stamp Serial.println(millis()); lines does. And "complete-circuit2" is the updated circuit from the previous post with the changes you suggested, just so we are up-to-date on what we're working with.

So "serial-out-after" shows that the time stamp before "loop start" is either 0 or 1ms off of the time stamp after "loop start". Here's the code we're working with again, with the updated pin declaration, for reference.

Code: Select all

#include "Adafruit_Soundboard.h"

const int SFX_RST = 4;
const int soundboardActive = 12;          // GPIO pin to read whether soundboard is currently playing an audio file. LOW when file being played.
Adafruit_Soundboard sfx = Adafruit_Soundboard(&Serial1, NULL, SFX_RST);
int x = 0;

void setup() {
  Serial1.begin(9600);
  pinMode(soundboardActive, INPUT_PULLUP);
}

void loop() {
  Serial.println("loop start");
  char soundToPlayChar[21];
  String soundToPlayString = "10000000OGG";
  soundToPlayString.toCharArray(soundToPlayChar, 20);
  Serial.println(millis());
  sfx.playTrack(soundToPlayChar);
  Serial.println(millis());
  //delay(100);
  while(digitalRead(soundboardActive) == LOW){
    Serial.println(x);
    x = x + 1;
  }
  x = 0;
}

Code: Select all

1804
loop start
1804
1868
loop start
1868
3607
loop start
3607
3672
loop start
3672
5411
loop start
5411
5475
loop start
5476
7215
loop start
7216
7280
loop start
7280
9019
loop start
9019
9084
loop start
9084
10823
loop start
10823
10888
loop start
10889
12628
loop start
12628
12692
loop start
12693
14432
loop start
14432
14496
loop start
14497
16236
loop start
16236
16300
loop start
16301
18039
loop start
18039
18103
loop start
18103
19843
loop start
19843
19907
loop start
19907
21646
loop start
21646
21710
loop start
21710
23449
loop start
23449
23513
loop start
23513
25252
loop start
25252
25316
loop start
25317
27056
loop start
27056
27121
loop start
27121
28860
loop start
28860
28924
loop start
28925
30664
loop start
30664
30728
loop start
30728
32468
loop start
32468
32532
loop start
32533
34272
loop start
34272
34336
loop start
34337
36076
loop start
36076
36141
loop start
36142
37881
loop start
37882
37946
loop start
37947
39686
loop start
39686
39750
loop start
39751
41490
loop start
41490
41554
loop start
41555
43294
loop start
43294
43358
loop start
43358
45098
loop start
45098
45162
loop start
45162
46901
loop start
46902
46966
loop start
46966
48705
loop start
48705
48770
loop start
48770
50509
loop start
50509
50573
loop start
50574
52313
loop start
52313
52377
loop start
52378
54116
loop start
54116
54180
loop start
54180
55920
loop start
55920
55984
loop start
55984
57723
loop start
57723
57788
loop start
57789
I went into Excel and calculated the differences between each pair of numbers (between each loop start print) and came up with the following differences in order. The sound effect I am playing is probably that ~1740ms time. As for the ~64ms duration, I think something is happening where parts of the code are skipped after the sound is played once. The following loop doesn't play the sound (maybe the SoundBoard is busy?) but then it is able to play it again after two loops. Apparently this "empty sound loop" takes ~64 milliseconds to run. What do you think? Thanks again for helping so far!

Code: Select all

64
1739
65
1739
64
1739
64
1739
65
1739
65
1739
64
1739
64
1739
64
1738
64
1740
64
1739
64
1739
64
1739
64
1739
65
1739
64
1739
64
1740
64
1739
64
1739
65
1739
64
1739
64
1739
64
1739
64
1740
64
1739
64
1739
65
1739
64
1739
64
1738
64
1740
64
1739
65
Attachments
serial-out-after.png
serial-out-after.png (28.56 KiB) Viewed 229 times
serial-out-before.png
serial-out-before.png (55.47 KiB) Viewed 229 times
complete-circuit2.png
complete-circuit2.png (70.74 KiB) Viewed 229 times

User avatar
cosined
 
Posts: 30
Joined: Tue Sep 22, 2015 8:05 pm

Re: Is Sound Board serial control "playTrack" blocking?

Post by cosined »

Hmm... So one way to interpret what's going on, based on the 1740ms and 64ms durations, is that playTrack() could actually be blocking first and takes that 1740ms duration while the sound plays. THEN the loop happens again, but the Sound Board is occupied immediately after playing the previous sound, so the loop skips playTrack() this time around. This second run-through takes only 64ms since playTrack() isn't executed and the track isn't played.

That's what I think might be going on. I don't really have a better explanation for that weird 64ms duration. Dave looked at the guts of the function and came to the conclusion that playTrack isn't blocking, so even the 1740ms "evidence" I found confuses me.

Does anyone have any ideas of what's happening, and more importantly, how to fix the issue? I want to be able to continue using the Feather to do other things while the Sound Board plays a sound. I really appreciate any help. Thanks!!

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”