Lego Mindstorms EV3 and ev3dev
So recently my Lego infatuation led, as it inevitably would, to Lego Mindstorms.
This post discusses a lot of the setup I’ve done to get the EV3 controller brick set up for development using a “normal” programming language instead of the visual one provided by Lego. That does look to be a nice way for a lot of people, especially kids, to learn to program robots. However, as a guy who has spent a very large number of years programming, visual languages like that are a bit confining. So imagine how happy I was to see that the ev3dev project has stepped in! (More about that later in this post)
So now I have a pretty functional development environment set up – time to work on some actual robotics!
- Remote Editing
- RSA Key for SSH
- FTP Server
- Python 3
While some of these such as remote editing are Mac-specific, a lot of the content here is the same regardless of your host computer.
Ev3dev is an awesome replacement OS for the EV3 brick, available here: ev3edev.
I won’t duplicate a lot of detail that’s on their website, but in general, it provides an alternate OS that lets you write Mindstorms programs in a variety of languages. The one I’m using is Python. The entire project is really slick, and an impressive accomplishment.
The ev3dev build I’m using is Jessie 2015-12-30.
All of the steps here assume that it is installed and running, and a network connection has been established along with being SSHed into the brick. (All of that is covered on the ev3dev website.)
Disclaimer: I have not gone back to a clean install of ev3dev and run though the steps in this post, so while I believe I captured everything, it is certainly possible I missed something.
Enable remote editing with TextMate
This obviously assumes that you have the latest TextMate running on your Mac. Did I mention that this post is going to be Mac-centric in places?
$ sudo gem install rmate
Add this to your
Host * RemoteForward 52698 localhost:52698
Or, when starting SSH, you can do this and not muck with the SSH config file:
$ ssh -R 52698:localhost:52698 firstname.lastname@example.org
Setup RSA key for SSH
By setting up the RSA key for my host computer, I can skip needing to enter a password every time I log in via SSH.
On the Mac:
$ scp ~/.ssh/id_rsa.pub email@example.com:/tmp
This assumes that an RSA key has been previously generated! You can generate a key using the
ssh-keygen command, which will create the private and public keys in (typically) the ~/.ssh directory. The file without the extension is the private key, and the one with the
.pub extension is the public key.
This public key is the one transfered to the system you want to access, and append to its
On the EV3:
$ mkdir ~/.ssh $ cat /tmp/id_rsa.pub >> ~/.ssh/authorized_keys
Even though I can edit files via
sip them back and forth from the remote shell, it’s nice to be able to move batches of files etc. via FTP. And with something like the Transmit application as an FTP client it’s trivial to do a sync and essentially back up my EV3 home directory to my Mac.
I spent a stupid amount of time trying to get vsftpd installed and running (installation went smoothly, but running always failed with an error no matter what I tried. And I tried a lot of things!)
So, since my goal is just to have simple FTP access, on to plan B – use Python! I grabbed a very nice FTP package for Python here: https://pypi.python.org/pypi/pyftpdlib/
The following shows the steps I went through (you may want to update the
wget line based on the current version of pyftplib). In a long-ago effort to install this library on a Beaglebone, the installer failed, so the steps below include just manually moving the library into place – didn’t want to invest a lot of time debugging that issue since manually moving it seemed to work just fine.
Install the FTP package
$ wget https://pypi.python.org/packages/source/p/pyftpdlib/pyftpdlib-1.5.0.tar.gz $ gunzip pyftp* $ tar -xf pyftp*.tar $ sudo mv pyftpdlib /usr/lib/python2.7
Create the FTP Server Python program
I added a super-simple FTP server program to my home directory
#!/usr/bin/env python from pyftpdlib.handlers import FTPHandler from pyftpdlib.servers import FTPServer from pyftpdlib.handlers import FTPHandler from pyftpdlib.servers import FTPServer authorizer = UnixAuthorizer(rejected_users=["root"], require_valid_shell=True) handler = FTPHandler handler.authorizer = authorizer handler.abstracted_fs = UnixFilesystem address = ('', 21) ftpd = FTPServer(address, handler) ftpd.serve_forever()
This will allow you to log in using any account other than
root. By default, the username of
robot and the password
Set up to start the FTP server at bootup
Add this script as
#!/bin/sh python /home/robot/ftpserver.py
Then make it executable and let the init system know to run it at boot up:
$ sudo chmod +x /etc/init.d/ftpserver $ sudo update-rc.d ftpserver defaults
Set up to use Python3 (this may not be needed with a future release of ev3dev?)
Note that Python 3 is pre-installed on the ev3dev distribution but some of the supporting libraries are not, which is what makes these steps necessary.
$ sudo apt-get update $ sudo apt-get install python3-pil $ sudo python3 -m easy_install python-ev3dev
Note that “apt-get update” may take a while…