Raspberry Pi with MPU6050 Sensor Data Visualisation (Accelerometer, Gyroscope)

6 ビュー (過去 30 日間)
Jayanth Tadikonda
Jayanth Tadikonda 2020 年 2 月 19 日
コメント済み: Vinod 2020 年 2 月 20 日
#!/usr/bin/python
import smbus
import math
import requests
import json
power_mgmt_1 = 0x6b
power_mgmt_2 = 0x6c
def read_byte(reg):
return bus.read_byte_data(address, reg)
def read_word(reg):
h = bus.read_byte_data(address, reg)
l = bus.read_byte_data(address, reg+1)
value = (h << 8) + l
return value
def read_word_2c(reg):
val = read_word(reg)
if (val >= 0x8000):
return -((65535 - val) + 1)
else:
return val
def dist(a,b):
return math.sqrt((a*a)+(b*b))
def get_y_rotation(x,y,z):
radians = math.atan2(x, dist(y,z))
return -math.degrees(radians)
def get_x_rotation(x,y,z):
radians = math.atan2(y, dist(x,z))
return math.degrees(radians)
bus = smbus.SMBus(1) # bus = smbus.SMBus(0) fuer Revision 1
address = 0x68 # via i2cdetect
bus.write_byte_data(address, power_mgmt_1, 0)
print "Gyrosk
op"
print "--------"
while(True):
gyroskop_xout = read_word_2c(0x43)
gyroskop_yout = read_word_2c(0x45)
gyroskop_zout = read_word_2c(0x47)
print "gyroscope_xout: ", ("%5d" % gyroskop_xout), " skaliert: ", (gyroskop_xout / 131)
print "gyroscope_yout: ", ("%5d" % gyroskop_yout), " skaliert: ", (gyroskop_yout / 131)
print "gyroscope_zout: ", ("%5d" % gyroskop_zout), " skaliert: ", (gyroskop_zout / 131)
# How to send the above sensor data to ThingSpeak ? Please Help.

回答 (1 件)

Vinod
Vinod 2020 年 2 月 19 日
There are numerous tutorials online. Have you tried looking at some?
  2 件のコメント
Jayanth Tadikonda
Jayanth Tadikonda 2020 年 2 月 20 日
Thanks for the response, I have gone through such tutorials but could'nt find information related to my project.
Vinod
Vinod 2020 年 2 月 20 日
OK. Based on the projects, what did you learn? Please share some example code of what you tried and what errors you got, as we can guide you based on that.

サインインしてコメントする。

コミュニティ

その他の回答  ThingSpeak コミュニティ

カテゴリ

Help Center および File ExchangeThingSpeak についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by