I am trying to learn how to code with Arduino so I can interface it with the RS232 port on a Motorola Micom HF radio. There are ton of these on ebay for less than $200 now. They are fully controllable via RS232 9600 baud serial. I built a cable and can control the radio with the MRC control software but the volume control was never integrated into the software. When the radio boots up it defaults to the lowest setting and is inaudible. I have a control head on loan but my goal is to learn enough to build an Arduino control head similar to the one in the Uniden remote head project thread.
My first goal I think would be to try to send the appropriate commands to set the volume. According to the documentation is breaks down as this:
Opcode: actual control code hex number
Length: length of entire control message excluding the length code, checksum and end of message which is always (03)
A volume message breaks down like this (all in hex):
24 = header indicating start of message
03 = length of message
18 = indicates direction of data (18 to radio) (81 from radio)
2B = opcode (2B is the opcode for volume control)
12 = volume level in hex
00 = temporary volume level (can be 01 for constant volume or 02 for clear constant)
7C = checksum (sum of all bytes in the message but checksum and EOM, modulo 256)
03 = EOM (end of message)
So, I could either have a table of various volume levels or some sort of algorithm that would calculate a potentiometer value and create the appropriate code according to those parameters. At first I would like to just have it match a few sensor levels and output a precanned data packet when the condition is met.
I found an example of code in the IDE that is somewhat similar but I'm not sure how to mod it to transmit my custom control packets. I could see where the printSensor should be replaced with possibly printSerial or something similar and perhaps strings of the precanned messages could be substituted.
Does anyone have any suggestions?
/*
Serial Call and Response in ASCII
Language: Wiring/Arduino
This program sends an ASCII A (byte of value 65) on startup
and repeats that until it gets some data in.
Then it waits for a byte in the serial port, and
sends three ASCII-encoded, comma-separated sensor values,
truncated by a linefeed and carriage return,
whenever it gets a byte in.
Thanks to Greg Shakar and Scott Fitzgerald for the improvements
The circuit:
* potentiometers attached to analog inputs 0 and 1
* pushbutton attached to digital I/O 2
Created 26 Sept. 2005
by Tom Igoe
modified 26 Oct 2011
by Tom Igoe and Scott Fitzgerald
This example code is in the public domain.
Arduino - SerialCallResponseASCII
*/
int firstSensor = 0; // first analog sensor
int secondSensor = 0; // second analog sensor
int thirdSensor = 0; // digital sensor
int inByte = 0; // incoming serial byte
void setup()
{
// start serial port at 9600 bps:
Serial.begin(9600);
pinMode(2, INPUT); // digital sensor is on digital pin 2
establishContact(); // send a byte to establish contact until receiver responds
}
void loop()
{
// if we get a valid byte, read analog ins:
if (Serial.available() > 0) {
// get incoming byte:
inByte = Serial.read();
// read first analog input:
firstSensor = analogRead(A0);
// read second analog input:
secondSensor = analogRead(A1);
// read switch, map it to 0 or 255L
thirdSensor = map(digitalRead(2), 0, 1, 0, 255);
// send sensor values:
Serial.print(firstSensor);
Serial.print(",");
Serial.print(secondSensor);
Serial.print(",");
Serial.println(thirdSensor);
}
}
void establishContact() {
while (Serial.available() <= 0) {
Serial.println("0,0,0"); // send an initial string
delay(300);
}
}
My first goal I think would be to try to send the appropriate commands to set the volume. According to the documentation is breaks down as this:
Opcode: actual control code hex number
Length: length of entire control message excluding the length code, checksum and end of message which is always (03)
A volume message breaks down like this (all in hex):
24 = header indicating start of message
03 = length of message
18 = indicates direction of data (18 to radio) (81 from radio)
2B = opcode (2B is the opcode for volume control)
12 = volume level in hex
00 = temporary volume level (can be 01 for constant volume or 02 for clear constant)
7C = checksum (sum of all bytes in the message but checksum and EOM, modulo 256)
03 = EOM (end of message)
So, I could either have a table of various volume levels or some sort of algorithm that would calculate a potentiometer value and create the appropriate code according to those parameters. At first I would like to just have it match a few sensor levels and output a precanned data packet when the condition is met.
I found an example of code in the IDE that is somewhat similar but I'm not sure how to mod it to transmit my custom control packets. I could see where the printSensor should be replaced with possibly printSerial or something similar and perhaps strings of the precanned messages could be substituted.
Does anyone have any suggestions?
/*
Serial Call and Response in ASCII
Language: Wiring/Arduino
This program sends an ASCII A (byte of value 65) on startup
and repeats that until it gets some data in.
Then it waits for a byte in the serial port, and
sends three ASCII-encoded, comma-separated sensor values,
truncated by a linefeed and carriage return,
whenever it gets a byte in.
Thanks to Greg Shakar and Scott Fitzgerald for the improvements
The circuit:
* potentiometers attached to analog inputs 0 and 1
* pushbutton attached to digital I/O 2
Created 26 Sept. 2005
by Tom Igoe
modified 26 Oct 2011
by Tom Igoe and Scott Fitzgerald
This example code is in the public domain.
Arduino - SerialCallResponseASCII
*/
int firstSensor = 0; // first analog sensor
int secondSensor = 0; // second analog sensor
int thirdSensor = 0; // digital sensor
int inByte = 0; // incoming serial byte
void setup()
{
// start serial port at 9600 bps:
Serial.begin(9600);
pinMode(2, INPUT); // digital sensor is on digital pin 2
establishContact(); // send a byte to establish contact until receiver responds
}
void loop()
{
// if we get a valid byte, read analog ins:
if (Serial.available() > 0) {
// get incoming byte:
inByte = Serial.read();
// read first analog input:
firstSensor = analogRead(A0);
// read second analog input:
secondSensor = analogRead(A1);
// read switch, map it to 0 or 255L
thirdSensor = map(digitalRead(2), 0, 1, 0, 255);
// send sensor values:
Serial.print(firstSensor);
Serial.print(",");
Serial.print(secondSensor);
Serial.print(",");
Serial.println(thirdSensor);
}
}
void establishContact() {
while (Serial.available() <= 0) {
Serial.println("0,0,0"); // send an initial string
delay(300);
}
}