Skip to main content

A Python API For The Circuit Playground Express

Project description

Control A Circuit Playground Express From Your PC With An Easy To Use Python 3 API

View the Installation and Usage Guide Here.

It supports the following CPX devices:

  • The Buttons and Slide Switch.
  • The D13 Board LED.
  • The 10 onboard neo-pixels.
  • Tone generation using the onboard speaker.
  • The accelerometer, including tap sensing.
  • The temperature sensor.
  • The light sensor.
  • The sound sensor.
  • Touchpad sensors.

An example to animate the neopixels and to start and stop the animation by simply tapping the Playground Express:

import random
import time

from pymata_cpx.pymata_cpx import PyMataCpx

class TheTapper():
    Illuminate the neopixels in a counter-clockwise fashion with randomly generated colors.
    When you tap the playground express, the neopixels will stop changing and the
    program pauses. Tap again and the neopixels will start again.
    def __init__(self):
        # create an instance of the API
        self.p = PyMataCpx()

        print('Tap the playground express to stop the neopixels from moving.')
        print('Tap again, to start them up')
        print('The tap state will be printed to the console')

        # Start monitoring for tap events and
        # send event notifications to the "tapped" callback method.

        # flag to start and stop the light show
        self.go = True

        while True:
                # run the light show
                for neopixel in range(0, 10):
                    # check the go flag
                    if self.go:
                        r = random.randint(0, 254)
                        g = random.randint(0, 254)
                        b = random.randint(0, 254)
                        self.p.cpx_pixel_set(neopixel, r, g, b)
            except KeyboardInterrupt:
                # If you press control-C, cleanly exit

    def tapped(self, data):
        :param data: data[0] = data type (analog = 2, digital =32)
                     data[1] = pin for device 27
                     data[2] = tap data - list of booleans.
                               First value for 1 tap
                               Second value for 2 taps
        # for any taps, toggle the go flag
        # print out the current go state
        if data[2] != [False, False]:
            self.go = not self.go

# start the program

Project details

Release history Release notifications | RSS feed

This version


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pymata-cpx, version 1.0
Filename, size File type Python version Upload date Hashes
Filename, size pymata_cpx-1.0-py2.py3-none-any.whl (22.0 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size pymata-cpx-1.0.tar.gz (20.5 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page