Created
February 2, 2016 11:23
-
-
Save thisMagpie/6a3658225100d927d4cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from webiopi.devices.analog import MCP3208 | |
import pylab | |
import numpy as np | |
x = [0.0]*100 | |
y = [0.0]*100 | |
hi_arr = [0.0] | |
low_arr = [0.0] | |
hi_0 = 2.84 | |
low_0 = 0.320 | |
hi = 2.20 | |
low = 0.880 | |
ADC0 = MCP3208(chip = 0) | |
print("Analog Channel Count {0}").format(ADC0.analogCount()) | |
print("Analog Bit Resolution {0}").format(ADC0.analogResolution()) | |
print("Analog Maximum {0}").format(ADC0.analogMaximum()) | |
print("Analog Reference Voltage {0}").format(ADC0.analogReference()) | |
for i in range(100): | |
y[i] = ADC0.analogReadVolt(3) | |
x[i] = i + 1 | |
if (y[i] > hi/2.0): | |
hi_arr.append(y[i]) | |
else: | |
low_arr.append(y[i]) | |
print("[{0}] {1}").format(x[i], y[i]) | |
hi_mean = np.mean(hi_arr) | |
low_mean = np.mean(low_arr) | |
print("Mean\n{0} {1}").format(hi_mean, low_mean) | |
v_adc = [0.447, low_mean, hi_mean, 2.90] | |
v_osc = [low_0, low, hi, hi_0] | |
pylab.plot(v_osc, v_adc) | |
pylab.xlabel('Measured Voltage (Volts)') | |
pylab.ylabel('ADC Voltage (Volts)') | |
pylab.title('Bit Resolution vs Sample No. for square wave') | |
pylab.grid(True) | |
pylab.savefig("sample_3_3.pdf") | |
pylab.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment