element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
In the Air Design Challenge
  • Challenges & Projects
  • Design Challenges
  • In the Air Design Challenge
  • More
  • Cancel
In the Air Design Challenge
Blog AirMobile - 27 - Driving a servo on BBB (2)
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: amgalbu
  • Date Created: 15 Feb 2015 10:43 AM Date Created
  • Views 374 views
  • Likes 1 like
  • Comments 0 comments
  • iot_distributed
  • openhab
  • pwm
  • in_the_air
  • servo
  • bbb
Related
Recommended

AirMobile - 27 - Driving a servo on BBB (2)

amgalbu
amgalbu
15 Feb 2015

After setting up the PWM outputs on BeagleBoneBlack, I created a binding for OpenHAB. In this way, I can create items and widgets that controls servos and are fully integrated into the OpenHAB UI.

What I basically did was to make some changes in the existing GPIO binding to accomodate some new configuration keywords.

The original GPIO binding accepts the following configuration settings


gpio="pin:PIN_NUMBER [debounce:DEBOUNCE_INTERVAL] [activelow:yes|no]"

 

After the changes, the binding accepts the following

 

gpio="pin:PIN_NUMBER [debounce:DEBOUNCE_INTERVAL] [activelow:yes|no] [name:PIN_NAME] pwm:[PWM period]"

 

The name is the name of the pin configured for PWM as I talked about in my previous post. When either a name is supplied, the output is assumed to be a PWM output

The pwm parameter allows user to set PWM period in microseconds. By default, this parameter is set to 20000 us, that is to say 20 ms which is the typical PWM period for controlling a servo

For example, on my BBB I set

 

gpio="pin:13 name:pwm_test_P8_13.11"

 

I also made some changes to the library

  • org.openhab.io.gpio

I added some new function overrides to accept an integer parameter that represent the duty cycle to set. Both the PWM and duty cycle are set by writing the values to the corresponding files. For example, to set the PWM the following code is executed


Files.write(runPath, "0".getBytes());
Files.write(periodPath, Long.valueOf(this.pwmPeriod).toString().getBytes());
Files.write(runPath, "1".getBytes());

 

In the same way, to set duty cycle the following code is executed

 

Files.write(runPath, "0".getBytes());
Files.write(dutyPath, value.toString().getBytes());
Files.write(runPath, "1".getBytes());

 

Note that both PWM and duty cycle values are passed to the class functions expressed in microseconds and hence they are multiplied by 1000 before being written.

runPath, dutyPath and periodPath are respectively set to


/sys/devices/ocp.3/<pin name>/run
/sys/devices/ocp.3/<pin name>/duty

/sys/devices/ocp.3/<pin name>/period

 

I finally created a test configuration with a single item

 

Number Home_Servo "Servo [%.0f]" {gpio="pin:13 name:pwm_test_P8_13.11"}

 

and a page with two controls: a setpoint to change the PWM duty cycle and a Text to provide feedback about the current PWM duty cycle

 

sitemap demo label="Main Menu"
{
                Frame label="Home"{
    Setpoint item=Home_Servo label="PWM" minValue=1500 maxValue=2500 step=100
    Text item=Home_Servo
  }
}

Attachments:
GPIO Binding.zip
  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube