Tracker SoM Eval - i2c/Wire

I’m having trouble getting the Wire library to work with the Tracker Eval.

The Tracker (master) is connected with A0/A1 to an Arduino Nano (slave) SDA/SCL pins with 10k pull-up resistors.

Tracker main.c

#include "Particle.h"

#include "tracker_config.h"
#include "tracker.h"

#include "Wire.h"

SYSTEM_THREAD(ENABLED);
SYSTEM_MODE(SEMI_AUTOMATIC);

PRODUCT_ID(TRACKER_PRODUCT_ID);
PRODUCT_VERSION(TRACKER_PRODUCT_VERSION);

STARTUP(
    Tracker::startup();
);

SerialLogHandler logHandler(115200, LOG_LEVEL_TRACE, {
    { "app.gps.nmea", LOG_LEVEL_INFO },
    { "app.gps.ubx",  LOG_LEVEL_INFO },
    { "ncp.at", LOG_LEVEL_INFO },
    { "net.ppp.client", LOG_LEVEL_INFO },
});

const unsigned long WIRE_CHECK_PERIOD_MS = 1000;
unsigned long wireLastCheck = 0;

void setup()
{
    Tracker::instance().init();
    
    Wire.begin();
}

void loop()
{
    Tracker::instance().loop();

    if (millis() - wireLastCheck >= WIRE_CHECK_PERIOD_MS) {
        wireLastCheck = millis();

        Wire.requestFrom(8, 6);    // request 6 bytes from slave device #8
        
        if (Wire.available()) {
            while (Wire.available()) { 
                char c = Wire.read(); // receive a byte as character
                Serial.print(c);         // print the character
            }
            Serial.println();
        } else {
            Serial.println("no data available for #8");
        }
    }
}

Arduino

#include <Wire.h>

void setup() {
  Wire.begin(8);                // join i2c bus with address #8
  Wire.onRequest(requestEvent); // register event
  Serial.begin(9600);
}

void loop() {
  Serial.println("waiting for request");
  delay(1000);
}

// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent() {
  Serial.println("received request");
  Wire.write("hello "); // respond with message of 6 bytes
  // as expected by master
}

This works for connecting two Arduinos but the Tracker doesn’t seem to send or receive anything on A0/A1, am I missing something in the setup?

HI,
looks like on A0/A1 is Wire1 object on Tracker Eval but I can’t confirm 100% as I couldn’t find any info in the doc. also not sure D0/D1 like on other Particle devices guessing that this is Wire object.
But you can try to use multi-function port pins MCU_RX and MCU_TX and Wire3 object as described here:
https://docs.particle.io/tutorials/asset-tracking/tracker-eval-tutorials/#i2c-sensor-example
but unfortunately you will have to disable Serial1.
Please note that I2C on Tracker is not 5V tolerant ! Do not connect your pull-ups to 5V instead connect them to 3V3
Best,
Arek

A0/A1 on the Tracker SoM is actually the same physical pin as D0/D1, so it is Wire.

The only caveat is that Wire and Wire3 (TX/RX) share the same I2C peripheral, so only one can be used at a time. In other words, if you enable Wire3, then Wire gets disabled.

Nothing jumped out as obviously wrong with the code. The next thing I’d do is run an I2C scanner on the Tracker and see if it can see the Arduino.

1 Like

Thanks for the responses. I tried the scanner app and Wire1, 2 & 3 but none of them worked for me. I will check with a logic analyzer next week and report back.

This is resolved. I think I had the SDA/SCL lines switched…