2015年4月30日 星期四

Grove Pi’s python API

買GrovePi,主要的原因就是他的API統一了許多複雜的控制,只要學會這13個指令,就可以控制全部的Grove Sensor, 詳細的寫法要開啟 grovepi.py 來看.

API:應用程式介面,Application Programming Interface,簡稱:API),又稱為應用編程介面,就是軟體系統不同組成部分銜接的約定。由於近年來軟體的規模日益龐大,常常需要把複雜的系統劃分成小的組成部分,編程介面的設計十分重要。程式設計的實踐中,編程介面的設計首先要使軟體系統的職責得到合理劃分。良好的介面設計可以降低系統各部分的相互依賴,提高組成單元的內聚性,降低組成單元間的耦合程度,從而提高系統的維護性和擴充功能性。

GROVEPI-SOFTWARE-ARCHITECTURE-1024x914
現成的API可以簡少學習上的困難.以下是將Grove的API資訊轉貼在這裡.


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

  1. Basic Arduino Functions => Grove的核心是Arduino嗎?
  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

沒有留言:

張貼留言

2024東京迪士尼,愛與夢想的樂園行

疫情的關係, 很多年沒有出國旅遊了.這回計畫出遊日本.歷經磨難的挑選.最後勝出的行程是五福旅行社的"銀色雪東京五日-戲雪,和服體驗,迪士尼"這標題簡單的標註出此行的目的. 上回去東京是20年前了.可以參考一下過去 2004年的Blog紀錄 心中的願景是能看到前...