Arduino  1.8.10
Adafruit_CPlay_LIS3DH クラス

Class that stores state and functions for LIS3DH accelerometer on the circuitPlayground board [詳解]

#include <Adafruit_CPlay_LIS3DH.h>

Adafruit_CPlay_LIS3DH の継承関係図
Adafruit_Sensor

公開メンバ関数

 Adafruit_CPlay_LIS3DH (void)
 Instantiates a new LIS3DH class in I2C mode [詳解]
 
 Adafruit_CPlay_LIS3DH (int8_t cspin)
 Instantiates a new LIS3DH class in hardware SPI mode [詳解]
 
 Adafruit_CPlay_LIS3DH (int8_t cspin, int8_t mosipin, int8_t misopin, int8_t sckpin)
 Instantiates a new LIS3DH class in software SPI mode [詳解]
 
bool begin (uint8_t addr=LIS3DH_DEFAULT_ADDRESS)
 Setups the HW (reads coefficients values, etc.) [詳解]
 
void read ()
 read x, y, and z axis data and store in class variables. [詳解]
 
int16_t readADC (uint8_t a)
 Read the auxilary ADC [詳解]
 
void setRange (lis3dh_range_t range)
 Sets the g range for the accelerometer [詳解]
 
lis3dh_range_t getRange (void)
 Sets the g range for the accelerometer [詳解]
 
void setDataRate (lis3dh_dataRate_t dataRate)
 Sets the data rate for the LIS3DH (controls power consumption) [詳解]
 
lis3dh_dataRate_t getDataRate (void)
 Sets the data rate for the LIS3DH (controls power consumption) [詳解]
 
bool getEvent (sensors_event_t *event)
 Gets the most recent sensor event [詳解]
 
void getSensor (sensor_t *sensor)
 Gets the sensor_t data [詳解]
 
void setClick (uint8_t c, uint8_t clickthresh, uint8_t timelimit=10, uint8_t timelatency=20, uint8_t timewindow=255)
 Set INT to output for single or double click [詳解]
 
uint8_t getClick (void)
 get a tap reading [詳解]
 
- 基底クラス Adafruit_Sensor に属する継承公開メンバ関数
 Adafruit_Sensor ()
 
virtual ~Adafruit_Sensor ()
 
virtual void enableAutoRange (bool enabled)
 enable or disable auto-ranging for the sensor [詳解]
 

公開変数類

int16_t x
 integer axis readings [詳解]
 
int16_t y
 

integer x-axis reading

[詳解]
 
int16_t z
 

integer y-axis reading

[詳解]
 
float x_g
 

integer z-axis reading

[詳解]
 
float y_g
 

floating point G reading for x axis

[詳解]
 
float z_g
 

floating point G reading for y axis

[詳解]
 

詳解

Class that stores state and functions for LIS3DH accelerometer on the circuitPlayground board

Adafruit_CPlay_LIS3DH.h135 行目に定義があります。

構築子と解体子

◆ Adafruit_CPlay_LIS3DH() [1/3]

Adafruit_CPlay_LIS3DH::Adafruit_CPlay_LIS3DH ( void  )

Instantiates a new LIS3DH class in I2C mode

Adafruit_CPlay_LIS3DH.cpp36 行目に定義があります。

37  : _cs(-1), _mosi(-1), _miso(-1), _sck(-1), _sensorID(-1)
38 {
39 }

◆ Adafruit_CPlay_LIS3DH() [2/3]

Adafruit_CPlay_LIS3DH::Adafruit_CPlay_LIS3DH ( int8_t  cspin)

Instantiates a new LIS3DH class in hardware SPI mode

引数
cspinthe pin used as a chip select

Adafruit_CPlay_LIS3DH.cpp47 行目に定義があります。

48  : _cs(cspin), _mosi(-1), _miso(-1), _sck(-1), _sensorID(-1)
49 { }

◆ Adafruit_CPlay_LIS3DH() [3/3]

Adafruit_CPlay_LIS3DH::Adafruit_CPlay_LIS3DH ( int8_t  cspin,
int8_t  mosipin,
int8_t  misopin,
int8_t  sckpin 
)

Instantiates a new LIS3DH class in software SPI mode

引数
cspinthe pin used as a chip select
mosipinthe pin used as master-out-slave-in
misopinthe pin used as master-in-slave-out
sckpinthe pin used as SPI serial clock

Adafruit_CPlay_LIS3DH.cpp60 行目に定義があります。

61  : _cs(cspin), _mosi(mosipin), _miso(misopin), _sck(sckpin), _sensorID(-1)
62 { }

関数詳解

◆ begin()

bool Adafruit_CPlay_LIS3DH::begin ( uint8_t  i2caddr = LIS3DH_DEFAULT_ADDRESS)

Setups the HW (reads coefficients values, etc.)

引数
i2caddrthe I2C address the device can be found on. defaults to 0x18
戻り値
true on success, false on any failure

Adafruit_CPlay_LIS3DH.cpp73 行目に定義があります。

73  {
74  _i2caddr = i2caddr;
75 
76  if (_cs == -1) {
77  // i2c
78  Wire.begin();
79  } else {
80  digitalWrite(_cs, HIGH);
81  pinMode(_cs, OUTPUT);
82 
83 #ifndef __AVR_ATtiny85__
84  if (_sck == -1) {
85  // hardware SPI
86  SPI.begin();
87  } else {
88  // software SPI
89  pinMode(_sck, OUTPUT);
90  pinMode(_mosi, OUTPUT);
91  pinMode(_miso, INPUT);
92  }
93 #endif
94  }
95 
96  /*
97  for (uint8_t i=0; i<0x30; i++) {
98  Serial.print("$");
99  Serial.print(i, HEX); Serial.print(" = 0x");
100  Serial.println(readRegister8(i), HEX);
101  }
102  */
103 
104  /* Check connection */
105  uint8_t deviceid = readRegister8(LIS3DH_REG_WHOAMI);
106  if (deviceid != 0x33)
107  {
108  /* No LIS3DH detected ... return false */
109  //Serial.println(deviceid, HEX);
110  return false;
111  }
112 
113  // enable all axes, normal mode
114  writeRegister8(LIS3DH_REG_CTRL1, 0x07);
115  // 400Hz rate
117 
118  // High res & BDU enabled
119  writeRegister8(LIS3DH_REG_CTRL4, 0x88);
120 
121  // DRDY on INT1
122  writeRegister8(LIS3DH_REG_CTRL3, 0x10);
123 
124  // Turn on orientation config
125  //writeRegister8(LIS3DH_REG_PL_CFG, 0x40);
126 
127  // enable adcs
128  writeRegister8(LIS3DH_REG_TEMPCFG, 0x80);
129 
130  /*
131  for (uint8_t i=0; i<0x30; i++) {
132  Serial.print("$");
133  Serial.print(i, HEX); Serial.print(" = 0x");
134  Serial.println(readRegister8(i), HEX);
135  }
136  */
137 
138  return true;
139 }
void pinMode(uint8_t, uint8_t)
void begin()
Definition: Wire.cpp:55
void digitalWrite(uint8_t, uint8_t)
SPIClass SPI
Definition: SPI.cpp:16
static void begin()
Definition: SPI.cpp:26
TwoWire Wire
Definition: Wire.cpp:330
#define HIGH
Definition: Arduino.h:40
#define OUTPUT
Definition: Arduino.h:44
void setDataRate(lis3dh_dataRate_t dataRate)
Sets the data rate for the LIS3DH (controls power consumption)
#define INPUT
Definition: Arduino.h:43

◆ getClick()

uint8_t Adafruit_CPlay_LIS3DH::getClick ( void  )

get a tap reading

戻り値
the tap reading

Adafruit_CPlay_LIS3DH.cpp281 行目に定義があります。

281  {
282  return readRegister8(LIS3DH_REG_CLICKSRC);
283 }

◆ getDataRate()

lis3dh_dataRate_t Adafruit_CPlay_LIS3DH::getDataRate ( void  )

Sets the data rate for the LIS3DH (controls power consumption)

戻り値
the data rate reading from the sensor.

Adafruit_CPlay_LIS3DH.cpp334 行目に定義があります。

335 {
336  return (lis3dh_dataRate_t)((readRegister8(LIS3DH_REG_CTRL1) >> 4)& 0x0F);
337 }
lis3dh_dataRate_t
LIS3DH datarates

◆ getEvent()

bool Adafruit_CPlay_LIS3DH::getEvent ( sensors_event_t event)
virtual

Gets the most recent sensor event

引数
eventthe pointer to place the event reading in
戻り値
none

Adafruit_Sensorを実装しています。

Adafruit_CPlay_LIS3DH.cpp346 行目に定義があります。

346  {
347  /* Clear the event */
348  memset(event, 0, sizeof(sensors_event_t));
349 
350  event->version = sizeof(sensors_event_t);
351  event->sensor_id = _sensorID;
352  event->type = SENSOR_TYPE_ACCELEROMETER;
353  event->timestamp = 0;
354 
355  read();
356 
357  event->acceleration.x = x_g * SENSORS_GRAVITY_STANDARD;
358  event->acceleration.y = y_g * SENSORS_GRAVITY_STANDARD;
359  event->acceleration.z = z_g * SENSORS_GRAVITY_STANDARD;
360 }
float y_g
floating point G reading for x axis
Gravity + linear acceleration */
void * memset(void *, int, size_t)
Fill memory with a constant byte.
float x_g
integer z-axis reading
void read()
read x, y, and z axis data and store in class variables.
float z_g
floating point G reading for y axis
#define SENSORS_GRAVITY_STANDARD

◆ getRange()

lis3dh_range_t Adafruit_CPlay_LIS3DH::getRange ( void  )

Sets the g range for the accelerometer

戻り値
the range reading from the sensor.

Adafruit_CPlay_LIS3DH.cpp308 行目に定義があります。

309 {
310  /* Read the data format register to preserve bits */
311  return (lis3dh_range_t)((readRegister8(LIS3DH_REG_CTRL4) >> 4) & 0x03);
312 }
lis3dh_range_t
LIS3DH measurement ranges

◆ getSensor()

void Adafruit_CPlay_LIS3DH::getSensor ( sensor_t sensor)
virtual

Gets the sensor_t data

引数
sensorthe pointer to place sensor information into.

Adafruit_Sensorを実装しています。

Adafruit_CPlay_LIS3DH.cpp368 行目に定義があります。

368  {
369  /* Clear the sensor_t object */
370  memset(sensor, 0, sizeof(sensor_t));
371 
372  /* Insert the sensor name in the fixed length char array */
373  strncpy (sensor->name, "LIS3DH", sizeof(sensor->name) - 1);
374  sensor->name[sizeof(sensor->name)- 1] = 0;
375  sensor->version = 1;
376  sensor->sensor_id = _sensorID;
378  sensor->min_delay = 0;
379  sensor->max_value = 0;
380  sensor->min_value = 0;
381  sensor->resolution = 0;
382 }
Gravity + linear acceleration */
void * memset(void *, int, size_t)
Fill memory with a constant byte.
int32_t version
version of the hardware + driver */
int32_t type
this sensor's type (ex. SENSOR_TYPE_LIGHT) */
char name[12]
sensor name */
int32_t sensor_id
unique sensor identifier */
float min_value
minimum value of this sensor's value in SI units */
float max_value
maximum value of this sensor's value in SI units */
float resolution
smallest difference between two values reported by this sensor */
char * strncpy(char *, const char *, size_t)
Copy a string.
int32_t min_delay
min delay in microseconds between events. zero = not a constant rate */

◆ read()

void Adafruit_CPlay_LIS3DH::read ( void  )

read x, y, and z axis data and store in class variables.

Adafruit_CPlay_LIS3DH.cpp146 行目に定義があります。

146  {
147  // read x y z at once
148 
149  if (_cs == -1) {
150  // i2c
151  Wire.beginTransmission(_i2caddr);
152  Wire.write(LIS3DH_REG_OUT_X_L | 0x80); // 0x80 for autoincrement
154 
155  Wire.requestFrom(_i2caddr, 6);
156  x = Wire.read(); x |= ((uint16_t)Wire.read()) << 8;
157  y = Wire.read(); y |= ((uint16_t)Wire.read()) << 8;
158  z = Wire.read(); z |= ((uint16_t)Wire.read()) << 8;
159  }
160  #ifndef __AVR_ATtiny85__
161  else {
162 #if SPI_HAS_TRANSACTION
163  if (_sck == -1)
165 #endif
166  digitalWrite(_cs, LOW);
167  spixfer(LIS3DH_REG_OUT_X_L | 0x80 | 0x40); // read multiple, bit 7&6 high
168 
169  x = spixfer(); x |= ((uint16_t)spixfer()) << 8;
170  y = spixfer(); y |= ((uint16_t)spixfer()) << 8;
171  z = spixfer(); z |= ((uint16_t)spixfer()) << 8;
172 
173  digitalWrite(_cs, HIGH);
174 #if SPI_HAS_TRANSACTION
175  if (_sck == -1)
176  SPI.endTransaction(); // release the SPI bus
177 #endif
178  }
179  #endif
180  uint8_t range = getRange();
181  uint16_t divider = 1;
182  if (range == LIS3DH_RANGE_16_G) divider = 1365;
183  if (range == LIS3DH_RANGE_8_G) divider = 4096;
184  if (range == LIS3DH_RANGE_4_G) divider = 8190;
185  if (range == LIS3DH_RANGE_2_G) divider = 16380;
186 
187  x_g = (float)x / divider;
188  y_g = (float)y / divider;
189  z_g = (float)z / divider;
190 
191 }
float y_g
floating point G reading for x axis
uint8_t endTransmission(void)
Definition: Wire.cpp:185
float x_g
integer z-axis reading
#define SPI_MODE0
Definition: SPI.h:54
void beginTransmission(uint8_t)
Definition: Wire.cpp:141
static void beginTransaction(SPISettings settings)
Definition: SPI.h:178
int16_t z
integer y-axis reading
void digitalWrite(uint8_t, uint8_t)
SPIClass SPI
Definition: SPI.cpp:16
#define MSBFIRST
Definition: Arduino.h:58
int16_t y
integer x-axis reading
TwoWire Wire
Definition: Wire.cpp:330
int16_t x
integer axis readings
#define LOW
Definition: Arduino.h:41
virtual size_t write(uint8_t)
Definition: Wire.cpp:193
#define HIGH
Definition: Arduino.h:40
float z_g
floating point G reading for y axis
static void endTransaction(void)
Definition: SPI.h:260
uint8_t requestFrom(uint8_t, uint8_t)
Definition: Wire.cpp:126
virtual int read(void)
Definition: Wire.cpp:244
lis3dh_range_t getRange(void)
Sets the g range for the accelerometer

◆ readADC()

int16_t Adafruit_CPlay_LIS3DH::readADC ( uint8_t  adc)

Read the auxilary ADC

引数
adcthe adc number to read. Valid adc numbers are 1, 2, and 3.
戻り値
the measured value

Adafruit_CPlay_LIS3DH.cpp200 行目に定義があります。

200  {
201  if ((adc < 1) || (adc > 3)) return 0;
202  uint16_t value;
203 
204  adc--;
205 
206  uint8_t reg = LIS3DH_REG_OUTADC1_L + adc*2;
207 
208  if (_cs == -1) {
209  // i2c
210  Wire.beginTransmission(_i2caddr);
211  Wire.write(reg | 0x80); // 0x80 for autoincrement
213  Wire.requestFrom(_i2caddr, 2);
214  value = Wire.read(); value |= ((uint16_t)Wire.read()) << 8;
215  }
216  #ifndef __AVR_ATtiny85__
217  else {
218 #if SPI_HAS_TRANSACTION
219  if (_sck == -1)
221 #endif
222  digitalWrite(_cs, LOW);
223  spixfer(reg | 0x80 | 0x40); // read multiple, bit 7&6 high
224 
225  value = spixfer(); value |= ((uint16_t)spixfer()) << 8;
226 
227  digitalWrite(_cs, HIGH);
228 #if SPI_HAS_TRANSACTION
229  if (_sck == -1)
230  SPI.endTransaction(); // release the SPI bus
231 #endif
232  }
233  #endif
234 
235  return value;
236 }
uint8_t endTransmission(void)
Definition: Wire.cpp:185
#define SPI_MODE0
Definition: SPI.h:54
void beginTransmission(uint8_t)
Definition: Wire.cpp:141
static void beginTransaction(SPISettings settings)
Definition: SPI.h:178
void digitalWrite(uint8_t, uint8_t)
SPIClass SPI
Definition: SPI.cpp:16
#define MSBFIRST
Definition: Arduino.h:58
TwoWire Wire
Definition: Wire.cpp:330
#define LOW
Definition: Arduino.h:41
virtual size_t write(uint8_t)
Definition: Wire.cpp:193
#define HIGH
Definition: Arduino.h:40
static void endTransaction(void)
Definition: SPI.h:260
uint8_t requestFrom(uint8_t, uint8_t)
Definition: Wire.cpp:126
virtual int read(void)
Definition: Wire.cpp:244

◆ setClick()

void Adafruit_CPlay_LIS3DH::setClick ( uint8_t  c,
uint8_t  clickthresh,
uint8_t  timelimit = 10,
uint8_t  timelatency = 20,
uint8_t  timewindow = 255 
)

Set INT to output for single or double click

引数
cthe number of taps to detect. pass 1 for single tap on all axis, 2 for double tap on all axis. Pass 0 to disable taps.
clickthreshthe threshold over which to register a tap.
timelimitOptional time limit for a tap. Defaults to 10
timelatencyOptional tap latency. defaults to 20
timewindowOptional time window. defaults to 255

Adafruit_CPlay_LIS3DH.cpp249 行目に定義があります。

249  {
250  if (!c) {
251  //disable int
252  uint8_t r = readRegister8(LIS3DH_REG_CTRL3);
253  r &= ~(0x80); // turn off I1_CLICK
254  writeRegister8(LIS3DH_REG_CTRL3, r);
255  writeRegister8(LIS3DH_REG_CLICKCFG, 0);
256  return;
257  }
258  // else...
259 
260  writeRegister8(LIS3DH_REG_CTRL3, 0x80); // turn on int1 click
261  writeRegister8(LIS3DH_REG_CTRL5, 0x08); // latch interrupt on int1
262 
263  if (c == 1)
264  writeRegister8(LIS3DH_REG_CLICKCFG, 0x15); // turn on all axes & singletap
265  if (c == 2)
266  writeRegister8(LIS3DH_REG_CLICKCFG, 0x2A); // turn on all axes & doubletap
267 
268 
269  writeRegister8(LIS3DH_REG_CLICKTHS, clickthresh); // arbitrary
270  writeRegister8(LIS3DH_REG_TIMELIMIT, timelimit); // arbitrary
271  writeRegister8(LIS3DH_REG_TIMELATENCY, timelatency); // arbitrary
272  writeRegister8(LIS3DH_REG_TIMEWINDOW, timewindow); // arbitrary
273 }

◆ setDataRate()

void Adafruit_CPlay_LIS3DH::setDataRate ( lis3dh_dataRate_t  dataRate)

Sets the data rate for the LIS3DH (controls power consumption)

引数
dataRatethe desired datarate.

Adafruit_CPlay_LIS3DH.cpp320 行目に定義があります。

321 {
322  uint8_t ctl1 = readRegister8(LIS3DH_REG_CTRL1);
323  ctl1 &= ~(0xF0); // mask off bits
324  ctl1 |= (dataRate << 4);
325  writeRegister8(LIS3DH_REG_CTRL1, ctl1);
326 }

◆ setRange()

void Adafruit_CPlay_LIS3DH::setRange ( lis3dh_range_t  range)

Sets the g range for the accelerometer

引数
rangethe desired range of the device. Pass LIS3DH_RANGE_2_G for highest sensitivity and lowest max/min value (+-2G), LIS3DH_RANGE_16_G for lowest sensitivity and highest max/min value (+-16G). Other acceptable values are LIS3DH_RANGE_4_G and LIS3DH_RANGE_8_G.

Adafruit_CPlay_LIS3DH.cpp294 行目に定義があります。

295 {
296  uint8_t r = readRegister8(LIS3DH_REG_CTRL4);
297  r &= ~(0x30);
298  r |= range << 4;
299  writeRegister8(LIS3DH_REG_CTRL4, r);
300 }

メンバ詳解

◆ x

int16_t Adafruit_CPlay_LIS3DH::x

integer axis readings

Adafruit_CPlay_LIS3DH.h163 行目に定義があります。

◆ x_g

float Adafruit_CPlay_LIS3DH::x_g

integer z-axis reading

floating point axis readings

Adafruit_CPlay_LIS3DH.h172 行目に定義があります。

◆ y

int16_t Adafruit_CPlay_LIS3DH::y

integer x-axis reading

Adafruit_CPlay_LIS3DH.h163 行目に定義があります。

◆ y_g

float Adafruit_CPlay_LIS3DH::y_g

floating point G reading for x axis

Adafruit_CPlay_LIS3DH.h172 行目に定義があります。

◆ z

int16_t Adafruit_CPlay_LIS3DH::z

integer y-axis reading

Adafruit_CPlay_LIS3DH.h163 行目に定義があります。

◆ z_g

float Adafruit_CPlay_LIS3DH::z_g

floating point G reading for y axis

Adafruit_CPlay_LIS3DH.h172 行目に定義があります。


このクラス詳解は次のファイルから抽出されました: