servo

package module
v0.0.0-...-1130691 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2023 License: MIT Imports: 4 Imported by: 0

README

go-servo-picobber

A golang port of the python driver for Geekroo's PWM Servo PiCobber.

The PWM Servo Driver PiCobber Raspberry Pi HAT has the ability to drive up to 16 servos or PWM outputs with over 12C with only 2 pins. The PWM controller on-board drives all the 16 channels and it does not require any additional Raspberry Pi processing overhead.

Install the driver

go get github.com/3rubasa/go-servo-picobber

Example

package main

import (
    "log"
    "time"

    "github.com/3rubasa/go-servo-picobber"
)

func main() {
    servoMin := 150 // Min pulse length out of 4096
    servoMax := 600 // Max pulse length out of 4096

    sv, err := servo.NewServo()
    if err != nil {
        log.Println(err)
    }
    sv.SetPwmFreq(50) // Set frequency to 60 Hz
    for {
        // Change speed of continuous servo on channel O
        sv.SetPwm(0, 0, servoMin)
        time.Sleep(1 * time.Second)
        sv.SetPwm(0, 0, servoMax)
        time.Sleep(1 * time.Second)
    }
}

Documentation

Index

Constants

View Source
const (
	I2C_BUS  byte = 1
	I2C_ADDR byte = 0x40

	SUBADR1      byte = 0x02
	SUBADR2      byte = 0x03
	SUBADR3      byte = 0x04
	MODE1        byte = 0x00
	PRESCALE     byte = 0xFE
	LED0_ON_L    byte = 0x06
	LED0_ON_H    byte = 0x07
	LED0_OFF_L   byte = 0x08
	LED0_OFF_H   byte = 0x09
	ALLLED_ON_L  byte = 0xFA
	ALLLED_ON_H  byte = 0xFB
	ALLLED_OFF_L byte = 0xFC
	ALLLED_OFF_H byte = 0xFD
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Servo

type Servo struct {
	// contains filtered or unexported fields
}

func NewServo

func NewServo() (*Servo, error)

func (*Servo) SetPwm

func (sv *Servo) SetPwm(channel uint8, on, off int) error

Sets a single PWM channel

func (*Servo) SetPwmFreq

func (sv *Servo) SetPwmFreq(freq uint8) error

Sets the PWM frequency

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL