top of page
Search
  • Writer's pictureIfrim Ciprian

Nicla Sense ME and Xiao Sense I2C Communication

As I have talked about in some of my previous blogs, the Nicla Sense ME communicated with the Xiao Sense for the CNN in voice recognition and ML models for weather classification and rainfall regression.


So the Nicla Sense Me with the pinout:

And the Xiao pinout:


The SCL and SDA pins, combined with the ground were connected from both devices to eachother.

Here is a test of a simple code in order to test the systems:

Nicla Code:

// Include Arduino Wire library for I2C
#include <Arduino.h>
#include "Nicla_System.h"
#include <Wire.h>

void setup() {
  Wire.begin(); // join i2c bus (address optional for master)
  Serial.begin(9600);
}

void loop() {
  while (Serial.available() > 0) {
    char incomingCharacter = Serial.read();
    if (incomingCharacter == '1') {
      Wire.beginTransmission(8); // transmit to device #8
      Wire.write(5);              // sends one byte
      Wire.endTransmission();    // stop transmitting

      Wire.requestFrom(8, 1);    // request 1 byte from slave device #8
      while (Wire.available()) { // slave may send less than requested
        int c = Wire.read(); // receive a byte as character

        Serial.print("Slave value : ");
        Serial.println(c);         // print the character
      }

      delay(100);
    }
  }
}

Seeed Xiao code:

#include <Wire.h>
int val = 50;

void setup() {
  Wire.begin(8);                // join i2c bus with address #8
  Wire.onRequest(requestEvent); // register event
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(9600);    // start serial for output

}

void loop() {

}

// function that executes whenever data is received from master
void receiveEvent(int howMany) {
  while (Wire.available()){
   int x = Wire.read();    // receive byte as an integer
   if (x == 5){
    Serial.println("Hello World!");
   }
  }
}

// function that executes whenever data is requested by master
void requestEvent() {
  Wire.write(val); // respond with message of 1 byte
}

And when I moved the I2C code to the voice recognition, I ran into some issues with the PDM (microphone library) which had interrupts, the same way the I2C had interrupts, creating issues.


I have then contacted the Edge Impulse developers on the forums to get some help:

It turns out that a flag system has to be used to be able to start the voice recording, so that it only happens separately from the I2C events.


Here is the system working:


3 views0 comments

Recent Posts

See All
bottom of page