Hi!
I'm trying to feed values from an arduino stored in a array to an ESP32 to help evaluate some unrelated code. The values I'm sending are in the form of an float, which I've already converted to ints by shifting the decimal point. This gives me a 5 digit whole number that I need to send over to the ESP32 over i2c.
i2c, as I've discovered can only handle values from 0 to 255, while I'm reaching up to about 40000. From reading other topics and forums I've seen that there are MANY ways to split up the data so that it can fit in the 8 bit packet, but since I'm not a very good programmer, I've been unsuccessful at any of the solutions I've come across yet. I'll add the send and recieve code below, and I appreciate any recomendations on how to make this work. Thanks!
Send
#include <Wire.h>
int send;
int x;
int data[36] = {
10625,10526,10526,10526,10526,10526,10527,10527,10527,10527,10527,10526,10527,10527,10526,10527,10526,10527,10527,10526,10527,10527,10526,10526,10526,10526,10526,10525,10525,10525,10525,10525,10525,
};
void setup() {
// Start the I2C Bus as Master
Serial.begin(115200);
Wire.begin();
}
void loop() {
Wire.beginTransmission(9); // transmit to device #9
Wire.write(send); // sends x
Wire.endTransmission(); // stop transmitting
Serial.println(send);
x++;
if (x > 36) {
x = 0;
}
send = data[x];
delay(100);
}
#include <Wire.h>
int x = 0;
void setup() {
Serial.begin(115200);
// Define the LED pin as Output
// Start the I2C Bus as Slave on address 9
Wire.begin(9);
// Attach a function to trigger when something is received.
Wire.onReceive(receiveEvent);
}
void receiveEvent(int bytes) {
x = Wire.read(); // read one character from the I2C
}
void loop() {
Serial.println(x);
delay(100);
}