Hello people of the code!
So I am trying to build The Scream: Interactive Screaming Painting. I am not good at coding but can figure out minor things. I have downloaded everything (i think), have the most up to date library for CircuitPython 7.x and have copy and pasted the code into Mu. I have tried a lot of things to no avail.
I keep getting this error:
File "code.py", line 32, in <module>
NameError: name 'crickit' is not defined
I have not been able to get any sound or movement from everything connected. Please help!
thanks!
The Scream: Interactive Screaming Painting
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- dastels
- Posts: 15653
- Joined: Tue Oct 20, 2015 3:22 pm
Re: The Scream: Interactive Screaming Painting
What board are you using? CircuitPlayground Express? If so, you'll need the "Circuit Playground Express + Crickit" build at https://circuitpython.org/board/circuit ... s_crickit/.
Dave
Dave
- LoupRouge
- Posts: 7
- Joined: Thu Sep 30, 2021 11:04 am
Re: The Scream: Interactive Screaming Painting
Hey Dave! Thanks for the reply! That is the build that i am using, I've tried both 7.0 and the unstable 7.1. I even upgraded the crickit seesaw.
- dastels
- Posts: 15653
- Joined: Tue Oct 20, 2015 3:22 pm
Re: The Scream: Interactive Screaming Painting
Hmm... can you post exactly the code.py that is running (trying to) on the CircuitPlayground?
Dave
Dave
- LoupRouge
- Posts: 7
- Joined: Thu Sep 30, 2021 11:04 am
Re: The Scream: Interactive Screaming Painting
Here is the code:
Code: Select all
import time
import math
import array
import audiobusio
import audioio
import audiocore
import board
from adafruit_crickit import crickit
# Number of samples to read at once.
NUM_SAMPLES = 160
# Remove DC bias before computing RMS.
def normalized_rms(values):
minbuf = int(mean(values))
samples_sum = sum(
float(sample - minbuf) * (sample - minbuf)
for sample in values
)
return math.sqrt(samples_sum / len(values))
def mean(values):
return sum(values) / len(values)
mic = audiobusio.PDMIn(board.MICROPHONE_CLOCK, board.MICROPHONE_DATA,
sample_rate=16000, bit_depth=16)
# Record an initial sample to calibrate. Assume it's quiet when we start.
samples = array.array('H', [0] * NUM_SAMPLES)
mic.record(samples, len(samples))
head_servo = crickit.servo_1
head_servo.set_pulse_width_range(min_pulse=500, max_pulse=2500)
head_servo.angle = 90 # center the head.
# Set audio out on speaker.
a = audioio.AudioOut(board.A0)
# Start playing the file (in the background).
def play_file(wavfile):
print("Playing scream!")
with open(wavfile, "rb") as f:
wav = audiocore.WaveFile(f)
a.play(wav)
while a.playing:
head_servo.angle = 60
time.sleep(.01)
head_servo.angle = 120
time.sleep(.01)
while True:
mic.record(samples, len(samples))
magnitude = normalized_rms(samples)
print(((magnitude),)) # formatting is for the Mu plotter.
if magnitude < 1000: # it's quiet, do nothing.
pass
else:
print("LOUD")
head_servo.angle = 60
time.sleep(.05)
head_servo.angle = 120
time.sleep(.05)
head_servo.angle = 90
time.sleep(.02)
play_file("scream_low.wav")
head_servo.angle = 90
time.sleep(2)
- dastels
- Posts: 15653
- Joined: Tue Oct 20, 2015 3:22 pm
Re: The Scream: Interactive Screaming Painting
The code looks fine.
I suggest retyping the problem line
Sometimes weird, invisible characters get in when copying.
Dave
I suggest retyping the problem line
Code: Select all
head_servo = crickit.servo_1
Dave
- LoupRouge
- Posts: 7
- Joined: Thu Sep 30, 2021 11:04 am
Re: The Scream: Interactive Screaming Painting
Will try this evening and update! Thanks
Please be positive and constructive with your questions and comments.