This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

reset NRF51 from serial with python

hi,

I am want to communicate with nr52 dongle via serial. The dongle periodically outputs data which I read.

The problem is that is the python connect in the middle of printf the data is corrupted. Hence, I would like to reset the NRF51 dongle for fresh print outs. I tried same code sequence as Arduino but that does not work. Cant find any documentation for that. Following is the code I am running

def runSerial(BAUD=38400, size=16):
    import serial.tools.list_ports
    PORT =''
    NAME =''
    for p in list(serial.tools.list_ports.comports()):
        if 'usbmodem' in p[0]:
            PORT = p[0]
            NAME = p[1]
            break
    if PORT:
        ser = serial.Serial(PORT, BAUD)
        ser.setDTR(level=False)
        time.sleep(0.5)
        # ensure there is no stale data in the buffer
        ser.flushInput()
        ser.setDTR()
        time.sleep(0.5)
        print( "waiting for NRF %s..." %NAME )

        s = struct.Struct('16B')
        read_byte = ser.read()
        while True:
            print  s.unpack_from(ser.readline())
            print "              "
  • Do you want to reset the device, as in powerdown and powerup again? Or do you just want to start a new transmission? Could you start each transmission with a characteristic magic word or something, and have the python code just wait for the first magic word and discard the rest?

Related