Skip to content

Commit 8545ed2

Browse files
authored
Merge pull request #68 from adafruit/temp-example-fix
Temp example fix
2 parents a716040 + 2cb82fc commit 8545ed2

File tree

4 files changed

+44
-11
lines changed

4 files changed

+44
-11
lines changed

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ confidence=
5252
# no Warning level messages displayed, use"--disable=all --enable=classes
5353
# --disable=W"
5454
# disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call
55-
disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation
55+
disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation,pointless-string-statement
5656

5757
# Enable the message, report, category or checker with the given id(s). You can
5858
# either give multiple identifier separated by comma (,) or put this option

adafruit_bno055.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ def _gravity(self):
456456

457457
@property
458458
def accel_range(self):
459-
""" Switch the accelerometer range and return the new range. Default value: +/- 4g
459+
"""Switch the accelerometer range and return the new range. Default value: +/- 4g
460460
See table 3-8 in the datasheet.
461461
"""
462462
self._write_register(_PAGE_REGISTER, 0x01)
@@ -474,7 +474,7 @@ def accel_range(self, rng=ACCEL_4G):
474474

475475
@property
476476
def accel_bandwidth(self):
477-
""" Switch the accelerometer bandwidth and return the new bandwidth. Default value: 62.5 Hz
477+
"""Switch the accelerometer bandwidth and return the new bandwidth. Default value: 62.5 Hz
478478
See table 3-8 in the datasheet.
479479
"""
480480
self._write_register(_PAGE_REGISTER, 0x01)
@@ -494,7 +494,7 @@ def accel_bandwidth(self, bandwidth=ACCEL_62_5HZ):
494494

495495
@property
496496
def accel_mode(self):
497-
""" Switch the accelerometer mode and return the new mode. Default value: Normal
497+
"""Switch the accelerometer mode and return the new mode. Default value: Normal
498498
See table 3-8 in the datasheet.
499499
"""
500500
self._write_register(_PAGE_REGISTER, 0x01)
@@ -514,7 +514,7 @@ def accel_mode(self, mode=ACCEL_NORMAL_MODE):
514514

515515
@property
516516
def gyro_range(self):
517-
""" Switch the gyroscope range and return the new range. Default value: 2000 dps
517+
"""Switch the gyroscope range and return the new range. Default value: 2000 dps
518518
See table 3-9 in the datasheet.
519519
"""
520520
self._write_register(_PAGE_REGISTER, 0x01)
@@ -534,7 +534,7 @@ def gyro_range(self, rng=GYRO_2000_DPS):
534534

535535
@property
536536
def gyro_bandwidth(self):
537-
""" Switch the gyroscope bandwidth and return the new bandwidth. Default value: 32 Hz
537+
"""Switch the gyroscope bandwidth and return the new bandwidth. Default value: 32 Hz
538538
See table 3-9 in the datasheet.
539539
"""
540540
self._write_register(_PAGE_REGISTER, 0x01)
@@ -554,7 +554,7 @@ def gyro_bandwidth(self, bandwidth=GYRO_32HZ):
554554

555555
@property
556556
def gyro_mode(self):
557-
""" Switch the gyroscope mode and return the new mode. Default value: Normal
557+
"""Switch the gyroscope mode and return the new mode. Default value: Normal
558558
See table 3-9 in the datasheet.
559559
"""
560560
self._write_register(_PAGE_REGISTER, 0x01)
@@ -574,7 +574,7 @@ def gyro_mode(self, mode=GYRO_NORMAL_MODE):
574574

575575
@property
576576
def magnet_rate(self):
577-
""" Switch the magnetometer data output rate and return the new rate. Default value: 20Hz
577+
"""Switch the magnetometer data output rate and return the new rate. Default value: 20Hz
578578
See table 3-10 in the datasheet.
579579
"""
580580
self._write_register(_PAGE_REGISTER, 0x01)
@@ -594,7 +594,7 @@ def magnet_rate(self, rate=MAGNET_20HZ):
594594

595595
@property
596596
def magnet_operation_mode(self):
597-
""" Switch the magnetometer operation mode and return the new mode. Default value: Regular
597+
"""Switch the magnetometer operation mode and return the new mode. Default value: Regular
598598
See table 3-10 in the datasheet.
599599
"""
600600
self._write_register(_PAGE_REGISTER, 0x01)
@@ -614,7 +614,7 @@ def magnet_operation_mode(self, mode=MAGNET_REGULAR_MODE):
614614

615615
@property
616616
def magnet_mode(self):
617-
""" Switch the magnetometer power mode and return the new mode. Default value: Forced
617+
"""Switch the magnetometer power mode and return the new mode. Default value: Forced
618618
See table 3-10 in the datasheet.
619619
"""
620620
self._write_register(_PAGE_REGISTER, 0x01)

examples/bno055_i2c-gpio_simpletest.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,22 @@
2121
i2c = I2C(1) # Device is /dev/i2c-1
2222
sensor = adafruit_bno055.BNO055_I2C(i2c)
2323

24+
last_val = 0xFFFF
25+
26+
27+
def temperature():
28+
global last_val # pylint: disable=global-statement
29+
result = sensor.temperature
30+
if abs(result - last_val) == 128:
31+
result = sensor.temperature
32+
if abs(result - last_val) == 128:
33+
return 0b00111111 & result
34+
last_val = result
35+
return result
36+
37+
2438
while True:
25-
print("Temperature: {} degrees C".format(sensor.temperature))
39+
print("Temperature: {} degrees C".format(temperature()))
2640
print("Accelerometer (m/s^2): {}".format(sensor.acceleration))
2741
print("Magnetometer (microteslas): {}".format(sensor.magnetic))
2842
print("Gyroscope (rad/sec): {}".format(sensor.gyro))

examples/bno055_simpletest.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,27 @@
1111
# uart = busio.UART(board.TX, board.RX)
1212
# sensor = adafruit_bno055.BNO055_UART(uart)
1313

14+
last_val = 0xFFFF
15+
16+
17+
def temperature():
18+
global last_val # pylint: disable=global-statement
19+
result = sensor.temperature
20+
if abs(result - last_val) == 128:
21+
result = sensor.temperature
22+
if abs(result - last_val) == 128:
23+
return 0b00111111 & result
24+
last_val = result
25+
return result
26+
27+
1428
while True:
1529
print("Temperature: {} degrees C".format(sensor.temperature))
30+
"""
31+
print(
32+
"Temperature: {} degrees C".format(temperature())
33+
) # Uncomment if using a Raspberry Pi
34+
"""
1635
print("Accelerometer (m/s^2): {}".format(sensor.acceleration))
1736
print("Magnetometer (microteslas): {}".format(sensor.magnetic))
1837
print("Gyroscope (rad/sec): {}".format(sensor.gyro))

0 commit comments

Comments
 (0)