From cafd3f49ea96aacd24b614064a20be445a5593a0 Mon Sep 17 00:00:00 2001 From: caternuson Date: Thu, 26 Jun 2025 09:47:27 -0700 Subject: [PATCH] updates for MSA311 --- README.md | 9 +++---- examples/acceldemo/acceldemo.ino | 40 ++++++++++++++++++-------------- examples/oleddemo/oleddemo.ino | 29 +++++++++++++---------- examples/plotdemo/plotdemo.ino | 30 +++++++++++++----------- examples/tapdemo/tapdemo.ino | 12 ++++++---- 5 files changed, 69 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index dc25262..be6c2b7 100644 --- a/README.md +++ b/README.md @@ -2,16 +2,17 @@ -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/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! -Written by Limor Fried for Adafruit Industries. +Written by Limor Fried for Adafruit Industries. BSD license, check license.txt for more information All text above must be included in any redistribution diff --git a/examples/acceldemo/acceldemo.ino b/examples/acceldemo/acceldemo.ino index 76c1caa..72f3ff5 100644 --- a/examples/acceldemo/acceldemo.ino +++ b/examples/acceldemo/acceldemo.ino @@ -1,23 +1,27 @@ -// Basic demo for accelerometer readings from Adafruit MSA301 +// Basic demo for accelerometer readings from Adafruit MSA301/311 #include #include #include -Adafruit_MSA301 msa; +// +// Comment/Uncomment as needed for specific MSA being used: +// +// Adafruit_MSA301 msa; +Adafruit_MSA311 msa; void setup(void) { Serial.begin(115200); 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! if (! msa.begin()) { - Serial.println("Failed to find MSA301 chip"); + Serial.println("Failed to find MSA301/311 chip"); while (1) { delay(10); } } - Serial.println("MSA301 Found!"); + Serial.println("MSA301/311 Found!"); //msa.setDataRate(MSA301_DATARATE_31_25_HZ); Serial.print("Data rate set to: "); @@ -79,22 +83,22 @@ void setup(void) { void loop() { msa.read(); // get X Y and Z data at once // Then print out the raw data - Serial.print("X: "); Serial.print(msa.x); - Serial.print(" \tY: "); Serial.print(msa.y); - Serial.print(" \tZ: "); Serial.print(msa.z); - delay(100); - - /* Or....get a new sensor event, normalized */ - sensors_event_t event; + Serial.print("X: "); Serial.print(msa.x); + Serial.print(" \tY: "); Serial.print(msa.y); + Serial.print(" \tZ: "); Serial.print(msa.z); + delay(100); + + /* Or....get a new sensor event, normalized */ + sensors_event_t event; msa.getEvent(&event); - + /* Display the results (acceleration is measured in m/s^2) */ Serial.print("\t\tX: "); Serial.print(event.acceleration.x); - Serial.print(" \tY: "); Serial.print(event.acceleration.y); - Serial.print(" \tZ: "); Serial.print(event.acceleration.z); + Serial.print(" \tY: "); Serial.print(event.acceleration.y); + Serial.print(" \tZ: "); Serial.print(event.acceleration.z); Serial.println(" m/s^2 "); Serial.println(); - - delay(100); + + delay(100); } \ No newline at end of file diff --git a/examples/oleddemo/oleddemo.ino b/examples/oleddemo/oleddemo.ino index 55e6b5e..5f9da0a 100644 --- a/examples/oleddemo/oleddemo.ino +++ b/examples/oleddemo/oleddemo.ino @@ -1,30 +1,35 @@ -// OLED demo for accelerometer readings from Adafruit MSA301 +// OLED demo for accelerometer readings from Adafruit MSA301/311 #include #include #include #include -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); void setup(void) { Serial.begin(115200); - Serial.println("Adafruit MSA301 demo!"); - + Serial.println("Adafruit MSA301/311 demo!"); + // Try to initialize! if (! msa.begin()) { - Serial.println("Failed to find MSA301 chip"); + Serial.println("Failed to find MSA301/311 chip"); while (1) { delay(10); } } - Serial.println("MSA301 Found!"); + Serial.println("MSA301/311 Found!"); // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32 Serial.println(F("SSD1306 allocation failed")); for(;;); // Don't proceed, loop forever - } + } display.display(); delay(500); // Pause for 2 seconds display.setTextSize(1); @@ -33,24 +38,24 @@ void setup(void) { } void loop() { - sensors_event_t event; + sensors_event_t event; msa.getEvent(&event); display.clearDisplay(); display.setTextSize(1); display.setCursor(0,0); - display.println("- Adafruit MSA301 -"); + display.println("- Adafruit MSA3x1 -"); /* Display the results (acceleration is measured in m/s^2) */ Serial.print("\t\tX: "); Serial.print(event.acceleration.x); - Serial.print(" \tY: "); Serial.print(event.acceleration.y); - Serial.print(" \tZ: "); Serial.print(event.acceleration.z); + Serial.print(" \tY: "); Serial.print(event.acceleration.y); + Serial.print(" \tZ: "); Serial.print(event.acceleration.z); Serial.println(" m/s^2 "); display.setCursor(0, 8); display.print("X: "); display.print(event.acceleration.x); display.println(" m/s^2 "); display.print("Y: "); display.print(event.acceleration.y); display.println(" m/s^2 "); - display.print("Z: "); display.print(event.acceleration.z); display.println(" m/s^2 "); + display.print("Z: "); display.print(event.acceleration.z); display.println(" m/s^2 "); display.display(); delay(100); diff --git a/examples/plotdemo/plotdemo.ino b/examples/plotdemo/plotdemo.ino index 625b4d4..ae60076 100644 --- a/examples/plotdemo/plotdemo.ino +++ b/examples/plotdemo/plotdemo.ino @@ -1,37 +1,41 @@ -// Basic demo for plotting accelerometer readings from Adafruit MSA301 +// Basic demo for plotting accelerometer readings from Adafruit MSA301/311 #include #include #include -Adafruit_MSA301 msa; +// +// Comment/Uncomment as needed for specific MSA being used: +// +// Adafruit_MSA301 msa; +Adafruit_MSA311 msa; void setup(void) { Serial.begin(115200); 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! if (! msa.begin()) { - Serial.println("Failed to find MSA301 chip"); + Serial.println("Failed to find MSA301/311 chip"); while (1) { delay(10); } } - Serial.println("MSA301 Found!"); + Serial.println("MSA301/311 Found!"); } void loop() { - /* Get a new sensor event, normalized */ - sensors_event_t event; + /* Get a new sensor event, normalized */ + sensors_event_t event; msa.getEvent(&event); - + /* Display the results (acceleration is measured in m/s^2), with commas in between */ Serial.print(event.acceleration.x); - Serial.print(", "); Serial.print(event.acceleration.y); - Serial.print(", "); Serial.print(event.acceleration.z); + Serial.print(", "); Serial.print(event.acceleration.y); + Serial.print(", "); Serial.print(event.acceleration.z); Serial.println(); - - delay(10); + + delay(10); } \ No newline at end of file diff --git a/examples/tapdemo/tapdemo.ino b/examples/tapdemo/tapdemo.ino index 2d2a7ec..c64438b 100644 --- a/examples/tapdemo/tapdemo.ino +++ b/examples/tapdemo/tapdemo.ino @@ -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 msa; +// +// Comment/Uncomment as needed for specific MSA being used: +// +// Adafruit_MSA301 msa; +Adafruit_MSA311 msa; void setup() { Serial.begin(115200); @@ -10,10 +14,10 @@ void setup() { // Try to initialize! if (! msa.begin()) { - Serial.println("Failed to find MSA301 chip"); + Serial.println("Failed to find MSA301/311 chip"); while (1) { delay(10); } } - Serial.println("Found MSA301!"); + Serial.println("Found MSA301/311!"); msa.setPowerMode(MSA301_NORMALMODE); msa.setDataRate(MSA301_DATARATE_1000_HZ);