# I2C drive a servo

**URL:** <https://forum.xod.io/t/i2c-drive-a-servo/1344>\
**Category:** Hardware Interfacing Questions\
**Created:** [November 10, 2018, 9:26pm UTC](https://forum.xod.io/t/i2c-drive-a-servo/1344 "2018-11-10T21:26:34Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![alanburdick](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@alanburdick](https://forum.xod.io/u/alanburdick)\
**Post date:** [November 10, 2018, 9:26pm UTC](https://forum.xod.io/t/i2c-drive-a-servo/1344/1 "2018-11-10T21:26:34Z")

</div>

Does anyone have an example of I2C patch driving a servo and reading a button

---

<div class="post-metadata">

**Author:** ![nkrkv](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/nkrkv/32/8_2.png) [@nkrkv](https://forum.xod.io/u/nkrkv)\
**Post date:** [November 12, 2018, 4:25pm UTC](https://forum.xod.io/t/i2c-drive-a-servo/1344/2 "2018-11-12T16:25:16Z")

</div>

Hello!

What hardware do you use? Casual buttons and servos don’t use I2C, so the particular model is important.

---

<div class="post-metadata">

**Author:** ![alanburdick](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@alanburdick](https://forum.xod.io/u/alanburdick)\
**Post date:** [November 12, 2018, 10:34pm UTC](https://forum.xod.io/t/i2c-drive-a-servo/1344/3 "2018-11-12T22:34:45Z")

</div>

Thanks for the quick reply. The hardware I am using is the PCA9685.

By the way the XOD software is fantastic.

Alan

---

<div class="post-metadata">

**Author:** ![nkrkv](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/nkrkv/32/8_2.png) [@nkrkv](https://forum.xod.io/u/nkrkv)\
**Post date:** [November 14, 2018, 4:21pm UTC](https://forum.xod.io/t/i2c-drive-a-servo/1344/4 "2018-11-14T16:21:09Z")

</div>

I see. That would be an interesting challenge. Unfortunately, I have no hardware based on PCA9585, so cannot provide any example. However, if someone will be close to success, feel free to ask for help.

---

<div class="post-metadata">

**Author:** ![bradzilla84](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/bradzilla84/32/659_2.png) [@bradzilla84](https://forum.xod.io/u/bradzilla84)\
**Post date:** [November 18, 2018, 4:22pm UTC](https://forum.xod.io/t/i2c-drive-a-servo/1344/5 "2018-11-18T16:22:13Z")

</div>

Hi alanburdick  
Just uploaded a simple wrapper for the Adafruit 16-channel PWM Servo driver  
I don’t have that servo board on me at the moment (i will grab one soon) if you could test and let me know if anything needs changing that would be great 😄

[bradzilla84/i2c-pwm-servo-16ch](https://xod.io/libs/bradzilla84/i2c-pwm-servo-16ch/)

---

<div class="post-metadata">

**Author:** ![alanburdick](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@alanburdick](https://forum.xod.io/u/alanburdick)\
**Post date:** [November 19, 2018, 12:49am UTC](https://forum.xod.io/t/i2c-drive-a-servo/1344/6 "2018-11-19T00:49:20Z")

</div>

Thanks, that is great. Now how do I upload the wrapper.

---

<div class="post-metadata">

**Author:** ![bradzilla84](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/bradzilla84/32/659_2.png) [@bradzilla84](https://forum.xod.io/u/bradzilla84)\
**Post date:** [November 19, 2018, 1:09am UTC](https://forum.xod.io/t/i2c-drive-a-servo/1344/7 "2018-11-19T01:09:57Z")

</div>

Just go File-\>Add Library on XOD and paste in “bradzilla84/i2c-pwm-servo-16ch” (Without the quotes) when the entry comes up just hit Enter and it will install it automatically.  
The first time you try to upload it if you don’t already have the adafruit library it will ask if you want it to download and install it for you.

---

<div class="post-metadata">

**Author:** ![alanburdick](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@alanburdick](https://forum.xod.io/u/alanburdick)\
**Post date:** [November 23, 2018, 11:02pm UTC](https://forum.xod.io/t/i2c-drive-a-servo/1344/8 "2018-11-23T23:02:39Z")

</div>

I am such a newbie. I cannot figure out how to assemble these nodes into a working program for 6 or more servo outputs.  
Again thanQ for your replies.  
Alan

---

<div class="post-metadata">

**Author:** ![bradzilla84](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/bradzilla84/32/659_2.png) [@bradzilla84](https://forum.xod.io/u/bradzilla84)\
**Post date:** [November 24, 2018, 1:23am UTC](https://forum.xod.io/t/i2c-drive-a-servo/1344/9 "2018-11-24T01:23:00Z")

</div>

Do you know the i2c Address or the control board you are using? Default is “0x40”

---

<div class="post-metadata">

**Author:** ![bradzilla84](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/bradzilla84/32/659_2.png) [@bradzilla84](https://forum.xod.io/u/bradzilla84)\
**Post date:** [November 24, 2018, 1:31am UTC](https://forum.xod.io/t/i2c-drive-a-servo/1344/10 "2018-11-24T01:31:07Z")

</div>

Hi Alan  
The block at the top of the example setups the link to the control board and the update frequency(Device Block).

The next block is for the servo itself each servo will be attached to a pin number on the control board just add one block for each servo you want and set its pin. Then connect the Device Block to each of the control blocks.

Then Connect the angle you want to the PWM Pin (i dont have one of these to test you may have to multiply the angle by 180 first to get the correct angle). I can fix in code later if necessary.

---

<div class="post-metadata">

**Author:** ![alanburdick](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@alanburdick](https://forum.xod.io/u/alanburdick)\
**Post date:** [November 26, 2018, 10:45pm UTC](https://forum.xod.io/t/i2c-drive-a-servo/1344/11 "2018-11-26T22:45:33Z")

</div>

I was over thinking it. i got the servos working. Now I am working on how to use buttons to control the various servos. I have never experienced such good feedback and help.  
Thank you again you are very helpful  
Alan

---

<div class="post-metadata">

**Author:** ![bradzilla84](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/bradzilla84/32/659_2.png) [@bradzilla84](https://forum.xod.io/u/bradzilla84)\
**Post date:** [November 27, 2018, 8:20am UTC](https://forum.xod.io/t/i2c-drive-a-servo/1344/12 "2018-11-27T08:20:50Z")

</div>

No problem 😊 check out the count block it may be useful for driving the servos.

---

<div class="post-metadata">

**Author:** ![carciofi](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/carciofi/32/1266_2.png) [@carciofi](https://forum.xod.io/u/carciofi)\
**Post date:** [May 17, 2019, 5:49am UTC](https://forum.xod.io/t/i2c-drive-a-servo/1344/13 "2019-05-17T05:49:14Z")

</div>

Is it possible to change the I2C address of the PCA9585 device node to run two or more of these boards? I need to run two remote clusters of servos.

---

<div class="post-metadata">

**Author:** ![cesars](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@cesars](https://forum.xod.io/u/cesars)\
**Post date:** [May 17, 2019, 10:03am UTC](https://forum.xod.io/t/i2c-drive-a-servo/1344/14 "2019-05-17T10:03:41Z")

</div>

You can use a “CLK” selector with a CD4066 and you can share the same address

but in the case of the PCA9685 (0x40-0x7F) if you can change it see the data sheet

```auto
# TECHNICAL DETAILS-
](https://www.adafruit.com/#technical-details)*Specifications:**

* Dimensions (no headers or terminal block) 2.5" x 1" x 0.1" (62.5mm x 25.4mm x 3mm)
* Weight (no headers or terminal block): 5.5grams
* Weight (with 3x4 headers & terminal block): 9grams
* This board/chip uses I2C 7-bit address between 0x40-0x7F, selectable with jumpers

```

---

<div class="post-metadata">

**Author:** ![carciofi](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/carciofi/32/1266_2.png) [@carciofi](https://forum.xod.io/u/carciofi)\
**Post date:** [May 17, 2019, 12:59pm UTC](https://forum.xod.io/t/i2c-drive-a-servo/1344/15 "2019-05-17T12:59:58Z")

</div>

Sorry I put the question wrong…

My question is how the address of the node object i2-servo-pwm-device can be set, so that i can use two boards in the same sketch. The address of the board itself is set by jumpers.

---

<div class="post-metadata">

**Author:** ![cesars](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@cesars](https://forum.xod.io/u/cesars)\
**Post date:** [May 17, 2019, 1:03pm UTC](https://forum.xod.io/t/i2c-drive-a-servo/1344/16 "2019-05-17T13:03:21Z")

</div>

![](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/2/2d5c10229152ca2a7e5970a3ae039689d0eccfc4.jpeg)

---

<div class="post-metadata">

**Author:** ![carciofi](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/carciofi/32/1266_2.png) [@carciofi](https://forum.xod.io/u/carciofi)\
**Post date:** [May 17, 2019, 1:06pm UTC](https://forum.xod.io/t/i2c-drive-a-servo/1344/17 "2019-05-17T13:06:14Z")

</div>

Thank you, I figured that out.

I’d like to change the adress of the XOD Object

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/c/ccb28555661f9bf6035d22ac11c5a6e13bec9873.png)

---

<div class="post-metadata">

**Author:** ![cesars](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@cesars](https://forum.xod.io/u/cesars)\
**Post date:** [May 17, 2019, 1:21pm UTC](https://forum.xod.io/t/i2c-drive-a-servo/1344/18 "2019-05-17T13:21:21Z")

</div>

> [@carciofi](#):
>
> I’d like to change the adress of the XOD Object

Well it is not implemented in the library, you should modify it, add a pin `ADDR` and modify this line

try that

```auto
Type pwm = new (state->mem) Adafruit_PWMServoDriver();
//to
Type pwm = new (state->mem) Adafruit_PWMServoDriver((int8_t)getValue<input_ADDR>(ctx));

```

---

<div class="post-metadata">

**Author:** ![carciofi](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/carciofi/32/1266_2.png) [@carciofi](https://forum.xod.io/u/carciofi)\
**Post date:** [May 17, 2019, 3:43pm UTC](https://forum.xod.io/t/i2c-drive-a-servo/1344/20 "2019-05-17T15:43:20Z")

</div>

Don’t get it to run. Tried to add ADDR as number or byte,  
changed the constructor to  
`Type pwm = new (state->mem) Adafruit_PWMServoDriver(0x41);`  
Anything but an empty pair brackets will not work and make the arduino’s LED flash.

According to adafruit’s tutorial the constructor should be  
`Adafruit_PWMServoDriver pwm2 = Adafruit_PWMServoDriver(0x41);`

---

<div class="post-metadata">

**Author:** ![cesars](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@cesars](https://forum.xod.io/u/cesars)\
**Post date:** [May 17, 2019, 3:56pm UTC](https://forum.xod.io/t/i2c-drive-a-servo/1344/21 "2019-05-17T15:56:07Z")

</div>

> [@carciofi](#):
>
> According to adafruit’s tutorial the constructor should be

in XOD is different  
the jumpers board, are at 41?

has placed two nodes devices with 40 and 41 respectively?

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/0/041c9b7533348be36947c3cc63f3b89b9659deb9.png)

[Next page](https://forum.xod.io/t/i2c-drive-a-servo/1344.md?page=2)
