Home/Support/Support Forum/XBee 3 Cannot Communicate with Trinket M0 over I2C.
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

XBee 3 Cannot Communicate with Trinket M0 over I2C.

0 votes
I am trying to use I2C to communicate between my XBee3 (controller) and an adafruit trinket m0. I'm pretty confident I have the modules connected properly (trinket SCL/pin 2 to xbee SCL/pin DIO1 & trinket SDA/pin 0 to xbee SDA/pin DIO11, and both grounds are connected). Here is my arduino code on the trinket:

======
#include <Wire.h>

void setup()
{
Wire.begin(72); // join i2c bus
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
Serial.print("Waiting for data...");
}

void loop()
{
delay(100);
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
(void)howMany; // avoid compiler warning about unused parameter

while(1 < Wire.available()) // loop through all but the last
{
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}
int x = Wire.read(); // receive byte as an integer
Serial.println(x); // print the integer
}
======

and here is my code for the xbee (I'm using pycharm):

======
from machine import I2C

# Instantiate an I2C peripheral.
i2c = I2C(1)
slave_addr = 72
i2c.writeto(slave_addr, b'123', False)
======

The xbee throws this error on the i2c.writeto() line: OSError: [Errno 7110] ETIMEDOUT.

Any ideas what I'm doing wrong?
asked Jan 12 in Python by byrleyar New to the Community (0 points)

Please log in or register to answer this question.

1 Answer

0 votes
Looks like you are not configuring the Micro Python for I2C interface. There is no driver listed to enable it. Take a closer look to the GPS and sensor examples that are offered in PyCharm.
answered Jan 12 by mvut Veteran of the Digi Community (13,684 points)
Thanks for the insights, @mvut, but I'm not sure that's it.  When I run the below code with an ISM330DHCX attached to the xbee I2C, the ISM330DHCX address pops right up.  But when I run the same code hooked to the trinket, the xbee doesn't find anything with i2c.scan().  I guess my issue is with the trinket, and not the xbee.

======
from machine import I2C

# Instantiate an I2C peripheral.
i2c = I2C(1)
# Scan for I2C slaves connected to the interface and print their address.
for address in i2c.scan():
    print("- I2C device found at address: %s" % hex(address))
======
That would be correct. Since it works with a different device, it is going to be with the one that is not working with.
...