Hi everybody,
I installed "music player deamon" (mpd, mpc) on my new rasberry pi. I created a playlist that contains the urls of some internet radio stations. I "tune" the stations by turning a potentiometer's knob, connected to my Arduino.
This is done using the "map" function: the pot's range is divided by the number of stations which are in my playlist. (The number of stations is initially set in variable "maxNumb". So the pot delivers values between 1 and 26)
The station number that mpc has to play is transfered via serial communication; on raspberry this value is read by a bash script that controls mpc. That works fine and stable:
int sensorValue = analogRead(A0);
delay(100);
int upperValue = sensorValue + 2;
int lowerValue = sensorValue - 2;
} while (sensorValue < upperValue && sensorValue > lowerValue);
int tunerValue = map(sensorValue, 0, 1023, 1, maxNumb);
if (tunerValue < 10)
{
Serial.print(0);
}
Serial.println(tunerValue,DEC);
Now to my problem:
If I add more stations I want to automatically change the value of variable "maxNumb", so that all stations can be addressed using the potentiometer.
Rasperry sends the number of stations that are on the playlist to Arduino via the serial interface:
echo "$NUMBEROFSTATIONS" > /dev/ttyACM0
The transfered number is between 20 and 99. If arduino receives this new value, variable "maxNumb" should change and the new stations should be selectable with the pod.
I try to receive this value with the following code (works well on arduino's serial monitor, but not together with raspberry):
if (Serial.available())
{
char ch = Serial.read();
if(index < MaxChars && ch >= '0' && ch <= '9'){
strValue[index++] = ch; // add the ASCII character to the string;
}
else
{
// here when buffer full or on the first non digit
strValue[index] = 0; // terminate the string with a 0
maxNumb = atoi(strValue); // use atoi to convert the string to an int
index = 0;
}
}
Any ideas, why this works on the serial console but not when the data comes from the computer?
Schwabinger