0

“Sound” motor control @adafruit with CRICKIT #CRICKIT

“Sound” motor control (video). The demo is how to control the speed of a motor with sound using the microphone sensor on CircuitPlayground & CRICKIT. To everything (turn, turn, turn). Code & guide. Crickit – A Creative Robotics & Interactive Construction Kit. It’s an add-on to our popular Circuit Playground Express that lets you #MakeRobotFriend using CircuitPython, MakeCode, Arduino, etc.. robotics, arts, crafts, audio animatronics, sensors, agriculture/robot farming, physical computing, kinetic sculptures, science experiments, telescope control…

The Crickit is powered by seesaw, an I2C-to-whatever bridge firmware. So you only need to use two data pins to control the huge number of inputs and outputs on the Crickit. All those timers, PWMs, sensors are offloaded to the co-processor.

https://www.adafruit.com/crickit & video playlist.

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
46
47
48
49
50
51
52
from busio import I2C
from adafruit_seesaw.seesaw import Seesaw
from adafruit_seesaw.pwmout import PWMOut
from adafruit_motor import motor
import audiobusio
import time
import board
import array
import math
 
print("Sound sensor motor!")
 
# Create seesaw object
i2c = I2C(board.SCL, board.SDA)
seesaw = Seesaw(i2c)
 
# Create one motor on seesaw PWM pins 22 & 23
motor_a = motor.DCMotor(PWMOut(seesaw, 22), PWMOut(seesaw, 23))
motor_a.throttle = 0 # motor is stopped
 
 
##################### helpers
 
# Maps a number from one range to another.
def map_range(x, in_min, in_max, out_min, out_max):
    mapped = (x-in_min) * (out_max - out_min) / (in_max-in_min) + out_min
    if out_min <= out_max:
        return max(min(mapped, out_max), out_min)
    return min(max(mapped, out_max), out_min)
 
# Returns the average
def mean(values):
    return sum(values) / len(values)
 
# Audio root-mean-square
def normalized_rms(values):
    minbuf = int(mean(values))
    return math.sqrt(sum(float(sample-minbuf)*(sample-minbuf) for sample in values) / len(values))
 
 
# Our microphone
mic = audiobusio.PDMIn(board.MICROPHONE_CLOCK, board.MICROPHONE_DATA,
		       sample_rate=16000, bit_depth = 16)
samples = array.array('H', [0] * 200)
mic.record(samples, len(samples))
 
while True:
    mic.record(samples, len(samples))
    magnitude = normalized_rms(samples)
    print(((magnitude),))
    motor_a.throttle = map_range(magnitude, 90, 200, 0, 1.0)
    time.sleep(0.1)

Join 6,000+ makers on Adafruit’s Discord channels and be part of the community! http://adafru.it/discord

CircuitPython in 2018 – Python on Microcontrollers is here!

Have an amazing project to share? Join the SHOW-AND-TELL every Wednesday night at 7:30pm ET on Google+ Hangouts.

Join us every Wednesday night at 8pm ET for Ask an Engineer!

Follow Adafruit on Instagram for top secret new products, behinds the scenes and more https://www.instagram.com/adafruit/


Maker Business — Aquarium troubles: the cost of iteration and troubleshooting with a manufacturers abroad

Wearables — Plastic gem know-how

Electronics — Counting Pin Numbers

Biohacking — Exploring Our Inner Reality : Entopic Visions

Python for Microcontrollers — CircuitPython 3.0.0 Release Candidate 0 released!

Get the only spam-free daily newsletter about wearables, running a "maker business", electronic tips and more! Subscribe at AdafruitDaily.com !



No Comments

No comments yet.

Sorry, the comment form is closed at this time.