C program that sends commands to Arduino program

Hi everyone,

I currently have a program on my Arduino that reads from the serial port and looks for a string and if the string from the serial port matches one of those strings, it executes the code in that block. This code currently works if I have my Arduino plugged in and type in strings into the serial monitor in the Arduino IDE. The problem that I'm trying to solve is that I want to create a C program that will print statements and then I want those statements to be read by the Arduino as if I was typing into the serial monitor. The purpose of this is that I have a separate piece of hardware that can run C programs and it hooks up to the Arduino and I 'm trying to run the program on the separate piece of hardware so that it talks to the Arduino.

#include <LiquidCrystal.h>

String input = "";
char inputbyte = 0;
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  delay(3000);
}


void loop()
{
  if(Serial.available() > 0){
    inputbyte = Serial.read();
    if(inputbyte != '\n'){
      input += inputbyte;
    }
    else{
      if(input == "start"){
        lcd.print("Welcome!");
        delay(3000);
        lcd.clear();
      }
      else if(input == "end"){
        lcd.print("Goodbye!");
        delay(3000);
        lcd.clear();
      }
      else{
        lcd.print("Oops!");
        delay(3000);
        lcd.clear();
      }
      input = "";
    }
  }
}

Thanks for all the help!

You need to learn how to send serial data from C, and determine how to specify the port the arduino is connected to.

That varies by PC and OS type.

Don't use C, it's a mess. Use C++.

aarg:
Don't use C, it's a mess. Use C++.

So is C++ Use Python or Ruby :slight_smile:

More seriously ...

It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. Just use cstrings - char arrays terminated with 0.

And have a look at the examples in Serial Input Basics - simple reliable ways to receive data. The technique in the 3rd example will be the most reliable and data can easily be sent in that format using any PC programming language.

...R

Or, my favorite, .NET C#.

Tell us about your "other piece of hardware", which is the topic of your actual question.