Cheap Serial Terminal

How about a cheap serial terminal for less than a fiver all-in?

In a previous blog entry I’ve been working on more developments for the increasingly powerful home control system using an Arduino as a kind of universal I2c peripheral to the ESP8266. The reason for that is just the vast range of driver software our there and the fact that from China you can get an Arduino-Nano-type-board for under £2. There are drivers for just about everything so it seems daft to just ignore that. It ends up cheaper than most actual i2c peripheral boards.

First thing I had to do with the Arduino base code was increase the size of the buffer used for storing I2c and that is covered elsewhere – but finally I got that working. In the process that led me to the idea of a prototyping board with both the ESP8266, running the home control 2016 software AND a 328 to power some peripheral devices and give extra IO pins.

In the process of THAT I got the QDTECH boards running (128*160 LCD – cheap) – and that also is covered in a previous blog entry. These are great – and cheap (though not as cheap since Banggood jacked the price up but thankfully there is still AliExpress – thanks to Squonk for that particular link) but they are a little limited in terms of resolution as any kind of terminal. I even found a little bit of code to do vertical scrolling. Fast enough but then it is a low resolution display.

In the meantime however I pulled out another favourite display of mine, the ILI9340-driven displays at 320*240 – at £3.47 – mind you if you go to the Italian version of Aliexpress they seem to go down to just over £3. The increased resolution of these means you really COULD make a nice monitoring terminal but for one thing – speed.  I checked out several implementations including the Adafruit ones and the drawing speed is atrocious – attempts to scroll the display are generally abysmal unless you use a fast processor.

Terminal[1]And so it was that I stumbled on THIS article.  The funny thing is that this is on an Arduino site – but points to an article that is anything but Arduino –the fellow has written some FAST code to chuck out small text in the form of a (subset of a) VT-100-compatible terminal. But the code needed you to use the C++ compiler on the command line, NOT in the Arduino environment – and that was no good for me as I have to add other stuff. But if you take a look, you’ll see my late hours have been FAR from wasted.

In the picture on the right (depending on your screen) you see this terminal running – it has  2 fixed areas and a scrolling area and it is fast.

The first problem was that this needed to be compiled outside of any environment and it simply would not work for me – the linker had issues and so on. I realised if this was to be useful – it needed to be inside the Arduino IDE where I could shove in all sorts of other code including my I2c connection.

I opened up a NEW Arduino project, copied all the files in there and renamed the primary file to be the same as the project. I then put the contents of his MAIN() code into “LOOP” – pulling out initialisation and putting that into “SETUP()”.  Stunningly, it all SEEMED to work – I just don’t have that much luck normally. However any attempts to use the serial port failed miserably. So I threw away his serial code and put in the normal Arduino serial – that worked just fine – but when I actually tried to do anything with it other than “hello world” – I got garbage characters.

I was reminded of the work I’d done to expand the I2c buffer on the Arduino and that reminded my that the normal Arduino serial buffer is a staggeringly useless 64 bytes.  I’m including hopefully helpful links here as you can fix this stuff. Despite the limits of the Arduino default software settings, I need way more than that so I increased the buffer to 1K, using up a significant amount of Arduino RAM. Voila – perfect.

Debug infoAs it happens I’ve been experimenting on a 1284 chip which while being Arduino-compatible kind of, it does have another serial port, so without disconnecting my FTDI – I hooked up the second serial port to the home control serial and fired the DEBUG command at the latter.

As you can see on the left, a perfectly usable terminal and now with programmable on-screen LEDS and baud rate control stored in EEPROM. At this point despite YEARS of VT-100 wilderness I’d mastered the colours and scrolling area controls – thanks to this handy VT-100-related link

I’d even noticed that in the code, there was a fast horizontal line command. Putting the driver code side by side with the Adafruit code for the same chipset, there were similarities. I should be able to drop in a PIXEL command to get a dot up. YES, with slight mods it worked. For my next trick I would add in a fast VERTICAL line routine from Adafruit – and then – the general LINE drawing routine and the world would be my oyster.

Erm, not quite – the Adafruit SWAP routine caused me endless issues – but I replaced that and all is now well.  What’s important here is that this is FAST.  I’ve put a little character count on the bottom status line so we know that something is actually happening in the case of repeating commands… and this could form a great plug-in for our prototyping board – or indeed any kind of experimental setup where having a dedicated little serial monitor costing next to nothing would be handy.

The code is currently sitting on BitBucket. Oh – and if you use these displays, don’t make the mistake of thinking, as they run on 5v that the LED power should be 5v. It works for a while but I just burned a LED out on the larger display – and yes I’d noted that it was running a tad warm and didn’t twig.  Now the LED supply is connected to 3v3 and it is just fine (apart from the one bust LED). I could probably do PWM brilliance control but that’s something for later. Right now I’m running the entire display on 3v3 and it is just fine. My tiny 3v3 regulator on my boards isn’t even breaking a sweat.

https://bitbucket.org/scargill/experimental-terminal

Block LEDs

In the VT-100 command-set, they refer to a command to turn LEDs on and off, 4 of them in fact and I thought that might be fun to implement – now bearing in mind I’ve no prior experience of the switch statements used in the VT-100 code I managed to get this lot running this morning.

On the top right of the image here, you’ll see 4 simple rectangles in red – filled or not. The state of those LEDs can be controlled as follows…

ESC [ parm q

Where parm is one of 5 values 0=all off, 1=one on, 2=2 on, 3=3 on, 4=4 on.

That apparently is the standard though WHY it won’t let you turn an individual LED off I don’t understand so I’ve extended this so that 5 turns off  LED1, 6 turns off LED2 etc.

That’s how I’m interpreting that particular VT-100 command.

I’ve added a non-standard command to set baud rate as I could not find a standard command to do it. This is stored in EEPROM.

ESC [ parm X

Where parm= 1,2,3,4,5 or 6 for 300,2400,9600,57500, 76800 or 115200 baud. Why that 76K? Because on power up that’s the speed the ESP8266 chucks out debug info. 

Developments

I now have code running native on the ESP8266 to handle this display and the terminal – so as not to detract from this article I’ve split this into another article – but you can see the first attempts running here… https://www.youtube.com/watch?v=qBxXZcleKq0

45 thoughts on “Cheap Serial Terminal

  1. Hello Peter,

    I am a bit late to the party here. But could you give me some quick details on the wiring. Are the MOSI, MISO etc lines 5V tolerant on these displays, or do I need to use level shifters? Do you have to supply 3V3 to the LED pin and 5V to the Vcc pin? And can I just use a standard UNO say for this project?
    Many Thanks,
    David

  2. I did a port of your VT100 program to an ADAFruit M0 processor with their 2.2in ILI9341 touch screen display…

    I had to add one routine to their library, but its included in the package

    if your interested, would be happy to send it your way to add to your website…

    I may add touch screen support someday…

    1. Well.. I guess 76800 must be just working as it is “near enough”…. I’m not even sure if the likes of Arduino Serial will do just any old speed… as against multiples of the standards..

    1. There are a couple of explanations… 76800 sounds right because it is exactly twice 38400…. which is a standard rate…. and I have to say 76800 works….

      Might want to check on that.

  3. Peter, i think in the article editing an image went lost… when you say:
    “I hooked up the second serial port to the home control serial and fired the DEBUG command at the latter.

    As you can see above, a perfectly usable terminal and now with programmable on-screen LEDS and baud rate control stored in EEPROM.”
    that image is missing… i think to remember it in previous version, with all the debug info on screen…

    1. Hi there – I ran out of steam last night – see updated article complete with updated pic (the only one was visually out of date).

      I may yet put this on an ESP – just to see how blisteringly fast it is compared to the Arduino – but for now, it is very fast and makes a great monitor.

        1. I have to be careful what I add as I don’t have an infinite amount of RAM left 🙂 Also I’ve not a lot of experience of using HSPI on the ESP though I do have working SPI routines in there. I have another display on the way and I may hook that up – however for now this remains more useful as a separate project – you could stick a NANO on the back of the display and you have a nice mini-terminal for next to nothing.

        2. I did try…. not having it – all I get is a white screen when I take the code over to the ESP – even with the clock slowed down. And here’s me thinking I’d have a quick conversion.

        3. After 2 days of struggle and head-scratching – the ESP8266 now says “Hello” – in other words I’ve ported the ILI9340 code across successfully. That took some doing – wrong ports, too fast SPI, absolutely everything got in the way. Now I have “Hello” up I’m going to go for the scrolling region- if I can get that working…. well, you never know.

  4. Note to self – when pulling in code from generic to Arduino – don’t use .c – it won’t find the likes of Serial – use .CPP – that wasted an hour – files updated.

  5. Hello, I am from Almeria. Here there are a lot of plastic, but also there are a lot of beautiful beachs and good people. I hope you enjoyded Almeria. Best regards.

  6. Hi Pete,

    If it’s still not working, why not try a bit of old school debugging.

    Dump the plot pixel coordinates out of the serial port for a line that doesn’t display?

    If you only try and plot the lines you highlighted that don’t work, do they then work?

    1. Thanks Glen – see revised comment above yours. Fixed thanks. I’m off to find an elipse routine- probably the Adafruit one – then I’m just about done and can start adding some useful little bits to this. Have to say I like it – I’m also going to send off for another one of the displays as this could have all sorts of uses. Right now the code is stand-alone but I’ll soon bring with my other code so it will take in I2c commands.

  7. I reckon the 1st one one you’ve highlighted in blue is being drawn.

    Try checking your screen width and height (maybe a rotation thing), as only the coords that are greater than 240 are not being drawn.

    1. Turns out it was nothing more than a duff Adafruit SWAP function. I replaced that and all is well. Will update code. NOW I can get on and do something useful with this.

  8. Amazing, I found an Arduino-supported, larger 2.4″ LCD with microSD card & touch screen featuring an spfd5408 controller 20 pence cheaper ($3.67):
    http://www.aliexpress.com/item/sku/32254339975.html

    It’s even fully Arduino R3 pinout-compatible.

    For support libraries based on Adafruit ones, just search SPFD5408 in Google, yo uwill find some code on Github. I don’t want to put a second link in this comment to avoid automatic the dreaded censorship approval delay 😉

    How low will they go?

    1. That’s a good price MrShark and amazingly if I go to the international site (English speaking) – that price is not available – however – it seems I CAN log in – so I can see another couple of boards coming my way…. Well done.

      Still not cracked the line drawing but I’m hoping to get that sorted by end of play today.

      1. Its a kind of random, there may be some cookies involved, as sometimes I land onto the IT website, sometimes on the global one. I can kinda force things by clicking on the “global site” at the bottom right and click on the above URL.

    1. As with all things – the panel is not the relevant bit – it’s the software – the software I’ve found here – and which I’m busy working on (and still having line drawing issues with) is by FAR the fastest text handling I’ve even seen on an Arduino – and that is for me the important issue and why I’ve written this blog… it is coming on very nicely – but if anyone wants to help me figure out what the HELL I’m doing wrong with the line drawing (taken from Adafruit) I’m all ears. Blog update coming in a minute.

      1. Why not use an STM32 board? They are also dirt cheap, have lots of I/O, are much faster than Arduinos, and can be programmed by the sam IDE.
        BTW, as an old DEC employee, I like that the VT 100 survived 😉

        1. See comment – got ESP8266 running – even cheaper and with WIFI etc… currently using it to monitor MQTT traffic in full technicolour. HOWEVER I do have an STM32 board coming…. what#s a SAM IDE. For ease I’m hoping to program it in the Arduino IDE rather than re-invent the wheel? I want to use that board as an I2c general purpose slave.

            1. See the manual – the page entitled EXPERIMENT – just updated it – basically string output is one of the home control commands now (experimental at this point) – and so MQTT is sending all traffic to this unit – in technocolour – lots of improvements possible but speed wise the ESP version now managing 200us per character. Not bad.

        2. Yes, I thought the same thing!

          Why no then use an $1.50 STM32 board with a $3.67 2.4″ LCD with touch panel to replace a $17.90 2.4″ Nextion display for $5.17?

          For this unbeatable price, you get tons of UARTs, I2C, SPI and GPIOs as a bonus.

Comments are closed.