diff --git a/examples/beaglebone_blink_usr_led.go b/examples/beaglebone_blink_usr_led.go index 34479e4b8..3774fc0c0 100644 --- a/examples/beaglebone_blink_usr_led.go +++ b/examples/beaglebone_blink_usr_led.go @@ -10,7 +10,7 @@ import ( func main() { beagleboneAdaptor := beaglebone.NewAdaptor() - led := gpio.NewLedDriver(beagleboneAdaptor, "usr0") + led := gpio.NewLedDriver(beagleboneAdaptor, "usr1") work := func() { gobot.Every(1*time.Second, func() { diff --git a/platforms/beaglebone/README.md b/platforms/beaglebone/README.md index c6de6a727..8cc6dcca2 100644 --- a/platforms/beaglebone/README.md +++ b/platforms/beaglebone/README.md @@ -50,7 +50,7 @@ func main() { Simply compile your Gobot program like this: ```bash -$ GOARM=7 GOARCH=arm GOOS=linux go build examples/beaglebone_blink.go +$ GOARCH=arm GOOS=linux go build examples/beaglebone_blink.go ``` If you are running the official Debian Linux through the usb->ethernet connection, or are connected to the board using WiFi, you can simply upload your program and execute it with the `scp` command like this: @@ -72,7 +72,7 @@ Once you have created the SD card, boot your BeagleBone using the new image as f - Insert SD card into your (powered-down) board, hold down the USER/BOOT button (if using Black) and apply power, either by the USB cable or 5V adapter. -- If using an original BeagleBone, you are done. +- If all you want to do it boot once from the SD card, it should now be booting. - If using BeagleBone Black and desire to write the image to your on-board eMMC, you'll need to follow the instructions at http://elinux.org/Beagleboard:BeagleBoneBlack_Debian#Flashing_eMMC. When the flashing is complete, all 4 USRx LEDs will be steady on or off. The latest Debian flasher images automatically power down the board upon completion. This can take up to 45 minutes. Power-down your board, remove the SD card and apply power again to be complete. diff --git a/platforms/beaglebone/beaglebone_adaptor.go b/platforms/beaglebone/beaglebone_adaptor.go index cd81c390d..c510d859b 100644 --- a/platforms/beaglebone/beaglebone_adaptor.go +++ b/platforms/beaglebone/beaglebone_adaptor.go @@ -21,15 +21,16 @@ var glob = func(pattern string) (matches []string, err error) { // Adaptor is the gobot.Adaptor representation for the Beaglebone type Adaptor struct { - name string - kernel string - digitalPins []sysfs.DigitalPin - pwmPins map[string]*pwmPin - i2cDevice sysfs.I2cDevice - usrLed string - ocp string - helper string - slots string + name string + kernel string + digitalPins []sysfs.DigitalPin + pwmPins map[string]*pwmPin + i2cDevice sysfs.I2cDevice + usrLed string + ocp string + analogPath string + analogPinMap map[string]string + slots string } // NewAdaptor returns a new Beaglebone Adaptor @@ -74,19 +75,31 @@ func (b *Adaptor) Kernel() string { return b.kernel } // Connect initializes the pwm and analog dts. func (b *Adaptor) Connect() error { - if err := ensureSlot(b.slots, "cape-bone-iio"); err != nil { - return err - } + // enable analog + if b.kernel[:1] == "4" { + if err := ensureSlot(b.slots, "BB-ADC"); err != nil { + return err + } - if err := ensureSlot(b.slots, "am33xx_pwm"); err != nil { - return err + b.analogPath = "/sys/bus/iio/devices/iio:device0" + b.analogPinMap = analogPins44 + } else { + if err := ensureSlot(b.slots, "cape-bone-iio"); err != nil { + return err + } + + g, err := glob(fmt.Sprintf("%v/helper.*", b.ocp)) + if err != nil { + return err + } + b.analogPath = g[0] + b.analogPinMap = analogPins3 } - g, err := glob(fmt.Sprintf("%v/helper.*", b.ocp)) - if err != nil { + // enable pwm + if err := ensureSlot(b.slots, "am33xx_pwm"); err != nil { return err } - b.helper = g[0] return nil } @@ -165,7 +178,7 @@ func (b *Adaptor) AnalogRead(pin string) (val int, err error) { if err != nil { return } - fi, err := sysfs.OpenFile(fmt.Sprintf("%v/%v", b.helper, analogPin), os.O_RDONLY, 0644) + fi, err := sysfs.OpenFile(fmt.Sprintf("%v/%v", b.analogPath, analogPin), os.O_RDONLY, 0644) defer fi.Close() if err != nil { @@ -233,7 +246,7 @@ func (b *Adaptor) translatePwmPin(pin string) (value string, err error) { // translateAnalogPin converts analog pin name to pin position func (b *Adaptor) translateAnalogPin(pin string) (value string, err error) { - for key, value := range analogPins { + for key, value := range b.analogPinMap { if key == pin { return value, nil } diff --git a/platforms/beaglebone/beaglebone_adaptor_test.go b/platforms/beaglebone/beaglebone_adaptor_test.go index f91322849..4316c565c 100644 --- a/platforms/beaglebone/beaglebone_adaptor_test.go +++ b/platforms/beaglebone/beaglebone_adaptor_test.go @@ -57,8 +57,8 @@ func TestBeagleboneAdaptor(t *testing.T) { "/sys/devices/platform/bone_capemgr", "/sys/devices/platform/ocp/ocp4", "/sys/class/leds/beaglebone:green:usr1/brightness", - "/sys/devices/platform/ocp/ocp4/helper.5", - "/sys/devices/platform/ocp/ocp4/helper.5/AIN1", + "/sys/bus/iio/devices/iio:device0", + "/sys/bus/iio/devices/iio:device0/in_voltage1_raw", "/sys/devices/platform/ocp/ocp4/pwm_test_P9_14.5", "/sys/devices/platform/ocp/ocp4/pwm_test_P9_14.5/run", "/sys/devices/platform/ocp/ocp4/pwm_test_P9_14.5/period", @@ -79,7 +79,7 @@ func TestBeagleboneAdaptor(t *testing.T) { a.Connect() - a.helper = "/sys/devices/platform/ocp/ocp4/helper.5" + a.analogPath = "/sys/bus/iio/devices/iio:device0" // PWM glob = func(pattern string) (matches []string, err error) { @@ -113,11 +113,11 @@ func TestBeagleboneAdaptor(t *testing.T) { ) // Analog - fs.Files["/sys/devices/platform/ocp/ocp4/helper.5/AIN1"].Contents = "567\n" + fs.Files["/sys/bus/iio/devices/iio:device0/in_voltage1_raw"].Contents = "567\n" i, _ := a.AnalogRead("P9_40") gobottest.Assert(t, i, 567) - i, err := a.AnalogRead("P9_99") + _, err := a.AnalogRead("P9_99") gobottest.Assert(t, err, errors.New("Not a valid pin")) // DigitalIO diff --git a/platforms/beaglebone/beaglebone_pins.go b/platforms/beaglebone/beaglebone_pins.go index b0b7facae..693af3496 100644 --- a/platforms/beaglebone/beaglebone_pins.go +++ b/platforms/beaglebone/beaglebone_pins.go @@ -80,7 +80,7 @@ var pwmPins = map[string]string{ "P8_46": "P8_46", } -var analogPins = map[string]string{ +var analogPins3 = map[string]string{ "P9_39": "AIN0", "P9_40": "AIN1", "P9_37": "AIN2", @@ -89,3 +89,13 @@ var analogPins = map[string]string{ "P9_36": "AIN5", "P9_35": "AIN6", } + +var analogPins44 = map[string]string{ + "P9_39": "in_voltage0_raw", + "P9_40": "in_voltage1_raw", + "P9_37": "in_voltage2_raw", + "P9_38": "in_voltage3_raw", + "P9_33": "in_voltage4_raw", + "P9_36": "in_voltage5_raw", + "P9_35": "in_voltage6_raw", +}