I2C between Arduino and Daisy Seed

Hi, I’m trying to establish communication between an Arduino Mega (Slave) and the Daisy Seed (Master). I’ve connected the SDA and SCL of each board (pins 12 and 13 on the Seed) and recently added pullup resistors (4.7kohm) to 5v.

The hardware.PrintLine(“RX Result: %d”, rx_result); in the following code of the Daisy returns 1 so there’s an error in the communication but can’t figure out what it is…

My Daisy code :

#include "daisy_seed.h"

// Use the daisy namespace to prevent having to type
// daisy:: before all libdaisy functions
using namespace daisy;

// Declare a DaisySeed object called hardware
DaisySeed hardware;
I2CHandle::Config i2c_conf;

int main(void)
{   
    hardware.Configure();
    hardware.Init();

    i2c_conf.periph = I2CHandle::Config::Peripheral::I2C_1;
    i2c_conf.speed = I2CHandle::Config::Speed::I2C_100KHZ;
    i2c_conf.mode = I2CHandle::Config::Mode::I2C_MASTER;
    i2c_conf.pin_config.scl = {DSY_GPIOB, 8};
    i2c_conf.pin_config.sda = {DSY_GPIOB, 9};

    I2CHandle i2c;
    i2c.Init(i2c_conf);

    hardware.StartLog(true);

    uint8_t rxdata=0x00;

    for (;;)
    {
        I2CHandle::Result rx_result = i2c.ReceiveBlocking(0xA1, &rxdata, 3, 1000);
        hardware.PrintLine("RX Result: %d", rx_result);
        
        if (rxdata==0){
            hardware.PrintLine("Released");
        }
        else {
            hardware.PrintLine("Pressed !");
        }
        hardware.DelayMs(100);
    }
}

My Arduino code :

#include <Wire.h>

const int button=5;
int buttonstate;

void setup() {
  pinMode(button,INPUT_PULLUP);
  Wire.begin(0xA1);
  Wire.setClock(100000);
  Wire.onRequest(requestEvent);
}

void loop() {
  buttonstate=digitalRead(button);
}

void requestEvent() {
  if (button==0){
    Wire.write(1);
    Wire.write(0);
  }
  else {
    Wire.write(1);
    Wire.write(1);
  }
}

It looks like Arduino isn’t sending a response, because Seed isn’t sending a request.

Isnt i2c.ReceiveBlocking a request ? If not, how would you send a request ? (Sorry im a newby)

https://electro-smith.github.io/libDaisy/classdaisy_1_1_i2_c_handle.html

Note also: your ReceiveBlocking() call has a ‘size’ parameter of 3, but rxdata is only one byte.

You could also consider using UART, sometimes i2c can be a bit tweaky between actual MCU’s

Thank you for your advices.

I’m not using UART because I’m already using it to receive data from a MIDI port, but yes it could have saved me some time…

I’ve digged into it and programmed both boards with the Arduino IDE. I’m testing the connection with 2 basic I2C codes, one for slave (Arduino Mega) and one for master (Daisy Seed).
I tried to replace the Seed with another Arduino (Uno), without changing anything else and the I2C communication works, so the problem doesn’t come from the code (do I have to specify more than the clock frequency when using Seed ?). For the I2C channels, I’ve also tried pullup resistor to 5v and to 3.3v : both do work with arduinos (even if their I2C is supposed to run on 5v) but still doesn’t work with the Seed…

Any help would be greatly appreciated, feel free to ask details.

Here are the simple codes I’ve used :

Master (Daisy/Arduino Uno for testing) :

#include <Wire.h>
 
byte RxByte;
 
void setup() {
  Wire.begin();
  Wire.setClock(400000);
  Serial.begin(9600);
}
 
void loop() {
  Wire.requestFrom(0x55, 1); // Request From Slave @ 0x55, Data Length = 1Byte
  while(Wire.available()) {  // Read Received Datat From Slave Device
    RxByte = Wire.read();
    Serial.println(RxByte);
  }
}

Slave (Arduino Mega) :

#include <Wire.h>
 
byte TxByte = 0xA9;

void I2C_TxHandler(void)
{
  Serial.print("Sent this : ");
  Wire.write(TxByte);
  Serial.println(TxByte);
}
 
void setup() {
  Serial.begin(9600);
  Wire.begin(0x55); // Initialize I2C (Slave Mode: address=0x55 )
  Wire.setClock(400000);
  Wire.onRequest(I2C_TxHandler);
}
 
void loop() {
}

You need to send a request, I’d suggest i2c.TransmitBlocking().