0

I have tried it several times myself but i never could send or receive it properly. I am asking myself if it is possible and if so could someone explain how?

Cheers.

asked Apr 17, 2019 at 19:06
1
  • It is possible. You gave to send both bytes of the float and put them back together correctly after it. Please include your code into the question, so that we can help you Commented Apr 17, 2019 at 19:18

1 Answer 1

1

Below is a simple rewrite of the Master Writer/Slave Receiver Wire Tutorial, https://www.arduino.cc/en/Tutorial/MasterWriter, for a vector of floating-point numbers.

Master Writer Sketch

#include <Wire.h>
const int DEVICE = 8;
void setup() {
 Wire.begin();
 Serial.begin(9600);
}
void loop() {
 const int VEC_MAX = 6;
 float vec[VEC_MAX];
 uint8_t* vp = (uint8_t*) vec;
 Wire.requestFrom(DEVICE, sizeof(vec));
 while (Wire.available()) {
 *vp++ = Wire.read();
 }
 for (int i = 0; i < VEC_MAX; i++) {
 Serial.println(vec[i]);
 }
 delay(500);
}

Slave Receiver Sketch

#include <Wire.h>
const int DEVICE = 8;
const int VEC_MAX = 6;
float vec[VEC_MAX] = { ... };
void setup() {
 Wire.begin(DEVICE);
 Wire.onRequest(requestEvent);
}
void loop() {
 delay(100);
}
void requestEvent() {
 Wire.write((uint8_t*) vec, sizeof(vec));
}

Is it possible to send a float Array over I2c

So I would answer - Yes.

answered Apr 17, 2019 at 21:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.