WiFi Controlled Mobile Robot

Similar documents
A REST API for Arduino & the CC3000 WiFi Chip

Monitor Your Home With the Raspberry Pi B+

Wireless Security Camera with the Arduino Yun

Arduino Home Automation Projects

Arduino Lesson 16. Stepper Motors

Network/Floating License Installation Instructions

Eric Mitchell April 2, 2012 Application Note: Control of a 180 Servo Motor with Arduino UNO Development Board

All About Arduino Libraries

How to program a Zumo Robot with Simulink

E-Blocks Easy Internet Bundle

Yun Shield Quick Start Guide VERSION: 1.0 Version Description Date 1.0 Release 2014-Jul-08 Yun Shield Quick Start Guide 1 / 14

Arduino Lesson 1. Blink

Arduino Wifi shield And reciever. 5V adapter. Connecting wifi module on shield: Make sure the wifi unit is connected the following way on the shield:

Intro to Intel Galileo - IoT Apps GERARDO CARMONA

2.2" TFT Display. Created by Ladyada. Last updated on :15:09 PM EDT

Internet of Things with the Arduino Yún

Board also Supports MicroBridge

Beginning Web Development with Node.js

IR Communication a learn.sparkfun.com tutorial

ICON UK 2015 node.js for Domino developers. Presenter: Matt White Company: LDC Via

Adafruit MCP9808 Precision I2C Temperature Sensor Guide

Getting Started with Android Smartphones and ThingWorx

Arduino Lesson 13. DC Motors. Created by Simon Monk

Work with Arduino Hardware

Yun Shield User Manual VERSION: 1.0. Yun Shield User Manual 1 / 22.

Frequently Asked Questions: Cisco Jabber 9.x for Android

Arduino Lesson 0. Getting Started

Manual Instruction for. AU06-DL13W/RGB/30K MiLight Wifi LED Controller

Building a Robot Kit with a Raspberry PI 2 and Windows 10 IoT Core

Arduino Lesson 14. Servo Motors

STB- 2. Installation and Operation Manual

Waspmote. Quickstart Guide

Adafruit SHT31-D Temperature & Humidity Sensor Breakout

DS1307 Real Time Clock Breakout Board Kit

Adafruit's Raspberry Pi Lesson 5. Using a Console Cable

To download and install directly to your phone

MeshBee Open Source ZigBee RF Module CookBook

Honeywell Internet Connection Module

Adafruit CC3000 WiFi. Created by Rick Lesniak. Last updated on :30:11 PM EDT

Sending an SMS with Temboo

N300 WiFi Range Extender WN2000RPT User Manual

Arduino & Android. A How to on interfacing these two devices. Bryant Tram

Using GitHub for Rally Apps (Mac Version)

The full setup includes the server itself, the server control panel, Firebird Database Server, and three sample applications with source code.

cs281: Introduction to Computer Systems Lab08 Interrupt Handling and Stepper Motor Controller

CS 589 Project Smart Home Hub, Phase I Due before 9am on October 21, 2015

Bluetooth + USB 16 Servo Controller [RKI-1005 & RKI-1205]

System Area Manager. Remote Management

Speedlink software will run on Windows NT, Windows 7, and Windows 8; it will run on both 32 byte and 64 byte versions of Windows.

The self-starting solar-powered Stirling engine

Dr Robot C# Advance Sputnik Demo Program

Tiny Arduino Music Visualizer

Adafruit's Raspberry Pi Lesson 5. Using a Console Cable. Created by Simon Monk

Arduino Due Back. Warning: Unlike other Arduino boards, the Arduino Due board runs at 3.3V. The maximum. Overview

CMS Server Installation Guide

Using the T&D Thermo App with TR-7wf Data Loggers

Android Dongle. User Manual TL869

Quick Start Guide. Installing. Setting up the equipment

Site Monitor. Version 5.3

Hadoop Data Warehouse Manual

MediaTek LinkIt Smart 7688 FAQ

1.8" TFT Display Breakout and Shield

Course Project Documentation

Step-by-Step Tutorial For Using LinkSprite UART- WIFI Module Model LS_UART_WIFI

Six-servo Robot Arm. DAGU Hi-Tech Electronic Co., LTD Six-servo Robot Arm

Adafruit's Raspberry Pi Lesson 5. Using a Console Cable

Spontania User Setup Guide

Nighthawk AC1900 WiF Range Extender

Using the Push Notifications Extension Part 1: Certificates and Setup

Motorising the Peco Turntable - a different approach

FileMaker Server 15. Getting Started Guide

Introduction to programming moway

Arduino Lesson 5. The Serial Monitor

#include <Gamer.h> Gamer gamer; void setup() { gamer.begin(); } void loop() {

How to develop your own app

Next Gen Platform: Team & Mentor Guide

DESIGN OF A TOUCHLESS USER INTERFACE. Author: Javier Onielfa Belenguer Director: Francisco José Abad Cerdá

ROBOTC Software Inspection Guide with Additional Help Documentation

N300 WiFi Range Extender

Network Monitoring User Guide Pulse Appliance

EARTH PEOPLE TECHNOLOGY SERIAL GRAPH TOOL FOR THE ARDUINO UNO USER MANUAL

Connecting Arduino to Processing a

Quick Start. Nighthawk X8 AC5300 Tri-Band WiFi Router Model R8500. Package Contents. NETGEAR, Inc. 350 East Plumeria Drive San Jose, CA USA

PN532 NFC RFID Module User Guide

Arduino Lesson 17. Sending Movement Detector

Data Sheet. Adaptive Design ltd. Arduino Dual L6470 Stepper Motor Shield V th November L6470 Stepper Motor Shield

Rapid Game Development Using Cocos2D-JS

mypro Installation and Handling Manual Version: 7

TUTORIAL FOR INITIALIZING BLUETOOTH COMMUNICATION BETWEEN ANDROID AND ARDUINO

Wireless Communication With Arduino

INTRODUCTION TO SERIAL ARM

Building a Basic Communication Network using XBee DigiMesh. Keywords: XBee, Networking, Zigbee, Digimesh, Mesh, Python, Smart Home

ipad 2 Basic Setup Guide

AutoDome Modular Camera System VG4 Series Firmware Update Manual. Firmware Update Manual

Shearwater Research Dive Computer Software Manual

Cloudwords Drupal Module. Quick Start Guide

Mercury User Guide v1.1

Getting Started with the AllJoyn Lighting Service Framework 14.12

TUTORIAL 3 :: ETHERNET SHIELD AND TWITTER.COM

Using Integrated Lights-Out in a VMware ESX environment

Transcription:

WiFi Controlled Mobile Robot Created by Marc-Olivier Schwartz Last updated on 2015-05-03 05:00:10 AM EDT

Guide Contents Guide Contents Introduction Connections Arduino sketch Building the web interface How to Go Further 2 3 4 7 10 14 Adafruit Industries https://learn.adafruit.com/wifi-controlled-mobile-robot Page 2 of 14

Introduction The CC3000 WiFi chip has a wide range of applications, and thanks to breakout boards like the Adafruit CC3000 breakout board, it is very easy to interface this chip with open-source platforms like Arduino. In this guide, we will focus on one of these applications: robotics. We are going to see how to plug the CC3000 WiFi breakout board on a mobile robot to control it remotely from your computer, or from your smartphone or tablet. This particular type of control uses a seperate server computer that the robot contacts to get "instructions", rather than hosting the server locally. If you'd like to check out an example of how to run a lightweight server on the CC3000+Arduino itself check out the WiFi candy bowl project (http://adafru.it/cvi)! The tutorial will start by introducing the different components that you need to build a robot suitable for this tutorial, and how to plug the WiFi chip to your robot. Then, we'll see how to write the Arduino sketch & the server-side interface. Finally, you will find a short video of the robot in action. Let's dive in! Adafruit Industries https://learn.adafruit.com/wifi-controlled-mobile-robot Page 3 of 14

Connections In this part, we are going to see how to completely setup the hardware part for this project. The core of this project is to connect the CC3000 breakout board to your robot. For this reason, I will not go through the details of the different parts of the robot, as your own robot can be slightly different. Instead, I will go through the main parts that your robot should have so this tutorial can work. The robot is basically a 2-wheels robot with a round base, and two ball casters to make it stable. The wheels are connected to 6V DC motors. The whole project is powered by a 7.5 V battery. This guide will work as well for servos or stepper motors, but you will have to make some changes in the code. Then, the command part is composed of an Arduino Uno, a motor shield, and a prototype shield to mount the CC3000 breakout board. I used boards from DFRobot for all these components, but you can use similar components from the supplier of your choice. You will find links to the equivalent Adafruit boards in the featured products on the right. I also added two ultrasonic sensors that won't be used in this tutorial, one on the front, one on the back of the robot. The following picture summarises the essential parts of the robot I used for this tutorial: Adafruit Industries https://learn.adafruit.com/wifi-controlled-mobile-robot Page 4 of 14

When you have your robot ready, you have to connect the CC3000 breakout board on the prototype shield on top of the robot. The important thing here is that you have to make sure that you don't interfere with the motor shield you have between the Arduino and the prototype shield. For example, on my board the motors are using pins 4,5,6 and 7, so I made sure that I didn't connect anything to these pins. Write down these pins for your motor shield, we will need them later. The following picture describes the hardware connections for the CC3000 breakout board: Adafruit Industries https://learn.adafruit.com/wifi-controlled-mobile-robot Page 5 of 14

This is how it should look like at the end: Adafruit Industries https://learn.adafruit.com/wifi-controlled-mobile-robot Page 6 of 14

Arduino sketch Let's now see the Arduino sketch for this project. You will need to have the Arduino IDE (http://adafru.it/f5e) installed on your computer, as well as the Adafruit CC3000 library (http://adafru.it/cfn) and the arest (http://adafru.it/dis) library. To install the library, simply clone the Git repository or extract the files in your Arduino /libraries folder. The sketch basically connects the CC3000 WiFi chip to your WiFi network, creates a web server on the Arduino board, and then start listening for incoming connections. When it gets the commands, it applies them directly to the two motors to move the robot accordingly. The main parts of the sketch are explained below, and you can find the complete code on the GitHub repository of the project (http://adafru.it/f5f). The sketch starts by importing the required libraries: #include <Adafruit_CC3000.h> #include <SPI.h> #include <arest.h> #include <avr/wdt.h> After that, we have to declare the pins for the CC3000 breakout board: #define ADAFRUIT_CC3000_IRQ 3 #define ADAFRUIT_CC3000_VBAT 8 #define ADAFRUIT_CC3000_CS 10 And the pins corresponding to your motor shield (that's where you need to enter your own values depending on the motor shield you are using): int speed_motor1 = 6; int speed_motor2 = 5; int direction_motor1 = 7; int direction_motor2 = 4; We can now set the parameters that depends on your WiFi network. You will need to modify these lines of code with your WiFi network configuration: #define WLAN_SSID "yournetwork" // cannot be longer than 32 characters! #define WLAN_PASS "yourpassword" #define WLAN_SECURITY WLAN_SEC_WPA2 // This can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLA Adafruit Industries https://learn.adafruit.com/wifi-controlled-mobile-robot Page 7 of 14

We also need to create the CC3000 instance: Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_ SPI_CLOCK_DIV2); We then create a server on our Arduino, that will accept the incoming connections coming from the network: // The port to listen for incoming TCP connections #define LISTEN_PORT 80 // Server instance Adafruit_CC3000_Server restserver(listen_port); Now, in the setup() function of the sketch, there is a large number of functions to connect to the WiFi network that we won t detail here. We also start the WiFi server: restserver.begin(); Serial.println(F("Listening for connections...")); And enable the watchdog, so our sketch restarts automatically if there is any problem: wdt_enable(wdto_4s); In the loop() function, we accept incoming connections and process them, and check if we are still connected to the network: // Measure distance distance = measure_distance(distance_sensor); // Handle REST calls Adafruit_CC3000_ClientRef client = restserver.available(); rest.handle(client); wdt_reset(); // Check connection if(!cc3000.checkconnected()){while(1){}} wdt_reset(); Adafruit Industries https://learn.adafruit.com/wifi-controlled-mobile-robot Page 8 of 14

Let s now have a look at one of the functions we will use to control the robot. Let s take the one that makes the robot goes forward: int forward(string command) { send_motor_command(speed_motor1,direction_motor1,100,1); send_motor_command(speed_motor2,direction_motor2,100,1); return 1; } We can see that we simply call the function send_motor_command twice, once per motor. This function is also defined in the sketch: void send_motor_command(int speed_pin, int direction_pin, int pwm, boolean dir) { analogwrite(speed_pin,pwm); // Set PWM control, 0 for stop, and 255 for maximum speed digitalwrite(direction_pin,dir); } It s now time to test the sketch. Make sure you modified it with your own WiFi parameters, and upload it to the robot. Open the Serial monitor, and check that the connection details are correctly printed, and note the IP address of your board. Let s it was 192.168.1.103, like in my case. You can now disconnect the USB cable from the robot. Then, go a web browser and type: http://192.168.1.103/id You should get the same answer as before, meaning the arest API is working via WiFi. Now, just type: http://192.168.1.103/forward You should see the robot going forward at full speed. To stop it, just do the same with the stop command. Adafruit Industries https://learn.adafruit.com/wifi-controlled-mobile-robot Page 9 of 14

Building the web interface Now, it s great to be able to command our robot remotely, but it is not ideal: we still need to type in commands in a browser. This is why we are going to build an interface based on the powerful Node.js framework. We are going to see some insights about this interface, but of course you can just skip this whole part and go straight at the end where we use the robot interface. For the interface, you will need to have Node.js installed on your computer. You can find all the installation instructions on the official Node website (http://adafru.it/dip). We first start with the main app.js file, which we will execute later. It starts by declaring that we are using the express module of Node.js: var express = require('express'); var app = express(); We also define the port on which we will access our interface: var port = 3000; We also have to declare some things concerning the express application: // View engine app.set('view engine', 'jade'); // Set public folder app.use(express.static( dirname + '/public')); What s important now is to define the main route of the application, which is where the application will redirect us when we access it in the browser. Here, we will simply render the interface that we will define later: // Serve interface app.get('/', function(req, res){ res.render('interface'); }); After that, we import the arest node module, that will handle all the communication with our robot. We also add a device at the address of our robot: Adafruit Industries https://learn.adafruit.com/wifi-controlled-mobile-robot Page 10 of 14

var rest = require("arest")(app); rest.adddevice('http','192.168.1.103'); Finally, we start the app and print a message in the console: app.listen(port); console.log("listening on port " + port); Let s now see the interface file, that is located in the application /views subfolder. This is a file written in the Jade format, which is basically a way to simplify HTML. You don t need to know all the details, just that we define one button per function of the robot, and also a field to print out the distance measured by the front sensor: doctype html head title Robot Control link(rel='stylesheet', href='/css/interface.css') link(rel='stylesheet', href='/css/flat-ui.css') script(src="/js/jquery-2.1.1.min.js") script(src="/js/interface.js") body.maincontainer.title Robot Control.buttonBlock button.btn.btn-block.btn-lg.btn-primary#1 Forward.buttonBlock button.btn.btn-block.btn-lg.btn-primary#2 Left button.btn.btn-block.btn-lg.btn-primary#3 Right.buttonBlock button.btn.btn-block.btn-lg.btn-primary#4 Backward.buttonBlock button.btn.btn-block.btn-lg.btn-danger#5 Stop.buttonBlock div.display#distance Distance:.buttonBlock div.status#wifistatus Offline Finally, we define a Javascript file to handle the interface, located in the /public/js folder of the application. For each button, we define an event in case the user click on it. For example, the first button is called forward, so we naturally route it to the forward function on the robot: Adafruit Industries https://learn.adafruit.com/wifi-controlled-mobile-robot Page 11 of 14

$("#1").click(function() { }); $.get('/robot/forward'); Finally, we refresh the status of the distance sensor & the connection indicator every second using this piece of code: setinterval(function() { $.get('/robot/distance', function( json_data ) { if (json_data.distance){ $("#distance").html("distance: " + json_data.distance); } if (json_data.connected == 1){ $("#wifistatus").html("online"); $("#wifistatus").css("color","green"); } else { $("#wifistatus").html("offline"); $("#wifistatus").css("color","red"); } }).fail(function() { $("#wifistatus").html("offline"); $("#wifistatus").css("color","red"); }); }, 1000); Note that all the code for this part can be found in the GitHub repository of the project: https://github.com/openhardwaredrones/wifi-mobile-robot (http://adafru.it/f5f) It s now time to test our application. Go the interface folder of the code you downloaded, and type: sudo npm install express arest jade This will install the required modules for the application. You can now type: node app.js This will start the application, and you should get the confirmation message in the console. You will Adafruit Industries https://learn.adafruit.com/wifi-controlled-mobile-robot Page 12 of 14

also see that the robot is added as a new device inside the application. You can now go to your favorite browser and go to: http://locahost:3000/ You should see the interface being displayed inside the web browser: You should see that the robot is immediately going online, and you should also see the measurement coming from the front sensor. Now, go ahead and press the buttons: you should see that the robot is reacting accordingly. Adafruit Industries https://learn.adafruit.com/wifi-controlled-mobile-robot Page 13 of 14

How to Go Further Let s summarise what we did in this project. We built an Arduino-based mobile robot, and controlled it via WiFi using the arest API. We also built a simple interface based on Node.js to control the robot via a graphical interface. How course, there are several ways to go further with this project. You can for example add more sensors to the robot, for example an accelerometer, and then also integrates them into the Node.js interface. Finally, you can also add more complex behaviour inside the robot code, for example automatically move the robot back when detecting an obstacle in front of it. Adafruit Industries Last Updated: 2015-05-03 05:00:11 AM EDT Page 14 of 14