Hacer una Web conectada Robot (por unos $500) (utilizando un Arduino y un Netbook) (3 / 6 paso)

Paso 3: Software - (Arduino)

Para ésos nuevos a Arduino revisa la gran guía que comenzó en Arduino.cc

Primer software que se ejecuta en el Arduino. Es un programa muy sencillo, lo que hace el Arduino es controlar el puerto serie para datos.

Lo que busca es una conversación de 5 bytes de longitud.

  • Byte 1-3 (bytes de verificación "AAA")
  • Comando de bytes 4 (dice el arduino que hacer) (admite comandos 'F' -, 'B' - al revés, 'L' 'R', izquierda - derecha, del ' - velocidad, 'X' - SetSpeedLeft, 'Y' - SetSpeedRight, 'C' - parada)
  • Parámetro del byte 5 - para el movimiento manda esto es interpretado como un intervalo de tiempo (parámetro * 100 ms), y para la velocidad manda un porcentaje de 0 a 100

El código es comentó fondo y dado este marco agregar comandos adicionales deben ser fácil.

Para descargar:

  • Descargue el archivo zip adjunto. (Código.zip 05-WEBB-Arduino)
  • Descomprimes en tu directorio de Arduino Sketch. (por defecto: mi Documents\Arduino\)
  • Abra su entorno de desarrollo arduino y subir a tu Arduino.

Copiar y pegar

  • Copie el código de abajo.
  • Pegar en el entorno de desarrollo Arduino.
  • Sube a tu Arduino.

Apéndice: El programa de Arduino

 /* * Arduino Controlled Web Connected Robot (WEBB) - Serial Host * For more details visit: http://www.oomlout.com/serb * * Behaviour: The Arduino listens to its Serial port for a command * in format 254, 88, 88, (COMMAND), (TIME) * Supported Commands - 'F' - 70 - Forward * 'B' - 66 - Backward * 'L' - 76 - Left * 'R' - 82 - Right * 'S' - 83 - Speed * 'X' - 88 - SetSpeedLeft * 'Y' - 89 - SetSpeedRight * 'C' - 67 - Stop * Supported Times - 0 - 255 (0 to 25.5 Seconds) value * 100 milliseconds *sp * Wiring: Right Servo Signal - pin 9 * Left Servo Signal - pin 10 * * License: This work is licenced under the Creative Commons * Attribution-Share Alike 3.0 Unported License. To * view a copy of this licence, visit * http://creativecommons.org/licenses/by-sa/3.0/ * or send a letter to Creative Commons, 171 Second * Street, Suite 300, San Francisco, California 94105, * USA. * */ //-------------------------------------------------------------------------//START OF ARDUINO SERIAL SERVER PREAMBLE//Defining constants corresponding to each command (also the ascii code number) #define FORWARD 70 //F#define BACKWARD 66 //B#define LEFT 76 //L#define RIGHT 82 //R#define SETSPEED 83 //S#define STOP 67 //C#define SETSPEEDLEFT 88 //X#define SETSPEEDRIGHT 89 //Y/*The three check bytes (used to keep the robot from responding to random serial *data) currently "AAA" */#define checkByte1 65 // "A"#define checkByte2 65 // "A"#define checkByte3 65 // "A" //--------------------------------------------------------------------------// START OF ARDUINO CONTROLLED SERVO ROBOT (SERB) PREAMBLE#include <Servo.h>#define LEFTSERVOPIN 10 //The pin the left servo is connected to#define RIGHTSERVOPIN 9 //The pin the right servo is connected toServo leftServo; Servo rightServo; int leftSpeed = 50; //holds the speed of the robots leftServo //a percentage between 0 and 100int rightSpeed = 100; //holds the speed of the robots rightServo //a percentage between 0 and 100// END OF ARDUINO CONTROLLED SERVO ROBOT (SERB) PREAMBLE//--------------------------------------------------------------------------//Gets everything up and runningvoid setup() { Serial.begin(9600); //Starts the serial port serbSetup(); //sets the state of all neccesary //pins and adds servos to your sketch}//The main program loopvoid loop() { serbPollSerialPort(); //continuously looks to the serial port //if there is data it processes it}//-----------------------------------------------------------------------//START OF ARDUINO SERIAL SERVER ROUTINES/* * Processes commands delivered to the arduino's serial port */void serbPollSerialPort(){ int dta; //variable to hold the serial byte if ( Serial.available() >= 5) { //if 5 bytes are in the buffer (length pf a full request) dta = Serial.read(); if ( dta = checkByte1){ //Checks for first check byte dta = Serial.read(); if ( dta = checkByte2){ //Checks for second check byte dta = Serial.read(); if ( dta = checkByte3){ //Checks for third check byte int command = Serial.read(); //Fourth byte is the command int param1 = Serial.read(); //Fifth byte is param1 interpretCommand(command, param1); //sends the parsed request to it's handler } } } }}/* * Takes the command and parameter and passes it to the robot */void interpretCommand(int command, int param1){if (command == FORWARD){goForward(); delay(param1 * 100); goStop();} //if forward else if(command == BACKWARD){goBackward(); delay(param1 * 100); goStop();} //if backwards else if(command == LEFT){goLeft(); delay(param1 * 100); goStop();} //if left else if(command == RIGHT){goRight(); delay(param1 * 100); goStop();} //if right else if(command == SETSPEED){setSpeed(param1);} //if setting speed else if(command == STOP){goStop();} //if stop else if(command == SETSPEEDLEFT){setSpeedLeft(param1);} //if setting left speed else if(command == SETSPEEDRIGHT){setSpeedRight(param1);} //if setting right speed else{ //if unrecognized command do a little shimmey goLeft(); delay(150); goRight(); delay(150); goStop(); }}//------------------------------------------------------------------------//START OF ARDUINO CONTROLLED SERVO ROBOT (SERB) ROUTINES/* * sets up your arduino to address your SERB using the included routines*/void serbSetup(){ setSpeed(leftSpeed); pinMode(LEFTSERVOPIN, OUTPUT); //sets the left servo signal pin //to output pinMode(RIGHTSERVOPIN, OUTPUT); //sets the right servo signal pin //to output leftServo.attach(LEFTSERVOPIN); //attaches left servo rightServo.attach(RIGHTSERVOPIN); //attaches right servo goStop();}/* * sets the speed of the robot between 0-(stopped) and 100-(full speed) * NOTE: speed will not change the current speed you must change speed * then call one of the go methods before changes occur.*/ void setSpeed(int newSpeed){ setSpeedLeft(newSpeed); //sets left speed setSpeedRight(newSpeed); //sets right speed}/* * Sets the speed of the left wheel */void setSpeedLeft(int newSpeed){ if(newSpeed >= 100) {newSpeed = 100;} //if speed is greater than 100 //make it 100 if(newSpeed <= 0) {newSpeed = 0;} //if speed is less than 0 make //it 0 leftSpeed = newSpeed * 0.9; //between 0 and 90}/* * Sets the speed of the right wheel */void setSpeedRight(int newSpeed){ if(newSpeed >= 100) {newSpeed = 100;} //if speed is greater than 100 //make it 100 if(newSpeed <= 0) {newSpeed = 0;} //if speed is less than 0 make //it 0 rightSpeed = newSpeed * 0.9; //scales the speed to be }/* * sends the robot forwards */void goForward(){ leftServo.write(90 + leftSpeed); rightServo.write(90 - rightSpeed);} /* * sends the robot backwards */void goBackward(){ leftServo.write(90 - leftSpeed); rightServo.write(90 + rightSpeed);} /* * sends the robot right */void goRight(){ leftServo.write(90 + leftSpeed); rightServo.write(90 + rightSpeed);}/* * sends the robot left */void goLeft(){ leftServo.write(90 - leftSpeed); rightServo.write(90 - rightSpeed);}/* * stops the robot */void goStop(){ leftServo.write(90); rightServo.write(90);}//END OF ARDUINO CONTROLLED SERVO ROBOT (SERB) ROUTINES//--------------------------------------------------------------------------- 

Artículos Relacionados

Hacer una calabaza de Halloween por uno mismo-equilibrio Robot

Hacer una calabaza de Halloween por uno mismo-equilibrio Robot

Calabaza es un símbolo típico de Halloween. Que siempre quisiste hacer una calabaza de a pie.Aquí les mostraré mi trabajo de utilizar un Robot de Self-balancing para moverse una calabaza brillante.Paso 1: preparación Lista de materiales principales:1
Cómo hacer una plataforma de Robot móvil de bajo costo

Cómo hacer una plataforma de Robot móvil de bajo costo

Este Instructable es sobre la construcción de una base robótica para apoyar los experimentos.Este Instructable es destinado a alguien para comenzar por una plataforma móvil de baja tensión. Otros lectores pueden encontrar algo interesante aquí tambié
Cómo hacer un control remoto inteligente web-títere por hacking Twitter, Google, Skype, Arduino y procesamiento!

Cómo hacer un control remoto inteligente web-títere por hacking Twitter, Google, Skype, Arduino y procesamiento!

Cómo manipular un objeto físico en la web sólo mediante el uso de servicios comunes de la web y sus datos de acceso se alimenta, con alguno añadido abrir cosas fuente para decodificar y manipular los datos y, en definitiva, utilizar los datos para mo
Cómo hacer una plataforma de Robot Arduino + frambuesa Pi

Cómo hacer una plataforma de Robot Arduino + frambuesa Pi

ACTUALIZACIÓN: Permite hacer Robots, mi hogar digital hackerspace, fue comprado por RobotShop. No quiero entrar, pero los nuevos propietarios prohibición yo y la mayoría de los miembros veteranos. Dijo la mayoría de los enlaces allí estará rota. Por
Hacer una web gratis 100%! Sin anuncios ni virus!

Hacer una web gratis 100%! Sin anuncios ni virus!

Es un sitio para crear sitios web totalmente gratis. Un sitio web personal o sitio web de la empresa, incluso una contraseña protegida sitio y usted puede crear todo por ti mismo y no se requiere ningún conocimiento de código pero ayudaría a crear un
Cómo hacer una web de Arduino servidor

Cómo hacer una web de Arduino servidor

En este ejemplo, utilizará su escudo de Ethernet y su Arduino para hacer un servidor Web básico. Utilizando la librería Ethernet dispositivo tendrá la capacidad para responder a una demanda HTTP con el shield Ethernet. La Ethernet estela de abrir un
Bunn-e-card - cómo hacer una tarjeta animada protagonizada por sus mascotas. Creer une e-carte de voeux personnalisee

Bunn-e-card - cómo hacer una tarjeta animada protagonizada por sus mascotas. Creer une e-carte de voeux personnalisee

divertirse creando una tarjeta personalizada que se puede enviar a través de internet o subir a su sitio favorito.Necesitas una mascota o mascotas, algo que les guste comer y una cámara sobre un trípode o mesa. El video explica cómo he creado esta ta
Cómo hacer una tortuga de juguete por Seth

Cómo hacer una tortuga de juguete por Seth

Cómo hacer una tortuga de juguete de maderaPaso 1: Reúna sus materialesHerramientas que necesarias:1. Sierra de cinta2. taladro de columna3. brocas de perforación4. lijadora de banda5. tabla router con ronda sobre pedacito6. gafas de protecciónSumini
Hacer una pistola de aire por debajo de $5

Hacer una pistola de aire por debajo de $5

esta es una guía sobre cómo hacer una pistola de aire de una pistola de Nerf.Paso 1: Materiales y herramientas Materiales:-Un arma de Nerf viejo-Un tubo de bolígrafo BIC-Un Nerf balaHerramientas:-Un par de tijeras-Pegamento gorilaPaso 2: El tubo de l
Cómo hacer una mesita de noche de lámpara de LED Arduino

Cómo hacer una mesita de noche de lámpara de LED Arduino

Cómo hacer una mesita de noche de lámpara de LED que tiene un cargador electrónico.Paso 1: Paso 1: reunir los materialesEl primer paso sobre cómo hacer una mesita de noche de lámpara de LED es reunir a todos sus materiales.Se necesita:1 ArduinoAlguno
HACER una célula sencilla por su cuerpo en solo unos segundo

HACER una célula sencilla por su cuerpo en solo unos segundo

creo que no necesito explicar es demasiado fácil, se puede entender a sí mismo. Usted puede utilizar las siguientes cosas para toda circuit.i utilizada diodo bcz parada condensador descarga por tu body.u va a necesitar estas cosas1. varilla de carbon
Hacer una web gratis sin el ABC de HTML

Hacer una web gratis sin el ABC de HTML

el nombre lo dice todo, hacer un sitio web gratis y sin ningún conocimiento de HTML, JavaScript o a alguno de los recién inventado cosas.Puede haber muchos instructables para este tema, así que vamos a comenzar.Aquí es lo que vamos a hacer-1) registr
Hacer una web básica usando Google Sites

Hacer una web básica usando Google Sites

puede crear una simple página web personal, familia, un club, clase u otro grupo. Tu motivo para crear un sitio de Google probablemente podrá ayudarle.Usted puede inscribirse en sitios hacia fuera pero recomiendo cantar para arriba para una cuenta de
Cómo hacer una bici-luz controlada por Arduino

Cómo hacer una bici-luz controlada por Arduino

microcontroladores son herramientas muy poderosas para la exploración en el mundo eléctrico. En este tutorial vamos a usar tablero de Arduino Uno, y le mostraremos cómo programar una serie de funciones básicas en una luz de bici de la protoboard. Par