Infineon Team
Published © MIT

PSOC™ Edge E84 AI Kit & IMU

Learn how to use the 6-axis IMU sensor on the PSOC™ Edge E84 AI Kit to read motion data and detect tilt with MicroPython.

BeginnerProtip1 hour205
PSOC™ Edge E84 AI Kit & IMU

Things used in this project

Hardware components

PSOC™ Edge E84 AI Kit
Infineon PSOC™ Edge E84 AI Kit
×1

Software apps and online services

MicroPython
MicroPython

Story

Read more

Code

Example code

MicroPython
from machine import I2C
import time
import bmi270

i2c = I2C(scl='P8_0', sda='P8_1') 
bmi = bmi270.BMI270(i2c)

while True:
    accx, accy, accz = bmi.accel() 
    gyrox, gyroy, gyroz = bmi.gyro()    
    
    print("-" * 40)   
    print("ACCELERATION (m/s²):")    
    print(f"   X: {accx:6.2f}    Y: {accy:6.2f}    Z: {accz:6.2f}")     
    print("GYROSCOPE (°/s):")    
    print(f"   X: {gyrox:6.2f}    Y: {gyroy:6.2f}    Z: {gyroz:6.2f}")    
    print("-" * 40)   
    print()   
    time.sleep(0.5)

Tilt game code

MicroPython
from machine import I2C
import time
import bmi270

# Initialize I2C and BMI270 sensor
i2c = I2C(scl='P8_0', sda='P8_1')
bmi = bmi270.BMI270(i2c)

# Game settings
TRACK_WIDTH = 40
ball_position = TRACK_WIDTH // 2
TILT_THRESHOLD = 0.3

print("Tilt the board left/right to control the ball\n")

while True:
    # Read acceleration data
    accx, accy, accz = bmi.accel()
    
    # Move ball based on tilt
    if accy > TILT_THRESHOLD:
        ball_position = max(0, ball_position - 1)
    elif accy < -TILT_THRESHOLD:
        ball_position = min(TRACK_WIDTH - 1, ball_position + 1)
    
    # Render track and ball
    track = ['-'] * TRACK_WIDTH
    track[ball_position] = 'O'
    print('|' + ''.join(track) + '|')
    
    time.sleep(0.1)

Credits

Infineon Team
133 projects • 263 followers
Hands-on projects, tutorials, and code for sensors, MCUs, connectivity, security, power, and IoT. Follow for new builds and ideas.

Comments