KOI Serial Command API
KOI can be used alongside any MCU capable of serial communication by sending a serial command, this section contains all the command available for the KOI.
The examples provided are in micropython for the Micro:bit, please adapt for the MCU of your preference.
Get Firmware Version
Command: K0
Function: Gets the firmware version of KOI
Returns: K0 (Firmware Version)
from microbit import *
uart.init(baudrate=115200, tx=pin1, rx=pin2)
uart.write('\n\n')
sleep(1000)
uart.write('K0\r\n')
sleep(100)
ret_list = []
if uart.any():
ret = str(uart.readline(), 'UTF-8')
ret = ret.strip()
ret_list = ret.split(' ')
if len(ret_list)>1:
display.scroll(ret_list[1])Taking and Showing Photos
Command: K1 (name.jpg)
Function: Saves the picture with file name.
Command: K2 (name.jpg)
Function: Shows the picture with filename
KOI Button Status
Command: K3
Function: Returns the button status of the 2 buttons
Returns: K3 (Button A Status) (Button B Status)
Display String
Command: K4 x y delay string
Function: Displays sting at (x,y) with a duration determined by delay
Change LCD Orientation
Command: K6 direction
Function: Changes LCD orientation
Direction:
0: Front Camera
1: Back Camera
from microbit import *
uart.init(baudrate=115200, tx=pin1, rx=pin2) uart.write(’\n\n’) sleep(1000)
while True: if button_a.is_pressed() and button_b.is_pressed(): uart.write(’K6 2\r\n’) if button_a.is_pressed(): uart.write(’K6 0\r\n’) if button_b.is_pressed(): uart.write(’K6 1\r\n’)
Circle Tracking
Command: K10 threshold
Function: Tracks the circle on screen, adjust threshold to the sensitivity, the default is 4000.
Returns: K10 (Center X) (Center Y) (Radius)
Rectangle Tracking
Command: K11 threshold
Function: Tracks the rectangle on screen, adjust threshold to the sensitivity, the default is 4000.
Returns: K11 (Center X) (Center Y) (width) (Height)
Linear Regression
Command: K16 color
Function: Calibrates to the color of the line, color refers to color name, the color name is just for reference.
Command: K12 color
Function: Tracks the line using linear regression and the given color name.
Returns: K12 (X1) (Y1) (X2) (Y2)
Color Blob Tracking
Command: K16 color
Function: Calibrates to the color of the blob, color refers to color name, the color name is just for reference.
Command: K15 color
Function: Tracks the color blob with the given color name.
Returns: K5 (X) (Y) (W) (H)
Read QR Code and Barcode
Command: K20
Function: Reads a QR Code
Returns: K20 (Content)
Command: K22
Function: Reads a Barcode
Returns: K22 (Content)
Face Detection
Command: K30
Function: Loads the face model for face detection.
Command: K31
Function: Face Detection for once
Returns: K0 (ID) (X) (Y)
Command: K32
Function: Gets the number of detected faces
Returns: K32 (faces)
Image Classifier
Command: K40
Function: Initiates the Image Classifier
Command: K41 className
Function: Adds a class with className as tag
Command: K42
Function: Image Classify
Returns: K42 (className)
Command: K43 name.json
Function: Saves the model to the SD Card, file extension can be json or bin.
Command: K44 name.json
Function: Loads the model from the SD card.
WiFi and IoT
Command: K50 SSID password
Function: Connects to a WiFi network with the given SSID and password.(Only 2.4GHz network is supported)
Command: K54
Command: Displays the IP Address on the screen
Command: K51 mqttHost clientID port [username] [password]
Function: Connects to a MQTT Broker.
Command: K52 topic
Function: Subscribes a MQTT topic
Command: K53 topic message
Function: Publishes a message to a MQTT topic
Command: K55 topic
Function: Reads data from a MQTT topic
Returns: K55 (message)
Recording and Playback
Command: K61 sound.wav
Function: Records a sound clip and saves to SD card
Command: K62 sound.wav
Function: Playbacks a sound clip from SD card.
Voice Recognition
Command: K63
Function: Calibrates the noise level
Command: K64 id
Function: Adds a command with id as tag.
Command: K65
Function: Recognizes a command.
Returns: K65 (id)
Command: K66 sound.json
Function: Saves the model to the SD Card.
Command: K67 sound.json
Function: Loads a model from SD Card.
Face Recognition
Command: K75
Function: Runs face recognition. (Internet Connection Required)
Returns: K75 (token) (age) (gender) (masked) (emotion)
Command: K76 token groupName faceName
Function: Adds the face token into a group with a given name.
Command: K77 token groupName
Function: Searches a person in a group with a face token.
Returns: K77 faceName
Text to Speech
Command: K78 string
Function: Text to speech. (Internet Connection Required)
KPU Stop
Command: K98
Function: Stops the KPU(Image Classifier/Face Detection)
KOI Restart
Command: K99
Function: Restarts the KOI
Last updated