Notifications
Clear all

Adafruit Soundboard help

6 Posts
3 Users
0 Reactions
308 Views
(@stiny77)
Member
Joined: 8 months ago
Posts: 3
Topic starter  

Hi everyone I am relatvely new to arduino, I can get by and keen to progress. I am working on a project that I need help with. It involves a push button, Oled Screen and a Adafruit sound board. Basically I am trying to run the sound board via serial and I can`t get both the screen and the sound board to both work at the same time. 

I want the Oled to display the track number which increments with a short press on the push button and if there is a long press the soundboard plays the track assigned to that number. the sound board has a activity pin (ACT) which is low when a track is being played which I am monitoring and if there is a track playing a short or long press of the button will stop the track.

My problem is getting the Oled and sound board to work at the same time. I thought it would work as the Oled is I2C and sound board is serial. The code compiles but neither the screen or sound board work. I have included my code bellow incase I have done something wrong or it might just not be possible, I don't know??? I would greatly appreciate and help you can give me with this problem. Thanks

 

#include "Wire.h"
#include "OneButton.h"
#include "Adafruit_SSD1306.h"
#include "SoftwareSerial.h"
#include "Adafruit_Soundboard.h"

#define ButtonPin 2
#define OLED_RESET 1
#define SFX_RST 4
#define SFX_TX 5
#define SFX_RX 6
#define Act_Pin 13

OneButton button(ButtonPin, true);
Adafruit_SSD1306 display(OLED_RESET);

SoftwareSerial ss = SoftwareSerial(SFX_TX, SFX_RX);
Adafruit_Soundboard sfx = Adafruit_Soundboard(&ss, NULL, SFX_RST);

byte Display = 1;
byte DisplayOld = 0;
bool Act;

void setup() {
button.attachClick(singleClick);
button.attachLongPressStop(longClick);
Wire.begin();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
pinMode (Act_Pin,INPUT_PULLUP);
ss.begin(9600);
}

void loop() {
Act = digitalRead (Act_Pin);

button.tick();
delay(10);

if (DisplayOld != Display) {                                                    // Run Screen if display has changed
Screen();}
if (Display>8){
Display = 1;}}

void singleClick() {                                                               // increment Display - if Track playing stop track
if (Act == true){
Display ++;}
if (Act == false) {
sfx.stop();}}

void longClick() {                                                                 // Play Track,
if (Act == true){
sfx.playTrack((Display));}
if (Act == false) {
sfx.stop();}}

void Screen() {                                                                   // Display Screen
display.setTextColor(WHITE);
display.clearDisplay();
display.setTextSize(1);
display.setCursor(55,0);
display.print("Tune");
display.setTextSize(2);
display.setCursor(35,15);
display.print("Track ");
display.print(Display);
DisplayOld = Display;}


   
Quote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7105
 

@stiny77 First learn how to post code. I don't see any constructor for the SoundBoard.

Screenshot 2023 09 17 at 06.56.02

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2538
 

@stiny77

I'm a bit confused about this. On one hand you say "I can't get both the screen and the sound board to both work at the same time" and later you say "The code compiles but neither the screen or sound board work".

One suggests that they both work (one at a time) and the other suggests that neither works (at all). Could you please specify which case applies and provide more details about the nature and timing of the failure ? Does it work when you first start it up and fail after that or does it just display 1 and not play the first track at all ? Remember, we can only see what you tell us, so if you don't supply good and accurate details, we can't help you.

As an aside, since you say you are relatively new to the Arduino, I would suggest that in future you might use a variable name like "track" instead of "Display" for the item being played.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@stiny77)
Member
Joined: 8 months ago
Posts: 3
Topic starter  

@will Hi sorry for the confusion. if I load the code for just the screen on the arduino that works fine. and same for just the soundboard. if I combine the two to try and get both working at the same time neither the screen or sound board work they will not both work on the same arduino for some reason. hope that makes a bit more sense.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2538
 

@stiny77 

OK, I'll have a closer look at it.

Some immediate questions ...

1) do you really need and INPUT_PULLUP on the activity pin, seems like the board should maintain its state, not you.

2) triple-check your wiring.

3) consider enabling Serial and peppering the sketch with print statements. Maybe one in each module to show that it was entered and what state the activity pin is at. That'll help you follow what's happening in the logic.

4) retest both items by running them through the one-at-a-time sketches to make sure that neither has been damaged.

5) Try unplugging each part and running the sketch to see if it works with just that part enabled. It may (long shot) just be that you don't have enough power to run both of them.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@stiny77)
Member
Joined: 8 months ago
Posts: 3
Topic starter  

Hi thanks for having a look. There’s no problem changing to input I am just a beginner with coding so I’m sure I have made mistakes there isn’t a lot of information on running the sound board with serial.  The ACT pin is high and goes low when something is being played. I will go through my wiring and do more tests. Thanks again


   
ReplyQuote