Motion sensing is everywhere today — from smartphones and wearables to drones and robotics. Being able to detect movement, orientation, and rotation opens the door to many interactive applications.
In this quick demo, we’ll use the built-in 6-axis IMU on the PSOC™ Edge E84 AI Kit. The board integrates the Bosch BMI270, combining a 3-axis accelerometer and a 3-axis gyroscope. Using MicroPython, we can read motion data and create an interactive application in just a few lines of code.
How the Sensor WorksThe accelerometer measures acceleration along the X, Y, and Z axes. When the board is resting on a table, you’ll typically see around 9.81 m/s² on the Z-axis, which corresponds to gravity.
The gyroscope measures rotational speed in degrees per second. If you rotate the board quickly, you’ll see spikes in the gyro values.
Together, these measurements allow systems to detect:
- tilt
- movement
- rotation
- orientation changes
This is exactly the type of sensing used in gesture recognition, stabilization systems, and motion-controlled interfaces.
HardwareThe BMI270 is integrated on the PSOC™ Edge E84 AI Kit and communicates via I²C. Simply connect the board to your computer via USB.
First, make sure the BMI270 MicroPython driver is available on the board and then import the necessary libraries:
from machine import I2C
import time
import bmi270For the bmi270 module, you can go to Tools > Manage Packages > search bmi270 and click install like it is shown in the pictures below:
Next, set up the I2C connection using the correct pins that we can find in the documentation here and then create an instance of the BMI270 sensor.
i2c = I2C(scl='P8_0', sda='P8_1') # Correct I2C pins for PSOC™ Edge E84 AI Kit
bmi = bmi270.BMI270(i2c)Then set up an infinite loop (while True:) to continuously read and display real-time acceleration data from the sensor:
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)bmi.accel(): reads linear acceleration on all three axes (X, Y, Z) in m/s². This indicates movement direction or tilt.bmi.gyro(): reads rotational speed around each axis in degrees per second (°/s), detecting spins and turns.
In the serial monitor, we see both sets of sensor data grouped together. When you tilt, shake, or rotate your board, you can observe how the values respond in real-time.
To demonstrate practical motion control, let's build a simple game where tilting the board moves a ball along a track.
The key is using the Y-axis acceleration to detect tilt direction:
# Read Y-axis acceleration to detect tilt
_, accy, _ = bmi.accel()
# Move ball based on tilt direction
if accy > 0.3: # Tilted right
ball_position = max(0, ball_position - 1)
elif accy < -0.3: # Tilted left
ball_position = min(39, ball_position + 1)
# Visualize ball position
track[ball_position] = 'O'
print('|' + ''.join(track) + '|')- Monitor the Y-axis acceleration to detect board tilt
- When tilted beyond ±0.3 g, the ball moves accordingly
- The ball position updates in real-time, simulating gravity on a physical surface
Congratulations! You've successfully explored motion sensing with the PSOC™ Edge E84 AI Kit! With just a few lines of MicroPython code, you can:
- Read real-time acceleration and rotation data from the BMI270 sensor
- Detect tilt, movement, and orientation changes
- Build interactive motion-controlled applications like our tilt-ball game
This is just the beginning — motion sensing opens up endless creative possibilities. Whether you're building gesture-controlled interfaces, fitness trackers, smart IoT devices, or even your own game controllers, the foundation you've learned here will serve you well.
Don't be afraid to experiment! Try adjusting the sensitivity thresholds, combining accelerometer and gyroscope data, or creating your own unique motion-based interactions. The best projects often come from playful exploration and curiosity.
Happy making, and enjoy bringing motion in your projects! :)









Comments