diff options
| author | Dan Halbert <halbert@halwitz.org> | 2018-02-27 22:03:52 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-02-27 22:03:52 -0500 |
| commit | 568c04e6afa8016062f685b2198c0209f62827f4 (patch) | |
| tree | d07b76119f715add462983b335797adf64b61249 /examples/accel_i2c.py | |
| parent | 6a2379fd0bfe10017d8abc5c36ef1d470c0d9b27 (diff) | |
| parent | ea633117d01d94e8d56ed94344e4b3e46b4eef03 (diff) | |
Merge pull request #650 from tannewt/merge_2x3.0.0-alpha.2
Merge in commits from 2.x branch.
Diffstat (limited to 'examples/accel_i2c.py')
| -rw-r--r-- | examples/accel_i2c.py | 34 |
1 files changed, 0 insertions, 34 deletions
diff --git a/examples/accel_i2c.py b/examples/accel_i2c.py deleted file mode 100644 index d635e3ccc..000000000 --- a/examples/accel_i2c.py +++ /dev/null @@ -1,34 +0,0 @@ -# This is an example on how to access accelerometer on -# PyBoard directly using I2C bus. As such, it's more -# intended to be an I2C example, rather than accelerometer -# example. For the latter, using pyb.Accel class is -# much easier. - -from machine import Pin -from machine import I2C -import time - -# Accelerometer needs to be powered on first. Even -# though signal is called "AVDD", and there's separate -# "DVDD", without AVDD, it won't event talk on I2C bus. -accel_pwr = Pin("MMA_AVDD") -accel_pwr.value(1) - -i2c = I2C(1, baudrate=100000) -addrs = i2c.scan() -print("Scanning devices:", [hex(x) for x in addrs]) -if 0x4c not in addrs: - print("Accelerometer is not detected") - -ACCEL_ADDR = 0x4c -ACCEL_AXIS_X_REG = 0 -ACCEL_MODE_REG = 7 - -# Now activate measurements -i2c.mem_write(b"\x01", ACCEL_ADDR, ACCEL_MODE_REG) - -print("Try to move accelerometer and watch the values") -while True: - val = i2c.mem_read(1, ACCEL_ADDR, ACCEL_AXIS_X_REG) - print(val[0]) - time.sleep(1) |
