sending float data with i2c from arduino to raspberry

hello,

i need to send a float value over i2c, from one Arduino to raspberry.
i understand i need to convert it, because only byte or string can be sent.
i wrote this code but it seems it doesn't work ,i dont know what should i do ,

code arduino

#include <Wire.h>
#include "SHTSensor.h"
#include <String.h>

SHTSensor sht;

 double Temperature;
 double Humidity;
 int i;

byte SLAVE_ADRESS = 8; 

char temp[10];
char humid[10];

String tmp;
 
char T_data[5];

int index = 0;

void SendData(){

if (sht.readSample()) {
      Serial.println("SHT:");
      Humidity=sht.getHumidity();
      Serial.println(Humidity,2);
      Temperature=sht.getTemperature();
      Serial.println(Temperature,2);
  } 
  else {
      Serial.println("Error in readSample()\n");
  }

  tmp = dtostrf(Temperature,5,2,temp);

for(i=0;i++;i<5){
  T_data[i] = tmp[i];
}

  Wire.write(T_data[index]);

  ++index;

  if(index >= 5){
    index=0;
  }

}





void setup() {
  

  Wire.begin(SLAVE_ADRESS);

  Wire.onRequest(SendData);

  Serial.begin(9600);


  if (sht.init()) {
      Serial.println("init(): success\n");
  } 
  
  else {
      Serial.println("init(): failed\n");
  }

}

void loop() {



}

code rasp

import smbus
import time

bus = smbus.SMBus(1)
address = 0x08                

while True:
    data = ""
    for i in range(0,5):
        data += chr(bus.read_byte(address))
        print(data)
        time.sleep(1)

so if you can cheek my codes and tell me what is the problem , i will be great full ,its been a week searching end it doesn't work
thank you

  Wire.onRequest(SendData);

You cannot use the I2C bus to read some sensor data while the Raspberry Pi (master) is requesting data from the Arduino.

Why don't you use the USB connection to transfer the data to the Raspberry Pi? As you use the I2C for the connection to the sensor the bus roles are fixed: Arduino is master, sensor is slave. If you try to make the Arduino a slave for some time (multi-master setup) you won't ever get that reliable.

Hello thank you for the response

in fact i want to use multiple arduino and sensors
so there is no way to use arduino as a master and slave at same time?
what other method can i use

in fact i want to use multiple arduino and sensors

Why? A single Mega2560 has more inputs than multiple UNOs (just an example). There might be good reasons to use multiple Arduinos but in almost every case I can imagine, I2C would be the wrong way to interconnect them.

so there is no way to use arduino as a master and slave at same time?

There is but it will never be a reliable solution.

what other method can i use

Read answer #1, I already told you one.

Hi

it work with the usb solution thank you ..

,now i want to know if there is a solution to save data in my raspberry coming from the arduino

now i want to know if there is a solution to save data in my raspberry coming from the arduino

There are tons of. A Google search will show you thousands.