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

[Bug] PUPdevice on TechnicHub reports ID=8 when no device is attached #230

Closed
BertLindeman opened this issue Jan 24, 2021 · 10 comments
Closed
Labels
bug Something isn't working hub: technichub Issues related to the LEGO Technic hub (Hub No. 2) software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime)

Comments

@BertLindeman
Copy link

BertLindeman commented Jan 24, 2021

Describe the bug
On a TechnicHub PUPDevice(port) reports device.info as id = 8
See pybricks technical-info: list of identifications
Part of it:

ID (hex) Description
0 (0x00) no device
8 (0x08) Powered Up Lights

To reproduce
Steps to reproduce the behavior:

  1. Go to code.pybricks.com
  2. Connect an hub
  3. load the program from below
  4. Run the program [EDIT Forgot this step]
  5. See console log

Expected behavior
Would have expected the hubs all to response the same or similar at least.
. Either return an OSError ENODEV
or
. return a device ID of '0' zero

Priority
LOW

Screenshots
None now

Source used

#
# Source: Z:\home\bert\py\pybricks\issue\issue_#230.py
# simple_discover_devices.py


from pybricks import version
# from pybricks.tools import wait
from pybricks.iodevices import PUPDevice  # was LUMPDevice
from pybricks.parameters import Port
print(version)
hw_type = version[0]

if hw_type == "inventorhub" or hw_type == "primehub":  # aliases == the same firmware
    from pybricks.hubs import InventorHub
    hub = InventorHub()
elif hw_type == "technichub":
    from pybricks.hubs import TechnicHub
    hub = TechnicHub()
elif hw_type == "movehub":
    from pybricks.hubs import MoveHub
    hub = MoveHub()
else:
    raise BaseException("Unknown hub " + hw_type)
print(hw_type, "loaded\n\tBattery voltage:", hub.battery.voltage(), "mV")


def what_device_on_port(xport):
    try:
        device = PUPDevice(xport)
    except OSError as e:
        print("OSError", e, "on:", xport)
    except Exception as e:  # noqa:  E722 do not use bare 'except'
        print("General ", e, "occurred on ", xport)
    else:
        print("\t\tOn %-7s device.ID=%2d %s" % (xport, device.info()['id'], device.info()))
    return


if not hw_type == 'movehub':
    what_device_on_port(Port.A)
    what_device_on_port(Port.B)
what_device_on_port(Port.C)
what_device_on_port(Port.D)
if hw_type == 'primehub':
    what_device_on_port(Port.E)
    what_device_on_port(Port.F)

Console log

----------
('technichub', '3.0.0b1', 'v3.0.0b1 on 2021-01-22')
technichub loaded
        Battery voltage: 8178 mV
                On Port.A  device.ID= 8 {'id': 8}
                On Port.B  device.ID= 8 {'id': 8}
                On Port.C  device.ID= 8 {'id': 8}
                On Port.D  device.ID= 8 {'id': 8}

----------
('primehub', '3.0.0a13', 'v3.0.0a13-13-g087a11f7 on 2021-01-19')
primehub loaded
        Battery voltage: 7389 mV
OSError [Errno 19] ENODEV: 
<removed the cable etc explanations>
 on: Port.A
OSError [Errno 19] ENODEV:  on: Port.B
OSError [Errno 19] ENODEV:  on: Port.C
OSError [Errno 19] ENODEV:  on: Port.D
OSError [Errno 19] ENODEV:  on: Port.E
OSError [Errno 19] ENODEV:  on: Port.F

----------
('movehub', '3.0.0b1', 'v3.0.0b1 on 2021-01-22')
movehub loaded
        Battery voltage: 7422 mV
OSError [Errno 19] ENODEV on: Port.C
OSError [Errno 19] ENODEV on: Port.D
@BertLindeman BertLindeman added the triage Issues that have not been triaged yet label Jan 24, 2021
@dlech
Copy link
Member

dlech commented Jan 24, 2021

Does the same thing happen on other hubs or only the TechnicHub?

@BertLindeman
Copy link
Author

Does the same thing happen on other hubs or only the TechnicHub?

David, I only have the TechnicHub, MoveHub, PrimeHub and InventorHub.
The results of those are above in the console log.

I do not know for the other hubs.

@dlech
Copy link
Member

dlech commented Jan 24, 2021

Sorry, I was just looking at the title of the issue.

@dlech dlech added bug Something isn't working hub: technichub Issues related to the LEGO Technic hub (Hub No. 2) software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime) and removed triage Issues that have not been triaged yet labels Jan 24, 2021
@laurensvalk
Copy link
Member

Thanks for reporting this and for taking the time to test this on all hubs.

Possibly related: I recently noticed that it was possible to initialize DCMotor when in fact a regular Motor was attached. I don't remember for sure, but it could have been the Technic Hub indeed.

@BertLindeman
Copy link
Author

BertLindeman commented Jan 24, 2021

Funny, may be related, but not on a technichub:
The example for DCMotor does work on the movehub.
This program:

from pybricks.pupdevices import DCMotor
from pybricks.parameters import Port
from pybricks.tools import wait

# Initialize a motor without rotation sensors on port A.
example_motor = DCMotor(Port.A)

# Make the motor go clockwise (forward) at 70% duty cycle ("70% power").
example_motor.dc(70)

# Wait for three seconds.
wait(3000)

# Make the motor go counterclockwise (backward) at 70% duty cycle.
example_motor.dc(-70)

# Wait for three seconds.
wait(3000)

But also on the TechnicHub...
And the motor on port A is correctly reported as id=75 the inventor medium motor.

@laurensvalk
Copy link
Member

So maybe it's a different issue then. Thanks!

@dlech
Copy link
Member

dlech commented Feb 2, 2021

    raise BaseException("Unknown hub " + hw_type)

(off topic) Python tip: Always use Exception instead of BaseException or even better, a more specific exception like RuntimeError.

@dlech
Copy link
Member

dlech commented Feb 3, 2021

Measurement shows that something is pulling down the ID2 pin on Technic Hub.

Top line is ID2, second line is ID1. Measurements taken with no sensor connected, showing device detection sequence repeating.

Technic Hub

image

Move Hub

image

@BertLindeman
Copy link
Author

BaseException

(off topic) Python tip: Always use Exception instead of BaseException or even better, a more specific exception like RuntimeError.

Thank you, David.
I really like these little nudges in the direction of writing better python.

(more on topic) I now have a "powered-up leds" device that should be reported as "8".
Will test it the next firmware distribution.

@BertLindeman
Copy link
Author

Found build artifact and this issue is fixed.

trimmed extra ENODEV messages

('technichub', '3.0.0b1', 'v3.0.0b1-15-ga4b616f7 on 2021-02-03')
technichub loaded
        Battery voltage: 7839 mV
On: Port.A OSError [Errno 19] ENODEV: 
On: Port.B OSError [Errno 19] ENODEV:
On: Port.C OSError [Errno 19] ENODEV: 
On: Port.D OSError [Errno 19] ENODEV: 

And with leds attached to port C and D:

                On Port.C  device.ID= 8 {'id': 8}
                On Port.D  device.ID= 8 {'id': 8}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working hub: technichub Issues related to the LEGO Technic hub (Hub No. 2) software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime)
Projects
None yet
Development

No branches or pull requests

3 participants