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.
For analog devices, slot number(n of PCB sink An) should be provided.
Some devices need root permission signed in sudo column, the coresponding command must prefix with "sudo" if run with a none-root user.
Most of the commands will list the available argument/pin when it need argument but not specifying.
Grove Devices | Command | RPi | Argument/Comment |
---|---|---|---|
1-Wire Thermocouple Amplifier (MAX31850K) | grove_1wire_thermocouple_amplifier_max31850 | • | 1-Wire |
3-Axis Digital Compass V2 | grove_3_axis_compass_bmm150 | y | I2C |
3-Axis Digital Accelerometer(+/-400g) | grove_3_axis_digital_accelerometer | y | I2C |
4 Digit Display | grove_4_digit_display | y | arg1 - digital pin |
6-Axis Accelerometer&Gyroscope | grove_6_axis_accel_gyro_bmi088 | y | I2C |
12 Key Capacitive I2C Touch Sensor V2(MPR121) | grove_12_key_cap_i2c_touch_mpr121 | y | I2C |
16 x 2 LCD (Black on Red) 16 x 2 LCD (Black on Yellow) 16 x 2 LCD (White on Blue) |
grove_16x2_lcd | y | I2C |
Air quality sensor v1.3 | grove_air_quality_sensor_v1_3 | y | arg1 - analog pin |
Button | grove_button | y | arg1 - digital pin |
Capacitive Touch Slide Sensor(CY8C4014LQI) | grove_cap_touch_slider_cy8c | y | I2C |
Collision Sensor | grove_collision_sensor | y | arg1 - digital pin |
Gesture Sensor v1.0 | grove_gesture_sensor | y | I2C |
I2C High Accuracy Temperature Sensor(MCP9808) | grove_high_accuracy_temperature | y | I2C |
I2C Color Sensor V2 | grove_i2c_color_sensor_v2 | y | I2C |
I2C Motor Driver | grove_i2c_motor_driver | y | I2C |
I2C Thermocouple Amplifier (MCP9600) | grove_i2c_thermocouple_amplifier_mcp9600 | y | I2C |
IMU 9DOF (ICM20600+AK09918) | grove_imu_9dof_icm20600_ak09918 | y | I2C |
OLED Display 1.12" OLED Display 1.12" V2 |
grove_lcd_1.2inches | y | I2C |
Red LED Green LED Purple LED White LED |
grove_led | y | arg1 - digital pin |
Light Sensor V1.2 | grove_light_sensor_v1_2 | y | arg1 - analog pin |
Loudness Sensor | grove_loudness_sensor | y | arg1 - analog pin |
Mech Keycap | grove_mech_keycap | • | arg1 - PWM pin |
mini PIR motion sensor PIR Motion Sensor |
grove_mini_pir_motion_sensor | y | arg1 - digital pin |
Moisture Sensor | grove_moisture_sensor | y | arg1 - analog pin |
5-Way Switch 6-Position DIP Switch |
grove_multi_switch or grove_multi_switch_poll |
y | I2C |
OLED Display 0.96" | grove_oled_display_128x64 | y | I2C |
Optical Rotary Encoder(TCUT1600X01) | grove_optical_rotary_encoder | y | arg1 - digital pin |
Piezo Vibration Sensor | grove_piezo_vibration_sensor | y | arg1 - digital pin |
Buzzer | grove_pwm_buzzer | • | PWM |
Recorder v3.0 | grove_recorder_v3_0 | y |
arg1 - digital pin arg2 - record duration in seconds |
Relay | grove_relay | y | arg1 - digital pin |
Rotary Angle Sensor(P) | grove_rotary_angle_sensor | y | arg1 - analog pin |
Round Force Sensor FSR402 | grove_round_force_sensor | y | arg1 - analog pin |
Red LED Button Yellow LED Button Blue LED Button |
grove_ryb_led_button | y | arg1 - digital pin |
Servo | grove_servo | y | arg1 - digital pin |
Slide Potentiometer | grove_slide_potentiometer | y | arg1 - analog pin |
Sound Sensor | grove_sound_sensor | y | arg1 - analog pin |
Step Counter(BMA456) | grove_step_counter_bma456 | y | I2C |
Switch(P) | grove_switch | y | arg1 - digital pin |
Temperature, Humidity, Pressure and Gas Sensor (BME680) | grove_temperature_humidity_bme680 | y | I2C |
Temperature & Humidity Sensor (DHT11) Temperature & Humidity Sensor Pro (AM2302) |
grove_temperature_humidity_sensor | y |
arg1 - digital pin arg2 - dht_type, could be 11 or 22, represent DHT11, DHT22/AM2302 |
Temperature & Humidity Sensor (SHT31) | grove_temperature_humidity_sht31 | y | I2C |
Temperature Sensor | grove_temperature_sensor | y | arg1 - analog pin |
Thumb Joystick | grove_thumb_joystick | y | arg1 - analog pin |
Tilt Switch | grove_tilt_switch | y | arg1 - digital pin |
Time of Flight Distance Sensor VL53L0X | grove_time_of_flight_distance | y | I2C |
Touch Sensor | grove_touch_sensor | y | arg1 - digital pin |
Ultrasonic Ranger | grove_ultrasonic_ranger | y | arg1 - digital pin |
UV Sensor | grove_uv_sensor | y | I2C |
VOC and eCO2 Gas Sensor (SGP30) | grove_voc_eco2_gas_sgp30 | y | I2C |
Water Sensor | grove_water_sensor | y | arg1 - analog pin |
WS2813 RGB LED Strip Waterproof - 30 LED/m - 1m WS2813 RGB LED Strip Waterproof - 60 LED/m - 1m WS2813 RGB LED Strip Waterproof - 144 LED/m - 1m |
grove_ws2813_rgb_led_strip | • |
arg1 - PWM pin arg2 - led count, could be 30, 60, 144 for the three models listed left. |
• means supported but prefix sudo
must be provided.
y
means supported without prefix sudo
.
You can copy below codes directly, and paste into any Python IDE (such as Thonny Python IDE) to run the demo and see the effect.
import time
from grove.grove_led import GroveLed
led = GroveLed(12)
while True:
led.on()
time.sleep(1)
led.off()
time.sleep(1)
import time
from grove.factory import Factory
relay = Factory.getGpioWrapper("Relay",16)
while True:
relay.on()
time.sleep(2)
relay.off()
time.sleep(5)
import time
from grove.factory import Factory
pin = 12
button = Factory.getButton("GPIO-HIGH", pin)
while True:
if button.is_pressed():
print('Button is pressed')
else:
print('Button is released')
time.sleep(1)
import time
from grove.factory import Factory
### connect to pin 5(slot D5)
pir = Factory.getGpioWrapper("PIRMotion", 5)
while True:
if pir.has_motion():
print("Hi, people is moving")
else:
print("Watching")
time.sleep(1)
import time
from grove.factory import Factory
buzzer = Factory.getGpioWrapper("Buzzer", 12)
while True:
buzzer.on()
time.sleep(1)
buzzer.off()
time.sleep(3)
import time
from grove.factory import Factory
magnet = Factory.getGpioWrapper("Electromagnet", 12)
while True:
magnet.on()
time.sleep(1)
magnet.off()
time.sleep(3)
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)
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)
Use along with DC-Motor.
import time
from grove.grove_i2c_motor_driver import MotorDriver
motor = MotorDriver()
while True:
# speed range: 0(lowest) - 100(fastest)
motor.set_speed(100)
# channel 1 only
# to set channel 1&2: motor.set_speed(100, 100)
# direction: True(clockwise), False(anti-clockwise)
motor.set_dir(True)
# channel 1 only,
# to set channel 1&2: motor.set_dir(True, True)
time.sleep(2)
motor.set_speed(70)
motor.set_dir(False)
time.sleep(2)
Use along with Stepper Motor 24BYJ48/28BYJ48.
Connections between 24BYJ48/28BYJ48 and I2C-Motor-Driver:
I2C-Motor-Driver | 24BYJ48 Wires | 28BYJ48 Wires |
---|---|---|
J1.M1-/OUT1 | Blue | Blue |
J1.M1+/OUT2 | Pink | Orange |
J2.M2-/OUT3 | Orange | Yellow |
J2.M2+/OUT4 | Yellow | Pink |
from grove.factory import Factory
import time
motor = Factory.getStepperMotor("24BYJ48")
# If it's 28BYJ48
# motor = Factory.getStepperMotor("28BYJ48")
ANGLE = 360 # rotate 360 degrees = 1 cycle
motor.rotate(ANGLE)
# set speed to max rpm, for Motor 24BYJ48, it's 30 RPM.
# direction is clockwise, anti-clockwise use negative value (-30)
SPEED = motor.speed_max # SPEED = 30
motor.speed(SPEED)
motor.enable(True) # enable the motor, begin to run
seconds = ANGLE / 360.0 / SPEED * 60
print("Motor {} rotate {} degrees, time = {:.2f}".format(motor.name, ANGLE, time.time()))
print(" with speed {} RPM".format(SPEED))
print(" will be stop after {:4.2f} seconds".format(seconds))
while True:
left = motor.rotate()
if left < 1e-5: break
print("Angle left {:6.2f} degrees, time = {:.2f}".format(left, time.time()))
time.sleep(1.0)
print("Motor run ended, time = {:.2f} !".format(time.time()))
import time
import RPi.GPIO as GPIO
# Grove Base Hat for Raspberry Pi
# PWM JST SLOT - PWM[12 13 VCC GND]
pin = 12
# create PWM instance
pwm = GPIO.PWM(pin, 10)
pwm.start(0)
# 1000 Hz sound
pwm.ChangeFrequency(1000)
pwm.ChangeDutyCycle(100)
import time
from grove.grove_temperature_humidity_sensor import DHT
# DHT11 type
# insert to GPIO pin 5, slot D5
dht11 = DHT("11", 5)
while True:
humi, temp = dht11.read()
print('DHT{0}, humidity {1:.1f}%, temperature {2:.1f}*'.format(dht11.dht_type, humi, temp))
time.sleep(1)
import time
from grove.factory import Factory
# LCD 16x2 Characters
dobj = Factory.getDisplay("JHD1802")
# If it's OLED Display 1.12"
# dobj = Factory.getDisplay("SH1107G")
rows, cols = dobj.size()
print("LCD model: {}".format(dobj.name))
print("LCD type : {} x {}".format(cols, rows))
dobj.setCursor(0, 0)
dobj.write("hello world!")
dobj.setCursor(0, cols - 1)
dobj.write('X')
dobj.setCursor(rows - 1, 0)
for i in range(cols):
dobj.write(chr(ord('A') + i))
time.sleep(3)
dobj.clear()
from grove.grove_ultrasonic_ranger import GroveUltrasonicRanger
import time
sonar = GroveUltrasonicRanger(12) # pin12, slot D12
print('Detecting distance...')
while True:
print('{} cm'.format(sonar.get_distance()))
time.sleep(1)