Git Product home page Git Product logo

go-pwm-example's Introduction

Overview

Example golang application that makes use of the hardware PWM channels.

Written as an example for the Onion Omega2 but this would serve as a good example for a number of compute modules that have PWM hardware exposed to Linux.

Dependencies

gobot.io's sysfs module is used to provide access to the pwm hardware

How to build

The project has been updated to take advantage of go's new module support. This makes it easy to build.

<go to where you'd like to place the 'go-pwm-example' directory>
git clone https://github.com/chmorgan/go-pwm-example.git
cd go-pwm-example
go build

Build for the Omega2

golang has support for a number of architectures built in, this makes it well suited for cross platform development.

The Omega2 uses a MediaTek MT7688 SoC. This processor is a mips architecture and little endian is being used. Therefore the architecture is 'mips' + 'le', or 'mipsle'.

GOOS=linux GOARCH=mipsle go build

You should now have a 'go-pwm-example' application in the current directory.

Copy to your Omega2

Replace 'xxxx' with the address of your Omega.

scp go-pwm-example [email protected]:/root/

How to run

Pin mux configuration

Note: Pin muxing must be set appropriately for the pwm channel being used.

For example:

# omega2-ctrl gpiomux get
Group i2c - [i2c] gpio
Group uart0 - [uart] gpio
Group uart1 - [uart] gpio pwm01
Group uart2 - [uart] gpio pwm23
Group pwm0 - pwm [gpio]
Group pwm1 - pwm [gpio]
Group refclk - refclk [gpio]
Group spi_s - spi_s [gpio] pwm01_uart2
Group spi_cs1 - [spi_cs1] gpio refclk
Group i2s - i2s [gpio] pcm
Group ephy - [ephy] gpio
Group wled - wled [gpio]

Assuming we are using pwm channel 0 (GPIO18) you'll reconfigure this pin for pwm mode via:

# omega2-ctrl gpiomux set pwm0 pwm
set gpiomux pwm0 -> pwm

Running

./go-pwm-example

And to get command line help you can pass the '-help' option:

# ./go-pwm-example -help
Usage of ./go-pwm-example:
  -channel int
    	PWM channel (0, 1, 2, or 3)
  -frequency float
    	Frequency in Hz (default 100)

go-pwm-example's People

Contributors

chmorgan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.