Skip to main content

Project Based Engineering Instrumentation High Level Coding and Microcontrollers

Chapter 15 Built-In Sensors

List 15.0.1. Parts List
List 15.0.2. Learning Objectives
  1. Understand the different sensors on the Circuitplayground
  2. Learn the difference between high level and low level control
  3. Get more practice plotting data from onboard sensors
The CPX has numerous built-in sensors. These include a light sensor, an IR sensor, an accelerometer, a microphone, a speaker, some neopixels, a temperature sensor and 8 analog inputs with ADCs and even I2C (pronounced I squared C - it’s a kind of serial communication) that you can use to easily hook up more sensors to it. We’re not going to utilize all of these sensors since that would be a rather large project. Instead we’re going to learn how to use the temperature, light and sound sensors as well as the accelerometer. For each of these examples there is a relatively easy way to access the sensors using a built-in module called adafruit_circuitplayground.express if you are using the CPX. If you are using the CPB you need to type adafruit_circuitplayground.bluefruit. It’s a very nice module because it imports everything on the board. Section SectionΒ 7.2 goes over the steps required to install different modules on the CPX/CPB. The problem is you can run into module conflicts. This happens when two different modules try to access the same pins on the CP. Sometimes if you import adafruit_circuitplayground you won’t be able to import some other modules. Note you might need to add the adafruit_circuitplayground library to your lib/ folder on your CIRCUITPY drive. Due to this module conflict issue, there are some low level control commands you can use to access each of the sensors on board. We’re obviously going to learn the low level control method first and then I’ll show you how to access the sensors using the adafruit_circuitplayground module. If you get a currently in use error it means you have a module conflict. Hence why I’m showing you the low level control method.