diff --git a/README.md b/README.md index c0729dbd..97cd4453 100644 --- a/README.md +++ b/README.md @@ -187,7 +187,8 @@ Gobot has a extensible system for connecting to hardware devices. The following - [Arduino](http://www.arduino.cc/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/firmata) - Audio <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/audio) -- [Beaglebone Black](http://beagleboard.org/Products/BeagleBone+Black/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/beaglebone) +- [Beaglebone Black](http://beagleboard.org/boards) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/beaglebone) +- [Beaglebone PocketBeagle](http://beagleboard.org/pocket/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/beaglebone) - [Bluetooth LE](https://www.bluetooth.com/what-is-bluetooth-technology/bluetooth-technology-basics/low-energy) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/ble) - [C.H.I.P](http://www.nextthing.co/pages/chip) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/chip) - [C.H.I.P Pro](https://docs.getchip.com/chip_pro.html) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/chip) diff --git a/platforms/beaglebone/README.md b/platforms/beaglebone/README.md index b0bd1c8a..841702ad 100644 --- a/platforms/beaglebone/README.md +++ b/platforms/beaglebone/README.md @@ -2,10 +2,14 @@ The BeagleBone is an ARM based single board computer, with lots of GPIO, I2C, and analog interfaces built in. -The Gobot adaptor for the BeagleBone should support all of the various BeagleBone boards such as the BeagleBone Black, SeeedStudio BeagleBone Green, SeeedStudio BeagleBone Green Wireless, and others that use the latest Debian and standard "Cape Manager" interfaces. +The Gobot adaptor for the BeagleBone supports all of the various BeagleBone boards such as the BeagleBone Black, SeeedStudio BeagleBone Green, SeeedStudio BeagleBone Green Wireless, and others that use the latest Debian and standard "Cape Manager" interfaces. For more info about the BeagleBone platform go to [http://beagleboard.org/getting-started](http://beagleboard.org/getting-started). +In addition, there is an separate Adaptor for the PocketBeagle, a USB-key-fob sized computer. The PocketBeagle has a different pin layout and somewhat different capabilities. + +For more info about the PocketBeagle platform go to [http://beagleboard.org/pocket](http://beagleboard.org/pocket). + ## How to Install @@ -54,6 +58,39 @@ func main() { } ``` +To use the PocketBeagle, use `beaglebone.NewPocketBeagleAdaptor()` like this: + +```go +package main + +import ( + "time" + + "gobot.io/x/gobot" + "gobot.io/x/gobot/drivers/gpio" + "gobot.io/x/gobot/platforms/beaglebone" +) + +func main() { + beagleboneAdaptor := beaglebone.NewPocketBeagleAdaptor() + led := gpio.NewLedDriver(beagleboneAdaptor, "P1_2") + + work := func() { + gobot.Every(1*time.Second, func() { + led.Toggle() + }) + } + + robot := gobot.NewRobot("pocketBeagleBot", + []gobot.Connection{beagleboneAdaptor}, + []gobot.Device{led}, + work, + ) + + robot.Start() +} +``` + ## How to Connect ### Compiling diff --git a/platforms/beaglebone/beaglebone_adaptor.go b/platforms/beaglebone/beaglebone_adaptor.go index 17173608..bbf9ae6c 100644 --- a/platforms/beaglebone/beaglebone_adaptor.go +++ b/platforms/beaglebone/beaglebone_adaptor.go @@ -23,7 +23,7 @@ type pwmPinData struct { const pwmDefaultPeriod = 500000 -// Adaptor is the gobot.Adaptor representation for the Beaglebone +// Adaptor is the gobot.Adaptor representation for the Beaglebone Black/Green type Adaptor struct { name string digitalPins []*sysfs.DigitalPin @@ -39,10 +39,10 @@ type Adaptor struct { findPin func(pinPath string) (string, error) } -// NewAdaptor returns a new Beaglebone Adaptor +// NewAdaptor returns a new Beaglebone Black/Green Adaptor func NewAdaptor() *Adaptor { b := &Adaptor{ - name: gobot.DefaultName("Beaglebone"), + name: gobot.DefaultName("BeagleboneBlack"), digitalPins: make([]*sysfs.DigitalPin, 120), pwmPins: make(map[string]*sysfs.PWMPin), i2cBuses: make(map[int]i2c.I2cDevice), diff --git a/platforms/beaglebone/beaglebone_adaptor_test.go b/platforms/beaglebone/beaglebone_adaptor_test.go index ae99114a..5d2dd23b 100644 --- a/platforms/beaglebone/beaglebone_adaptor_test.go +++ b/platforms/beaglebone/beaglebone_adaptor_test.go @@ -257,3 +257,8 @@ func TestBeagleboneDigitalPinFinalizeFileError(t *testing.T) { err = a.Finalize() gobottest.Assert(t, strings.Contains(err.Error(), "/sys/class/gpio/unexport: No such file."), true) } + +func TestPocketBeagleAdaptorName(t *testing.T) { + a := NewPocketBeagleAdaptor() + gobottest.Assert(t, strings.HasPrefix(a.Name(), "PocketBeagle"), true) +} diff --git a/platforms/beaglebone/beaglebone_pins.go b/platforms/beaglebone/black_pins.go similarity index 100% rename from platforms/beaglebone/beaglebone_pins.go rename to platforms/beaglebone/black_pins.go diff --git a/platforms/beaglebone/doc.go b/platforms/beaglebone/doc.go index 0c3ccb02..f94786b9 100644 --- a/platforms/beaglebone/doc.go +++ b/platforms/beaglebone/doc.go @@ -1,5 +1,6 @@ /* -Package beaglebone provides the Gobot adaptor for the Beaglebone Black. +Package beaglebone provides the Gobot adaptor for the Beaglebone Black/Green, as well as a +separate Adaptor for the PocketBeagle. Installing: diff --git a/platforms/beaglebone/pocketbeagle_adaptor.go b/platforms/beaglebone/pocketbeagle_adaptor.go new file mode 100644 index 00000000..f67c03f5 --- /dev/null +++ b/platforms/beaglebone/pocketbeagle_adaptor.go @@ -0,0 +1,24 @@ +package beaglebone + +import "gobot.io/x/gobot" + +// PocketBeagleAdaptor is the Gobot Adaptor for the PocketBeagle +// For more information check out: +// http://beagleboard.org/pocket +// +type PocketBeagleAdaptor struct { + *Adaptor +} + +// NewPocketBeagleAdaptor creates a new Adaptor for the PocketBeagle +func NewPocketBeagleAdaptor() *PocketBeagleAdaptor { + a := NewAdaptor() + a.SetName(gobot.DefaultName("PocketBeagle")) + a.pinMap = pocketBeaglePinMap + a.pwmPinMap = pocketBeaglePwmPinMap + a.analogPinMap = pocketBeagleAnalogPinMap + + return &PocketBeagleAdaptor{ + Adaptor: a, + } +} diff --git a/platforms/beaglebone/pocketbeagle_pins.go b/platforms/beaglebone/pocketbeagle_pins.go new file mode 100644 index 00000000..6a96d719 --- /dev/null +++ b/platforms/beaglebone/pocketbeagle_pins.go @@ -0,0 +1,94 @@ +package beaglebone + +var pocketBeaglePinMap = map[string]int{ + // P1_1 - VIN + "P1_2": 87, + // P1_3 - USB1-V_EN + "P1_4": 89, + // P1_5 - USB1-VBUS + "P1_6": 5, + // P1_7 - USB1-VIN + "P1_8": 2, + // P1_9 - USB1-DN + "P1_10": 3, + // P1_11 - USB1-DP + "P1_12": 4, + // P1_13 - USB1-ID + // P1_14 - 3.3V + // P1_15 - USB1-GND + // P1_16 - GND + // P1_16 - AIN-VREF- + // P1_18 - AIN-VREF+ + // P1_19 - AIO0 + "P1_20": 20, + // P1_21 - AIO1 + // P1_22 - GND + // P1_23 - AIO2 + // P1_24 - VOUT-5V + // P1_25 - AIO3 + "P1_26": 12, + // P1_27 - AIO4 + "P1_28": 13, + "P1_29": 117, + "P1_30": 43, + "P1_31": 114, + "P1_32": 42, + "P1_33": 111, + "P1_34": 26, + "P1_35": 88, + "P1_36": 110, + + "P2_1": 50, + "P2_2": 59, + "P2_3": 23, + "P2_4": 58, + "P2_5": 30, + "P2_6": 57, + "P2_7": 31, + "P2_8": 60, + "P2_9": 15, + "P2_10": 52, + "P2_11": 14, + // P2_12 - PWR-BTN + // P2_13 - VOUT + // P2_14 - BAT-VIN + // P2_15 - GND + // P2_16 - BAT-TEMP + "P2_17": 65, + "P2_18": 47, + "P2_19": 27, + "P2_20": 64, + // P2_21 - GND + "P2_22": 46, + // P2_23 - 3.3V + "P2_24": 44, + "P2_25": 41, + // P2_26 - NRST + "P2_27": 40, + "P2_28": 116, + "P2_29": 7, + "P2_30": 113, + "P2_31": 19, + "P2_32": 112, + "P2_33": 45, + "P2_34": 115, + "P2_35": 86, + // P2_36 - AIO7 +} + +var pocketBeaglePwmPinMap = map[string]pwmPinData{ + "P1_33": {path: "/sys/devices/platform/ocp/48300000.epwmss/48300200.pwm/pwm/pwmchip*", channel: 1}, + "P1_36": {path: "/sys/devices/platform/ocp/48300000.epwmss/48300200.pwm/pwm/pwmchip*", channel: 0}, + + "P2_1": {path: "/sys/devices/platform/ocp/48302000.epwmss/48302200.pwm/pwm/pwmchip*", channel: 0}, + "P2_3": {path: "/sys/devices/platform/ocp/48304000.epwmss/48304200.pwm/pwm/pwmchip*", channel: 1}, +} + +var pocketBeagleAnalogPinMap = map[string]string{ + "P1_19": "in_voltage0_raw", + "P1_21": "in_voltage1_raw", + "P1_23": "in_voltage2_raw", + "P1_25": "in_voltage3_raw", + "P1_27": "in_voltage4_raw", + "P2_36": "in_voltage7_raw", +}