ATtiny85 TinyWireS I2C sending multiple bytes

Hi, how would I accomplish the following?

I'm setting up a slave device using ATtiny85, the master is a Raspberry Pi and I can't edit code on it.

To start I used an Arduino Due as the slave as it's easier to upload and have it working with the master.

The master sends an R character and the slave responds with 31 bytes. This is the code the Due slave is using which is good.

#include <Wire.h>                //enable I2C.
#define address 45               //default I2C ID number for EZO pH Circuit.

char computerdata[32];           //we make a 20 byte character array to hold incoming data from a pc/mac/other.
byte in_char = 0;
char inData[20];               //used as a 1 byte buffer to store inbound bytes from the pH Circuit.
byte w = 0;                      //counter used for ph_data array.

void setup() {
  Serial.begin(115200);
  Serial.println("startup: ");
  Wire.begin(45);
  Wire.onReceive(receiveEvent); // register event
  Wire.onRequest(requestEvent); // register event
}
void requestEvent()  // send data to controller
{
  if ((inData[0] == 'R'))
  {
    computerdata[0] = '7';
    computerdata[1] = '.';
    computerdata[2] = '6';
    computerdata[3] = '1';
    Wire.write(1);
    Wire.write(computerdata,30);
  }
}

void receiveEvent(int howMany)  // controller is asking for something
{
  while (Wire.available()) {            //are there bytes to receive.
    in_char = Wire.read();              //receive a byte.
    inData[w] = in_char;               //load this byte into our array.
    w += 1;                             //incur the counter for the array element.
    if (in_char == 0) {                 //if we see that we have been sent a null command.
      w = 0;                            //reset the counter i to 0.
      break;                            //exit the while loop.
    }
  }
}
void loop() {
  // put your main code here, to run repeatedly:

}

On the ATtiny85 I have to use TinyWireS library and it doesn't allow me to specify how many bytes are sent.

Wire.write(computerdata,30);

has to be

TinyWireS.send(computerdata);

for it to compile but that isn't sending the data the same way as it gives parsing errors on the master.

So how can I do the equivalent of Wire.write(computerdata,30); on the ATtiny85?

I've tried sending the array in a for loop but it doesn't send it correctly either.

Thanks

This seems strangely familiar to another thread you started. Why the change?

TinyWire has the same function

uint8_t send(uint8_t *data, uint8_t length);

so you can change write() to send() and all should be well.

I figured this one was only related to the TinyWireS library so made a new thread.

Turns out I was using the wrong library, I had tried another but neither had same function, only data in it. After looking through 4 libraries I found this one that has that function and works. :slight_smile:

Thanks for your help, much appreciated.

Communication works good. I have been able to keep the network running correctly for hours.

This thing is kicking my butt, now I can't convert a float to a char array.

snprintf doesn't seem to put anything in the array, I just get a parse error on master with no data. I can't do serial prints as I'm using ATtiny85 and no spare pins.

dtostrf won't compile.

itoa(f, computerdata, 30); will work but I only get the converted int obviously.

When I search everything recommends the above.

I'm trying to do the following but now an actual float value needs to go where those test numbers are.

    computerdata[0] = '2';
    computerdata[1] = '.';
    computerdata[2] = '5';
    computerdata[3] = '7';
    
    TinyWire.send(1);
    TinyWire.send(computerdata,30);