Hi, im currently having trouble with software serial, as i want to read what is being transmitted and recieved from a player module im currently trying to set up. The board i am using is an arduino UNO v3, The code im using is:
#include <SoftwareSerial.h>
#define rxPin 7
#define txPin 8
// set up a new serial port
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
byte pinState = 0;
void setup() {
// define pin modes for tx, rx, led pins:
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
// set the data rate for the SoftwareSerial port
Serial.begin(19200);
Serial.println("Test of arduino player module");
mySerial.begin(19200);
mySerial.println("\\:n");
}
void loop
The problem is that for the software serial "mySerial" im and not getting any information show up in the serial monitor. I have the player module connected to pins 7 and 8, but not even transmitted ":n" is showing up in the serial monitor, only the "Test for arduino player module"
My final goal is to be able to have my player module, play songs off it's SD card by a filename. I am trying to see what i recieve from the play module with software serial, hoping for atleast a "file not found" so i no im on the right track.
The problem is that for the software serial "mySerial" im and not getting any information show up in the serial monitor.
First, you don't have a mySerial attached to the Arduino, using pins 7 and 8, do you? If you used a meaningful name for the SoftwareSerial instance, it just MIGHT become obvious what the problem is.
Now, when you do mp3player.print(), mp3player.write(), mp3player.available(), and mp3player.read(), it is quite obvious what you are writing to/reading from.
Second, the data that goes back and forth between the Arduino and the mp3 player is NOT going to appear on the Serial Monitor. You need to make that happen by reading from the mp3 player, using mp3player.read() and writing to the Serial Monitor using Serial.print().
Third, snippets are for http://snippets-r-us.com. Here, we, quite reasonably, expect to see ALL of your code.
So, iv solved my problem, i can now play a filename through a serial.println.
All i want to do now is read the player module so it will tell be, when the song ends, when it starts, things like "file not found" etc. The module is capable of;
Play music via receiving filename command "filename\r\n" Return "Play ok\r\n" if success. Return "Not found\r\n" if failed to find the file.
Return "over\r\n" if finish playing one song.
Pause Play ":p\r\n" Return "pause\r\n" if success
Continoue Play ":s\r\n" Return "start\r\n" if success
Play next ":n\r\n" Return "next\r\n" if success?Return "false\r\n" if failed
Play previous ":u\r\n" Return "key up\r\n"
Set the volume ":v 255\r\n"?set the volume, from 0 (minimum)-255 (maximum), Return "vol set ok" if success
My current code:
int incomingByte = 0;
void setup() {
// define pin modes for tx, rx, led pins:
pinMode(0, INPUT);
pinMode(1, OUTPUT);
digitalWrite(0, HIGH);
digitalWrite(1, HIGH);
// set the data rate for the SoftwareSerial port
Serial.begin(19200);
Serial.println("Test of arduino player module");
delay(2000);
Serial.println("\\:v 210\r\n");
delay(2000);
Serial.println("\\7\r\n");
}
void loop () {
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte);
}
}
Problem is, this serial read, prints it in decimals and i want this in the text eg. File not found, Play ok.. im new to arduino programming so not familiar with Serial.read
Connect to your mp3 player using SoftwareSerial. Send commands to it using those pins. Read the input back from those pins and send it to the screen using Serial.print.
dannable:
Connect to your mp3 player using SoftwareSerial. Send commands to it using those pins. Read the input back from those pins and send it to the screen using Serial.print.
ok i understand how to send commands to the pins. Im just guessing how to read the input back from the pins.. within the software serial.. but no idea on using serial.print. this is what i got:
#include <SoftwareSerial.h>
SoftwareSerial mp3player(7,8); //RX, TX
void setup() {
// define pin modes for tx, rx, led pins:
pinMode(0, INPUT);
pinMode(1, OUTPUT);
digitalWrite(0, HIGH);
digitalWrite(1, HIGH);
// set the data rate for the SoftwareSerial port
Serial.begin(19200);
Serial.println("Test of arduino player module");
delay(2000);
mp3player.begin(19200);
mp3player.println("\\:v 210\r\n");
mp3player.read();
mp3player.print(); // ????
}
void loop()
{
}
Look up Serial.print and Serial.println for an explanation and guidance on how to use them. Once you have the hardware serial port working add your mp3 player using SoftwareSerial. You had that working earlier as you could use the 'next track' command. Once both work in the same program read data from the SoftwareSerial port and write it to the Serial port.
serial monitor give me numbers though, whats next ?
You tell us what the numbers ARE.
Serial.println(mp3player.read());
The read() method returns an int. The print method converts the int to a string. That is NOT what you want. You need to do one of these:
char ltr = mp3player.read();
Serial.println(ltr);
or
Serial.println((char)mp3player.read());
There is a available() method that tells you how many (could be 0) characters there are to read. It would then be necessary for you to loop and read all the data.
i got: ÿ
i got: ÿ
on 19200 braud and "both NL & CR"
Using:
Serial.begin(19200);
mp3player.begin(19200);
mp3player.println("\\:v 210\r\n");
Serial.print("i got: ");
Serial.println((char)mp3player.read());
delay(1000);
mp3player.println("\\5\r\n");
Serial.print("i got: ");
Serial.println((char)mp3player.read());[\code]
i got: o
i got: l