Hi-
I’ve reviewed the serial section of the user guide and I’m still having some issues. I have an MP3 Trigger Board from Sparkfun that I’m trying to control via serial commands from the Photon. The Serial interface for the MP3 Board is documented in this user manual.
I’ve gotten this to work properly with an Arduino using the following code which triggers off a button press:
int sensorValue = digitalRead(7);
if (sensorValue == 1) {
// play track 1. name on sd-card: 001TRACK.mp3
Serial.print("t");
Serial.write(1);
}
When I move this over to the Photon (and make the interface Serial1), I’m not able to trigger the tracks to play using the same serial commands as with the Arduino. I’ve tried various other commands and combinations including serial.println and no luck.
I’ve also hooked up my Arduino to the serial interface (RX, TX) of the Photon and have read in the serial messages coming in using this code on an Arduino Uno:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte);
}
I might be not reading in properly, but on the Arduino serial monitor reading in, I see values of 1 (which is good) alternating with values of 116. Long story short, unable to trigger the MP3s. I feel like this has something to do with not getting the command byte and the value byte sent properly. Any help would be much appreciated!
That is something to look into, but AFAIK there are some pending issues with Serial1.
I recently also ran in some odd behaviour, so could you show the rest of your code too?
BTW you could try to only use Serial1.write() and for testing your output just short RX<->TX to read back what you send out on the Photon itself without the Arduino.
@LukeUSMC Yes, I believe I’m using the Photon pin designations correctly. I have the Tx out of the Photon going to the Rx of the MP3 board, and the Tx out of the MP3 board going into the Rx of the MP3 board.
@ScruffR Would the Serial2 interface be any different or is there a system issue across the library? Any idea when there will be a new release with serial library fixes?
Here is the complete code dump for the Photon (includes a couple debug lines here and there):
//Debugging LED on Photon
int led1 = D7;
//Trigger pulldown
int trigger = D3;
int triggerCurrent = 0;
void setup() {
// Debugging LED on Photon
Serial.begin(38400);
Serial1.begin(38400);
pinMode(led1, OUTPUT);
//Trigger pulldown
pinMode(trigger, INPUT_PULLDOWN);
}
void loop(){
//Get the state of the trigger button current
triggerCurrent = digitalRead(trigger);
//Pulling trigger: LED comes on and audio clip
if(triggerCurrent == HIGH) {
digitalWrite(led1, HIGH);
// play track 1. name on sd-card: 001.mp3
Serial1.print("t");
Serial1.write(1);
}
// And if the button's not on, then the LED should be off
else {
digitalWrite(led1, LOW);
delay(50);
}
}
And one I have to investigate more before opening an issue in connection with non-AUTOMATIC modes and/or multithreading
If you feel adventerous, you could try building the develop firmware from the open source repo.
But I’ll try your code on my side and see if I notice anything, since the code seems simple enough to not be the cause , but maybe the 38400 timing is slightly off.
Ok, thanks for the heads up. I’ve been trying to come up with a solution and have started to try to port the MP3Trigger Arduino library in hopes that it could be implemented on the Particle Photon to perform the serial messages.
When I try to build the library I get a number of messages because the core libraries don’t match the Arduino core libraries. Of particular note flags on: byte, Stream, boolean. Any advice on how to include the necessary libraries to fix these errors?
I added the #include “application.h” line to my .cpp file in the firmware directory and now I get a flag indicating:
basicsoftserialtrigger.cpp:2:24: fatal error: MP3Trigger.h: No such file or directory #include “application.h”
^
I’m back to basics on the troubleshooting and not sure what I’m doing wrong, searched the forums and tried a few different things, but can’t seem to get Serial1 to be available. I’m still trying to talk to the MP3 Triggerboard and it is 3.3V compatible, so I don’t think I need to worry about a level shifter or resistors.
Here is my code on the particle, and I never enter the while (Serial1.available() > 0) statement.
#include "application.h"
//Debugging LED on Photon
int led1 = D7;
//Trigger pulldown
int trigger = D3;
int triggerCurrent = 0;
void setup() {
delay(1000);
Serial.begin(9600);
Serial1.begin(9600);
pinMode(led1, OUTPUT);
//Trigger pulldown
pinMode(trigger, INPUT_PULLDOWN);
}
void loop(){
//Get the state of the trigger button current
triggerCurrent = digitalRead(trigger);
//Pulling trigger: LED comes on and audio clip
if(triggerCurrent == HIGH) {
digitalWrite(led1, HIGH);
// play track 1 on sd-card: 001TRACK.mp3
while (Serial1.available() > 0) {
Serial1.print("t");
Serial1.write(1);
Serial.println("Msg sent");
}
Serial.print("Pressed, but Serial1 not available");
}
//If button is not pressed, then the LED should be off
else {
digitalWrite(led1, LOW);
delay(50);
}
}
got this figured out. On the last trouble shooting, looks like Photon was waiting for a message from the trigger to signal that it was available. So, after pressing the switch on the MP3 trigger, things started to work in the code as i posted a few minutes ago.
Second, took out the while available statement, and I think the addition of #include appplication.h fixed my original issue!
Sorry for resurrecting an old-ish thread - but would you be willing to post the final code please, RedSquirrel? I’m trying to interface with a Tenda MP3 board and am running into the same frustrations.