Hi Guys,
Hopefully looking for some general advice to keep me in the right direction. Fairly new to arduino, but have done MatLab programming before and understand basic logic and am slowly learning the limits of functions as I read more and more.
I am trying to build a basic speaker controller. I have a pair of Meridian DSP5200 speakers, which can be RS232 controlled and am hoping to eventually add a centre channel and surrounds and need a way of controlling all 3 [L/R, C, Sur] together [whilst keeping the respective volumes separate.]
I am using Arduino Uno and utilising 3 software serials at once. As I don't want to flood the system or require myself to add extraneous code, I am utilising serial from only front L speaker, which I am reading and the hoping to adjust the others to suit. Using 3 of the MAX232 TTL to Serial converters.
I have copied my code below so you can take a look.
//Meridian Speaker Controller
#include <SoftwareSerial.h>
SoftwareSerial LRSerial(8, 9); // RX, TX for Front L/R
SoftwareSerial CSerial(10, 11); // RX, TX for C Channel and Sub
SoftwareSerial SUSerial(12, 13); // RX, TX for Surround L/R
int AmpSource = 0; //need to read the amp current source
int AmpVol = 0; //need to read the current volume of the amp
const int COffsetVol = 3; //This value is the volume offset for the centre channel
int LRVolNew;
const int SUOffsetVol = 5; //This value is the volume offset for the surround channels
int SUVol;
int SUVolNew;
int CVol;
int CVolNew;
int LRVol;
int VolumeCommand = "VN";
int CVolSend = VolumeCommand + CVolNew;
int SUVolSend = VolumeCommand + SUVolNew;
void setup() {
Serial.begin(9600);
delay(10);
//This is for starting the front speakers(s)
LRSerial.begin(9600);
delay(10);
//This is for starting the C speaker(s) serial
CSerial.begin(9600);
delay(10);
//This is for starting the Surround speaker(s) serial
SUSerial.begin(9600);
delay(10);
}
void loop() {
LRSerial.listen();
delay(10);
// while there is data coming in, read it
// and send to the hardware serial port:
while (LRSerial.available() > 0) {
LRSerial.read();
LRVolNew = LRSerial.parseInt(SKIP_ALL); //Processes the integer out
Serial.println("LR Vol: ");
Serial.println(LRVolNew); //Prints it out
delay(50);
//This sets the new C Channel Volume, based on L/R Input
int CVolNew = (LRVolNew - COffsetVol);
Serial.println("C Vol: ");
delay(25);
Serial.println(CVolNew);
//This sets the new Su Channel Volume, also based on L/R Input
int SUVolNew = (LRVolNew - SUOffsetVol);
Serial.println("SU Vol: ");
delay(25);
Serial.println(SUVolNew);
while (LRSerial.available())
LRSerial.read();
}
//This adjust the centre channel volume if it needs to be
if (CVol != CVolNew) {
delay(10);
CSerial.print(CVolSend);
int CVol = CVolNew;
//Similarly, adjusting the surround channel(s) volume
delay(10);
SUSerial.print(SUVolSend);
int SUVol = SUVolNew;
}
}
Not looking for someone to rewrite this perfectly for me [as is too often the case here]. Just have a few questions regarding.
-I can get the program compiled with no errors and can now stop it looping unnecessarily using the while on LR serial, which is great.
-The next step is believe, is to send commands out on the other serial lines so that they may keep in step with the main [L/R] as required.'
-I was using CSerial.write and SUSerial.write to send these values to the speakers, but for some reason I cant seem to get them to respond. Am I missing something blaringly obvious?
-Format for sending volume commands to the speakers is VNXX, with XX being input parameters for volume (1-99).
As mentioned, any general advice here would be swell. Have also tried using CSerial.write and the same for the surrounds to no avail. I used the if statement down the bottom to avoid unnecessary looping and constant spamming on the serial ports, it only sends the command to change vol if it is out of step.
Again, as above, fairly new to arduino, happy to also cop a bit of flac for code layout/formatting
Many thanks!