Main Site Documentation

Control servos with I2C and AdaFruit PCA9685

Hi all,

Has any of you ever tried to control a servo motor from a TinyClr board via a PCA9685 PWM board?
I’m trying without any success. I see 4 problems:

  • I’m a newbe
  • I2C
  • To my knowledge there’s no library for the PCA9685 (for TinyClr). I am trying to understand the datasheet.
  • I’m a newbe.
    The last problem may well be the biggest. I’m looking around on the internet and in this forum and there’s not much material to find about TinyClr to get some base knowledge. Am I missing a source?
    I can’t be the first to try this, can I?

Greetings from the Netherlands,

Egbert

The datasheet is not very friendly for a beginner but you are probably up for a challenge.

I would pay attention to what address is the board set at as they seem to have that as an option https://learn.adafruit.com/16-channel-pwm-servo-driver?view=all

Here is the good news! Adafruit driver is done well so you can quickly convert to C# https://github.com/adafruit/Adafruit-PWM-Servo-Driver-Library/blob/master/Adafruit_PWMServoDriver.cpp

All you need you modify is the write and read function. They are at the very bottom of the code. Noe how TinyCLR handles all I2C stages automatically so the multi-line code oyu see in these function will become a single TinyCLR line.

Here is our I2C tutorial http://docs.ghielectronics.com/software/tinyclr/tutorials/i2c.html

Hey Egbert,

I modified the Adafruit code to work with a FEZ. The information/documentation in the code is minimal. The code here [https://github.com/TwoSeven/I2CPWMDriverPCA9685] is documented quite well and is the same code as in the Adafruit driver class but was written for the Raspberry Pi running Windows.

Hope this helps.

4 Likes

Gus, William,

Thanks for your help.
Thanks to your examples I have discovered a big mistake I was making and learned a few things, like working with bits and bytes. It’s not working yet, but I think I’m close, certainly a lot closer than yesterday.

Regards,
Egbert

Hello Gus,

I have a further question regarding I2C in TinyClr and the tutorial.
Before sending data to a slave, the master has to send a start condition or start bits. Is this done automatically or do I have to code that? Same question for stop condition/bits.
Another question. To the 7 bit device address an 8th bit is added which indicates reading or writing. I’m reading a document which states that when one wants to write one sends address (f.i.) 0x40 and when one wants to read one sends 0x41. I guess in TinyClr this is done automatically. I think this implies that with every read or write the device address is sent. Fantasizing further I think it may be true that every device.write, device.writeread, etc. is a transaction of it’s own. Am I close?
Isn’t there any more documentation on I2C or TinyClr than the tutorials?

Thanks,
Egbert

Everything is done automatically. Just like the examples show.