Hey there, this is the first project that I'm creating on my own and I'm having a problem that I cant fix
The project is a simple 4 button audio player/sampler. button 1 plays audio 0001.wav, button 2 0002.wav and it goes until button 4.
This project worked fine on protoboard, but once I solded everything on a PCB and replaced it for an arduino nano, its not working anymore. All my 4 buttons are in a loop on serial monitor and it keeps showing:
Button 1: 1
Button 2: 1
Button 3: 1
Button 4: 1
In an infinite loop. It recognizes when I press the button, but it keeps going on the loop and it doesnt play the sample.
This is my code:
#include <SD.h>
#include <TMRpcm.h>
#include <SPI.h>
TMRpcm tmrpcm; // Criando um objeto player.
const int chipSelect = 4;
const int buttonPin1 = 2;
const int buttonPin2 = 6;
const int buttonPin3 = 7;
const int buttonPin4 = 8;
void setup() {
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
pinMode(buttonPin3, INPUT_PULLUP);
pinMode(buttonPin4, INPUT_PULLUP);
tmrpcm.speakerPin = 9; // O alto-falante está conectado ao pino 9.
Serial.begin(9600); // Inicializando a porta serial com a velocidade de 9600 bauds.
if (!SD.begin(chipSelect)) // Se o cartão estiver disponível.
{
Serial.println("Falha no SD");
return;
}
Serial.println("SD funcionando");
}
void loop() {
int buttonState1 = digitalRead(buttonPin1);
int buttonState2 = digitalRead(buttonPin2);
int buttonState3 = digitalRead(buttonPin3);
int buttonState4 = digitalRead(buttonPin4);
Serial.print("Button 1: ");
Serial.println(buttonState1);
Serial.print("Button 2: ");
Serial.println(buttonState2);
Serial.print("Button 3: ");
Serial.println(buttonState3);
Serial.print("Button 4: ");
Serial.println(buttonState4);
if (buttonState1 == LOW) {
tmrpcm.play("0001.wav");
Serial.println("Botão 1 pressionado");
delay(500); // Aguarda um pouco para evitar acionamentos múltiplos do botão.
}
if (buttonState2 == LOW) {
tmrpcm.play("0002.wav");
Serial.println("Botão 2 pressionado");
delay(500);
}
if (buttonState3 == LOW) {
tmrpcm.play("0003.wav");
Serial.println("Botão 3 pressionado");
delay(500);
}
if (buttonState4 == LOW) {
tmrpcm.play("0004.wav");
Serial.println("Botão 4 pressionado");
delay(500);
}
}
Welcome to the forum..
Sounds like TMRpcm is having an issue..
You know, if you don't press a button, then yes, you print at loop speed..
Maybe only print when the button is pressed..
And what nano specifically are you using now??
their not all the same..
As soon as I get home tonight I'm testing to only print when button is pressed. What I think its kind weird is that I've tested this circuit using an Arduino Uno and on protobard, it worked just fine.
Now I'm using an Arduino Nano V3 and the buttons are soldered to the PCB, and I doesnt work
Yess, you're right! I guess the problem is on wiring/power.
I've uploaded the code that @hallowed31 posted and I kept having the same issue. Also made a test with only 1 button and it shows the same message on serial monitor: "Button 1: 1" in a continuous loop.
I really appreciate all the messages and suggestions. Now I'm gonna remake the soldering, testing everything before soldering (lesson learned haha)