pycubed.py

A helper library to make it easy to access core PyCubed functionality and illustrate how to interact with the hardware.



📑 Example Usage


Calling the library

The pycubed.py library is always invoked by importing the "cubesat" object as shown below:

from pycubed import cubesat

This is usually done at the start of your main.py file (or whatever script you're writing). But it also makes it easy to interact with the board from the REPL:

>>> from pycubed import cubesat
[ERROR][SD Card] no SD card
[WARNING][RADIO #2] Failed to find rfm9x with expected version -- check wiring
>>>

However you are working with the board, you should always start with:

from pycubed import cubesat if you intend to use the pycubed.py helper library.

Checking available on-board hardware

from pycubed import cubesat
print(cubesat.hardware)

Controlling the RGB LED (aka NeoPixel)

Simple property that lets you set the color of the RGB LED using a tuple in the format of (RED,GREEN,BLUE). Values can only be 0→255. The full adafruit_neopixel library is accessible from the cubesat.neopixel object. See adafruit_neopixel→ for more details.

from pycubed import cubesat
cubesat.RGB = (0,255,0) # sets the LED to pure green
cubesat.RGB = (0,0,0) # turns the LED off
cubesat.RGB = (255,255,255) # this sets the LED to white (consuming the most power)

print(cubesat.RGB) # returns the current LED color value

cubesat.neopixel.brightness = 0.5 # sets the LED brightness. Default is 0.2, max is 1

Measuring microcontroller temperature

Returns a float of the CPU temperature in Celsius measured on-chip by the SAMD51

from pycubed import cubesat
temp = cubesat.micro.cpu.temperature # returns the temperature in celcius for the SAMD51

Reading IMU data

The IMU is capable of many other functions as well.
See See BMX160 datasheet for more details:
🗄Component Datasheets

Temperature

Returns a float of the temperature in Celsius measured by the BMX160 IMU

from pycubed import cubesat
temp = cubesat.temperature # Celsius

Acceleration

Returns a 3-tuple with (X,Y,Z) acceleration values (m/s^2) from the BMX160

from pycubed import cubesat

x_accel, y_accel, z_accel = cubesat.acceleration # m/s^2

Magnetometer

Returns a 3-tuple with (X,Y,Z) magnetometer values (gauss) from the BMX160

from pycubed import cubesat

x_mag, y_mag, z_mag = cubesat.magnetic # uT

Gyroscope

Returns a 3-tuple with (X,Y,Z) gyroscope values (degrees/second) from the BMX160

from pycubed import cubesat

x_gyro, y_gyro, z_gyro = cubesat.gyro # degrees/second

Measuring battery voltage

Returns a float of the battery voltage in volts. Measured with the SAMD51 16-bit ADC using a 316/110 voltage divider

from pycubed import cubesat
vbatt = cubesat.battery_voltage

Measuring battery charge current (Solar)

Returns a float of the charge current in mA. Measured with the SAMD51 16-bit ADC of the "L1 Prog" analog output from the LTC4121 energy harvesting circuit. See ☀️PyCubed Energy Harvesting and LTC4121 datasheet for more details: 🗄Component Datasheets

from pycubed import cubesat
ichrg = cubesat.charge_current

Measuring system voltage

Returns a float of the system voltage right before the main 3.3V regulator. Value returned from the ADM1176 power-monitoring IC over I2C. See ADM1176 datasheet for more details: 🗄Component Datasheets, and CircuitPython_ADM1176 library.

from pycubed import cubesat
vsys = cubesat.system_voltage

Measuring system current draw

Returns a float of the system current flowing into the main 3.3V regulator. Value returned from the ADM1176 power-monitoring IC over I2C. See ADM1176 datasheet for more details: 🗄Component Datasheets, and CircuitPython_ADM1176 library.

from pycubed import cubesat
isys = cubesat.current_draw

Controlling the burn wires

The specific burn wire parameters need to be tuned to the specific system. This burn wire parameters are to configured by directly editing the pycubed.py text file. See 🔥PyCubed Burn Wire Info & Usage for more details.

Accessing the SD card

See 💾Selecting an SD card for details on which cards to use, and 📂SD Card for code examples.

Controlling USB charging

USB charging is disabled by default when the pycubed.py library is invoked.

Checking charging state

from pycubed import cubesat
print(cubesat.charge_batteries)

Enable/disable charging

from pycubed import cubesat
# enable charging (green LED will blink if no battery detected)
cubesat.charge_batteries=True
# disable charging 
cubesat.charge_batteries=False

Set charging current

See BQ25883 datasheet 🗄Component Datasheets section 8.5.2 for more details.

from pycubed import cubesat
cubesat.usb.charging_current=8 #400mA

Controlling Radio(s)

See Example Flight Software for an introduction to using the radio and the advanced example for common usage patterns. See 📁Radio for coding examples.

Controlling GPS

See 📁GPS example for a demo using a commercial GPS module.

Accessing PyCubed status bytes

See 📋PyCubed NVM Bit Map & Usage for more details.

Reading the boot counter

from pycubed import cubesat

bootcnt = cubesat.boot_count

Resetting the boot counter

⚠CAUTION - this can't be undone.

from pycubed import cubesat

# set the boot_count status byte to 0
cubesat.reset_boot_count

📚 pycubed.py code


Latest library code can always be found in its repo: https://github.com/pycubed/library_pycubed.py