Go back to Product Documents Navigation
Go back to KOI Documents Navigation
Please refer to this page on how to utilize the various functions of the KOI using micropython.
Importing KOI library
| from koi import * |
Basics
LCD Orientation
| lcd.rotation(0) |
Changes LCD orientation.
- 0 for front facing, 1 for back facing.
Drawing Strings
| drawString(x, y, string, delay) |
Draws a string on the LCD.
- X, Y: Coordinates represent top left corner of string.
- String: String.
- Delay: Text duration.
Taking and showing pictures
|
img.save("s1.jpg") |
Taking and showing pictures.
Getting button values
|
btnAValue() |
Obtains button values.
- Returns 1 when pressed, 0 when not pressed.
Sample Program
|
#/bin/python |
Image Classifier
Initiate Classifier
|
cla.reset() |
Initiates the classifier.
Feature extraction
|
cla.addImage("tag") |
Extract features and add tag.
- tag: object name, maximum 40 items, 40 pictures
Image Classifying
|
cla.getImageTag() |
Classify the image, returns tag.
Classifier Event Triggers
|
while cla.getImageTag()=='tag': |
Triggers an event on classification.
Saving and Loading Classifier Models
|
cla.save("abc.json") |
Save or load classifier models.
Sample Program
|
#Model Training |
|
#Model Running |
Face Detection
Classifier Event Triggers
|
yoloinit() |
Load face model.
Track face
|
trackface() |
Tracks the face, returns a list.
Sample Program
|
#/bin/python |
Geometric Shape Tracking
Track Lines
|
findLines() |
Find lines, returns a list.
Track Circles
|
findCircle(threshold) |
Find circles, returns a list.
- threshold: adjust this value to adjust sensitivity, default is 4000.
Track Rectangles
|
findRect(threshold) |
Find rectangles, returns a list.
- threshold: adjust this value to adjust sensitivity, default is 4000.
Sample Program
|
from koi import * |
Color Blob Tracking
Calibrates Color
|
colorCalibrate() |
Calibrates color for tracking.
Finds Color Blob
|
findBlob() |
Finds color blob, returns a list.
Finds Line
|
findLinearRegress() |
Finds line, returns a list.
Sample Program
|
from koi import * |
Barcode and QR code Recognition
QR Code Recognition
|
findQRCode() |
Finds QR code, returns content of QR code.
Barcode Recognition
|
findBarcode() |
Finds Barcode, returns content of barcode.
AprilTag Recognition
|
findAprilTag() |
Finds Apriltag, returns content of Apriltag.
Sample Program
|
from koi import * |
Voice Recognition
Record and Play
|
speech.recordWav('hi.wav') |
Records and plays a wav file.
Calibrates Noise Level
|
speech.noiseTap() |
Calibrates the noise level, mandatory before voice recognition.
Adds Voice Command
|
speech.addCommand('hi') |
Adds a voice command.
Recognizes Voice Command
|
speech.getCommand() |
Recognizes and returns the command.
Saves Voice Model
|
speech.saveClass('name.json') |
Saves the voice model.
Loads Voice Model
|
speech.loadClass('name.json') |
Loads the voice model.
Sample Program
|
# Rec and Play |
|
#Voice Recognition |
IoT
Connecting to WiFi
|
wifi.joinap(str("apname"),str("password")) |
Connects to WiFi.
IP Address
|
wifi.ipaddr() |
Return IP address.
Connects to MQTT Broker.
|
wifi.mqtthost(host) |
Connects to MQTT Broker.
- host: MQTT host address
Subscribes Topic
|
wifi.mqttsub(topic) |
Connects to MQTT Broker.
- topic: topic to subscribe
Publishes Message to Topic
|
wifi.mqttsub(topic, message) |
Publishes a message to topic.
- topic: topic to publish.
- message: message to publish.
Reads MQTT message
|
wifi.mqttread(topic) |
Reads topic message.
- topic: topic to read from, returns a list.
Sample Program
|
from koi import * |
Face Recognition
Face Recognition
|
face=baiduFace(op=1) |
Runs face recognition once.(WiFi required)
Face Parameters
|
face['parameter'] |
Returns result from face recognition.
parameter:
- face_token: unique face token for each face
- location: coordinates, size of face
- gender: gender of person
- expression: emotion of person
- angle: tilt angle of face
- mask: true if person is wearing a mask
- age: age of person
Adding Faces to a Group
|
baiduFace(op=2, token=face['face_token'], group="group", name="name") |
Adds a face to the face group.
Searching Faces from a Group
|
baiduFace(op=3, token=face['face_token'], group="group") |
Searches a face from a group, returns name and confidence.
Sample Program
|
from koi import * |
Q&A
Q1: KOI’s display is laggy.
A1: Please enable the screen refresh.
Q2: KOI does not run the program I uploaded.
A2: Please restart the KOI because it was still running the original main.py.
Q3: Can I connect other modules using the 4-Pin Port?
A3: No, this port is for connecting to Micro:bit only.
Q4: KOI’s LCD is reversed.
A4: Please use the LCD orientation command.
If you have any question, please feel free to contact us at Discord, we will always be there to help.
KittenBot Team

