Python Library Documentation

Python Library Documentation

Write your First Python Program for the GrovePi

In this video we walk you through writing your first program in Python for the GrovePi.

 

Python Documentation

The python library (Available at github) for grove pi has three types of functions:

  1. Basic Arduino Functions
  2. Grove Specific Functions
  3. Private Functions for Communication

Basic Arduino Functions

  • digitalRead(pin)

Reads the value from a specified digital pin, either HIGH or LOW.

Parameter:     

pin: The Pin number

Return: 1 for HIGH and 0 for LOW

  • digitalWrite(pin,value)

Write a HIGH or a LOW value to a digital pin.

Parameter:

pin: The Pin number

value: 1 for HIGH and 0 for LOW

Return: 1 on success

  • pinMode(pin,mode)

Configures the specified pin to behave either as an input or an output.

Parameter:

pin: the number of the pin whose mode you wish to set

mode: INPUT, OUTPUT

Return: 1 on success

  • analogRead(pin):

Reads the value from the specified analog pin.

Parameters

pin: the number of the analog input pin to read from (0,1 and 2)

Returns: 0 to 1023

  • analogWrite(pin,value):

Writes an analog value (PWM wave) to a pin

Parameters

pin: the pin to write to.

value: the duty cycle: between 0 (always off) and 255 (always on).

Return: 1 on success

Grove Specific functions

  • temp(pin)

Read the temperature from the analog Grove Temperature Sensor http://www.seeedstudio.com/depot/Grove-Temperature-Sensor-p-774.html

Parameter:

pin: the number of the analog input pin to read from (0,1 and 2)

Return: temp in float

  • ultrasonicRead(pin)

Read the distance reading from the Grove Ultasonic ranger http://www.seeedstudio.com/depot/Grove-Ultrasonic-Ranger-p-960.html

Parameter:

pin: pin on which the Ultrasonic ranger is connected

Return: distance in cm

  • acc_xyz()

read the x,y,z value from the accelerometer http://www.seeedstudio.com/depot/Grove-3Axis-Digital-Accelerometer15g-p-765.html?cPath=25_26

return: an array of 3 values [x,y,z] -32 to 32 (-1.5g to +1.5g)

  • rtc_getTime()

Read the time from Grove RTC http://www.seeedstudio.com/depot/Grove-RTC-p-758.html?cPath=25_30

Return: 8 byte array [hour,min,sec,month,dayOfMonth,year,dayOfMonth,dayOfWeek] or junk value if RTC not connected

  • dht (pin,module_type)

Parameter:

pin: pin on which the DHT  sensor  is connected

module_type:

0-      DHT11

1-      DHT22

2-      DHT21

3-      AM2301

Return:  array of 2 floats [temp,humidity]

Private functions (should not be used directly)

  • write_i2c_block (address,block)

Write a block of data to address using I2C interface

Parameter:

address: address of the I2C device (0x04 GrovePi)

block: block of data in bytes to be sent

Return: positive value on success, -1 on failure

  • read_i2c_block (address)

Read a block of data from address using I2C interface

Parameter:

address: address of the I2C device (0x04 GrovePi)

Return: block of data read on success, -1 on failure

  • read_i2c_byte (address)

Read a byte of data from address using I2C interface

Parameter:

address: address of the I2C device (0x04 GrovePi)

Return: byte of data read on success, -1 on failure

Have a question or a problem?  Post it on the forums and we’ll help you out.

{"cart_token":"","hash":"","cart_data":""}