Skip to content

Screen displays corrupted images on Mac #7

Open

Description

@opless

Someone else has had a similar issue here:

https://youtu.be/4z5OOW1jL94

I’m also using an M1 Mac.

I’m also reverse engineering the vendor .net binaries to attempt to figure out what is going wrong.

Though I’m struggling a little with the obfuscation. 😂

it’s not something as simple as endian issues!

Activity

  1. opless commented on Feb 3, 2022

    @opless
    Author

    Looks like it's something weird with the serial comms or the operating system.

    Closing because it's not fixable here.

  2. mathoudebine commented on Feb 3, 2022

    @mathoudebine
    Owner

    Sorry to hear that, FYI the display you should expect is this one: https://www.youtube.com/watch?v=Y1m4KK881Aw
    I had greater success in decompiling the chinese binary than the english one, it was not obfuscated. You will find the link of it in the README

  3. opless commented on Feb 3, 2022

    @opless
    Author

    I've had a look at all three, and yes, the one you mention is MUCH easier to work with.

    It's a shame there's no way to get hold of the creators and have a look at their firmware source.

    I'm considering knocking something up in golang, to see if it's just the serial port drivers are broken on the M1 or if it's just pyserial that's not working.

  4. alanrenouf commented on May 13, 2022

    @alanrenouf

    Im also getting this issue on my Mac, dont get it on windows. the port shows up as "/dev/tty.usbmodemUSB35INCHIPSV21" @opless did you find a workaround ?

  5. opless commented on May 13, 2022

    @opless
    Author

    It's very much to do with the USB serial implementation, as far as I can tell.

    I had some better luck sending data to it via golang, as the serial port initialisation is different.

    I pretty much put the project aside after things getting busy with the day job and having less brain in the evening. It's certainly something weird with the M1 serial usb drivers though!

  6. changed the title [-]Screen displays images but is corrupted and weird.[/-] [+]Screen displays corrupted images on Mac[/+] on May 16, 2022
  7. mathoudebine commented on May 16, 2022

    @mathoudebine
    Owner

    Hi, i'm reopening this issue for people with Mac that have the same problem. Feel free to discuss here. What you can also try is changing the COM port settings here:

    lcd_comm = serial.Serial(COM_PORT, 115200, timeout=1, rtscts=1)

    If i remember correctly, the display also works with baudrates slower than 115200

  8. added
    bug
    help wanted
    on May 16, 2022
  9. alanrenouf commented on May 16, 2022

    @alanrenouf

    Tried slower baudrates and not getting any luck

  10. Ebag333 commented on Jun 6, 2022

    @Ebag333
    Contributor

    #15

    I think I've fixed it by serializing the updates to the screen (using a queue, so it'll run through each one cleanly before executing the next).

    With the default code base I could get it to step on itself, once I started adding a bunch more things to update it just got worse and worse. You could help by increasing the delay after an update was done, but slowing down the updates isn't really a solution as it makes everything slow.

    With this PR it runs at a very high rate and has no issues with keeping up, not getting serial errors anymore.

  11. alanrenouf commented on Jun 6, 2022

    @alanrenouf

    I still get the corrupt image using the overhaul branch on my mac, I like the other changes to make the code more modular. Nice!

  12. gerph commented on Aug 29, 2022

    @gerph
    Contributor

    From my own investigation:

    In my testing in my own library, I found that the delay between the bitmap data being output and the next command being issued needs to be quite long - about 0.02 seconds. Shorter than this and you get corruption on the display. The current delay in the code on the master branch is about 0.01 seconds, which means that the other slack is being taken up by the code sitting between the time.sleep(0.01) and the next SendReg writing a command. On faster machines that code will be executed faster, and result in the corruption (I believe).

    In my library I changed the behaviour so that instead of explicitly sleeping at the end of the update of a bitmap, we remember when the last output happened and if we try to write a command before the required inter-bitmap-delay has expired, we sleep there instead. This means that we get useful work done between the two operations, and if you did enough work you'd never need to sleep at all before the next command was written.

    My library changes that did this were here, if they're useful to you:

    gerph/turing-smart-screen-python-mit@8ba5901

    It looks like the changes in PR #15, mentioned above, move the logic for the delay out of the communications library. I cannot tell how this keeps the bitmap transfers and the subsequent command updates apart enough to avoid the corruption.

  13. 27 remaining items

  14. mathoudebine commented on Mar 20, 2025

    @mathoudebine
    Owner

    Hi everyone!

    I may have fixed the issue with this simple change on the serial communication:
    ac169f3

    By manually flushing the serial buffer regularly, it has solved the corruption problem on my setup:

    • MacBook Air (13-inch, 2017)
    • macOS Monterrey 12.7.6

    A pull request has been opened with this fix here: #721

    Before merging, I would like to have your feedback, especially for people with Apple M1 CPU.
    You can use the branch fix/7-screen-displays-corrupted-images-on-mac or just apply the one-line fix manually.

    Thanks!

  15. mathoudebine commented on Apr 1, 2025

    @mathoudebine
    Owner

    Reopened because some corruptions still occur

  16. mathoudebine commented on Apr 1, 2025

    @mathoudebine
    Owner

    @gregsadetsky @oldirtdog what display do you have? Is it a Turing rev. A?
    Can you try with some portrait content if possible? Thanks

  17. gregsadetsky commented on Apr 2, 2025

    @gregsadetsky

    It's a Rev A yeah. I've been using simple-program.py for all of my tests, should I have been using some other sample code? thanks!

  18. tapsu01 commented on Apr 5, 2025

    @tapsu01

    I get this on MacOS Ventura 13.7.5:
    Image

  19. oldirtdog commented on May 13, 2025

    @oldirtdog

    @mathoudebine Tried in portrait mode... same garbage showing up on screen.

  20. aptonline commented on Apr 27, 2026

    @aptonline

    Can I confirm if it's just revision A displays that have this issues or is it all displays?

  21. oldirtdog commented on Apr 27, 2026

    @oldirtdog

    I'll be honest, I got tired of messing around with this thing and threw it in the trash. I only had the Revision A display.

  22. marcelors27 commented on May 10, 2026

    @marcelors27

    I investigated image corruption on macOS with a TURZX/Turing/UsbMonitor 3.5" device and found a likely root cause/workaround.

    Device

    • macOS on Apple Silicon
    • Device appears as serial:
      • /dev/cu.usbmodemUSB35INCHIPSV21
    • USB metadata:
      • Manufacturer: Turing
      • Product: UsbMonitor
      • Serial: USB35INCHIPSV2
      • VID/PID: 1a86:5722

    Symptom

    Using the current Rev A serial backend, the display receives data but complex images are corrupted/glitched:

    • shifted lines
    • repeated blocks
    • broken colors
    • framebuffer-like misalignment

    Simple solid color band patterns can appear mostly correct, which initially makes the serial path look valid, but real theme images are corrupted.

    What I tested

    • Python/pyserial Rev A serial backend: corrupted
    • Same protocol reimplemented in Go via /dev/cu.usbmodem...: corrupted
    • Smaller chunks / delays / flushing / skipping HELLO: still corrupted
    • Rev B protocol: device does not respond
    • Windows vendor software: works correctly

    I captured the Windows USB traffic with USBPcap. The payload is standard RGB565 little-endian and matches the Rev A framebuffer format. The key difference is transport:

    • Windows sends data directly to USB bulk OUT endpoint 0x03
    • macOS serial path goes through /dev/cu.usbmodem...

    When I bypassed the macOS serial device and wrote directly to USB bulk endpoint 0x03 using PyUSB/libusb, the image rendered correctly.

    Conclusion

    For this device, the framebuffer/protocol is not the issue. The corruption seems to come from the macOS USB CDC serial path. Writing directly to the bulk endpoint fixes it.

    Working approach

    Use PyUSB/libusb and write to:

    • VID/PID: 1a86:5722
    • interface: CDC data interface 1
    • OUT endpoint: 0x03
    • framebuffer: RGB565 little-endian
    • resolution: 320x480

    Minimal flow:

    1. Claim interface 1
    2. Send Rev A SET_ORIENTATION
    3. Send Rev A DISPLAY_BITMAP
    4. Send full RGB565 framebuffer to endpoint 0x03

    This works on macOS for the USB35INCHIPSV2 device where /dev/cu.usbmodem... corrupts images.

    This suggests the project may need a macOS-specific backend for Rev A UsbMonitor devices that uses raw USB bulk instead of pyserial.

  23. gregsadetsky commented on May 10, 2026

    @gregsadetsky

    @marcelors27 amazing work! Would you be able to share what code worked for you on macos?

  24. marcelors27 commented on May 10, 2026

    @marcelors27

    Sure. What worked for me on macOS was bypassing /dev/cu.usbmodem... entirely and writing directly to the USB bulk OUT endpoint with PyUSB/libusb.

    My device is:

    • VID/PID: 1a86:5722
    • Manufacturer: Turing
    • Product: UsbMonitor
    • Serial: USB35INCHIPSV2
    • Working OUT endpoint: 0x03
    • Resolution: 320x480
    • Pixel format: RGB565 little-endian

    Minimal example:

    import time
    from PIL import Image
    import usb.core
    import usb.util
    
    VID = 0x1A86
    PID = 0x5722
    INTERFACE = 1
    OUT_ENDPOINT = 0x03
    
    CMD_SET_ORIENTATION = 121
    CMD_DISPLAY_BITMAP = 197
    
    WIDTH = 320
    HEIGHT = 480
    
    
    def rgb565le(image):
        image = image.convert("RGB")
        out = bytearray()
        for r, g, b in image.getdata():
            value = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3)
            out += value.to_bytes(2, "little")
        return bytes(out)
    
    
    def send_command(endpoint, cmd, x, y, ex, ey):
        buf = bytearray(6)
        buf[0] = x >> 2
        buf[1] = ((x & 3) << 6) + (y >> 4)
        buf[2] = ((y & 15) << 4) + (ex >> 6)
        buf[3] = ((ex & 63) << 2) + (ey >> 8)
        buf[4] = ey & 255
        buf[5] = cmd
        endpoint.write(bytes(buf), timeout=5000)
    
    
    def set_orientation(endpoint):
        buf = bytearray(16)
        buf[5] = CMD_SET_ORIENTATION
        buf[6] = 100  # portrait
        buf[7] = WIDTH >> 8
        buf[8] = WIDTH & 255
        buf[9] = HEIGHT >> 8
        buf[10] = HEIGHT & 255
        endpoint.write(bytes(buf), timeout=5000)
    
    
    dev = usb.core.find(idVendor=VID, idProduct=PID)
    if dev is None:
        raise RuntimeError("Display not found")
    
    try:
        dev.set_configuration()
    except usb.core.USBError:
        pass
    
    try:
        if dev.is_kernel_driver_active(INTERFACE):
            dev.detach_kernel_driver(INTERFACE)
    except Exception:
        pass
    
    usb.util.claim_interface(dev, INTERFACE)
    
    cfg = dev.get_active_configuration()
    intf = usb.util.find_descriptor(cfg, bInterfaceNumber=INTERFACE)
    
    endpoint = usb.util.find_descriptor(
        intf,
        custom_match=lambda ep:
            usb.util.endpoint_direction(ep.bEndpointAddress) == usb.util.ENDPOINT_OUT
            and ep.bEndpointAddress == OUT_ENDPOINT
    )
    
    if endpoint is None:
        raise RuntimeError("OUT endpoint not found")
    
    image = Image.open("background.png").convert("RGB").resize((WIDTH, HEIGHT))
    
    set_orientation(endpoint)
    time.sleep(0.05)
    
    send_command(endpoint, CMD_DISPLAY_BITMAP, 0, 0, WIDTH - 1, HEIGHT - 1)
    time.sleep(0.02)
    
    endpoint.write(rgb565le(image), timeout=5000)
    
    usb.util.release_interface(dev, INTERFACE)
    usb.util.dispose_resources(dev)

    On macOS I also needed libusb:

    brew install libusb
    

    The important finding is that the framebuffer/protocol itself was correct. The corruption happened when using the macOS serial device (/dev/cu.usbmodemUSB35INCHIPSV21). Sending the same RGB565 little-endian framebuffer directly to USB bulk endpoint 0x03 fixed the corrupted image for me.

  25. amarok30 commented on Aug 21, 2026

    @amarok30

    Root cause found + verified working fix on macOS (Mac mini M4, macOS 26.5.2, Turing/UsbMonitor 3.5" rev A — 1a86:5722, serial USB35INCHIPSV2).

    After a systematic reverse-engineering session (solid fills, gradients, per-packet rainbow maps, barcode-tagged bands, full USB descriptor probing), the corruption mechanism is now clear:

    The panel firmware is USB-transfer-oriented, not byte-stream-oriented.

    • It reads a command from the start of a USB transfer and ignores the rest of that transfer.
    • After a DISPLAY_BITMAP header, it counts exactly w*h pixel bytes (RGB565 LE). Any byte arriving before the rectangle is complete — including what we believe are commands — is swallowed as pixel data.
    • Once the byte stream loses sync (a single lost/mis-framed byte), the panel's pixel counter is off, and every subsequent command is eaten as pixels → permanent corruption until power cycle. This explains why RESET/CLEAR "don't work" once the image is corrupted, and why every run produces different garbage.
    • The macOS CDC ACM serial path (/dev/cu.usbmodemUSB35INCHIPSV21) repackages/fragments USB transfers arbitrarily, so commands end up glued to pixel data or split mid-command → instant desync. This matches @gregsadetsky's 64-byte packet reordering observations and why Linux/Windows/ESP32 are unaffected.

    These exact semantics are documented in @tanakamasayuki's EspUsbHost TuringDevice.hpp (ESP32 USB-host driver for this same panel): "The panel takes a command from the start of a transfer and ignores the rest of it" / "The panel counts the pixels itself".

    Working fix (verified end-to-end): bypass the serial device entirely — write directly to bulk OUT endpoint 0x03 via PyUSB/libusb with strict transfer discipline:

    1. every command in its own transfer (one endpoint.write() per command; a header never shares a transfer with pixel data),
    2. SET_ORIENTATION is 11 bytes (6-byte command + orientation+100 + width/height BE), not 16,
    3. pixel data in 64-byte-aligned chunks totalling exactly w*h*2 bytes,
    4. nothing else is written while a bitmap is in progress,
    5. if the panel ever desyncs, unplug/replug the USB-C cable — RESET only reaches the panel when the stream is in sync.

    With this, the panel renders solid full-screen frames back-to-back with zero desync, and the full system monitor (themes + live stats) runs correctly on macOS.

    A ready-to-use backend (subclass of LcdCommRevA, registered as REVISION: A_USBMAC) is here: https://gist.github.com/amarok30/cddaa9a9818d6830a74d9332f501047e

    Note: @marcelors27's one-shot bulk write worked on their unit but not on ours (identical VID/PID/serial), there seem to be firmware batch differences; the strict transfer discipline above is what made it reliable here. Hope this helps finally close this one .

  26. eaglstun commented on Nov 19, 2026

    @eaglstun

    Update: PR #1138 adds the USB bulk fix below as an opt-in USB_BULK option.

    Another rev A unit (1a86:5722, serial USB35INCHIPSV2, TURZX-branded) working on macOS. I'm on an M4 Max, macOS 27, with the screen behind a USB-C dock. A few findings that might help this get merged.

    1. Raw USB works without root. I used the bulk endpoint approach from marcelors27 and amarok30. On my machine detach_kernel_driver() fails with Access denied, but claim_interface(1) succeeds anyway with the CDC driver still attached, and writes to endpoint 0x03 draw perfectly. So a macOS backend doesn't need sudo or a special entitlement.

    2. Why the serial path corrupts, as seen on this unit. Before finding this thread I worked it out from photos of test patterns. The firmware draws every USB packet as 64 bytes (32 px), whatever its real length:

    • a short packet is drawn padded with stale bytes, which makes slanted or staircase images;
    • when a write's length is an exact multiple of 64, macOS ends the transfer with a zero-length packet, and that is drawn as a duplicate 64 bytes. With large writes this shows up as about 20% extra data: bands too tall, and leftover pixels that become the "second pass" / desync people describe here.

    This fits amarok30's "transfer-oriented" description. It also explains why flushing and delays never fully fixed it: they change where the packet boundaries fall, not what the firmware does with them.

    3. Partial updates. I keep a framebuffer copy of the screen and widen every DisplayPILImage call horizontally to the 32-px grid. Each bitmap is then exactly w*h*2 bytes in whole 64-byte packets, so text, clock and progress-bar updates are packet-aligned too, not only full frames. A full 320×480 frame takes about 1.9 s. The stock 3.5inchTheme2 theme runs at about 1% of one core.

    4. Fallback for people who can't use libusb. Through /dev/cu.usbmodem* it also works if each write is several full 64-byte packets plus one 62-byte packet (no write is ever a multiple of 64), with flush() after each write and 160 px per write. The firmware's junk pixel then always lands on the same column, which leaves 2 faint hairlines (x = 159 and 319). Writes over ~512 bytes got split by macOS and broke it.

    Two smaller things:

    • Reset() on startup left my unit ignoring draw commands until it was replugged. RESET_ON_STARTUP: false avoids that.
    • The same unit draws correctly on Raspberry Pi OS through the stock serial path, with no workarounds. That confirms this is specific to macOS's serial driver.
    • Unrelated to the display, but needed for a usable Mac theme: on Apple Silicon psutil.cpu_freq() returns placeholders (the theme shows 0.00 GHz), and disk_usage("/") reads the sealed system volume. I read live per-cluster frequency from IOReport (no root, residency-weighted over the pmgr DVFS tables) and use /System/Volumes/Data for disk. I've since added GPU load, memory, frequency and temperature, plus CPU temperature, from IOAccelerator, IOReport and the SMC. SMC sensor keys are found from the SMC's own key table, because the M1–M3 names don't all exist on M4, and parked cores read a 40.0 °C placeholder. That overlaps Add Apple Silicon sensor support (SMC, IOReport, AGX GPU) #977, so I've kept it out of Rev A: optional USB bulk transport to fix corrupted images on macOS #1138 and sent it separately as Python sensors: Apple Silicon CPU/GPU frequency, temperatures and macOS disk #1139.

    PR #1138 adds the USB bulk transport as USB_BULK under REVISION: A (default false; configure.py's revision map untouched), falling back to the serial port if the device can't be opened over USB. The serial 62-byte workaround from point 4 is left out to keep it small.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions