LocoMotion – The build : technical chit-chat

*Caution: this posting contains a bit of technical inside of the LocoMotion project*
Previous weekend, I did not post anything !
Some of you became worried that this project was not getting the attention it deserved. Nothing like that, I have been very busy !
(and not only with the LocoMotion project unfortunate)

First of all, I wanted to take decent screenshots. Not the ones taken with a DSLR, iPad Pro or iPhone X. Believe me, I tried almost anything, nothing gave me the result I wanted 🙁 I even did try to put the TFT screen on my Canon i-Sensys MF645Cx
(a multifunctional printer, with scanning possbilities) The images on the scanner where “crisp”, but in black and white only !
(due to the TFT technology and the scanning technology combined) …
Then it hit me, sending data to those TFT screens is not the only possibility. You can also read data from them !
With the help of Bodmer (the guy who wrote the TFT_ESPI library I’m using), we managed to get data back from the display,
by turning the MOSI pin into a bi-directional pin … A simple function included in my LocoMotion firmware, making it possible
to send screenshots to a PC-software, solved this whole “bad-quality” screenshots.
The function simply reads every pixel of the screen, and sends it value to the PC-software,
that combines this data into a nice JPG file 🙂 Eeh voila, one problem down 🙂

Furthermore, I have been busy with implementing firmware update functionality. You can manually download a new firmware
from my website, and upload it to the LocoMotion. I even included some code, to automatically check for updates,
every time the device is turned on, and automatically installing them. (If you want this, of course)

By using this “OTA” (Over-The-Air) technology, I condemned myself to “half the program memory size”.
Let me explain:
These ESP32 modules do have 4 MB of Flash on board. My code used about 30% of this flash memory,
because I did have a partion scheme of about 3.7 MB program memory, and 3KB Spiffs memory (Spiffs is a file-system)
When you want to use OTA, you need to have twice the amount of program memory. One part for running the current program
(and update procedure), and one part to download the new firmware and check it. So, initially, my firmware is about 1.1 MB
(30% of 3.7MB) When using OTA, I need 1.1MB for my current application to run, and another 1.1MB to store the download.
So I need 2 partitions of each 1.85MB, and so I can only use 1.85MB to run my program in. My program stays the same in size,
but it’s using 60% of the available memory. I don’t know if I’m going to make it with only 40% left of program memory …
So I did look at another “solution” …
I found the Lolin D32 Pro module, “almost” the same as the my current LilyGo TTGO T8, but it does have 16 MB Flash instead of 4 MB.
PostNL delivered my new modules, about half an hour ago. (order them on Thursday before lunch from www.tinytronics.nl)
Flashing my code to memory goes a bit slower (460800 baud instead of 921600), and I also need to take pin D0 down to GND
before flashing, but they do return back as 16 MB Flash, and that is the most important part 🙂
I need to make changes in the boards.txt file, and create a custom CSV file for partitioning, but I think I will manage 🙂
Because I really don’t need 16 MB program memory, I’m thinking of creating a Flash size of about 5 MB for file-storage.
The whole graphic library and config-files and dictionary, take up about a total of 3.5 MB
It’s a pitty to use an SD-card for such a small amount of data, and internal flash storage will be much faster !

Furthermore, my locomotive list can contain 16384 locomotives. I use PSram to store all this information.
I need about 100 bytes for every locomotive, so I will have 1.6MB of PSram occupied with the maximum amount of locomotives.
(the EcoS itself can also hold a maximum a 16384 locomotives, and I want to keep this data “available at hand”, for performance. (instead of querying each loco again and again …)

For the firmware update, I did learn a few new “tricks” …
My webspace-provider uses HTTPS (who not in these days), and I had very limited experience with secure data communication.
Well, I mean, I use it every day (VPN, HTTP, SFTP …), but on a “regular” PC, you don’t have to worry about it, it’s all done for you.
On a microprocessor it’s different !
First of all, I needed the root certifcate to communicate with *.digitalplayground.be, second of all, I needed the digital fingerprint,
to get the version-file of my website. (to check the installed version versus the available version)

Luckely the internet is full of interesting things, if you know where to look for 🙂

1. There is a website called grc, where you can find the “fingerprints”.
Take a look at https://www.grc.com/fingerprints.htm
2. I’m using MacOS and Linux for a reason 🙂
Try this command: openssl s_client -showcerts -verify 5 -connect digitalplayground.be:443 < /dev/null

TO BE CONTINUED …

This entry was posted in Blog, LocoMotion, Railroading. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *