adafruit_circuitplayground.circuit_playground_base

CircuitPython base class for Circuit Playground.

class adafruit_circuitplayground.circuit_playground_base.CircuitPlaygroundBase[source]

Circuit Playground base class.

acceleration

Obtain data from the x, y and z axes.

Accelerometer

This example prints the values. Try moving the board to see how the printed values change.

To use with the Circuit Playground Express or Bluefruit:

from adafruit_circuitplayground import cp

while True:
    x, y, z = cp.acceleration
    print(x, y, z)
adjust_touch_threshold(adjustment)[source]

Adjust the threshold needed to activate the capacitive touch pads. Higher numbers make the touch pads less sensitive.

Parameters:adjustment (int) – The desired threshold increase
Capacitive touch pads

To use with the Circuit Playground Express or Bluefruit:

from adafruit_circuitplayground import cp

cp.adjust_touch_threshold(200)

while True:
    if cp.touch_A1:
        print('Touched pad A1')
button_a

True when Button A is pressed. False if not.

Button A

To use with the Circuit Playground Express or Bluefruit:

from adafruit_circuitplayground import cp

while True:
    if cp.button_a:
        print("Button A pressed!")
button_b

True when Button B is pressed. False if not.

Button B

To use with the Circuit Playground Express or Bluefruit:

from adafruit_circuitplayground import cp

while True:
    if cp.button_b:
        print("Button B pressed!")
detect_taps

Configure what type of tap is detected by cp.tapped. Use 1 for single-tap detection and 2 for double-tap detection. This does nothing without cp.tapped.

Accelerometer

To use with the Circuit Playground Express or Bluefruit:

from adafruit_circuitplayground import cp

cp.detect_taps = 1
while True:
  if cp.tapped:
    print("Single tap detected!")
light

The light level.

Light sensor

Try covering the sensor next to the eye to see it change.

To use with the Circuit Playground Express or Bluefruit:

from adafruit_circuitplayground import cp
import time

while True:
    print("Light:", cp.light)
    time.sleep(1)
pixels

Sequence-like object representing the ten NeoPixels around the outside of the Circuit Playground. Each pixel is at a certain index in the sequence as labeled below. Colors can be RGB hex like 0x110000 for red where each two digits are a color (0xRRGGBB) or a tuple like (17, 0, 0) where (R, G, B). Set the global brightness using any number from 0 to 1 to represent a percentage, i.e. 0.3 sets global brightness to 30%.

See neopixel.NeoPixel for more info.

NeoPixel order diagram

Here is an example that sets the first pixel green and the ninth red.

To use with the Circuit Playground Express or Bluefruit:

from adafruit_circuitplayground import cp

cp.pixels.brightness = 0.3
cp.pixels[0] = 0x00FF00
cp.pixels[9] = (255, 0, 0)
play_file(file_name)[source]

Play a .wav file using the onboard speaker.

Parameters:file_name – The name of your .wav file in quotation marks including .wav
Onboard speaker

To use with the Circuit Playground Express or Bluefruit:

from adafruit_circuitplayground import cp

while True:
    if cp.button_a:
        cp.play_file("laugh.wav")
    elif cp.button_b:
        cp.play_file("rimshot.wav")
play_tone(frequency, duration)[source]

Produce a tone using the speaker. Try changing frequency to change the pitch of the tone.

Parameters:
  • frequency (int) – The frequency of the tone in Hz
  • duration (float) – The duration of the tone in seconds
Onboard speaker

To use with the Circuit Playground Express or Bluefruit:

from adafruit_circuitplayground import cp

cp.play_tone(440, 1)
red_led

The red led next to the USB plug marked D13.

D13 LED

To use with the Circuit Playground Express or Bluefruit:

from adafruit_circuitplayground import cp
import time

while True:
    cp.red_led = True
    time.sleep(0.5)
    cp.red_led = False
    time.sleep(0.5)
shake(shake_threshold=30)[source]

Detect when device is shaken.

Parameters:shake_threshold (int) – The threshold shake must exceed to return true (Default: 30)
Accelerometer

To use with the Circuit Playground Express or Bluefruit:

from adafruit_circuitplayground import cp

while True:
    if cp.shake():
        print("Shake detected!")

Decreasing shake_threshold increases shake sensitivity, i.e. the code will return a shake detected more easily with a lower shake_threshold. Increasing it causes the opposite. shake_threshold requires a minimum value of 10 - 10 is the value when the board is not moving, therefore anything less than 10 will erroneously report a constant shake detected.

from adafruit_circuitplayground import cp

while True:
    if cp.shake(shake_threshold=20):
        print("Shake detected more easily than before!")
start_tone(frequency)[source]

Produce a tone using the speaker. Try changing frequency to change the pitch of the tone.

Parameters:frequency (int) – The frequency of the tone in Hz
Onboard speaker

To use with the Circuit Playground Express or Bluefruit:

from adafruit_circuitplayground import cp

while True:
    if cp.button_a:
        cp.start_tone(262)
    elif cp.button_b:
        cp.start_tone(294)
    else:
        cp.stop_tone()
stop_tone()[source]

Use with start_tone to stop the tone produced.

Onboard speaker

To use with the Circuit Playground Express or Bluefruit:

from adafruit_circuitplayground import cp

while True:
    if cp.button_a:
        cp.start_tone(262)
    elif cp.button_b:
        cp.start_tone(294)
    else:
        cp.stop_tone()
switch

True when the switch is to the left next to the music notes. False when it is to the right towards the ear.

Slide switch

To use with the Circuit Playground Express or Bluefruit:

 from adafruit_circuitplayground import cp
import time

 while True:
     print("Slide switch:", cp.switch)
     time.sleep(0.1)
tapped

True once after a detecting a tap. Requires cp.detect_taps.

Accelerometer

Tap the Circuit Playground once for a single-tap, or quickly tap twice for a double-tap.

To use with Circuit Playground Express or Bluefruit:

from adafruit_circuitplayground import cp

cp.detect_taps = 1

while True:
    if cp.tapped:
        print("Single tap detected!")

To use single and double tap together, you must have a delay between them. It will not function properly without it. This example uses both by counting a specified number of each type of tap before moving on in the code.

from adafruit_circuitplayground import cp

# Set to check for single-taps.
cp.detect_taps = 1
tap_count = 0

# We're looking for 2 single-taps before moving on.
while tap_count < 2:
    if cp.tapped:
        tap_count += 1
print("Reached 2 single-taps!")

# Now switch to checking for double-taps
tap_count = 0
cp.detect_taps = 2

# We're looking for 2 double-taps before moving on.
while tap_count < 2:
    if cp.tapped:
       tap_count += 1
print("Reached 2 double-taps!")
print("Done.")
temperature

The temperature in Celsius.

Temperature sensor

Converting this to Fahrenheit is easy!

To use with the Circuit Playground Express or Bluefruit:

from adafruit_circuitplayground import cp
import time

while True:
    temperature_c = cp.temperature
    temperature_f = temperature_c * 1.8 + 32
    print("Temperature celsius:", temperature_c)
    print("Temperature fahrenheit:", temperature_f)
    time.sleep(1)
touch_A1

Detect touch on capacitive touch pad A1.

Capacitive touch pad A1

To use with the Circuit Playground Express or Bluefruit:

from adafruit_circuitplayground import cp

while True:
    if cp.touch_A1:
        print('Touched pad A1')
touch_A2

Detect touch on capacitive touch pad A2.

Capacitive touch pad A2

To use with the Circuit Playground Express or Bluefruit:

from adafruit_circuitplayground import cp

while True:
    if cp.touch_A2:
        print('Touched pad A2')
touch_A3

Detect touch on capacitive touch pad A3.

Capacitive touch pad A3

To use with the Circuit Playground Express or Bluefruit:

from adafruit_circuitplayground import cp

while True:
    if cp.touch_A3:
        print('Touched pad A3')
touch_A4

Detect touch on capacitive touch pad A4.

Capacitive touch pad A4

To use with the Circuit Playground Express or Bluefruit:

from adafruit_circuitplayground import cp

while True:
    if cp.touch_A4:
        print('Touched pad A4')
touch_A5

Detect touch on capacitive touch pad A5.

Capacitive touch pad A5

To use with the Circuit Playground Express or Bluefruit:

from adafruit_circuitplayground import cp

while True:
    if cp.touch_A5:
        print('Touched pad A5')
touch_A6

Detect touch on capacitive touch pad A6.

Capacitive touch pad A6

To use with the Circuit Playground Express or Bluefruit:

from adafruit_circuitplayground import cp

while True:
    if cp.touch_A6:
        print('Touched pad A6'
touch_TX

Detect touch on capacitive touch pad TX (also known as A7 on the Circuit Playground Express) Note: can be called as touch_A7 on Circuit Playground Express.

Capacitive touch pad TX

To use with the Circuit Playground Express or Bluefruit:

from adafruit_circuitplayground import cp

while True:
    if cp.touch_A7:
        print('Touched pad A7')
were_pressed

Returns a set of the buttons that have been pressed

Button B

To use with the Circuit Playground Express or Bluefruit:

from adafruit_circuitplayground import cp

while True:
    print(cp.were_pressed)
class adafruit_circuitplayground.circuit_playground_base.Photocell(pin)[source]

Simple driver for analog photocell on the Circuit Playground Express and Bluefruit.

light

Light level.

adafruit_circuitplayground.bluefruit

CircuitPython helper for Circuit Playground Bluefruit.

  • Author(s): Kattni Rembor

Implementation Notes

Hardware:

class adafruit_circuitplayground.bluefruit.Bluefruit[source]

Represents a single CircuitPlayground Bluefruit.

loud_sound(sound_threshold=200)[source]

Utilise a loud sound as an input.

Parameters:sound_threshold (int) – Threshold sound level must exceed to return true (Default: 200)
Microphone (sound sensor)

This example turns the LEDs red each time you make a loud sound. Try clapping or blowing onto the microphone to trigger it.

from adafruit_circuitplayground.bluefruit import cpb

while True:
    if cpb.loud_sound():
        cpb.pixels.fill((50, 0, 0))
    else:
        cpb.pixels.fill(0)

You may find that the code is not responding how you would like. If this is the case, you can change the loud sound threshold to make it more or less responsive. Setting it to a higher number means it will take a louder sound to trigger. Setting it to a lower number will take a quieter sound to trigger. The following example shows the threshold being set to a higher number than the default.

from adafruit_circuitplayground.bluefruit import cpb

while True:
    if cpb.loud_sound(sound_threshold=300):
        cpb.pixels.fill((50, 0, 0))
    else:
        cpb.pixels.fill(0)
play_mp3(file_name)[source]

Play a .mp3 file using the onboard speaker.

Parameters:file_name – The name of your .mp3 file in quotation marks including .mp3
Onboard speaker

To use with the Circuit Playground Bluefruit:

from adafruit_circuitplayground import cp

while True:
    if cp.button_a:
        cp.play_mp3("laugh.mp3")
    elif cp.button_b:
        cp.play_mp3("rimshot.mp3")
sound_level

Obtain the sound level from the microphone (sound sensor).

Microphone (sound sensor)

This example prints the sound levels. Try clapping or blowing on the microphone to see the levels change.

from adafruit_circuitplayground.bluefruit import cpb

while True:
    print(cpb.sound_level)
adafruit_circuitplayground.bluefruit.cpb = <adafruit_circuitplayground.bluefruit.Bluefruit object>

Object that is automatically created on import.

To use, simply import it from the module:

from adafruit_circuitplayground.bluefruit import cpb

adafruit_circuitplayground.express

CircuitPython helper for Circuit Playground Express.

Hardware:

class adafruit_circuitplayground.express.Express[source]

Represents a single CircuitPlayground Express. Do not use more than one at a time.

loud_sound

This feature is not supported on Circuit Playground Express.

play_mp3

This feature is not supported on Circuit Playground Express.

sound_level

This feature is not supported on Circuit Playground Express.

touch_A7

Detect touch on capacitive touch pad TX (also known as A7 on the Circuit Playground Express) Note: can be called as touch_A7 on Circuit Playground Express.

Capacitive touch pad TX

To use with the Circuit Playground Express or Bluefruit:

from adafruit_circuitplayground import cp

while True:
    if cp.touch_A7:
        print('Touched pad A7')
adafruit_circuitplayground.express.cpx = <adafruit_circuitplayground.express.Express object>

Object that is automatically created on import.

To use, simply import it from the module:

from adafruit_circuitplayground.express import cpx