Hi guys,
I'm currently working on a ground station transmitter controller for a satellite that I helped build over the summer. It's getting ready to launch October 27th, so I'm in a bit of a hurry to get the final touches on the software end of things to control the transmitter. Here's what I've run into tonight:
- char pointers (and pointers in general) can be quite dangerous with Arduinos. I have succeeded in wiping the bootloader on two Diecimilas tonight before I "discovered" the issue. All I really found out was that using "char*" wasn't a good idea.
- String objects seem very glitchy. I was not able to use String arrays to store a lot of text and then print it out later. The arrays seemed to overwrite themselves or something. I'm not quite sure what was going on to be honest.
- The same code loaded onto a working Diecimila wouldn't run, whereas it would run just fine on my new Uno. What's up with that?!
Here's the code:
//AubieSat-1 Ground Station Transmitter Controller/Interface
//Rev. 0 (10/15/2011)
/* Pin Definitions */
int IPA_Switch = 3;
int HPA_Switch = 4;
int Coax_Switch = 5;
int Spare_Switch = 6;
int Encoder_TE = 7;
int Encoder_AD11 = 8;
int Encoder_AD10 = 9;
int Encoder_AD9 = 10;
int Encoder_AD8 = 11;
int Melexis_FSKD = 12;
int Melexis_ENTX = 13;
/* Commands */
int numberOfCommands = 11;
char commands[][15] =
{
"txtime ",
"transmit ",
"hpaenable ",
"encoderenable ",
"carrierenable ",
"moduleenable ",
"antennaswitch ",
"spareenable ",
"fskdata ",
"command ",
"help "
};
char shortcuts[] =
{
'x',
't',
'h',
'e',
'i',
'm',
'a',
's',
'f',
'c',
'?'
};
char arguments[][20] =
{
"<0 to 10000> ",
"[hexadecimal byte] ",
"<0 or 1> ",
"<0 or 1> ",
"<0 or 1> ",
"<0 or 1> ",
"<0 or 1> ",
"<0 or 1> ",
"<0 or 1> ",
"<hexadecimal byte> ",
"[] "
};
char description[][36] =
{
"sets the transmit time in ms ",
"transmits the command ",
"enables/disables the HPA ",
"enables/disables the encoder ",
"enables/disables the carrier signal",
"enables/disables the module ",
"switches the coaxial relay ",
"enables/disables the spare relay ",
"sets the FSK data ",
"sets the command data ",
"displays the valid commands "
};
/* Other variables */
byte lastCommand = 0;
int currentTransmitTime = 1000;
void setup()
{
Serial.begin(19200);
Serial.println("Welcome to the AubieSat-1 Ground Station Transmitter Command Prompt");
Serial.println("Rev. 0 (10/15/2011)");
Serial.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
Serial.println("Warning: This unit controls a 100W amplifier. Do not operate this device");
Serial.println("without a proper 50 ohm load on the output. Also, make sure the coaxial");
Serial.println("relay is switched to the proper position when transmitting. Failure to do");
Serial.println("so will result in serious injury or death...to the equipment. Operating");
Serial.println("this transmitter from console assumes you know what you are doing. If you");
Serial.println("are unsure of what you are doing and/or you are not holding a valid amateur");
Serial.println("radio license, you should close this terminal window now.\n");
help();
for (int i = IPA_Switch; i <= Melexis_ENTX; i++)
{
pinMode(i, OUTPUT);
}
}
void help()
{
Serial.println("Available commands are:");
//Serial.println("txtime (x) <0 to 10000> sets the transmit time in ms ");
Serial.println("COMMAND (SHORTCUT) ARGUMENT DESCRIPTION");
for (int i = 0; i < 11; i++)
{
Serial.print(commands[i]);// + "(" + shortcuts[i] + ") " + arguments[i]);// + description[i]);
Serial.print(" (");
Serial.print(shortcuts[i]);
Serial.print(") ");
Serial.print(arguments[i]);
Serial.print(" ");
Serial.println(description[i]);
}
Serial.println("\nArguments in [] indicate that the argument is optional and that the command");
Serial.println("will be executed with or without an argument. Arguments in <> indicate that");
Serial.println("the command will echo the current configuration without executing the command.");
}
void loop()
{
//Serial.println("This is a test.");
//delay(500);
}
I would have preferred to use String objects wherever possible, but most of the time, the text output was composed of parts of other strings elsewhere in the program, even string literals. Sounds like a mis-malloc() to me, but I'm not positive.
I guess my biggest questions are these:
Why won't this code run on my working Diecimila, but it will run fine on my Uno?
Why won't this code work well with String objects, or will it but I'm doing something wrong?
Why can't I concatenate a string literal (const char[]) with a character array (char[])? Is it not common practice to do such a concatenation in a println() statement?
Why can I make a 2D char[] array (3D char array) with string literals in braces, but I can't make a 2D char[] array from char[] arrays in braces? Like this:
char c[][2] = {{'a', 'b'}, {'c', 'd'}}; //this works
vs.
char a[] = {'a', 'b'};
char b[] = {'c', 'd'};
char c[][2] = {a, b}; //this doesn't...
Thank you very much!