Adafruit RP2040 flush/empty buffer

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
TobyGraf
 
Posts: 3
Joined: Fri Apr 09, 2021 6:10 am

Adafruit RP2040 flush/empty buffer

Post by TobyGraf »

I am using an Adafruit RP2040 and have it set up with 2 Rotary encoders and a small display. When I start the program I can change the value on the display using the Rotary encoders, but as soon as I set the value via PC command the two Rotary encoders don't react anymore. I tried to close the instance with the pc but still nothing. I can reconnect the PC again after closing the instance and set the values via PC again, but no reactions from the Rotary encoders anymore until I restart the whole RP2040.

Is there a command I can use to make the RP2040 listen to the encoders again?


Here is the code I use to establish connection:

Code: Select all

 import pyvisa
import board
import time

resources = rm.list_resources()
foundInstr = None

for iRes in resources:
    if 'ASRL6' in iRes:
        foundInstr = iRes
    if foundInstr != None:
        inst = rm.open_resource(foundInstr) 
and here the code I use to set the value and read back the set value:

Code: Select all

 inst.clear()
inst.write('250')
value = inst.read()
print(value) 
Thank you very much for your help

User avatar
TobyGraf
 
Posts: 3
Joined: Fri Apr 09, 2021 6:10 am

Re: Adafruit RP2040 flush/empty buffer

Post by TobyGraf »

I use the supervisor.runtime to check for an input:

Code: Select all

if supervisor.runtime.serial_bytes_available:  # 65536        /    0,000050354
    cmd = input()
    if cmd.replace('.','',1).isdigit() and cmd[0] in ['1','2']:
        Vset = float(cmd)
        if Vset < 100.:
            print('not recognized command: \"' + cmd + '\"')
        elif Vset < 200.: # set voltage for channel 1
            V1 = Vset - 100.
            changeV1 = True
        else:          # set voltage for channel 2
            V2 = Vset - 200.
            changeV2 = True
    else:
        if 'test' in cmd.lower():
            print('PZT driver') 
        elif 'idn' in cmd.lower():
            print(ID + ',' + SerialNumber + ',' + version)
        elif 'now?' in cmd.lower():
            print(f'{measure100V(analog_1):.2f};{measure100V(analog_3):.2f}')
        elif 'set?' in cmd.lower():
            print(f'{V1:.2f};{V2:.2f}')
        else:
            print('not recognized command: \"' + cmd + '\"')
I read something about the input() function blocking the system, but I can't find how to unblock it....

Some help would really be appreciated :D

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”