Get Adobe Flash player
FacebookTwitterGoogle+
English Arabic French German Italian Portuguese Russian Spanish

Did you know?

The first use of water to generate electricity was in 1882 on the Fox river, in the USA, which produced enough power to light two paper mills and a house.
 

Help us stay online:

small donate

CaptureThis is tutorial explains how to use Docklight RS232 terminal to change Arduino variables with AT style commands (including full source code of the example).

Special features of Docklight adjustable Sending sequences with wildcards are also used.

Once you make your Microcontroller project, you will almost always want to have communication to change some of your project variables.
In this tutorial we are presenting very effective way to define different commands styled as standard modem AT commands.

Code is explained in details line by line and is C based so it can be used with any AVR compiler or PIC, dsPIC, MSP..

Once you incorporate this technique in you projects it will be a lot easier to maintain your code and add additional commands to your custom communication protocol.

 

 

Here is full source code, or you can download it from -->>THIS LINK<<--

 

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
}
char  incommingBuffer[30];
unsigned int  incommingBufferIndex = 0;
const char commandsArray[][20] = {
  "PARAMETER=",
  "MINUTE=",
  "HOUR=",
  "FREQUENCY="
};
unsigned int parameterArray[4];
enum {
  PARAMETER_INDEX,
  MINUTE_INDEX,
  HOUR_INDEX,
  FREQUENCY_INDEX,
  COMMANDS_INDEX_MAX
};
void loop() {
  // put your main code here, to run repeatedly:
  if (Serial.available())
  {
    incommingBuffer[incommingBufferIndex] = Serial.read();
    if (incommingBuffer[incommingBufferIndex] == '\n')
    {
      Serial.print("String recieved is: ");
      Serial.print(incommingBuffer);
      Serial.print("Length of incoming string is: ");
      Serial.println(incommingBufferIndex);
      for (int k = 0; k < COMMANDS_INDEX_MAX; k++)
      {
        if (strstr(incommingBuffer, commandsArray[k]))
        {
          Serial.print ("Command found is: ");
          Serial.print (commandsArray[k]);
          Serial.print(" Parameter value is:");
          Serial.println(strstr(incommingBuffer, commandsArray[k]) + strlen(commandsArray[k]));
          parameterArray[k] = atoi(strstr(incommingBuffer, commandsArray[k]) + strlen(commandsArray[k]));
        }
      }
      char  tmparray[200];
      sprintf(tmparray, "Current values are  PARAMETER:%d  MINUTE::%d  HOUR:%d  FREQUENCY:%d\n", parameterArray[PARAMETER_INDEX], parameterArray[MINUTE_INDEX], parameterArray[HOUR_INDEX], parameterArray[FREQUENCY_INDEX]);
      Serial.println(tmparray);
      memset(incommingBuffer, 0, sizeof(incommingBuffer));
      incommingBufferIndex = 0;
    }
    else
    {
      incommingBufferIndex++;
    }
  }
}