Welcome to Our Community

Some features disabled for guests. Register Today.

Connecting with PySerial requires a reset

Discussion in 'Other Software' started by flashmasterdice, Feb 24, 2025.

  1. flashmasterdice

    Builder

    Joined:
    Feb 24, 2025
    Messages:
    1
    Likes Received:
    0
    Hi! Thanks for reading.

    I'm controlling the BlackBox via Python and PySerial on Raspberry Pi (Raspberry Pi OS). It works great. One problem I have and can't figure out is why I have to press the Reset button to get the script to work a second time. I have used this code on another controller board and I don't have this problem. When I connect to the Black Box via CuteCom or Arduino IDE Serial monitor, i don't have the problem. I feel like these programs are doing something to properly close the connection I'm not. Below is a sample script I've been using for testing purposes.

    If I use one of these terminal emulators to open and close the serial connection, then I am able to reconnect via PySerial.

    Thanks for any help.

    Code:
    import serial
    import time
    
    dev = serial.Serial('/dev/ttyUSB0', 115200, timeout=2)
    time.sleep(2)
    
    while(True):  
        response = dev.readline().decode('utf-8').strip()
        print(response)
        uin = input("> ")
      
        if(uin == "quit"):
            dev.close()
            exit()
      
        uinb =  bytes(uin, 'utf-8')
        dev.write(uinb)
      
        time.sleep(1)
    
    
     
  2. Peter Van Der Walt

    Peter Van Der Walt OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Mar 1, 2017
    Messages:
    15,497
    Likes Received:
    4,421

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice