Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can someone help with TMRpcm.h conflict #226

Open
whatislove23 opened this issue Jan 16, 2024 · 1 comment
Open

Can someone help with TMRpcm.h conflict #226

whatislove23 opened this issue Jan 16, 2024 · 1 comment

Comments

@whatislove23
Copy link

Hello. Im trying to download wav file from server and store them to sd card. This part of code is working but when im trying to add library #include <TMRpcm.h> to play audio ESP starts behave like this (see screenshoot) without the line everything is okay. Maybe someone has idea how to solve this because im not really good into this. Thanks
image

@whatislove23
Copy link
Author

#include "WiFiEsp.h"
#include "SoftwareSerial.h"
#include <SPI.h>
#include <SD.h>
#define R_PIN 5
#define G_PIN 6
#define B_PIN 7
#define BUTTON_PIN 8
#define SD_ChipSelectPin 4
uint8_t btn_prev;
char ssid[] = "Home"; // your network SSID (name)
char pass[] = "23042002"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
char server[] = "192.168.31.160";
const int CHUNK_SIZE = 64; // Adjust the chunk size as needed
char mybuffer[CHUNK_SIZE];
WiFiEspClient client;
SoftwareSerial Serial1(3, 2); // RX, TX

void setRGBColor(int mode) {
switch (mode) {
case 0:
analogWrite(R_PIN, 0);
analogWrite(G_PIN, 0);
analogWrite(B_PIN, 0);
break;
case 1:
// Set color for mode 1 (e.g., red)
analogWrite(R_PIN, 255);
analogWrite(G_PIN, 0);
analogWrite(B_PIN, 0);
break;

case 2:
  // Set color for mode 2 (e.g., green)
  analogWrite(R_PIN, 0);
  analogWrite(G_PIN, 255);
  analogWrite(B_PIN, 0);
  break;

case 3:
  // Set color for mode 3 (e.g., blue)
  analogWrite(R_PIN, 0);
  analogWrite(G_PIN, 0);
  analogWrite(B_PIN, 255);
  break;

  // Add more cases as needed for different modes
case 4:
  // Set color for mode 4 (e.g., purple)
  analogWrite(R_PIN, 255);
  analogWrite(G_PIN, 0);  // Adjust green value for orange
  analogWrite(B_PIN, 255);
  break;
default:
  // Default case (e.g., turn off)
  analogWrite(R_PIN, 0);
  analogWrite(G_PIN, 0);
  analogWrite(B_PIN, 0);
  break;

}
}

void setup() {
setRGBColor(3);
pinMode(R_PIN, OUTPUT);
pinMode(G_PIN, OUTPUT);
pinMode(B_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT);
Serial.begin(115200);
Serial1.begin(9600);
Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("initialization failed!");
while (true) setRGBColor(1);
}
Serial.println("initialization done.");
WiFi.init(&Serial1);
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
while (true) setRGBColor(1);
}
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
}
setRGBColor(2);
}

void saveAudioToFile() {
File audioFile = SD.open("audio.wav", FILE_WRITE );

if (audioFile) {
while (client.available()) {
int bytesRead = client.readBytes(mybuffer, CHUNK_SIZE);
audioFile.write(mybuffer, bytesRead);
Serial.print(".");
}
Serial.println("Audio saved to SD card.");
audioFile.close();
setRGBColor(2);

} else {
Serial.println("Error opening audio file for saving!");
}
}
void loop() {
uint8_t btn = digitalRead(BUTTON_PIN);

if (btn == LOW && btn_prev == HIGH) {
setRGBColor(4);
/* RECORD SPEECH/ SAVE TO SD/ SEND FROM SD TO SERVER
TO DO
*/
if (client.connect(server, 5000)) {
Serial.println("Connected to server");
int value = 2.5; // an arbitrary value for testing
String content = "{"JSON_key": " + String(value) + "}";
client.println("POST /post HTTP/1.1");
client.println("Host: 192.168.31.160:5000");
client.println("Accept: /");
client.println("Content-Length: " + String(content.length()));
client.println("Content-Type: application/json");
client.println();
client.println(content);
}
if (client.connect(server, 5000)) {
Serial.println("Connected to server");
client.println("GET / HTTP/1.1");
client.println("Host: 192.168.31.160:5000");
client.println("Connection: close");
client.println();
}
}
if(client.available()){
Serial.println(1);
saveAudioToFile();
}
btn_prev = digitalRead(BUTTON_PIN);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant