覆盆子πMPU6050传感器数据可视化(加速度计、陀螺仪)
5视图(30天)
显示旧的评论
# ! / usr / bin / python
进口smbus
导入数学
进口的要求
进口json
power_mgmt_1 = 0 x6b
power_mgmt_2 = 0 x6c
def read_byte(注册):
返回公共汽车。read_byte_data(地址、注册)
def read_word(注册):
h =公共汽车。read_byte_data(地址、注册)
l =公共汽车。read_byte_data(地址、注册+ 1)
值= (h < < 8) + l
返回值
def read_word_2c(注册):
val = read_word(注册)
如果(val > = 0 x8000):
(恢复)- (65535 - val + 1)
其他:
返回瓦尔
def dist (a, b):
返回math.sqrt ((*) + (b * b))
def get_y_rotation (x, y, z):
弧度=数学。量化(x, dist (y, z))
返回-math.degrees(弧度)
def get_x_rotation (x, y, z):
弧度=数学。量化(y, dist (x, z))
返回math.degrees(弧度)
总线= smbus.SMBus(1) #总线= smbus.SMBus(0)为了修订1
通过i2cdetect地址= 0 x68 #
公共汽车。write_byte_data(地址、power_mgmt_1 0)
打印”Gyrosk
op”
打印”- - - - - - - - - -”
而(真正的):
gyroskop_xout = read_word_2c (0 x43)
gyroskop_yout = read_word_2c (0 x45)
gyroskop_zout = read_word_2c(0开发)x47
gyroscope_xout:“打印”,(“% 5 d”% gyroskop_xout),“skaliert:“(gyroskop_xout / 131)
gyroscope_yout:“打印”,(“% 5 d”% gyroskop_yout),“skaliert:“(gyroskop_yout / 131)
gyroscope_zout:“打印”,(“% 5 d”% gyroskop_zout),“skaliert:“(gyroskop_zout / 131)
#如何给ThingSpeak上面的传感器数据吗?请帮助。