Micropython and TFT display test environment

Last Updated or created 2022-07-31

This exercise is to get a micropython dev environment with a graphical display.

pip3 install esptool adafruit-ampy

Erase board (use correct tty device!)

esptool.py --chip esp32 --port /dev/ttyUSB0 erase_flash

Flash using

esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 460800 write_flash -z 0x1000 esp32-20190125-v1.10.bin

Download from https://micropython.org/resources/firmware/esp32-20220618-v1.19.1.bin

Test with

screen /dev/ttyUSB0 115200

import machine

Great up and running

Now we have to install a boot loader
Use ampy to list files

#list boot
ampy -p /dev/ttyUSB0 ls 

#get boot.py
ampy -p /dev/ttyUSB0 get boot.py

vi boot.py (create new)

#import esp
#import webrepl

def connect():
    import network
    sta_if = network.WLAN(network.STA_IF)
    if not sta_if.isconnected():
        print('connecting to network...')
        sta_if.connect('WIFISSID', 'WIFIPASS')
        while not sta_if.isconnected():
    print('network config:', sta_if.ifconfig())

Push the file

ampy -p /dev/ttyUSB0 put boot.py
Usage: ampy [OPTIONS] COMMAND [ARGS]...

  ampy - Adafruit MicroPython Tool

  Ampy is a tool to control MicroPython boards over a serial connection.
  Using ampy you can manipulate files on the board's internal filesystem and
  even run scripts.

  -p, --port PORT    Name of serial port for connected board.  Can optionally
                     specify with AMPY_PORT environment variable.  [required]
  -b, --baud BAUD    Baud rate for the serial connection (default 115200).
                     Can optionally specify with AMPY_BAUD environment
  -d, --delay DELAY  Delay in seconds before entering RAW MODE (default 0).
                     Can optionally specify with AMPY_DELAY environment
  --version          Show the version and exit.
  --help             Show this message and exit.

  get    Retrieve a file from the board.
  ls     List contents of a directory on the board.
  mkdir  Create a directory on the board.
  put    Put a file or folder and its contents on the board.
  reset  Perform soft reset/reboot of the board.
  rm     Remove a file from the board.
  rmdir  Forcefully remove a folder and all its children from the board.
  run    Run a script and print its output.

Connect to serial console using screen

sudo screen /dev/ttyUSB0 115200
(use CTRL-A \ to exit)

Connect to wifi

import boot

Led blinky test, with below file named ledtest.py

import time
from machine import Pin
led=Pin(2,Pin.OUT)        #Internal led pin

while True:
  led.value(1)            #Set led turn on
  led.value(0)            #Set led turn off

Upload and run script

ampy -p /dev/ttyUSB0 put ledtest.py
import ledtest (without .py!)

Next todo: boot.py @boot ?!?
Run custom python after booting.
Connect display and play with drawing.

Tip: Install rshell !

sudo pip3 install rshell
fash@zspot:~$ rshell 
Welcome to rshell. Use Control-D (or the exit command) to exit rshell.

No MicroPython boards connected - use the connect command to add one

/home/fash> autoconnect: /dev/ttyUSB0 action: add

/home/fash> ?

Documented commands (type help <topic>):
args    cat  connect  date  edit  filesize  help  mkdir  rm     shell
boards  cd   cp       echo  exit  filetype  ls    repl   rsync

Use Control-D (or the exit command) to exit rshell.

Connecting the display

I’ve connected the display as above. Note the different connections on the display. Above fritzing part has connections for touch screen!
The 4 or 5 pins on the other side are for sdcard functionallity.

display       esp
SDO/MISO      D19
LED           VIN (5v)
SCK           D18
SDI/MOSI      D23
DC/RS         D15
RESET         D14
CS            D5
GND           GND
VCC           3.3V

Not my different ESP, gpio has high numbers and only 30 pins.
Most ESP have 2 SPI controllers. Check yours!

Software part

git clone https://github.com/rdagger/micropython-ili9341

Next create a setupmydisplay.py file, and edit your pin connections

from ili9341 import Display
from machine import Pin, SPI

TFT_CLK_PIN = const(18)
TFT_MOSI_PIN = const(23)
TFT_MISO_PIN = const(19)

TFT_CS_PIN = const(5)
TFT_RST_PIN = const(14)
TFT_DC_PIN = const(15)

def createMyDisplay():
    #spi = SPI(0, baudrate=40000000, sck=Pin(TFT_CLK_PIN), mosi=Pin(TFT_MOSI_PIN))
    spiTFT = SPI(2, baudrate=51200000,
                 sck=Pin(TFT_CLK_PIN), mosi=Pin(TFT_MOSI_PIN))
    display = Display(spiTFT,
                      dc=Pin(TFT_DC_PIN), cs=Pin(TFT_CS_PIN), rst=Pin(TFT_RST_PIN))
    return display

Now you can use the library by editing a example like demo_bouncing_boxes.py

Add and change

# At the beginning of the file
import setupmydisplay.py

Futher down comment two lines and add your own setup

        # Baud rate of 40000000 seems about the max
        #spi = SPI(1, baudrate=40000000, sck=Pin(14), mosi=Pin(13))
        #display = Display(spi, dc=Pin(4), cs=Pin(16), rst=Pin(17))
        display = setup.createMyDisplay()

Upload to ESP32 and testing!

ampy -p /dev/ttyUSB0 put demo_bouncing_boxes.py
ampy -p /dev/ttyUSB0 put setupmydisplay.py
# connect and start
sudo screen /dev/ttyUSB0 115200
import demo_bouncing_boxes.py

Race track Controller

Last Updated or created 2022-07-29

I got a vintage racetrack from a colleage a while back.

In the past i had some ideas controlling train or race tracks.
For train tracks i wanted to write intelligent maneuver software.
For a racetrack a web controllable race. Maybe with a webcam mounted on the car??

L298N – DC motor controller

So i bought a little DC motor controller (2 channels) and took a esp32.

GPIO04 Player1 IN1 
GPIO05 Player1 IN2
GPIO19 Player2 IN1 
GPIO18 Player2 IN2
GPIO13 PWM Player1
GPIO14 PWM Player2

The webinterface is behind a reverse proxy (apache)

TO BE POSTED .. arduino code

<VirtualHost *:443>
   SSLEngine on
   SSLProxyEngine On

   SSLProtocol all -SSLv2 -SSLv3 +TLSv1

   SSLCertificateFile /etc/ssl/.......cer
   SSLCertificateKeyFile /etc/ssl/private/........key
   SSLCertificateChainFile /etc/ssl/private/GlobalSignRootCA.cer
   SSLCertificateChainFile /etc/ssl/private/AlphaSSLCA-SHA256-G2.cer

   CustomLog /var/log/httpd/media_ssl_request_log "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

    ServerAdmin webmaster@henriaanstoot.nl
    ServerName race.henriaanstoot.nl

ProxyRequests Off
ProxyPreserveHost On
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off

<Location />

    ErrorLog /var/log/httpd/race.henriaanstoot.nl-error.log
    CustomLog /var/log/httpd/race.henriaanstoot.nl-access.log combined

Arduino IDE

Last Updated or created 2022-07-29

Adding boards:

File > Preferences > Additional Boards
Add url (comma separated)
Press OK

ESP32 :




After that go to the Board manager.
Tools > Board: ..... > Board Manager
Search board, click and install.
NOTE: Some sketches require a specific version!

Select your board, and write/open you sketch.

First thing to do is test compiling your sketch

Press the little button on the left


When you get a compile error like below, you are missing those libraries

Goto tools > Manage libraries

Search for your needed library, sometimes there are multiple which look alike. This is a trial and error approach.
Sometimes it doesn’t exists and you need to upload a zip containing the library. (Sketch > Include Library > Add .zip library

Downloading a zip containing the library
Adding the library zip file

When looking at the first lines of you sketch, there are include statements like:

#include <WiFi.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>

But sometimes there are statements without the < > characters.
Then it will be a included file just for your sketch.

Note the second tab MPU6050x.h which contains specific code only for this sketch.

Redo a test recompile using the tic icon again.

Everything okay? .. Select the correct port in Tools > Port
And press the Arrowright icon to upload/flash.
Note: sometimes you have to hold a button or press a little flash button on your device to flash.

esptool.py v3.3
Serial port COM8
Chip is ESP32-D0WDQ6-V3 (revision 3)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: c8:c9:a3:f9:02:d0
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600
Configuring flash size...
Flash will be erased from 0x00001000 to 0x00005fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x0000e000 to 0x0000ffff...
Flash will be erased from 0x00010000 to 0x000c7fff...
Flash params set to 0x022f
Compressed 18880 bytes to 12992...
Writing at 0x00001000... (100 %)
Wrote 18880 bytes (12992 compressed) at 0x00001000 in 0.3 seconds (effective 482.8 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 128...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (128 compressed) at 0x00008000 in 0.0 seconds (effective 627.7 kbit/s)...
Hash of data verified.
Compressed 8192 bytes to 47...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.1 seconds (effective 1087.9 kbit/s)...
Hash of data verified.
Compressed 750976 bytes to 477779...
Writing at 0x00010000... (3 %)
Writing at 0x000bb633... (93 %)
Writing at 0x000c0acd... (96 %)
Writing at 0x000c6649... (100 %)
Wrote 750976 bytes (477779 compressed) at 0x00010000 in 6.3 seconds (effective 947.4 kbit/s)...
Hash of data verified.

Hard resetting via RTS pin...

Most of the boards you can connect via micro-usb.
Sometimes you need adaptors like:

TIPS ‘n tricks:

Open same file in another editor, so you can compare for example the top (declarations) and futher down the code.
Else you could be ending up scolling up/down all day long. And probably forgetting how a variablename was exacly spelled.

Use serial monitor!
When debugging this is a valuable tool.
Enter statements into you code, which prints debugging info to a serial monitoring window when your device is still hookedup to your PC.

Example printing connected IP and values registered
You even can use serial plotting!!

How to print?

void setup(){
  ... code 
  ... code



Other obvious tips:
Add comment lines (documentation)
Use variable names which make sense!
( Hard to find what aaaa() does, or what tmp-a is, but
LastTempValue says a lot more)

Kicad – Power-on-reset

Last Updated or created 2022-08-02

UPDATE: 20220728 Added POC

The workshop at MCH2022 gave me the idea to make my next PCB not at home, but professionally.

I’m planning to make my 6502 on modular PCB’s when i’ve got the base part working.
( I probably will only make THT (Though Hole Technology) boards instead of smd )
So i’ll probably end up making a few boards, namely:

  • Power on reset
  • Clock module
  • Interconnect with arduino
  • CPU, memory and ROM
  • Display
  • 6522 Via
  • SID chip
  • Hex keyboard

This power-on reset is based on the original C64 part to reset the CPU when you power the machine on. With my 6502 i have to manually push reset to start booting.
(The CPU starts in a unknown state when you power it up, it needs a reset)

PCB design

Working POC

MCH 2022

Last Updated or created 2022-07-27

Back from the hackers event “May Contain Hackers”

MCH2022 is a nonprofit outdoor hacker camp taking place in Zeewolde, the Netherlands, July 22 to 26 2022. The event is organized for and by volunteers from the worldwide hacker community.

Knowledge sharing, technological advancement, experimentation, connecting with your hacker peers and hacking are some of the core values of this event.

MCH2022 is the successor of a string of similar events happening every four years since 1989.

I’ve bin to several of these big events. Besides these big events are many different smaller events (wannull, ne2000 etc).

First one i’ve been was HIP97. I went with Bigred at that time.
I had to get the tickets at that time, he didn’t had a handle at that time. It was Monique who came up with his new nick.

After HIP97 there was HAL2001 WTH2005 and OHM2013 which i was present.
HAL2001 the whole ICEcrew was present, WTH a part of them, OHM a few and i was with a few PRUTS friends.

Now i was with my girlfriend, AND with Bigred again!
Loads of fun and memories. Had not seen Bigred since a inbetween hacker party at my place.
So ’97 and now ’22 .. jeez 25 years!

So MCH, it was great again.
Loads of stuff to do and to see.
Weather was … okay. Two days where really hot, one day some light rain but a load of wind. Our neighbours tent collapsed, beer tents where reenforced.
First campsite with a supermarket!
Music stage was awesome, lasers and fire!

I went to a lot of talks, even my girlfriend found some she was interested in.

This was the last time i’ve brought my “Windows free zone tape”
This big roll of tape was used on many occasions.
I got this roll somewhere < 2000, I did a search but couldn’t find anything mentioning it on the web. Maybe some archive.org entry?

  • Starting a Home Computer Museum (which i almost did in the past)
  • streaming 360 video (going to try this with my Vuze XR Camera)
  • Non-Euclidean Doom: what happens to a game when pi is not 3.14159…
    (Really enjoyed this one)
  • Hacking the genome: how does it work, and should we?
  • And more

Besides the talks i’ve done some workshops:

  • Micropython on the badge (see my other post)
  • Kicad – PCB designing

Meanwhile we where looking at all the villages and hackerspaces. Loads of interesting people to meet. Like our neighbour two tents futher, he was also a home-brewer, and he brought a minifridge with beer taps connected to it.

When back at our tent or Bigreds Campervan, we talked about differences now and then. New technology, what we’ve been upto in the last years and tinkering, loads of tinkering.

I’ve brough a big plastic container with .. ehh “things to do ….”

  • My 6502, bigred helped me debugging the 16*2 display.
    (Luckily his campervan was packed with electronics!)
    We cannibalized one of his projects for a display, and re-flashed his eeprom programming arduino to test my display. ( The arduino i had to reflash later to program a rom he had given me for my 6502. )
    Other toys he gave me: Print for the programmer, and a C64 Cartridge print for Exrom and Game.
  • Mini C64 with a little screen and raspberry zero.
  • 5050 ledstrip (didn’t had time to reprogram this for our mood-light)
  • Handheld gamehat: Bigred found some old games he played when he was young
  • Mikrotik router, because i wanted to make a dmz for my girlfriends laptop. (MS)
  • Playing around with my Vuze XR camera
  • Huskycam, which i’m planning to use on a racetrack
  • DVB-T DAB FM Stick, got some hints and tips from Bigred.
    (Note to myself … fix the antenna!)
  • My Arduino touch bagpipe player with i2c
  • The wifi deauther, which has a display which i wanted to use to make a programmable clock for my 6502. Using a rotary encoder and the display to control the speed in Hz.
  • I spend many hours playing with the Badge and Kicad

Wrote some 6502 assembly, arduino sketches, php, bash and micropython.

While playing around with the badge i got some things working easily.
Spinning logo and blinky leds.
Next goal to achieve was, to get the gyroscope to control the angle of spinning.
Most of the code worked, but the gyro values stayed zero!
(After many hours …. you have to start/enable the chip/measurements on the bno055 first! .. duh! )

I didn’t had my dev directory from my main battlestation synced in my nextcloud, so changing things for the 6502 was a b*tch.
Used vasm and acme to generate a bin file to use to fill the rom.
Didn’t like the eeprom programmer program, because i could not easily check the rom contents.
Have to look into that later on.

While learning to use Kicad, which i only had been using to draw schematics (besides fritzing) , i learned to create a pcb.
Which gave me the idea to make a print for the power-on-reset for the 6502. Which is going to be the first PCB by ordering, instead of the old skool messing around with DIY print making. (see next post)

….. Oh, why my display was not working?
I even connected my 8bit logic analyzer to the pins of the display.

Everything was correct.
But i didn’t use a variable resistor for the contrast. Just a simple resistor i could find. Luckily … bigreds stash.
All those hours debugging, all for one resistor!
(I have to mention, we had a suspicion halfway. But it was too hot and we where too lazy to go to Bigred’s campervan, to get a potentiometer. )

Goodies from Bigred

Movies and more.

Last Updated or created 2022-07-21

We love movies, and watch anything.

I’ve posted about genres:

And we are watching the whole top 250 of imdb.

Now i wanted to have a list of movies by Actor or Director.
So i could see if there are more movies i have to watch
So today i started to figure out how.

So i made a Google Sheet and scraped websites with the needed information.

  • Create a new sheet
  • Make a tab for top-dutch, actor or director
  • Do a search of things you want to display
  • A search of actor and filmography will probably work (imdb of wikipedia)
  • copy the url and make a note of which table it is, first second or more.
  • Paste in the sheet the following at A1

Where the last number (this case 1) is the number of table in the page.

Now you can color code those entries.

DIY 6502 – VIC (Versatile Interface Adapter)

Last Updated or created 2022-07-21

65c22 connected, new data, and address-bus ribboncables!

First led on Register B blinking!

Temporary display wil be 2×16 Chars.
Ram in place, but not connected (is emulated by the Arduino Mega at the moment)
Rom is somewhere halfway the atlantic ocean .. still waiting on that one.
Ben Eatons clock module is disconnected, i’m using the Arduino as programmable clock right now.
(There wil be a little display and a rotary encoder to set clock speed.)

lda #$ff ; all bits
sta $6002 ; set direction (out) for B register
lda #$80 ; set 1 bit
sta $6000 ; set register B
lda #$00 ; reset bit
sta $6000 ; set register B
jmp $8005 ; jmp to bit set part

MCH2022 Badge

Last Updated or created 2022-08-12

Almost … friday will be the day i’ll attend May Contain Hackers.
Besides the awesome villages and talks.

UPDATE: 20220727
UPDATE: 20220812

You get a hackable badge, this one is more amazing as previous versions.

I can’t wait to have a go at this cool gadget. I personally could do without the pcb fancy design.

  • Espressif ESP32 Wrover-E with 16MB of flash storage and paired with 8MB of PSRAM, for front-end badge computing and compatibility with the badge.team ecosystem back to the 2017 SHA badge.
  • Lattice ICE40UP5K FPGA for hardware-accelerated graphics and user FPGA hardware designs.
  • Raspberry Pi RP2040 for advanced USB communication and board management.
  • 2Ah LiPo battery to give you a full day of fun on a charge.
  • 16-bit DAC with stereo output to headphone socket, onboard mono speaker.
  • ILI9341 2.2 inch TFT display with a 240 by 320 pixel resolution.
  • Bosch BNO055 orientation sensor.
  • Bosch BME680 environmental sensor.
  • The usual array of addressable LEDs.
  • SAO and Qwiic expansion connectors, FPGA PMOD expansion, plus onboard prototyping area.

Downloadable apps, micro python, Arduino ide programming.
All kinds of GPIO pins, leds buttons, sound.
Check out https://hatchery.badge.team/

You can play with this virtually here!

So much potential! Great start for a DIY project.

I won’t post about the workings, thats all well documented online.
I shall post about the hacks/findings i personally did.

UPDATE: 20220727
Made a micropython program to keep your NameTag level to the ground (Better version)

UPDATE: 20220812

Someone made a 8bit logic analyser using the pmod connector !

VR 360 180 3D

Last Updated or created 2022-07-19

First tests with a Vuze Xr. (unedited unoptimized)

It can record 360 movies or take 360 degrees pictures.
Besides that it can do stereoscopic recording for using in VR glasses. (2D 180 tested in a oculus vr set)
In the past i made those 360 degrees pictures manually using Hugin for example. Also stereoscopic images, using two pictures.
But it was a lot of work, and most of the times the quality wasn’t worth it.

Another test i did recently was

Soon more

6502 and Arduino (due to missing components)

Last Updated or created 2022-07-20

(Work in process, will certainly change)

Due to eeproms being scarce, i’m going to use a arduino as Rom emulator.
Below is a test setup i’m going to build.

Made the drawing in Kicad.

KiCad is a free software suite for electronic design automation. It facilitates the design and simulation of electronic hardware. It features an integrated environment for schematic capture, PCB layout, manufacturing file viewing, SPICE simulation, and engineering calculation.

Memory assignment:

$8000-FFFF - Rom
$4000-7FFF - Ram ?
$2000-3FFF - Multiple times the 6522 *
$0000-???? - Ram probably

* This is due to the fact i am only using Address lines: 0,1,2,3,13,14,15