-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathADXL355_3DPlot_python-bindings.py
47 lines (35 loc) · 1.12 KB
/
ADXL355_3DPlot_python-bindings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
""" 3D plot using ADXL355 and python bindings for libiio """
import iio
import sys
from matplotlib import pyplot as plt
from matplotlib import animation
my_uri = sys.argv[1] if len(sys.argv) >= 2 else None
print("uri: " + str(my_uri))
if my_uri is None:
print("Connection error")
exit(1)
ctx = iio.Context(my_uri)
if ctx is None:
print("No context found")
exit(1)
adxl355 = ctx.find_device('adxl355')
fig = plt.figure(figsize=(4, 4))
ax = fig.add_subplot(111, projection='3d')
ax.set_xlim(-10, 10)
ax.set_ylim(-10, 10)
ax.set_zlim(-10, 10)
chx = adxl355.find_channel('accel_x').attrs
chy = adxl355.find_channel('accel_y').attrs
chz = adxl355.find_channel('accel_z').attrs
def init():
ax.scatter(0, 0, 0, s=500, c='b')
return fig,
def animate(i):
ax.collections.clear()
x = float(chx.get('raw').value) * float(chx.get('scale').value)
y = float(chy.get('raw').value) * float(chy.get('scale').value)
z = float(chz.get('raw').value) * float(chz.get('scale').value)
ax.scatter(x, y, z, s=500, c='b')
return fig,
ani = animation.FuncAnimation(fig, animate, init_func=init, interval=50)
plt.show()