# Workshops

## 1. ภาพรวม IMU Sensor

### 1.1 BMI270 - 6-Axis IMU

<figure><img src="/files/0MrVlepnYGPARTbw2NkD" alt=""><figcaption></figcaption></figure>

### 1.2 หลักการทำงาน Accelerometer

<figure><img src="/files/7y42V4A5UUT1xtX2Umri" alt=""><figcaption></figcaption></figure>

เมื่อวางราบ (face up):

* acc\_x ≈ 0 m/s²
* acc\_y ≈ 0 m/s²
* acc\_z ≈ +9.81 m/s² (1g pointing up)

เมื่อเอียง:

* acc ถูกแบ่งไปตามแกนต่างๆ
* Magnitude (ขนาด) ยังคง ≈ 9.81 m/s²

### 1.3 I2C Communication

<figure><img src="/files/XT2Hdi0afGEi5IwJpsey" alt=""><figcaption></figcaption></figure>

### 1.4 การแปลงค่า Raw → Physical Units

<figure><img src="/files/0yvjZU7DDijiS6xRalnG" alt="" width="375"><figcaption></figcaption></figure>

```c
/* BMI270 Raw Data: int16_t (-32768 to +32767) */

/* สูตรแปลง Accelerometer (Range ±2g) */
               raw_value × g_range × 9.80665
acc (m/s²) = ─────────────────────────────────
                     2^(bit_width - 1)

/* สูตรแปลง Gyroscope (Range ±2000 dps) */
              raw_value × dps_range × 0.01745
gyro (rad/s) = ────────────────────────────────
                     2^(bit_width - 1)
```

```c
/* BMI270 Raw Data: int16_t (-32768 to +32767) */

/* สูตรแปลง Accelerometer (Range ±2g) */
acc (m/s²) = (raw_value × g_range × 9.80665) / 2^(bit_width - 1)

/* สูตรแปลง Gyroscope (Range ±2000 dps) */
gyro (rad/s) = (raw_value × dps_range × 0.01745) / 2^(bit_width - 1)

```

***

## 2. C Programming Review

### 2.1 Arrays สำหรับ Sensor Buffer

```c
/* Array declaration */
#define BUFFER_SIZE  100
float sensor_buffer[BUFFER_SIZE];    /* 100 samples */
int16_t imu_data[6];                 /* ax,ay,az,gx,gy,gz */

/* Array size macro - ใช้บ่อยมาก! */
#define ARRAY_SIZE(arr)  (sizeof(arr) / sizeof((arr)[0]))

/* ตัวอย่าง: circular buffer index */
uint32_t index = 0;
sensor_buffer[index] = new_value;
index = (index + 1) % BUFFER_SIZE;  /* Wrap around */
```

### 2.2 Structs สำหรับ Sensor Data

```c
/* Vector 3D - ใช้บ่อยกับ sensor data */
typedef struct {
    float x;
    float y;
    float z;
} vector3f_t;

/* IMU Complete Data */
typedef struct {
    vector3f_t acceleration;  /* m/s² */
    vector3f_t gyroscope;     /* rad/s */
    uint32_t timestamp_ms;
} imu_data_t;

/* Usage */
imu_data_t sensor;
sensor.acceleration.x = 0.0f;
sensor.acceleration.z = 9.81f;
```

### 2.3 Pointers และ Pass-by-Reference

```c
/* Pass by pointer - efficient for structs */
void process_data(const imu_data_t *data)  /* read-only */
{
    printf("X: %.2f\n", data->acceleration.x);
}

void update_data(imu_data_t *data)  /* can modify */
{
    data->timestamp_ms = get_time_ms();
}

/* Usage */
imu_data_t my_data;
process_data(&my_data);  /* Pass address */
update_data(&my_data);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.aic-eec.com/interfacing-with-infineon-psoc-tm-edge/sensor-interfacing/workshops.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
