NeoSteamLabs
Published © CC BY

Project #30 - UNIHIKER - Accelerometer and Gyroscope - Mk01

UNIHIKER - Accelerometer and Gyroscope

BeginnerFull instructions provided30 minutes65
Project #30 - UNIHIKER - Accelerometer and Gyroscope - Mk01

Things used in this project

Hardware components

UNIHIKER - IoT Python Programming Single Board Computer with Touchscreen
DFRobot UNIHIKER - IoT Python Programming Single Board Computer with Touchscreen
×1
SparkFun USB Battery Pack
×1
DFRobot USB 3.1 Cable A to C
×1

Software apps and online services

Adafruit Thonny

Story

Read more

Schematics

UNIHIKER Accelerometer and Gyroscope

Code

DL2408Mk03p.py

Python
"""
****** Don Luc Electronics © ******
Software Version Information
Project #30 - UNIHIKER - Accelerometer and Gyroscope - Mk01
30-01
DL2408Mk03p.py
DL2408Mk03
1 x UNIHIKER
1 x USB Battery Pack
1 x USB 3.1 Cable A to C

-*- coding: utf-8 -*-
"""
# Import the unihiker library
from unihiker import GUI

# Import the time library
import time

# Import the Board module from the pinpong.board package 
from pinpong.board import Board

# Import all modules from the pinpong.extension.unihiker package
from pinpong.extension.unihiker import *

# Initialize the board by selecting the board type and port number;
# if not specified, the program will automatically detect it
Board().begin()

# Instantiate the GUI class and create a gui object
gui = GUI()

# Display the initial background image 'dlemk02'
img = gui.draw_image(x=0, y=0, w=240, h=320, image='dlemk02.png')

# Accelerometer
# Display the initial Accelerometer X valueAX
valueAX = gui.draw_text(x=60, y=145, text='0', font_size=10)

# Display the initial Accelerometer Y valueAY
valueAY = gui.draw_text(x=60, y=170, text='0', font_size=10)

# Display the initial Accelerometer Z valueAZ
valueAZ = gui.draw_text(x=60, y=195, text='0', font_size=10)

# Gyroscope
# Display the initial Gyroscope X valueGX
valueGX = gui.draw_text(x=60, y=240, text='0', font_size=10)

# Display the initial Gyroscope Y valueGY
valueGY = gui.draw_text(x=60, y=260, text='0', font_size=10)

# Display the initial Gyroscope Z valueGZ
valueGZ = gui.draw_text(x=60, y=285, text='0', font_size=10)

while True:
    
    # Accelerometer
    # Display the Accelerometer X
    AX = accelerometer.get_x()
    # Update the displayed Accelerometer X valueAX
    valueAX.config(text=AX)
    # Display the Accelerometer Y
    AY = accelerometer.get_y()
    # Update the displayed Accelerometer Y valueAY
    valueAY.config(text=AY)
    # Display the Accelerometer Z
    AZ = accelerometer.get_z()
    # Update the displayed Accelerometer Z valueAZ
    valueAZ.config(text=AZ)
    
    # Gyroscope
    # Display the Gyroscope X
    GX = gyroscope.get_x()
    # Update the displayed Gyroscope X valueAX
    valueGX.config(text=GX)
    # Display the Gyroscope Y
    GY = gyroscope.get_y()
    # Update the displayed Gyroscope Y valueAY
    valueGY.config(text=GY)
    # Display the Gyroscope Z
    GZ = gyroscope.get_z()
    # Update the displayed Gyroscope Z valueAZ
    valueGZ.config(text=GZ)

    # Delay for 1 second to keep the screen content displayed for a longer time
    time.sleep(1)

Credits

NeoSteamLabs
40 projects • 15 followers
Luc Paquin Microcontrollers, IoT, Robotics Experts https://www.donluc.com https://www.donluc.com/luc https://www.linkedin.com/in/jlucpaquin
Contact

Comments

Please log in or sign up to comment.