Pages: [1]   Go Down
Author Topic: Communicating with Arduino via Serial  (Read 1525 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Simple LED control code.

Code:
// 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);
  }
}

Logged

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

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Sussex UK / CT USA
Offline Offline
Edison Member
*
Karma: 0
Posts: 1028
Forums forever
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: