Skip to main content

Python library for Seeedstudio Grove devices

Project description

grove.py

Build Status

Python library for Seeedstudio Grove Devices on Raspberry Pi.

Installation

sudo pip install grove.py

Usage

After installing grove.py, A few CLI commands with prefix grove_ is available, such as grove_led, grove_button, grove_ultrasonic_ranger and etc. For I2C Grove devices, the default bus is used (I2C 1 on Pi). For digital input & output Grove devices, pin numbers should be provided as the arguments of these commands.

grove_i2c_color_sensor_v2
grove_led 12
grove_button 22
grove_ultrasonic_sensor 12 13

For digital output device like Grove - LED

import time
from grove.grove_led import GroveLed

led = GroveLed(12)

while True:
    led.on()
    time.sleep(1)
    led.off()
    time.sleep(1)

For digital input device like Grove - Button

import time
from grove.grove_button import GroveButton

button = GroveButton(12)

def on_press(t):
    print('Button is pressed')

button.on_press = on_press

while True:
    time.sleep(1)

Basic GPIO Input & Output

import time
from grove.gpio import GPIO

led = GPIO(12, GPIO.IN)
button = GPIO(22, GPIO.OUT)

def on_button_event(pin, value):
    print('pin {} is {}'.format(pin, value))
    led.write(value)

button.on_event = on_button_event

while True:
    time.sleep(1)

For Grove 4 Digit Display

import time
from grove.grove_4_digit_display import Grove4DigitDisplay

display = Grove4DigitDisplay(12, 13))

count = 0
while True:
    t = time.strftime("%H%M", time.localtime(time.time()))
    display.show(t)
    display.set_colon(count & 1)
    count += 1
    time.sleep(1)

For Grove I2C Color Sensor V2

import time
from grove.grove_i2c_color_sensor_v2 import GroveI2CColorSensorV2
sensor = GroveI2cColorSensorV2()

print('Raw data of red-filtered, green-filtered, blue-filtered and unfiltered photodiodes')
while True:
    # r, g, b = sensor.rgb
    r, g, b, clear = sensor.raw
    print((r, g, b, clear))
    time.sleep(1.0)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

grove.py-0.2.tar.gz (9.8 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page