-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCPB_BLEplotter.py
More file actions
45 lines (34 loc) · 1.43 KB
/
CPB_BLEplotter.py
File metadata and controls
45 lines (34 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# CircuitPython Bluefruit LE Connect Plotter Example
# Adafruit bluetooth plotter tutorial
# https://learn.adafruit.com/adafruit-circuit-playground-bluefruit/playground-bluetooth-plotter
# Dr Gallaugher's CPB Tutorials
# https://www.youtube.com/playlist?list=PL9VJ9OpT-IPSsQUWqQcNrVJqy4LhBjPX2
# Materials
# Circuit Playground Bluefruit https://www.adafruit.com/product/4333
# USB A to Micro B data cable https://www.adafruit.com/product/592
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)