Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to use gobot libraries without all the gobot/robot initialization. #302

Closed
ericho opened this issue Aug 18, 2016 · 7 comments

Comments

@ericho
Copy link
Contributor

ericho commented Aug 18, 2016

I'm wondering if it's possible to have a program like this

package main

import (
    "time"

    "github.com/hybridgroup/gobot/platforms/gpio"
    "github.com/hybridgroup/gobot/platforms/intel-iot/edison"
)

func main() {
    e := edison.NewEdisonAdaptor("edison")
    led := gpio.NewLedDriver(e, "led", "13")
    for {
        led.Toggle()
        time.Sleep(1)
    }
}

That could be part of another program. For instance if I want to read values from a sensor and send it to a database or another process. I think that I can achieve this by using a channel but the idea would be to have a simple way to get the ports/sensors data, something like the mraa library.

Is there a way to have such functionality on gobot?

Thanks

@trevrosen
Copy link
Collaborator

Try something like this, but with the Edison adaptor and let me know what happens.

https://github.com/hybridgroup/gobot/blob/dev/examples/beaglebone_basic_direct_pin.go

@trevrosen
Copy link
Collaborator

You're basically on the right track, you just need to Connect() the adaptor.

@ericho
Copy link
Contributor Author

ericho commented Aug 23, 2016

Awesome! The connect() was the thing I needed. Now this code works

package main

import (
    "time"
    "github.com/hybridgroup/gobot/platforms/gpio"
    "github.com/hybridgroup/gobot/platforms/intel-iot/edison"
)

func main() {
    e := edison.NewEdisonAdaptor("edison")
    led := gpio.NewLedDriver(e, "led", "13")
    e.Connect()
    for {
        led.Toggle()
        time.Sleep(1000 * time.Millisecond)
    }
}

Thanks :)

@ericho ericho closed this as completed Aug 23, 2016
@deadprogram
Copy link
Member

One other small thing worth mentioning. You should also call Start() on the driver, to ensure that it is properly initialized:

package main

import (
    "time"
    "github.com/hybridgroup/gobot/platforms/gpio"
    "github.com/hybridgroup/gobot/platforms/intel-iot/edison"
)

func main() {
    e := edison.NewEdisonAdaptor("edison")
    led := gpio.NewLedDriver(e, "led", "13")
    e.Connect()
    led.Start()
    for {
        led.Toggle()
        time.Sleep(1000 * time.Millisecond)
    }
}

@deadprogram
Copy link
Member

We should update the docs with this info, so people realize they can use Gobot as a set of Golang device libraries, not just use the entire framework.

@trevrosen
Copy link
Collaborator

@deadprogram if you want to make an issue and assign it to me w/ some details about what you'd like to see and what platforms to cover, I can take on that docs update.

@deadprogram
Copy link
Member

Hi @trevrosen I just added hybridgroup/gobot-site#48 to discuss this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants