Hi guys,
I'm using i2c to transfer 11520 numbers (maybe it is too large, but it's what I need) from Raspberry Pi to Arduino Nano 33 BLE.
I already sent and received data successfully but at a very slow speed.
I sent 11520 floats continuously; each float contains 8 or 9 bytes (float -> str -> bytes).
So the ideal transmission time should be 11520 * 9 / 100000 = 1.0368 second
.
But the actual time consumed is about 10 seconds.
Is my math wrong (i.e. it really should take this much time), or is there something wrong with my sketch?
Thanks a million for any idea.
#include <Wire.h>
#define INPUT_LEN 10
#define FEATURE_LEN 11520
// Globals, used for compatibility with Arduino-style sketches.
namespace
{
char X_test_byteArr[INPUT_LEN];
}
void setup()
{
Serial.begin(115200);
// Join I2C bus as slave with address 8
Wire.begin(0x8);
Wire.onReceive(receivefunc);
}
void loop()
{
delay(1);
}
void receivefunc(int num)
{
char recv_char;
for (size_t i = 0; i < num; i++)
{
recv_char = Wire.read(); // receive byte as a character
if (recv_char != '\n')
{
X_test_byteArr[i] = recv_char;
}
else
{
X_test_byteArr[i] = '\0';
Serial.println(X_test_byteArr);
}
}
}