-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
450 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
/** | ||
* @file QMI8658_InterruptExample.ino | ||
* @author Lewis He ([email protected]) | ||
* @license MIT | ||
* @copyright Copyright (c) 2024 ShenZhen XinYuan Electronic Technology Co., Ltd | ||
* @date 2024-10-17 | ||
* | ||
*/ | ||
#include <Arduino.h> | ||
#include <Wire.h> | ||
#include <SPI.h> | ||
#include <SensorQMI8658.hpp> | ||
|
||
// T-A7670X SIM-Hat Pin | ||
const uint8_t sda = 21; | ||
const uint8_t scl = 22; | ||
|
||
#define IMU_INT1 39 | ||
#define IMU_INT2 34 | ||
|
||
|
||
SensorQMI8658 qmi; | ||
|
||
IMUdata acc; | ||
IMUdata gyr; | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
while (!Serial); | ||
|
||
if (!qmi.begin(Wire, QMI8658_L_SLAVE_ADDRESS, sda, scl)) { | ||
Serial.println("Failed to find QMI8658 - check your wiring!"); | ||
while (1) { | ||
delay(1000); | ||
} | ||
} | ||
|
||
/* Get chip id*/ | ||
Serial.print("Device ID:"); | ||
Serial.println(qmi.getChipID(), HEX); | ||
|
||
qmi.configAccelerometer( | ||
/* | ||
* ACC_RANGE_2G | ||
* ACC_RANGE_4G | ||
* ACC_RANGE_8G | ||
* ACC_RANGE_16G | ||
* */ | ||
SensorQMI8658::ACC_RANGE_4G, | ||
/* | ||
* ACC_ODR_1000H | ||
* ACC_ODR_500Hz | ||
* ACC_ODR_250Hz | ||
* ACC_ODR_125Hz | ||
* ACC_ODR_62_5Hz | ||
* ACC_ODR_31_25Hz | ||
* ACC_ODR_LOWPOWER_128Hz | ||
* ACC_ODR_LOWPOWER_21Hz | ||
* ACC_ODR_LOWPOWER_11Hz | ||
* ACC_ODR_LOWPOWER_3H | ||
* */ | ||
SensorQMI8658::ACC_ODR_1000Hz, | ||
/* | ||
* LPF_MODE_0 //2.66% of ODR | ||
* LPF_MODE_1 //3.63% of ODR | ||
* LPF_MODE_2 //5.39% of ODR | ||
* LPF_MODE_3 //13.37% of ODR | ||
* LPF_OFF // OFF Low-Pass Fitter | ||
* */ | ||
SensorQMI8658::LPF_MODE_0); | ||
|
||
|
||
qmi.configGyroscope( | ||
/* | ||
* GYR_RANGE_16DPS | ||
* GYR_RANGE_32DPS | ||
* GYR_RANGE_64DPS | ||
* GYR_RANGE_128DPS | ||
* GYR_RANGE_256DPS | ||
* GYR_RANGE_512DPS | ||
* GYR_RANGE_1024DPS | ||
* */ | ||
SensorQMI8658::GYR_RANGE_64DPS, | ||
/* | ||
* GYR_ODR_7174_4Hz | ||
* GYR_ODR_3587_2Hz | ||
* GYR_ODR_1793_6Hz | ||
* GYR_ODR_896_8Hz | ||
* GYR_ODR_448_4Hz | ||
* GYR_ODR_224_2Hz | ||
* GYR_ODR_112_1Hz | ||
* GYR_ODR_56_05Hz | ||
* GYR_ODR_28_025H | ||
* */ | ||
SensorQMI8658::GYR_ODR_896_8Hz, | ||
/* | ||
* LPF_MODE_0 //2.66% of ODR | ||
* LPF_MODE_1 //3.63% of ODR | ||
* LPF_MODE_2 //5.39% of ODR | ||
* LPF_MODE_3 //13.37% of ODR | ||
* LPF_OFF // OFF Low-Pass Fitter | ||
* */ | ||
SensorQMI8658::LPF_MODE_3); | ||
|
||
|
||
/* | ||
* If both the accelerometer and gyroscope sensors are turned on at the same time, | ||
* the output frequency will be based on the gyroscope output frequency. | ||
* The example configuration is 896.8HZ output frequency, | ||
* so the acceleration output frequency is also limited to 896.8HZ | ||
* */ | ||
qmi.enableGyroscope(); | ||
qmi.enableAccelerometer(); | ||
|
||
|
||
pinMode(IMU_INT1, INPUT); | ||
#ifdef IMU_INT2 | ||
pinMode(IMU_INT2, INPUT); | ||
#endif | ||
|
||
// qmi.enableINT(SensorQMI8658::INTERRUPT_PIN_1); //no use | ||
// Enable data ready to interrupt pin2 | ||
qmi.enableINT(SensorQMI8658::INTERRUPT_PIN_2); | ||
qmi.enableDataReadyINT(); | ||
|
||
// Print register configuration information | ||
qmi.dumpCtrlRegister(); | ||
|
||
Serial.println("Read data now..."); | ||
} | ||
|
||
void readSensorData(const char *name) | ||
{ | ||
uint8_t status = qmi.getIrqStatus(); | ||
// status == 0x01 | ||
// If syncSmpl (CTRL7.bit7) = 1: | ||
// 0: Sensor Data is not available | ||
// 1: Sensor Data is available for reading | ||
// If syncSmpl = 0, this bit shows the same value of INT2 level | ||
Serial.print(name); | ||
Serial.print(" -> ["); | ||
Serial.print(millis()); | ||
Serial.print("]: -<HEX> "); | ||
Serial.print(status); | ||
Serial.print(" -<BIN> "); | ||
Serial.println(status, BIN); | ||
if (status & 0x01) { | ||
if (qmi.getAccelerometer(acc.x, acc.y, acc.z)) { | ||
Serial.print("{ACCEL: "); | ||
Serial.print(acc.x); | ||
Serial.print(","); | ||
Serial.print(acc.y); | ||
Serial.print(","); | ||
Serial.print(acc.z); | ||
Serial.println("}"); | ||
} | ||
|
||
if (qmi.getGyroscope(gyr.x, gyr.y, gyr.z)) { | ||
Serial.print("{GYRO: "); | ||
Serial.print(gyr.x); | ||
Serial.print(","); | ||
Serial.print(gyr.y ); | ||
Serial.print(","); | ||
Serial.print(gyr.z); | ||
Serial.println("}"); | ||
} | ||
Serial.print("\t\t\t\t > "); | ||
Serial.print(qmi.getTimestamp()); | ||
Serial.print(" "); | ||
Serial.print(qmi.getTemperature_C()); | ||
Serial.println("*C"); | ||
} | ||
|
||
} | ||
|
||
void loop() | ||
{ | ||
if (digitalRead(IMU_INT1) == HIGH) { | ||
readSensorData("INT1"); | ||
} | ||
|
||
#ifdef IMU_INT2 | ||
if (digitalRead(IMU_INT2) == HIGH) { | ||
readSensorData("INT2"); | ||
} | ||
#endif | ||
|
||
} | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// REQUIRES the following Arduino libraries: | ||
// - Adafruit INA219 Lib: https://github.com/adafruit/Adafruit_INA219 | ||
// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor | ||
#include <Adafruit_Sensor.h> | ||
#include <Adafruit_BusIO_Register.h> | ||
#include <Adafruit_INA219.h> | ||
#include <Wire.h> | ||
|
||
const uint8_t ina219_salve_address1 = 0x40; | ||
const uint8_t ina219_salve_address2 = 0x41; | ||
|
||
Adafruit_INA219 ina219_1(ina219_salve_address1); | ||
Adafruit_INA219 ina219_2(ina219_salve_address2); | ||
|
||
// T-A7670X SIM-Hat Pin | ||
const uint8_t sda = 21; | ||
const uint8_t scl = 22; | ||
|
||
void setup(void) | ||
{ | ||
Serial.begin(115200); | ||
|
||
while (!Serial) { | ||
// will pause Zero, Leonardo, etc until serial console opens | ||
delay(1); | ||
} | ||
|
||
Wire.begin(sda, scl); | ||
|
||
Serial.println("Hello!"); | ||
|
||
// Initialize the INA219. | ||
// By default the initialization will use the largest range (32V, 2A). However | ||
// you can call a setCalibration function to change this range (see comments). | ||
if (! ina219_1.begin()) { | ||
while (1) { | ||
Serial.println("Failed to find INA219 1 chip"); | ||
delay(1000); | ||
} | ||
} | ||
|
||
if (! ina219_2.begin()) { | ||
while (1) { | ||
Serial.println("Failed to find INA219 2 chip"); | ||
delay(1000); | ||
} | ||
} | ||
// To use a slightly lower 32V, 1A range (higher precision on amps): | ||
//ina219.setCalibration_32V_1A(); | ||
// Or to use a lower 16V, 400mA range (higher precision on volts and amps): | ||
//ina219.setCalibration_16V_400mA(); | ||
|
||
Serial.println("Measuring voltage and current with INA219 ..."); | ||
} | ||
|
||
void loop(void) | ||
{ | ||
float shuntvoltage_1 = 0; | ||
float busvoltage_1 = 0; | ||
float current_mA_1 = 0; | ||
float loadvoltage_1 = 0; | ||
float power_mW_1 = 0; | ||
|
||
shuntvoltage_1 = ina219_1.getShuntVoltage_mV(); | ||
busvoltage_1 = ina219_1.getBusVoltage_V(); | ||
current_mA_1 = ina219_1.getCurrent_mA(); | ||
power_mW_1 = ina219_1.getPower_mW(); | ||
loadvoltage_1 = busvoltage_1 + (shuntvoltage_1 / 1000); | ||
|
||
Serial.print("Bus Voltage 1: "); Serial.print(busvoltage_1); Serial.println(" V"); | ||
Serial.print("Shunt Voltage 1: "); Serial.print(shuntvoltage_1); Serial.println(" mV"); | ||
Serial.print("Load Voltage 1: "); Serial.print(loadvoltage_1); Serial.println(" V"); | ||
Serial.print("Current 1: "); Serial.print(current_mA_1); Serial.println(" mA"); | ||
Serial.print("Power 1: "); Serial.print(power_mW_1); Serial.println(" mW"); | ||
Serial.println(""); | ||
|
||
|
||
float shuntvoltage_2 = 0; | ||
float busvoltage_2 = 0; | ||
float current_mA_2 = 0; | ||
float loadvoltage_2 = 0; | ||
float power_mW_2 = 0; | ||
|
||
shuntvoltage_2 = ina219_2.getShuntVoltage_mV(); | ||
busvoltage_2 = ina219_2.getBusVoltage_V(); | ||
current_mA_2 = ina219_2.getCurrent_mA(); | ||
power_mW_2 = ina219_2.getPower_mW(); | ||
loadvoltage_2 = busvoltage_2 + (shuntvoltage_2 / 1000); | ||
|
||
Serial.print("Bus Voltage 2: "); Serial.print(busvoltage_2); Serial.println(" V"); | ||
Serial.print("Shunt Voltage 2: "); Serial.print(shuntvoltage_2); Serial.println(" mV"); | ||
Serial.print("Load Voltage 2: "); Serial.print(loadvoltage_2); Serial.println(" V"); | ||
Serial.print("Current 2: "); Serial.print(current_mA_2); Serial.println(" mA"); | ||
Serial.print("Power 2: "); Serial.print(power_mW_2); Serial.println(" mW"); | ||
Serial.println(""); | ||
|
||
|
||
delay(2000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// DHT Temperature & Humidity Sensor | ||
// Unified Sensor Library Example | ||
// Written by Tony DiCola for Adafruit Industries | ||
// Released under an MIT license. | ||
|
||
// REQUIRES the following Arduino libraries: | ||
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library | ||
// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor | ||
|
||
#include <Adafruit_Sensor.h> | ||
#include <Adafruit_BusIO_Register.h> | ||
#include <DHT.h> | ||
#include <DHT_U.h> | ||
#include <Wire.h> | ||
|
||
|
||
// T-A7670X SIM-Hat Pin | ||
#define DHTPIN 23 // Digital pin connected to the DHT sensor | ||
|
||
// Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 -- | ||
// Pin 15 can work but DHT must be disconnected during program upload. | ||
|
||
// Uncomment the type of sensor in use: | ||
#define DHTTYPE DHT11 // DHT 11 | ||
// #define DHTTYPE DHT22 // DHT 22 (AM2302) | ||
//#define DHTTYPE DHT21 // DHT 21 (AM2301) | ||
|
||
// See guide for details on sensor wiring and usage: | ||
// https://learn.adafruit.com/dht/overview | ||
|
||
DHT_Unified dht(DHTPIN, DHTTYPE); | ||
|
||
uint32_t delayMS; | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
// Initialize device. | ||
dht.begin(); | ||
Serial.println(F("DHTxx Unified Sensor Example")); | ||
// Print temperature sensor details. | ||
sensor_t sensor; | ||
dht.temperature().getSensor(&sensor); | ||
Serial.println(F("------------------------------------")); | ||
Serial.println(F("Temperature Sensor")); | ||
Serial.print (F("Sensor Type: ")); Serial.println(sensor.name); | ||
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version); | ||
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id); | ||
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F("°C")); | ||
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F("°C")); | ||
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F("°C")); | ||
Serial.println(F("------------------------------------")); | ||
// Print humidity sensor details. | ||
dht.humidity().getSensor(&sensor); | ||
Serial.println(F("Humidity Sensor")); | ||
Serial.print (F("Sensor Type: ")); Serial.println(sensor.name); | ||
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version); | ||
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id); | ||
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F("%")); | ||
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F("%")); | ||
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F("%")); | ||
Serial.println(F("------------------------------------")); | ||
// Set delay between sensor readings based on sensor details. | ||
delayMS = sensor.min_delay / 1000; | ||
} | ||
|
||
void loop() | ||
{ | ||
// Delay between measurements. | ||
delay(delayMS); | ||
// Get temperature event and print its value. | ||
sensors_event_t event; | ||
dht.temperature().getEvent(&event); | ||
if (isnan(event.temperature)) { | ||
Serial.println(F("Error reading temperature!")); | ||
} else { | ||
Serial.print(F("Temperature: ")); | ||
Serial.print(event.temperature); | ||
Serial.println(F("°C")); | ||
} | ||
// Get humidity event and print its value. | ||
dht.humidity().getEvent(&event); | ||
if (isnan(event.relative_humidity)) { | ||
Serial.println(F("Error reading humidity!")); | ||
} else { | ||
Serial.print(F("Humidity: ")); | ||
Serial.print(event.relative_humidity); | ||
Serial.println(F("%")); | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Oops, something went wrong.