Skip to content

MemoryError on scan() when nothing is attached to bus #7

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

Closed
NonsenseInc opened this issue Jun 18, 2018 · 9 comments
Closed

MemoryError on scan() when nothing is attached to bus #7

NonsenseInc opened this issue Jun 18, 2018 · 9 comments
Assignees

Comments

@NonsenseInc
Copy link

When no sensor is attached to the OneWire bus on calling scan() a MemoryError occurs:

Adafruit CircuitPython 2.3.1 on 2018-05-07; Adafruit CircuitPlayground Express with samd21g18
>>> import board
>>> from adafruit_onewire.bus import OneWireBus
>>> ow_bus = OneWireBus(board.D5)
>>> ow_bus.scan()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "adafruit_onewire/bus.py", line 133, in scan
MemoryError: memory allocation failed, allocating 1024 bytes

I tested this on a Trinket M0, Feather M0 express and Feather M0 basic with CircuitPython 2.2.0, 2.3.1 and the 3.0 beta.

I tested the negative (with sensor attached and working) on Trinket M0 and Feather M0 basic with CircuitPython 2.3.1.

@caternuson
Copy link
Contributor

The scan currently has no limit check. It would be pretty easy to add one, but not sure what the max value should be. Maybe just set it to something sane, 10? And if someone actually has more devices they can bump it up.

Probably related:
adafruit/Adafruit_CircuitPython_DS18X20#7

@caternuson caternuson self-assigned this Nov 3, 2018
@ladyada
Copy link
Member

ladyada commented Nov 3, 2018

max 10 is plenty!

@caternuson
Copy link
Contributor

Just add a property?

import board
from adafruit_onewire.bus import OneWireBus
ow_bus = OneWireBus(board.D5)
# scan for up to max number of devices, throw error if more are discovered
ow_bus.scan()
# if more actually exist, reset the limit
ow_bus.maximum_devices = 20

@ladyada
Copy link
Member

ladyada commented Nov 5, 2018

yep thats fine

@caternuson
Copy link
Contributor

PR'd it up: #9

@caternuson
Copy link
Contributor

For now, fixed with #9.

@tannewt
Copy link
Member

tannewt commented Dec 3, 2019

@caternuson Why was the solution to add a limit when there is nothing on the bus? Shouldn't we return an empty list in that case?

@caternuson
Copy link
Contributor

@tannewt Can't remember exactly, but I think maybe it was because the scan can't distinguish between connected devices and not connected devices, so with nothing connected, it runs open ended.

@alexwhittemore
Copy link

@caternuson Why was the solution to add a limit when there is nothing on the bus? Shouldn't we return an empty list in that case?

For my own notes since I know I'll be back here eventually: No attached devices, data pull-up resistor present => empty list returned. No attached devices, data pin floating => hits the max limit. So I think it's to do with the bus idle state being incorrect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants