Go Down

Topic: Communicating with Arduino via Serial (Read 1 time) previous topic - next topic

BLaZuRE

I am currently working on flashing an LED connected to one of the pins on my Arduino.  I would like it to do it from C++ for Windows and Android.
Does anyone have any tips on what I should do?  Right now, I only want an LED to flash, but eventually I want it to send/receive bytes from the Arduino.

PaulS

Quote
Right now, I only want an LED to flash

Then just load the blink sketch.

Quote
but eventually I want it to send/receive bytes from the Arduino.

Serial.print(), Serial.write(), Serial.available(), and Serial.read() deserve scrutiny.

Quote
I would like it to do it from C++ for Windows

Is that different than C++ for Linux? I don't think so.


BLaZuRE

I can easily make the Arduino flash using Arduino code or the example sketch.

I am talking about making the Arduino LED flash from C++, not via a sketch.  I want to specify some input pin to receive a flashing signal from C++.

Also, yes I believe Windows is different from Linux in the way that it opens and communicates with ports.  I would assume that a library would have different code to open a port in Windows than a port in Linux.

senti

Communication between Arduino and C# program is a something suprisely easy to do.
Check out this url:

http://www.technicana.com/physical-computing/73-connect-to-the-arduino-with-c-.html

zoomkat

Simple LED control code.

Code: [Select]

// zoomkat 8-6-10 serial I/O string test
// type a 1 or 0 in serial monitor. then send or enter
// for IDE 0019 and later

void setup() {
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  Serial.println("serial blink 0021"); // so I can keep track of what is loaded
  Serial.println("send a 1 to turn LED on");
  Serial.println("send a 0 to turn LED off");
}

void loop()
{
  while (Serial.available() > 0){
    char c = Serial.read();
    if (c == '1') digitalWrite(13, HIGH);
    if (c == '0') digitalWrite(13, LOW);
  }
}

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

BLaZuRE

Thank you senti, you helped me connect the dots.

I finally figured out that I need both a sketch that needs to be uploaded to the Arduino, that will handle Serial communication and act upon that serial communication (i.e. flash an LED when a byte is sent).  From the computer C++ code, I can then send information via Serial to the Arduino.  In my searches, I had always found either Arduino code to receive serial information or C++ code to send serial information separately, but did not understand that you needed both.

tkbyd

More on what you want to do at....

http://sheepdogguides.com/arduino/art4SeIntro.htm

The PC-side code isn't written in C++, but the basic ideas are all there, and many specifics which will help you.

Go Up