EasyTransfer Issues. Sending Char Array via i2c

Hello.

I am trying to transfer variables over i2c using the easyTransfer library.. and it works until i try to transfer a char array. I am transferring between a teensy and an esp8266. I thought perhaps it has an issue with differences in how the teensy and esp8266 deal with chars, so i attempted to change the type to int_8, but that also gave me errors, (Invalid conversion from “const char*” to “char” error) because from what i read, the compiler looks at "char" differenty that uint_8 and int_8, even though they are both a "type" of char.

If i try to send the char array, i receive nothing.
If i try to send a char, i receive the integer variables, and the char variable just shows up blank

Here is my code for the TX; The Char array is commented out, if i uncommented nothing is transferred

#include <Wire.h>
#include <EasyTransferI2C.h>

//create object
EasyTransferI2C ET; 

struct SEND_DATA_STRUCTURE{
  unsigned long unixTime;
  int currentTemp;
  //char weather[25];
  char x;
};

 
//give a name to the group of data
SEND_DATA_STRUCTURE mydata;

 
 
//define slave i2c address
#define I2C_SLAVE_ADDRESS 9

void setup(){
  Serial.begin(115200);
  Wire.begin();
  //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc.
  ET.begin(details(mydata), &Wire);
  
  pinMode(13, OUTPUT);
   mydata.unixTime = 56;
   mydata.currentTemp = 25;
   //mydata.weather[25] = 'apple sauce';
   mydata.x = 2;
  randomSeed(analogRead(0));
  
}

void loop(){
  
  ET.sendData(I2C_SLAVE_ADDRESS);
  Serial.println("Sent");
  
  delay(5000); //normally not using delay, just for the example as to not overflow my serial monitor
}

here is my rx code, again, the char array is commented out.

#include <Wire.h>
#include <EasyTransferI2C.h>

//create object
EasyTransferI2C ET; 

struct RECEIVE_DATA_STRUCTURE{
  unsigned long unixTime;
  int currentTemp;
 // char weather[25];
 char x;
};

//give a name to the group of data
RECEIVE_DATA_STRUCTURE mydata;

//define slave i2c address
#define I2C_SLAVE_ADDRESS 9

void setup(){
  Serial.begin(115200);
  Wire.begin(I2C_SLAVE_ADDRESS);
  //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc. 
  ET.begin(details(mydata), &Wire);
  //define handler function on receiving data
  Wire.onReceive(receive);
  
  pinMode(13, OUTPUT);
  
}

void loop() {
  //check and see if a data packet has come in. 
  if(ET.receiveData()){
    Serial.println(mydata.unixTime);
    Serial.println(mydata.currentTemp);
   // Serial.println(mydata.weather);
   Serial.println(mydata.x);
    }
  }

void receive(int numBytes) {}

and here is the resultant serial output

56
25

56
25

56
25

The 'integer' has different sizes on different microcontrollers/processors. Maybe the unsigned long as well.
You could print the sizeof() of the struct with both to detect a difference.

thank you for your reply.

sending ints and unsigned longs works fine, it's the chars I am having an issue with. I read somewhere else that you cannot send more than 32bytes of data via i2c/wire library... is that correct? I haven't had a chance to test it yet...

You are right, I should have mentioned that. The default size for the buffers in the Wire library is 32 byte.

I'm not sure that the full 32 bytes can be used. Let's say 31 bytes, and the EasyTransfer seems to use 2 or 3 bytes for itself, that leaves 28 bytes for you.

If you have installed the EasyTransfer library, please tell how you have installed it and which library or version or fork that is.

What do you want to put in the characters ?
If you print it with " Serial.println ( mydata.weather ) ; " then it has to be a zero-terminated string.

If you use a newer Teensy, then it has probably 32 bit for an integer, perhaps also the ESP8266. That means that if you connect to a Arduino Uno, there is a mismatch. I suggest to print the sizeof() the struct in setup() anyway.

I downloaded the zip here:

and installed the library using arduino ide "add library" tool.

In my full program, I am using the finder library to search for words in rss files, eg "clear" and that is stored in the mydata.weather array. I can print it on the esp8266 side, but it won't transfer over to the teensy...

I will do the sizeof are report back soon.

I think that is the original and newest version and you installed it in the right way.
It does not support multiple I2C transactions, therefor the maximum is 28 or 29 bytes.

Thinking about it now, there is no reason to send the word "clear"... I can just send a byte "weather" and have its value stand for the weather condition....

  //char weather[25];

Define an array that can hold 25 characters, indexed from 0 to 24.

   //mydata.weather[25] = 'apple sauce';

Please post a picture of your keyboard with the apple sauce key circled. Single quotes are for SINGLE characters.

Writing to the 26th element of a 25 element array is not indicative of being the sharpest crayon in the box.

it's a shame I have no applesauce, as I'm temped to pour some on a keyboard and call it a day.

I tried

mydata.wearher[25] = "apple sauce"

but it wouldn't even compile, and I read somewhere sometime you need single ' so I gave it a shot and compiled.

So, in closing I'm not sure I'm a crayon. I'm still stuck in the box here, so I must be the dust left over after the crayons are long gone. "Apple sauce" is only 11 characters....

I tried

Of course that won't work. For two reasons. First, is you MUST stop trying to write beyond the end of the array.

Second, you assign characters to an array ONE AT A TIME.

mydata.wearher[0] = 'a';
mydata.wearher[1] = 'p';
mydata.wearher[2] = 'p';
mydata.wearher[3] = 'l';

etc.

Or, you use a function that knows how to do that:

strcpy(mydata.weather, "apple sauce");

Understood. Thank you.