This example shows how to use the Grove ADC.
A Grove I2C ADC (v1.2) and PYNQ Grove Adapter are required. An analog input is also required. In this example, the Grove slide potentiometer was used.
In the example, the ADC is initialized, a test read is done, and then the sensor is set to log a reading every 100 milliseconds. The ADC can be connected to any Grove peripheral that provides an analog voltage.
In [1]:
from pynq import Overlay
Overlay("base.bit").download()
In [2]:
from pynq.iop import Grove_ADC
from pynq.iop import PMODA
from pynq.iop import PMOD_GROVE_G4
grove_adc = Grove_ADC(PMODA, PMOD_GROVE_G4)
print("{} V".format(round(grove_adc.read(),4)))
In [3]:
grove_adc.set_log_interval_ms(100)
grove_adc.start_log()
In [4]:
log = grove_adc.get_log()
In [5]:
%matplotlib inline
import matplotlib.pyplot as plt
plt.plot(range(len(log)), log, 'ro')
plt.title('Grove ADC Voltage Log')
plt.axis([0, len(log), min(log), max(log)])
plt.show()
In [6]:
from pynq.iop import Grove_ADC
from pynq.iop import ARDUINO
from pynq.iop import ARDUINO_GROVE_I2C
grove_adc = Grove_ADC(ARDUINO, ARDUINO_GROVE_I2C)
print("{} V".format(round(grove_adc.read(),4)))
In [7]:
grove_adc.set_log_interval_ms(100)
grove_adc.start_log()
In [8]:
log = grove_adc.get_log()
In [9]:
%matplotlib inline
import matplotlib.pyplot as plt
plt.plot(range(len(log)), log, 'ro')
plt.title('Grove ADC Voltage Log')
plt.axis([0, len(log), min(log), max(log)])
plt.show()