Dependencies¶
This driver depends on:
Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.
Usage Example¶
import board
from adafruit_onewire.bus import OneWireBus
ow_bus = OneWireBus(board.D2)
devices = ow_bus.scan()
for d in devices:
print("ROM={}\tFamily=0x{:02x}".format(d.rom, d.family_code))
Contributing¶
Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.
Building locally¶
To build this library locally you’ll need to install the circuitpython-build-tools package.
python3 -m venv .env
source .env/bin/activate
pip install circuitpython-build-tools
Once installed, make sure you are in the virtual environment:
source .env/bin/activate
Then run the build:
circuitpython-build-bundles --filename_prefix adafruit-circuitpython-onewire --library_location .
Sphinx documentation¶
Sphinx is used to build the documentation based on rST files and comments in the code. First, install dependencies (feel free to reuse the virtual environment from above):
python3 -m venv .env
source .env/bin/activate
pip install Sphinx sphinx-rtd-theme
Now, once you have the virtual environment activated:
cd docs
sphinx-build -E -W -b html . _build/html
This will output the documentation to docs/_build/html
. Open the index.html in your browser to
view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to
locally verify it will pass.
Table of Contents¶
Simple test¶
Ensure your device works with this simple test.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | import board
from adafruit_onewire.bus import OneWireBus
# Create the 1-Wire Bus
# Use whatever pin you've connected to on your board
ow_bus = OneWireBus(board.D2)
# Reset and check for presence pulse.
# This is basically - "is there anything out there?"
print("Resetting bus...", end='')
if ow_bus.reset():
print("OK.")
else:
raise RuntimeError("Nothing found on bus.")
# Run a scan to get all of the device ROM values
print("Scanning for devices...", end='')
devices = ow_bus.scan()
print("OK.")
print("Found {} device(s).".format(len(devices)))
# For each device found, print out some info
for i, d in enumerate(devices):
print("Device {:>3}".format(i))
print("\tSerial Number = ", end='')
for byte in d.serial_number:
print("0x{:02x} ".format(byte), end='')
print("\n\tFamily = 0x{:02x}".format(d.family_code))
# Usage beyond this is device specific. See a CircuitPython library for a 1-Wire
# device for examples and how OneWireDevice is used.
|
adafruit_onewire.bus
¶
Provide access to a 1-Wire bus.
- Author(s): Carter Nelson
-
class
adafruit_onewire.bus.
OneWireAddress
(rom)[source]¶ A class to represent a 1-Wire address.
-
crc
¶ The 8 bit CRC.
-
family_code
¶ The 8 bit family code.
-
rom
¶ The unique 64 bit ROM code.
-
serial_number
¶ The 48 bit serial number.
-
-
class
adafruit_onewire.bus.
OneWireBus
(pin)[source]¶ A class to represent a 1-Wire bus.
-
static
crc8
(data)[source]¶ Perform the 1-Wire CRC check on the provided data.
Parameters: data (bytearray) – 8 byte array representing 64 bit ROM code
-
maximum_devices
¶ The maximum number of devices the bus will scan for. Valid range is 1 to 255. It is an error to have more devices on the bus than this number. Having less is OK.
-
readinto
(buf, *, start=0, end=None)[source]¶ Read into
buf
from the device. The number of bytes read will be the length ofbuf
.If
start
orend
is provided, then the buffer will be sliced as ifbuf[start:end]
. This will not cause an allocation likebuf[start:end]
will so it saves memory.Parameters:
-
reset
(required=False)[source]¶ Perform a reset and check for presence pulse.
Parameters: required (bool) – require presence pulse
-
static
adafruit_onewire.device
¶
Provides access to a single device on the 1-Wire bus.
- Author(s): Carter Nelson
-
class
adafruit_onewire.device.
OneWireDevice
(bus, address)[source]¶ A class to represent a single device on the 1-Wire bus.
-
readinto
(buf, *, start=0, end=None)[source]¶ Read into
buf
from the device. The number of bytes read will be the length ofbuf
.If
start
orend
is provided, then the buffer will be sliced as ifbuf[start:end]
. This will not cause an allocation likebuf[start:end]
will so it saves memory.Parameters:
-