Lesson 9 – Displaying Gyroscope Values on the LCD

 


Setting up our environment –

Follow each of these steps to set up the Kittenbot Meowbit for programming with MicroPython.

  1. Connect up the Kittenbot Meowbit to your laptop using a USB cable
  2. Power on the Kittenbot Meowbit by sliding the power button at the top
  3. Click the reset button once so that you get into the bootloader mode
  4. Refer to the following article if you are unclear about what bootloader mode is – Article@OzToyLib
  5. You should now see your Kittenbot Meowbit as an additional drive on your laptop
  6. Let’s install the Python firmware onto our Meowbit.
    1. Drag and drop this file onto the new drive – <Python Bootloader>
    2. Hit reset twice and you should see the Kittenbot Meowbit boot into Python.
    3. You should see the following message on your Meowbit, “Welcome to MicroPython”
  7. You should now see your Kittenbot Meowbit as an additional drive on your laptop
  8. Download and install the Python mu editor from – <Kittenbot software>
  9. Edit the “main.py” file and let’s start writing our code

If you’ve already got the Python firmware i.e. you’ve performed step 1 – 9 earlier, skip step 1 – 7 and hit the reset button twice (with 5 seconds gap) to enter into the Python mode.


Let’s get coding

In this example we will read data from the Gyroscope Sensor and display it on the LCD screen on the Kittenbot Meowbit. See code below.

 

import mpu6050
import framebuf
from pyb import I2C
import pyb
import time

fbuf = bytearray(160*128*2)
fb = framebuf.FrameBuffer(fbuf, 160, 128, framebuf.RGB565) 
tft = pyb.SCREEN()

time.sleep(1)

i2c = I2C(1)
acc = mpu6050.accel(i2c)

while True: 
    fb.fill(0) 
    ac_x = str(acc.get_ac_x())
    ac_y = str(acc.get_ac_y())
    ac_z = str(acc.get_ac_z())
    ac_value = [ac_x, ac_y, ac_z]
    ac_ori = ['x:', 'y:', 'z:']

    for index in range(len(ac_value)):
        fb.text(ac_value[index], 65, 25*(index+1), 0x00ff00)
        fb.text(ac_ori[index], 40, 25*(index+1), 0x00ff00)
    tft.show(fb)
    time.sleep(0.1)


Prerequisites –

Here are the hardware prerequisites for this course –

  1. This tutorial makes extensive use of the Kittenbot Meowbit.
  2. If you haven’t purchased a Kittenbot Meowbit yet you might want to head over and pick one up now.
  3. We also recommend picking up a Kittenbot IoBit for working on electronics projects and a Kittenbot Robobit to be able to create a programmable robot.

About the Programming Games with the Kittenbot Meowbit development track –

As part of this development track you will learn to work with the Kittenbot Meowbit board and learn how to create retro style games and even play those games on the Kittenbot Meowbit. You will program the games using Microsoft Makecode Arcade (https://arcade.makecode.com/). Microsoft Makecode Arcade is currently in Beta but has support for a number of different boards including the Kittenbot Meowbit. We will program games for the Kittenbot Meowbit using block based coding platform and also using Javascript.

Here’s the outcomes we will be working towards as part of this development track.

  1. Explore the fundamentals of computational thinking
  2. Explore fundamentals of programming i.e. program structure, decisions, loops, variables, etc.
  3. Learn how to design, create games using Makecode Arcade
  4. Learn how to program retro style games using a block based programming approach
  5. Learn how to program retro style games using Javascript
  6. Learn Learn to work with the Kittenbot Meowbit, program the board with custom games and play them when not connected to the computer/internet

About the Kittenbot Meowbit Gaming & Development board –

The Meowbit is a card-sized graphical retro game computer with allows you coding with Makecode arcade and Python. In other words, it can combines game programming, design while presenting learners the opportunity to learn mainstream programming languages like micropython. The Meowbit is a card-sized graphical programming video game console designed for kids of all ages.

The Kittenbot Meowbit comes with a 1.8′ full-color screen, 6 x programmable buttons, 1 x buzzer, built-in light sensor, temperature sensor, SD card slot (For external storage), multiplayer connector and edge connector. A special feature of the Meowbit is the in-built edge connector which should (**no extensive testing or certification of other 3rd party expansion boards has been conducted) be compatible with most micro:bit expansion boards out there. When combined with the Kittenbot Robot:bit board you have the ability to create a programmable versatile robot in a very short time. The Kittenbot Meowbit can also be used with the Kittenbot IoBit to create different electronics projects.

If you haven’t purchased a Kittenbot Meowbit yet you might want to head over and pick one up now.

Questions