Skip to content

Commit 9c9e4f5

Browse files
committed
Updated documentation and added new examples
2 parents 90eb451 + 354de7e commit 9c9e4f5

13 files changed

Lines changed: 880 additions & 304 deletions

File tree

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"cstdio": "c",
6969
"freertos.h": "c",
7070
"pdm_microphone.h": "c",
71-
"pins.h": "c"
71+
"pins.h": "c",
72+
"optional": "c"
7273
}
7374
}

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ add_subdirectory(examples/hat_imu_ex)
9898
add_subdirectory(examples/hat_imu_cdc_ex)
9999
add_subdirectory(examples/hello_serial_client)
100100
add_subdirectory(examples/hello_serial_bidirectional_client)
101+
add_subdirectory(examples/hat_imu_display)
101102
#
102103
# You can edit it if you want to add new examples
103104
# ==============================================================================================

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,60 @@
1+
# TKJHAT project
2+
This project includes the TKJHAT SDK and a set of use examples for the University of Oulu course [Computer Systems](https://lovelace.oulu.fi/tietokonej%C3%A4rjestelm%C3%A4t/tietokonej%C3%A4rjestelm%C3%A4t/).
3+
4+
## Changelogs
5+
6+
7+
### Project changelog
8+
* **0.84** *(11-11-2025)* Updated the README.md files including changelog and list of examples. Version 0.83 of TKJHAT. Created hat_imu_display (not in course repo)
9+
* **0.83** *(28-10-2025)* Added serial client examples: hello_serial_bidirectional_client and hello_serial_client.
10+
* **0.82** *(22-10-2025)* TKJHat version 0.82. Added example hat_imu_ex and hat_imu_cdc_ex
11+
* **0.81** *(13-10-2025)* Added hat examples: hello_hat, hat_example. Solved problem in toolchain with Ninja path. Version 0.81 of the TKJHAT
12+
* **0.80** *(05-10-2025)* First version ready.
13+
14+
### TKJHAT changelog
15+
* **0.83** *(11-11-2025)*: Restructured documentation. Including names for pins. Restructured the topics section.
16+
* **0.82** *(22-10-2025)*: Solved bug that under certain circunstances did not allow to init correctly the IMU, making the I2C get stuck and without possibility of being used again. Corrected some links in documentation.
17+
* **0.81** *(13-10-2025)*: Refactor IMU function to start sampling with default values. Hat initialization now includes I2C.
18+
* **0.80** *(05-10-2025)*: First official version.
19+
20+
### usb-serial-debug changelog
21+
22+
* **0.80** *(05-10-2025)*:Initial working version
23+
124
## Important links
225
[TKJHAT library](https://unioulu-ubicomp-programming-courses.github.io/JTKJ-PicoRTOS-Project/)
326

27+
## List of examples
28+
29+
The **examples folder** contains a list of test programs that you can use to learn how to use different aspects of FreeRTOS and the TKJHAT SDK. The following list contains a description of each example and the target necessary to compile and run the code between parenthesis.
30+
31+
### Hello Pico
32+
33+
* **hello_pico** (*hello_pico*): Another Hello World app for the Raspberry Pi Pico that does not need either FreeRTOS or the TKJHAT SDK. Just print in terminal periodically.
34+
* **hello_blink** (*hello_blink*): Example application to run without the need of the TKJHAT. It blinks the Raspberry Pi Pico LED.
35+
36+
### Hello FreeRTOS
37+
38+
* **hello_freertos** (*hello_freertos*): Hello World application for using FreeRTOS. TKJHAT not needed
39+
* **hello_blink_freertos** (*hello_blink_freertos*): Same as before but the blinking happens inside a FreeRTOS task.
40+
41+
### Hello JTKJHAT
42+
43+
* **hello_hat** (*hello_hat*): Hello World application for the JTKHAT SDK. It tests the buzzer, device LED and the LCD screen
44+
* **hat_example** (*hat_example*): Code not finished yet. Few examples to test running different sensors using different tasks. Do not use yet.
45+
* **hello_dual_cdc** (*hello_dual_cdc*): Example of using the usb-serial-debug to open two different serial ports via USB using TinyUSB library. One of the ports uses the helpers of the usb-serial-debug library instead of ```printf``` to send string to the terminal.
46+
* **hat_imu_ex** (*hat_imu_ex*): Example on how to use the IMU sensor in a FreeRTOS task to collect acceleration and gyroscope data and printing it in the terminal.
47+
* **hat_imu_display** (*hat_imu_display*): Same as before but module of acceleration data is presented in the LCD display. Two FreeRTOS tasks in use: one to collect data and other to print datat in the LCD.
48+
* **hat_imu_cdc_ex**(*hat_imu_cdc_ex*): Another example of collecting data using the IMU. In this case data is sent to two different terminals using the usb-serial-debug library.
49+
* **hello_microphone** (*test_microphone*): Application that configures and sets up the microphone using the JTKJSDK api. Collects microphone sample. PCM samples are sent to the terminal. The script located at *tools/record_audio.sh* can be used to collect the samples and added to a .wav file that can be played. It needs to have Sox as dependency. The file *tools/play_stream_audio.sh* plays directly the audio, storing it first in a buffer.
50+
51+
### Computer System Course specific examples
52+
53+
* **compilation_errors** (*compilation_error*): This code is a broken code that is used in the lab session 2 of the course [Computer Systems](https://lovelace.oulu.fi/tietokonej%C3%A4rjestelm%C3%A4t/tietokonej%C3%A4rjestelm%C3%A4t/)
54+
* **hello_serial_client** (*hello_serial_client*): It uses the protocol of the [https://github.com/Gr701/serial_client|Serial-client] application, used to translate ```.``` and ```-``` to Morse code. It only sends data to the application.
55+
* **hello_serial_bidirectional_client** (*hello_serial_client*): It uses the protocol of the [https://github.com/Gr701/serial_client|Serial-client] application, used to translate ```.``` and ```-``` to Morse code. It sends data to the application and is able to process received data and echo it as a comment to the Serial-client application.
56+
57+
458
## Installation in Linux with VSCode extension
559

660
This section explains how to install and configure a **development environment for Raspberry Pi Pico (and Pico 2)** using **Lubuntu 24.04**.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
PORT="${1:-/dev/ttyACM0}" # serial device
5+
SR="${2:-8000}" # sample rate Hz (default 16 kHz)
6+
7+
# Put TTY in raw, 8-bit mode (baud ignored for USB CDC but fine to set)
8+
stty -F "$PORT" 115200 raw -echo -echoe -echok
9+
10+
# Open the port once (shared FD) and auto-close on exit
11+
exec 3<> "$PORT"
12+
trap 'exec 3>&- 3<&- || true' EXIT
13+
14+
# Wait until device prints READY (consumes that line)
15+
grep -m1 -a "READY" <&3 >/dev/null
16+
17+
# Stream the remaining bytes (binary PCM) straight to aplay
18+
exec aplay -q -f S16_LE -r "$SR" -c 1 <&3
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
PORT="${1:-/dev/ttyACM0}" # optional arg 1: serial device
5+
SECS=5
6+
SR=8000
7+
BYTES=$((SECS * SR * 2)) # 16-bit mono => 2 bytes/sample
8+
OUT=mic_5s_$(date +%Y%m%d_%H%M%S).raw
9+
10+
echo "Preparing the output"
11+
# Put TTY in raw, 8-bit clean mode
12+
stty -F "$PORT" raw -echo -echoe -echok
13+
14+
# Open the port once for read+write on FD 3
15+
exec 3<> "$PORT"
16+
trap 'exec 3>&- 3<&- || true' EXIT
17+
18+
echo "Collecting data"
19+
# Read exactly the expected byte count into the file
20+
head -c "$BYTES" <&3 > "$OUT"
21+
22+
# All good — close and report
23+
exec 3>&- 3<&-
24+
echo "done: File written in $OUT"
25+
26+
# Quick play/convert hints
27+
echo "Play it: aplay -f S16_LE -r $SR -c 1 \"$OUT\""
28+
echo "To WAV: sox -r $SR -e signed -b 16 -c 1 \"$OUT\" \"${OUT%.raw}.wav\""

libs/TKJHAT/docs/Doxyfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ OUTPUT_DIRECTORY = out
33
GENERATE_HTML = YES
44
GENERATE_LATEX = NO
55
FULL_PATH_NAMES = NO
6+
STRIP_FROM_PATH = ../include/tkjhat
67
RECURSIVE = NO
78
GENERATE_TREEVIEW = YES
89
INPUT = ../include/tkjhat/sdk.h \
@@ -15,6 +16,12 @@ CALL_GRAPH = YES
1516
USE_MDFILE_AS_MAINPAGE = overview.md
1617
EXTRACT_PRIVATE = NO
1718
EXTRACT_STATIC = NO
19+
SHOW_FILES = YES
20+
SHOW_DIRECTORIES = NO
21+
GENERATE_GROUPS = YES
22+
EXTRACT_ALL = YES
23+
SHOW_NAMESPACES = YES
24+
1825

1926
# Diagrams
2027
HAVE_DOT = YES

libs/TKJHAT/docs/overview.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,34 @@ This SDK provides a minimal C API for working with the onboard sensors and actua
55

66
---
77

8-
## Actuators
8+
## Peripherals connected to GPIO pins
9+
10+
| Device | Interface | Pin name(s) | Notes |
11+
|------------------------|----------------------|----------------------------------|-------|
12+
| Red LED | GPIO 14 | `RED_LED_PIN` / `LED1` | Onboard indicator LED (also referred to as “onboard LED”) |
13+
| RGB LED | GPIO 18:R, 19:G, 20:B| `RGB_LED_R`, `RGB_LED_G`, `RGB_LED_B` | Common-anode LED, driven via PWM |
14+
| Buzzer | GPIO 17 | `BUZZER_PIN` | Digital output, simple square-wave control |
15+
| PDM MEMS Microphone | GPIO 16 (DATA), GPIO 15 (CLK) | `PDM_DATA`, `PDM_CLK` | Uses PIO + [Arm Developer Pico microphone library](https://github.com/ArmDeveloperEcosystem/microphone-library-for-pico/tree/main) |
916

10-
| Device | Interface | Notes |
11-
|---------------|-----------|-------|
12-
| Red LED | GPIO 14 | Onboard indicator LED (also referred to as “onboard LED”) |
13-
| RGB LED | GPIO 18:R, 19:G, 20:B | Common-anode LED, driven via PWM |
14-
| Buzzer | GPIO 17 | Digital output, simple square-wave control |
15-
| OLED display (SSD1306) | I²C (0x3C) | 128×64 pixels, text & graphics via [SSD1306 datasheet](https://cdn-shop.adafruit.com/datasheets/SSD1306.pdf) |
1617

1718
---
1819

19-
## Sensors
20+
## Peripherals connected to I²C
21+
22+
The default I²C bus uses SDA = GPIO 12 (*DEFAULT_I2C_SDA_PIN*) and SCL = GPIO 13 (DEFAULT_I2C_SCL_PIN ).
2023

2124
| Sensor | Interface | Address | Datasheet |
2225
|---------------|-----------|---------|-----------|
23-
| Ambient light sensor (VEML6030) | I²C | 0x10 | [Vishay VEML6030](https://www.vishay.com/docs/84366/veml6030.pdf) |
24-
| Temperature & humidity (HDC2021) | I²C | 0x40 | [TI HDC2021](https://www.ti.com/lit/ds/symlink/hdc2021.pdf) |
25-
| IMU (ICM-42670, accel+gyro) | I²C | 0x69 | [TDK ICM-42670](https://invensense.tdk.com/wp-content/uploads/2021/07/DS-000451-ICM-42670-P-v1.0.pdf) |
26-
| PDM MEMS Microphone | GPIO 16 (DATA), GPIO 15 (CLK) || Uses PIO + [Arm Developer Pico microphone library](https://github.com/ArmDeveloperEcosystem/microphone-library-for-pico/tree/main) |
26+
| Ambient light sensor (VEML6030) | I²C | VEML6030_I2C_ADDR (0x10) | [Vishay VEML6030](https://www.vishay.com/docs/84366/veml6030.pdf) |
27+
| Temperature & humidity (HDC2021) | I²C | HDC2021_I2C_ADDRESS (0x40) | [TI HDC2021](https://www.ti.com/lit/ds/symlink/hdc2021.pdf) |
28+
| IMU (ICM-42670, accel+gyro) | I²C | ICM42670_I2C_ADDRESS (0x69) | [TDK ICM-42670](https://invensense.tdk.com/wp-content/uploads/2021/07/DS-000451-ICM-42670-P-v1.0.pdf) |
29+
| OLED display (SSD1306) | I²C | SSD1306_I2C_ADDRESS (0x3C) | [SSD1306 datasheet](https://cdn-shop.adafruit.com/datasheets/SSD1306.pdf) |
30+
2731

2832
---
2933

3034
## Notes
3135

32-
- The default I²C bus uses SDA = GPIO 12 and SCL = GPIO 13.
3336
- The SDK is intended for teaching: APIs are simplified, and defaults (e.g. 100 Hz ODR, ±4 g accelerometer) are chosen to be practical.
3437

3538
---

libs/TKJHAT/include/tkjhat/pins.h

Lines changed: 97 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,112 @@
1-
/*
2-
Version 0.8
31

4-
MIT License
52

6-
Copyright (c) 2025 Raisul Islam, Iván Sánchez Milara
73

8-
Permission is hereby granted, free of charge, to any person obtaining a copy
9-
of this software and associated documentation files (the "Software"), to deal
10-
in the Software without restriction, including without limitation the rights
11-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12-
copies of the Software, and to permit persons to whom the Software is
13-
furnished to do so, subject to the following conditions:
14-
15-
The above copyright notice and this permission notice shall be included in all
16-
copies or substantial portions of the Software.
17-
18-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24-
SOFTWARE.
25-
*/
4+
/**
5+
* @file tkjhat/pins.h
6+
* \author Iván Sánchez Milara
7+
* @brief Macros including the pins of the HAT.
8+
*
9+
*
10+
* @version 0.83
11+
*/
12+
2613

2714
/* =========================
2815
* Board / pin macros
2916
* ========================= */
3017

31-
#define DEFAULT_I2C_SDA_PIN 12
32-
#define DEFAULT_I2C_SCL_PIN 13
18+
/**
19+
* @defgroup board_pins Board and pin definitions
20+
* @brief Default GPIO assignments for peripherals on the JTKJ HAT.
21+
*
22+
* @details
23+
* These macros define the GPIO pin numbers for peripherals and interfaces
24+
* used by the SDK. They can be referenced directly or overridden at compile time
25+
* if custom wiring is used.
26+
*
27+
* **Default pinout:**
28+
* | Function | Macro | GPIO | Notes |
29+
* |-----------|--------|------|-------|
30+
* | I²C SDA | @ref DEFAULT_I2C_SDA_PIN | 12 | Default I²C data |
31+
* | I²C SCL | @ref DEFAULT_I2C_SCL_PIN | 13 | Default I²C clock |
32+
* | UART0 | @ref DEFAULT_UART_0 | 0 | Primary UART port |
33+
* | UART1 | @ref DEFAULT_UART_1 | 1 | Secondary UART port |
34+
* | SW1 | @ref SW1_PIN / @ref BUTTON1 | 2 | User button 1 |
35+
* | SW2 | @ref SW2_PIN / @ref BUTTON2 | 22 | User button 2 |
36+
* | Red LED | @ref RED_LED_PIN / @ref LED1 | 14 | Onboard LED |
37+
* | RGB LED R | @ref RGB_LED_R | 18 | RGB red channel |
38+
* | RGB LED G | @ref RGB_LED_G | 19 | RGB green channel |
39+
* | RGB LED B | @ref RGB_LED_B | 20 | RGB blue channel |
40+
* | Buzzer | @ref BUZZER_PIN | 17 | Active buzzer |
41+
* | PDM DATA | @ref PDM_DATA | 16 | Microphone data line |
42+
* | PDM CLK | @ref PDM_CLK | 15 | Microphone clock line |
43+
* | VEML6030 Interrupt | @ref VEML6030_INTERRUPT | 9 | Light sensor INT pin |
44+
* | HDC2021 Interrupt | @ref HDC2021_INTERRUPT | 21 | Temp/humidity INT pin |
45+
* | ICM42670 Interrupt | @ref ICM42670_INT | 6 | IMU INT1 pin |
46+
*
47+
* @note These pin numbers correspond to the Raspberry Pi Pico GPIO numbers.
48+
* @{
49+
*/
50+
51+
/** @name I²C Bus (default)
52+
* Pins used for the I²C bus connected to sensors and the display.
53+
* @{
54+
*/
55+
#define DEFAULT_I2C_SDA_PIN 12 /**< I²C data pin (SDA) */
56+
#define DEFAULT_I2C_SCL_PIN 13 /**< I²C clock pin (SCL) */
57+
/** @} */
58+
59+
/** @name UART interfaces
60+
* @{
61+
*/
62+
#define DEFAULT_UART_0 0 /**< UART0 identifier */
63+
#define DEFAULT_UART_1 1 /**< UART1 identifier */
64+
/** @} */
65+
66+
/** @name Buttons / Switches
67+
* @{
68+
*/
69+
#define SW1_PIN 2 /**< SW1 button pin (GPIO 2) */
70+
#define SW2_PIN 22 /**< SW2 button pin (GPIO 22) */
71+
#define BUTTON1 SW1_PIN /**< Alias for SW1 button */
72+
#define BUTTON2 SW2_PIN /**< Alias for SW2 button */
73+
/** @} */
3374

34-
#define DEFAULT_UART_0 0
35-
#define DEFAULT_UART_1 1
75+
/** @name LEDs
76+
* @{
77+
*/
78+
#define RED_LED_PIN 14 /**< Onboard red LED pin (GPIO 14) */
79+
#define LED1 RED_LED_PIN /**< Alias for red LED */
80+
/** @} */
3681

37-
#define SW1_PIN 02
38-
#define SW2_PIN 22
39-
#define BUTTON1 SW1_PIN
40-
#define BUTTON2 SW2_PIN
82+
/** @name RGB LED (common-anode)
83+
* @{
84+
*/
85+
#define RGB_LED_R 18 /**< RGB LED red channel (GPIO 18) */
86+
#define RGB_LED_G 19 /**< RGB LED green channel (GPIO 19) */
87+
#define RGB_LED_B 20 /**< RGB LED blue channel (GPIO 20) */
88+
/** @} */
4189

42-
#define RED_LED_PIN 14
43-
#define LED1 RED_LED_PIN
90+
/** @name Audio
91+
* @{
92+
*/
93+
#define BUZZER_PIN 17 /**< Buzzer control pin (GPIO 17) */
94+
/** @} */
4495

45-
#define RGB_LED_R 18
46-
#define RGB_LED_G 19
47-
#define RGB_LED_B 20
96+
/** @name PDM Microphone
97+
* @{
98+
*/
99+
#define PDM_DATA 16 /**< Microphone data input (GPIO 16) */
100+
#define PDM_CLK 15 /**< Microphone clock output (GPIO 15) */
101+
/** @} */
48102

49-
#define BUZZER_PIN 17
103+
/** @name Interrupts from Sensors
104+
* @{
105+
*/
106+
#define VEML6030_INTERRUPT 9 /**< Ambient light sensor interrupt pin */
107+
#define HDC2021_INTERRUPT 21 /**< Temperature & humidity sensor interrupt pin */
108+
#define ICM42670_INT 6 /**< IMU interrupt pin */
109+
/** @} */
50110

51-
#define PDM_DATA 16
52-
#define PDM_CLK 15
53111

54-
#define VEML6030_INTERRUPT 9
55-
#define HDC2021_INTERRUPT 21
56-
#define ICM42670_INT 6
112+
/** @} */ /* end of group board_pins */

0 commit comments

Comments
 (0)