L3G4200D Arduino Unified Sensor Library
Public Member Functions | List of all members
L3G4200D_Unified Class Reference

Class for interfacing with an L3G4200D gyroscope, using the Adafruit Unified Sensor API. Most common methods: L4G4200D_Unified::begin and L3G4200D_Unified::getEvent. More...

#include <L3G4200D_U.h>

Inheritance diagram for L3G4200D_Unified:

Public Member Functions

 L3G4200D_Unified (int32_t sensorId)
 Create a new object representing an L3G4200D gyroscope. More...
 
bool begin (int spiChipSelect, gyroRange_t range=GYRO_RANGE_4_DOT_36_RAD_PER_SEC, SPIClass &spi=SPI, uint32_t spiFrequency=5L *1000L *1000L)
 Initializes this L3G4200D gyroscope using SPI. More...
 
void enableAutoRange (bool enabled)
 Enables automatic range increasing if the sensor seems to be saturating its current range. More...
 
void enableDebugLogging (bool enabled)
 Enables or disables debug logging to the Serial console. More...
 
bool getEvent (sensors_event_t *event)
 The Unified Sensor API method to get data from this sensor. More...
 
void getSensor (sensor_t *sensor)
 The Unified Sensor API method to get information about this sensor. More...
 
void setRange (gyroRange_t range)
 Sets the range for this gyroscope. More...
 
float rangeInRadians ()
 Returns the full scale of the current range in the SI unit rad/s. More...
 
uint8_t rawReadReg (uint8_t regAddress)
 Advanced functionality: reads a raw value from a raw address. See Registers for more information. More...
 
void rawWriteReg (uint8_t regAddress, uint8_t newValue)
 Advanced functionality: writes a raw value to a raw address. See Registers for more information. More...
 

Detailed Description

Class for interfacing with an L3G4200D gyroscope, using the Adafruit Unified Sensor API. Most common methods: L4G4200D_Unified::begin and L3G4200D_Unified::getEvent.

Constructor & Destructor Documentation

◆ L3G4200D_Unified()

L3G4200D_Unified::L3G4200D_Unified ( int32_t  sensorId)

Create a new object representing an L3G4200D gyroscope.

Parameters
sensorIdA number to uniquely identify this sensor. This number can be arbitrarily chosen by you, but should not be shared with any other sensors in your sketch.

Member Function Documentation

◆ begin()

bool L3G4200D_Unified::begin ( int  spiChipSelect,
gyroRange_t  range = GYRO_RANGE_4_DOT_36_RAD_PER_SEC,
SPIClass &  spi = SPI,
uint32_t  spiFrequency = 5L * 1000L * 1000L 
)

Initializes this L3G4200D gyroscope using SPI.

Parameters
spiChipSelect

The pin number on your board that you have connected to the SPI CS (Chip Select) pin on the L3G4200D. For example, on the Digilent PmodGYRO, CS is pin 1 on the J1 (the first jumper). If you connected that pin to pin 10 on your Arduino board, then you would call L4G4200D_Unified::begin like this:

L3G4200D_Unified gyroscope = L3G4200D(2113);
gyroscope.begin(10);

Parameters
rangeOne of the gyroRange_t values to use for this gyroscope. Defaults to 4.36 rad/s.
spi

The SPI interface to use when communicating to this gyroscope. Defaults to SPI, the default SPI interface on Arduino boards. This is often connected to pins labeled SCK, MOSI, and MISO on the physical board. For example, on Arduino Uno the MISO of the default SPI interface is pin 12.

spiFrequencyThe clock frequency for the SPI peripheral. Defaults to 5 MHz if not specified. Must be lower than 10 MHz, per the L3G4200D datasheet.
Returns
True if this sensor was successfully activated, false if it was not. If false, you can use enableDebugLogging to potentially get information on why logged in your serial console.

◆ enableAutoRange()

void L3G4200D_Unified::enableAutoRange ( bool  enabled)

Enables automatic range increasing if the sensor seems to be saturating its current range.

The range will not automatically decrease after being increased.

Parameters
enabledSet to true to enable auto range, false to disable it.

◆ enableDebugLogging()

void L3G4200D_Unified::enableDebugLogging ( bool  enabled)

Enables or disables debug logging to the Serial console.

Parameters
enabledSet to true to enable debug logging, false to disable it.

◆ getEvent()

bool L3G4200D_Unified::getEvent ( sensors_event_t *  event)

The Unified Sensor API method to get data from this sensor.

Parameters
event[out] A pointer to a sensors_event_t object for this method to populate with the X, Y, and Z gyro data.

After this function is called, event->gyro.x, event->gyro.y, and event->gyro.z are set to the values from the sensor. For example:

L3G4200D_U gyro;
gyro.begin(10);
sensors_event_t event;
gyro.getEvent(&event);
Serial.print("X, Y, Z: ");
Serial.print(event.gyro.x);
Serial.print(", ");
Serial.print(event.gyro.y);
Serial.print(", ");
Serial.println(event.gyro.z);
Returns
True if this sensor was successfully read from, false if it was not.

◆ getSensor()

void L3G4200D_Unified::getSensor ( sensor_t *  sensor)

The Unified Sensor API method to get information about this sensor.

Parameters
sensor[out] A pointer to a sensor_t object for this method to populate with information about this sensor.

◆ setRange()

void L3G4200D_Unified::setRange ( gyroRange_t  range)

Sets the range for this gyroscope.

Parameters
rangeOne of the values of gyroRange_t to set as the new range for this gyroscope.

◆ rangeInRadians()

float L3G4200D_Unified::rangeInRadians ( )

Returns the full scale of the current range in the SI unit rad/s.

Returns
The current range, in radians.

◆ rawReadReg()

uint8_t L3G4200D_Unified::rawReadReg ( uint8_t  regAddress)

Advanced functionality: reads a raw value from a raw address. See Registers for more information.

Parameters
regAddressThe address of the gyroscope register to read from. One of the values of register addresses.
Returns
The raw value of the register that was read.

◆ rawWriteReg()

void L3G4200D_Unified::rawWriteReg ( uint8_t  regAddress,
uint8_t  newValue 
)

Advanced functionality: writes a raw value to a raw address. See Registers for more information.

Parameters
regAddressThe address of the gyroscope register to read from. One of the values of register addresses.
newValueThe raw value to write to the register specified in regAddress.

The documentation for this class was generated from the following files: