Grove Light Sensor 1.1

This example shows how to use the Grove Light Sensor v1.1. You will also see how to plot a graph using matplotlib.

The Grove Light Sensor produces an analog signal which requires an ADC.

The Grove Light Sensor, PYNQ Grove Adapter, and Grove I2C ADC are used for this example.

When the ambient light intensity increases, the resistance of the LDR or Photoresistor will decrease. This means that the output signal from this module will be HIGH in bright light, and LOW in the dark. Values for the sensor ranges from ~5.0 (bright) to >35.0 (dark).

1. Load overlay

Download base overlay.


In [1]:
from pynq import Overlay
Overlay("base.bit").download()

2. Read single luminance value

Now read from the Grove Light sensor which is connected to the ADC. In this example, the PYNQ Grove Adapter is connected to PMODA interface on the board.

The Grove I2C ADC is used as a bridge between G4 on the Grove Adapter and the Grove Light Sensor.


In [2]:
from pynq.iop import Grove_Light
from pynq.iop import PMODA
from pynq.iop import PMOD_GROVE_G4

lgt = Grove_Light(PMODA, PMOD_GROVE_G4)

sensor_val = lgt.read()
print(sensor_val)


5.71

3. Plot the light intensity over time

This Python code will do multiple light measurements over a 10 second period.

To change the light intensity, cover and uncover the light sensor. In typical ambient light, there is no need to provide an external light source, as the sensor is already reading at full scale.


In [3]:
import time
%matplotlib inline
import matplotlib.pyplot as plt

lgt.set_log_interval_ms(100)
lgt.start_log()
# Change input during this time
time.sleep(10)
r_log = lgt.get_log()

plt.plot(range(len(r_log)), r_log, 'ro')
plt.title('Grove Light Plot')
min_r_log = min(r_log)
max_r_log = max(r_log)
plt.axis([0, len(r_log), min_r_log, max_r_log])
plt.show()