The Circuit Playground board is built on an ATmega32u4 (at 8MHz) and comes loaded with ten programmable sensors/components. To power the Circuit Playground use a micro-USB cable, a AAA battery pack, or a 3.7V LiPo. The board has a voltage regulator to step up to 5V.
The Circuit Palyaground
10 Mini NeoPixel LEDs
1 LIS3DH Triple-Axis Accelerometer
1 Thermistor for Temperature Sensing
1 Phototransistor for Light Sensing
1 MEMS microphone for Sound Sensing
1 Mini Speaker for playing tones
2 Push Buttons
1 Slide Switch
Eight alligator-clip friendly IO pins - all enabled for capacitive sensing
Reset Switch, Power LED and Pin 13 LED.
GPIO + Capacitive Touch Pads
All 8 non-power pads around the circuit playground have the ability to act as capacitive touch pads. Each pad has a 1Mohm resistor between it and digital pin #30. You can toggle this pin to control whether the resistor is a pullup or pulldown or floating. Note that this means that all the pads have a 2Mohm resistance between them.
You can also of course just use those pads for GPIO, we expose the hardware Serial (TX + RX), hardware I2C (SDA + SCL) and 4 gpio pins that can also do analog readings. They are the same exact pins as those on the Flora
NeoPixels
Each Circuit Playground comes with 10 'NeoPixels' (technically, SK6812-3535 chips). These are connected to digital pin #17 and are powered by the 3.3V regulator. This is technically undervolting but we test them at this voltage and they work fine, if slightly tinted
Pushbuttons
There are three tactile pushbutton switches. One is the Reset button. Press this button once to reset, double-click to enter the bootloader manually.
The other two buttons are the Left and Right buttons, connected to digital #4 (Left) and #19 (Right) each. These have pull-down resistors installed so are, by default, LOW and when pressed read HIGH. This is to make if-then logic a little easier to read for beginners
Slide Switch
There is a single slide switch near the center of the Circuit Playground. It is connected to digital #21 and will read LOW when slid to the left, and HIGH when in the right hand position
Light Sensor
There is an analog light sensor, part number ALS-PT19, in the top left part of the board. This can be used to detect ambient light, with similar spectral response to the human eye.
This sensor is connect to analog pin #A5 and will read between 0 and 1023 with higher values corresponding to higher light levels. A reading of about 300 is common for most indoor light levels.
Temperature Sensor
There is an NTC thermistor (Murata NCP15XH103F03RC) that we use for temperature sensing. While it isn't an all-in-one temperature sensor, with linear output, it's easy to calculate the temperature based on the analog voltage on analog pin #A0. There's a 10K resistor connected to it as a pull down.
Speaker Buzzer
You can make your circuit playground sing with the built in buzzer. This is a miniature magnetic speaker connected to digital pin #5 with a transistor driver. You can use PWM at varying frequencies to make basic tones.
Microphone Audio Sensor
A MEMS microphone can be used to detect audio levels and even perform basic FFT functions. You can read the analog voltage corresponding to the audio on analog pin #A4. Note that this is the raw analog audio waveform! When it's silent there will be a reading of ~330 and when loud the audio will read between 0 and 800 or so. Averaging and smoothing must be done to convert this to sound-pressure-level.
Triple-Axis Accelerometer
A LIS3DH 3-axis XYZ accelerometer is in the dead center of the board and you can use it to detect tilt, gravity, motion, as well as 'tap' and 'double tap' strikes on the board. The LIS3DH is connected to the hardware SPI pins (to leave the I2C pins free) and has the CS pin on digital pin #8 and an optional interrupt output on digital pin #7 (also known as IRQ #4)
Mac and Linux do not require drivers
With the latest Arduino IDE version you can add 3rd party boards directly from the IDE.
Start the IDE and navigate to the Preferences menu. You can access it from the File menu in Windows or Linux, or the Arduino menu on OS X.
Here is the link to add: https://adafruit.github.io/arduino-board-index/package_adafruit_index.json
Adding the link to the Adafruit board support package does not actually install anything, it only tells the Arduino IDE where to find the software.
Now that you have added the appropriate URLs to the Arduino IDE preferences, you can open the Boards Manager by navigating to the Tools→Board menu.
Once the Board Manager opens, click on the category drop down menu on the top left hand side of the window and select Contributed. You will then be able to select and install the boards supplied by the URLs added to the prefrences. In the example below, we are installing support for Adafruit AVR Boards, but the same applies to all boards installed with the Board Manager.
Next, quit and reopen the Arduino IDE to ensure that all of the boards are properly installed. You should now be able to see the new boards listed in the Tools→Board menu.
Finally follow the steps below for your platform to finish the installation - basically installing drivers and permissions management
For Circuit Playground, Adafruit provides a number of handy functions to use all the goodies on the board - all wrapped up into a library called CircuitPlayground.
Source:adafruit.com
Buttons
When you look at the Circuit Playground the battery connector should be at 6:00.
Oriented this way, the left and right buttons are on the proper sides of the board.
Here is basic code:
const int leftButton = 4; // The CP microcontroller pin for the left button
const int rightButton = 19; // The CP microcontroller pin for the right button
void setup() {
// put your setup code here, to run once:
pinMode(leftButton, INPUT); // We'll read in from the buttons
pinMode(rightButton, INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.print("Left Button: ");
if (digitalRead(leftButton)) { // if reading the left button returns true
Serial.print(" DOWN");
}else{
Serial.print(" UP");
}
Serial.print(" Right Button: ");
if (digitalRead(rightButton)) { // if reading the right button returns true
Serial.println(" DOWN");
}else{
Serial.println(" UP");
}
delay(1000);
}
3.3V - these are outputs from the onboard 3.3V power supply.
#4, #19 Left and Right button pins. These have pull-down resistors installed so are, by default, LOW and when pressed read HIGH.
#5 is a miniature magnetic speaker with a transistor driver. You can use PWM at
varying frequencies to make basic tones.
#8 is connected to the A LIS3DH 3-axis XYZ accelerometer which you can use
to detect tilt, gravity, motion, as well as 'tap' and 'double tap' strikes on the board. There is an optional interrupt output on digital pin #7 (also known as IRQ #4
#6, #9, #10, #12 - this is connected to the microcontroller's pin #10. This pin can also be used for analog inputs and is called A6, A9, A10, A12. They can also act as a PWM output.
#21 is connected to the slide switch. It will read LOW when slide to the left, and HIGH when in the right hand position
GND - shorthand for Ground you'll need to these when powering or connecting to external devices.
VBATT - this is the battery voltage output from whichever is higher: the JST battery pack or USB. It cannot be used as a power input! It is designed to power high-current or high-voltage devices that need more like 5V than 3.3V. If connected to USB, this pin provides 5V. If powered from battery, the output voltage will vary depending on the battery pack.
#A0 is connected to the temperature sensor. There's a 10K resistor connected to it as a pull down.
#A4 is connected to a MEMS microphone and can be used to detect audio levels and even perform basic FFT functions. You can read the analog voltage corresponding to the audio on analog pin.
Note that this is the raw analog audio waveform! When it's silent there will be a reading of ~330 and when loud the audio will read between 0 and 800 or so. Averaging and smoothing must be done to convert this to sound-pressure-level.
#A5 is the light sensor. It will read between 0 and 1023 with higher
values corresponding to higher light levels. A reading of about 300 is common for most indoor light levels.
RX #0 - This is a special-purpose pin. It is connected to the microcontroller's pin #0. This pin can also act as an interrupt input (INT2). The other special usage is connecting to UART/Serial sensors and devices, as the Data Receive (RX) pin.
TX #1 - This is a special-purpose pin. It is connected to the microcontroller's pin #1. This pin can also act as an interrupt input (INT3). The other special usage is connecting to UART/Serial sensors and devices, as the Data Transmit (TX) pin.
SDA #2 - This is a special-purpose pin. It is connected to the microcontroller's pin #2. This pin can also act as a PWM output and an interrupt input (INT1). The other special usage is connecting to I2C sensors and devices, as the I2C Data pin
SCL #3 - This is a special-purpose pin. It is connected to the microcontroller's pin #3. This pin can also act as a PWM output and an interrupt input (INT0). The other special usage is connecting to I2C sensors and devices, as the I2C Clock pin
Tones
The program's main loop function reads the two push buttons.
If the left one is pressed, the speaker outputs a sound at 440 Hz (a low tone).
If the right button is pressed, it outputs a sound at 1760 Hz (a higher tone).
At the bottom of the program see the code for making the tone via the makeTone() function.
The loop turns on the speaker, waits, then turns it off.
The speed of switching, slow or fast, makes the tone at the frequency at which the speaker pin is turned on and off.
// Adafruit Circuit Playground - Two tone sounds Support Open Source, buy at Adafruit
// 2016-08-05 Version 1 by Mike Barela for Adafruit Industries
const int speaker = 5; // The CP microcontroller pin for the speaker
const int leftButton = 4; // The CP microcontroller pin for the left button
const int rightButton = 19; // The CP microcontroller pin for the right button
void setup() {
pinMode(speaker, OUTPUT); // We will write out to the speaker
pinMode(leftButton, INPUT); // We'll read in from the buttons
pinMode(rightButton,INPUT);
}
void loop() {
if(digitalRead(leftButton)) { // if reading the left button returns true
makeTone(speaker,440,100); // output a 440 Hz sound for a tenth of a second
}
else if(digitalRead(rightButton)) { // if reading the right button returns true
makeTone(speaker,1760,100); // output a 1760 Hz sound for a tenth of a second
}
}
// the sound producing function (a brute force way to do it)
void makeTone (unsigned char speakerPin, int frequencyInHertz, long timeInMilliseconds) {
int x;
long delayAmount = (long)(1000000/frequencyInHertz);
long loopTime = (long)((timeInMilliseconds*1000)/(delayAmount*2));
for (x=0; x<loopTime; x++) { // the wave will be symetrical (same time high & low)
digitalWrite(speakerPin,HIGH); // Set the pin high
delayMicroseconds(delayAmount); // and make the tall part of the wave
digitalWrite(speakerPin,LOW); // switch the pin back to low
delayMicroseconds(delayAmount); // and make the bottom part of the wave
}
}
With the Circuit Playground Library:
// Adafruit Circuit Playground - Two tone sounds Support Open Source, buy at Adafruit
// 2016-08-05 Version 1 by Mike Barela for Adafruit Industries
// Uses the CircuitPlayground library to easily use the full functionality of the board
#include <Adafruit_CircuitPlayground.h>
void setup() {
CircuitPlayground.begin();
}
void loop() {
if(CircuitPlayground.leftButton()) { // if reading the left button returns true
CircuitPlayground.playTone(440,100); // output a 440 Hz sound for a tenth of a second
}
else if(CircuitPlayground.rightButton()) { // if reading the right button returns true
CircuitPlayground.playTone(1760,100); // output a 1760 Hz sound for a tenth of a second
}
}
// Adafruit Circuit Playground - Melody Support Open Source, buy at Adafruit
// 2016-08-06 Version 1 by Mike Barela for Adafruit Industries
// Adapted from melody by Tom Igoe on arduino.cc
// Uses the CircuitPlayground library to easily use the full functionality of the board
#include <Adafruit_CircuitPlayground.h>
#include "pitches.h"
const int numNotes = 8; // number of notes we are playing
int melody[] = { // specific notes in the melody
NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4 };
int noteDurations[] = { // note durations: 4 = quarter note, 8 = eighth note, etc.:
4, 8, 8, 4, 4, 4, 4, 4 };
void setup() {
CircuitPlayground.begin(); // initialize the CP library
}
void loop() {
if(CircuitPlayground.rightButton()) { // play when we press the right button
for (int thisNote = 0; thisNote < numNotes; thisNote++) { // play notes of the melody
// to calculate the note duration, take one second divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000 / noteDurations[thisNote];
CircuitPlayground.playTone(melody[thisNote], noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
}
}
}
Neopixels
To program the LEDs you need to use the library.
When using the library you can set the pixel color by addressing the pixel and then setting the RGB or hex color value:
To turn a single pixel off, set thecolor to black:
CircuitPlayground.setPixelColor(6, 0x000000);
Brightness takes a range from 0-255:
CircuitPlayground.setBrightness()
Here's a spinner example:
// Circuit Playground Bike Light - Spinner
//
// Author: Carter Nelson
// MIT License (https://opensource.org/licenses/MIT)
#include <Adafruit_CircuitPlayground.h>
#define COLOR 0xFF0000 // change this to your favorite color
#define SPIN_RATE 100 // lower is faster
int pixel1;
int pixel2;
///////////////////////////////////////////////////////////////////////////////
void setup() {
CircuitPlayground.begin();
// Make it bright!
CircuitPlayground.setBrightness(255);
// Can be any two pixels
pixel1 = 0;
pixel2 = 5;
}
///////////////////////////////////////////////////////////////////////////////
void loop() {
// Turn off all the NeoPixels
CircuitPlayground.clearPixels();
// Turn on two pixels to COLOR
CircuitPlayground.setPixelColor(pixel1, COLOR);
CircuitPlayground.setPixelColor(pixel2, COLOR);
// Increment pixels to move them around the board
pixel1 = pixel1 + 1;
pixel2 = pixel2 + 1;
// Check pixel values
if (pixel1 > 9) pixel1 = 0;
if (pixel2 > 9) pixel2 = 0;
// Wait a little bit so we don't spin too fast
delay(SPIN_RATE);
}