Skip to content

Commit 424b3d8

Browse files
author
neil.hamilton
committed
Add looped capture and data display to example
1 parent 8b5888b commit 424b3d8

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

pt104Examples/pt104Example.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import numpy as np
1010
from picosdk.functions import assert_pico_ok
1111
from time import sleep
12+
import matplotlib.pyplot as plt
1213

1314
# Create chandle and status ready for use
1415
status = {}
@@ -31,16 +32,32 @@
3132
status["setChannel1"] = pt104.UsbPt104SetChannel(chandle, channel, datatype, noOfWires)
3233
assert_pico_ok(status["setChannel1"])
3334

34-
print(status)
35+
#collect data
36+
print("collecting data")
37+
numSamples = 20
3538

36-
#pause
37-
sleep(2)
39+
data = (ctypes.c_int32 * numSamples)()
3840

39-
# Get values
40-
value = ctypes.c_int32()
41-
filtered = 1 # true
42-
status["getValue"] = pt104.UsbPt104GetValue(chandle, channel, ctypes.byref(value), filtered)
43-
assert_pico_ok(status["getValue"])
41+
for i in range(numSamples):
42+
43+
#pause
44+
sleep(2)
45+
46+
# Get values
47+
measurement = ctypes.c_int32()
48+
filtered = 1 # true
49+
status["getValue"] = pt104.UsbPt104GetValue(chandle, channel, ctypes.byref(measurement), filtered)
50+
assert_pico_ok(status["getValue"])
51+
52+
data[i] = measurement.value
53+
54+
samples = np.linspace(0, numSamples*2, numSamples)
55+
dataTemp = [x /1000 for x in data]
56+
57+
plt.plot(samples, dataTemp)
58+
plt.xlabel('Time (s)')
59+
plt.ylabel('Temperature ($^o$C)')
60+
plt.show()
4461

4562
# Close the device
4663
status["closeUnit"] = pt104.UsbPt104CloseUnit(chandle)

0 commit comments

Comments
 (0)