raspi

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2022 License: Apache-2.0, Apache-2.0 Imports: 12 Imported by: 118

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

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.

You would normally install Go and Gobot on your workstation. Once installed, cross compile your program on your workstation, transfer the final executable to your Raspberry Pi, and run the program on the Raspberry Pi as documented here.

go get -d -u gobot.io/x/gobot/...

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"
        "gobot.io/x/gobot/drivers/gpio"
        "gobot.io/x/gobot/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 added in v1.0.0

type Adaptor struct {
	PiBlasterPeriod uint32
	// contains filtered or unexported fields
}

Adaptor is the Gobot Adaptor for the Raspberry Pi

func NewAdaptor added in v1.0.0

func NewAdaptor() *Adaptor

NewAdaptor creates a Raspi Adaptor

func (*Adaptor) Connect added in v1.0.0

func (r *Adaptor) Connect() (err error)

Connect starts connection with board and creates digitalPins and pwmPins adaptor maps

func (*Adaptor) DigitalPin added in v1.5.0

func (r *Adaptor) DigitalPin(pin string, dir string) (sysfsPin sysfs.DigitalPinner, err error)

DigitalPin returns matched digitalPin for specified values

func (*Adaptor) DigitalRead added in v1.0.0

func (r *Adaptor) DigitalRead(pin string) (val int, err error)

DigitalRead reads digital value from pin

func (*Adaptor) DigitalWrite added in v1.0.0

func (r *Adaptor) DigitalWrite(pin string, val byte) (err error)

DigitalWrite writes digital value to specified pin

func (*Adaptor) Finalize added in v1.0.0

func (r *Adaptor) Finalize() (err error)

Finalize closes connection to board and pins

func (*Adaptor) GetConnection added in v1.2.0

func (r *Adaptor) GetConnection(address int, bus int) (connection i2c.Connection, err error)

GetConnection returns an i2c connection to a device on a specified bus. Valid bus number is [0..1] which corresponds to /dev/i2c-0 through /dev/i2c-1.

func (*Adaptor) GetDefaultBus added in v1.2.0

func (r *Adaptor) GetDefaultBus() int

GetDefaultBus returns the default i2c bus for this platform

func (*Adaptor) GetSpiConnection added in v1.7.0

func (r *Adaptor) GetSpiConnection(busNum, chipNum, mode, bits int, maxSpeed int64) (connection spi.Connection, err error)

GetSpiConnection returns an spi connection to a device on a specified bus. Valid bus number is [0..1] which corresponds to /dev/spidev0.0 through /dev/spidev0.1.

func (*Adaptor) GetSpiDefaultBits added in v1.12.0

func (r *Adaptor) GetSpiDefaultBits() int

GetSpiDefaultBits returns the default spi number of bits for this platform.

func (*Adaptor) GetSpiDefaultBus added in v1.7.0

func (r *Adaptor) GetSpiDefaultBus() int

GetSpiDefaultBus returns the default spi bus for this platform.

func (*Adaptor) GetSpiDefaultChip added in v1.12.0

func (r *Adaptor) GetSpiDefaultChip() int

GetSpiDefaultChip returns the default spi chip for this platform.

func (*Adaptor) GetSpiDefaultMaxSpeed added in v1.7.0

func (r *Adaptor) GetSpiDefaultMaxSpeed() int64

GetSpiDefaultMaxSpeed returns the default spi bus for this platform.

func (*Adaptor) GetSpiDefaultMode added in v1.7.0

func (r *Adaptor) GetSpiDefaultMode() int

GetSpiDefaultMode returns the default spi mode for this platform.

func (*Adaptor) Name added in v1.0.0

func (r *Adaptor) Name() string

Name returns the Adaptor's name

func (*Adaptor) PWMPin added in v1.5.0

func (r *Adaptor) PWMPin(pin string) (raspiPWMPin sysfs.PWMPinner, err error)

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

func (*Adaptor) PwmWrite added in v1.0.0

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

PwmWrite writes a PWM signal to the specified pin

func (*Adaptor) ServoWrite added in v1.0.0

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

ServoWrite writes a servo signal to the specified pin

func (*Adaptor) SetName added in v1.0.0

func (r *Adaptor) SetName(n string)

SetName sets the Adaptor's name

type PWMPin added in v1.5.0

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

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

func NewPWMPin added in v1.5.0

func NewPWMPin(pin string) *PWMPin

NewPwmPin returns a new PWMPin

func (*PWMPin) DutyCycle added in v1.5.0

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

DutyCycle returns the duty cycle for the pin

func (*PWMPin) Enable added in v1.5.0

func (p *PWMPin) Enable(e bool) (err error)

Enable enables/disables the PWM pin

func (*PWMPin) Export added in v1.5.0

func (p *PWMPin) Export() error

Export exports the pin for use by the Raspberry Pi

func (*PWMPin) InvertPolarity added in v1.5.0

func (p *PWMPin) InvertPolarity(invert bool) (err error)

InvertPolarity does not do anything when using PiBlaster

func (*PWMPin) Period added in v1.5.0

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

Period returns the current PWM period for pin

func (*PWMPin) Polarity added in v1.5.0

func (p *PWMPin) Polarity() (polarity string, err error)

Polarity returns the polarity either normal or inverted

func (*PWMPin) SetDutyCycle added in v1.5.0

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

SetDutyCycle writes the duty cycle to the pin

func (*PWMPin) SetPeriod added in v1.5.0

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

SetPeriod uses PiBlaster setting and cannot be changed once set

func (*PWMPin) Unexport added in v1.5.0

func (p *PWMPin) Unexport() error

Unexport unexports the pin and 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