View unanswered posts | View active topics It is currently Sun Apr 20, 2014 5:04 am






Reply to topic  [ 2 posts ] 
Driver for NXP PCA9685 LED/PWM (Servo) controller 
Author Message
Rookie

Joined: Thu Sep 20, 2012 2:13 pm
Posts: 1
Post Driver for NXP PCA9685 LED/PWM (Servo) controller
Thank you for your work on this.

(I accidentally posted this question to the topic "RELEASED: 3RD PARTY ROBOTC DRIVER SUITE V2.7" so please ignore it there.)

I am struggling to write a Mindstorms NXT driver for the NXP PCA9685 LED/PWM (Servo) controller I2C chip. I am using the Adafruit Server Controller module.

Adafruit provides a driver in c for Arduino processors to control this board, so I am using that to help understand how to write one for NXT.

The main thing I need to figure out is, how do the RobotC I2C calls compare with the wire.h calls?

In wire.h these calls are used to write to the PCA9685:

Wire.beginTransmission(_i2caddr);
Wire.write(addr);
Wire.write(d);
Wire.endTransmission();

where:
_i2caddr = the bus address of the PCA9685
addr = Specifies what address within the PCA9685 to write the next value to
d = the value to write to the address given by addr.

To set the position of a servo, you would do the above steps 4 times to set the on, off, high and low bytes.

In Robotc, would this be a way to accomplish basically the same thing? Note that the array passed to writetoI2C() has 3 values in it. Does each value in the array get sent sequentially?

bool PCA9685sendBytes(tSensors link, ubyte _byte)
{
memset(PCA9685_I2CRequest, 0, sizeof(tByteArray));

PCA9685_I2CRequest[0] = 3; // Message size
PCA9685_I2CRequest[1] = _i2caddr; // I2C Address
PCA9685_I2CRequest[2] = _addr; // PCA9685 control-register address
PCA9685_I2CRequest[3] = _byte;

return writeI2C(link, PCA9685_I2CRequest, 0);
}

Thanks again!


Thu Sep 20, 2012 6:26 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3107
Location: Rotterdam, The Netherlands
Post Re: Driver for NXP PCA9685 LED/PWM (Servo) controller
Hi kahnfu,

kahnfu wrote:
[color=#4040BF](I accidentally posted this question to the topic "RELEASED: 3RD PARTY ROBOTC DRIVER SUITE V2.7" so please ignore it there.)

It's fine, I deleted it and split this one off from the other thread.

Quote:
The main thing I need to figure out is, how do the RobotC I2C calls compare with the wire.h calls?

Other than being able to do I2C, not a whole lot. The names are very different and you don't have to deal with the stop and start conditions yourself. The firmware takes care of that stuff for you.

Quote:
In Robotc, would this be a way to accomplish basically the same thing? Note that the array passed to writetoI2C() has 3 values in it. Does each value in the array get sent sequentially?

Yeah, almost. The first byte is the actual size of the transmission, 3 bytes in this case (address, register and value to be sent to register).

Code:
bool PCA9685sendBytes(tSensors link, ubyte _byte)
{
  memset(PCA9685_I2CRequest, 0, sizeof(tByteArray));

  PCA9685_I2CRequest[0] = 3; // Message size
  PCA9685_I2CRequest[1] = _i2caddr; // I2C Address
  PCA9685_I2CRequest[2] = _addr; // PCA9685 control-register address
  PCA9685_I2CRequest[3] = _byte;

  return writeI2C(link, PCA9685_I2CRequest, 0);
}

This code looks fine to me. Please note that for the 3.0 beta 1 driver suite, I've changed some of the internal I2C functions, but it would be super easy to modify, you'll see.

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Sat Sep 22, 2012 1:05 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.