I am trying to communicate with AD5933 PmodIA sensor via i2c using Arduino nano BLE 33 boards (I have both sense board and non-Sense board). I am not able to send data to the sensor via I2C. I went through the tutorial: https://docs.arduino.cc/tutorials/nano-33-ble-sense/I2C to see if my I2C communication works. Here I figured out I can't send data via I2C to turn on and off LEDs but I can use them to receive data, when I used them along with an UNO board. So they can act as reader but not as writer. When I try to use them as writer the serial monitor gets stuck after I try to send the data first time. Same thing happens when I try to communicate with my PmodIA. The serial monitor gets stuck once I try to send something via I2c and the data is also not being sent. Can anyone help me? Previously I thought the issue was with AD5933 library but now I'm sure it is not that. Does anyone know what to do here?
void setup() {
Serial.begin(9600);
while (!Serial);
Wire1.begin(); // join i2c bus (address optional for writer)
}
void loop() {
Serial.print("Enter 0 to turn off led, enter 1 to turn it on ");
char ledVal[0];
readSerial(ledVal);
Serial.println(ledVal);
Wire1.beginTransmission(8); // transmit to device #8
Wire1.write(ledVal); // sends the given value
Wire1.endTransmission(); // stop transmitting
delay(500);
}
/* Read input serial */
int readSerial(char result[ ]) {
int i = 0;
while (1) {
while (Serial.available() > 0) {
char inChar = Serial.read();
if (inChar == '\n') {
result[i] = '\0';
Serial.flush();
return 0;
}
if (inChar != '\r') {
result[i] = inChar;
i++;
}
}
}
}
This works when used on UNO
Wire1 was with some changes but this is the original code I found from the tutorial I mentioned. Yeah I think that is declaring an empty array that will be used when user enters 0 or 1 and will be sent to the reader. The code works fine when used with UNO. Only Nano Board cannot be used as Writer.