Hello, I am fairly new to using redboards. I have a redboard Artemis Nano. the site says there are 4 i2c buses on the board (including the QUIC connector). I was wondering if anyone knows of a guide, example, video, tutorial etc… on how to use more than one i2c bus? It seems obvious, but I have not found too much help.
BTW, the reason is I have two sensors with the same i2c address, so to use them both I would like to use the QUIC connector and a second i2c bus.
Declare a new wire port using the IOM instance that you want like this:
TwoWire myWire(N);
Choose N depending on which pins you want to use (there are 3 options that aren’t on the qwiic connector) for example pins 9 and 10 on the Nano are connected to IOM# N=4
As of the latest 2.2.1 core (today 4/20/22) this takes two arguments, which are the SDA and SCL pins (not a single device number). Compiling and running the code causes a hard fault. The other method that I used in the past on a Redboard Thing was to reference an external pre-defined Wire1() object as my second i2c device. The result of that technique on Nano is also a hard fault.
SPI and I2C (or Wire) are driven by an Input Output Module (IOM) in the Apollo3. Unlike some other processors, the pins for each IOM can only be assigned to a fixed pad (processor connection point) . If the SCL / SDA combination is not as indicated belowfor a Nano, you will get an hard error:
IOM SDA-PAD SCL-PAD NANO-PIN (SDA) NANO-PIN (SCL)
0 6 5 11 (sck) 13 (MISO) pins assigned to SPI
1 9 8 NOT CONNECTED on the NANO
2 25 27 QWIIC QWIIC Wire
3 43 42 7 (SDA3) 6 (SCL3) Wire1
4 40 39 10 (RX1) 9 (TX1) pins assigned to Serial1
5 49 48 Serial / USB
If you do NOT use SPI OR do NOT use Serial1 you can try re-assign to Wire-interface on the Nano.: #include “Wire.h”
In case of SPI re-assign : arduino::MbedI2C MyWire(6, 5);
In case of Serial1-re-assign: arduino::MbedI2C MyWire(40, 39);
my issue was solved by moving the #include <Wire.h> statement up to the top of my code. I’m writing my code to work with both arduino and artemis with some #if compiler directives, so maybe that had something to do with it.
Old code (broken):
//#define Arduino
#define Artemis
#ifdef Arduino
#define I2C Wire
#endif
#ifdef Artemis
#define I2C Wire1
#endif
#include <Wire.h>
void setup() {
I2C.begin();
}
// and so on
New code (working):
#include <Wire.h>
//#define Arduino
#define Artemis
#ifdef Arduino
#define I2C Wire
#endif
#ifdef Artemis
#define I2C Wire1
#endif
void setup() {
I2C.begin();
}
// and so on