我正在尝试使用覆盆子PI4为AD8232心脏监护仪编程。据我所知,我已经为ump和ADC ads1115安装了所有正确的软件包
问题是,当我尝试运行代码时,我得到一个值错误:
File "/usr/lib/python2.7/dist-packages/upm/pyupm_ad8232.py", line 170, in init
this = _pyupm_ad8232.new_AD8232(loPlus, loMinus, output, aref)
ValueError: UPM Invalid Argument: Invalid AIO pin specified - do you `have an ADC?`
#!/usr/bin/env python3
from __future__ import print_function
import time, sys, signal, atexit
from upm import pyupm_ad8232 as upmAD8232
def main():
# Instantiate a AD8232 sensor on digital pins 10 (LO+), 11 (LO-)
# and an analog pin, 0 (OUTPUT)
myAD8232 = upmAD8232.AD8232(10, 11, 0)
## Exit handlers ##
# This function stops python from printing a stacktrace when you hit
def SIGINTHandler(signum, frame):
raise SystemExit
# This function lets you run code on exit, including functions from myAD8232
def exitHandler():
print("Exiting")
sys.exit(0)
# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)
# Output the raw numbers from the ADC, for plotting elsewhere.
# A return of 0 indicates a Lead Off (LO) condition.
# In theory, this data could be fed to software like Processing
# (https://www.processing.org/) to plot the data just like an
# EKG you would see in a hospital.
while(1):
print(myAD8232.value())
time.sleep(.001)
if __name__ == '__main__':
main()
#!/usr/bin/env python
# Author: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
# Copyright (c) 2016 Intel Corporation.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# This example demonstrates how to use one of the ADS1115 ADCs on the
# DFRobot Joule Shield with devices that output a small differential
# voltage (e.g. geophones, piezoelectric bands or pads, thermocouples).
from __future__ import print_function
from threading import Timer
from time import sleep
from upm import pyupm_ads1x15 as upm
def stop():
global running
running = False
def main():
global running
running = True
fileName = './ads1115.data' # Output filename
id = 0 # Sample number
# Initialize and configure the ADS1115 for the SM-24 Geophone
# There are two ADS1115 chips on the DFRobot Joule Shield on the same I2C bus
# - 0x48 gives access to pins A0 - A3
# - 0x49 gives access to pins A4 - A7
ads1115 = upm.ADS1115(0, 0x48)
# Put the ADC into differential mode for pins A0 and A1,
# the SM-24 Geophone is connected to these pins
ads1115.getSample(upm.ADS1X15.DIFF_0_1)
# Set the gain based on expected VIN range to -/+ 2.048 V
# Can be adjusted based on application to as low as -/+ 0.256 V, see API
# documentation for details
ads1115.setGain(upm.ADS1X15.GAIN_TWO)
# Set the sample rate to 860 samples per second (max) and turn on continuous
# sampling
ads1115.setSPS(upm.ADS1115.SPS_860)
ads1115.setContinuous(True)
# Open the output file
try:
f = open(fileName, 'w')
except OSError as e:
print('Cannot open output file:', e)
return
# Setup a timer to stop logging after 10 seconds
t = Timer(10, stop)
t.start()
# Read sensor and write to file every 1 ms
while running:
f.write(str(id) + ' %.7f' % ads1115.getLastSample() + '\n')
id += 1
sleep(0.001)
# Close and exit
f.close()
print('Wrote', id, 'samples to file:', fileName)
return
if __name__ == '__main__':
main()
目前没有回答
相关问题 更多 >
编程相关推荐