Learning the Sensor

Once you've got everything installed and your computer can talk to the Circuit Playground, it's time to start playing with the sensor.

Plug your Circuit Playground into your computer and select the Circuit Plaground under Tools > Boards.  Then select the Circuit Playground as the Port.

Next, open Examples > Adafruit Circuit Playground > Hello_Circuitplayground > Hello_Accelerometer.

Upload the code to your Circuit Playground by clicking the Upload button.

Now open your serial monitor in Arduino.  The serial monitor gives you feedback from the board so you can test your code at a really basic level and make sure everything is working.

If all is well, you should see some numbers scrolling by in this window.  You'll see values for x, y, and z -- these represent the three different directions this board can move.  Keeping the circuit playground plugged in, pick it up and move it around a bit and watch to see how the numbers change.

Let's simplify even more.  Go into your code window and comment out all the serial commands that talk about Y and Z -- we'll just focus on X for now.

While you're in there, change X's second "serial print" to a "serial print line" command.  This will make a new line for each value in the serial monitor so it's easier to read.    Upload the code again.

Download: file
  Serial.print("X: ");
  Serial.println(X);
  //Serial.print("  Y: ");
  //Serial.println(Y);
  //Serial.print("  Z: ");
  //Serial.println(Z);

Take another look at your serial monitor.  You'll see just one reading for X appear each second.  Play around with moving the circuit playground through space again and watch what happens with the values on the screen. 

Try moving the board in all three dimensions and see which one changes X the most consistently.  With the board oriented the way I want it in my project, it looks like X changes the most dramatically when I turn the board clockwise or counter clockwise.

Go back to your code and uncomment only the Y lines, and upload again. Then get a feel for which axis of movement the Y direction controls.  Looks like it's related to the board twisting left to right.

Try once more with Z.  Z appears to control the back and forth motion.

Conclusions

To help imagine what this means in real life, I held the board against my hip, where it's going to live in my project, to visualize the real world orientation.

I learned that the data for X will measure my side to side motion, like when I do cartwheels.  Y will measure whether I'm spinning around in circles.  Z will be able to tell me if I'm doing forward bends or back bends.

This guide was first published on Feb 18, 2017. It was last updated on Feb 18, 2017. This page (Learning the Sensor) was last updated on Nov 20, 2019.