# Edge AI :: Machine Learning for PSoC6 using Edge-Impulse

## Set up Environment

### Install Infineon CyProgrammer, Nodejs, and edge-impulse

1. [Infineon ](https://softwaretools.infineon.com/tools/com.ifx.tb.tool.cypressprogrammer)[CyProgrammer](https://softwaretools.infineon.com/tools/com.ifx.tb.tool.cypressprogrammer) : Use to flash firmware images into the target.
2. Install [Nodejs](https://nodejs.org/en/) v14 or higher on your computer.

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2FEFcOxz2pl2N5WCkdiweY%2Fimage.png?alt=media&#x26;token=ce61f82d-50a7-4a10-aab9-f078f39b2984" alt=""><figcaption><p>Infineon CyProgrammer</p></figcaption></figure>

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2FysWf5u2uwYSRnjryHLWc%2Fimage.png?alt=media&#x26;token=a50ddd66-fe9b-4f90-8d5a-c0785b7e7549" alt=""><figcaption><p>Nodejs</p></figcaption></figure>

3. Install the CLI tools via:&#x20;

```
npm install -g edge-impulse-cli --force
```

### Board Connecting

* [Download the latest  Edge Impulse ](https://cdn.edgeimpulse.com/firmware/infineon-cy8ckit-062s2.zip)[firmware](https://cdn.edgeimpulse.com/firmware/infineon-cy8ckit-062s2.zip), and unzip the file. Once downloaded, unzip it to obtain the firmware-infineon-cy8ckit-062s2.hex file, which are using in following step.

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2FfIfPnvtR6xmYQk01vfht%2Fimage.png?alt=media&#x26;token=201ba01a-9642-45f2-b07b-09fe75f83b4a" alt=""><figcaption><p>Connect the board to your computer</p></figcaption></figure>

* You can use [Infineon ](https://softwaretools.infineon.com/tools/com.ifx.tb.tool.cypressprogrammer)[CyProgrammer](https://softwaretools.infineon.com/tools/com.ifx.tb.tool.cypressprogrammer) to flash your CY8CKIT-062S2 Pioneer Kit with our [base firmware image](https://cdn.edgeimpulse.com/firmware/infineon-cy8ckit-062s2.zip). To do this, first select your board from the dropdown list on the top left corner. Make sure to select the item that starts with CY8CKIT-062S2-43012:

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2FyMzDEfhoHFwZl5mUjtU4%2Fimage.png?alt=media&#x26;token=de113e0f-c2c1-42c6-9c5f-32d9434f2ede" alt=""><figcaption><p>Open Cypress program and select the board CY8CKIT-062s2-43012</p></figcaption></figure>

Then select the base firmware image file you downloaded in the first step above (i.e., the file named firmware-infineon-cy8ckit-062s2.hex). You can now press the Connect button to connect to the board, and finally the Program button to load the base firmware image onto the CY8CKIT-062S2 Pioneer Kit.

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2FNZn2Zmnhz6w2USPU4q5D%2Fimage.png?alt=media&#x26;token=46f18790-b0df-4cc7-93e4-5f2f2ee23c1e" alt=""><figcaption></figcaption></figure>

* Create account <https://studio.edgeimpulse.com/signup>
* Open Edge impulse through command prompt:

  &#x20;`edge-impulse-daemon`

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2FYuNHzwue0ok3zmt9GegI%2Fimage.png?alt=media&#x26;token=9ed5f510-fa43-4635-b461-da98d1330cca" alt=""><figcaption></figcaption></figure>

### Let's start with Edge-Impulse

&#x20;  That's all! Your device is now connected to Edge Impulse. To verify this, go to [your Edge Impulse project](https://studio.edgeimpulse.com/studio/select-project?autoredirect=1), and click Devices on the left sidebar. The device will be listed there:

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2FQGu29xMBM41tnioIBAZ5%2Fimage.png?alt=media&#x26;token=891f7daf-ee4c-45c7-8bf5-dfeecb1be3b6" alt=""><figcaption><p>Device</p></figcaption></figure>

## Collecting your first data

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2FogWuJ0v8oXdsgoe8ufot%2Fimage.png?alt=media&#x26;token=10f49f6c-9f75-4ef3-9940-6d0e3b5a8dad" alt=""><figcaption><p>Collecting the dataset</p></figcaption></figure>

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2F3mRNuJ29oxlLj6O9SmGF%2Fimage.png?alt=media&#x26;token=8acbb450-6ade-478f-ac53-4ba927921598" alt=""><figcaption><p>Machine learning</p></figcaption></figure>

* Make sure your device is connected.&#x20;
* Go to the Data acquisition tab in the studio. This is where your raw data is stored.&#x20;
* Choose "Record new data."&#x20;
* Select your device and set the label to "updown."&#x20;
* Set the sample length to 10,000, which means recording for 10 seconds.&#x20;
* Choose the Built-in accelerometer as the sensor.&#x20;
* Set the frequency to 62.5Hz, which is how often data points are recorded per second.

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2FylHtLUq2oanSHAcViojA%2Fimage.png?alt=media&#x26;token=d61d9f2d-4637-422f-9097-2ecbd4361edd" alt=""><figcaption><p>Prepare all parameters before collecting the data.</p></figcaption></figure>

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2FiGeqG5wPCAKX2TgEHWfp%2Fimage.png?alt=media&#x26;token=58c54729-1bf4-4ad3-bcb9-c126b7a50335" alt=""><figcaption><p>Dataset result</p></figcaption></figure>

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2FiEsUEUggIyPlJJHPMQQg%2Fimage.png?alt=media&#x26;token=e505ed32-d7f3-4d7f-ac08-6c9badd753aa" alt=""><figcaption><p>Download Dataset</p></figcaption></figure>

## Use Prebuild Dataset&#x20;

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2F3mxB0KXnwlf2EnlUrY9A%2Fimage.png?alt=media&#x26;token=aa5cb63c-a0c7-48ae-9e19-660f77ea9ccd" alt=""><figcaption><p>Training and Testing Data</p></figcaption></figure>

Alternately, you can import this dataset to your Edge Impulse project using the Edge Impulse CLI Uploader. If you haven't done so, follow the Installation instructions.

* Download the [gestures dataset](https://cdn.edgeimpulse.com/datasets/gestures.zip).
* Unzip the file in a location of your choice.&#x20;
* Open a modus-shell and navigate to the place where you extracted the file.

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2FJrXVGygYq9L15WGrWiit%2Fimage.png?alt=media&#x26;token=14773330-520b-4893-9dd7-9ebb95889b15" alt=""><figcaption><p>modus-shell</p></figcaption></figure>

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2FrOQ8g1FY2p1nnmTW6P7k%2Fimage.png?alt=media&#x26;token=18cfd257-4ace-4643-bfb1-e92e7eb220ef" alt="" width="342"><figcaption><p>Open a modus-shell and navigate to the place where you extracted the file.</p></figcaption></figure>

```
$ edge-impulse-uploader --clean
```

* Add training Dataset

```
$ edge-impulse-uploader --category training training/*.cbor
```

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2F1KYYmvE97NRn6TJoiShW%2Fimage.png?alt=media&#x26;token=6496e98a-4947-4611-865a-a0fbf041012a" alt=""><figcaption></figcaption></figure>

```tcl
$ edge-impulse-uploader --category testing testing/*.cbor
```

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2FCuTjKvt3XQ33RQ2tVpkN%2Fimage.png?alt=media&#x26;token=86f1c7e4-fc92-4218-beb2-fd6611a49760" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2F8sQl4ULxpUdh3eAtBGI5%2Fimage.png?alt=media&#x26;token=c5e8d873-062f-4b83-b811-c0f032c7f77b" alt=""><figcaption><p>After adding the dataset, you will see the Training and Testing data on Edge-Impulse.</p></figcaption></figure>

## Design an Impulse

In the studio go to Create impulse, set the window size to 2000 (you can click on the 2000 ms. text to enter an exact value), the window increase to 80, and add the 'Spectral Analysis', and 'Classification' blocks. Then click Save impulse.

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2Fgqx2bEpr8E4ofrNmNlkm%2Fimage.png?alt=media&#x26;token=3cbc4ea0-2e05-4936-8274-614f087395c8" alt=""><figcaption><p>Create Impulse</p></figcaption></figure>

* Go to Spectral features => Save parameters => Generate features

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2FubARJZwAz9pzTaEnpQwy%2Fimage.png?alt=media&#x26;token=7f7b0133-53a3-49c5-9261-145cc48e4970" alt=""><figcaption><p>Spectral features</p></figcaption></figure>

## Training model

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2F2JTmb2fBaZjIkvxTwHbZ%2Fimage.png?alt=media&#x26;token=c7d874b8-6490-470d-b6e2-7ccae25061ae" alt=""><figcaption></figcaption></figure>

### Classifier

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2FLwKz95HstrRZrMVBFvLj%2Fimage.png?alt=media&#x26;token=d2cd9686-30b4-492d-a7ed-0d6710463d07" alt=""><figcaption><p>Select Classifier, Add Number of training cycles, Start Training. </p></figcaption></figure>

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2Fy14gqscwJiMeyT7oIKdU%2Fimage.png?alt=media&#x26;token=a54a201f-3a5e-4d86-b06d-ec5c9b07643b" alt=""><figcaption><p>Training result</p></figcaption></figure>

### Live Classification

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2FIKXp8z76YL2lW3Llak8J%2Fimage.png?alt=media&#x26;token=6c56b2aa-63bd-4e2a-a73a-da9d6ea1cb5d" alt=""><figcaption><p>Select Device</p></figcaption></figure>

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2FHSg3Ik2wfaR0GFuvyKsy%2Fimage.png?alt=media&#x26;token=b7ab75a5-e959-4816-ab9e-a1cc22a380f8" alt=""><figcaption><p>Classification Result</p></figcaption></figure>

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2Fgs65EHdcvnOLt5Izlpt2%2Fimage.png?alt=media&#x26;token=fdf9c6be-5dd9-4f4a-bc4a-62b6a6256fa0" alt=""><figcaption><p>Model Testing Result</p></figcaption></figure>

## Deploy the model

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2FR0ZVRXeGZsXeTvxIXt30%2Fimage.png?alt=media&#x26;token=103f1e19-201d-4492-b77e-cd3d417a416e" alt=""><figcaption><p>Model Deployer</p></figcaption></figure>

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2FliDPJYtd7kSitmIFjKFa%2Fimage.png?alt=media&#x26;token=5832d992-6fe6-4dd9-959f-f427ad6079cd" alt=""><figcaption><p>Build Firmware for PSoC board</p></figcaption></figure>

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2FvPK9KQBoYkdRFknEz2xi%2Fimage.png?alt=media&#x26;token=22a1e525-7ded-455a-b7c5-92cf4c0c20b8" alt=""><figcaption><p>Built firmware successfully</p></figcaption></figure>

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2FensIhqQgc7Qwsf3h2SLF%2Fimage.png?alt=media&#x26;token=fb6aac07-9d8d-4ada-bacf-6c330f44525d" alt=""><figcaption><p>Add ml firmware to PSoC using Cypress Program</p></figcaption></figure>

We can connect to the board's newly flashed firmware over serial. Open a terminal and run:&#x20;

```
$ edge-impulse-run-impulse
```

<figure><img src="https://1856353139-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MClo3nC-1US0rbK8Qau%2Fuploads%2FujGxordTKWdbbuU18AlX%2Fimage.png?alt=media&#x26;token=ffd5070a-d6db-42e0-a572-893ea4295fac" alt=""><figcaption><p>Real Time Classification</p></figcaption></figure>

Ref: <https://docs.edgeimpulse.com/docs/~/revisions/9dKGATK7EnFnYNRMlqcb/pre-built-datasets/continuous-gestures>


---

# 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/iot-development-with-infineon-psoc-tm-6-and-bdh-platform/edge-ai-machine-learning-for-psoc6-using-edge-impulse.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.
