Skip to content

Commit b3981e7

Browse files
committed
Small fixes.
1 parent 2ab0e1c commit b3981e7

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
__pycache__
22
_build
33
*.pyc
4+
*.mpy

adafruit_fxas21002c.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class FXAS21002C:
7171
def __init__(self, i2c, address=_FXAS21002C_ADDRESS,
7272
gyro_range=GYRO_RANGE_250DPS):
7373
assert gyro_range in (GYRO_RANGE_250DPS, GYRO_RANGE_500DPS,
74-
GYRO_RANGE_100DPS, GYRO_RANGE_2000DPS)
74+
GYRO_RANGE_1000DPS, GYRO_RANGE_2000DPS)
7575
self._gyro_range = gyro_range
7676
self._device = i2c_device.I2CDevice(i2c, address)
7777
# Check for chip ID value.
@@ -87,8 +87,11 @@ def __init__(self, i2c, address=_FXAS21002C_ADDRESS,
8787
elif gyro_range == GYRO_RANGE_2000DPS:
8888
ctrlReg0 = 0x00
8989
# Reset then switch to active mode with 100Hz output
90-
self._write_u8(_GYRO_REGISTER_CTRL_REG1, 0x00) # Standby
91-
self._write_u8(_GYRO_REGISTER_CTRL_REG1, (1<<6)) # Reset
90+
# Putting into standy doesn't work as the chip becomes instantly
91+
# unresponsive. Perhaps CircuitPython is too slow to go into standby
92+
# and send reset? Keep these two commented for now:
93+
#self._write_u8(_GYRO_REGISTER_CTRL_REG1, 0x00) # Standby)
94+
#self._write_u8(_GYRO_REGISTER_CTRL_REG1, (1<<6)) # Reset
9295
self._write_u8(_GYRO_REGISTER_CTRL_REG0, ctrlReg0) # Set sensitivity
9396
self._write_u8(_GYRO_REGISTER_CTRL_REG1, 0x0E) # Active
9497
time.sleep(0.1) # 60 ms + 1/ODR
@@ -97,7 +100,7 @@ def _read_u8(self, address):
97100
# Read an 8-bit unsigned value from the specified 8-bit address.
98101
with self._device:
99102
self._BUFFER[0] = address & 0xFF
100-
self._device.write(self._BUFFER, end=1)
103+
self._device.write(self._BUFFER, end=1, stop=False)
101104
self._device.readinto(self._BUFFER, end=1)
102105
return self._BUFFER[0]
103106

@@ -115,8 +118,8 @@ def read_raw(self):
115118
"""
116119
# Read 7 bytes from the sensor.
117120
with self._device:
118-
self._BUFFER[0] = GYRO_REGISTER_STATUS | 0x80
119-
self._device.write(self._BUFFER, end=1)
121+
self._BUFFER[0] = _GYRO_REGISTER_STATUS | 0x80
122+
self._device.write(self._BUFFER, end=1, stop=False)
120123
self._device.readinto(self._BUFFER)
121124
# Parse out the gyroscope data.
122125
status = self._BUFFER[0]

examples/simpletest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# Read gyroscope.
2222
gyro_x, gyro_y, gyro_z = sensor.gyroscope
2323
# Print values.
24-
print('Gyroscope (radians/s): ({0:0.3f},{0:0.3f},{0:0.3f})'.format(
24+
print('Gyroscope (radians/s): ({0:0.3f},{1:0.3f},{2:0.3f})'.format(
2525
gyro_x, gyro_y, gyro_z))
2626
# Delay for a second.
2727
time.sleep(1.0)

0 commit comments

Comments
 (0)