Skip to content

Commit ad77865

Browse files
authored
Merge pull request #4 from caternuson/feather_sense
Some fixes and new example
2 parents b806634 + cc8e59e commit ad77865

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

adafruit_rockblock.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
4343
"""
4444

45+
import time
4546
import struct
4647

4748
__version__ = "0.0.0-auto.0"
@@ -107,15 +108,19 @@ def data_out(self, buf):
107108
resp = int(line)
108109
if resp != 0:
109110
raise RuntimeError("Write error", resp)
111+
# seems to want some time to digest
112+
time.sleep(0.1)
110113
self._buf_out = buf
111114

112115
@property
113116
def text_out(self):
114117
"""The text in the outbound buffer."""
115118
text = None
119+
# TODO: add better check for non-text in buffer
120+
# pylint: disable=broad-except
116121
try:
117122
text = self._buf_out.decode()
118-
except UnicodeDecodeError:
123+
except Exception:
119124
pass
120125
return text
121126

@@ -170,7 +175,7 @@ def satellite_transfer(self, location=None):
170175
else:
171176
resp = self._uart_xfer("+SBDIX")
172177
if resp[-1].strip().decode() == "OK":
173-
status = resp[1].strip().decode().split(":")[1]
178+
status = resp[-3].strip().decode().split(":")[1]
174179
status = [int(s) for s in status.split(",")]
175180
if status[0] <= 8:
176181
# outgoing message sent successfully

examples/feather_sense_sensors.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import time
2+
import struct
3+
import board
4+
import adafruit_lsm6ds
5+
import adafruit_lis3mdl
6+
import adafruit_apds9960.apds9960
7+
import adafruit_sht31d
8+
import adafruit_bmp280
9+
import adafruit_rockblock
10+
11+
# RockBlock setup
12+
uart = board.UART()
13+
uart.baudrate = 19200
14+
rb = adafruit_rockblock.RockBlock(uart)
15+
16+
# all the sensors
17+
accelo = adafruit_lsm6ds.LSM6DS33(board.I2C())
18+
magno = adafruit_lis3mdl.LIS3MDL(board.I2C())
19+
prox = adafruit_apds9960.apds9960.APDS9960(board.I2C())
20+
sht = adafruit_sht31d.SHT31D(board.I2C())
21+
bmp = adafruit_bmp280.Adafruit_BMP280_I2C(board.I2C())
22+
23+
# build data
24+
# can decode on other end with struct.unpack("<6fB5f", data)
25+
data = struct.pack("3f", *accelo.acceleration)
26+
data += struct.pack("3f", *magno.magnetic)
27+
data += struct.pack("B", prox.proximity())
28+
data += struct.pack("2f", sht.relative_humidity, sht.temperature)
29+
data += struct.pack("3f", bmp.pressure, bmp.altitude, bmp.temperature)
30+
31+
# send data
32+
rb.data_out = data
33+
print("Talking to satellite...")
34+
retry = 0
35+
status = rb.satellite_transfer()
36+
while status[0] > 8:
37+
time.sleep(10)
38+
status = rb.satellite_transfer()
39+
print(retry, status)
40+
retry += 1
41+
print("\nDONE.")

0 commit comments

Comments
 (0)