raspi

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: Apache-2.0, Apache-2.0 Imports: 10 Imported by: 9

README

Raspberry Pi

The Raspberry Pi is an inexpensive and popular ARM based single board computer with digital & PWM GPIO, and i2c interfaces built in.

The Gobot adaptor for the Raspberry Pi should support all of the various Raspberry Pi boards such as the Raspberry Pi 4 Model B, Raspberry Pi 3 Model B, Raspberry Pi 2 Model B, Raspberry Pi 1 Model A+, Raspberry Pi Zero, and Raspberry Pi Zero W.

For more info about the Raspberry Pi platform, click here.

How to Install

Please refer to the main README.md

We recommend updating to the latest Raspian Jessie OS when using the Raspberry Pi, however Gobot should also support older versions of the OS, should your application require this.

How to Use

The pin numbering used by your Gobot program should match the way your board is labeled right on the board itself.

package main

import (
"time"

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

func main() {
  r := raspi.NewAdaptor()
  led := gpio.NewLedDriver(r, "7")

  work := func() {
    gobot.Every(1*time.Second, func() {
      led.Toggle()
    })
  }

  robot := gobot.NewRobot("blinkBot",
    []gobot.Connection{r},
    []gobot.Device{led},
    work,
  )

  robot.Start()
}

How to Connect

Compiling

Compile your Gobot program on your workstation like this:

GOARM=6 GOARCH=arm GOOS=linux go build examples/raspi_blink.go

Use the following GOARM values to compile depending on which model Raspberry Pi you are using:

GOARM=6 (Raspberry Pi A, A+, B, B+, Zero) GOARM=7 (Raspberry Pi 2, 3)

Once you have compiled your code, you can upload your program and execute it on the Raspberry Pi from your workstation using the scp and ssh commands like this:

scp raspi_blink pi@192.168.1.xxx:/home/pi/
ssh -t pi@192.168.1.xxx "./raspi_blink"
Enabling PWM output on GPIO pins

For extended PWM support on the Raspberry Pi, you will need to use a program called pi-blaster. You can follow the instructions for pi-blaster install in the pi-blaster repo here:

https://github.com/sarfata/pi-blaster

Documentation

Overview

Package raspi contains the Gobot adaptor for the Raspberry Pi.

For further information refer to raspi README: https://github.com/hybridgroup/gobot/blob/master/platforms/raspi/README.md

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adaptor

type Adaptor struct {
	*adaptors.DigitalPinsAdaptor
	*adaptors.I2cBusAdaptor
	*adaptors.SpiBusAdaptor
	PiBlasterPeriod uint32
	// contains filtered or unexported fields
}

Adaptor is the Gobot Adaptor for the Raspberry Pi

func NewAdaptor

func NewAdaptor(opts ...func(adaptors.Optioner)) *Adaptor

NewAdaptor creates a Raspi Adaptor

Optional parameters:

		adaptors.WithGpiodAccess():	use character device gpiod driver instead of sysfs (still used by default)
		adaptors.WithSpiGpioAccess(sclk, nss, mosi, miso):	use GPIO's instead of /dev/spidev#.#
   adaptors.WithGpiosActiveLow(pin's): invert the pin behavior
   adaptors.WithGpiosPullUp/Down(pin's): sets the internal pull resistor
   adaptors.WithGpiosOpenDrain/Source(pin's): sets the output behavior
   adaptors.WithGpioDebounce(pin, period): sets the input debouncer
   adaptors.WithGpioEventOnFallingEdge/RaisingEdge/BothEdges(pin, handler): activate edge detection

func (*Adaptor) Connect

func (c *Adaptor) Connect() error

Connect create new connection to board and pins.

func (*Adaptor) DefaultI2cBus

func (c *Adaptor) DefaultI2cBus() int

DefaultI2cBus returns the default i2c bus for this platform. This overrides the base function due to the revision dependency.

func (*Adaptor) Finalize

func (c *Adaptor) Finalize() error

Finalize closes connection to board and pins

func (*Adaptor) Name

func (c *Adaptor) Name() string

Name returns the Adaptor's name

func (*Adaptor) PWMPin

func (c *Adaptor) PWMPin(id string) (gobot.PWMPinner, error)

PWMPin returns a raspi.PWMPin which provides the gobot.PWMPinner interface

func (*Adaptor) PwmWrite

func (c *Adaptor) PwmWrite(pin string, val byte) (err error)

PwmWrite writes a PWM signal to the specified pin

func (*Adaptor) ServoWrite

func (c *Adaptor) ServoWrite(pin string, angle byte) (err error)

ServoWrite writes a servo signal to the specified pin

func (*Adaptor) SetName

func (c *Adaptor) SetName(n string)

SetName sets the Adaptor's name

type PWMPin

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

PWMPin is the Raspberry Pi implementation of the PWMPinner interface. It uses Pi Blaster.

func NewPWMPin

func NewPWMPin(sys *system.Accesser, path string, pin string) *PWMPin

NewPWMPin returns a new PWMPin

func (*PWMPin) DutyCycle

func (p *PWMPin) DutyCycle() (uint32, error)

DutyCycle returns the duty cycle for the pin

func (*PWMPin) Enabled

func (p *PWMPin) Enabled() (bool, error)

Enabled returns always true for "enabled"

func (*PWMPin) Export

func (p *PWMPin) Export() error

Export exports the pin for use by the Raspberry Pi

func (*PWMPin) Period

func (p *PWMPin) Period() (uint32, error)

Period returns the cached PWM period for pin

func (*PWMPin) Polarity

func (p *PWMPin) Polarity() (bool, error)

Polarity returns always true for "normal"

func (*PWMPin) SetDutyCycle

func (p *PWMPin) SetDutyCycle(duty uint32) error

SetDutyCycle writes the duty cycle to the pin

func (*PWMPin) SetEnabled

func (p *PWMPin) SetEnabled(e bool) error

SetEnabled do nothing for PiBlaster

func (*PWMPin) SetPeriod

func (p *PWMPin) SetPeriod(period uint32) error

SetPeriod uses PiBlaster setting and cannot be changed once set

func (*PWMPin) SetPolarity

func (p *PWMPin) SetPolarity(bool) (err error)

SetPolarity does not do anything when using PiBlaster

func (*PWMPin) Unexport

func (p *PWMPin) Unexport() error

Unexport releases the pin from the operating system

Jump to

Keyboard shortcuts

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