VT100 Terminal for HC2016

rear view ESP8266 VT100Well, I had to give it a go, didn’t I – porting the code for the cheap VT100-type serial terminal into the main ESP8266 home control software.

BOY was that difficult but… after 2 days of head-scratching – check out the home control manual in the source code repository for Home Control 2016 – this  uses up four precious port bits (GPIO 13,14,15,16).

I have the terminal code up and running (minus baud rate controls… and the bottom line is now a general status line) and I have to say, fast doesn’t start to explain it.

As you can see in the image above, all we have here is the display with a slim ESP8266 board behind it – a WEMO D1 does the job superbly and you can use double sided tape to fasten the ESP8266 to the flat part of the board.  I just used a board I had handy The FTDI you see attached to the back is merely there to provide 5v power and, erm, stand the unit up!!!

At this point I’ll add what I seemed to have missed out of the original article – the pins!

Connections:  Connect VCC to 5v, ground to ground, light to 3v3.   GPIO16 to D/C, GPIO15 to CS, GPIO14 to SCK and GPIO13 to SDI (MOSI).  Connect RESET to RESET.  Leave the SDO (MISO) on the display unconnected.  The whole thing should light up.. and when you give the {ili_set:1} command and reboot the ESP, the display should clear and put up the header. That’s it.

ESP8266 VT100 front viewI did some tests to see if how fast I could make it -  I’ve already optimised the SPI and character routines – the board will not operate at all under ESP8266 at the fastest SPI speed so that is probably a dead-end, I tried caching the ROM reads (which are 8 bits – meaning you have to read 32 bits at a time and select the right 8 bits.

Caching that info actually very marginally slowed things down – I tried all sorts, writing 16 bits at a time to SPI – and finally after being able to obtain no more speed improvements, I stopped – not sure why I needed any of this as it was already blazingly fast.  Now, writing an X to every location on the screen (that’s 1600 character writes) takes 330ms so that is 200us per character (5*7). I think that is fast enough for now. Clear screen is near enough instant and scrolling is instant.

See this demo video of the ESP8266 version – the 328 version isn’t  quite THIS fast but it is still fast.

https://www.youtube.com/watch?v=YXqLVmoyKPE

So I’ve added some commands in the HC2016 project code

{ili_set:1}
The above will setup the display and make it available to accept data – once set the display will set itself up on power up of the unit.  Setting that command to 0 stops any data and from there on the display will NOT initialise on powerup.
{ili_text:"\e[35;40mHello there \e[32;40mmate\r\n"}
{ili_status:"All working exceedingly well"}
{ili_title:"\e[37;40mESP8266 Status Monitor"}

In addition to the above, {ili_rssi} puts the time and date down in the status area AND puts a nice phone-like RSSI indicator on the bottom right, showing the current WIFI signal strength of the ESP board. {ili_reset} resets the display after clearing it – to show the header and the LED rectangles on the top.

If you want to experiment with lines – and remember this is going via MQTT so don’t plan on making complex objects…  {ili_line:x1,y1,x2,x2,colour} but YOU WILL need to clear the screen first -  you can do that with  {ili_text:"\e[2J"} and when you’re done you can return the display to normal with {ili_reset}

{ili_pixel:x,y,colour} will draw a dot. {ili_rect:x1,y1,x2,y2,colour,background_colour} will draw a filled rectangle.
{ili_string:x1,y1,string} will position a string at an arbitrary location
{ili_fore:colour} will set the foreground colour for future strings
{ili_back:colour} will set the background colour for future strings

All of the above require that you clear the screen – you cannot do the scrolling terminal – and arbitrary text and lines at the same time but this does add a lot of flexibility (which I thought of much later than when I wrote this article originally).

The manual that comes with the bitbucket download is updated with new commands.

Hence by firing serial or MQTT commands at the board, I can get stuff onto the display.  To monitor all MQTT traffic was easy – over to the Pi and MQTT..

In Node-Red – a simple MQTT node picks up all traffic, passes it to a function – which then passes the result to the board which in this case is called “thisone”.

tmpPayload=”  “ + msg.payload;
tmpTopic="
\\e[36;40m"+msg.topic+"\\e[32;40m\r\n";
if (msg.topic!="thisone/toesp")
{
msg.topic="thisone/toesp";
msg.payload="{ili_text:\"" + tmpTopic + tmpPayload + "\r\n\"}";
return msg;
}

DisplayHence the board gets all traffic except for traffic destined for the board (which could end up in an infinite loop).

And now thanks to a conversation with reader Bob Green –  a WIFI signal strength (RSSI) indicator for the board and the time in the bottom left. I deliberately left the seconds out as this would typically not be refreshed that often – maybe every couple of seconds...

Bob suggested that by plugging the board into a battery pack you have a simple range tester and he’s absolutely right of course. Now, how to teach it to make coffee…

On the subject of terminals

No need to talk about VT100-type terminals for PCs – they’re coming out of our ears – but…

Android

I’d put this all together and I thought…an 80 line or 132 line version of this would be nice – I’ll put one on my Android phone. Well, you may well write in and tell me I’m wrong but I cannot find a VT-100 compatible serial modem for Android anywhere (I did find one but it was not clear if scrolling regions worked and it had a limited range of serial settings). Surprising considering that it can be done on a  relatively simple unit like the ESP8266

Linux

And that led me to Linux - or rather - I was thinking about the various single board computers I have lying around - a Pi would do but I have a rather nice FriendlyArm NanoPC T2 which was not quite fast enough for Android but runs a nice Debian.  I started looking for fancy graphical terminals - not a lot - nothing to anywhere near TOUCH some of the stuff on Windows - however I had this T3 with a little 7" LCD touch screen lying around and was determined it would not go to waste.

It turns out that the humble LX terminal does at least some VT 100 - but that pulls up a command line and lets you interact with it  -was there any way to get it to talk to serial instead - preferably one of it's own rather than a USB serial as it has FOUR serial ports on it.

Well, yes. I discovered this..

cu -l /dev/device -s baud-rate-speed

It looked as if this would let me use the terminal with serial instead of a keyboard- but of course when I tried it using:

cu -l /dev/ttyAMAT3-s 115200

I got zilch. The system didn't have a clue what CU is (neither did I for that matter).

Anyway, just for a laugh I tried SUDO APT-GET CU

And it worked. I tried again. THIS time all was well - but it could not contact the serial port - as it was "busy" - yeah right.

I added user FA (the user in control of that terminal session) to the relevant group - no difference - so as is often the case I just gave 777 permissions to the serial port and VOILA.

Terminal on Debian running serial

I tested some colour escape sequences from my PC Serial Terminal I wrote some time ago (and just recently updated to let me put ESC in there) and all worked well but for some visible representation of the ESCAPE sequences (which still worked). I continued experimenting and the UX terminal that comes with Debian LDXE does not suffer that particular issue – so it has the job!!!

Facebooktwittergoogle_pluspinterestlinkedin

32 thoughts on “VT100 Terminal for HC2016

  1. Nice Job Peter. I have an ESP12 linked to a similar display with SPI using Arduino / ESP and standard libraries. It's brilliant for testing MQTT and for range testing. Powered by the Ravpower I can move it around and check that I can receive the MQTT messages. I have been using it for months and it works flawlessly.

    1. Done - bottom right of status line - -xxdb
      I need to make one of those little indicators they have on Android phones to show the signal strength - that would be better. Looking at it, white rectangles and grey - but what signal strength to attach to each bar... hmmmm.

        1. Right chaps - refresh browsers and take a look at the end of the blog entry.... I'm quite chuffed with this.. thanks Bob. Oh, -55db to -95db works REALLY well as an indicator - so at -95 there is only one bar left on - shortly after that I lose signal... and bearing in mind my software has dual SSID capability - I may well put some kind of indication to say which one is in use...

    2. Right- went off range testing and -45 seems to be a very GOOD signal and much after -95db the board loses the plot (I took your lead and plugged it into the RavPower - what a good idea). So I reckon 10px high, 8px, 6px,4px and 2px - all by 2px wide with 2px in-between - at maybe <-50, <-61, <-72 <-83 <94 should make for a pretty good phone-like signal strength indicator...

  2. Why not use the standard Wi-Fi RSSI symbol of a dot with concentric arcs of circle figuring RF waves above it?

    The "staircase" style RSSI is more dedicated to the cellular network, is it?

    Just to avoid confusion.

  3. Peter, actually I like the staircase version as it is easy to see at a glance. Probably takes less coding / code space than concentric circles as well. I originally made my unit so I could leave it running and see MQTT traffic without having to leave the PC running with MQTT-Spy.

    1. Yup, I'm leaving it in - and that is just what I'm using it for - next challenge - a bezel or neat non-amateur looking case... I put the time on and there's room for more. and no I don't have a 3d printer 🙂

      Interestingly I've just spent HOURS tackling putting a new font in and had issues - turns out they were because I don't (didn't) disable interrupts around the code to grab fonts from FLASH - I'm guessing an issue with the internal SPI - anyway - resolved - will update code tomorrow as soon as I figure out why my 16 bit retrieval doesn't work (8-bit does)... so I can add an option for 16*16 chars for static displays... whole host of fonts using the same format is the reward for getting it working. Most likely in the morning.

      1. Peter, just ordered from the link in the other blog post, the italian link i gave you a few days ago... now let's wait for shipment, as soon as it arrive i'll make a box and publish on thingiverse... can you publish a little schematic of how you attached the esp8266 on the back? A better back photo maybe could help, too... maybe even without the lcd itself i can make a 3d model, if you send me the measurements... let me look online if i found something, keep in contact this evening... i imagine you'd like to leave a little space on the back for better air flow, and for ftdi connection... in the end it should have only a battery to power it, or a side power socket, maybe... mmm... many ideas... publish other if you'd like... maybe a small lipo with microusb charger, so to have it independent and not carry around a powerbank? mmm... mumble mumble 😀

  4. I like this a lot. Especially the RSSI.

    Your comment about the bezel / non-amateur case is a subject that a lot of my projects fall foul of with 'she who must be obeyed'.

    I think that manufactures of iOT boards could make a killing if they made cases for their stuff as well. I'd certainly buy a case with a board. Even a case for something simple like an ftdi board would be useful.

  5. Great Work !
    Do you think there is a chance to get an ESP8266 to serve this VT100 screen on a webpage ?

    I would love a universal frontend to bring serial port data to a webpage with at least some basic VT100 functions

    This should enable almost any client with a web browser to view the formatted serial data

    1. Hi there

      Getting this working on a web page would be a completely separate project. The code is designed to fire off to a video controller. The idea is that you would buy one of these very cheap displays and use that for debugging instead of a PC. If you want a VT100 display on a bigger screen why not just use the VT100-kind-of-compatible serial terminal on any old Linux computer - like the VERY cheap FriendlyArm NanoPi NEO - or a Raspberry Pi. The CU program lets that take it's input from serial.

      1. Peter,
        you are right - for just a bigger screen this suggestion is perfectly ok

        However, I would like to "decouple" the screen from the serial port
        and have a cheap standard frontend to different embedded systems

        A VT100 as a webpage would allow to use almost any client from any location, without any special client SW Terminal app
        All the available terminal apps have various dialects and glitches

        Locally it could be i.e. a cheapo Android tablet acting as screen
        Remotely any smartphone or tablet

        I looked for possible solutions and found some Javacode to emulate a VT100,
        but my programming skills are rather oldfashioned (VAX & PDP11 Machinecode...)
        - so I have no real clue how to put this on a ESP8266

        I just hoped that you eventually have some idea, how to achieve this

        cheers
        Guenter

        1. See elsewhere on the blog. Any old or PC using Linux. The standard terminal is partly VT100 compatible... and a program called CU can be run to redirect keyboard to serial and serial to the screen hence making a handy serial monitor.

            1. Well, I have to say I did get VERY excited about this - I rushed to get the ROMS, flashed them onto a standard ESP12 module and turned on - sure enough the screen came up in a browser - I sent a few characters... lovely....

              But then . I went to WIFI settings and told it to scan. It could not find ANY of my bog-standard WIFI access points! Nothing wrong with the WIFI on the board or my phone would not be talking to it via the internal access point - but it could not find my nearby access points.

              1. For me it worked fine with a bunch of Fritzbox 7490 and Ubiquity Pro Access points with the 6.8 Version of ESPterm

                Since that I only reflashed the new versions and it kept the old settings.
                I just tried a Wifi scan with 1.01 - does not work, you are right

                I drop Ondrej a note, he is a very nice and responsive guy
                You find his email in the "about" page

              2. One temporary workaround could be:
                Flash the 7.1 Version (I just tested the scan) do all config settings and then flash the 1.01 over - it keeps the settings

                Full Screen ?
                There is always the "Frame" around
                You can hide most of the buttons in setup or with OSC sequences

                1. I've written to the author - I'd rather not investigate further until basic things like WIFI access are reliable.....

                  Full screen? Well, once the novelty wears off and assuming you're at a PC with a keyboard - surely what you want is to be able to put the browser on full screen - and see nothing but the contents of the terminal... with maybe a special key to pop up any controls....

  6. To me on thinking about it - the use for this would be to access a system remotely via a terminal where that system only has serial in and out...

    Another way to do this of course is to use any old serial VT100 terminal on a PC or Phone or tablet (such things DO exist) - and instead of having the terminal software on an ESP8266 - have a serial to Ethernet ESP8266 - ie transparent bridge.... but the ones I tried don't work...

Leave a Reply

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