Sunday, July 10, 2016

Using Web and Cisco Spark to control a Lego EV3 Robot

I have bought the Lego Mindstorms EV3 robot for more than 2 years, however I didn't spend any time on it until recently.  My daughter was sick and she has to stay at home, to keep her busy I built the EV3 together with her and we had run some pre-set missions to make the robot move and did some simple tasks.  It works great, except that I have to use the Mindstorm software to program it.

There is also another iPhone app to give you basic control of your robot, however it only accepts bluetooth connection, which makes me a lot less flexible compare with Wifi.

I have done some googling and find this post:

It looks interesting to me and I would want to make it my first EV3 project.  This is what I've done:

1. Get an microSD card.  So happen I've found one old 2GB card at home and I've used that for this project.  Flash it with the ev3dev OS following the instruction in this page, it is based on Debian Linux:

2. Putting the microSD card into my EV3 and power it on.  It will not affect your original firmware in EV3, it is just like dual booting another OS.

3. Setting up the wireless network.  I've bought a wireless USB dongle from a local computer store, and it is less than US$9.  It works like a charm.  I did purposely pick one without 802.11ac, older model, claim to have Linux support.  Just bet on it, provided that it is so cheap.

4. Plug that into the USB port of EV3.  Use the screen on EV3 to choose my home wifi network, and entered the WPA PSK.  It is now connected, and able to access the Internet.

5. SSH to the box.  Use apt-get to get the packages, make sure you did a apt-get upgrade and update before you download the other packages.

sudo apt-get update; sudo apt-get upgrade
sudo apt-get install apache2 libapache2-mod-php5 unzip

6. Download the files in zip in this github project -  Unzip and copy these contents into your apache document root, in my case it is /var/www/html.  I download it to my Mac and then scp to the EV3, unzip it then copy it to the document root.

7. Install the python-ev3 on EV3 -  My version of python is 2.7, therefore these are the commands that I've issued to my EV3.

Python 2.7

apt-get update
apt-get install virtualenv virtualenvwrapper python-setuptools python-smbus python-pil
source /etc/bash_completion.d/virtualenvwrapper
mkvirtualenv ev3_py27 --python=/usr/bin/python2.7 --system-site-packages
workon ev3_py27
easy_install -U python-ev3
type deactive to exit

8. Download the python-ev3 project in zip file -  Similar to step 6, copy the content to the EV3.  In python-ev3, there is a ev3 folder.  Make sure this folder is copied to /var/www/html.  You will need to make sure you do this otherwise your will not work.

9. Some python libraries dependencies need to be resolved, and this is what I've done:

10.  Start your apache using the command /etc/init.d/apache2 start.  Run the LegoR2D2 python scripts with sudo.  tcp/8080 will be listened after you run the script.

11. Launch your web browser.  I have tried Chrome and Firefox, for some reasons it only works on my Firefox, probably it is something specific to my laptop.  By the way this is what you will see:

12.  Click on the arrows to move your robot!  Is that it?  No!  How about we using a Cisco Spark Chatbot to control the EV3?

1 comment:

dwalton76 said...

FYI there is an update to the seanbot code, this should make it much easier to use