How to Plot Capacitive Touch Sensor Data with Mu and CircuitPython

2023-04-22 22:34:43 By : admin
, Sensor Plotting, Mu, CircuitPython, Adafruit Learning System, Plotting

Capacitive touch sensors are a popular way of inputting data into electronic devices. By detecting changes in the capacitance of the sensor, the device can determine whether or not a user is touching it. This makes it an ideal input method for devices like smartphones and tablets. But how can you use capacitive touch sensors in your own projects? And how can you plot data from these sensors? In this blog post, we'll explore how to do just that using Mu and CircuitPython.
Capacitive Touch | Sensor Plotting with Mu and CircuitPython | Adafruit Learning System


First, let's start with the basics. Capacitive touch sensors work by detecting changes in capacitance. Capacitance is a measure of an object's ability to store an electric charge. When your finger touches a capacitive touch sensor, it changes the capacitance of the sensor, which the device can detect. This makes capacitive touch sensors much more responsive than other types of touch sensors.

Now that you understand how capacitive touch sensors work, let's move on to how to use them in your own projects. The first thing you'll need is a capacitive touch sensor. There are many types of capacitive touch sensors available, but we recommend using the Adafruit Capacitive Touch Sensor Breakout Board. This board makes it easy to connect a capacitive touch sensor to your project.

Next, you'll need an MCU that supports CircuitPython. CircuitPython is a programming language designed for use on MCUs. It makes it easy to write code for your MCU, even if you're not an experienced programmer. We recommend using the Adafruit ItsyBitsy M4 Express. This board is small and affordable, but powerful enough to handle most projects.

Finally, you'll need a way to plot data from your capacitive touch sensor. This is where Mu comes in. Mu is an open-source IDE that makes it easy to write and debug code for your MCU. It also includes a built-in plotter, which makes it easy to plot data from your sensors.

Now that you have all the hardware you need, it's time to start writing code. Here's a simple example that reads data from a capacitive touch sensor and plots it using Mu:

```
import time
import adafruit_touchio
import board
import analogio

touch = adafruit_touchio.TouchIn(board.A0)
light = analogio.AnalogIn(board.LIGHT)

while True:
touch_val = touch.raw_value
light_val = light.value

print((touch_val, light_val))

time.sleep(0.01)
```

This code reads the raw value from a capacitive touch sensor connected to pin A0 and the light sensor connected to the built-in light sensor on the board. It then prints the values to the serial console and sleeps for 0.01 seconds. This loop will run continuously, reading data from the sensors and plotting it using Mu's built-in plotter.

To plot the data, simply click on the plotter button in Mu, and you should see a plot of the data from your sensors. You can then adjust the range of the plot, change the colors, and add labels as needed.

In conclusion, capacitive touch sensors are a powerful input method that can be used in a wide range of electronic devices. By using Mu and CircuitPython, you can easily read data from these sensors and plot it for further analysis. Whether you're building a smartphone or a simple sensor array, capacitive touch sensors and Mu are powerful tools that can help you explore the world of electronics.