howto: Build MicroPython on Debian Linux or a Raspberry Pi for the ESP8266

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
gojimmypi
Posts: 36
Joined: Wed Mar 02, 2016 8:01 pm
Contact:

howto: Build MicroPython on Debian Linux or a Raspberry Pi for the ESP8266

Post by gojimmypi » Wed Mar 30, 2016 7:00 pm

First: The this is *not* the official documentation on how to build esp-open-sdk and MicroPython, rather this is information that I found helpful for building on Debian and Raspberry Pi.

See http://forum.micropython.org/viewtopic.php?f=16&t=1689 and http://forum.micropython.org/viewtopic. ... 9114#p9188

edit 5/23/2016: minor updates, code cleanup, include link (above) to official build documentation.

edit 9/25/2016: added make myp-cross - see https://github.com/micropython/micropyt ... er/esp8266

edit 4/23/2017: removed --flash-size parameter from esptool.py (it now auto-detects, and old value would not upload properly)

I was having a difficult time (1) being patient waiting for the next kickstarter firmware to arrive in my inbox, and (2) finding instructions all in one place regarding how to build MicroPython from the git repository from scratch myself. So I came up with this! I hope others find it useful. This is all done from a windows machine, either connecting to the RPi with putty - or on a Debian install with VMware.

There are some other useful tidbits thrown in. They can be uncommented and used as desired.

Basically the instructions are:
  • - Install Raspian (Jessie) on a Raspberry Pi with at least 16GB free SD
    -- or --
    - Install Debian (Jessie) on a machine or in a VM
    - Install toolchain
    - Get recent esp-open-sdk and compile it
    - Add xtensa-lx106-elf to your path
    - Get recent micropython and compile it
    - Get esptool
    - Send binary image to your EPS8266 using esptool
    - Write cool MicroPython apps
So here's what I came up with (I'm certainly not a master at Linux, so let me know how it can be improved):

https://github.com/gojimmypi/build_esp8266

This version has some command-line parameters:

Code: Select all

Usage:
./build_esp8266.sh [OPTION]

OPTIONS

  HELP
    show this help. Source will be placed in ~/workspace/ directory.

  FULL
     Update RPi, download latest esp-open-sdk and micropython, build everything, erase and upload new binary to /dev/ttyUSB0

  MAKE-ONLY
     Download latest esp-open-sdk and micropython, build everything.

  MAKE-ONLY-ESP8266
     Download latest micropython and build (skip esp-open-sdk).
     
  RUN-TESTS
     Run the esp8266 test script

  FLASH-ONLY
     Only writing existing flash to device. (no updates, no build)
Note that the lines to actually erase and flash your ESP8266 IS NO LONGER commented out.

If all is successful, Ta-da!

Code: Select all

�ó�ì�päl�pcl`��lûcould not find module 'boot'

#4 ets_task(40100264, 3, 3fff4668, 4)
MicroPython v1.6-380-g9c04299 on 2016-04-07; ESP module with ESP8266
Type "help()" for more information.
>>> print("hello world!")
hello world!
>>>
Note: sometimes there are a few errors at boot time that look kinda scary, but this is a build straight from git - and we all know still very much in alpha stage. :) Simply press enter, and the MicroPython prompt appears.

Some folks have suggested doing all this in a VM. Although I agree this would be good on a "real" debian... well, with the easily re-imaged SD disk in the RPi, I treat raspian as essentially a VM, complete with snapshots and all! I keep all sorts of SD images on hand for the RPi. (the win32diskimager tool is great for this, but not nearly as fast and convenient as VMware). The drawback is the RPi compile takes a long time (well in excess of an hour).

Update: Debian on a VM with a SSD is incredibly faster than the RPi! (ok, not really a surprise here, eh?) A fresh install of Debian was missing some critical dependencies that are otherwise installed by default on the RPi (e.g. curl, git, and compiler). So for Debian - I added a new debian_specific.sh:

Code: Select all

# this is not a bash script, rather best used as copy & paste since su command will start a new shell

#start root shell
su

apt-get update && apt-get upgrade
apt-get install curl
apt-get install git
apt-get install build-essential

# sudo is only needed to check if script is running as root. can be ommited
apt-get install sudo

# this next line makes sure the current user is allowed to use sudo (omit if not installing sudo)
echo "$USER ALL=(ALL:ALL) ALL" >> /etc/sudoers

#exit root shell
exit
Then to get started quickly and easily, I created a quick_start.sh:

Code: Select all

#!/bin/bash

curl https://raw.githubusercontent.com/gojimmypi/build_esp8266/master/build_esp8266.sh > build_esp8266.sh

chmod +x build_esp8266.sh

./build_esp8266.sh
I'll update this message as needed, and update script on https://github.com/gojimmypi/build_esp8266 as needed. Let me know if you have any comment or suggestions.

Many thanks again to Damien, Paul and Viktoriya for this really excellent project! You seriously rock :)
Last edited by gojimmypi on Sun Apr 23, 2017 11:30 am, edited 4 times in total.

Lornioiz
Posts: 36
Joined: Wed Aug 03, 2016 11:39 am
Location: Florence, Italy

Re: howto: Build MicroPython on Debian Linux or a Raspberry Pi for the ESP8266

Post by Lornioiz » Fri Nov 25, 2016 11:48 am

Thank you Gojimmypi, great tutorial.

One question: how do I update the source code in the VM when a new version of Micropython is out?

Thanks!

gojimmypi
Posts: 36
Joined: Wed Mar 02, 2016 8:01 pm
Contact:

Re: howto: Build MicroPython on Debian Linux or a Raspberry Pi for the ESP8266

Post by gojimmypi » Sat Apr 22, 2017 10:17 pm

Lornioiz wrote:Thank you Gojimmypi, great tutorial.

One question: how do I update the source code in the VM when a new version of Micropython is out?
@Lornioiz thanks, I am glad you found it helpful. :)

by doing a

Code: Select all

./build_esp8266 FULL 
all of the most recent code should be downloaded, including all of the supporting toolchain updates such as esptool and esp-open-sdk, as well as operating system.

stay tuned for an update to my build_esp8266, as I am working on using this same build tool to compile things other than MicroPython (e.g. your own C source).

jonathanscottjames
Posts: 1
Joined: Thu Mar 08, 2018 1:59 pm

Re: howto: Build MicroPython on Debian Linux or a Raspberry Pi for the ESP8266

Post by jonathanscottjames » Thu Mar 08, 2018 2:22 pm

lol. i tell you i was loosing hope with all the errors on "make"
but i ran upgrade and update a few times and still was hopeless.
then i reset a few times and looked in "start"/"programing" and there it was.. thanks
even though the scripting is different and i cant seem to get it,,
python 3 ide execuits almost 10% it runs faster and seems much smoother..
i used my serial click speed tester script which sprints a stream of numbers to the ide terminal
i put this on my on github: www.github.com/jonathanscottjames/jsj_p ... -for-scope

was yielding 16270 average now max= 17936 min= 13839 avr= 17535.050986842107
-------------------------------------------------------------------------------------------------------------------------------
#!/usr/bin/env python27
import RPi.GPIO as GPIO
from datetime import datetime
import time

GPIO.setmode(GPIO.BCM) # set board mode to Broadcom
countingb=0
countington=0
timington=time.time()
averagington=0
average=0
maxington=0
minington=0

GPIO.setwarnings(False) #this supresses error messages to avoid clutter
GPIO.setup(2, GPIO.IN, pull_up_down=GPIO.PUD_UP) #set pull up resistor so grounding will change it
GPIO.setup(3, GPIO.OUT) #set gpio 4 to output mode
GPIO.setup(4, GPIO.OUT) #set gpio 4 to output mode
#GPIO.setup(channel, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

#************** end setup *****************************
# `

timington = time.time()+1
while True:
GPIO.output(4, 1)
GPIO.output(4, 0)
GPIO.output(3, 1)
GPIO.output(3, 0)
GPIO.output(3, 1)
GPIO.output(3, 0)
GPIO.output(3, 1)
GPIO.output(3, 0)
GPIO.output(3, 1)
GPIO.output(3, 0)
GPIO.output(3, 1)
GPIO.output(3, 0)
GPIO.output(3, 1)
GPIO.output(3, 0)
GPIO.output(3, 1)
GPIO.output(3, 0)
GPIO.output(3, 1)
GPIO.output(3, 0)
GPIO.output(3, 1)
GPIO.output(3, 0)
GPIO.output(3, 1)
GPIO.output(3, 0)
GPIO.output(3, 1)
GPIO.output(3, 0)
GPIO.output(3, 1)
GPIO.output(3, 0)
GPIO.output(3, 1)
GPIO.output(3, 0)
GPIO.output(3, 1)
GPIO.output(3, 0)
GPIO.output(3, 1)
GPIO.output(3, 0)
GPIO.output(3, 1)
GPIO.output(3, 0)
countington=countington+1
if ((timington)<time.time()):
print(countington, end=" ")
countingb=countingb+1
average=average+countington
if average>2000000000:
average=countington
countingb=1
averagington=average/countingb
if(countington>maxington):
maxington=countington
print(" ")
print ("max=",maxington," min=",minington," avr=",averagington)
if(minington==0):
minington=countington
if(countington<minington):
minington=countington
print(" ")
print ("max=",maxington," min=",minington," avr=",averagington)
countington=0
timington=time.time()+1

Post Reply