Jim

[EV3DEV] Venturing into the World of EV3Dev and Python

Recommended Posts

Recently @MajorAlvega created an interesting topic about ev3dev, a Linux based operating system compatible with Mindstorms EV3.

One of the possible languages for programming the software for the brick is Python. I never paid much attention to Python as a potential language to do my EV3 programming. However, it has a very big pro, which is the option to use Visual Studio Code as the IDE for programming the brick.

In this topic I will share my experience with you. I will try to maintain an index in this first post.

LINKS

 

DISCLAIMER
I know the official name is ev3dev, but I will also use the term EV3Dev.

 

Share this post


Link to post
Share on other sites

STEP 1: MicroSD Card
My first step was to get a new microSD or microSDHC card. All the cards I own are 64GB and the EV3 brick only supports a max of 32GB.

I purchased the SanDisk 16GB.

Unfortunately, I didn't have time to continue installing Python this evening, so I will probably continue tomorrow.

Share this post


Link to post
Share on other sites

STEP 2: Download ev3dev-stretch

Next step is to download the proper version of ev3dev. Make sure to get the stretch version, not jessie. Check out the getting started section on ev3dev to follow the steps.

I will be working with ev3dev-stretch-ev3-generic-2018-08-06.zip

STEP 3: Flash the Micro SD Card

I need to download Etcher from their website and install it, in order to flash the card.

Done, that was easy.

Share this post


Link to post
Share on other sites

STEP 4: Boot EV3Dev

Booting....which will take a minute and....done!

I really wish the LCD was backlit btw, but that's a different discussion.

Share this post


Link to post
Share on other sites

STEP 4: Connect to Network

The first thing I tried was connecting to my Wifi network, using the Netgear WNA1000M Wireless N USB Micro Adapter. This one wasn't compatible with the default EV3 firmware. Works like a charm with ev3dev :wub:

s-l300.jpg

 

Too bad it isn't available anymore. Does anyone know if this one will work too?

1003004012437373.jpg

Could get this one too.

589897

Share this post


Link to post
Share on other sites

STEP 5: Connect to the EV3 using SSH

I have downloaded Putty and now I am trying to connect to the brick.

Connected to the robot using login robot and password maker.

 

Capture.PNG

STEP 6: Choosing the Programming Language

Since I have decided to go with Python, I will be using the Visual Studio Code extensions.

Share this post


Link to post
Share on other sites

I have setup VSCode, installed the extensions and downloaded the program. When I run it...VS states

/usr/bin/env: 'python3\r': No such file or directory

The first problem I encountered. Let's see what's wrong.

Share this post


Link to post
Share on other sites

If you encounter an error such as /usr/bin/env: 'python3\r': No such file or directory, you must switch your editor’s “line endings” setting for the file from “CRLF” to just “LF”. This is usually in the status bar at the bottom. For help, see our FAQ page.

Solved the issue, thanks to the Python Language Bindings for ev3dev.

So, I just ran my first program! :wub:

Victory!

 

Share this post


Link to post
Share on other sites

Great to watch your progress.

About the wi-fi dongles, I mostly use Enermax and ASUS N10 Nano. There are a few more - most (but not all) that work with the Raspberry Pi native OS (Raspbian) will also work. A few based on a specific Realtek chipset have some long run problems but recent kernel updates have made things better.

Share this post


Link to post
Share on other sites

I use this one:

https://www.amazon.com/Raspberry-Pi-WIFI-Adapter-Dongle/dp/B009FA2UYK/ref=sr_1_fkmr0_2?ie=UTF8&qid=1542755291&sr=8-2-fkmr0&keywords=pig+hut+wifi

 

4 hours ago, Jim said:

I really wish the LCD was backlit btw, but that's a different discussion.

It isn't as compact as an EV3 but a pi3 + brickpi3 + this screen:

https://www.amazon.com/gp/product/B01N447AEY/ref=oh_aui_search_detailpage?ie=UTF8&psc=1

makes for a nice alternative, it boots in about 8 seconds!!  I put a SSD on it once and the boot time was even better :) (I forget exactly how fast it was though)

Share this post


Link to post
Share on other sites
14 hours ago, MajorAlvega said:

Great to watch your progress.

About the wi-fi dongles, I mostly use Enermax and ASUS N10 Nano. There are a few more - most (but not all) that work with the Raspberry Pi native OS (Raspbian) will also work. A few based on a specific Realtek chipset have some long run problems but recent kernel updates have made things better.

Yeah, it worked out nicely yesterday. Accomplished the basics.

The Asus N10 Nano looks great....well the price does. Thanks, I will get me some of those. 

12 hours ago, dwalton76 said:

It isn't as compact as an EV3 but a pi3 + brickpi3 + this screen:

https://www.amazon.com/gp/product/B01N447AEY/ref=oh_aui_search_detailpage?ie=UTF8&psc=1

makes for a nice alternative, it boots in about 8 seconds!!  I put a SSD on it once and the boot time was even better :) (I forget exactly how fast it was though)

I probably need to get me something like that for my big robot project.

Let's say I want to connect like 16 motors (or a big number); how can I connect the EV3 motors to my pi3?

I see the Brickpi has several outputs, but I do need a lot of them. One option would be to use multiple Brickpi's, but maybe there is a better solution. Some of the motors can be multiplexed, but not all of them.

Share this post


Link to post
Share on other sites

More importantly; can I change the name of my brick? If I am not mistaken it is called ev3dev now and since I will be using multiple bricks, I like to call them EV3A, EV3B, EV3C and......EV3D :laugh:

My next step is to setup communication between multiple bricks. Ideally, I would designate one brick (EV3A) as the master and the other three as slaves. The master is the brain of the robot and the slaves provide sensory information and operate certain functions/motors.

Share this post


Link to post
Share on other sites
1 hour ago, Jim said:

Let's say I want to connect like 16 motors (or a big number); how can I connect the EV3 motors to my pi3?

Some of the motors can be multiplexed, but not all of them.

You can stack up to four brickpi3s on a single pi3 :) Support for this just went into ev3dev-lang-python about a month ago so you may need to clone the repo to run the latest and greatest.  You can see the port names for the stacked brickpi3s here:

https://github.com/ev3dev/ev3dev-lang-python/pull/562/files

In terms of motor multiplexors I am not sure which ones are supported on ev3dev off the top of my head.  I am sure there are some that are but I have never tried to use any of them.  Another option is to do a physical multiplexor:

I used this several years ago to combine an EV3 with an excavator to make it remote controlled.  I needed to be able to control six movements with just four motors:

In hindsight I should have used a smaller turntable that would have made it easier to fit everything.

2 hours ago, Jim said:

More importantly; can I change the name of my brick? If I am not mistaken it is called ev3dev now and since I will be using multiple bricks, I like to call them EV3A, EV3B, EV3C and......EV3D :laugh:

My next step is to setup communication between multiple bricks. Ideally, I would designate one brick (EV3A) as the master and the other three as slaves. The master is the brain of the robot and the slaves provide sensory information and operate certain functions/motors.

yep you can name the brick whatever you want.  ev3dev is just debian linux so anything you can do in debian you can do in ev3dev.

If you do not go the route of stacking brickpi3s and decide to do "setup communicatino between multiple bricks" come on over to ev3dev-lang-python and I can assign https://github.com/ev3dev/ev3dev-lang-python/issues/385 to you :)  We are always looking for new contributors and it sounds like you have a legit use case for that feature...it would be awesome if you implemented that one.

Share this post


Link to post
Share on other sites
On 11/21/2018 at 2:26 PM, dwalton76 said:

If you do not go the route of stacking brickpi3s and decide to do "setup communicatino between multiple bricks" come on over to ev3dev-lang-python and I can assign https://github.com/ev3dev/ev3dev-lang-python/issues/385 to you :)  We are always looking for new contributors and it sounds like you have a legit use case for that feature...it would be awesome if you implemented that one.

I will check out your answer about stacking brickpi's later (thanks a lot), but I am definitely interested in the "multiple brick communication", so I will come over to ev3dev-lang-python and give it a go. I must confess that I have zero Python experience, but I am a pretty experienced software engineer, so maybe I will be able to contribute :wink: 

Share this post


Link to post
Share on other sites

If you have software dev experience python is pretty easy to pick up...it is very readable. 

I did some digging and found a repo on GitHub where someone has already implemented the EV3 protocol in python...so from their laptop they can control an EV3. This part we should be able to bring into the ev3dev python library without a crazy amount of work.

What is missing is the code to implement the server side of the protocol. So if you want to take an EV3 and use it to control an ev3dev that code has not been written (not that I have found at least).  

Share this post


Link to post
Share on other sites
18 hours ago, Jim said:

I will check out your answer about stacking brickpi's later (thanks a lot), but I am definitely interested in the "multiple brick communication", so I will come over to ev3dev-lang-python and give it a go. I must confess that I have zero Python experience, but I am a pretty experienced software engineer, so maybe I will be able to contribute :wink: 

I broke the "support EV3 protocol" issue up into two issues, one to implement client support and one to implement server support:

It would probably be best to start with the "client support" issue.  A large chunk of that code is already written in another repo and you could test it by trying to control a stock EV3.

Share this post


Link to post
Share on other sites

Here is a TP-Link Wifi dongle that works on my EV3 with ev3dev.  I believe it is based on the Realtek chipset.  I didn't notice any network issues when I Putty'ed into my EV3.

ev3wifi.jpg

 

Instead of Etcher, I used Image Writer Win32DiskImager to put the *.img on my SD card since I am already using it to image SD cards for my Raspberry Pi'es.

Share this post


Link to post
Share on other sites
On 11/21/2018 at 2:26 PM, dwalton76 said:

yep you can name the brick whatever you want.  ev3dev is just debian linux so anything you can do in debian you can do in ev3dev.

I have edited the hostname file in etc with sudoedit from ev3dev to EV3A, but it still shows ev3dev in Putty and in VSCode. Any idea why?

Admittedly, I am a Windows man, so I really need to find my way in Debian. But I do like the challenge. Can you recommend any (visual) tools to browse the brick, instead of SSH commandline with Putty.

Share this post


Link to post
Share on other sites

I suddenly get pylint errors. Strange thing is that the led is actually causing an error. When I comment out the led statement, the program runs fine. And the funny thing is that the other day it worked with the led statement in the program.

I see in the readme todo "explain how to get code completion working". Can you tell me how to do this?

Sorry for all the questions, but I need to find my way around Python.

Python1.PNG

Share this post


Link to post
Share on other sites

not sure but I think the last import should be

from ev3dev2.led import Leds

 

And for visual browsing the file system I think WinSCP does that, it's like Filezilla but uses SSH instead of FTP.

I'm not sure but I think Filezilla also suports SSH but never used for that.

Share this post


Link to post
Share on other sites

Another question; is it possible to use the requests class in the EV3 bricks?

https://code.tutsplus.com/articles/how-to-use-restful-web-apis-in-python--cms-29493

Traceback (most recent call last):
File "/home/robot/vscode-hello-python/hello.py", line 8, in <module>
import requests
ImportError: No module named 'requests'

 

10 minutes ago, MajorAlvega said:

not sure but I think the last import should be

Ahhh yes, of course. That makes sense. Maybe I accidentally added the 4. It's working again, thanks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.