Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching mode of PUPDevice only works with read, not with write method #1213

Closed
ste7anste7an opened this issue Aug 27, 2023 · 1 comment
Closed
Labels
bug Something isn't working platform: Powered Up Issues related to LEGO Powered Up software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime) topic: sensors Issues involving sensors

Comments

@ste7anste7an
Copy link

ste7anste7an commented Aug 27, 2023

Describing the bug
The bug only appears to be present in the beta pybricks firmware (Pybricks MicroPython v1.20.0-23-g6c633a8dd on 2023-07-07; SPIKE Prime Hub with STM32F413VG).

When writing to a PUPDevice, the write(mode,data) method is used, with the mode the mode of the sensor to write data to. E.g. the Distance sensor uses mode 5 to set the values of LEDS around the two sensors with 4 segments representing the 4 bytes of the data. When I read another mode first, and write immediately to mode 5, I get an error.
Using the latest pybricks firmware (Pybricks MicroPython v3.2.3 on 2023-02-17; SPIKE Prime Hub with STM32F413VG) this works OK, and the program below does not result in an error.

To reproduce
Steps to reproduce the behavior:

  1. Flash Spike Prime hub with beta firmware (Pybricks MicroPython v1.20.0-23-g6c633a8dd on 2023-07-07; SPIKE Prime Hub with STM32F413VG)
  2. Connect the distance sensor to port A
  3. Run the following program:
from pybricks.hubs import PrimeHub
from pybricks.pupdevices import Motor, ColorSensor, UltrasonicSensor, ForceSensor
from pybricks.parameters import Button, Color, Direction, Port, Side, Stop
from pybricks.robotics import DriveBase
from pybricks.tools import wait, StopWatch

hub = PrimeHub()

from pybricks.iodevices import PUPDevice
p=PUPDevice(Port.A)
#correct
print("read mode 1=",p.read(1))
print("read mode 5=",p.read(5))
p.write(5,[1,1,1,1])
print("success")
# failure
print("read mode 1=",p.read(1))
p.write(5,[1,1,1,1])
  1. See error
read mode 1= (91,)
read mode 5= (1, 1, 1, 1)
success
read mode 1= (91,)
Traceback (most recent call last):
  File "test_mode.py", line 18, in <module>
OSError: [Errno 1] EPERM: 

The requested operation is not valid in the current state:
--> Check the documentation for required conditions.
--> Check the line in your script that matches
    the line number given in the 'Traceback' above.

Expected behavior
The program should run without errors.

Screenshots
image

@ste7anste7an ste7anste7an added the triage Issues that have not been triaged yet label Aug 27, 2023
@dlech dlech added bug Something isn't working platform: Powered Up Issues related to LEGO Powered Up topic: sensors Issues involving sensors software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime) and removed triage Issues that have not been triaged yet labels Aug 27, 2023
@laurensvalk
Copy link
Member

Was able to reproduce and just pushed a fix. Thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working platform: Powered Up Issues related to LEGO Powered Up software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime) topic: sensors Issues involving sensors
Projects
None yet
Development

No branches or pull requests

3 participants