The Circuit Playground Bluefruit has a built in light sensor that returns a light value and a temperature sensor that returns the temperature in degrees Celsius. The Adafruit Bluefruit LE Connect mobile app has a built in plotter function that you can use to plot any numerical information. This page will show you how to plot the light and temperature data from the Circuit Playground Bluefruit in the Bluefruit LE Connect app!

Installing Project Code

To use with CircuitPython, you need to first install a few libraries, into the lib folder on your CIRCUITPY drive. Then you need to update code.py with the example script.

Thankfully, we can do this in one go. In the example below, click the Download Project Bundle button below to download the necessary libraries and the code.py file in a zip file. Extract the contents of the zip file, open the directory examples/ and then click on the directory that matches the version of CircuitPython you're using and copy the contents of that directory to your CIRCUITPY drive.

Your CIRCUITPY drive should now look similar to the following image:

CIRCUITPY
# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

# CircuitPython Bluefruit LE Connect Plotter Example

import time
import board
import analogio
import adafruit_thermistor
from adafruit_ble import BLERadio
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
from adafruit_ble.services.nordic import UARTService

ble = BLERadio()
uart_server = UARTService()
advertisement = ProvideServicesAdvertisement(uart_server)

thermistor = adafruit_thermistor.Thermistor(board.TEMPERATURE, 10000, 10000, 25, 3950)
light = analogio.AnalogIn(board.LIGHT)


def scale(value):
    """Scale the light sensor values from 0-65535 (AnalogIn range)
    to 0-50 (arbitrarily chosen to plot well with temperature)"""
    return value / 65535 * 50


while True:
    # Advertise when not connected.
    ble.start_advertising(advertisement)
    while not ble.connected:
        pass
    ble.stop_advertising()

    while ble.connected:
        print((scale(light.value), thermistor.temperature))
        uart_server.write("{},{}\n".format(scale(light.value), thermistor.temperature))
        time.sleep(0.1)

Connect to your board through the Adafruit Bluefruit LE Connect mobile app. If you need assistance, check out the Bluefruit LE Connect Basics page in the Getting Started guide.

Once connected, tap Plotter.

Your data should start plotting automatically. Try shining a light towards your Circuit Playground Bluefruit to see the light value line change. Try placing your finger over the thermistor (towards the top-right, labeled A9, next to the picture of a thermometer) to see the temperature value line change.

That's all there is to plotting numerical data with the Circuit Playground Bluefruit and the Adafruit Bluefruit LE Connect mobile app!

This guide was first published on Sep 12, 2019. It was last updated on Jul 18, 2024.

This page (Playground Bluetooth Plotter) was last updated on Jul 18, 2024.

Text editor powered by tinymce.