updates for MSA311

This commit is contained in:
caternuson 2025-06-26 09:47:27 -07:00
parent 3b15d2c6a9
commit cafd3f49ea
5 changed files with 69 additions and 51 deletions

View file

@ -2,12 +2,13 @@
<a href="https://www.adafruit.com/products"><img src="assets/board.jpg?raw=true" width="500px"></a> <a href="https://www.adafruit.com/products"><img src="assets/board.jpg?raw=true" width="500px"></a>
This is the Adafruit MSA301 Accelerometer library This is the Adafruit MSA301/311 Accelerometer library
Tested and works great with the Adafruit MSA301 Breakout Board Tested and works great with the Adafruit MSA301 and MSA311 Breakout Board
* https://www.adafruit.com/product/4344 * https://www.adafruit.com/product/4344
* https://www.adafruit.com/product/5309
This chip uses I2C to communicate, 2 pins are required to interface This breakout uses I2C to communicate, 2 pins are required to interface.
Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!

View file

@ -1,23 +1,27 @@
// Basic demo for accelerometer readings from Adafruit MSA301 // Basic demo for accelerometer readings from Adafruit MSA301/311
#include <Wire.h> #include <Wire.h>
#include <Adafruit_MSA301.h> #include <Adafruit_MSA301.h>
#include <Adafruit_Sensor.h> #include <Adafruit_Sensor.h>
Adafruit_MSA301 msa; //
// Comment/Uncomment as needed for specific MSA being used:
//
// Adafruit_MSA301 msa;
Adafruit_MSA311 msa;
void setup(void) { void setup(void) {
Serial.begin(115200); Serial.begin(115200);
while (!Serial) delay(10); // will pause Zero, Leonardo, etc until serial console opens while (!Serial) delay(10); // will pause Zero, Leonardo, etc until serial console opens
Serial.println("Adafruit MSA301 test!"); Serial.println("Adafruit MSA301/311 test!");
// Try to initialize! // Try to initialize!
if (! msa.begin()) { if (! msa.begin()) {
Serial.println("Failed to find MSA301 chip"); Serial.println("Failed to find MSA301/311 chip");
while (1) { delay(10); } while (1) { delay(10); }
} }
Serial.println("MSA301 Found!"); Serial.println("MSA301/311 Found!");
//msa.setDataRate(MSA301_DATARATE_31_25_HZ); //msa.setDataRate(MSA301_DATARATE_31_25_HZ);
Serial.print("Data rate set to: "); Serial.print("Data rate set to: ");

View file

@ -1,24 +1,29 @@
// OLED demo for accelerometer readings from Adafruit MSA301 // OLED demo for accelerometer readings from Adafruit MSA301/311
#include <Wire.h> #include <Wire.h>
#include <Adafruit_SSD1306.h> #include <Adafruit_SSD1306.h>
#include <Adafruit_MSA301.h> #include <Adafruit_MSA301.h>
#include <Adafruit_Sensor.h> #include <Adafruit_Sensor.h>
Adafruit_MSA301 msa; //
// Comment/Uncomment as needed for specific MSA being used:
//
// Adafruit_MSA301 msa;
Adafruit_MSA311 msa;
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &Wire); Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &Wire);
void setup(void) { void setup(void) {
Serial.begin(115200); Serial.begin(115200);
Serial.println("Adafruit MSA301 demo!"); Serial.println("Adafruit MSA301/311 demo!");
// Try to initialize! // Try to initialize!
if (! msa.begin()) { if (! msa.begin()) {
Serial.println("Failed to find MSA301 chip"); Serial.println("Failed to find MSA301/311 chip");
while (1) { delay(10); } while (1) { delay(10); }
} }
Serial.println("MSA301 Found!"); Serial.println("MSA301/311 Found!");
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32 if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
@ -39,7 +44,7 @@ void loop() {
display.clearDisplay(); display.clearDisplay();
display.setTextSize(1); display.setTextSize(1);
display.setCursor(0,0); display.setCursor(0,0);
display.println("- Adafruit MSA301 -"); display.println("- Adafruit MSA3x1 -");
/* Display the results (acceleration is measured in m/s^2) */ /* Display the results (acceleration is measured in m/s^2) */
Serial.print("\t\tX: "); Serial.print(event.acceleration.x); Serial.print("\t\tX: "); Serial.print(event.acceleration.x);

View file

@ -1,23 +1,27 @@
// Basic demo for plotting accelerometer readings from Adafruit MSA301 // Basic demo for plotting accelerometer readings from Adafruit MSA301/311
#include <Wire.h> #include <Wire.h>
#include <Adafruit_MSA301.h> #include <Adafruit_MSA301.h>
#include <Adafruit_Sensor.h> #include <Adafruit_Sensor.h>
Adafruit_MSA301 msa; //
// Comment/Uncomment as needed for specific MSA being used:
//
// Adafruit_MSA301 msa;
Adafruit_MSA311 msa;
void setup(void) { void setup(void) {
Serial.begin(115200); Serial.begin(115200);
while (!Serial) delay(10); // will pause Zero, Leonardo, etc until serial console opens while (!Serial) delay(10); // will pause Zero, Leonardo, etc until serial console opens
Serial.println("Adafruit MSA301 test!"); Serial.println("Adafruit MSA301/311 test!");
// Try to initialize! // Try to initialize!
if (! msa.begin()) { if (! msa.begin()) {
Serial.println("Failed to find MSA301 chip"); Serial.println("Failed to find MSA301/311 chip");
while (1) { delay(10); } while (1) { delay(10); }
} }
Serial.println("MSA301 Found!"); Serial.println("MSA301/311 Found!");
} }

View file

@ -1,8 +1,12 @@
// Basic demo for tap/doubletap readings from Adafruit MSA301 // Basic demo for tap/doubletap readings from Adafruit MSA301/311
#include <Adafruit_MSA301.h> #include <Adafruit_MSA301.h>
Adafruit_MSA301 msa; //
// Comment/Uncomment as needed for specific MSA being used:
//
// Adafruit_MSA301 msa;
Adafruit_MSA311 msa;
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
@ -10,10 +14,10 @@ void setup() {
// Try to initialize! // Try to initialize!
if (! msa.begin()) { if (! msa.begin()) {
Serial.println("Failed to find MSA301 chip"); Serial.println("Failed to find MSA301/311 chip");
while (1) { delay(10); } while (1) { delay(10); }
} }
Serial.println("Found MSA301!"); Serial.println("Found MSA301/311!");
msa.setPowerMode(MSA301_NORMALMODE); msa.setPowerMode(MSA301_NORMALMODE);
msa.setDataRate(MSA301_DATARATE_1000_HZ); msa.setDataRate(MSA301_DATARATE_1000_HZ);