Skip to content

CircuitPython library for onboard battery management and sensors for Seeed XIAO nRF52840 (Sense)

License

Notifications You must be signed in to change notification settings

furbrain/CircuitPython_seeed_xiao_nRF52840

Repository files navigation

Introduction

Discord Build Status Code Style: Black

Provides access to onboard sensors and battery charge management circuitry

Dependencies

This driver depends on:

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle or individual libraries can be installed using circup.

Installing to a Connected CircuitPython Device with Circup

Make sure that you have circup installed in your Python environment. Install it with the following command if necessary:

pip3 install circup

With circup installed and your CircuitPython device connected use the following command to install:

circup install seeed_xiao_nrf52840

Or the following command to update an existing version:

circup update

Usage Example

import array
import time

import audiocore
import audiopwmio
import board

from seeed_xiao_nrf52840 import IMU, Mic, Battery

with Battery() as bat:
    print(f"Charge_status: {bat.charge_status}")
    print(f"Voltage: {bat.voltage}")
    print(f"Charge_current high?: {bat.charge_current}")
    print("Setting charge current to high")
    bat.charge_current = bat.CHARGE_100MA
    print(f"Charge_current high?: {bat.charge_current}")

with IMU() as imu:
    for i in range(5):
        print("Acceleration:", imu.acceleration)
        time.sleep(1)

with Mic() as mic:
    for i in range(5):
        print(f"Start speaking in: {5-i}")
        time.sleep(1)
    b = array.array("H")
    for i in range(8000):
        b.append(0)
    print("SPEAK!!!")
    mic.record(b, len(b))
    print(b)
    for i in range(5):
        print(f"Replaying in: {5-i}")
        time.sleep(1)
    with audiopwmio.PWMAudioOut(board.D0) as aud:
        print("PWM setup")
        sample = audiocore.RawSample(b, sample_rate=8000)
        print("sample ready")
        aud.play(sample,loop=True)
        print("playing")
        time.sleep(5)
        aud.stop()

Documentation

API documentation for this library can be found on Read the Docs.

For information on building library documentation, please check out this guide.

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

About

CircuitPython library for onboard battery management and sensors for Seeed XIAO nRF52840 (Sense)

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages