Hallo.
Ich möchte mir ein Modul zusammenstellen das über ein URL ein auf einer SD-Karte abgespechertes mp3-File abspielt. Zusätzlich soll der File-Namen am Display dargestellt werden.
Leider funktioniert mein Code sobald ich den DF Player über SoftwareSerial einbinde nicht mehr.
Woarn kann das liegen?
lg Thomas
#include <EtherCard.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
#define STATIC 1 // set to 1 to disable DHCP (adjust myip/gwip values below)
// mac address
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
// ethernet interface ip address
static byte myip[] = { 10,0,0,56 };
// gateway ip address
static byte gwip[] = { 10,0,0,138 };
// LED to control output
int ledPin10 = 2;
int ledPin11 = 3;
LiquidCrystal_I2C lcd(0x27, 16, 2);
SoftwareSerial mySoftwareSerial(6,7); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
byte Ethernet::buffer[700];
char const page[] PROGMEM =
"HTTP/1.0 503 Service Unavailable\r\n"
"Content-Type: text/html\r\n"
"Retry-After: 600\r\n"
"\r\n"
"<html>"
"<head><title>"
"Service Temporarily Unavailable"
"</title></head>"
"<body>"
"<h3>Antwortseite</h3>"
"<p><em>"
"Komando fuer Sound1.<br />"
"The syntax: ?Sound1"
"</em></p>"
"</body>"
"</html>"
;
void setup () {
pinMode(ledPin10, OUTPUT);
pinMode(ledPin11, OUTPUT);
mySoftwareSerial.begin(9600);
myDFPlayer.volume(30); //Lautstärke auf Maximum (30)
lcd.begin();
lcd.backlight();
if (ether.begin(sizeof Ethernet::buffer,mymac) == 0)
{
lcd.print(F("keine Verbindung"));
}
else
{
lcd.print(F("Verbindung: OK"));
}
;
#if STATIC
if (!ether.staticSetup(myip, gwip)){
blinkLed(); // blink forever to indicate a problem
}
#else
if (!ether.dhcpSetup()){
blinkLed(); // blink forever to indicate a problem
}
#endif
lcd.setCursor(0,1);
lcd.print("IP: ");
for (byte x = 0; x < 4; ++x) {
lcd.print(myip[x]);
if (x < 3)
lcd.print(".");
}
}
void loop () {
word len = ether.packetReceive();
word pos = ether.packetLoop(len);
if(strstr((char *)Ethernet::buffer + pos, "GET /?Sound1") != 0) {
lcd.backlight();
lcd.setCursor(0,0);
lcd.print(F("Sound1 abspielen"));
lcd.setCursor(0,1);
lcd.print(" ");
digitalWrite(ledPin10, HIGH);
myDFPlayer.play(1);
//delay(1000);
digitalWrite(ledPin10, LOW);
lcd.setCursor(0,0);
lcd.print(" ");
lcd.noBacklight();
}
if(strstr((char *)Ethernet::buffer + pos, "GET /?Sound2") != 0) {
lcd.backlight();
lcd.setCursor(0,0);
lcd.print(F("Sound2 abspielen"));
lcd.setCursor(0,1);
lcd.print(" ");
digitalWrite(ledPin11, HIGH);
delay(1000);
digitalWrite(ledPin11, LOW);
lcd.setCursor(0,0);
lcd.print(" ");
lcd.noBacklight();
}
// show some data to the user
memcpy_P(ether.tcpOffset(), page, sizeof page);
ether.httpServerReply(sizeof page - 1);
}
void blinkLed(){
while (true){
digitalWrite(ledPin10, HIGH);
delay(500);
digitalWrite(ledPin10, LOW);
delay(500);
}
}