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 Overview | Adafruit PCA9685 16-Channel Servo Driver | Adafruit Learning System

Here is the good news! Adafruit driver is done well so you can quickly convert to C# Adafruit-PWM-Servo-Driver-Library/Adafruit_PWMServoDriver.cpp at master · adafruit/Adafruit-PWM-Servo-Driver-Library · GitHub

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 I2C

Hey Egbert,

I modified the Adafruit code to work with a FEZ. The information/documentation in the code is minimal. The code here [GitHub - TwoSeven/I2CPWMDriverPCA9685: A C# class and example code for Windows 10 IoT Core or Windows Universal Apps to provide interaction with the NXP PCA9685 integrated circuit or expansion modules that use it such as the Adafruit 16-Channel 12-bit PWM/Servo Driver PCA9685 module.] 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.