I'm using an Arduino and Castle Serial Link chip to run a BLDC motor through an Castle Phoenix Edge 75 ESC. I'm using an I2C communication protocol to have Arduino extract the data (such as RPM) from the ESC/Serial Link. The problem is I keep getting a read value of 0 every time.
I know for sure the address of the slave (ESC) is correct. I quadruple checked it. There is definitely communication between the Arduino and Serial Link Chip/ESC by the nature of my code. I've attached the code that controls the motor and collects data here. Anyone have any idea why this is happening?
Here is the link to the Castle Serial Link and where it tells me the value of the register read:
http://www.castlecreations.com/support/documents/castle_serial_link_v1.3.pdf
//set up library
#include <Servo.h>
#include <Wire.h>
int motorSpeed = 0; // set inital speed to zero
Servo ESC;
void setup() {
ESC.attach(9); // attached to pin 9
Serial.begin(9600); // start serial at 9600 baud
Wire.begin();
}
void loop() {
ESC.writeMicroseconds(motorSpeed);
//I2C communication protocal
Wire.beginTransmission(0x08);
Wire.write(0x05);
Wire.requestFrom(0x08, 2);
while (Wire.available() == 0);
byte data1 = Wire.read();
byte data2 = Wire.read();
Wire.endTransmission();
byte val = ((data1 << 8) + data2);
//covert the data into RPM
float rpm = val / (2042 * 20416.66);
Serial.print("rpm: ");
Serial.println(rpm);
delay(100);
//ask user to input new speed for motor
//Enter value that range from 1050 to 1300
//values over 1300 will make the motor spin INCREDIBLY FAST. WATCH OUT!!!!
if (Serial.available())
motorSpeed = Serial.parseInt(); // Parse an Integer from Serial
Serial.print("motorSpeed: ");
Serial.println(motorSpeed);
}