The Scream: Interactive Screaming Painting

Play with it! Please tell us which board you're using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
LoupRouge
 
Posts: 7
Joined: Thu Sep 30, 2021 11:04 am

The Scream: Interactive Screaming Painting

Post by LoupRouge »

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!

User avatar
dastels
 
Posts: 15608
Joined: Tue Oct 20, 2015 3:22 pm

Re: The Scream: Interactive Screaming Painting

Post by dastels »

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

User avatar
LoupRouge
 
Posts: 7
Joined: Thu Sep 30, 2021 11:04 am

Re: The Scream: Interactive Screaming Painting

Post by LoupRouge »

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.

User avatar
dastels
 
Posts: 15608
Joined: Tue Oct 20, 2015 3:22 pm

Re: The Scream: Interactive Screaming Painting

Post by dastels »

Hmm... can you post exactly the code.py that is running (trying to) on the CircuitPlayground?

Dave

User avatar
LoupRouge
 
Posts: 7
Joined: Thu Sep 30, 2021 11:04 am

Re: The Scream: Interactive Screaming Painting

Post by LoupRouge »

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)

User avatar
dastels
 
Posts: 15608
Joined: Tue Oct 20, 2015 3:22 pm

Re: The Scream: Interactive Screaming Painting

Post by dastels »

The code looks fine.

I suggest retyping the problem line

Code: Select all

head_servo = crickit.servo_1
Sometimes weird, invisible characters get in when copying.

Dave

User avatar
LoupRouge
 
Posts: 7
Joined: Thu Sep 30, 2021 11:04 am

Re: The Scream: Interactive Screaming Painting

Post by LoupRouge »

Will try this evening and update! Thanks

Locked
Please be positive and constructive with your questions and comments.

Return to “Circuit Playground Classic, Circuit Playground Express, Circuit Playground Bluefruit”