Skip to content

[PXCT-1073] Tutorial from library - Uno R4 Capacitor Tutorial #2559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
130 changes: 130 additions & 0 deletions content/hardware/02.hero/boards/uno-r4-wifi/tutorials/touch/content.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
---
title: Uno R4 Capacitor Tutorial
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
title: Uno R4 Capacitor Tutorial
title: Uno R4 Capacitive-Touch Tutorial.

I'd like to suggest this title since it correlates more naturally with the topic and the library that the tutorial will focus on, the capacitive touch chracteristic.

description: Learn to use the built-in capacitive sensing capabilities of the Arduino® Uno R4.
tags: [Arduino, Capacitive Sensing, Uno R4]
author: Pedro Lima
Comment on lines +3 to +5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it would be nice to add additional metadata keys that we have as well for other documentation, like:

Suggested change
description: Learn to use the built-in capacitive sensing capabilities of the Arduino® Uno R4.
tags: [Arduino, Capacitive Sensing, Uno R4]
author: Pedro Lima
difficulty: beginner
description: Learn to use the built-in capacitive sensing capabilities of the Arduino® Uno R4.
tags: [Arduino, Capacitive Sensing, Uno R4]
author: Pedro Lima
hardware:
- hardware/02.hero/boards/uno-r4-wifi
- hardware/02.hero/boards/uno-r4-minima
software:
- ide-v2
- web-editor

---

Capacitive sensing is a technology that detects changes in capacitance to determine the presence or absence of a conductive object, such as a human finger. This principle is widely used in touch-sensitive devices. The Arduino® Uno R4, both the [WiFi](https://store.arduino.cc/products/arduino-uno-r4-wifi) and [Minima](https://store.arduino.cc/products/arduino-uno-r4-minima) versions, come equipped with built-in capacitive sensing capabilities, making it easier to integrate touch inputs into your projects.

![Sensor Example](assets/Touch_Cover_001.gif)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could add this as a duplicate after the example section, so it works as a nice visual addition of what to expect or how it would work. The image placement here is good because it shows the reader from the introduction what they are expecting to learn within the tutorial, so I think it would be nice to copy this line and add it next to the example section.


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I think we should add:

Goals

Required Hardware and Software

To show directly what are the goals of the tutorial, as well as the hardware and software that would be used so the reader knows the requirements right at the beginning

## How Capacitive Sensing Works

Imagine the sensor as creating an invisible electric field around itself. When a conductive object (like your finger) approaches, it's like dropping a stone into a calm pond - the field gets disturbed. The sensor detects this disturbance as a change in capacitance, which is essentially how much electrical charge the system can store.
Here's the process:

1. The sensor generates a small electric field
2. When you touch or approach the sensor, your body acts like a conductor
3. This changes the capacitance of the system
4. The microcontroller measures this change and determines if it's significant enough to register as a "touch"



Comment on lines +22 to +23
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Suggestion for spacing removal

## Using Capacitive Sensing on the Uno R4

The Uno R4 features a Capacitive Touch Sensing Unit (CTSU) that allows you to use certain pins as capacitive touch inputs. To utilize these capabilities, you can use the [Arduino_CapacitiveTouch library](https://github.com/arduino-libraries/Arduino_CapacitiveTouch).

### Compatible Pins

For both the Uno R4 WiFi and Minima, the compatible pins for capacitive touch are listed in the [Arduino_CapacitiveTouch library documentation](https://github.com/arduino-libraries/Arduino_CapacitiveTouch?tab=readme-ov-file#compatible-pins).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
For both the Uno R4 WiFi and Minima, the compatible pins for capacitive touch are listed in the [Arduino_CapacitiveTouch library documentation](https://github.com/arduino-libraries/Arduino_CapacitiveTouch?tab=readme-ov-file#compatible-pins).
For both the Uno R4 WiFi and Minima boards, the compatible pins for capacitive touch are listed in the [Arduino_CapacitiveTouch library documentation](https://github.com/arduino-libraries/Arduino_CapacitiveTouch?tab=readme-ov-file#compatible-pins).

A minor suggestion


**Arduino® UNO-R4 Minima:**
| Arduino Pin | Touch Sensor Channel (TS#) | Channel Control Index (CHAC idx) | Channel Control Bit Mask (CHAC val) |
|--------------|----------------------------|----------------------------------|-------------------------------------|
Comment on lines +32 to +34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the preview, here I see some broken formatting:

image

Maybe we could apply the following update:

Suggested change
**Arduino® UNO-R4 Minima:**
| Arduino Pin | Touch Sensor Channel (TS#) | Channel Control Index (CHAC idx) | Channel Control Bit Mask (CHAC val) |
|--------------|----------------------------|----------------------------------|-------------------------------------|
**Arduino® UNO-R4 Minima:**
| Arduino Pin | Touch Sensor Channel (TS#) | Channel Control Index (CHAC idx) | Channel Control Bit Mask (CHAC val) |
|--------------|----------------------------|----------------------------------|-------------------------------------|

Which separates the table title from the table itself

| D0 | 9 | 1 | (1 << 1) |
| D1 | 8 | 1 | (1 << 0) |
| D2 | 34 | 4 | (1 << 2) |
| D3 | 13 | 1 | (1 << 5) |
| D8 | 11 | 1 | (1 << 3) |
| D9 | 2 | 0 | (1 << 2) |
| D11 | 10 | 1 | (1 << 2) |
| D13 | 12 | 1 | (1 << 4) |
| A1 (D15) | 21 | 2 | (1 << 5) |
| A2 (D16) | 22 | 2 | (1 << 6) |
| LOVE_BUTTON | 0 | 0 | (1 << 0) |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the lovebutton is a pin at bottom side of the minima right?


**Arduino® UNO-R4 WiFi:**
| Arduino Pin | Touch Sensor Channel (TS#) | Channel Control Index (CHAC idx) | Channel Control Bit Mask (CHAC val) |
|--------------|----------------------------|----------------------------------|-------------------------------------|
Comment on lines +47 to +49
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**Arduino® UNO-R4 WiFi:**
| Arduino Pin | Touch Sensor Channel (TS#) | Channel Control Index (CHAC idx) | Channel Control Bit Mask (CHAC val) |
|--------------|----------------------------|----------------------------------|-------------------------------------|
**Arduino® UNO-R4 WiFi:**
| Arduino Pin | Touch Sensor Channel (TS#) | Channel Control Index (CHAC idx) | Channel Control Bit Mask (CHAC val) |
|--------------|----------------------------|----------------------------------|-------------------------------------|

Similar to the table above

| D0 | 9 | 1 | (1 << 1) |
| D1 | 8 | 1 | (1 << 0) |
| D2 | 13 | 1 | (1 << 5) |
| D3 | 34 | 4 | (1 << 2) |
| D6 | 12 | 1 | (1 << 4) |
| D8 | 11 | 1 | (1 << 3) |
| D9 | 2 | 0 | (1 << 2) |
| D11 | 7 | 0 | (1 << 7) |
| D12 | 6 | 0 | (1 << 6) |
| A1 (D15) | 21 | 2 | (1 << 5) |
| A2 (D16) | 22 | 2 | (1 << 6) |
| LOVE_BUTTON | 27 | 3 | (1 << 3) |


### Library Functions

The Arduino_CapacitiveTouch library provides several functions to work with capacitive touch inputs:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The Arduino_CapacitiveTouch library provides several functions to work with capacitive touch inputs:
The **Arduino_CapacitiveTouch** library provides several functions to work with capacitive touch inputs:

A minor suggestion to bold the library name


- **```CapacitiveTouch(uint8_t pin)```** Constructs a capacitive touch sensor for the given pin.
- **```bool begin()```** Initializes the sensor and configures the pin and hardware.
- **```int read()```** Reads the raw sensor value and returns it.
- **```bool isTouched()```** Checks if the sensor is touched based on the threshold.
- **```void setThreshold(int threshold)```** Sets the detection threshold for touch sensitivity.
- **```int getThreshold()```** Retrieves the current detection threshold.
Comment on lines +68 to +73
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- **```CapacitiveTouch(uint8_t pin)```** Constructs a capacitive touch sensor for the given pin.
- **```bool begin()```** Initializes the sensor and configures the pin and hardware.
- **```int read()```** Reads the raw sensor value and returns it.
- **```bool isTouched()```** Checks if the sensor is touched based on the threshold.
- **```void setThreshold(int threshold)```** Sets the detection threshold for touch sensitivity.
- **```int getThreshold()```** Retrieves the current detection threshold.
- **`CapacitiveTouch(uint8_t pin)`** Constructs a capacitive touch sensor for the given pin.
- **`bool begin()`** Initializes the sensor and configures the pin and hardware.
- **`int read()`** Reads the raw sensor value and returns it.
- **`bool isTouched()`** Checks if the sensor is touched based on the threshold.
- **`void setThreshold(int threshold)`** Sets the detection threshold for touch sensitivity.
- **`int getThreshold()`** Retrieves the current detection threshold.

A minor suggestion to keep the formatting and removing redundancy formatting


For more detailed usage and examples, refer to the [CapacitiveSensor library documentation](https://docs.arduino.cc/libraries/capacitivesensor/).

## Example Code

Here's a simple example to get you started with capacitive sensing on the Uno R4.
For this example we are connecting a single piece of any conductive material to the pin ```D0``` on the Board.
Comment on lines +79 to +80
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Here's a simple example to get you started with capacitive sensing on the Uno R4.
For this example we are connecting a single piece of any conductive material to the pin ```D0``` on the Board.
Here's a simple example to get you started with capacitive sensing on the Uno R4. For this example, we are connecting a single piece of any conductive material to the pin `D0` on the Board.

A minor suggestion to keep the sentences in the same line and removing redundant formatting.


![How to connect](assets/HoockupGuideExample.png)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice to move this to a separate and dedicated section, so the readers can assemble the hardware and understand how it works electrically. Then they can move to example section to upload the code and test it.


**Note:**
You will first need to install the library [Arduino_CapacitiveTouch](https://docs.arduino.cc/libraries/capacitivesensor/):
```Arduino IDE: Library Manager → Search "Arduino_CapacitiveTouch" → Install```
Comment on lines +84 to +86
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, since the idea seems to put the information as a highlighted note, I suggest the following:

Suggested change
**Note:**
You will first need to install the library [Arduino_CapacitiveTouch](https://docs.arduino.cc/libraries/capacitivesensor/):
```Arduino IDE: Library Manager → Search "Arduino_CapacitiveTouch" → Install```
***__Note:__ You will first need to install the library [Arduino_CapacitiveTouch](https://docs.arduino.cc/libraries/capacitivesensor/). To do so, open `Arduino IDE: Library Manager``Search "Arduino_CapacitiveTouch"` within _Manage Libraries_ option → `Install` .***

With some formatting update


```ARDUINO
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```ARDUINO
```arduino

Here maybe you were referring to code formatting as above? or you could use ```cpp which works as well.

#include "Arduino_CapacitiveTouch.h"

CapacitiveTouch touchButton = CapacitiveTouch(D0);

void setup() {
Serial.begin(9600);

if(touchButton.begin()){
Serial.println("Capacitive touch sensor initialized.");
} else {
Serial.println("Failed to initialize capacitive touch sensor. Please use a supported pin.");
while(true);
}

touchButton.setThreshold(2000);
}

void loop() {
int sensorValue = touchButton.read();
Serial.print("Raw value: ");
Serial.println(sensorValue);

if (touchButton.isTouched()) {
Serial.println("Button touched!");
}

delay(100);
}
```

## Creative Project Ideas
Now that you understand the basics, here are some project ideas:

**Touch-Controlled Night Light -** Create a lamp that turns on/off with a touch
**Capacitive Touch Piano -** Use multiple pins to create touch-sensitive keys
**Smart Home Controller -** Touch different areas to control various devices
**Interactive Art Installation -** Create touch-responsive visual or audio effects
Comment on lines +119 to +125
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Creative Project Ideas
Now that you understand the basics, here are some project ideas:
**Touch-Controlled Night Light -** Create a lamp that turns on/off with a touch
**Capacitive Touch Piano -** Use multiple pins to create touch-sensitive keys
**Smart Home Controller -** Touch different areas to control various devices
**Interactive Art Installation -** Create touch-responsive visual or audio effects
## Creative Project Ideas
Now that you have learned the basics, here are some fun and interesting project ideas:
- **Touch-Controlled Night Light -** Create a lamp that turns on/off with a touch
- **Capacitive Touch Piano -** Use multiple pins to create touch-sensitive keys
- **Smart Home Controller -** Touch different areas to control various devices
- **Interactive Art Installation -** Create touch-responsive visual or audio effects

Some suggestion to update spacing between section title, bit of phrasing update, and bullet point addition for each element.


## Conclusion

The built-in capacitive sensing capabilities of the Arduino® Uno R4 provide an excellent way to add touch inputs to your projects. By leveraging the Arduino_CapacitiveTouch library, you can easily integrate touch-sensitive features, enhancing the interactivity and functionality of your designs. Whether you're building a simple touch interface or a more complex interactive system, the Uno R4's capacitive sensing features offer a versatile and user-friendly solution.
Remember to experiment with threshold values and consider the environment where your project will be used, as factors like humidity and nearby electronics can affect sensitivity. With practice, you'll develop an intuitive understanding of how to tune these sensors for optimal performance in your specific applications.
Comment on lines +129 to +130
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here it would be nice to be more concise if possible, for example, like:

Suggested change
The built-in capacitive sensing capabilities of the Arduino® Uno R4 provide an excellent way to add touch inputs to your projects. By leveraging the Arduino_CapacitiveTouch library, you can easily integrate touch-sensitive features, enhancing the interactivity and functionality of your designs. Whether you're building a simple touch interface or a more complex interactive system, the Uno R4's capacitive sensing features offer a versatile and user-friendly solution.
Remember to experiment with threshold values and consider the environment where your project will be used, as factors like humidity and nearby electronics can affect sensitivity. With practice, you'll develop an intuitive understanding of how to tune these sensors for optimal performance in your specific applications.
Capacitive sensing on the Arduino UNO R4 lets you add intuitive touch controls with minimal hardware, simply pair the board with the `Arduino_CapacitiveTouch` library. Tune the detection threshold for your environment (humidity, nearby electronics, etc.), and you can quickly scale from a single touch button to richer, multi-point interfaces.

It would also be nice to add Next Steps section if possible

Loading