Redirecting terminal/WebRepl to OLED 1306

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
pythonista
Posts: 16
Joined: Sun Jun 12, 2016 4:51 pm

Redirecting terminal/WebRepl to OLED 1306

Post by pythonista » Mon Jun 20, 2016 6:21 pm

Any idea how can I easily redirect terminal output to OLED screen while typing over webrepl ?

I would really like to make "stand alone" python terminal :lol:

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Redirecting terminal/WebRepl to OLED 1306

Post by deshipu » Mon Jun 20, 2016 8:05 pm

I would look at how WebREPL does it (https://github.com/micropython/micropyt ... dwebrepl.c). I think it involves the os.dupterm call.

HermannSW
Posts: 197
Joined: Wed Nov 01, 2017 7:46 am
Contact:

Re: Redirecting terminal/WebRepl to OLED 1306

Post by HermannSW » Mon Oct 01, 2018 6:36 pm

Seems to be doable (I could read after Google translate Chinese->English):
https://blog.boochow.com/article/oled-c ... pterm.html
Image

Gist reply-to-oled.py can be found here:
https://gist.github.com/boochow

Code: Select all

from machine import I2C
i2c=I2C(1)
i2c.init(freq=1000000)
oled = SSD1306_I2C(128, 64, i2c)
console = FBConsole(oled)
os.dupterm(console)

I did copy FBConsole.py from there to ESP32 module with Oled:

Code: Select all

$ ~/webrepl/webrepl_cli.py FBConsole.py 192.168.4.1:
Password: 
op:put, host:192.168.4.1, port:8266, passwd:abcd.
FBConsole.py -> /FBConsole.py
Remote WebREPL version: (1, 9, 4)
Sent 2294 of 2294 bytes
$
My ESP32 module boots up with "oled" already:
https://www.esp32.com/viewtopic.php?f=2 ... 240#p31240
Image

"oled" is created as the oled in Gist in my boot.py.
Unfortunately the next line from Gist does not work:

Code: Select all

>>> from FBConsole import FBConsole
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "FBConsole.py", line 3, in <module>
AttributeError: 'module' object has no attribute 'IOBase'
>>> 
>>> import FBConsole
>>> console = FBConsole(oled)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable
>>> 
What am I missing? Or is the Gist just for Python and not for MicroPython?
Pico-W Access Point static file webserver:
https://github.com/Hermann-SW/pico-w

Tiny MicroPython robots (the PCB IS the robot platform)
viewtopic.php?f=5&t=11454

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

User avatar
mattyt
Posts: 410
Joined: Mon Jan 23, 2017 6:39 am

Re: Redirecting terminal/WebRepl to OLED 1306

Post by mattyt » Mon Oct 01, 2018 11:01 pm

Hi HermanSW,

That looks like legitimate MicroPython code (the 'u' prefixing . And uio.IOBase exists, at least on my recent-ish 1.9.4 build:

Code: Select all

MicroPython v1.9.4-564-gcb3c66e79 on 2018-09-21; ESP32 module with ESP32
Type "help()" for more information.
>>> import uio
>>> uio.
__class__       __name__        BufferedWriter  BytesIO
FileIO          IOBase          StringIO        TextIOWrapper
open
Which version of MicroPython are you running?

Googling the issue does identify a possible hint. Do you have an 'io' directory on the filesystem that could be confusing the import?

HermannSW
Posts: 197
Joined: Wed Nov 01, 2017 7:46 am
Contact:

Re: Redirecting terminal/WebRepl to OLED 1306

Post by HermannSW » Tue Oct 02, 2018 8:08 pm

> Which version of MicroPython are you running?
>
1.9.4 from May, see below.

> Do you have an 'io' directory on the filesystem that could be confusing the import?
>
No, I flashed MicroPython and had just single boot.py file then.
Never created directories, see below for which files are in filesystem:

Code: Select all

$ webrepl_client.py 192.168.4.1
Password: 

WebREPL connected
>>> 
>>> 
MicroPython v1.9.4 on 2018-05-11; ESP32 module with ESP32
Type "help()" for more information.
>>> uos.listdir()
['boot.py', 'webrepl_cfg.py', 'ssd1306.py', 'pye.py', 'FBConsole.py']
>>> 
P.S:

Code: Select all

>>> import uio
>>> help(uio)
object <module 'uio'> is of type module
  __name__ -- uio
  open -- <function>
  FileIO -- <class 'FileIO'>
  TextIOWrapper -- <class 'TextIOWrapper'>
  StringIO -- <class 'StringIO'>
  BytesIO -- <class 'BytesIO'>
  BufferedWriter -- <class 'BufferedWriter'>
>>> 
Pico-W Access Point static file webserver:
https://github.com/Hermann-SW/pico-w

Tiny MicroPython robots (the PCB IS the robot platform)
viewtopic.php?f=5&t=11454

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

User avatar
boochow
Posts: 30
Joined: Sat Dec 16, 2017 9:36 am

Re: Redirecting terminal/WebRepl to OLED 1306

Post by boochow » Wed Oct 03, 2018 1:58 pm

Hi,

IOBase had been added on 4 June.

https://github.com/micropython/micropyt ... 69700b0bee

An older version of FBClass.py is here, which I had written before IOBase was added.

https://gist.github.com/boochow/4163e00 ... 4c359527aa

hope this helps!

HermannSW
Posts: 197
Joined: Wed Nov 01, 2017 7:46 am
Contact:

Re: Redirecting terminal/WebRepl to OLED 1306

Post by HermannSW » Wed Oct 03, 2018 9:02 pm

Thank you! -- my fault.
I just installed latest 1.9.4

Code: Select all

MicroPython v1.9.4-623-g34af10d2e on 2018-10-03; ESP32 module with ESP32
after copying off all files with webrepl_cli.py, then I did screen session into ESP32, activated AP, enabled WebREPL and copied in all files via webrepl_cli.py again.

After reboot my Oled screen did show up nicely.
Then only 3 commands later REPL did show up on Oled!!

Code: Select all

>>> from FBConsole import FBConsole
>>> console = FBConsole(oled)
>>> os.dupterm(console)
<_webrepl>
>>> 
Image


P.S:
Ooops, seems I don't have matching ssd1306.py ... which ssd1306.py do you use?

Code: Select all

>>> os.listdir()
['boot.py', 'webrepl_cfg.py', 'FBConsole.py', 'pdupterm: Exception in write() method, deactivating: Traceback (most recent call last):
  File "FBConsole.py", line 62, in write
  File "FBConsole.py", line 50, in _putc
  File "FBConsole.py", line 77, in _newline
AttributeError: 'SSD1306_I2C' object has no attribute 'fill_rect'
ye.py', 'ssd1306.py']
>>> 
Pico-W Access Point static file webserver:
https://github.com/Hermann-SW/pico-w

Tiny MicroPython robots (the PCB IS the robot platform)
viewtopic.php?f=5&t=11454

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

HermannSW
Posts: 197
Joined: Wed Nov 01, 2017 7:46 am
Contact:

Re: Redirecting terminal/WebRepl to OLED 1306

Post by HermannSW » Wed Oct 03, 2018 9:23 pm

Wow!
I did google for "ssd1306.py fille_rect" and found this:
https://git.zgyarmati.de/zgyarmati/micr ... ssd1306.py

Then I did download it and copied it over to ESP32.
Adter doing soft reboot in screen session my initial Oled screen showed nicely.
Then doing the three commands from previous posting and REPL started on Oled.
This time without issues, with line scrolling, ...
Image
Pico-W Access Point static file webserver:
https://github.com/Hermann-SW/pico-w

Tiny MicroPython robots (the PCB IS the robot platform)
viewtopic.php?f=5&t=11454

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

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Redirecting terminal/WebRepl to OLED 1306

Post by pythoncoder » Thu Oct 04, 2018 5:01 am

HermannSW wrote:
Wed Oct 03, 2018 9:23 pm
...
I did google for "ssd1306.py fille_rect" and found this...
Is there a problem with the official version? It definitely supports fill_rect().
Peter Hinch
Index to my micropython libraries.

HermannSW
Posts: 197
Joined: Wed Nov 01, 2017 7:46 am
Contact:

Re: Redirecting terminal/WebRepl to OLED 1306

Post by HermannSW » Thu Oct 04, 2018 12:15 pm

pythoncoder wrote:
Thu Oct 04, 2018 5:01 am
Is there a problem with the official version? It definitely supports fill_rect().
Thanks for asking, I looked at it but found no "fill_rect" in that file.
Anyway I tried it and copied over to ESP32 module.
My normal boot.py Oled comands worked,
Image
as well os.dupterm with FBConsole. I will keep using the official ssd1306.py from now on.

While 16x8 character display might not be that useful to interact with MicroPython REPL, bigger displays definitely are.
Image


I really would like to see FBConsole from Boochow
https://gist.github.com/boochow/4163e00 ... 17cfc0297c
being part of official MicroPython.
If possible his repl-to-oled.py (as sample) somehow as well:
https://gist.github.com/boochow/f3bbd6a ... 20cbd9f9e0

Working with REPL is cool, accessing history commands with arrow up/down is fine. Moving cursor left seems to erase the character on display, but "END" key makes all visible again. I found a little bug sofar, if getting a history command, doing some arrow left, and then change something, is correct for first change action, but display gets scrambled for 2nd (like delete character, then insert new). Only display is scrambled, command is still correct as can be seen by pressing Return.
Pico-W Access Point static file webserver:
https://github.com/Hermann-SW/pico-w

Tiny MicroPython robots (the PCB IS the robot platform)
viewtopic.php?f=5&t=11454

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

Post Reply