Skip to content

Instantly share code, notes, and snippets.

@thisMagpie
Created November 25, 2015 15:52
Show Gist options
  • Save thisMagpie/31eae3a941cf500e43a7 to your computer and use it in GitHub Desktop.
Save thisMagpie/31eae3a941cf500e43a7 to your computer and use it in GitHub Desktop.
from webiopi.devices.analog import MCP3208
import pylab
import numpy as np
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())
x = [0.0]*100
y = [0.0]*100
for i in range(100):
#print("Analog bit resolution at input channel {0}: {1}").format( 3, ADC0.analogRead(3))
#print("Analog Read Voltage Channel {0}: {1}").format( 3, ADC0.analogReadVolt(3))
y[i] = ADC0.analogRead(3)
x[i] = i + 1
print("[{0}] {1} {2}").format(x[i], y[i], ADC0.analogReadVolt(3))
pylab.plot(x, y)
pylab.xlabel('Sample No')
pylab.ylabel('Bit Resolution')
pylab.title('Bit Resolution vs Sample No.')
pylab.grid(True)
pylab.savefig("sample_3_2.pdf")
pylab.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment