/* Reading CAT commands and queries from HDSDR */ // include LCD library: #include // initialize the LCD library by associating any needed LCD interface pin // with the arduino pin number it is connected to const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7; LiquidCrystal lcd(rs, en, d4, d5, d6, d7); const int numRows = 2; // LCD number of rows const int numCols = 16; // LCD number of columns volatile uint32_t vfo = 7000000ULL; // initial value for vfo freq. (7MHz) String vfoString = ""; // a String to hold incoming data String inputString = ""; // a String to hold incoming data boolean stringComplete = false; // flag whether the string is complete /* SerialEvent occurs whenever a new data comes in the hardware serial RX. This routine is run between each time loop() runs. */ void serialEvent() { while (Serial.available()) { char inChar = (char)Serial.read(); // get the new byte inputString += inChar; // add it to the inputString if (isDigit(inChar)) // check if it is a digit { vfoString += (char)inChar; // convert the incoming byte to a char and add it to the vfoString string vfo = vfoString.toInt(); // update vfo variable with new freq. value } if (inChar == ';') // if the incoming character is a ';' (end of CAT command), { // set a flag so the main loop can do something about it: stringComplete = true; } } } // end of serialEvent() void setup() { Serial.begin(9600); inputString.reserve(200); // reserve 200 bytes for the inputString // set up the LCD's number of columns and rows: lcd.begin(16, 2); lcd.clear(); char buffr[14]; // prepare a char buffer array sprintf(buffr, "FA%011ld;", vfo); // format the string Serial.print(buffr); // send VFO freq command to HDSDR } // end of setup() void loop() { if (stringComplete) { if(inputString == "FA;") // FA; is a SDR VFO frequency query { char buffr[14]; // prepare a char buffer array sprintf(buffr, "FA%011ld;", vfo); // format the response Serial.print(buffr); // answer the query. lcd.setCursor(0, 1); // first column on second line lcd.print(buffr); // print the answer to LCD } lcd.setCursor(0, 0); // first column on first line lcd.print(inputString); // print input string to LCD inputString = ""; // clear the string vfoString = ""; // clear the string stringComplete = false; // change flag delay(500); // wait a moment lcd.clear(); // clear display } } // end of loop()