Kittenbot HK Sharing Hub English
  • Welcome to KittenBot HK English Sharing Hub
  • Extension Boards
    • Robotbit Edu
      • Robotbit Edu Introduction
      • Robotbit Base Shield
      • Robotbit Edu Coding with MakeCode
      • Robotbit Edu Coding with KittenBlock
    • Robotbit 2.2
      • Robotbit 2.2 Info
      • Robotbit Base Shield
      • Robotbit 2.2 Coding with MakeCode
      • Robotbit 2.2 Coding with KittenBlock
    • Robotbit EDU and Robotbit 2.2 Differences
    • Newbit Arcade Shield
      • Newbit Arcade Shield Info
      • MakeCode Arcade Programming Tutorial
        • Using Newbit Arcade Shield as a remote controller
      • MicroCode Programming Tutorial
    • Armourbit Expansion Box
    • JoyFrog Micro:bit Controller
      • JoyFrog micro:bit Controller Info
      • JoyFrog Coding with MakeCode
      • JoyFrog Coding with Kittenblock
    • SugarBox Expansion Box
    • IOBit Expansion Board
    • K-Watch for Futureboard
  • AI Modules
    • AI Camera KOI 2
      • AI Camera KOI 2 Info
      • MakeCode Programming
        • KOI 2 in MakeCode Quick Start Guide
        • Show String
        • KOI Buttons
        • Taking and Displaying Photos
        • Recording and Playing Voice Clips
        • Switch Camera Orientation
        • Color Blob Tracking
        • Line Tracing
        • Code Scanner
        • Face Mask Detection
        • Face Attributes Detection
        • WiFi and IoT
        • Image Classifier: Model Training and Save
        • Image Classifier: Running and Load
        • Built-in Tracking: Road Signs
        • Built-in Tracking: Numbers
        • Built-in Tracking: Common Items
        • Built-in Tracking: Color Balls
        • File Operations
      • MicroPython Programming
        • KOI 2 in MicroPython Quick Start Guide
        • Basic Operations
        • Color Blob and Line Tracking
        • Code Scanner
        • Face Detection
        • Image Classifier
        • Built-in Tracking Models
        • Custom Tracking Models
      • KittenBlock Programming
        • KOI 2 in KittenBlock Quick Start Guide
        • Basic Operations
        • Color Blob and Line Tracking
        • Code Scanner
        • Face Detection
        • Image Classifier
        • Built-in Tracking Models
      • KOI 1 and KOI 2 Firmware Upgrades
      • KOI 2 Serial Command API
    • AI Camera KOI
      • AI Camera KOI Info
      • KOI Coding with MakeCode
        • KOI MakeCode Quickstart Guide
        • Interchanging between Armourbit and Robotbit
        • A and B Buttons
        • Displaying Text
        • LCD Orientation
        • Taking and Displaying Pictures
        • Recording and Playback
          • Making sound clips for KOI(Audacity)
        • Scanning Barcodes and QR Codes
        • Circle Tracing
        • Rectangle Tracing
        • Line Tracing
        • Face Detection
        • Classifier Model Training
        • Classifier Model Predicting
        • Voice Recognition (Firmware v1.9.5 or above)
        • Voice Recognition Train Model(KOI v1.12.0)
        • Voice Recognition Load Model(KOI v1.12.0)
        • Internet of Things (KOI v1.9.5)
        • Internet Time (KOI v1.12.0)
        • Face Recognition (KOI v1.9.5)
        • Text-to-Speech (KOI v1.9.5)
      • KOI Coding with Futureboard
        • Using KOI with Futureboard QuickStart
        • Futureboard x KOI 1: Basics
        • Futureboard x KOI 2: Face Detection
        • Futureboard x KOI 3: Image Classifier
        • Futureboard x KOI 4: Blob and Line Tracking
        • Futureboard x KOI 5: Shape Detection
        • Futureboard x KOI 6: Code Scanner
        • Futureboard x KOI 7: IoT and Baidu
        • Futureboard x KOI 8: Voice
      • KOI Serial Command API
      • KOI Kittenblock & MicroPython
        • KOI Programming with KittenBlock QuickStart
        • KOI MicroPython Programming Quickstart
        • KOI MicroPython API
      • KOI Firmware Update
        • KOI Update History
        • Firmware Update Tutorial
        • KOI WiFi Firmware Update
    • Sugar ASR Voice Module
      • Sugar ASR Voice Module Info
      • Sugar ASR Programming
      • Sugar ASR Custom Command Training
      • Sugar ASR Commands List
      • Sugar ASR Unplugged Usage
    • Sugar Cam Tutorial: AI Mode(Advanced)
  • Wifibrick & IoT Solutions
    • Wifibrick
      • Wifibrick Info
      • WifiBrick Firmware Update
    • IoT Platform Introductions
      • ThingSpeak
      • MakerCloud
      • ObjectBlocks
      • Kittenblock Built-in MQTT
    • MakeCode Coding for IoT Platforms
      • Makecode Coding and Thinkspeak
      • Makecode Coding and MakerCloud
      • Makecode Coding and ObjectBlocks
      • Makecode X KittenBlock IoT
      • Makecode Coding and KittenBot IoT
    • FutureBoard Programming for IoT Platforms
      • FutureBoard and ThingSpeak
      • FutureBoard and MakerCloud
      • FutureBoard and ObjectBlocks
    • IFTTT x IoT Platform
      • MakerCloud x IFTTT
      • ThingSpeak x IFTTT
    • IoT Platform x MIT AI2
  • Functional Modules
    • Powerbrick Series
      • Armourbit Expansion Box
      • Battery Box
      • Environment Temperature and Humidity Module
      • Soil Moisture Sensor
      • Water Level Sensor
      • Ultrasound and Sound Module
      • IR Line Trace Module
      • AB Bumpers Module
      • Color & Gesture Module
      • RFID Reader Module
      • RGB LED Matrix
      • MP3 Music Module
      • Powerbrick MakeCode Programming for Armourbit
      • Powerbrick MakeCode Programming for Robotbit
    • Sugar Series
      • Sugar Button Module
      • Sugar PIR Sensor Module
      • Sugar Line Sensor Module
      • Sugar Magnet Sensor Module
      • Sugar LED Module
      • Sugar Potentiometer Module
      • Sugar Flame Sensor Module
      • Sugar Light Sensor Module
      • Sugar Water Level Sensor Module
      • Sugar Soil Moisture Sensor Module
      • Sugar Environment Sensor Module
      • Sugar Joystick Module
      • Sugar TOF Distance Sensor
      • Sugar ASR Voice Module
      • Sugar String Light
      • Sugar Vibe Motor
      • Sugar Laser LED Module
      • Sugar Atmospheric Pressure Module
      • Sugar Crash Microswitch Module
      • Sugar Water Temperature Sensor
      • Sugar Buzzer Module
      • Sugar Touch Module
      • Sugar 7-Segment Display Module
      • Sugar I2C Hub
      • Sugar Grayscale Module
      • Sugar Sound Sensor Module
      • Sugar Camera Module
        • Sugar Cam Tutorial: Command Mode(Default)
          • Sugar Cam Tutorial: QR Code Scanner
          • Sugar Cam Tutorial: Voice Recognition
          • Sugar Cam Tutorial: Capture and MP3
          • Sugar Cam Tutorial: Futureboard FPV
          • Sugar Cam Tutorial: KittenBlock
          • Sugar Cam Tutorial: KittenBlock AI
        • Sugar Cam Tutorial: Remote Mode(Advanced)
          • Sugar Cam Tutorial: Web-based Streaming
          • Sugar Cam Tutorial: HTML Customization
        • Sugar Cam Tutorial: AI Mode(Advanced)
          • Sugar Cam Tutorial: Teachable Machine Model Training
          • Sugar Cam Tutorial: Teachable Machine Image Classification
        • Serial Command API
      • Sugar Atomizer Module
      • Sugar Carbon Dioxide Sensor Module
      • Sugar Solar Panel and Power Management Module
      • Sugar Weigh Module
      • Sugar UV Module
      • Sugar RFID Module
      • Sugar Numpad Module
      • Sugar RGB LED Ring
    • Turbidity Sensor
    • pH Meter
      • pH Meter Info
      • pH Meter Initial Tuning
      • pH Meter Programming Tutorial
      • pH Meter Export Calibration Value
      • pH Buffer Solution Mixing Tutorial
    • PM2.5 Particulates Sensor
    • KittenClock RTC Module
    • Contactless Infra Red Temperature Sensor
    • All in 1 Water Pump
    • Ultrasound Sensor
    • 5 Way Line Follow Module
    • GeekServo Fan
    • KittenRadio
    • RGB LED Strip and Board
      • RGB LED Strip
      • RGB LED Screen
        • RGB LED Screen Info
        • RGB LED Screen - Neopixel Tutorial
        • RGB LED Screen and Matrices
        • RGB LED Screen Daisy Chaining
        • RGB LED Screen - Static Effects Tutorial
        • 8x32 RGB LED Screen - Dynamic Effects Tutorial
        • 16x16 RGB LED Screen - Dynamic Effects Tutorial
    • Discontinued Modules
      • Button Module
      • Potentiometer
      • Ambient Light Sensor
      • Analog Flame Sensor
      • Moisture Sensor
      • Water Sensor
      • Magnetic Sensor
      • Slider Potentialmeter
      • Sound Sensor
      • Infra Red Tracker Sensor
      • RGB LED Module
    • FingerPrint Recognition Module
  • Motors and Servos
    • Geekservo Motor
    • Geekservo Servo
    • GeekServo 2KG Motors
    • GeekServo 2KG Servo
    • T/T DC Motors
    • Geek Motor O 360 Servo
    • High Speed DC Motor
    • 9g Servo
  • Microsoft Jacdac Series
    • What's Jacdac?
    • Jacdac Hardware
      • Jacdac+MakeCode Quickstart
      • Jacdac+MicroCode QuickStart
      • Jacdac Kit A
        • Jacdapter
        • Jacdac Slider
        • Jacdac Rotary Button
        • Jacdac RGB Ring
        • Jacdac Button
        • Jacdac Magnet Sensor
        • Jacdac Light Sensor
        • Jacdac Hub
      • Jacdac Kit B
        • Jacdac Power Module
        • Jacdac Haptic
        • Jacdac Accelerometer
        • Jacdac Relay
        • Jacdac Environment
        • Jacdac RGB Light Strip
        • Jacdac Servo Driver
        • Jacdac Ultrasound
      • Jacdac Duckybot
        • Duckybot Instructions
          • Wake Up Duckling
          • Environment Sensing
          • Fall Detection
          • Following Duckling
  • Main Controllers
    • BBC Micro:bit V2
    • FutureBoard
      • About FutureBoard
        • FutureBoard Info
        • FutureOS Operation Guide
      • FutureBoard KittenBlock Programming Tutorial
        • FutureBoard and KittenBlock Quick Start Guide
        • Programming with Kittenblock: Onboard Sensors
        • Programming with KittenBlock: Buzzer
        • Programming with KittenBlock: Screen
        • Programming with KittenBlock: Turtle
        • Programming with KittenBlock: GPIO
        • Programming with KittenBlock: Neopixel
        • Programming with KittenBlock: WiFi & IoT
        • Programming with KittenBlock: Microphone
        • Programming with KittenBlock: Radio
        • Programming with KittenBlock: Robotbit
        • Programming with KittenBlock: Powerbrick
        • Programming with KittenBlock: Sugar
        • Programming with KittenBlock: HK Observatory
        • Programming with KittenBlock: KMB ETA
      • FutureBoard MicroPython Programming Tutorial
        • FutureBoard & MicroPython Quick Start Guide
        • Programming with MicroPython: Screen and Display
        • Programming with MicroPython: Onboard Sensors
        • Programming with MicroPython: Buzzer
        • Programming with Micropython: Turtle
        • Programming with MicroPython: GPIO
        • Programming with MicroPython: NeoPixel
        • Programming with MicroPython: WiFi & IoT
        • Programming with MicroPython: Network Time Protocol
        • Programming with MicroPython: I2S Microphone
        • Programming with MicroPython: Wireless Radio
        • Programming with MicroPython: Robotbit
        • Programming with MicroPython: urequests & ujson
        • Programming with MicroPython: I2C Device
        • Programming with MicroPython: Sugar and Powerbrick Modules
        • Programming with MicroPython: ASR Voice Recognition Module
        • Programming with MicroPython: KOI
      • Firmware Updates
        • Update Process
        • FutureBoard Firmware History
        • Resetting the FutureBoard
    • MeowBit
      • Meowbit Introduction
      • MeowBit System Operations
      • Meowbit Programming Tutorial
        • Meowbit MakeCode Coding QuickStart
        • MeowBit HourOfCode Tutorial
        • Meowbit Kittenblock Coding Quickstart
        • MeowBit’s Light Sensor
        • Meowbit’s Accelerometer
        • Meowbit’s Temperature Sensor
        • Meowbit’s IO Pins
        • MeowBit Wireless SD Module
        • Meowbit & Robotbit
        • Meowbit & Neopixel
        • Meowbit & IOBit
        • Meowbit & Turtle(Kittenblock)
        • Meowbit’s Display(Kittenblock)
        • Meowbit MicroPython Quick Start
        • Meowbit MicroPython API
    • Nanobit
      • Nanobit Introduction
      • Nanobit & MakeCode Programming
      • Nanobit Shield Expansion Board
  • Educational Kit Sets
    • Micro:bit Inventor Education Kit
      • Micro:bit Inventor Education Kit Introduction
      • Micro:bit Inventor Kit Instructions
        • Traffic Lights
        • Fire Alarm
        • Birthday Candles
        • Electric Gate
        • Smart Hanger
        • Plant Helper
        • Radio
        • Rhythm Machine
        • Quiz Machine
        • Nightlight
        • Swinging Fan
        • Zombie Game
        • Delivery Kart
        • RC Kart
        • Safe
        • Piano
      • Micro:bit Inventor Kit - AI Upgrade
        • Micro:bit Inventor Kit x KOI AI Camera Use Cases
        • Voice Control AI Hanger
        • AI Pedestrian Crossing
        • AI Access Gate Control
        • AI Face Tracking Fan
        • Biometrics Authentication Safe Locker
      • Micro:bit Inventor Kit - IoT Upgrade
        • IoT Streetlight
        • IoT Hanger
        • IoT Gate
        • IoT Door Lock
        • IoT Safe
        • IoT Fire Alarm
      • Micro:bit Inventor Kit - ASR Upgrade
        • ASR Upgrade Use Cases
        • Voice Control Fan
        • Voice Control Hanger
        • Voice Control Night Light
        • Voice Control Smart Appliances
      • Micro:bit Inventor Kit - KOI 2 Upgrade
        • Mask Detector Gate
        • Facial Image Identification Safe
        • Face Detection Fan
        • AI Traffic Management
        • Road Sign Tracking Car
    • Powerbrick
      • PowerBrick All-In-One
      • PowerBrick Instructions and Parts List
        • PowerBrick Building Blocks List
        • Gestured Controlled Crane
        • Chomping Duck
        • Line Follow Street Cleaning Car
        • Dino King
        • Robo Dancer
        • Smart Bin
        • Smart Gate
        • Weather Reporter
        • Brick Sorter
        • Windmill
    • Health Care Educational AI Kit
      • Health Care Educational AI Kit Introduction
      • Health Care Educational AI Kit Instructions(KOI 1)
        • Health Care Educational AI Kit Parts List
        • AI Disinfection Alcohol Dispenser
        • Handheld Contactless Temperature Monitor
        • Auto-Tracking Temperature Monitor
        • Anti-epidemic Supplies Commander
        • Mask Detector
        • Contactless Elevator
        • Contactless Door Bell
        • Driverless Delivery Cart
        • UV Light Sterilizer
      • Health Care Educational AI Kit Instructions(KOI 2)
        • Health Care Educational AI Kit Parts List
        • Handheld Contactless Temperature Monitor
        • AI Disinfection Alcohol Dispenser
        • Auto-Tracking Temperature Monitor
        • Anti-epidemic Supplies Commander
        • Mask Detector
        • Contactless Elevator
        • Contactless Door Bell
        • Driverless Delivery Cart
        • Driverless Sterilizing Cart
        • UV Light Sterilizer
    • FutureBoard IoT Education Kit
      • FutureBoard IoT Education Kit Intro
      • FutureBoard IoT Education Kit Instructions
        • Weather Station
        • Welcoming Robot
        • Timer
        • Safe
        • Smart Streetlamp
        • Laser Distance Ruler
        • RC Kart
        • Smart Parking Lot
    • Weather Station Educational Kit
      • Weather Station Educational Kit Introduction
      • Voice Weather Station Instructions
        • 6-in-1 Complete Weather Station
        • Environment Light Meter
        • Temperature & Humidity Barometer
        • Air Pressure Meter
        • Rainfall Meter
        • Wind Vane
        • Anemometer
      • IoT Weather Station Instructions
        • 6-in-1 Complete Weather Station
        • Environment Light Meter
        • Temperature & Humidity Barometer
        • Air Pressure Meter
        • Rainfall Meter
        • Wind Vane
        • Anemometer
      • Weather Station Building Instructions
        • 6-in-1 Weather Station Instructions
        • Environment Light Meter Instructions
        • Barometer Instructions
        • Rainfall Meter Instructions
        • Wind Vane Instructions
        • Anemometer Instructions
    • KOI AI Air Hockey
    • AI/AIoT Recycling Bin
      • AI/AIoT Recycling Bin Intro
      • AI/AIoT Recycling Building Instructions
      • AI/AIoT Recycling Kit Tutorial(KOI 1)
      • AI/AIoT Recycling Kit Tutorial(KOI 2)
    • Smart Book Crossing Cabinet Education Kit
      • Smart Book Crossing Cabinet Intro
      • Smart Book Crossing Cabinet Instructions
        • Building Instructions
        • MakeCloud Set Up Procedure
        • AI2 Application Set Up
        • FutureBoard Sample Program
        • Micro:bit Sample Program
    • IoT Make Easy Smart Home Education Kit
      • IoT Make Easy Smart Home Education Kit Introduction
      • IoT Make Easy Building Instructions
        • Set Up for MakerCloud
        • MakerCloud x IFTTT Guide
        • Set Up for ObjectBlocks
        • Set Up for Thingspeak
        • Safety Gas Stove
        • Remote Security Door
        • Safety Bathtub
        • Anti-Spilling Sink
    • Industry 4.0 Conveyor Belt
      • Industry 4.0 Conveyor Belt Introduction
      • Building Instructions
      • Inventory System Sample Program(FutureBoard)
      • Inventory System Sample Program(MakeCode)
      • IoT Platform Set Up Tutorial
    • Industry 4.0 Robotic Arm
      • Industry 4.0 Robotic Arm for SYE
    • KittenBot Fitness Testing Kit
      • KittenBot Fitness Testing Kit Intro
      • 1. Push-Up Exercise
      • 2. Sit-Up Exercise
      • 3. Sit and Reach Test
      • 4. Y-Balance Test
      • 5. Plank Exercise
    • SumoBot 12-in-1 Kit
      • SumoBot 12-in-1 Kit Introduction
      • SumoBot 12-in-1 Model Instructions
        • SumoBot 12-in-1 Parts List
        • SumoBot
        • Flag Swiper
        • RoboPusher
        • Punching Mantis
        • Speed Racer
        • RoboCatcher
        • RoboDino
        • Sumo Wrestler
        • RoboFootballer
        • RoadBlock Smasher
        • Battle Turret
        • Smart Toilet Tissue Machine
    • MR STEMER 3-in-1 BattleBots Kit
      • MR STEMER 3-in-1 BattleBots Kit Intro
      • MR STEMER 3-in-1 Model Instructions
        • MR STEMER 3-in-1 Parts List
        • SumoBot
        • Flag Swiper
        • RoboPusher
    • Robotbit Basic Kart
      • Robotbit Basic Kart Introduction
      • Basic Kart Building Instructions
      • Remote Control Kart
      • Line Tracing Kart
      • Obstacle Avoiding Kart
      • AI Automated Driving Kart
    • Mecanum Wheel Robotic Car Kit
      • Mecanum Wheel Robotic Car Kit Intro
      • Mecanum Wheel Robotic Car Kit Instructions
        • Mecanum Robotic Car
        • Mecanum Robotic Shooter
    • Mecanum Wheel Robot 2KG
      • Mecanum Wheel Robot 2KG Introduction
      • Mecanum Wheel Robot 2KG Building Instructions
      • Mecanum Wheel Robot 2KG Sample Programs
    • All Terrain RC Rover Kit
      • All Terrain RC Rover
      • All Terrain RC Rover Building Instructions
      • All Terrain RC Rover Sample Program
    • MR STEMer Kart Lite
    • Robotbit Robot Arm
    • Meowbit Creator Kit
      • Meowbit Creator Kit Introduction
      • Meowbit Creator Kit Instructions
        • Meowbit Creator Kit Parts List
        • 1. Step Counter
        • 2. Tug-Of-War
        • 3. Coin Collector
        • 5. Basketball Game
        • 6. Piano Master
        • 7. Voice Control Lights
        • 8. Anti-Noise Window
        • 9. Line Follower Robot
        • 10. Obstacle Avoiding Robot Cat
        • 11. Smart Parking Lot
    • Circuitry Experiments Education Kit
      • Circuitry Experiments Education Kit Introduction
      • Circuitry Experiments Kit Component List
    • MRSTEMer Competition Arena
    • TabbyBot AI Cart
      • TabbyBot Programming QuickStart
      • Scaredy Cart Programming Tutorial
      • Light Show Programming Tutorial
      • Obstacle Avoiding Cart Tutorial
      • Line Follower Cart Tutorial
    • (Discontinued Item)Robotbit Sensor Kit
    • Pneumatic Rocket Launching Kit
      • Pneumatic Rocket Tutorial
    • Robotbit Differential Car
      • RC Differential Car Tutorial
      • AI Upgrade: KOI 2 Auto Parking
        • KOI 2 Auto Parking Tutorial
  • Programming Platforms
    • Newest! Microsoft MicroCode
    • MakeCode Tutorial
      • Kittenbot & MakeCode
      • Makecode Extension Updates
      • MakeCode Micro:bit Programming for iPad
    • KittenBlock
      • Installing KittenBlock
      • Uninstall KittenBlock 1.88 Completely
      • Kittenblock User Interface
        • Kittenblock Main UI
        • Blocks Menu
        • Coding Area
        • Stage
      • KittenBlock & Micro:bit
        • Connecting Micro:bit to KittenBlock
        • Micro:bit Coding & Kittenblock
      • KittenBlock Functions & Features
        • Kittenblock Unique Features
          • Python Editor
          • KittenBlock Hardware File System
          • Wiring Diagram Maker
        • Kittenblock VS Scratch 3.0
        • Learning Python 3 with Kittenblock
        • Kittenbot Extensions
          • Video Sensing
          • Translation
          • Text to Speech
          • Internet of Things
          • Artificial Intelligence
            • FaceAI
            • BaiduAI
          • Machine Learning
            • Machine Learning 5
            • Machine Learning 5 Image Classification
            • Machine Learning 5 Feature Extraction
            • Machine Learning 5 SketchRNN
            • Machine Learning 5 PoseNet
            • Machine Learning 5 FaceAPI
    • KittenCode
      • KittenCode Introduction
      • KittenCode Interface
  • Scientific Measuring Device Kit
    • Measuring PM2.5 Particulates
    • Measuring Carbon Dioxide
    • Measuring Water Temperature
    • Measuring Water Turbidity
    • Measuring Sound Level
    • Measuring pH Level
    • Futureboard Lite Operation Manual
  • Kittenbot & Bricklink Studio
  • Kittenbot HK SharingHub Chinese
Powered by GitBook
On this page
  • Importing KOI library
  • Basics
  • Image Classifier
  • Face Detection
  • Geometric Shape Tracking
  • Color Blob Tracking
  • Barcode and QR code Recognition
  • Voice Recognition
  • IoT
  • Face Recognition
  • Q&A
  1. AI Modules
  2. AI Camera KOI
  3. KOI Kittenblock & MicroPython

KOI MicroPython API

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")
loadImage("s1.jpg")

Taking and showing pictures.

Getting button values

btnAValue()
btnBValue()

Obtains button values.

  • Returns 1 when pressed, 0 when not pressed.

Sample Program

#/bin/python
from koi import *

from time import sleep

x = 0

lcd.rotation(2)     #Change LCD orientation
sleep(1)
lcd.rotation(0)     #Change LCD orientation
sleep(1)
drawString(5,5,"hello world",500)       #Show String
while True:
  img=sensor.snapshot()     #Enables screen refresh
  lcd.display(img)          #Enables screen refresh
  if btnAValue() == 1:
    img.save("s1.jpg")      #Takes picture
  if btnBValue() == 1:
    loadImage("s1.jpg")     #Shows picture

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':
    pass

Triggers an event on classification.

cla.save("abc.json")
cla.load("abc.json")

Save or load classifier models.

Sample Program

#Model Training
from koi import *

x=0

cla.reset()     #Init classifier

while True:
    img=sensor.snapshot()   #Enables screen refresh
    lcd.display(img)        #Enables screen refresh
    if btnAValue():
        cla.addImage('apple')       #Add tag
    if btnBValue():
        cla.addImage('orange')      #Add tag
    if btnAValue() and btnBValue():
        cla.save('fruit.json')      #Save Model
    time.sleep(0.1)

#Model Running
from koi import *

x=0
cla.reset()         #init classifier
cla.load("fruit.json")      #Load Model

while True:
    img=sensor.snapshot()   #Enables screen refresh
    lcd.display(img)        #Enables screen refresh
    if btnAValue():
        tag=cla.getImageTag()       #Classify
        if tag=='orange':
            print('I like oranges.')
        elif tag=='apple':
            print('Apples are healthy.')
    time.sleep(0.1)

Face Detection

Load Face Model

yoloinit()

Load face model.

Track face

trackface()

Tracks the face, returns a list.

Sample Program

#/bin/python
from koi import *

x = 0
face_prop=[0,0]

yoloinit()          #Load Face model
while True:
    img=sensor.snapshot()   #Enables screen refresh
    lcd.display(img)        #Enables screen refresh
    r = trackface()         #Tracks the face
    if r:
        is_face=1
        drawString(5,5,r,500)
        face_prop[0]=(r[0][2]+r[0][0])/2
        face_prop[1]=(r[0][3]+r[0][1])/2
    else:
        is_face=0
        
    while is_face:
        print('X: '+str(face_prop[0]))
        print('Y: '+str(face_prop[1]))
        is_face=0
    time.sleep(0.5)

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 *

x=0

while True:
    img=sensor.snapshot()   #Enables screen refresh
    lcd.display(img)        #Enables screen refresh
    if btnAValue() and btnBValue():
        line_prop = findLines()     #Find lines
        print(line_prop[0])
        time.sleep(0.1)
    elif btnAValue():
        circle_prop = findCircle(4000)    #Find Circles
        print(circle_prop[0])
        time.sleep(0.1)
    elif btnBValue():
        rect_prop = findRects(4000)       #Find Rectangles
        print(rect_prop[0])
        time.sleep(0.1)

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 *

x=0

while True:
    img=sensor.snapshot()   #Enables screen refresh
    lcd.display(img)        #Enables screen refresh
    if btnAValue():
        colorCalibrate()        #Color Calibration
        time.sleep(0.1)
    elif btnBValue():
        blob_prop=findBlob()        # Finds Color Blob  
        print(blob_prop[0])
        time.sleep(0.1)
    elif btnAValue() and btnBValue():
        line_prop=findLinearRegress()       #Finds Line
        print(line_prop[0])
        time.sleep(0.1)

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 *

x=0

lcd.rotation(2)

while True:
    img=sensor.snapshot()   #Enables screen refresh
    lcd.display(img)        #Enables screen refresh
    if btnAValue():
        barcode=findBarCode()       #Barcode
        print(barcode[0][4])
        time.sleep(0.1)
    if btnBValue():
        qrcode=findQRCode()     #QR Code
        print(qrcode[0][4])
        time.sleep(0.1)
    if btnAValue() and btnBValue():
        april=findAprilTag()        #AprilTag
        print(april[0])
        time.sleep(0.1)

Voice Recognition

Record and Play

speech.recordWav('hi.wav')
speech.playWav('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
from koi import *

x=0

while True:
    img=sensor.snapshot()   #Enables screen refresh
    lcd.display(img)        #Enables screen refresh
    if btnAValue():
        speech.recordWav('hi.wav')      #Record
        time.sleep(0.1)
    if btnBValue():
        speech.playWav('hi.wav')        #Play
        time.sleep(0.1)

#Voice Recognition
from koi import *

x=0

speech.noiseTap()       #Calibrate

while True:
    img=sensor.snapshot()   #Enables screen refresh
    lcd.display(img)        #Enables screen refresh
    if btnAValue():
        speech.addCommand("hello")      #Add command
        time.sleep(0.1)
    if btnBValue():
        speech.addCommand("bye")    #Add command
        time.sleep(0.1)
    if btnAValue() and btnBValue():
        print(speech.getCommand())      #Recognize
        time.sleep(0.1)

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)

Subscribes a topic on MQTT.

  • 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 *

wifi.joinap(str("apname"),str("password"))      #WiFi
time.sleep(2)
print(wifi.ipaddr())    #IP
time.sleep(2)
wifi.mqtthost("127.0.0.1")      #MQTT
wifi.mqttsub("test01")      #Subscribe

while True:
    img=sensor.snapshot()    #Enables screen refresh
    lcd.display(img)         #Enables screen refresh
    if btnAValue():
        wifi.mqttpub("test01","hello world")    #Publish
    if btnBValue():
        msg=wifi.mqttread("test01")     #Read
        print("Message: "+msg[0])
        print("Topic: "+msg[1])

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 *

wifi.joinap(str("apname"),str("password"))
time.sleep(2)

while True:
    img=sensor.snapshot()   #Enables screen refresh
    lcd.display(img)        #Enables screen refresh
    if btnAValue():
        face=baiduFace(op=1)
        time.sleep(5)
        baiduFace(op=2, token=face['face_token'], group="group", name="name")   #add face
    if btnBValue():
        face=baiduFace(op=1)
        time.sleep(5)
        result=baiduFace(op=3, token=face['face_token'], group="name")  #search face
        print("Name: "+faceResult['result']['user_list'][0]['user_id'])
        print("Confidence: "+str(faceResult['result']['user_list'][0]['score']))

Q&A

KOI’s display is laggy.

Please enable the screen refresh.

KOI does not run the program I uploaded.

Please restart the KOI because it was still running the original main.py.

Can I connect other modules using the 4-Pin Port?

No, this port is for connecting to Micro:bit only.

KOI’s LCD is reversed.

Please use the LCD orientation command.

PreviousKOI MicroPython Programming QuickstartNextKOI Firmware Update

Last updated 1 year ago

Saving and Loading Classifier Models

