Micropython as debug shell for ESP32 (and its OLED)

User avatar
HermannSW
Posts: 97
Joined: Fri Oct 27, 2017 6:58 am
Location: Eberbach, Germany
Contact:

Re: Micropython as debug shell for ESP32 (and its OLED)

Postby HermannSW » Fri Mar 02, 2018 6:01 pm

6 weeks ago I did kill my 2nd ESP32+OLED module due to bad soldering. I ordered two new modules that day, and they arrived today:
Image


I looked into this thread and the steps needed to get my "debug MicroPython" flashed seem not to be completely described.

This is how I did flash the bottom module today, the top module still runs the graphics demo application as arrived here:
  1. download and extract the .zip attached above
  2. modify flash.sh, then run ./flash.sh
  3. run "screen /dev/ttyUSB0 115200"
  4. press reset button on module
  5. copy below from boot.py and paste into screen session
  6. enable wireless access point on my smartphone
  7. connect laptop to smartphone AP as well
  8. click on both connected mac addresses in Android to identify ESP32 IP address
  9. ftp into ESP32 with "ftp 192.168.43.227" from laptop
  10. cd flash
  11. upload with "put boot.py" to ESP32
  12. in screen session do "machine.reset()" to reboot ESP32 into new boot.py
code for copy&paste:

Code: Select all

import sys
sys.path[1] = '/flash/lib'

import network
station = network.WLAN(network.STA_IF)
station.active(True)
station.connect("HUAWEI Y360-U61_8621", "verySecret")

import machine

network.ftp.start()

Next step is to repeat these steps with the other new module.

User avatar
HermannSW
Posts: 97
Joined: Fri Oct 27, 2017 6:58 am
Location: Eberbach, Germany
Contact:

Re: Micropython as debug shell for ESP32 (and its OLED)

Postby HermannSW » Fri Mar 02, 2018 6:14 pm

Of course you need to adapt network ssid and password to your AP.
For conveniance I attach my latest complete "boot.py" here.
Attachments
boot.zip
contains boot.py
(738 Bytes) Downloaded 481 times

User avatar
HermannSW
Posts: 97
Joined: Fri Oct 27, 2017 6:58 am
Location: Eberbach, Germany
Contact:

Re: Micropython as debug shell for ESP32 (and its OLED)

Postby HermannSW » Mon Sep 24, 2018 4:54 pm

A year is gone, and lately I worked a lot with ESP-01s modules (the 1MB new version of ESP-01) running MicroPython. Reason for ESP-01s instead of ESP32 is ESP-01s module 1.5g weight. It is part of remote servo bomb drop mechanism and will be attached to flying drone. The ESP-01s MicroPython will be controlled with a remote (console) webrepl_client.py session running on a mobile Pi ZeroW on the ground. I did all the development for webrepl_client.py against ESP-01s Micropython.

Just today I did flash 1.9.4 MicroPython on one of my ESP32 with Oled modules and tested -- webrepl_client.py worked like a charme with ESP32:
https://forum.micropython.org/viewtopic ... 427#p30434

From webrepl_client.py documentation:
https://github.com/Hermann-SW/webrepl#webrepl-shell

Code: Select all

$ webrepl_client.py 192.168.4.1 
Password: 

WebREPL connected
>>> A
raw REPL; CTRL-B to exit
>
OK>
MicroPython v1.9.4-8-ga9a3caad0 on 2018-05-11; ESP module with ESP8266
Type "help()" for more information.
>>> a
42
>>> E
paste mode; Ctrl-C to cancel, Ctrl-D to finish
=== a=43
=== 
>>> a
43
>>> 4**3**2
262144
>>> exit
### closed ###
$

I have to say that I currently prefer to connect remotely to ESP32 MicroPython with webrepl_client.py instead of telnet as previously described in this thread, because the WebREPL service is present on all versions of MicroPython, not needing special version with telnet server from loboris. And it works with ESP8266 module MicroPython as well (not sure whether there is a ESP8266 MicroPython with telnet server).


"WIRELESS ESP01S BOMB DROP SERVO WORKS RELIABLY FROM LIPO"
https://www.esp8266.com/viewtopic.php?f=15&t=18515
Image

User avatar
HermannSW
Posts: 97
Joined: Fri Oct 27, 2017 6:58 am
Location: Eberbach, Germany
Contact:

Re: Micropython as debug shell for ESP32 (and its OLED)

Postby HermannSW » Mon Sep 24, 2018 6:43 pm

These are the steps to get MicroPython with OLED setup with just WebREPL and WebREPL tools:
https://github.com/Hermann-SW/webrepl
  • flash any ESP32 MicroPython to module with esptool.py
    https://micropython.org/download#esp32
  • open screen session

    Code: Select all

    screen /dev/ttyUSB0 115200
  • do "import webrepl_setup", enable WebREPL and power cycle ESP32
  • open screen session again
  • activate access point

    Code: Select all

    import network
    ap = network.WLAN(network.AP_IF)
    ap.active(True)
    
  • detach screen session by pressing CTRL-A, then CTRL-D
  • download ssd1306.py from https://github.com/adafruit/micropython ... it-ssd1306
  • copy over to ESP32:

    Code: Select all

    $ webrepl/webrepl_cli.py ssd1306.py 192.168.4.1:
    Password: 
    op:put, host:192.168.4.1, port:8266, passwd:abcd.
    ssd1306.py -> /ssd1306.py
    Remote WebREPL version: (1, 9, 4)
    Sent 5477 of 5477 bytes
    $
  • store below boot.py (with or without modifications)
  • copy over to ESP32:

    Code: Select all

    $ webrepl/webrepl_cli.py boot.py 192.168.4.1:
    Password: 
    op:put, host:192.168.4.1, port:8266, passwd:abcd.
    boot.py -> /boot.py
    Remote WebREPL version: (1, 9, 4)
    Sent 637 of 637 bytes
    $ 
    
  • power cycle ESP32, that will result in Oled display as shown in photo below


Connect to the module as displayed on Oled, either with webrepl_client.py or with webrepl.html from github repo, or online:
https://micropython.org/webrepl/

Small WebREPL shell sample session:

Code: Select all

$ webrepl_client.py 192.168.4.1
Password: 

WebREPL connected
>>> oled.invert(1)
>>> os.listdir()
['boot.py', 'webrepl_cfg.py', 'ssd1306.py']
>>> 
And this is the boot script used, it displays whatever access point IP is configured:

Code: Select all

$ cat boot.py 
# This file is executed on every boot (including wake-boot from deepsleep)
#import esp
#esp.osdebug(None)

import network
ap = network.WLAN(network.AP_IF)
ap.active(True)

import webrepl
webrepl.start()

import machine, ssd1306
i2c = machine.I2C(scl=machine.Pin(4), sda=machine.Pin(5))
oled = ssd1306.SSD1306_I2C(128, 64, i2c)

oled.fill(0) 
oled.text(' MicroPython on ', 0, 0)
oled.text('ESP32 board with', 0, 9)
oled.text('- SSD1306 OLED  ', 0, 19)
oled.text('- WebREPL active', 0, 28)
oled.text('AP = ' + ap.ifconfig()[0], 0, 38)
oled.text('connect: webrepl', 0, 47)
oled.text('_client.py|.html', 0, 56)
oled.show()

import os, time

$
Image

Who is online

Users browsing this forum: No registered users and 114 guests