gobot
gobot copied to clipboard
LED works, RGB not?
Hi, so I have one RGB led and I tried the basic example here https://gobot.io/documentation/platforms/raspi/ separately on all pins (11, 13, 15) and corresponding color fired up and blinks and everything is good.
Then I changed NewLedDriver to NewRgbLedDriver, keeping the physical connections the same. And my led does not respond to any of the functions. Anything else I need to know? Raspberry Pi 3
Hello @stuomas it should work, can you please submit your exact code?
@deadprogram For example this works, and turns red led on. Works with pins 13 and 15 too.
package main
import (
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/platforms/raspi"
)
func main() {
r := raspi.NewAdaptor()
led := gpio.NewLedDriver(r, "11")
work := func() {
led.Off()
}
robot := gobot.NewRobot("ledbot",
[]gobot.Connection{r},
[]gobot.Device{led},
work,
)
robot.Start()
}
This doesn't respond to anything
package main
import (
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/platforms/raspi"
)
func main() {
r := raspi.NewAdaptor()
led := gpio.NewRgbLedDriver(r, "11", "13", "15")
work := func() {
led.SetRGB(255, 0, 0)
}
robot := gobot.NewRobot("ledbot",
[]gobot.Connection{r},
[]gobot.Device{led},
work,
)
robot.Start()
}
On, Off, or Toggle neither work. Led stays off (or in the state it was left before)
So one important question @stuomas is have you installed pi-blaster in order to use PWM on the Raspi?
https://github.com/hybridgroup/gobot/tree/master/platforms/raspi#enabling-pwm-output-on-gpio-pins
You can now install pi-blaster using Gort, by install Gort on your Raspiberry Pi and then running the gort raspi install piblaster command.
@deadprogram I haven't. Is it mandatory with rgb functions even if you don't want to modulate the pins, but just on/off?
Well, the assumption behind this particular driver is to have an LED that can support all of the RGB colors, which requires PWM. That should probably be documented upfront.
That said, if https://github.com/hybridgroup/gobot/blob/master/drivers/gpio/rgb_led_driver.go#L141 could be modified to handle your use case.
For example:
if level == 0 || level == 255 {
// use DigitalWriter instead of PwmWriter, cause we do not need it.
return
}
// current logic using PwmWriter
What do you think?
I installed pi-blaster and now everything is fine. You're right it makes sense to require it, if you want to just turn on/off single colors of a rgb led, you can probably use the LedDriver for them separately. Or like that in your example, I think it would work nicely.
Maybe it could be mentioned in the documentation though :)
Thanks!
Do you need Pi-Blaster even if you use the native PWM pins of the Raspberry Pi? There are four hardware PWM pins that I hope will work without PI-Blaster.
Unfortunately Gort can't build pi-blaster for me. And manually fails in the same way.
Hi @NomadMaker the PWM mapping of the Raspi Adaptor expects that pi-blaster is installed.
Can you please open a GH issue on Gort repo with details about your pi-blaster install issue?
The support for the build-in PWM of Raspi is implemented with #1048 and some examples are provided/adjusted. So I'm going to close this issue now.