On Mon, 11 Nov 2019 09:32:07 -0500, in gmane.comp.hardware.beagleboard.user
Dennis Lee Bieber <[email protected]>
wrote:
Actually, forget the immediately prior correction for adc-2
>-=-=-=- adc-2.py
>#!/usr/bin/env python3
>"""
> adc-2.py ADC example using MCP3008 and Adafruit_Blinka
> and Adafruit_CircuitPython_MCP3xxx libraries
> November 11, 2019 Dennis L Bieber
>
> *** UNTESTED **
> I do not have access to an MCP3008 ADC chip
>
> *** PREREQUISITES ***
> sudo pip3 install adafruit_blinka (might be adafruit-blinka)
> sudo pip3 install adafruit-circuitpython-mcp3xxx
>
> This code reads all 8 channels of the MCP3008. It may be worth
> checking the data sheet for the chip to determine which state
> draws the least current and using a 10KOhm or higher resister to
> pull-up/pull-down the unused inputs.
>"""
>
>import time
>
>import busio
>import digitalio
>import board
>import adafruit_mcp3xxx.mcp3008 as MCP
>from adafruit_mcp3xxx.analog_in import AnalogIn
>
>#constants from spec sheets
>ADC_REF = 3.3
>ADC_CHANNELS = 8
>
>T_DELTA = 5.0
>
>#create the SPI bus and ChipSelect
>spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)
>cs = digitalio.DigitalInOut(board.DS)
>
>#create ADC instance (note: ref_voltage default is 3.3 if not supplied)
>adc = MCP.MCP3008(spi, cs, ref_voltage = ADC_REF)
>
>#create ADC channel instances -- relies on MCP.P0 = 0, etc.
>channels = [ AnalogIn(adc, chan) for chan in range(ADC_CHANNELS) ]
>
>t0 = t = time.time()
>while True:
> print("\nT: %16.2f" % (time.time() - t0))
Replace following...
> for channel in channels:
> #while a 10-bit ADC chip, the raw counts are scaled to 65472
> raw, voltage = channels[channel].value, channels[channel].voltage
> print("\tChannel: %2d\tCount: %4d\tVoltage: %6.3f"
> % (channel, raw, voltage))
for ch, channel in enumerate(channels):
#while a 10-bit ADC chip, the raw counts are scaled to 65472
raw, voltage = channel.value, channel.voltage
print("\tChannel: %2d\tCount: %4d\tVoltage: %6.3f"
% (ch, raw, voltage))
> t += T_DELTA
> time.sleep(t - time.time())
>-=-=-=-
--
Dennis L Bieber
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/beagleboard/q01jselmqhg9r70bfoejfnq7f23nq3ecjj%404ax.com.