Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix BBB servo cape overlay #174

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

lorforlinux
Copy link

@RobertCNelson I have tested this overlay now and these changes are to be made in the DT file to make it work.

@lorforlinux
Copy link
Author

The DT overlay only creates pca9685-pwm/2-0070/pwm/pwmchip9/[pwm9:0 & pwm9:1] when it loads, do you know how to enable all 16 at the same time?

this file linux/Documentation/devicetree/bindings/pwm/nxp,pca9685-pwm.txt says The index 16 is the ALL CALL channel, that sets all PWM channels at the same time. but what index is that?

@silver2row
Copy link

Hello,

@lorforlinux , How can I use this overlay w/ the ServoCape?

Seth

@lorforlinux
Copy link
Author

Hi,
you can follow these steps to get this overlay loaded onto your BeagleBone Black when you plug in the cape.

  1. $ su
  2. # cd /opt/sources/bb.org-overlay/
  3. # vi src/arm/BBORG_SERVO-00A2.dts
  4. Paste in the content of this file.
  5. # make src/arm/BBORG_SERVO-00A2.dtbo
  6. # cp src/arm/BBORG_SERVO-00A2.dtbo /lib/firmware/
  7. # reboot

Note: $ -> normal user command, # -> superuser command. Also, plug in your cape before rebooting your board to load the overlay automatically during boot.

Copy link
Member

@jadonk jadonk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see a few more comments to clarify what is going on here and what the input pins are used for and how they should be set.

BONE_P9_27 (PIN_OUTPUT_PULLDOWN | MUX_MODE7) /* P9_27: gpio3_19 */
BONE_P9_41 (PIN_OUTPUT_PULLDOWN | MUX_MODE7) /* P9_41: gpio3_20 */
BONE_P9_42 (PIN_OUTPUT_PULLDOWN | MUX_MODE7) /* P9_42: gpio0_7 */
BONE_P8_12 (PIN_INPUT_PULLDOWN | MUX_MODE7) /* P8_12: gpio1_12 */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these pins for? I thought they were to configure the device. Shouldn't they be set to output GPIOs from the board and then set to properly configure the device?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are the RC input pins.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But what do they do? I know I should know, but it really isn't clear to me. At first, I thought these were PWM inputs, but looking at the datasheet it seems these are just configuration pins.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They take input signal from a remote control, you shared a link on the group which shows different types of signals we may encounter from the receiver https://oscarliang.com/pwm-ppm-sbus-dsm2-dsmx-sumd-difference/. I asked others on the group and we agreed to have GPIO inputs here.

I think the main purpose is to take input from those RC receivers and control servos on a drone, car, plane, etc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a flat-out misinterpretation and bad guess. Please check the datasheet https://www.nxp.com/docs/en/data-sheet/PCA9685.pdf.

>;
};


bborg_servo_pca9685_i2c_pins: bborg_servo_pca9685_i2c_pins {
bborg_servo_pca9685_i2c_pins: pinmux_bborg_servo_pca9685_i2c_pins {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this bus need to be reconfigured? Cant the default configuration be used?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can use the default I2C bus configuration. But, this will make sure the person using the cape sees the pins attached to the cape when he/she uses show-pins utility. There may be other benefits also :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess, but note that some of these capes are stackable. I2C2 is a shared resource for all capes and only a handful need to reconfigure those pins to be anything but the default I2C function.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are absolutely right, I forgot to take that into account.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you updated? I think you can add new commits to your pull request, even if it has been merged.

pca: pca@70 {
compatible = "nxp,pca9685-pwm";
#pwm-cells = <16>;
reg = <0x70>;
lable = "pca9685_servo";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the correct spelling for 'lable'?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, it should be label 😂

lable = "pca9685_servo";
pinctrl-names = "default";
pinctrl-0 = <&bborg_servo_pca9685_en_pins>;
enable-gpios = <&gpio2 4 GPIO_ACTIVE_HIGH>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there or is there not an enable gpio? I'd think you'd need that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is but we handle it separately not, I tried using it this way but I was not able to make it work out.

};
};

&{/} {
gpio_inputs {
compatible = "gpio-keys";
leds {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this called leds?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was a different person back then, didn't knew as much as I know now. I will update this accordingly 👍

@@ -35,27 +35,27 @@

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some comments above about the overall function and resources. I think I know now, but a summary in the comments would be nice.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing 👍

gpios = <&gpio0 7 GPIO_ACTIVE_HIGH>;
compatible = "gpio-leds";

pca9685-enable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just an enable GPIO, right? There's no real LED, is there? Would be good to clarify in the comments.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no there is not really any led on the cape, this pin control the PCA9685's enable pin.

@silver2row
Copy link

silver2row commented Jun 21, 2020

Hello,

Thank you. I will test it. Once the overlay is loaded onto the board, my BBBW, do I need to have already composed source or can I use this overlay as a base?

Seth

P.S. As you can tell, I am a bit new still. So, any help would be greatly appreciated. If not, that is okay too.

@lorforlinux
Copy link
Author

@silver2row can you please explain a bit more what do you mean by this

composed source or can I use this overlay as a base?

@silver2row
Copy link

@lorforlinux ,

Yes sir...here is some background. When I first joined to learn about bbb.io, the boards, linux, and relative info, I was caught in b/t 2015. 2015 was a year of change. Books were ending for the BBB.io peoples and uboot was being introduced. So, the overlay scheme was changing.

...

W/ the Cape attached, would I use the GPIO pins or PWM pins or i2c communication for use w/ this specific Cape? Somewhere along the lines, I purchased this Cape and I have not been able to use it just yet. If this is not your job and it is too much work on your end, that is okay. I understand. So, I guess I am trying to figure out if the Cape's overlay, the one you made, has me use GPIO, i2c, or PWM for making the servos move.

Seth

P.S. Sorry for the long explanation.

@lorforlinux
Copy link
Author

lorforlinux commented Jun 21, 2020

@silver2row No problemo :) After following the above steps see if the cape is successfully loaded, you can check that by going to /proc/device-tree/chosen/overlays.

Now you go to this directory
/sys/bus/i2c/drivers/pca9685-pwm/2-0070/pwm/pwmchip* (it was pwmchip9 for me)
there you'll find `pwm*:0/ and pwm*:1/' these are for servo 1 and servo 2. cd to one of them and attach your servo to that output on the cape.

After doing that you have to set period and duty cycle for that PWM pin

$ echo 10000000 > period
$ echo 1000000 > duty_cycle

now enable the output by running this

$ echo 1 > enable

You'll see the servo moving, try changing the duty cycle now by running

$ echo 2000000 > duty_cycle

You can check out this library for easier use https://github.com/adafruit/Adafruit_Python_PCA9685/
the address of PCA9685 is 0x70 attached to I2C2 just in case If you ever need to put them somewhere while testing that library :)

This might also be helpful for you http://www.civrays.com/beaglebone/tutorials/pca9685

@silver2row
Copy link

Hello Sir,

Thank you. I will test this later today.

Seth

P.S. I will check the address and look for the files in my system. I will check that last link, too! Thank you, again!

@jadonk
Copy link
Member

jadonk commented Jun 22, 2020

Should we add symlinks for these capes to make interfaces easier to find for users?

@silver2row
Copy link

Hello,

Order one: I think there is something faulty going on. No offense. It is most likely on my side.

...

I followed the instructions, rebooted, and then found my make .dtbo file in /proc/device-tree/chosen/overlays/ but I have three files in /sys/bus/i2c/drivers/pca9685-pwm/ which are:

bind
uevent
unbind

Seth

@lorforlinux
Copy link
Author

@jadonk Yes we should use symlinks, I will try it out today :)

@lorforlinux
Copy link
Author

@silver2row I will update the overlay ASAP to make it easier for you and other future users to follow :)

@silver2row
Copy link

silver2row commented Jun 22, 2020

@lorforlinux ,

Okay. Thank you. I tried to use your instructions on how to use it. I failed somehow. Anyway, I will keep an eye out. Oh and I always thought we just put the .dtbo file in /boot/uEnv.txt and reboot. Is this still true?

Seth

@lorforlinux
Copy link
Author

lorforlinux commented Jun 23, 2020

@silver2row Did you applied power through the terminal block where this is specified -> 5v IN Max?

@silver2row
Copy link

silver2row commented Jun 23, 2020

Hello...yes. @lorforlinux I am using the sys_5v power supply from the BBBW to the 5v IN MAX portion on the ServoCape.

When I boot the board w/ the Cape attached, the servo indeed moves but not by my command in /sys/bus/i2c/drivers/pca9685-pwm/2-0070/pwm/pwmchip*.

That file location does not exist on my board for some reason.

I think 2-0070 on my board is located at another location: /sys/class/pwm/.

Oh! I forgot to mention something...

The 5v IN MAX terminal is loose. It came this way. I guess I can move it off the board.

I can then solder on some wiring to help out on this dilemma. 

Just to reiterate, the servo shows signs of moving, does move, when I power on the board w/ the Cape attached and the standard servo in S1.

@lorforlinux
Copy link
Author

@jadonk This overlay is final as it gets, for now! I will make /bone/bus changes after I test the buses through virtual capes.

Should we add symlinks for these capes to make interfaces easier to find for users?

There will be /bone/i2c/2 device after using symlink but the thing is we are using pwm-pca9685 driver from the kernel and as long as we keep doing that we can not use another user-space example to access the pca9685 device which is at 0x70 address of /bone/i2c/2. So, if want to use it through /bone/i2c/2 we can not use the kernel driver and if we are using kernel driver we have at least these two paths to access the device,

  1. /sys/class/i2c-adapter/i2c-2/2-0070/pwm/pwmchip*/
  2. /sys/bus/i2c/drivers/pca9685-pwm/2-0070/pwm/pwmchip*/

I have written a blog post to test the servo cape on a BBB, which will help users to test the cape easily.

If you are happy with the work done here please merge the changes :)

@silver2row
Copy link

Hello @lorforlinux ,

Thank you, sir. I tested it and it works for me. I cannot thank you enough.

Seth

@lorforlinux lorforlinux requested a review from jadonk June 26, 2020 23:01
This overlay is using the new compatibility code from beagleboard/BeagleBoard-DeviceTrees#17
@lorforlinux
Copy link
Author

The overlay has been updated to work on both BBB and BBAI. It requires the compatibility code from beagleboard/BeagleBoard-DeviceTrees#17 to work correctly.

Copy link
Member

@jadonk jadonk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not seeing updates or resolution. Is there somewhere else I should be looking?

BONE_P9_27 (PIN_OUTPUT_PULLDOWN | MUX_MODE7) /* P9_27: gpio3_19 */
BONE_P9_41 (PIN_OUTPUT_PULLDOWN | MUX_MODE7) /* P9_41: gpio3_20 */
BONE_P9_42 (PIN_OUTPUT_PULLDOWN | MUX_MODE7) /* P9_42: gpio0_7 */
BONE_P8_12 (PIN_INPUT_PULLDOWN | MUX_MODE7) /* P8_12: gpio1_12 */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a flat-out misinterpretation and bad guess. Please check the datasheet https://www.nxp.com/docs/en/data-sheet/PCA9685.pdf.

>;
};


bborg_servo_pca9685_i2c_pins: bborg_servo_pca9685_i2c_pins {
bborg_servo_pca9685_i2c_pins: pinmux_bborg_servo_pca9685_i2c_pins {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you updated? I think you can add new commits to your pull request, even if it has been merged.

@lorforlinux
Copy link
Author

please see the most recent commit -> 64606c5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants