python - Analog sampling on the Beaglebone Black only reads noise -
i want write script in python data acquisition beaglebone black. however, i'm getting noise when read in values.
i have circuit set feed in signal (i running .1-10 hz 12v square pulse), voltage regulator limits voltage 5v, , voltage divider drops down safe voltage (~1v) analog pin on bbb.
circuit:
then using python script wanted log values array , plot them once program finished.
in ipython shell:
in [1]: import adafruit_bbio.adc adc in [2]: import time in [3]: ain0 = "p9_39" in [4]: t = 0.1 # or other value in [5]: adc.setup() in [6]: = [] in [7]: while true: a.append(adc.read(ain0)*1800) # pin value times 1.8 ref voltage time.sleep(t)
after running while, crash script , write a
file scp
ed desktop. when plot it, it's noise. i've hooked on o-scope between ain0
, ground , wave form expect. set potentiometer so:
and able read in correct values through python. so, figure must doing continuous sampling that's creating problems.
if don't connect power supply ground beaglebone ground not work, , should indeed see noise, since ain0
sampling beaglebone's ground. have connect them in order ain0
see signal of interest.
see "missing connection" wire. if don't have have no return path current coming power supply (blue arrows), there can't voltage across pontentiometer (remember ohm's law: voltage = resistance x current
. if current zero, sampled voltage must zero).
as script part, can directly write sampled data file this:
with open('sampled_data.csv', 'w') f: while true: f.write(','.join(str(adc.read(ain0)*1800))) time.sleep(t)
when interrupt script you'll sample_data.csv
file, values separated commas (,
), importable spreadsheet or other software use plot it.
Comments
Post a Comment