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

Can't move servo using raspberry pi adapter and servo driver #703

Closed
ezerw opened this issue Oct 26, 2019 · 3 comments
Closed

Can't move servo using raspberry pi adapter and servo driver #703

ezerw opened this issue Oct 26, 2019 · 3 comments

Comments

@ezerw
Copy link

ezerw commented Oct 26, 2019

Here is my code

package main

import (
	"log"
	"time"

	"gobot.io/x/gobot"
	"gobot.io/x/gobot/drivers/gpio"
	"gobot.io/x/gobot/platforms/raspi"
)

func main() {
	r := raspi.NewAdaptor()
	servo := gpio.NewServoDriver(r, "11")
	work := func() {
		gobot.Every(10*time.Second, func() {
			i := uint8(gobot.Rand(180))
			log.Printf("Moving servo to %d", i)
			servo.Move(i)
		})
	}
	robot := gobot.NewRobot(
		"servoBot",
		[]gobot.Connection{r},
		[]gobot.Device{servo},
		work,
	)

	robot.Start()
}

I've also have installed and running pi-blaster but still not able to move the servo. The program runs and I can see the logs but it seems that the signal is not being sent to the servo.

I tried using different pins and also following the indications on pi-blaster repo (You must use the GPIO number (BCM xx in the diagram below). but nothing works.

Any ideas how to debug or what's going on?

here the output of pi-blaster:

pi@raspberrypi:~/pi-blaster $ sudo ./pi-blaster
MBox Board Revision: 0xa020d3
DMA Channels Info: 0x7f35, using DMA Channel: 14
Using hardware:                   PWM
Number of channels:                32
PWM frequency:                 100 Hz
PWM steps:                       1000
Maximum period (100  %):      10000us
Minimum period (0.100%):         10us
DMA Base:                  0x3f007000
Initialised, Daemonized, Reading /dev/pi-blaster.
@erkexzcx
Copy link

erkexzcx commented Dec 8, 2019

#692

It's broken - this framework is useless for me. Instead I am using below code for my automation:

package main

import (
        "fmt"
        "log"
        "net/http"
        "time"

        piblaster "github.com/ddrager/go-pi-blaster"
)

const pin = 18 // GPIO18
var blaster = piblaster.Blaster{}

func main() {

        // Initialize blaster
        blaster.Start([]int64{pin})

        // Do a servo routine
        for i := 0; i < 7; i++ {
                setAngle(142)
                time.Sleep(600 * time.Millisecond)
                setAngle(129)
                time.Sleep(120 * time.Millisecond)
        }
        setAngle(48)

}

// Move servo to requested angle
func setAngle(angle uint8) {
        blaster.Apply(pin, angleToServo(angle))
}

// helper function - converts angle to servo value (aka 'map' function)
func angleToServo(val uint8) float64 {
        return (float64(val)-0)*(0.25-0.05)/(180-0) + 0.05
}


@gen2thomas
Copy link
Collaborator

I'm going to close this issue as a duplicate, because it is now referenced by an issue which collect all the various problems with raspi and gpio.servo.

@gen2thomas
Copy link
Collaborator

PWM frequency: 100 Hz

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

No branches or pull requests

3 participants