Go Down

Topic: Trouble Obtaining Data From ESC/Motor (Read 913 times) previous topic - next topic

kuan3

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   

Code: [Select]
//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);
}

MarkT

I2C needs pullups - do you have any?
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

kuan3

The pull-up resistor should be built into the arduino board.

CrossRoads

Pullup resistors are not built into the Arduino board. You need to add 4.7K pullups to VCC yourself,  or on you I2C module.
The Mega has 10K pullups built in, they are often too large a value tho. 4.7K with 5V works much better.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up