4. On Library & Hardware¶
4.1. Requirements¶
Before you check the API for the DI-Sensors, please make sure you have the DI-Sensors
package installed. You can do this by checking with pip
by typing the following command.
pip show DI-Sensors
Or you can check by trying to import the package in a Python console the following way:
import di_sensors
If there’s nothing to be shown when pip show
-ing or you get an import error on the di_sensors
package, then please check the Getting Started section and follow the instructions.
4.2. Hardware interface¶
Instantiating the 4 sensors in Python is a matter of choosing the right bus. Thus, there are 4 buses to choose from, depending on the context:
The
"RPI_1SW"
bus - this can be used along all 5 platforms we have (the GoPiGo3, GoPiGo, BrickPi3, GrovePi & PivotPi). This bus corresponds to the"I2C"
port.The
"RPI_1"
bus - this bus can be used along all 5 platforms we have (the GoPiGo3, GoPiGo, BrickPi3, GrovePi & PivotPi). Does not correspond to the"I2C"
port.The
"GPG3_AD1"
/"GPG3_AD2"
buses - these buses can only be used on the GoPiGo3 platform. The advantage of using these ones is that the interface between the Raspberry Pi and the sensor is more stable. These buses correspond to the"AD1"
and"AD2"
ports of the GoPiGo3.
Important
These notations for ports ("RPI_1SW"
, "RPI_1"
, "GPG3_AD1"
and "GPG3_AD2"
) are only required for classes that don’t start with the Easy word,
specifically for:
InertialMeasurementUnitSensor
If you choose to use a sensor library that starts with the Easy word, you can use the same notations as those used and mentioned in the GoPiGo3’s documentation, such as:
"I2C"
instead of"RPI_1SW"
."AD1/AD2"
instead of"GPG3_AD1/GPG3_AD2"
.
Also, you may notice that for the "I2C"
port we only support the "RPI_1SW"
, which is a software implementation for the I2C so that the hardware one can be avoided.
The problem with the hardware implementation (the "RPI_1"
bus) is that it’s riddled with bugs and if you don’t want your application to crash, use the software implemented one.
The software implemented driver for the I2C is as fast the HW one and it doesn’t take much CPU time at all.
For seeing where the "AD1"
/"AD2"
are located on the GoPiGo3, please check the GoPiGo3’s documentation.
4.3. Library Structure¶
4.3.1. Classes Short-List¶
The classes that are more likely to be of interest are graphically displayed shortly after this. In this graphic you can also notice inheritance links between different classes. We can notice 3 groups of classes:
Those that start with the Easy word in them and are easier to use and may provide some high-level functionalities.
Those that don’t start with the Easy word and yet are related to those that are. These are generally intented for power users.
Those that look like they might represent a model number (that belong to modules such as
di_sensors.VL53L0X
,di_sensors.BME280
, etc). These are intented for those who want to extend the functionalities of our library and are not documented here.
Note
Since this is an interactive graphic, you can click on the displayed classes and it’ll take you to the documentation of a given class, if provided.
4.3.2. Functions Short-List¶
Here’s a short summary of all classes and methods. There’s a list going on for each class. We first start off by listing the Easy classes/methods and then we end up showing the classes/methods for power users. In this short summary, we’re not covering the low-level classes that are not even documented in this documentation.
4.3.2.1. Easy - TempHumPress¶
Class for interfacing with the Temperature Humidity Pressure Sensor. |
|
Constructor for initializing link with the Temperature Humidity Pressure Sensor. |
|
Read temperature in Celsius degrees. |
|
|
Read temperature in Fahrenheit degrees. |
|
Read the air pressure in pascals. |
|
Read the relative humidity as a percentage. |
4.3.2.2. Easy - Light & Color¶
|
Class for interfacing with the Light Color Sensor. |
|
Constructor for initializing a link to the Light Color Sensor. |
|
Standard algorithm to switch from one color system (RGB) to another (HSV). |
|
Returns the color as read by the Light Color Sensor. |
|
Detect the RGB color off of the Light Color Sensor. |
|
Determines which color in_color parameter is closest to in the |
4.3.2.3. Easy - Distance¶
Class for the Distance Sensor device. |
|
|
Creates a |
|
Reads the distance in millimeters. |
Reads the distance in centimeters. |
|
|
Reads the distance in inches. |
4.3.2.4. Easy - IMU¶
4.3.2.5. Easy - Line Follower¶
Higher-level of abstraction class for either the |
|
|
Initialize a class to interface with either the |
|
Calibrate the sensor for the given |
|
Read the calibration values from the disk for the given |
Read the sensors’ values from either line follower. |
|
|
Same as calling |
|
Same as calling |
Returns a string telling to which side the black line that we’re following is located. |
|
|
Same as calling |
4.3.2.6. TempHumPress¶
Class for interfacing with the Temperature Humidity Pressure Sensor. |
|
Constructor for initializing link with the Temperature Humidity Pressure Sensor. |
|
|
Read temperature in Celsius degrees. |
|
Read temperature in Fahrenheit degrees. |
Read the air pressure in pascals. |
|
Read the relative humidity as a percentage. |
|
Read the relative humidity as a percentage. |
4.3.2.7. Light & Color¶
Class for interfacing with the Light Color Sensor. |
|
|
Constructor for initializing a link to the Light Color Sensor. |
|
Set the LED state. |
|
Read the sensor values. |
4.3.2.8. Distance¶
Class for interfacing with the Distance Sensor. |
|
Constructor for initializing a |
|
|
Start taking continuous measurements. |
|
Read the detected range while the sensor is taking continuous measurements at the set rate. |
|
Read the detected range with a single measurement. |
|
Checks if a timeout has occurred on the |
4.3.2.9. IMU¶
4.3.2.10. Line Follower Black/Red¶
Class for interfacing with the Line Follower Sensor (black board). |
|
Constructor for initializing an object to interface with the Line Follower Sensor (black board). |
|
Read the line follower’s values. |
|
Read the manufacturer of the Line Follower Sensor (black board)’s. |
|
Read the board name of the Line Follower Sensor (black board). |
|
|
Get the firmware version currently residing on the Line Follower Sensor (black board). |
Class for interfacing with the depreciated Line Follower Sensor (red board). |
|
Constructor for initializing an object to interface with the depreciated Line Follower Sensor (red board). |
|
Read the line follower’s values. |