Serial communication with arduino breaks when turning USB port power on/off

If you're having trouble with your LattePanda, here's the place to get help.
Forum rules
    Post technical issues here.

    - Discussion tone should be kept polite and focused on facts
    - Vulgar language or flaming constitutes an instant ban
    - Please note we cannot support PM requests for help
    - Members are asked to post in English only so that posts can be well received and properly monitored
    - You can find the RMA guide [here]
    - Please check if your question has already been answered before opening a new thread. If it has not, please verify the following:


    - Have you tried a hard reset?
    - Are you using a 5V@2A+ power supply and a high quality USB cable?
    - Have you tried powering the board through the CN2 headers?
    - Have you tried a cooling solution such as a fan or heatsink?
    - Have you tried reinstalling drivers?
    - Have you tried reloading the operating system?
    - Have you tried flashing the BIOS?
    - Are you able to flash the BIOS at the hardware level?

    If you have not found a solution, post a new issue. To speed up the process please let us know:
    - Have you tried the solutions listed above?
    - What board are you using? Standard (2GB RAM/32GB eMMC) or Enhanced (4GB RAM/64GB eMMC)?
    - Have you tried any other solutions?
    - How long have you had your board for?
    - When did you first boot your board?
    - Did it work ok before the issue occurred or has the issue always been there?
    - Use images and videos to help us understand the issue where possible

    If you are seeking RMA:
    - Please open a new topic rather than hijacking someone else's thread
    - Mark RMA posts with [DEFECTIVE] + <helpful description of issue>. We can then approve/disapprove each request
    - Completed RMA cases will be marked with [CLOSED]
    You can find the RMA guide [here]

    Resolved Issues
    - If you manage to fix an issue, please share your solution for the good of the community. It could help someone else in future.
    - If an issue is resolved the thread should be marked as [RESOLVED]. We can then sticky the thread to help people in future.

    What does troubleshooting support?
    - Hardware queries
    - Hardware issues that weren’t caused by you, e.g DOA board
    - Windows 10 specific issues
    Post Reply
    User avatar
    overdrive
    Posts: 2
    Joined: Tue May 21, 2019 9:50 am

    Wed May 22, 2019 9:01 am

    Hello,

    To give you some context, I'm running the Firmata sketch on the onboard Arduino and my program communicates with it through Serial.
    This works quite well, BUT, I recently had to adapt the electronics circuit so that I can power one of the USB ports on and off using an external relay.
    I basically run a USB cable's +5V wire through a relay and when I need to switch the power on or off I send a signal through one of the Arduino pins. This works
    as expected (in fact my circuit has another relay controlled by the Arduino and that has been working for months now), EXCEPT, every once in a while the Serial communication breaks, after which my program needs to restart and, in some rare occasions the COM port is no longer detected so a reboot of the LattePanda is required.

    The error I'm getting is reported by PyMata3 (the python client for the Firmata Arduino program):

    Code: Select all

    [Errno 5] Input/output error
    Write exception
    Shutting down ...
    
    This may be an issue with my electronics circuit, but it also may be due to something Latte-related - could the COM port be affected by my relay switching a USB cable?
    I've been struggling with this issue for quite some time and I've tried modifying my circuit but I can't seem to find a solution. Any help would be appreciated.

    [Edit]: I failed to mention that I'm running Linux on the LattePanda - Ubuntu 16.04.2 LTS

    User avatar
    ccs_hello
    Posts: 376
    Joined: Sat Oct 13, 2018 9:16 pm

    Wed May 22, 2019 1:11 pm

    On the control coil side of the relay, did you put a reverse-polarity connected diode to absorb the transient high voltage pulse?
    (Use Google search relay + diode to know what I mean)

    BTW, do you energize the relay coil almost all the time, or just momentary?
    The relay coil is driven by (which power? from where?)

    User avatar
    overdrive
    Posts: 2
    Joined: Tue May 21, 2019 9:50 am

    Wed May 22, 2019 4:21 pm

    ccs_hello wrote:
    Wed May 22, 2019 1:11 pm
    On the control coil side of the relay, did you put a reverse-polarity connected diode to absorb the transient high voltage pulse?
    (Use Google search relay + diode to know what I mean)
    I'm using one of these: https://www.google.com/search?q=JQC-3FF ... QguQ5KSYM: and it does have a reverse-polarity diode.
    ccs_hello wrote:
    Wed May 22, 2019 1:11 pm
    BTW, do you energize the relay coil almost all the time, or just momentary?
    It is inactive by default, I only activate it when I need the USB and after the USB operations are finished the relay is again deactivated.
    That said, the above-mentioned USB operations are error-prone and my python script re-tries (sometimes 5-6 times or even more) until it succeeds which means that it can 'connect' and 'disconnect' the USB cable 5-6 times in an interval of 1-2 minutes. I do have reasonable wait times though.
    ccs_hello wrote:
    Wed May 22, 2019 1:11 pm
    The relay coil is driven by (which power? from where?)
    As you may have seen from the image above it's one of those all-in-one relay packages so it takes +5V and GND from the LattePanda/Arduino and a signal from one of the Arduino digital pins. This signal goes to the base of a transistor (the transistor is on the relay PCB) which in turn energizes the relay coil.

    Post Reply