# KOI MakeCode Quickstart Guide

### **Connecting to Micro:bit**

#### **1. Connecting to Armourbit**

It is easier to connect to an Armourbit because they both use PH2.0 connectors.

When using KOI with an Armourbit, KOI needs an extra 5V power source.

Using the USB port on the battery box, 5V power can be supplied to KOI. (See figure below)

<figure><img src="https://kittenbothk.readthedocs.io/en/latest/_images/armourbit_connection1-1.png" alt=""><figcaption></figcaption></figure>

<figure><img src="https://kittenbothk.readthedocs.io/en/latest/_images/armourbit_connection2-3.png" alt=""><figcaption></figcaption></figure>

#### **2. Connecting to Robotbit Edu**

As Robotbit can supply 5V power, there is no need to power KOI with an USB cable.

Please pay attention in connecting the power wires to the Robotbit.

**xxx DO NOT connect it in the wrong way. xxx**

Or KOI may not function correctly, it may even suffer damage.

Using the cable included with KOI, connect KOI to Robotbit using Dupont wires.

The Dupont wires are arranged as: Black, Red, Blue, Green

These wires correspond to: GND, 5V, P2, P12

<figure><img src="https://kittenbothk.readthedocs.io/en/latest/_images/edu1.png" alt=""><figcaption></figcaption></figure>

<figure><img src="https://kittenbothk.readthedocs.io/en/latest/_images/edu2.png" alt="" width="375"><figcaption></figcaption></figure>

#### **3. Connecting to Robotbit 2.2**

As Robotbit can supply 5V power, there is no need to power KOI with an USB cable.

Please pay attention in connecting the power wires to the Robotbit.

**xxx DO NOT connect it in the wrong way. xxx**

Or KOI may not function correctly, it may even suffer damage.

Using the cable included with KOI, connect KOI to Robotbit using Dupont wires.

The Dupont wires are arranged as: Black, Red, Blue, Green

These wires correspond to: GND, 5V, P1(TX), P12(RX)

```
The (Blue)TX wire must be connected to an analog pin(Pin0-Pin2).
Remember to remove the buzzer jumper when Pin0 is used.
```

<figure><img src="https://kittenbothk.readthedocs.io/en/latest/_images/robotbit_connection1.png" alt=""><figcaption></figcaption></figure>

**Do not connect Red to Ground and Black to 5V!!!**

Ensure the connection is correct and switch the power on.

<figure><img src="https://kittenbothk.readthedocs.io/en/latest/_images/robotbit_connection2.png" alt=""><figcaption></figcaption></figure>

<figure><img src="https://kittenbothk.readthedocs.io/en/latest/_images/robotbit_connection3-1.png" alt=""><figcaption></figcaption></figure>

### **MakeCode Coding Tutorial**

<figure><img src="https://kittenbothk-eng.readthedocs.io/en/latest/_images/mcbanner.png" alt=""><figcaption></figcaption></figure>

<https://makecode.microbit.org>

<figure><img src="https://kittenbothk.readthedocs.io/en/latest/_images/01-14.png" alt=""><figcaption></figcaption></figure>

#### **Loading Extensions**

<figure><img src="https://kittenbothk.readthedocs.io/en/latest/_images/16-1.png" alt=""><figcaption></figcaption></figure>

Search "KOI" in the search bar.

<figure><img src="https://kittenbothk.readthedocs.io/en/latest/_images/koi_search1.png" alt=""><figcaption></figcaption></figure>

Or copy and paste the following link to the search bar.

**<https://github.com/KittenBot/pxt-koi>**

<figure><img src="https://kittenbothk.readthedocs.io/en/latest/_images/03-12.png" alt=""><figcaption></figcaption></figure>

### **Blocks Explained**

This section briefly explains the functions of blocks.

Please refer to tutorials for detailed tutorial and sample codes.

#### **KOI Initialization**

<figure><img src="https://kittenbothk-eng.readthedocs.io/en/latest/_images/042.png" alt=""><figcaption></figcaption></figure>

**1st Block** —— is used for Robotbit.

**2nd Block** —— is used for Armourbit.

#### **Classifier**

It is easier to understand Classifier blocks if you are already familiar with ML5 extension on Kittenblock.

Classifier is used to train and run a customized model for object/scene classification.

<figure><img src="https://kittenbothk-eng.readthedocs.io/en/latest/_images/051.png" alt=""><figcaption></figcaption></figure>

#### **Screenshots and Display**

Micro SD card is required for this function to work.

The Screenshot block creates a png file and saves it onto the SD card. *The name must not contain spaces.*

The Display block finds the file on the SD Card then displays it on the screen for 1 second. *The name must not contain spaces.*

<figure><img src="https://kittenbothk-eng.readthedocs.io/en/latest/_images/061.png" alt=""><figcaption></figcaption></figure>

#### **Show Text**

The print block shows a string at the specific coordinates. It shows the text for 1 second by default, this duration can be changed via delay.

<figure><img src="https://kittenbothk-eng.readthedocs.io/en/latest/_images/071.png" alt=""><figcaption></figcaption></figure>

#### **Display Orientation**

Since KOI cannot detect the direction of the camera, the display orientation has to be set manually so that the image corresponds to camera direction.

There are 2 modes, Front, Back. (Refer to figure below.)

<figure><img src="https://kittenbothk.readthedocs.io/en/latest/_images/081.png" alt=""><figcaption></figcaption></figure>

#### **Circle Tracking**

A threshold can be adjusted, a higher value can filter out more noise and interferences, but tracking difficulty increases as well.

Tracking circle returns 3 values, the coordinates of the circle as well as the radius.

<figure><img src="https://kittenbothk-eng.readthedocs.io/en/latest/_images/091.png" alt=""><figcaption></figcaption></figure>

#### **Rectangle Tracking**

Similar to Circle Tracking, the threshold can be adjusted.

Rectangle Tracking returns the coordinates of the rectangle and its width and height.

<figure><img src="https://kittenbothk-eng.readthedocs.io/en/latest/_images/10.png" alt=""><figcaption></figcaption></figure>

#### **Line Tracing and Color Blob Tracing**

Calibration is required before tracing lines or color blobs.

Line Tracing returns the starting and ending coordinates of the line.

Color Blob Tracing returns the coordinates of the blob and its width and height.

<figure><img src="https://kittenbothk-eng.readthedocs.io/en/latest/_images/111.png" alt=""><figcaption></figcaption></figure>

#### **Barcode/QRCode Recognition**[](https://kittenbothk-eng.readthedocs.io/en/latest/AI%20Cam/makecodeQs.html#barcode-qrcode-recognition)

Scans and returns the contents of the Barcode/QRCode.

The Barcode/QRCode should not be smaller than 3.5cm in width or the resoulution is too small to be recognized.

<figure><img src="https://kittenbothk-eng.readthedocs.io/en/latest/_images/121.png" alt=""><figcaption></figcaption></figure>

#### **Apriltag Recognition**

Apriltags are seldomly used in Hong Kong, this tag is usually used in robots.

Apriltags Recognition returns an id and its geometric attributes.

<figure><img src="https://kittenbothk.readthedocs.io/en/latest/_images/141.png" alt=""><figcaption></figcaption></figure>

#### **Face Detection**

1. Load the face model before detecting faces.
2. Runs the model once to detect faces.
3. Returns the coordinates of the face.

<figure><img src="https://kittenbothk-eng.readthedocs.io/en/latest/_images/151.png" alt=""><figcaption></figcaption></figure>

#### **Recording and Playing wav files**

Micro SD card is required for this function to work.

This function records and plays a wav file from the SD card.

<figure><img src="https://kittenbothk-eng.readthedocs.io/en/latest/_images/17.png" alt=""><figcaption></figcaption></figure>

#### **Using the built-in Buttons**

When the button is pressed, it returns 1, otherwise 0 is returned.

<figure><img src="https://kittenbothk-eng.readthedocs.io/en/latest/_images/02-1.png" alt=""><figcaption></figcaption></figure>

### **Extension Version and Updates**

There may be updates to extensions periodically, please refer to the following link to update/downgrade your extension.

[Makecode Extension Update](https://kittenbothk-eng.readthedocs.io/en/latest/Makecode/makecode_extensionUpdate.html)
