Skip to content

Commit 5273871

Browse files
authored
Merge branch 'master' into action
2 parents 05d76f6 + 2aff72d commit 5273871

File tree

83 files changed

+158869
-119
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+158869
-119
lines changed

Activity_Generator/code.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""ACTIVITY GENERATOR for Adafruit CLUE"""
2+
3+
import time
4+
import random
5+
from adafruit_clue import clue
6+
from things import activities
7+
from things import subjects
8+
9+
screen = clue.simple_text_display(text_scale=4, colors=(clue.WHITE,))
10+
11+
screen[1].text = "ACTIVITY"
12+
screen[2].text = "GENERATOR"
13+
screen.show()
14+
time.sleep(1.5)
15+
16+
screen[0].text = "make a"
17+
screen[2].text = "about"
18+
screen[1].color = clue.RED
19+
screen[3].color = clue.GREEN
20+
screen[4].color = clue.BLUE
21+
22+
activity = "???"
23+
subject_a = "???"
24+
subject_b = "???"
25+
two_subjects = True
26+
27+
def random_pick(items):
28+
index = random.randint(0, len(items)-1)
29+
return items[index]
30+
31+
while True:
32+
33+
if clue.button_a:
34+
activity = random_pick(activities)
35+
subject_a = random_pick(subjects)
36+
subject_b = random_pick(subjects)
37+
time.sleep(0.25)
38+
if clue.button_b:
39+
two_subjects = not two_subjects
40+
time.sleep(0.5)
41+
42+
screen[1].text = activity
43+
screen[3].text = subject_a
44+
45+
if two_subjects:
46+
screen[4].text = subject_b
47+
else:
48+
screen[4].text = ""
49+
50+
screen.show()

Activity_Generator/things.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
activities = [
2+
"DRAWING",
3+
"SONG",
4+
"STORY",
5+
"VIDEO",
6+
]
7+
8+
subjects = [
9+
"COMPUTER",
10+
"ALIEN",
11+
"LASER",
12+
"FOOD",
13+
"TREE",
14+
"DREAM",
15+
"WEATHER",
16+
"DOG",
17+
"CAT",
18+
"BIRD",
19+
"HORSE",
20+
"BLANKET",
21+
"TIME",
22+
"PLANT",
23+
"LEAF",
24+
"EAR",
25+
"HAND",
26+
"FEET",
27+
"TEETH",
28+
"PHONE",
29+
"SPACE",
30+
"ROBOT",
31+
"GHOST",
32+
"FUTURE",
33+
"PROBLEM",
34+
"MUSIC",
35+
"NOISE",
36+
"METAL",
37+
"ROCK",
38+
"AIR",
39+
"HOPE",
40+
"FEAR",
41+
"LOVE",
42+
"DANGER",
43+
"COOKIE",
44+
"BREAD",
45+
"WATER",
46+
"HAT",
47+
"ROUND",
48+
"SQUARE",
49+
"SUCCESS",
50+
"LIGHT",
51+
"RUNNING",
52+
"TALKING",
53+
"SLEEPING",
54+
"FLYING",
55+
"SINGING",
56+
"ACTING",
57+
]
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""Sensor demo for Adafruit Feather Sense. Prints data from each of the sensors."""
2+
import time
3+
import array
4+
import math
5+
import board
6+
import audiobusio
7+
import adafruit_apds9960.apds9960
8+
import adafruit_bmp280
9+
import adafruit_lis3mdl
10+
import adafruit_lsm6ds
11+
import adafruit_sht31d
12+
13+
i2c = board.I2C()
14+
15+
apds9960 = adafruit_apds9960.apds9960.APDS9960(i2c)
16+
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)
17+
lis3mdl = adafruit_lis3mdl.LIS3MDL(i2c)
18+
lsm6ds33 = adafruit_lsm6ds.LSM6DS33(i2c)
19+
sht31d = adafruit_sht31d.SHT31D(i2c)
20+
microphone = audiobusio.PDMIn(board.MICROPHONE_CLOCK, board.MICROPHONE_DATA,
21+
sample_rate=16000, bit_depth=16)
22+
23+
def normalized_rms(values):
24+
minbuf = int(sum(values) / len(values))
25+
return int(math.sqrt(sum(float(sample - minbuf) *
26+
(sample - minbuf) for sample in values) / len(values)))
27+
28+
apds9960.enable_proximity = True
29+
apds9960.enable_color = True
30+
31+
# Set this to sea level pressure in hectoPascals at your location for accurate altitude reading.
32+
bmp280.sea_level_pressure = 1013.25
33+
34+
while True:
35+
samples = array.array('H', [0] * 160)
36+
microphone.record(samples, len(samples))
37+
38+
print("\nFeather Sense Sensor Demo")
39+
print("---------------------------------------------")
40+
print("Proximity:", apds9960.proximity)
41+
print("Red: {}, Green: {}, Blue: {}, Clear: {}".format(*apds9960.color_data))
42+
print("Temperature: {:.1f} C".format(bmp280.temperature))
43+
print("Barometric pressure:", bmp280.pressure)
44+
print("Altitude: {:.1f} m".format(bmp280.altitude))
45+
print("Magnetic: {:.3f} {:.3f} {:.3f} uTesla".format(*lis3mdl.magnetic))
46+
print("Acceleration: {:.2f} {:.2f} {:.2f} m/s^2".format(*lsm6ds33.acceleration))
47+
print("Gyro: {:.2f} {:.2f} {:.2f} dps".format(*lsm6ds33.gyro))
48+
print("Humidity: {:.1f} %".format(sht31d.relative_humidity))
49+
print("Sound level:", normalized_rms(samples))
50+
time.sleep(0.3)

BLE_Heart_Rate_Trainer/ble_heart_rate_trainer.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@
3535
# Seven Segment FeatherWing setup
3636
i2c = board.I2C()
3737
display_A = Seg7x4(i2c, address=0x70) # this will be the BPM display
38-
display_A.brightness = 15
3938
display_A.fill(0) # Clear the display
4039
# Second display has A0 address jumpered
4140
display_B = Seg7x4(i2c, address=0x71) # this will be the % target display
42-
display_B.brightness = 15
4341
display_B.fill(0) # Clear the display
4442

4543
# display_A "b.P.M."

BLE_Sensornet/clue_sensornet.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""This uses the CLUE as a Bluetooth LE sensor node."""
2+
3+
import time
4+
from adafruit_clue import clue
5+
import adafruit_ble_broadcastnet
6+
7+
print("This is BroadcastNet CLUE sensor:", adafruit_ble_broadcastnet.device_address)
8+
9+
while True:
10+
measurement = adafruit_ble_broadcastnet.AdafruitSensorMeasurement()
11+
12+
measurement.temperature = clue.temperature
13+
measurement.pressure = clue.pressure
14+
measurement.relative_humidity = clue.humidity
15+
measurement.acceleration = clue.acceleration
16+
measurement.magnetic = clue.magnetic
17+
18+
print(measurement)
19+
adafruit_ble_broadcastnet.broadcast(measurement)
20+
time.sleep(60)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""This uses the Feather Sense as a Bluetooth LE sensor node."""
2+
3+
import time
4+
import adafruit_ble_broadcastnet
5+
import board
6+
import adafruit_lsm6ds # accelerometer
7+
import adafruit_sht31d # humidity sensor
8+
import adafruit_bmp280 # barometric sensor
9+
import adafruit_lis3mdl # magnetic sensor
10+
11+
i2c = board.I2C()
12+
13+
sense_accel = adafruit_lsm6ds.LSM6DS33(i2c)
14+
sense_humid = adafruit_sht31d.SHT31D(i2c)
15+
sense_barometric = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)
16+
sense_magnet = adafruit_lis3mdl.LIS3MDL(i2c)
17+
18+
print("This is BroadcastNet Feather Sense sensor:", adafruit_ble_broadcastnet.device_address)
19+
20+
while True:
21+
measurement = adafruit_ble_broadcastnet.AdafruitSensorMeasurement()
22+
23+
measurement.temperature = sense_barometric.temperature
24+
measurement.pressure = sense_barometric.pressure
25+
measurement.relative_humidity = sense_humid.relative_humidity
26+
measurement.acceleration = sense_accel.acceleration
27+
measurement.magnetic = sense_magnet.magnetic
28+
29+
# print(measurement)
30+
adafruit_ble_broadcastnet.broadcast(measurement)
31+
time.sleep(60)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import time
2+
import board
3+
import digitalio
4+
import analogio
5+
from adafruit_clue import clue
6+
7+
# Turn off the NeoPixel
8+
clue.pixel.fill(0)
9+
10+
# Motor setup
11+
motor = digitalio.DigitalInOut(board.P2)
12+
motor.direction = digitalio.Direction.OUTPUT
13+
14+
# Soil sense setup
15+
analog = analogio.AnalogIn(board.P1)
16+
17+
def read_and_average(analog_in, times, wait):
18+
analog_sum = 0
19+
for _ in range(times):
20+
analog_sum += analog_in.value
21+
time.sleep(wait)
22+
return analog_sum / times
23+
24+
clue_display = clue.simple_text_display(title=" CLUE Plant", title_scale=1, text_scale=3)
25+
clue_display.show()
26+
27+
while True:
28+
# Take 100 readings and average them
29+
analog_value = read_and_average(analog, 100, 0.01)
30+
# Calculate a percentage (analog_value ranges from 0 to 65535)
31+
percentage = analog_value / 65535 * 100
32+
# Display the percentage
33+
clue_display[0].text = "Soil: {} %".format(int(percentage))
34+
# Print the values to the serial console
35+
print((analog_value, percentage))
36+
37+
if percentage < 50:
38+
motor.value = True
39+
clue_display[1].text = "Motor ON"
40+
clue_display[1].color = (0, 255, 0)
41+
time.sleep(0.5)
42+
43+
# always turn off quickly
44+
motor.value = False
45+
clue_display[1].text = "Motor OFF"
46+
clue_display[1].color = (255, 0, 0)
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Bonsai Buckaroo + CLUE Plant Care Bot
2+
3+
import time
4+
import board
5+
from digitalio import DigitalInOut, Direction
6+
from analogio import AnalogIn
7+
from adafruit_clue import clue
8+
from adafruit_display_text import label
9+
import displayio
10+
import terminalio
11+
import pulseio
12+
13+
moist_level = 50 # adjust this value as needed for your plant
14+
15+
board.DISPLAY.brightness = 0.8
16+
clue.pixel.fill(0) # turn off NeoPixel
17+
18+
clue_display = displayio.Group(max_size=4)
19+
20+
# draw the dry plant
21+
dry_plant_file = open("dry.bmp", "rb")
22+
dry_plant_bmp = displayio.OnDiskBitmap(dry_plant_file)
23+
dry_plant_sprite = displayio.TileGrid(dry_plant_bmp, pixel_shader=displayio.ColorConverter())
24+
clue_display.append(dry_plant_sprite)
25+
26+
# draw the happy plant on top (so it can be moved out of the way when needed)
27+
happy_plant_file = open("happy.bmp", "rb")
28+
happy_plant_bmp = displayio.OnDiskBitmap(happy_plant_file)
29+
happy_plant_sprite = displayio.TileGrid(happy_plant_bmp, pixel_shader=displayio.ColorConverter())
30+
clue_display.append(happy_plant_sprite)
31+
32+
# Create text
33+
# first create the group
34+
text_group = displayio.Group(max_size=3, scale=3)
35+
# Make a label
36+
title_label = label.Label(terminalio.FONT, text="CLUE Plant", color=0x00FF22)
37+
# Position the label
38+
title_label.x = 10
39+
title_label.y = 4
40+
# Append label to group
41+
text_group.append(title_label)
42+
43+
soil_label = label.Label(terminalio.FONT, text="Soil: ", color=0xFFAA88, max_glyphs=10)
44+
soil_label.x = 4
45+
soil_label.y = 64
46+
text_group.append(soil_label)
47+
48+
motor_label = label.Label(terminalio.FONT, text="Motor off", color=0xFF0000, max_glyphs=9)
49+
motor_label.x = 4
50+
motor_label.y = 74
51+
text_group.append(motor_label)
52+
53+
clue_display.append(text_group)
54+
board.DISPLAY.show(clue_display)
55+
56+
motor = DigitalInOut(board.P2)
57+
motor.direction = Direction.OUTPUT
58+
59+
buzzer = pulseio.PWMOut(board.SPEAKER, variable_frequency=True)
60+
buzzer.frequency = 1000
61+
62+
sense_pin = board.P1
63+
analog = AnalogIn(board.P1)
64+
65+
def read_and_average(ain, times, wait):
66+
asum = 0
67+
for _ in range(times):
68+
asum += ain.value
69+
time.sleep(wait)
70+
return asum / times
71+
72+
time.sleep(5)
73+
74+
while True:
75+
# take 100 readings and average them
76+
aval = read_and_average(analog, 100, 0.01)
77+
# calculate a percentage (aval ranges from 0 to 65535)
78+
aperc = aval / 65535 * 100
79+
# display the percentage
80+
soil_label.text = "Soil: {} %".format(int(aperc))
81+
print((aval, aperc))
82+
83+
if aperc < moist_level:
84+
happy_plant_sprite.x = 300 # move the happy sprite away
85+
time.sleep(1)
86+
motor.value = True
87+
motor_label.text = "Motor ON"
88+
motor_label.color = 0x00FF00
89+
buzzer.duty_cycle = 2**15
90+
time.sleep(0.5)
91+
92+
# always turn off quickly
93+
motor.value = False
94+
motor_label.text = "Motor off"
95+
motor_label.color = 0xFF0000
96+
buzzer.duty_cycle = 0
97+
98+
if aperc >= moist_level:
99+
happy_plant_sprite.x = 0 # bring back the happy sprite

Buckaroo_Plant_Care_Bot/dry.bmp

113 KB
Binary file not shown.

Buckaroo_Plant_Care_Bot/happy.bmp

113 KB
Binary file not shown.

0 commit comments

Comments
 (0)