Commit 58373738 authored by yuichitamiya's avatar yuichitamiya
Browse files

add QT

parent 6257aff3
Pipeline #242947 passed with stage
in 2 minutes and 5 seconds
# make QTouch keyboard
## QTouch
The QTouch® Peripheral Touch Controller (PTC) offers built-in hardware for capacitive touch measurement on sensors that function as buttons, sliders, and wheels.
ref. [Introduction to QTouch® Peripheral Touch Controller (PTC)](https://microchipdeveloper.com/touch:introduction-to-qtouch-peripheral-touch-controller-ptc)
---
## Pinout
![](../images/make/Seeeduino-XIAO-pinout-1.jpg){width=600}
ref. [Seeeduino XIAO](https://wiki.seeedstudio.com/Seeeduino-XIAO/#qtouch)
---
## BOM
|Item |Qty |Price/p|Link|-|
|-- |:--:|-- |--|--|
|Seeeduino Xiao| 1|5.40 USD |[Seeed](https://www.seeedstudio.com/Seeeduino-XIAO-Arduino-Microcontroller-SAMD21-Cortex-M0+-p-4426.html)|
|Pinsocket 1x7 THT| 2| 0.8 USD|[Akizuki](https://akizukidenshi.com/catalog/g/gC-10073/)|1x40 -> 1x7x2P
|3.5mm Phone Jack| 1|0.50 USD |[Akizuki](https://akizukidenshi.com/catalog/g/gC-02460/)| Stereo or monaural
|2 POS Terminal Block| 1|0.20 USD |[Akizuki](https://akizukidenshi.com/catalog/g/gP-02333/)|5.08mm pitch
---
## PCB
![](../images/make/QT_sch.png){width=800}
![](../images/make/QT_brd.png){width=800}
![](../eagle/QT/QT_top.png){width=300}
![](../eagle/QT/QT_holes_outline.png){width=300}
download Eagle [sch](../eagle/QT/QT.sch)|[brd](../eagle/QT/QT.brd)
---
## Program
### Library
[adafruit/Adafruit_FreeTouch](https://github.com/adafruit/Adafruit_FreeTouch)
```
#include "Adafruit_FreeTouch.h"
```
### Arduino Sketch
[download ino](./Xiao_QT_keyboard.ino)
<details closed>
<summary>Xiao_QT_keyboard.ino</summary>
<pre>
#include <Adafruit_FreeTouch.h>
//#include &lt;Adafruit_FreeTouch.h&gt;
Adafruit_FreeTouch qt_0 = Adafruit_FreeTouch(A0, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
Adafruit_FreeTouch qt_1 = Adafruit_FreeTouch(A1, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
Adafruit_FreeTouch qt_6 = Adafruit_FreeTouch(A6, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
Adafruit_FreeTouch qt_7 = Adafruit_FreeTouch(A7, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
Adafruit_FreeTouch qt_8 = Adafruit_FreeTouch(A8, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
Adafruit_FreeTouch qt_9 = Adafruit_FreeTouch(A9, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
Adafruit_FreeTouch qt_10 = Adafruit_FreeTouch(A10, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
#include <TinyUSB_Mouse_and_Keyboard.h>
//#include &lt;TinyUSB_Mouse_and_Keyboard.h&gt;
uint8_t Key2;//pin2 bike sensor in
void setup() {
Keyboard.begin();
Serial.begin(115200);
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
pinMode(2, INPUT_PULLUP);//pin2 bike sensor in
qt_0.begin();
qt_1.begin();
qt_6.begin();
qt_7.begin();
qt_8.begin();
qt_9.begin();
qt_10.begin();
}
int qt_Threshold = 850;
void loop() {
Key2 = digitalRead(2);//pin2 bike sensor_in
int qt0 = 0;
int qt1 = 0;
int qt6 = 0;
int qt7 = 0;
int qt8 = 0;
int qt9 = 0;
int qt10 = 0;
qt0 = qt_0.measure();
qt1 = qt_1.measure();
qt6 = qt_6.measure();
qt7 = qt_7.measure();
qt8 = qt_8.measure();
qt9 = qt_9.measure();
qt10 = qt_10.measure();
/* Xiao
|USB-C|
|A0_qt0| |5V|
|A1_qt1| |GND|
|A2_bike| |3V3|
|A3| |A10_qt10|
|A4| |A9_qt9|
|A5| |A8_qt8|
|A6_qt6| |A7_qt7|
*/
if (Key2 == LOW ) { //pin2 bike sensor_in // XIAO: LOW means On = key pressed
Key3_act();
}
if (qt0 >= qt_Threshold) {
Serial.print("qt0: "); Serial.println(qt0);
Key2_act();
}
if (qt1 >= qt_Threshold) {
Serial.print("qt1: "); Serial.println(qt1);
Key1_act();
}
if (qt6 >= qt_Threshold) {
Serial.print("qt6: "); Serial.println(qt6);
Key3_act();
}
if (qt7 >= qt_Threshold) {
Serial.print("qt7: "); Serial.println(qt7);
Key0_act();
}
if (qt8 >= qt_Threshold) {
Serial.print("qt8: "); Serial.println(qt8);
Key1_act();
}
if (qt9 >= qt_Threshold) {
Serial.print("qt9: "); Serial.println(qt9);
Key4_act();
}
if (qt10 >= qt_Threshold) {
Serial.print("qt10: "); Serial.println(qt10);
Key3_act();
}
//delay(100);
}
void Key0_act() {
// <-
Keyboard.press(KEY_RIGHT_ARROW);
delay(400);
Keyboard.releaseAll();
digitalWrite(LED_BUILTIN, LOW);// XIAOでは、LOW = On
KeyRelease();
}
void Key1_act() {
// ->
Keyboard.press(KEY_LEFT_ARROW);
delay(400);
Keyboard.releaseAll();
digitalWrite(LED_BUILTIN, LOW);
KeyRelease();
}
void Key2_act() {
// down arrow
Keyboard.press(KEY_DOWN_ARROW);
Keyboard.releaseAll();
digitalWrite(LED_BUILTIN, LOW);
KeyRelease();
}
void Key3_act() {
// up arrow
Keyboard.press(KEY_UP_ARROW);
Keyboard.releaseAll();
digitalWrite(LED_BUILTIN, LOW);
KeyRelease();
}
void Key4_act() {
// feedback
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.write('f');
Keyboard.releaseAll();
digitalWrite(LED_BUILTIN, LOW);
KeyRelease();
}
void KeyRelease() {
Keyboard.releaseAll();
delay(500);
digitalWrite(LED_BUILTIN, HIGH);// XIAO HIGH = Off
}
/*Example
Keyboard.write('a'); //press and release 'a' key
uint8_t Multiple[3]= {'1','2','3'};
Keyboard.write(Multiple,3); //multiple keys sequentially from a buffer
Keyboard.print("456"); //print a string
Keyboard.println("789"); //print another string with a line
Keyboard.press(KEY_LEFT_SHIFT); //hold down the shift
Keyboard.println("a uppercase sentence"); //this will be all caps
Keyboard.release(KEY_LEFT_SHIFT);//release the shift
Keyboard.println ("back to lowercase");
Keyboard.press(KEY_LEFT_SHIFT); //press shift
Keyboard.println("1234"); //some text
Keyboard.releaseAll(); //release all
Keyboard.println("1234"); //not shifted
Keyboard.print("A mistake"); //will attempt to erase this
delay(1000);
Keyboard.press(KEY_LEFT_CTRL); //will attempt control-z
Keyboard.write('z');
Keyboard.releaseAll(); //release the control key
*/
</pre>
</details>
---
# Video
<video width="640" controls>
<source src="../../images/make/qt.mp4" type="video/mp4">
</video>
......@@ -32,7 +32,7 @@
![](../eagle/b2/b2sch.png){width=800}
![](../eagle/b2/b2brd.png){width=800}
download Eagle [sch](../eagle/b2/b2.brd)|[brd](../eagle/b2/b2.sch)
download Eagle [sch](../eagle/b2/b2.sch)|[brd](../eagle/b2/b2.brd)
---
## Program
......
This diff is collapsed.
This diff is collapsed.
......@@ -28,118 +28,159 @@ void setup() {
qt_8.begin();
qt_9.begin();
qt_10.begin();
}
int qt_Threshold = 850;
void loop() {
Key2 = digitalRead(2);//pin2 bike sensor_in
int qt0 = 0;
int qt1 = 0;
int qt6 = 0;
int qt7 = 0;
int qt8 = 0;
int qt9 = 0;
int qt10 = 0;
qt0 = qt_0.measure();
qt1 = qt_1.measure();
qt6 = qt_6.measure();
qt7 = qt_7.measure();
qt8 = qt_8.measure();
qt9 = qt_9.measure();
qt10 = qt_10.measure();
/* Xiao
|USB-C|
|A0_qt0| |5V|
|A1_qt1| |GND|
|A2_bike| |3V3|
|A3| |A10_qt10|
|A4| |A9_qt9|
|A5| |A8_qt8|
|A6_qt6| |A7_qt7|
*/
if (Key2 == LOW ) { //pin2 bike sensor_in // XIAO: LOW means On = key pressed
Key3_act();
}
if (qt0 >= qt_Threshold) {
Serial.print("qt0: "); Serial.println(qt0);
Key0_act();
}
if (qt1 >= qt_Threshold) {
Serial.print("qt1: "); Serial.println(qt1);
Key1_act();
}
if (qt6 >= qt_Threshold) {
Serial.print("qt6: "); Serial.println(qt6);
Key2_act();
}
if (qt7 >= qt_Threshold) {
Serial.print("qt7: "); Serial.println(qt7);
Key3_act();
}
if (qt8 >= qt_Threshold) {
Serial.print("qt8: "); Serial.println(qt8);
Key3_act();
}
if (qt9 >= qt_Threshold) {
Serial.print("qt9: "); Serial.println(qt9);
Key3_act();
}
if (qt10 >= qt_Threshold) {
Serial.print("qt10: "); Serial.println(qt10);
Key3_act();
}
//delay(100);
}
void Key0_act() {
// <-
Keyboard.press(KEY_RIGHT_ARROW);
delay(400);
Keyboard.releaseAll();
int qt_Threshold = 850;
digitalWrite(LED_BUILTIN, LOW);// XIAOでは、LOW = On
KeyRelease();
}
void loop() {
void Key1_act() {
// ->
Keyboard.press(KEY_LEFT_ARROW);
delay(400);
Keyboard.releaseAll();
Key2 = digitalRead(2);//pin2 bike sensor_in
digitalWrite(LED_BUILTIN, LOW);
KeyRelease();
}
int qt0 = 0;
int qt1 = 0;
int qt6 = 0;
int qt7 = 0;
int qt8 = 0;
int qt9 = 0;
int qt10 = 0;
void Key2_act() {
// down arrow
Keyboard.press(KEY_DOWN_ARROW);
Keyboard.releaseAll();
qt0 = qt_0.measure();
qt1 = qt_1.measure();
qt6 = qt_6.measure();
qt7 = qt_7.measure();
qt8 = qt_8.measure();
qt9 = qt_9.measure();
qt10 = qt_10.measure();
digitalWrite(LED_BUILTIN, LOW);
KeyRelease();
}
void Key3_act() {
// up arrow
Keyboard.press(KEY_UP_ARROW);
Keyboard.releaseAll();
/* Xiao
|USB-C|
|A0_qt0| |5V|
|A1_qt1| |GND|
|A2_bike| |3V3|
|A3| |A10_qt10|
|A4| |A9_qt9|
|A5| |A8_qt8|
|A6_qt6| |A7_qt7|
*/
digitalWrite(LED_BUILTIN, LOW);
KeyRelease();
}
void KeyRelease() {
Keyboard.releaseAll();
delay(500);
digitalWrite(LED_BUILTIN, HIGH);// XIAOでは、HIGH = Off
if (Key2 == LOW ) { //pin2 bike sensor_in // XIAO: LOW means On = key pressed
Key3_act();
}
if (qt0 >= qt_Threshold) {
Serial.print("qt0: "); Serial.println(qt0);
Key2_act();
}
if (qt1 >= qt_Threshold) {
Serial.print("qt1: "); Serial.println(qt1);
Key1_act();
}
if (qt6 >= qt_Threshold) {
Serial.print("qt6: "); Serial.println(qt6);
Key3_act();
}
if (qt7 >= qt_Threshold) {
Serial.print("qt7: "); Serial.println(qt7);
Key0_act();
}
if (qt8 >= qt_Threshold) {
Serial.print("qt8: "); Serial.println(qt8);
Key1_act();
}
if (qt9 >= qt_Threshold) {
Serial.print("qt9: "); Serial.println(qt9);
Key4_act();
}
if (qt10 >= qt_Threshold) {
Serial.print("qt10: "); Serial.println(qt10);
Key3_act();
}
//delay(100);
}
void Key0_act() {
// <-
Keyboard.press(KEY_RIGHT_ARROW);
delay(400);
Keyboard.releaseAll();
digitalWrite(LED_BUILTIN, LOW);// XIAOでは、LOW = On
KeyRelease();
}
void Key1_act() {
// ->
Keyboard.press(KEY_LEFT_ARROW);
delay(400);
Keyboard.releaseAll();
digitalWrite(LED_BUILTIN, LOW);
KeyRelease();
}
void Key2_act() {
// down arrow
Keyboard.press(KEY_DOWN_ARROW);
Keyboard.releaseAll();
digitalWrite(LED_BUILTIN, LOW);
KeyRelease();
}
void Key3_act() {
// up arrow
Keyboard.press(KEY_UP_ARROW);
Keyboard.releaseAll();
digitalWrite(LED_BUILTIN, LOW);
KeyRelease();
}
void Key4_act() {
// feedback
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.write('f');
Keyboard.releaseAll();
digitalWrite(LED_BUILTIN, LOW);
KeyRelease();
}
void KeyRelease() {
Keyboard.releaseAll();
delay(500);
digitalWrite(LED_BUILTIN, HIGH);// XIAO HIGH = Off
}
/*Example
Keyboard.write('a'); //press and release 'a' key
uint8_t Multiple[3]= {'1','2','3'};
Keyboard.write(Multiple,3); //multiple keys sequentially from a buffer
Keyboard.print("456"); //print a string
Keyboard.println("789"); //print another string with a line
Keyboard.press(KEY_LEFT_SHIFT); //hold down the shift
Keyboard.println("a uppercase sentence"); //this will be all caps
Keyboard.release(KEY_LEFT_SHIFT);//release the shift
Keyboard.println ("back to lowercase");
Keyboard.press(KEY_LEFT_SHIFT); //press shift
Keyboard.println("1234"); //some text
Keyboard.releaseAll(); //release all
Keyboard.println("1234"); //not shifted
Keyboard.print("A mistake"); //will attempt to erase this
delay(1000);
Keyboard.press(KEY_LEFT_CTRL); //will attempt control-z
Keyboard.write('z');
Keyboard.releaseAll(); //release the control key
*/
# Workshop
## QT keyboard
ref. [How to Make a Fruit Piano on Seeeduino XIAO’s Q-Touch Function
](https://www.seeedstudio.com/blog/2020/07/20/how-to-make-a-fruit-piano-on-seeeduino-xiaos-q-touch-function-m/)
## Xiao
![](../images/make/Seeeduino-XIAO-pinout-1.jpg){width=600}
ref. [Seeeduino XIAO](https://wiki.seeedstudio.com/Seeeduino-XIAO/#qtouch)
### BOM
#### Minimam
Item |Qty
--|--
Xiao |1
Jumper cables |1 - 7
#### Normal
Item |Qty
--|--
Xiao |1
Jumper cables |1 - 7
Bread Board |1
#### Fun
Item |Qty
--|--
Xiao |1
Jumper cables |1 - 7
Bread Board |1
Apple | 1-7
---
ref [How to Add Seeed boards to Arduino IDE](https://wiki.seeedstudio.com/Seeed_Arduino_Boards/)
### Arduino IDE
[Download](https://www.arduino.cc/en/software)
#### Additional Boards Manager URLs
File > Preferences
Copy below url to Additional Boards Manager URLs
```
https://files.seeedstudio.com/arduino/package_seeeduino_boards_index.json
```
#### Board Manager
Toos > Board > Board Manager
Search "xiao"
Install "Seeed SAMD(32 bit ....)Boards"
Board: "Seeduino XIAO"
Port: "/dev/....(Seeduino XIAO)" or COMx (Seeduino XIAO)
### Board and Port
Tools > Board
find "Seeeduino XIAO M0"
### Library
[TinyUSB_Mouse_and_Keyboard](https://github.com/cyborg5/TinyUSB_Mouse_and_Keyboard/)
[adafruit/Adafruit_FreeTouch](https://github.com/adafruit/Adafruit_FreeTouch)
Sketch > Include Library > Add . ZIP Library
---
### Xiao_QT_keyboard.ino
[Download](./sketch/Xiao_QT_keyboard/Xiao_QT_keyboard.ino)
Double click to open
### Keyboard Functions & Parameters
ref .[TinyUSB_Mouse_and_Keyboard/examples/TinyUSB_Keyboard_Test/TinyUSB_Keyboard_Test.ino](https://github.com/cyborg5/TinyUSB_Mouse_and_Keyboard/blob/master/examples/TinyUSB_Keyboard_Test/TinyUSB_Keyboard_Test.ino)