買GrovePi,主要的原因就是他的API統一了許多複雜的控制,只要學會這13個指令,就可以控制全部的Grove Sensor, 詳細的寫法要開啟 grovepi.py 來看.
API:應用程式介面,Application Programming Interface,簡稱:API),又稱為應用編程介面,就是軟體系統不同組成部分銜接的約定。由於近年來軟體的規模日益龐大,常常需要把複雜的系統劃分成小的組成部分,編程介面的設計十分重要。程式設計的實踐中,編程介面的設計首先要使軟體系統的職責得到合理劃分。良好的介面設計可以降低系統各部分的相互依賴,提高組成單元的內聚性,降低組成單元間的耦合程度,從而提高系統的維護性和擴充功能性。
現成的API可以簡少學習上的困難.以下是將Grove的API資訊轉貼在這裡.
The python library (Available at github) for grove pi has three types of functions:
- Basic Arduino Functions => Grove的核心是Arduino嗎?
- Grove Specific Functions
- 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
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
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
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
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
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
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
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)
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
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 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 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 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
沒有留言:
張貼留言