Gobot Beaglebone Black GPIO question...

156 views
Skip to first unread message

Curtis Paul

unread,
Feb 11, 2018, 11:21:57 PM2/11/18
to golang-nuts
Anybody out there have any experience with BeagleBone Black and gobot?
I need some advice on how I could go about troubleshooting this...or if you know what the issue is, etc...

I have a very simple Gobot/GPIO Button circuit.  
It should show output when button is pushed and then again when released, but it doesn't do anything.
It's not working.

Running image BBB-blank-debian-9.3-iot-armhf-2018-02-04-4gb.img.xz.  (I also tried the version posted on the BeagleBone site)
Modified /boot/uEnv.txt according to instructions at https://gobot.io/documentation/platforms/beaglebone.

I can see all the gpio's in /sys/class/gpio.

I'm using gpio67, so I cat the value file and see 0 when button is not pushed, then see 1 when button is pushed.  I know my circuit is good.

This is my gobot code for interacting with the button:
FYI...P8_8 is gpio67

package main

import (
        "fmt"

        "gobot.io/x/gobot"
)

func main() {
        beagleboneAdaptor := beaglebone.NewAdaptor()
        button := gpio.NewButtonDriver(beagleboneAdaptor, "P8_8")

        work := func() {
                button.On(gpio.ButtonPush, func(data interface{}) {
                        fmt.Println("button pressed")
                })

                button.On(gpio.ButtonRelease, func(data interface{}) {
                        fmt.Println("button released")
                })
        }

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

        robot.Start()
}


This is what it looks like when the code runs.  No errors, etc...
Push the button and don't get any of the Println's.

2018/02/12 04:14:03 Initializing connections...
2018/02/12 04:14:03 Initializing connection BeagleboneBlack-65FB3BAE ...
2018/02/12 04:14:03 Initializing devices...
2018/02/12 04:14:03 Initializing device Button-51E1127C ...
2018/02/12 04:14:03 Robot buttonBot initialized.
2018/02/12 04:14:03 Starting Robot buttonBot ...
2018/02/12 04:14:03 Starting connections...
2018/02/12 04:14:03 Starting connection BeagleboneBlack-65FB3BAE...
2018/02/12 04:14:03 Starting devices...
2018/02/12 04:14:03 Starting device Button-51E1127C on pin P8_8...
2018/02/12 04:14:03 Starting work...

I should be seeing "button pressed" when I press the P8_8 button....but I don't see anything.

silviu...@gmail.com

unread,
Feb 12, 2018, 12:41:58 AM2/12/18
to golang-nuts
Hi Curtis,

I used to play a bit with a Beaglebone Black a few years ago, but it's now gathering dust at my father's place. I really liked it at the time.

Can you double check that you are correctly using your work := func() ... construct ?

Here's what that documentation of the gobot.NewRobot initializer says at: https://github.com/hybridgroup/gobot/blob/master/robot.go#L104
"func(): The work routine the robot will execute once all devices and connections have been initialized and started"

Could it be that your two "button.On(...)" handlers are actually only executed once, then they are lost for ever ?

Maybe you can try using the Subscribe method ? https://github.com/hybridgroup/gobot/blob/master/eventer.go#L108

e,g, myEventsChan := button.Subscribe()  (just before the work := func() block , then launch a go routing with that channel as a parameter ? )

Just a thought

Cheers,
Silviu

silviu...@gmail.com

unread,
Feb 12, 2018, 1:07:04 AM2/12/18
to golang-nuts
Hmm... I actually looked at that .On method. It does in fact call Subscribe(),  then spawns a go routine. Strange, so maybe it is a device specific issue.

Maybe try to move those .On handlers before the work := func() block, just in case...

Curtis Paul

unread,
Feb 12, 2018, 1:28:30 AM2/12/18
to golang-nuts
Not sure....

It's fairly common demo code that more then a few people have used.
Maybe it's wrong...
 

 
Message has been deleted

Curtis Paul

unread,
Feb 12, 2018, 1:41:22 AM2/12/18
to golang-nuts
I'm at a loss...


I think the first thing is that I'm not sure I understand how to diagnose this code....how to validate it's doing what I think it may or may not be doing.

Silviu Capota Mera

unread,
Feb 12, 2018, 8:36:35 AM2/12/18
to Curtis Paul, golang-nuts
If you have more time to spare on this project, try to circumvent the events / subscriber functionality. Try to see if you can read directly from the adaptor:


so inside your work function, you would do:  
dVal, err := beagleboneAdaptor.DigitalRead("P8_8")
if err != nil {
  fmt.Println("Error reading the pin: ", err)
  return
}
fmt.Println("Pin read correctly, the value is: ", dVal)

Then you would run the program while holding the button on, and off, respectively. This way you can tell whether the most basic part of the gobot subsystem does its job. That would be a first start at debugging.
Otherwise, just circumvent it, and read the /sys/class/gpio/[your number] through the file system api



--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/y6ZYXVsfvS0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marc-Antoine Ruel

unread,
Feb 13, 2018, 9:10:33 AM2/13/18
to Silviu Capota Mera, Curtis Paul, golang-nuts
Gobot is great if you want to delegate the "event loop".

If you want to keep control, you may want to take a look periph.io, which supports interrupt based edge detection, so no need to do a busy loop. Which library to use depends about how you want to structure the control loops, and that's why the two libraries are so different.

Side note; if you care about high performance GPIO, we're looking to have PRU support which I feel is more useful on T.I. CPUs than memory mapped GPIO, unlike for Broadcom and Allwinner CPUs.

Thanks,

M-A

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.

Ranjib Dey

unread,
Feb 13, 2018, 10:24:32 AM2/13/18
to Marc-Antoine Ruel, Silviu Capota Mera, Curtis Paul, golang-nuts
From what I recall gobot uses sysfs bases GPIO driver that writes to /sys/class/gpio/* (using mmaped GPIOs is another way) using standard file io. If I am you, I would start with simply using the digitalinput or button driver (https://godoc.org/gobot.io/x/gobot/drivers/gpio) straight. I think its missing on exporting the pin before it starts reading. In sysfs based gpio manipulation the pins need to be exported first, followed by setting its direction (input in this case) , and then you can start reading it, its somewhat like this in shell
```
echo <PIN> >/sys/class/gpio/export
echo input > /sys/class/gpio/gpio<PIN>/direction
cat /sys/class/gpio/gpio<PIN>/value
```
So, you can check manually whats going on, if the pin is being exported, if its direction is set correctly etc. You can also strace your executable to check what its doing, look for the specific write calls against those file path. gobot author is active in the mailing list as well, probably he'll respond soon (i noticed the opencv bindings from him recently, great person).

I dont have beaglebone with me, but i have tried with RPi,
hth

Ron Evans

unread,
Feb 14, 2018, 4:58:54 PM2/14/18
to golang-nuts
Hi, everyone

The issue turned out to simply be a matter of a misnamed pin, combined with some changes to how you configure the BeagleBone. The Beaglebone's Debian OS is now much simpler to setup, so some of our directions needed to be removed, as they were also interferring with the newer distro.

Updates to Gobot have already been committed and released. Thanks again for eveyone who chimed in.

Regards,
Ron
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages