CircuitPython Example

Actual applications will most likely end up using some form of microcontroller to control the RockBLOCK. We've written a CircuitPython library to allow you to do this using an available CircuitPython board.

In this example, we'll use a Feather nRF52840 Sense to send data from the onboard sensors. You'll also need the accessory cable to attach the RockBLOCK to the Feather.

Adafruit Feather nRF52840 Sense

PRODUCT ID: 4516
The Adafruit Feather Bluefruit Sense takes our popular Feather nRF52840 Express and adds a smorgasbord of sensors...
$28.95
IN STOCK

RockBLOCK 9603 Accessory Cable

PRODUCT ID: 4529
The RockBLOCK 9603 Accessory Cable is terminated with a simple 10-pin Molex-style connector at one end and male jumper wires at the other.This accessory cable...
$4.95
IN STOCK

Wiring

Here's the wiring diagram. If you use the accessory cable, you should be able to match the colors. But it's also best to verify actual pin location on the RockBLOCK.

  • GND to GND
  • USB to 5V*
  • RX to RXD
  • TX to TXD

* in this example we will power everything via the Feather's micro USB connector (no battery).

CircuitPython Libraries

You'll need the following CircuitPython libraries installed. Make sure all of these are in your CIRCUITPY/lib folder.

  • adafruit_apds9960
  • adafruit_bus_device
  • adafruit_register
  • adafruit_bmp280
  • adafruit_lis3mdl
  • adafruit_lsm6ds
  • adafruit_rockblock
  • adafruit_sht31d

Code

The code used is included as an example in the library. Here it is:

import time
import struct
import board
import adafruit_lsm6ds
import adafruit_lis3mdl
import adafruit_apds9960.apds9960
import adafruit_sht31d
import adafruit_bmp280
import adafruit_rockblock

# RockBlock setup
uart = board.UART()
uart.baudrate = 19200
rb = adafruit_rockblock.RockBlock(uart)

# all the sensors
accelo = adafruit_lsm6ds.LSM6DS33(board.I2C())
magno = adafruit_lis3mdl.LIS3MDL(board.I2C())
prox = adafruit_apds9960.apds9960.APDS9960(board.I2C())
sht = adafruit_sht31d.SHT31D(board.I2C())
bmp = adafruit_bmp280.Adafruit_BMP280_I2C(board.I2C())

# build data
# can decode on other end with struct.unpack("<6fB5f", data)
data = struct.pack("3f", *accelo.acceleration)
data += struct.pack("3f", *magno.magnetic)
data += struct.pack("B", prox.proximity())
data += struct.pack("2f", sht.relative_humidity, sht.temperature)
data += struct.pack("3f", bmp.pressure, bmp.altitude, bmp.temperature)

# send data
rb.data_out = data
print("Talking to satellite...")
retry = 0
status = rb.satellite_transfer()
while status[0] > 8:
    time.sleep(10)
    status = rb.satellite_transfer()
    print(retry, status)
    retry += 1
print("\nDONE.")

Save that code as code.py to your CIRCUITPY folder. If you need to do a soft-reboot, you can with <CTRL>-<D> in the REPL. It will run and display the status of the attempts to send the message:

The output will show the number of attempts and the status (the numbers in parans). Just as in the simple test done before, the first number needs to be 0 for success. So it will keep trying until that happens:

Once it is successful, it will exit and is done.

If you then go to your account on the Rock Seven server and look in your Messages, you should see something like:

So what are all those numbers and letters? The next section is a brief run down. We'll go into more detail later.

Unpacking Data

For those familiar with Python's struct module, the example data can be decoded with:

Download: file
struct.unpack("<6fB5f", data)

where data is a bytes or bytearray of the raw data in the message. An easy way to create that is to use bytes.fromhex() and give it the hex text (copy pasta it) from the message.

Using the above message as an example:

Download: file
>>> import struct
>>> data = bytes.fromhex("88984cbe90267bbe50b21d41f43754c2081dac3fb40c82c2009cd2bf4110aed74188277a44b4a2d342cc86d741")
>>> struct.unpack("<6fB5f", data)
(-0.19980061054229736, -0.24526429176330566, 9.856033325195312, -53.05464172363281, 1.3446359634399414, -65.02481079101562, 0, 23.97783660888672, 26.959991455078125, 1000.61767578125, 105.81777954101562, 26.940818786621094)

And there's the data. First 3 are x/y/z acceleration from the LSM6DS33, next 3 are x/y/z magnetic from the LIS3MDL, next one is proximity from the APDS9960, then humidity and temperature from the SHT31D, and finally pressure, altitude, and temperature from the BMP280.

Much sensors. So data. Wow!

This guide was first published on Apr 08, 2020. It was last updated on Apr 08, 2020.
This page (CircuitPython Example) was last updated on Jul 14, 2020.