Hackster is hosting Impact Spotlights: Robotics. Watch the stream live on Thursday!Hackster is hosting Impact Spotlights: Robotics. Stream on Thursday!
Infineon Team
Published © MIT

Accelerometer & Gyroscope with PSOC™ 6 and MicroPython

Easily sense motion and orientation with the PSOC™ 6's accelerometer and gyroscope!

BeginnerProtip1 hour321
Accelerometer & Gyroscope with PSOC™ 6 and MicroPython

Things used in this project

Hardware components

PSoC™ 6 AI Evaluation Kit (CY8CKIT-062S2-AI)
Infineon PSoC™ 6 AI Evaluation Kit (CY8CKIT-062S2-AI)
×1

Software apps and online services

MicroPython
MicroPython

Story

Read more

Code

MicroPython

MicroPython
import time
from machine import I2C
import bmi270
i2c = I2C(scl='P0_2', sda='P0_3') # Correct I2C pins for PSOC6 AI Kit
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)

Credits

Infineon Team
112 projects • 183 followers

Comments