microbit

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2018 License: Apache-2.0, Apache-2.0 Imports: 6 Imported by: 0

README

Microbit

The Microbit is a tiny computer with built-in Bluetooth LE aka Bluetooth 4.0.

How to Install

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

You must install the Microbit firmware from [@sandeepmistry] located at https://github.com/sandeepmistry/node-bbc-microbit to use the Microbit with Gobot. This firmware is based on the micro:bit template, but with a few changes.

If you have the Gort command line tool installed, you can install the firmware using the following commands:

gort microbit download
gort microbit install /media/mysystem/MICROBIT

Substitute the proper location to your Microbit for /media/mysystem/MICROBIT in the previous command.

Once the firmware is installed, make sure your rotate your Microbit in a circle to calibrate the magnetometer before your try to connect to it using Gobot, or it will not respond.

You can also follow the firmware installation instructions at https://github.com/sandeepmistry/node-bbc-microbit#flashing-microbit-firmware.

The source code for the firmware is located at https://github.com/sandeepmistry/node-bbc-microbit-firmware however you do not need this source code to install the firmware using the installation instructions.

How to Use

The Gobot platform for the Microbit includes several different drivers, each one corresponding to a different capability:

  • AccelerometerDriver
  • ButtonDriver
  • IOPinDriver
  • LEDDriver
  • MagnetometerDriver
  • TemperatureDriver

The following example uses the LEDDriver:

package main

import (
	"os"
	"time"

	"gobot.io/x/gobot"
	"gobot.io/x/gobot/platforms/ble"
	"gobot.io/x/gobot/platforms/microbit"
)

func main() {
	bleAdaptor := ble.NewClientAdaptor(os.Args[1])
	ubit := microbit.NewLEDDriver(bleAdaptor)

	work := func() {
		ubit.Blank()
		gobot.After(1*time.Second, func() {
			ubit.WriteText("Hello")
		})
		gobot.After(7*time.Second, func() {
			ubit.Smile()
		})
	}

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

	robot.Start()
}
Using Microbit with GPIO and AIO Drivers

The IOPinDriver is a special kind of Driver. It supports the DigitalReader, DigitalWriter, and AnalogReader interfaces.

This means you can use it with any gpio or aio Driver. In this example, we are using the normal gpio.ButtonDriver and gpio.LedDriver:

package main

import (
	"os"

	"gobot.io/x/gobot"
	"gobot.io/x/gobot/drivers/gpio"
	"gobot.io/x/gobot/platforms/ble"
	"gobot.io/x/gobot/platforms/microbit"
)

func main() {
	bleAdaptor := ble.NewClientAdaptor(os.Args[1])

	ubit := microbit.NewIOPinDriver(bleAdaptor)
	button := gpio.NewButtonDriver(ubit, "0")
	led := gpio.NewLedDriver(ubit, "1")

	work := func() {
		button.On(gpio.ButtonPush, func(data interface{}) {
			led.On()
		})
		button.On(gpio.ButtonRelease, func(data interface{}) {
			led.Off()
		})
	}

	robot := gobot.NewRobot("buttonBot",
		[]gobot.Connection{bleAdaptor},
		[]gobot.Device{ubit, button, led},
		work,
	)

	robot.Start()
}

How to Connect

The Microbit is a Bluetooth LE device.

You need to know the BLE ID of the Microbit that you want to connect to.

OSX

If you connect by name, then you do not need to worry about the Bluetooth LE ID. However, if you want to connect by ID, OS X uses its own Bluetooth ID system which is different from the IDs used on Linux. The code calls thru the XPC interfaces provided by OSX, so as a result does not need to run under sudo.

For example:

go run examples/microbit_led.go "BBC micro:bit"

OSX uses its own Bluetooth ID system which is different from the IDs used on Linux. The code calls thru the XPC interfaces provided by OSX, so as a result does not need to run under sudo.

Ubuntu

On Linux the BLE code will need to run as a root user account. The easiest way to accomplish this is probably to use go build to build your program, and then to run the requesting executable using sudo.

For example:

go build examples/microbit_led.go
sudo ./microbit_led "BBC micro:bit"
Windows

Hopefully coming soon...

Documentation

Overview

Package microbit contains the Gobot drivers for the Microbit.

For more information refer to the microbit README: https://github.com/hybridgroup/gobot/blob/master/platforms/microbit/README.md

Index

Constants

View Source
const (

	// ButtonA event
	ButtonA = "buttonA"

	// ButtonB event
	ButtonB = "buttonB"
)
View Source
const (

	// Accelerometer event
	Accelerometer = "accelerometer"
)
View Source
const (

	// Magnetometer event
	Magnetometer = "magnetometer"
)
View Source
const (

	// Temperature event
	Temperature = "temperature"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AccelerometerData

type AccelerometerData struct {
	X float32
	Y float32
	Z float32
}

type AccelerometerDriver

type AccelerometerDriver struct {
	gobot.Eventer
	// contains filtered or unexported fields
}

AccelerometerDriver is the Gobot driver for the Microbit's built-in accelerometer

func NewAccelerometerDriver

func NewAccelerometerDriver(a ble.BLEConnector) *AccelerometerDriver

NewAccelerometerDriver creates a Microbit AccelerometerDriver

func (*AccelerometerDriver) Connection

func (b *AccelerometerDriver) Connection() gobot.Connection

Connection returns the BLE connection

func (*AccelerometerDriver) Halt

func (b *AccelerometerDriver) Halt() (err error)

Halt stops LED driver (void)

func (*AccelerometerDriver) Name

func (b *AccelerometerDriver) Name() string

Name returns the Driver Name

func (*AccelerometerDriver) SetName

func (b *AccelerometerDriver) SetName(n string)

SetName sets the Driver Name

func (*AccelerometerDriver) Start

func (b *AccelerometerDriver) Start() (err error)

Start tells driver to get ready to do work

type ButtonDriver

type ButtonDriver struct {
	gobot.Eventer
	// contains filtered or unexported fields
}

ButtonDriver is the Gobot driver for the Microbit's built-in buttons

func NewButtonDriver

func NewButtonDriver(a ble.BLEConnector) *ButtonDriver

NewButtonDriver creates a Microbit ButtonDriver

func (*ButtonDriver) Connection

func (b *ButtonDriver) Connection() gobot.Connection

Connection returns the BLE connection

func (*ButtonDriver) Halt

func (b *ButtonDriver) Halt() (err error)

Halt stops LED driver (void)

func (*ButtonDriver) Name

func (b *ButtonDriver) Name() string

Name returns the Driver Name

func (*ButtonDriver) SetName

func (b *ButtonDriver) SetName(n string)

SetName sets the Driver Name

func (*ButtonDriver) Start

func (b *ButtonDriver) Start() (err error)

Start tells driver to get ready to do work

type IOPinDriver added in v1.5.0

type IOPinDriver struct {
	gobot.Eventer
	// contains filtered or unexported fields
}

IOPinDriver is the Gobot driver for the Microbit's built-in digital and analog I/O

func NewIOPinDriver added in v1.5.0

func NewIOPinDriver(a ble.BLEConnector) *IOPinDriver

NewIOPinDriver creates a Microbit IOPinDriver

func (*IOPinDriver) AnalogRead added in v1.5.0

func (b *IOPinDriver) AnalogRead(pin string) (val int, err error)

AnalogRead reads from a pin

func (*IOPinDriver) Connection added in v1.5.0

func (b *IOPinDriver) Connection() gobot.Connection

Connection returns the BLE connection

func (*IOPinDriver) DigitalRead added in v1.5.0

func (b *IOPinDriver) DigitalRead(pin string) (val int, err error)

DigitalRead reads from a pin

func (*IOPinDriver) DigitalWrite added in v1.5.0

func (b *IOPinDriver) DigitalWrite(pin string, level byte) (err error)

DigitalWrite writes to a pin

func (*IOPinDriver) Halt added in v1.5.0

func (b *IOPinDriver) Halt() (err error)

Halt stops driver (void)

func (*IOPinDriver) Name added in v1.5.0

func (b *IOPinDriver) Name() string

Name returns the Driver Name

func (*IOPinDriver) ReadAllPinData added in v1.5.0

func (b *IOPinDriver) ReadAllPinData() (pins []PinData)

ReadAllPinData reads and returns the pin data for all pins

func (*IOPinDriver) ReadPinADConfig added in v1.5.0

func (b *IOPinDriver) ReadPinADConfig() (config int, err error)

ReadPinADConfig reads and returns the pin A/D config mask for all pins

func (*IOPinDriver) ReadPinIOConfig added in v1.5.0

func (b *IOPinDriver) ReadPinIOConfig() (config int, err error)

ReadPinIOConfig reads and returns the pin IO config mask for all pins

func (*IOPinDriver) SetName added in v1.5.0

func (b *IOPinDriver) SetName(n string)

SetName sets the Driver Name

func (*IOPinDriver) Start added in v1.5.0

func (b *IOPinDriver) Start() (err error)

Start tells driver to get ready to do work

func (*IOPinDriver) WritePinADConfig added in v1.5.0

func (b *IOPinDriver) WritePinADConfig(config int) (err error)

WritePinADConfig writes the pin A/D config mask for all pins

func (*IOPinDriver) WritePinData added in v1.5.0

func (b *IOPinDriver) WritePinData(pin string, data byte) (err error)

WritePinData writes the pin data for a single pin

func (*IOPinDriver) WritePinIOConfig added in v1.5.0

func (b *IOPinDriver) WritePinIOConfig(config int) (err error)

WritePinIOConfig writes the pin I/O config mask for all pins

type LEDDriver

type LEDDriver struct {
	gobot.Eventer
	// contains filtered or unexported fields
}

LEDDriver is the Gobot driver for the Microbit's LED array

func NewLEDDriver

func NewLEDDriver(a ble.BLEConnector) *LEDDriver

NewLEDDriver creates a Microbit LEDDriver

func (*LEDDriver) Blank

func (b *LEDDriver) Blank() (err error)

Blank clears the LEDs on the Microbit

func (*LEDDriver) Connection

func (b *LEDDriver) Connection() gobot.Connection

Connection returns the BLE connection

func (*LEDDriver) Dimond

func (b *LEDDriver) Dimond() (err error)

Dimond displays a dimond on the Microbit LEDs

func (*LEDDriver) DownLeftArrow

func (b *LEDDriver) DownLeftArrow() (err error)

DownLeftArrow displays an arrow pointing down and to the left on the Microbit LEDs

func (*LEDDriver) DownRightArrow

func (b *LEDDriver) DownRightArrow() (err error)

DownRightArrow displays an arrow pointing down and to the right on the Microbit LEDs

func (*LEDDriver) Halt

func (b *LEDDriver) Halt() (err error)

Halt stops LED driver (void)

func (*LEDDriver) Name

func (b *LEDDriver) Name() string

Name returns the Driver Name

func (*LEDDriver) ReadMatrix

func (b *LEDDriver) ReadMatrix() (data []byte, err error)

ReadMatrix read the current LED matrix state

func (*LEDDriver) ReadScrollingDelay

func (b *LEDDriver) ReadScrollingDelay() (delay uint16, err error)

func (*LEDDriver) SetName

func (b *LEDDriver) SetName(n string)

SetName sets the Driver Name

func (*LEDDriver) Smile

func (b *LEDDriver) Smile() (err error)

Smile displays a smile on the Microbit LEDs

func (*LEDDriver) Solid

func (b *LEDDriver) Solid() (err error)

Solid turns on all of the Microbit LEDs

func (*LEDDriver) Start

func (b *LEDDriver) Start() (err error)

Start tells driver to get ready to do work

func (*LEDDriver) UpLeftArrow

func (b *LEDDriver) UpLeftArrow() (err error)

UpLeftArrow displays an arrow pointing upwards and to the left on the Microbit LEDs

func (*LEDDriver) UpRightArrow

func (b *LEDDriver) UpRightArrow() (err error)

UpRightArrow displays an arrow pointing upwards and to the right on the Microbit LEDs

func (*LEDDriver) Wink

func (b *LEDDriver) Wink() (err error)

Wink displays a wink on the Microbit LEDs

func (*LEDDriver) WriteMatrix

func (b *LEDDriver) WriteMatrix(data []byte) (err error)

WriteMatrix writes an array of 5 bytes to set the LED matrix

func (*LEDDriver) WriteScrollingDelay

func (b *LEDDriver) WriteScrollingDelay(delay uint16) (err error)

func (*LEDDriver) WriteText

func (b *LEDDriver) WriteText(msg string) (err error)

WriteText writes a text message to the Microbit LED matrix

type MagnetometerData

type MagnetometerData struct {
	X float32
	Y float32
	Z float32
}

type MagnetometerDriver

type MagnetometerDriver struct {
	gobot.Eventer
	// contains filtered or unexported fields
}

MagnetometerDriver is the Gobot driver for the Microbit's built-in magnetometer

func NewMagnetometerDriver

func NewMagnetometerDriver(a ble.BLEConnector) *MagnetometerDriver

NewMagnetometerDriver creates a Microbit MagnetometerDriver

func (*MagnetometerDriver) Connection

func (b *MagnetometerDriver) Connection() gobot.Connection

Connection returns the BLE connection

func (*MagnetometerDriver) Halt

func (b *MagnetometerDriver) Halt() (err error)

Halt stops LED driver (void)

func (*MagnetometerDriver) Name

func (b *MagnetometerDriver) Name() string

Name returns the Driver Name

func (*MagnetometerDriver) SetName

func (b *MagnetometerDriver) SetName(n string)

SetName sets the Driver Name

func (*MagnetometerDriver) Start

func (b *MagnetometerDriver) Start() (err error)

Start tells driver to get ready to do work

type PinData added in v1.5.0

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

PinData has the read data for a specific digital pin

type RawAccelerometerData

type RawAccelerometerData struct {
	X int16
	Y int16
	Z int16
}

type RawMagnetometerData

type RawMagnetometerData struct {
	X int16
	Y int16
	Z int16
}

type TemperatureDriver

type TemperatureDriver struct {
	gobot.Eventer
	// contains filtered or unexported fields
}

TemperatureDriver is the Gobot driver for the Microbit's built-in thermometer

func NewTemperatureDriver

func NewTemperatureDriver(a ble.BLEConnector) *TemperatureDriver

NewTemperatureDriver creates a Microbit TemperatureDriver

func (*TemperatureDriver) Connection

func (b *TemperatureDriver) Connection() gobot.Connection

Connection returns the BLE connection

func (*TemperatureDriver) Halt

func (b *TemperatureDriver) Halt() (err error)

Halt stops Temperature driver (void)

func (*TemperatureDriver) Name

func (b *TemperatureDriver) Name() string

Name returns the Driver Name

func (*TemperatureDriver) SetName

func (b *TemperatureDriver) SetName(n string)

SetName sets the Driver Name

func (*TemperatureDriver) Start

func (b *TemperatureDriver) Start() (err error)

Start tells driver to get ready to do work

Jump to

Keyboard shortcuts

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