I am very new to Arduino. I wrote a program in order to read some registers in a I2C device. I receive HEX datas.
So the Arduino LEONARDO is connected to the external board using the 2-wires-bus. Then informations are sent to my computer by using Serial.println.
My problem is my Arduino stops working after a while, maybe 25 or 30 loops. Sometimes I loose communication and I have to reboot the Arduino.
I guess it's an overflow issue or I'm loosing connection randomly :
int dt = 500;
int dt2 = 1000; // used for delay duration
#include "Wire.h"
#include <Process.h>
#define pot_address 0x25 // each I2C object has a unique bus address, the MCP40
void setup() {
// put your setup code here, to run once:
Wire.begin();
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Wire.beginTransmission(pot_address);
Wire.write(0); //
Wire.endTransmission();
Wire.requestFrom(pot_address,8);
byte b = Wire.read();
Wire.beginTransmission(pot_address);
Wire.write(1); //
Wire.endTransmission();
Wire.requestFrom(pot_address,8);
byte c = Wire.read();
Wire.beginTransmission(pot_address);
Wire.write(2); //
Wire.endTransmission();
Wire.requestFrom(pot_address,8);
byte d = Wire.read();
Wire.beginTransmission(pot_address);
Wire.write(3); //
Wire.endTransmission();
Wire.requestFrom(pot_address,8);
byte e = Wire.read();
Wire.beginTransmission(pot_address);
Wire.write(4); //
Wire.endTransmission();
Wire.requestFrom(pot_address,8);
byte f = Wire.read();
Serial.print("b");
Serial.println(b, HEX);
Serial.println("-");
Serial.print("c");
Serial.println(c, HEX);
Serial.println("-");
Serial.print("d");
Serial.println(d, HEX);
Serial.println("-");
Serial.print("e");
Serial.println(e, HEX);
Serial.println("-");
Serial.print("f");
Serial.println(f, HEX);
Serial.println("-");
delay(dt2);
}
Wire.requestFrom()
), yet you read only one (one single call toWire.read()
). – Edgar Bonet Oct 14 '16 at 10:29