gopi-tools

module
v0.0.0-...-eb28b5e Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2019 License: MIT

README

gopi-tools

A variety of GPIO utilities for your Raspberry Pi.

Documentation: GoDoc

gopi-tools is a Go Library providing a set of tools that control various hardware devices and sensors for a Raspberry Pi.

Dependencies

Access to the Raspberry Pi's GPIO pins is by the following python 2.7 packages.

RPi.GPIO

Make sure you have the latest library by executing:

sudo pip install RPi.GPIO
Adafruit_Python_CharLCD

Installation and setup instructions here, https://github.com/adafruit/Adafruit_Python_CharLCD

Adafruit_Python_MCP3008

Installation and setup instructions here, https://github.com/adafruit/Adafruit_Python_MCP3008

Installation and Usage

To install run the following on the command prompt:

go get "github.com\brumawen\gopi-tools"

Add the following import to the top of your code:

import "github.com/brumawen/gopi-tools"

Tool Module Descriptions

Led

This type provides control over a LED that has been connected to a GPIO pin of your Pi.

alt text

func TestLed(t *testing.T) {
    l := Led{GpioLed: 18}
    err := l.Init()
    if err != nil {
        t.Error(err)
    }
    defer l.Close()

    l.On()
    time.Sleep(2 * time.Second)
    l.Off()
}
CharDisplay

This type provides control for a LCD Display.

alt text

func TestDisplayMessage(t *testing.T) {
	d := CharDisplay{}
	err := d.Message("Hello\nWorld")
	if err != nil {
		t.Error(err)
	}
	defer d.Close()
	time.Sleep(2 * time.Second)
	d.Clear()
}
OneWireTemp

This type provides control for a 1-Wire Temperature device like a DS18B20 temperature probe.

alt text

func TestCanReadTemp(t *testing.T) {
	st, err := GetDeviceList()
	if err != nil {
		t.Error(err)
	}
	if len(st) == 0 {
		t.Error(errors.New("Temperature device not found."))
	} else {
		fmt.Println("Devices found", st)
	}

	o := OneWireTemp{ID: st[0].ID}
	err = o.Init()
	if err != nil {
		t.Error(err)
	}
	defer o.Close()
	v, err := o.ReadTemp()
	if err != nil {
		t.Error(err)
	}
	if v == 999999 {
		t.Error("Temperature could not be read from the file.")
	} else {
		fmt.Println("Temperature", v)
	}
}
Mcp3008

This type provides control for a 8-Channel ADC IC.

alt text

A call to the Read method returns a float slice containing the 8 channel values read from the IC.

func TestMcp3008CanReadChannels(t *testing.T) {
	m := Mcp3008{}
	if err := m.Init(); err != nil {
		t.Error(err)
	}
	defer m.Close()

	r, err := m.Read()
	if err != nil {
		t.Error(err)
	}
	if len(r) == 0 {
		t.Error("No values returned")
	} else {
		fmt.Println(r)
	}
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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