Skip to content

added examples folder and two example .py #15

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

Merged
merged 1 commit into from
Jan 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions examples/read_register_i2c.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import busio
import board
from adafruit_bus_device.i2c_device import I2CDevice

DEVICE_ADDRESS = 0x68 # device address of DS3231 board
A_DEVICE_REGISTER = 0x0E # device id register on the DS3231 board

# The follow is for I2C communications
comm_port = busio.I2C(board.SCL, board.SDA)
device = I2CDevice(comm_port, DEVICE_ADDRESS)

with device as bus_device:
bus_device.write(bytes([A_DEVICE_REGISTER]))
result = bytearray(1)
bus_device.readinto(result)

print(''.join('{:02x}'.format(x) for x in result))
20 changes: 20 additions & 0 deletions examples/read_register_spi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import busio
import board
import digitalio
from adafruit_bus_device.spi_device import SPIDevice

DEVICE_ADDRESS = 0x68 # device address of BMP280 board
A_DEVICE_REGISTER = 0xD0 # device id register on the BMP280 board

# The follow is for SPI communications
cs = digitalio.DigitalInOut(board.A2)
comm_port = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
device = SPIDevice(comm_port, cs)

#pylint: disable-msg=no-member
with device as bus_device:
bus_device.write(bytes([A_DEVICE_REGISTER]))
result = bytearray(1)
bus_device.readinto(result)

print(''.join('{:02x}'.format(x) for x in result))