What you need to get started:

Raspberry Pi and GrovePi Interrupts

If you have a hardware component, like a switch or a button, that you want to track, one way is to constantly monitor, or poll, that switch. This involves using code similar to the following:

 GPIO.setup(pin15, GPIO.IN)
 while GPIO.input(pin15) == 1:
    time.sleep(.01)
 print("Pin 15 set low")

The only problem with this kind of approach is that you'll end up tying up the CPU; in fact, if we didn't add the sleep() call, the CPU would be occupied completely with our single, simple program. 

The alternative to this is to let the peripheral device, like our switch, inform the CPU when an event has happened; this alert by the device is called an interrupt. This approach eliminates the need for a loop or a delay and lets the CPU concentrate on other programs while nothing is happening at the switch. For example, we can use some code like the following:

  GPIO.wait_for_edge(pin15, GPIO.RISING)
print("Pin 15 set low")

In general, if you have a sensor like a light sensor which utilizes an analog input (ignoring the quantum nature of light, of course! :), it has an internal threshold which, when surpassed, triggers an event that is communicated to the processor that can subsequently be handled by an interrupt (for which you can add an interrupt handler in your Python code), thus avoiding the need for polling.

You can learn up more about interrupts with the GrovePI and Raspberry Pi by perusing the following links:

In particular, the text references connecting devices to various pins.  At first, it might seem that the GrovePi is simplifying that for you by mapping particular pins to ports on the GrovePi.  But this is not the case. All the ports on the GrovePi are connected to the microcontroller on the GrovePi.  The Raspberry Pi (RPi) only communicates with the GrovePi microcontroller through the Python API that Dexter Labratories provides, and all of that communication happens on the I2C bus.  All but one of the 26 pins that are exposed on top of the GrovePi are simply pass-through and can be used to support another RPi HAT (a "Hardware Attached on Top" add-on board that conforms to a specific set of rules and enables the RPi to automatically configure its GPIO signals and drivers for use with external devices) or directly connected to devices via a breadboard. This means that the only way an interrupt can be initiated by anything on the GrovePi is over the I2C serial interface, which would mean a software-based interrupt. Thus, the GrovePi simulates an interrupt but you will normally have to create the interrupt with software. For more on hardware interrupts vs software-based interrupts, please do see this link: https://unix.stackexchange.com/questions/17998/what-are-software-and-hardware-interrupts-and-how-are-they-processed/18023

Sensors Not Working

If you're having issues getting the sensors to work, or if they seem to work intermittently or half-heartedly, the most likely solution is repeated firmware/dependency update cycles or going with the Raspbian For Robots distro by Dexter Industries installation. 

For the first case, it's likely a firmware issue; in this case, you have to update the firmware and reinstall GrovePi dependencies, as seen in this link: https://forum.dexterindustries.com/t/solved-dht-sensor-responding-1/2815/4

Usually, Steps 1 - 3 solve the problem and you don't need to do any of the in-depth troubleshooting. You can also increase the sleep interval from 0.05 to 0.1 to avoid NaN errors if you're getting those.

Here are the steps, directly from the above link:

 

  1. Run the firmware update without any sensors or HDMI connected to the Pi. So, open a terminal and follow this commands.:
cd /home/pi/Dexter/GrovePi/Firmware
sudo bash firmware_update.sh
  1. Then next, let’s reinstall the GrovePi dependencies (there might be something that’s still not set up). After you update the firmware, you’ll reboot it. So, open a terminal and follow this commands:
cd /home/pi/Dexter/GrovePi/Script
sudo bash install.sh
sudo reboot
  1. Run again your DHT sensor example from here: https://github.com/DexterInd/GrovePi/blob/master/Projects/Home_Weather_Display/Home_Weather_Display.py