Ad Widget



No announcement yet.

Sending Commands from Terminal and Python

  • Filter
  • Time
  • Show
Clear All
new posts

  • Sending Commands from Terminal and Python

    Hi Folks,

    I'm going to post this here in case others come looking for the same info about communicating to the TIMI or TED devices from a Terminal program or their chosen host microcontrollers. The info regarding the direct comms to and from the TIMI or TED devices was courtesy of Juniel Cruz in an email exchange. The addition of CircuitPython code examples was from my own research - primarily through postings on the Adafruit forum and various web searches.

    I hope this will be helpful to folks looking to use this display in their projects and in commercial applications.

    Regarding the format of communications between the TIMI/TED products and the host microcontrollers, reference the Mates Serial Command Protocol document

    Next, note that the strings given, while shown, for example, as 42 00 01, need to be sent that way as raw hex (0x240001). No spaces, and if you're running from a serial terminal on windows/mac/linux, be sure it can send AS HEX, not just receive in hex, otherwise you'll get no response or behavior from the display.

    Sending actual hex when you already have the hex values to send can be tricky (or maybe it just was for me...) because most serial send commands (uart.write, usart.write, etc) will assume the string you have is in ascii.

    Here are some examples of ways to send the hex strings you see in the command manual AS HEX, in CircuitPython. Most of these will apply to regular old Python as well (assuming 3.7 and above).

    In regular Python, you can use:

    message_bytes = bytes.fromhex("240001")
    But CircuitPython does not currently support that method.

    Since you will likely be building your commands in your code each time, probably the easiest way to develop and send your string is to escape each byte as follows:

    message = b"\x24\x00\\x01"

    message = bytes([0x24, 0x00, 0x01])
    If you are running a controller running a version of CircuitPython that supports it (not M0 apparently, but M4 should), you have binascii available to you:

    import binascii
    message = binascii.unhexlify("240000000001")​
    Lastly, this cool bit, again, courtesy of Adafruit's forum folks:

    s = "240000000001"
    message = bytes([int(s[p:p+2],16) for p in range(0,len(s),2)])​
    I'll also post this under the TED forum in case folks are looking in there first (as did I).

    Thanks again Juniel!

    Dave Xanatos

  • #2
    Hi Dave,

    Thanks for the informative post from our email exchange.

    ​I moved this in this section as this applies to all Mates Studio compatible products as long as you use Commander or Architect environment.

    I would also like to add that we have software libraries that you can find to help you get started. You can find these here:

    There are Python libraries that you can either use right away or fork and modify.

    Best Regards
    Juniel Cruz