Odd issue with Nano 33 I2C

I'm new to Adruino, but a long time programmer. Last time I worked at the chip level was the Z80 so that will give you some idea of my age.

So I purchased a Nano 33 to build a marine refrigerator controller. The IOT was the big attraction. I soon figured out you can't easily use Bluetooth and IOT at the same time, so I decided to try (2) Nano 33's - one for the IOT and one for the Bluetooth using I2C for the communication.

I'm at point now where everything actually works. The first Arduino collects Bluetooth data and the second Arduino reads the data using the I2C connection. for the physical wiring, I followed the handy diagram at Wiring Diagram

The program follows below. Here is the weirdness: In order to get it to work, I have to remove the A4 and A5 link. (SCL and SDA). Actually I think maybe just the SCL.

Then after the IOT is (mostly) stable, make the connection. Then it will run (indefinitely I think) and receives the I2C data from the master Nano.

I've tried various ways to get it to start with the pins connected; no luck. Things like delaying the wire start for 30 seconds, testing for IOT connection first, etc.

So basically the Issue seems to be that if the clock is connected when the sketch starts, it hangs, and I haven't figured a workaround. Any insights? Code and breadboard pic below:

Edit: In the breadboard pic the Bluetooth "writer" is on the left (that always works fine with I2C) and the problematic IOT "reader" on the right.

#include "arduino_secrets.h"


#include "thingProperties.h"
#include <Wire.h>

const byte flashRate = 25;
boolean wireStarted = false;
unsigned long int flashCount = 0;
short int ledState = HIGH;



void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, ledState);

  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500);

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);

  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(4);
  ArduinoCloud.printDebugInfo();

  message = "Startup Fridge State**";

  Serial.println("Starting wire...");
  wireStarted = true;
  Wire.begin(8);                 // join i2c bus with address #8
  Wire.onReceive(receiveEvent);  // function that executes whenever data is received from writer

  Serial.println("Startup done.");
}

void receiveEvent(int howMany) {
  for (int i = 1; i <= howMany; i++) {
    char c = Wire.read();  // receive a character
    Serial.println(c);
  }
}

void loop() {

  ArduinoCloud.update();


  if (flashCount++ >= flashRate) {
    // medium blink = running
    digitalWrite(LED_BUILTIN, ledState = !ledState);

    flashCount = 0;
  }
}



/*
  Since FridgeCompressorCutin is READ_WRITE variable, onFridgeCompressorCutinChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onFridgeCompressorCutinChange() {
  // Add your code here to act upon FridgeCompressorCutin change
}

/*
  Since FreezerCompressorCutin is READ_WRITE variable, onFreezerCompressorCutinChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onFreezerCompressorCutinChange() {
  // Add your code here to act upon FreezerCompressorCutin change
}

/*
  Since FridgeCompressorCutout is READ_WRITE variable, onFridgeCompressorCutoutChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onFridgeCompressorCutoutChange() {
  // Add your code here to act upon FridgeCompressorCutout change
}

Origin of the Wiring Diagram is this tutorial: https://docs.arduino.cc/tutorials/nano-33-iot/i2c
That tutorial might be the limit for the I2C Slave mode. You might be the first one to try it with Bluetooth and Wifi.

The Nina module on the Arduino 33 IoT contains a ESP32.
You could use a ESP32 board. However, it has the same problem when using Wifi and Bluetooth together, but maybe that have been fixed by now. If not, then they have a spare Serial2 port that can be used to communicate.

The Arduino 33 IoT has special initialization code here: https://github.com/arduino/ArduinoCore-samd/tree/master/variants/nano_33_iot
I think that nothing special is done there.
But there is a sensor and a security chip on the board. They are connected to the normal I2C bus at pin A4 and A5. When you connect two Arduino 33 IoT boards, then they are all on the I2C bus. That is not allowed. Each board should get to its own security chip for Wifi. That means your project is not possible that way.

What actually is going on: When I read on this forum that someone uses two Arduino boards with I2C communication between them, then I go: O no, not another one :scream: How much of the trouble shall I mention, 1%, 2%, 5% ? I have to stop typing before it gets annoying :face_with_spiral_eyes: (just kidding, I don't mind being annoying).

Ahhh! Thanks so much. That explains a lot. I was hoping this would work - serial was my next backup strategy.

I played around with this for a while as it does work (but I later discovered only for a while) if I connect while it’s running.

So back to the drawing board I guess. I’ll go look at serial implementation.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.