I have a samd21 (m0) board that I would like to use 2 MPR sensors with but I only have one i2c bus. I’ve followed the tutorial for adding sercom ports https://learn.sparkfun.com/tutorials/ad … boards/all but when I try to pass the newly created bus, myWire, into the sensors begin function, nothing happens. I loose any output with serial monitor and I can not get a reading from either sensor. I have tried using the example to run the LCD and the MPR and that works, so the new myWire bus IS working. That’s good but that doesnt help me since my main issue is needing two sensors. What am I doing wrong?
Sensor: https://www.sparkfun.com/products/16476 … 1599677515
Modified example code:
/*
Basic test of the Qwiic MicroPressure Sensor
By: Alex Wende
SparkFun Electronics
Date: July 2020
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
Feel like supporting our work? Buy a board from SparkFun!
https://www.sparkfun.com/products/16476
This example demonstrates how to get started with the Qwiic MicroPressure Sensor board, and read pressures in various units.
*/
#include <Wire.h>
#include "wiring_private.h" // pinPeripheral() function
#include <SparkFun_MicroPressure.h>
TwoWire myWire(&sercom1, 11, 13);
SparkFun_MicroPressure mpr; // Use default values with reset and EOC pins unused
SparkFun_MicroPressure mpr1; // Use default values with reset and EOC pins unused
void setup() {
// Initalize UART, I2C bus, and connect to the micropressure sensor
Serial1.begin(115200);
Wire.begin();
myWire.begin();
// Assign pins 13 & 11 to SERCOM functionality
pinPeripheral(11, PIO_SERCOM);
pinPeripheral(13, PIO_SERCOM);
/* The micropressure sensor uses default settings with the address 0x18 using Wire.
The mircropressure sensor has a fixed I2C address, if another address is used it
can be defined here. If you need to use two micropressure sensors, and your
microcontroller has multiple I2C buses, these parameters can be changed here.
E.g. mpr.begin(ADDRESS, Wire1)
Will return true on success or false on failure to communicate. */
if(!mpr.begin())
{
Serial.println("Cannot connect to MicroPressure sensor1 on orig i2c bus.");
while(1);
}
if(!mpr1.begin(0x18, myWire))
{
Serial1.println("Cannot connect to MicroPressure sensor2 on new i2c bus.");
while(1);
}
}
void loop() {
Serial.print(mpr.readPressure(PA),1);
Serial.println(" Pa");
Serial1.print(mpr1.readPressure(PA),1);
Serial1.println(" Pa");
delay(500);
}