Pages: [1]   Go Down
Author Topic: Tutorial Interfacing with arduino over serial  (Read 416 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I made a video tutorial on how to receive commands from the computer over serial and recognize specific characters to do specific functions.

It will be a two part tutorial. Part1 is the arduino code and part2 will be some code written in python so for part 1 look here:

http://dredx.com/electronics/?p=199

for those more curious in just the code I wrote in the tutorial here it is...

Code:
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;
int state;

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  if (Serial.available() > 0) {
    if (Serial.peek() == 'c') { //check for the character that signifies that this will be a command
      Serial.read(); //remove the character that signifies this is a command from the serial buffer
      state = Serial.parseInt(); //store our expected integer into state
      digitalWrite(led,state); // set the state of the LED
    }
    while (Serial.available() > 0){ //Discard everything that we didn't expect
      Serial.read();
    }
  }
}
Logged

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

Part 2 which details the python side of things is posted here: http://dredx.com/electronics/2013/01/python-tutorial-to-send-data-to-arduino/
Logged

Pages: [1]   Go Up
Jump to: