forked from adafruit/Adafruit_Sensor
change it to adxl343 example
This commit is contained in:
@ -1,61 +0,0 @@
|
||||
/***************************************************************************
|
||||
This is a library for the BMP280 humidity, temperature & pressure sensor
|
||||
This example shows how to take Sensor Events instead of direct readings
|
||||
|
||||
Designed specifically to work with the Adafruit BMP280 Breakout
|
||||
----> http://www.adafruit.com/products/2651
|
||||
|
||||
These sensors use I2C or SPI to communicate, 2 or 4 pins are required
|
||||
to interface.
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit andopen-source hardware by purchasing products
|
||||
from Adafruit!
|
||||
|
||||
Written by Limor Fried & Kevin Townsend for Adafruit Industries.
|
||||
BSD license, all text above must be included in any redistribution
|
||||
***************************************************************************/
|
||||
|
||||
#include <Wire.h>
|
||||
#include <SPI.h>
|
||||
#include <Adafruit_BMP280.h>
|
||||
|
||||
Adafruit_BMP280 bmp; // use I2C interface
|
||||
Adafruit_Sensor *bmp_temp = bmp.getTemperatureSensor();
|
||||
Adafruit_Sensor *bmp_pressure = bmp.getPressureSensor();
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.println(F("BMP280 Sensor event test"));
|
||||
|
||||
if (!bmp.begin()) {
|
||||
Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
|
||||
while (1) delay(10);
|
||||
}
|
||||
|
||||
/* Default settings from datasheet. */
|
||||
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
|
||||
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
|
||||
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */
|
||||
Adafruit_BMP280::FILTER_X16, /* Filtering. */
|
||||
Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
|
||||
|
||||
bmp_temp->printSensorDetails();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
sensors_event_t temp_event, pressure_event;
|
||||
bmp_temp->getEvent(&temp_event);
|
||||
bmp_pressure->getEvent(&pressure_event);
|
||||
|
||||
Serial.print(F("Temperature = "));
|
||||
Serial.print(temp_event.temperature);
|
||||
Serial.println(" *C");
|
||||
|
||||
Serial.print(F("Pressure = "));
|
||||
Serial.print(pressure_event.pressure);
|
||||
Serial.println(" hPa");
|
||||
|
||||
Serial.println();
|
||||
delay(2000);
|
||||
}
|
153
examples/sensortest/sensortest.ino
Normal file
153
examples/sensortest/sensortest.ino
Normal file
@ -0,0 +1,153 @@
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include <Adafruit_ADXL343.h>
|
||||
|
||||
/* Assign a unique ID to this sensor at the same time */
|
||||
/* Uncomment following line for default Wire bus */
|
||||
Adafruit_ADXL343 accel = Adafruit_ADXL343(12345);
|
||||
|
||||
/* NeoTrellis M4, etc. */
|
||||
/* Uncomment following line for Wire1 bus */
|
||||
//Adafruit_ADXL343 accel = Adafruit_ADXL343(12345, &Wire1);
|
||||
|
||||
void displaySensorDetails(void)
|
||||
{
|
||||
sensor_t sensor;
|
||||
accel.getSensor(&sensor);
|
||||
Serial.println("------------------------------------");
|
||||
Serial.print ("Sensor: "); Serial.println(sensor.name);
|
||||
Serial.print ("Driver Ver: "); Serial.println(sensor.version);
|
||||
Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id);
|
||||
Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" m/s^2");
|
||||
Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" m/s^2");
|
||||
Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" m/s^2");
|
||||
Serial.println("------------------------------------");
|
||||
Serial.println("");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
void displayDataRate(void)
|
||||
{
|
||||
Serial.print ("Data Rate: ");
|
||||
|
||||
switch(accel.getDataRate())
|
||||
{
|
||||
case ADXL343_DATARATE_3200_HZ:
|
||||
Serial.print ("3200 ");
|
||||
break;
|
||||
case ADXL343_DATARATE_1600_HZ:
|
||||
Serial.print ("1600 ");
|
||||
break;
|
||||
case ADXL343_DATARATE_800_HZ:
|
||||
Serial.print ("800 ");
|
||||
break;
|
||||
case ADXL343_DATARATE_400_HZ:
|
||||
Serial.print ("400 ");
|
||||
break;
|
||||
case ADXL343_DATARATE_200_HZ:
|
||||
Serial.print ("200 ");
|
||||
break;
|
||||
case ADXL343_DATARATE_100_HZ:
|
||||
Serial.print ("100 ");
|
||||
break;
|
||||
case ADXL343_DATARATE_50_HZ:
|
||||
Serial.print ("50 ");
|
||||
break;
|
||||
case ADXL343_DATARATE_25_HZ:
|
||||
Serial.print ("25 ");
|
||||
break;
|
||||
case ADXL343_DATARATE_12_5_HZ:
|
||||
Serial.print ("12.5 ");
|
||||
break;
|
||||
case ADXL343_DATARATE_6_25HZ:
|
||||
Serial.print ("6.25 ");
|
||||
break;
|
||||
case ADXL343_DATARATE_3_13_HZ:
|
||||
Serial.print ("3.13 ");
|
||||
break;
|
||||
case ADXL343_DATARATE_1_56_HZ:
|
||||
Serial.print ("1.56 ");
|
||||
break;
|
||||
case ADXL343_DATARATE_0_78_HZ:
|
||||
Serial.print ("0.78 ");
|
||||
break;
|
||||
case ADXL343_DATARATE_0_39_HZ:
|
||||
Serial.print ("0.39 ");
|
||||
break;
|
||||
case ADXL343_DATARATE_0_20_HZ:
|
||||
Serial.print ("0.20 ");
|
||||
break;
|
||||
case ADXL343_DATARATE_0_10_HZ:
|
||||
Serial.print ("0.10 ");
|
||||
break;
|
||||
default:
|
||||
Serial.print ("???? ");
|
||||
break;
|
||||
}
|
||||
Serial.println(" Hz");
|
||||
}
|
||||
|
||||
void displayRange(void)
|
||||
{
|
||||
Serial.print ("Range: +/- ");
|
||||
|
||||
switch(accel.getRange())
|
||||
{
|
||||
case ADXL343_RANGE_16_G:
|
||||
Serial.print ("16 ");
|
||||
break;
|
||||
case ADXL343_RANGE_8_G:
|
||||
Serial.print ("8 ");
|
||||
break;
|
||||
case ADXL343_RANGE_4_G:
|
||||
Serial.print ("4 ");
|
||||
break;
|
||||
case ADXL343_RANGE_2_G:
|
||||
Serial.print ("2 ");
|
||||
break;
|
||||
default:
|
||||
Serial.print ("?? ");
|
||||
break;
|
||||
}
|
||||
Serial.println(" g");
|
||||
}
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
Serial.begin(9600);
|
||||
while (!Serial);
|
||||
Serial.println("Accelerometer Test"); Serial.println("");
|
||||
|
||||
/* Initialise the sensor */
|
||||
if(!accel.begin())
|
||||
{
|
||||
/* There was a problem detecting the ADXL343 ... check your connections */
|
||||
Serial.println("Ooops, no ADXL343 detected ... Check your wiring!");
|
||||
while(1);
|
||||
}
|
||||
|
||||
/* Set the range to whatever is appropriate for your project */
|
||||
accel.setRange(ADXL343_RANGE_16_G);
|
||||
// accel.setRange(ADXL343_RANGE_8_G);
|
||||
// accel.setRange(ADXL343_RANGE_4_G);
|
||||
// accel.setRange(ADXL343_RANGE_2_G);
|
||||
|
||||
/* Display some basic information on this sensor */
|
||||
displaySensorDetails();
|
||||
displayDataRate();
|
||||
displayRange();
|
||||
Serial.println("");
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
/* Get a new sensor event */
|
||||
sensors_event_t event;
|
||||
accel.getEvent(&event);
|
||||
|
||||
/* Display the results (acceleration is measured in m/s^2) */
|
||||
Serial.print("X: "); Serial.print(event.acceleration.x); Serial.print(" ");
|
||||
Serial.print("Y: "); Serial.print(event.acceleration.y); Serial.print(" ");
|
||||
Serial.print("Z: "); Serial.print(event.acceleration.z); Serial.print(" ");Serial.println("m/s^2 ");
|
||||
delay(500);
|
||||
}
|
@ -8,3 +8,4 @@ category=Sensors
|
||||
url=https://github.com/adafruit/Adafruit_Sensor
|
||||
architectures=*
|
||||
includes=Adafruit_Sensor.h
|
||||
depends=Adafruit ADXL343
|
Reference in New Issue
Block a user