[{"element_type":"text","content":"\n  \n        \u003cp\u003eThose nice magnetic connectors (four pins) were waiting to be used in some small project of mine, until now.\u003c/p\u003e\n\u003cp\u003eI needed a way to peek in on a UART serial stream, but did not want to add a UI to the project or always have a laptop along for the ride. So I made what is not all that different from those old DEC VT-200 terminal consoles of old (nevermind if you are not nostalgic for those beasts).\u003c/p\u003e\n\u003cp\u003eWith an RP-2040 to listen to the UART and send the text to one of those nice little Monochrome 0.96\" 128x64 OLED Graphic Display.\u003cbr\u003e\u003cbr\u003eI first used this snap on terminal concept as part of a project that was logging data to an SD card, but really any project that might need to log serial data can also have a snap on terminal added. Wire the UART to a mag connector, in my case I put 5v Power and Ground on either side while the TX and RX pins are in the middle, but there's not really a standard (until now ;) and the RX is optional as it is not used (yet). [Gnd, TX, RX, 5v]\u0026nbsp;\u003c/p\u003e\n\u003cp\u003eThe code for any project just needs to send serial data out via UART serial.\u003c/p\u003e\n\u003cp\u003e\u003ccode\u003eimport busio\u003cbr\u003e\u003c/code\u003e\u003ccode\u003e\u003cspan\u003euart1\u003c/span\u003e\u003cspan\u003e \u003c/span\u003e\u003cspan\u003e=\u003c/span\u003e\u003cspan\u003e \u003c/span\u003e\u003cspan\u003ebusio\u003c/span\u003e\u003cspan\u003e.UART(\u003c/span\u003e\u003cspan\u003eboard\u003c/span\u003e\u003cspan\u003e.GP8, \u003c/span\u003e\u003cspan\u003eboard\u003c/span\u003e\u003cspan\u003e.GP9, \u003c/span\u003e\u003cspan\u003ebaudrate\u003c/span\u003e\u003cspan\u003e=\u003c/span\u003e\u003cspan\u003e115200\u003c/span\u003e\u003cspan\u003e)\u003cbr\u003e# then Write out your messages ...\u003cbr\u003euart1.write(bytes(\"Hello Terminal\\n\", \"ascii\"))\u003c/span\u003e\u003c/code\u003e\u003c/p\u003e\n\u003cp\u003eThe code for the terminal console monitor gadget (to listen and display) is Circuitpython. Easy with a just a bit work to get the all the previous lines of text to \u003cspan\u003elinefeed-up\u003c/span\u003e like terminals do (at least it DOES NOT using up endless green-\u0026amp;-white stripe fan-fold paper).\u003c/p\u003e\n      \n","metadata":{}},{"element_type":"code","content":"# A VT-200 like serial terminal display for RP-2040 and tiny .96\" OLED Display\nimport board\nimport busio\nimport displayio\nimport time\n\ntry:\n    from i2cdisplaybus import I2CDisplayBus\nexcept ImportError:\n    from displayio import I2CDisplay as I2CDisplayBus\n\n\nimport terminalio\nfrom adafruit_display_text import label\nimport adafruit_displayio_ssd1306\n\nuart0 = busio.UART(board.GP0, board.GP1, baudrate=115200)\n\ndisplayio.release_displays()\n\noled_reset = board.GP21\n\n# Initialize I2C on GP26 (SDA) and GP27 (SCL)\ni2c = busio.I2C(scl=board.GP27, sda=board.GP26)\n# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller\ndisplay_bus = I2CDisplayBus(i2c, device_address=0x3D, reset=oled_reset)\n\nWIDTH = 128\nHEIGHT = 64  # Change to 64 if needed\nBORDER = 5\nLINE_HEIGHT = HEIGHT // 6\n\ndisplay = adafruit_displayio_ssd1306.SSD1306(display_bus, width=WIDTH, height=HEIGHT)\n\n# Make the display context\nsplash = displayio.Group()\ndisplay.root_group = splash\n\ncolor_bitmap = displayio.Bitmap(WIDTH, HEIGHT, 1)\ncolor_palette = displayio.Palette(1)\ncolor_palette[0] = 0xFFFFFF  # White\n\nline = 0\ntext = [\"\", \"\", \"\", \"\", \"\", \"\", \"\"]\nLINES = 7\ntext_line = [None, None, None, None, None, None, None]\nfor i in range(LINES):\n    text_line[i] = label.Label(terminalio.FONT, text=text[i], color=0xFFFFFF, x=2, y=LINE_HEIGHT * i - 1)\n    splash.append(text_line[i])\n\nmode = \"linefeed-up\" # \"linefeed-up\" (fancy) OR \"scan-down\"\nwhile True:\n    dataIn = uart0.readline()\n    if dataIn is not None:\n        line = (line + 1) % LINES    \n        # convert bytearray to string\n        text[line] = ''.join([chr(b) for b in dataIn])\n        print(text[line], end=\"\")\n                \n        if mode == \"scan-down\" :\n            text_line[line].text = text[line]\n        elif mode == \"linefeed-up\" :\n            l = line\n            text_line[l].y = LINE_HEIGHT * -1 - 1\n            text_line[l].text = text[l]\n            text_line[l].y = LINE_HEIGHT * 6 - 1\n            l = (l + 1) % LINES\n            text_line[l].y = LINE_HEIGHT * 0 - 1\n            l = (l + 1) % LINES\n            text_line[l].y = LINE_HEIGHT * 1 - 1\n            l = (l + 1) % LINES\n            text_line[l].y = LINE_HEIGHT * 2 - 1\n            l = (l + 1) % LINES\n            text_line[l].y = LINE_HEIGHT * 3 - 1\n            l = (l + 1) % LINES\n            text_line[l].y = LINE_HEIGHT * 4 - 1\n            l = (l + 1) % LINES\n            text_line[l].y = LINE_HEIGHT * 5 - 1","metadata":{"language":"python","linenums":false,"filename":""}},{"element_type":"text","content":"\n        \u003cp\u003eOther than the wiring for the display, all you need to do is get your power and serial from the mag-connector and remember to connect the TX coming from your serial sending project to the RX on the tiny terminal.\u0026nbsp;\u0026nbsp;\u003cbr\u003e\u003cbr\u003eOnce you have this tiny terminal working on a project, adding a little code and mag connector to any new project is easy.\u0026nbsp; Sending Serial Data out on a UART TX pin and providing a little power and ground is all that is needed to light up a very useful, retro and tiny terminal.\u003cbr\u003e\u003cbr\u003e\u003c/p\u003e\n      ","metadata":{}}]