Home

Awesome

ADS8718: Python class for the ADS7818 AD-converter

This is a very short and simple class. It uses the SPI bus for the interface. That ensures that the tight timing requirements of the ADS7818 are met.

Constructor

adc = ADS7818(spi, *, baudrate = 1000000, vref = 2.5, inverted = False)

Methods

value = adc.value()

Retrieves the adc raw value using the setting of the constructor. The returned value is in the range of 0 - 4095

volt = adc.voltage()

Reads the adc value and return the equivalent voltage. This is based on the vref value set in the constructor. The formula is:
voltage = 2 * vref * value / 4096

Interface

The ADS7818 is connected to the SPI bus signals. There is no CS needed. The connection consist of:

MicroADS7818
MOSICONV (5)
MISODATA (6)
CLKCLK (7)

The ADS7818 needs a Vcc of 5V. For connecting to a 3.3V device, insert a resistor of about 4.7 kOhm between MISO and DATA. Device like those of Pycom have low MOSI level. This does not nicely match the interface description of the ADS7818. In that is a problem, an inverter can be placed between MOSI and CONV, and the flag inverted has to be set True when calling the constructor.

Example

# Drive the ADS7818 ADC using SPI
# Connections:
# xxPy | ADS7818
# -----|-------
# P10  |  CLK
# P11  |  CONV
# P14  |  DATA add a series resistor of about 4.7k between DATA and P14
#
from machine import SPI
from ads7818 import ADS7818

spi = SPI(0, SPI.MASTER)
vref = 2.493 # measured at the ADS7818
ads = ADS7818(spi)

while True:
    # start a conversion and get the result back
    value = ads.value()
    volt = 2.0 * vref * value / 4096

    print(value, volt)
    res= input("Next: ")
    if res == "q":
        break