Go Down

Topic: Tutorial Interfacing with arduino over serial (Read 698 times) previous topic - next topic


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:


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

Code: [Select]

// 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);

// 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


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/

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131