Herunterladen Inhalt Inhalt Diese Seite drucken

SunFounder Da Vinci Kit Bedienungsanleitung Seite 268

Für den raspberry pi 4 modell b, 3 modell a +, 3 modell b +, 3 modell b, 2 modell b, 1 modell b +, 1 modell a +, zero w and zero
Inhaltsverzeichnis

Werbung

SunFounder Da Vinci Kit
Bemerkung: Sie können den folgenden Code Ändern/Zurücksetzen/ Kopieren/Ausführen/Stoppen. Zuvor müssen
Sie jedoch zu einem Quellcodepfad wie davinci-kit-for-raspberry-pi\\python gehen.
import
smbus
import
math
import
time
# Power management registers
power_mgmt_1
=
0x6b
power_mgmt_2
=
0x6c
def
read_byte(adr):
return
bus.read_byte_data(address, adr)
def
read_word(adr):
high
=
bus.read_byte_data(address, adr)
low
=
bus.read_byte_data(address, adr+1)
val
=
(high
<<
return
val
def
read_word_2c(adr):
val
=
read_word(adr)
if
(val
>=
0x8000):
return
-((65535
else:
return
val
def
dist(a,b):
return
math.sqrt((a
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)
address
=
0x68
# Now wake the 6050 up as it starts in sleep mode
bus.write_byte_data(address, power_mgmt_1, 0)
while
True:
time.sleep(0.1)
gyro_xout
=
read_word_2c(0x43)
gyro_yout
=
read_word_2c(0x45)
gyro_zout
=
read_word_2c(0x47)
print
("gyro_xout :
print
("gyro_yout :
print
("gyro_zout :
accel_xout
=
read_word_2c(0x3b)
264
8)
+
low
-
val)
+
1)
a)+(b
b))
*
*
# or bus = smbus.SMBus(1) for Revision 2 boards
# This is the address value read via the i2cdetect command
", gyro_xout,
", gyro_yout,
", gyro_zout,
" scaled:
", (gyro_xout
" scaled:
", (gyro_yout
" scaled:
", (gyro_zout
/
131))
/
131))
/
131))
(Fortsetzung auf der nächsten Seite)
Kapitel 1. Über das Da Vinci Kit

Werbung

Inhaltsverzeichnis
loading

Verwandte Produkte für SunFounder Da Vinci Kit

Diese Anleitung auch für:

Davinci-kit-for-raspberry-pi

Inhaltsverzeichnis