Before compiling the following programs, readers must follow the steps shown in the “Hardware Interaction” section.
Sensors are acceded using file operations that operate on special device files. In order to access the sensor data, the user must perform a few steps that involve opening the device, mapping the device data in user space, and if needed, configuring the device.
Opening and mapping the device is done in pretty much the same way for all types of sensors. The following examples cover some typical cases:
At startup, a sensor will be configured to work using default configuration parameters, however users may want to change the sampling frequency, pick a different mode of operation, increase the number of bytes in the data packet, or send direct commands to the sensor. This is done using input/output control functions (ioctl). The use of this function requires some understanding of the sensor capabilities. The following examples show the use of configuration functions: