Git Product home page Git Product logo

go-rpio's People

Contributors

akramer avatar b3nn0 avatar codelingobot avatar dotdoom avatar drahoslove avatar kbudde avatar nox-404 avatar omardelarosa avatar pier-oliviert avatar stianeikeland avatar tmsmr avatar wfd3 avatar youngkin avatar yuku avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-rpio's Issues

Pin is being read low after being pull up resistor set

	if err := rpio.Open(); err != nil {
		fmt.Println(err)
		b.GPIOEnabled = false
		return
	} else {
		b.GPIOEnabled = true
	}

	ButtonPinPullUp := rpio.Pin(ButtonPin)
	ButtonPinPullUp.PullUp()

	res2 := ButtonPinPullUp.Read()
	fmt.Printf("Read after pull-up: %v\n", res2)
user@host:~ $ ~/executable
Read after pull-up: 0

Am I incorrect in my understanding that an input pin connected to a pull-up resistor should read high after being set to pull-up?

Setting active_high=False with go-rpio

Hi!

In the standard gpio python library you have an option to active_high=False, do you have that in this library for go?

Python code:

pin = gpiozero.OutputDevice(2, active_high=False)

Because now the go code looks bonkers, when I want to send a HIGH signal for two seconds on GPIO 2 I have to write the opposite:

func openDoor() {
	doorRemote.Low()
	time.Sleep(time.Second * 2)
	doorRemote.High()
}

Excerpt from the docs:

active_high (bool) – If True (the default), the on() method will set the GPIO to HIGH. If False, the on() method will set the GPIO to LOW (the off() method always does the opposite).

Go mod not getting the latest version

Using the mod feature of newly released go1.11 and importing go-rpio as a library causes a downgrade to v3.0.0.

In go.mod file, the version is listed as github.com/stianeikeland/go-rpio v3.0.0+incompatible, where:

  • v3.0.0 is the larges version tagged following the SIV, since 4.0.0 and 4.1.0 are missing v so they are ignored.
  • +incompatible prevent the import path from adding the major version.

Adding the tags v4.0.0 and v4.1.0 should fix the immediate problem.

more information about +incompatible flag form another Go project.

Dockerize?

Anybody ever dockerize an app using this library on a raspberry pi? Is it as simple as just making a volume for /dev/mem?

@stianeikeland If you can share any other files / devices the library needs access to that'd be awesome

A way to set inbetween low and high

I'm working with an RGB led strip and i'd like to be able to control the brightness via the gpio, but with this lib i only get High or Low, no way to do it in between.

Just wondering if it's possible?

Thanks.

Hardlock when EdgeDetect is used

I found a small issue with the library. For some reason when rpio is close and EdgeDetect is still enable it will hard lock the rpi. i tested it on both a pi3 and pi4. if i call pin.Detect(rpio.NoEdge) before close nothing locks up and everything is fine. I don't have any logs unfortunately dmsg and the kernel log give no insight.

go version: go1.17 linux/arm64
kernel version (uname-a): Linux XXXX 5.13.0-1013-raspi #15-Ubuntu SMP PREEMPT Fri Jan 7 23:16:57 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux
go-rpio version: 4.5.1

Orange PI support?

I try go-rpio with an Orange PI Lite board to toggle the BCM pin 6 but it does not work. I note that the board works fine with WiringOP and .net iot. Does go-rpio actually support Orange PI boards?

add GPIO frequency detection

Hi,

I think it would be very useful if you can add a function which measure the frequency a GPIO pin change status. This will allow to interface with a multitude of sensors.
Some examples of implementation in C are here: http://abyz.me.uk/rpi/pigpio/examples.html#C_code
Arduino core library has a conceptually similar functio called pulseIn:
https://www.arduino.cc/reference/en/language/functions/advanced-io/pulsein/

I tried to use a loop with pin.EdgeDetected() and a microsecond sleep but my RPI freezes all the time.

Thanks

pullup does not work on RPI 4 B

I tried to build and run the pullup example https://github.com/stianeikeland/go-rpio/blob/master/examples/pullup/pullup.go. But it does not build, see error message:

pi@raspberrypi ~/g/e/pullup> go build
# github.com/stianeikeland/go-rpio/v4/examples/pullup
./pullup.go:26:48: pin.ReadPull undefined (type rpio.Pin has no field or method ReadPull)
./pullup.go:30:50: pin.ReadPull undefined (type rpio.Pin has no field or method ReadPull)
note: module requires Go 1.13~

After I removed the ReadPull() call, I got the following output:

pi@raspberrypi ~/g/e/pullup> ./pullup
PullUp: 0, 0
PullDown: 0, 0

That means PullUp does not work.

Prevent running tests on wrong platforms

Go can restrict compilation with build tags. It would be nice if the code refused to build/run tests on non-Raspberry, or at least non-ARM platforms.

// +build arm for any code that touches hardware would be a good safety net.

Input interrupts

Hi,

Have you considered adding input interrupts? You can get them from the files exposed by sysfs in /sys/class/gpio. I've made a library which does this at https://github.com/brian-armstrong/gpio

sysfs can also expose i2c and spi if you uncomment the modules in /boot/config.txt and then reboot. This might be an easy way for you to add i2c and spi functionality as well.

Errors on go get

I get the following output when I get this package. I'm running Windows 10 with go version go1.5.1 windows/amd64

> go get github.com/stianeikeland/go-rpio
# github.com/stianeikeland/go-rpio
..\..\..\github.com\stianeikeland\go-rpio\rpio.go:290: undefined: syscall.Mmap
..\..\..\github.com\stianeikeland\go-rpio\rpio.go:294: undefined: syscall.PROT_READ
..\..\..\github.com\stianeikeland\go-rpio\rpio.go:294: undefined: syscall.PROT_WRITE
..\..\..\github.com\stianeikeland\go-rpio\rpio.go:295: undefined: syscall.MAP_SHARED
..\..\..\github.com\stianeikeland\go-rpio\rpio.go:315: undefined: syscall.Munmap

I assume this has something to do with: https://golang.org/s/go1.4-syscall

strangely, does *not* work with sudo

I'm having a very strange issue here, hopefully someone can shed some light on the subject.

go 1.14, raspberry pi 4 B+

using the blinker.go example:

./blinker works just fine
sudo ./blinker makes nothing happen.

Why is this? Normally that would be fine, except that I'm trying to use rpio along with a dht11 library that requires root access to run. I find it perplexing that running rpio with heightened privileges causes it to not work.

Device is stuck on EdgeDetected

I'm running this code (just experimenting for now) and after some time (about 1 minute) device is going to be stuck.
(I did the same actions with another languages: python, nodejs, but nothing, everything works stable and great, but when running this go application - I have a stuck and need just manually disconnect device from power supply and enable again).

I have Raspberry Pi 3 Model B.
Hardware : BCM2835
Revision : a22082

Kernel: 4.19.58-v7+

Distributor ID: Raspbian
Description: Raspbian GNU/Linux 10 (buster)
Release: 10
Codename: buster

package main

import (
	"fmt"
	"github.com/stianeikeland/go-rpio"
	"log"
	"time"
)

func main() {
	err := rpio.Open()
	if err != nil {
		log.Fatal(err)
	}

	ch := make(chan struct{})

	pin := rpio.Pin(10)
	pin.Input()
	pin.PullUp()
	pin.Detect(rpio.FallEdge)

	lastTime := time.Now().UnixNano() / 1000000

	go func() {
		for {
			if pin.EdgeDetected() {
				now := time.Now().UnixNano() / 1000000
				diff := now - lastTime
				lastTime = now
				fmt.Println("Heyhey!", diff)
			}
			time.Sleep(time.Millisecond * 10)
		}
	}()
	fmt.Println("init")

	<-ch
}

Corrupts gpiomem as non-root

The following code from rpio.Open implies that /dev/mem and /dev/gpiomem are equivalent, the latter only ignores certain writes:

	// Open fd for rw mem access; try dev/mem first (need root)
	file, err = os.OpenFile("/dev/mem", os.O_RDWR|os.O_SYNC, 0)
	if os.IsPermission(err) { // try gpiomem otherwise (some extra functions like clock and pwm setting wont work)
		file, err = os.OpenFile("/dev/gpiomem", os.O_RDWR|os.O_SYNC, 0)
	}

However judging from http://www.macs.hw.ac.uk/~hwloidl/hackspace/linux/drivers/char/broadcom/bcm2835-gpiomem.c, /dev/gpiomem only maps the GPIO page.

The following program, running as non-root only, crashes a Raspberry 3 Model B+ latest at the first attempt to set the duty cycle. Crashing means “not reachable via IP anymore” in my case, presumably because random GPIO memory was overwritten.

package main

import (
        "fmt"
        rpio "github.com/stianeikeland/go-rpio"
        "time"
)

func main() {
        rpio.Open()
        defer rpio.Close()

        p := rpio.Pin(12)
        p.Mode(rpio.Pwm)
        p.Freq(4688 * 0xFFFF)
        for i := 0; i <= int(^uint16(0)); i++ {
                fmt.Println("setting", i)
                p.DutyCycle(uint32(i), 0xffff)
                time.Sleep(10 * time.Millisecond)
        }
}

cannot find package "github.com/stianeikeland/go-rpio/v4"

Hi,

when importing the package for v4 like

import "github.com/stianeikeland/go-rpio/v4"

I get this error:

main.go:32:2: cannot find package "github.com/stianeikeland/go-rpio/v4" in any of:
/usr/local/go/src/github.com/stianeikeland/go-rpio/v4 (from $GOROOT)

go get github.com/stianeikeland/go-rpio/v4

cannot find package "github.com/stianeikeland/go-rpio/v4" in any of:
/usr/local/go/src/github.com/stianeikeland/go-rpio/v4 (from $GOROOT)

returns the same error. What am I missing here?

traffic light test faild on RPi 4

go version: go version go1.12.9 linux/arm

export GO111MODULE=on

go code:

import (
        "log"
        "time"

        rpio "github.com/stianeikeland/go-rpio"
)

func main() {

        err := rpio.Open()
        if err != nil {
                log.Fatalf("open rpio error %v", err)
        }
        defer rpio.Close()

        red := rpio.Pin(13)
        red.Output()

        red.Low()

        for {
                red.High()
                time.Sleep(time.Second)
                red.Low()
                time.Sleep(time.Second)
        }
}

we i run my binary, the red light didn't respond.

pinout

,--------------------------------.
| oooooooooooooooooooo J8   +======
| 1ooooooooooooooooooo  PoE |   Net
|  Wi                    oo +======
|  Fi  Pi Model 4B  V1.1 oo      |
|        ,----.               +====
| |D|    |SoC |               |USB3
| |S|    |    |               +====
| |I|    `----'                  |
|                   |C|       +====
|                   |S|       |USB2
| pwr   |HD|   |HD| |I||A|    +====
`-| |---|MI|---|MI|----|V|-------'

Revision           : b03111
SoC                : BCM2711
RAM                : 2048Mb
Storage            : MicroSD
USB ports          : 4 (excluding power)
Ethernet ports     : 1
Wi-fi              : True
Bluetooth          : True
Camera ports (CSI) : 1
Display ports (DSI): 1

J8:
   3V3  (1) (2)  5V
 GPIO2  (3) (4)  5V
 GPIO3  (5) (6)  GND
 GPIO4  (7) (8)  GPIO14
   GND  (9) (10) GPIO15
GPIO17 (11) (12) GPIO18
GPIO27 (13) (14) GND
GPIO22 (15) (16) GPIO23
   3V3 (17) (18) GPIO24
GPIO10 (19) (20) GND
 GPIO9 (21) (22) GPIO25
GPIO11 (23) (24) GPIO8
   GND (25) (26) GPIO7
 GPIO0 (27) (28) GPIO1
 GPIO5 (29) (30) GND
 GPIO6 (31) (32) GPIO12
GPIO13 (33) (34) GND
GPIO19 (35) (36) GPIO16
GPIO26 (37) (38) GPIO20
   GND (39) (40) GPIO21

For further information, please refer to https://pinout.xyz/

lscpu:

Architecture:        armv7l
Byte Order:          Little Endian
CPU(s):              4
On-line CPU(s) list: 0-3
Thread(s) per core:  1
Core(s) per socket:  4
Socket(s):           1
Vendor ID:           ARM
Model:               3
Model name:          Cortex-A72
Stepping:            r0p3
CPU max MHz:         1500.0000
CPU min MHz:         600.0000
BogoMIPS:            108.00
Flags:               half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32

and when i use python to test , it works.

#!/usr/bin/env python

import RPi.GPIO as GPIO
import time

RED = 13

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(RED, GPIO.OUT)

def Close():
        GPIO.output(RED,False)

try:
        while(1):
            GPIO.output(RED,True)
            time.sleep(1)
            GPIO.output(RED,False)
            time.sleep(1)
except KeyboardInterrupt:
        Close()
        pass


Event based input detection - proposal

Hi, I'd like to contribute again and implement functionality inspired by this bcm2835 lib example.

(In my eyes this has higher priority than software pwm duscussed in #20)

Reason

The use case is, when you want to detect short input signal, eg. fast button press (or something much much shorter), and you don't want to waste much CPU (prevent rapid pooling), but you don't mind waiting a bit to actually process the action.

Let's say the button accuation time when pressed may be as short as 10ms. In current stage, only way to reliably detect it is to sample input every 5ms, like in following example.

pin.Input()
for {
	if pin.Read() == rpio.High {
		println("button pressed")
	}
	time.Sleep(5*time.Millisecond) // wait time determines shortes detectable signal length
}

This is not much CPU effecient for long running instances.

Solution

I propose to use rise/fall edge event detection (without interruption handling like in github.com/brian-armstrong/gpio, but it would still be an improvement).

Two new pin method would be implemented. (Better naming ideas are welcomed).

  • func(pin) Detect(edge) - for enabling/disabling detection of rising and/or falling edge event
    • It would write to GPREN and GPFEN registers - this functionality scans pins using clock and detect 011 and/or 100 patterns.
    • The edge argument would be one of: NoEdge, RiseEdge, FallEdge, AnyEdge.
  • func(pin) EdgeDetected() bool - for checking if event has occured since last call
    • done by reading and cleaning bits of GPEDS register

Example of usage:

pin.Input()
pin.Detect(rpio.RiseEdge)

for {
	if pin.EdgeDetected() {
		prinln("button pressed")
	}
	time.Sleep(500*time.Millisecond)
 	// wait time only affect user experience; signal length may be as short as two CLK ticks

}

It would (partially) solve issues #18.

In the future this functionaluty might be extended over intteruption handling using blocking channel, which would avoid the neccessity to use any sleeps.

I will create pull request soon, if there are no objections.

RPI 4 B PWM not working

I know this has been mentioned in several other issues but I am putting it here for a specific issue.

I'm running on a RPI 4 Model B. Running output on Pin 18 and setting the pin to High works. Setting the same Pin 18 to PWM and setting it to a 100% duty cycle does not work.

I'm running the program as root.

There has been suggestions made that the PWM functionality was fixed for the RPI 4. This does not appear to be the case.

SPI Locking?

Converted a driver for TLC95711 pwm board which uses SPI. I got it working fully with one weird issue when I have to rpio.Open() within the same function when I am writing to SPI.

With that being said, I found an issue when looping though colors and sending it through SPI, I am getting a "memory issue" according to the panic that gets thrown. I figure it's being caused when writing to SPI while a previous write hasn't finish being sent just yet. I have set up sleeps but you really can only delay so long before effects don't look right.

Would it be possible to add Locking capabilities similar to Arduino?

Running build vs file

I couldn't get the blinker.go example to work when I did

go run blinker.go

But when I build the file it works fine.

./blinker

Is there a way to just run the file to speed up the prototyping process?

Unable To Find Compatible WiringPi Pinouts With This Library

I'm currently trying to write a golang equivalent of this Raspberry Pi LoRa hot module, which uses wiringPi pniouts.

I've tried the wiringPi pin out numbers in this golang library using go-rpio and I'm unable to get it to work properly, and it fails with a unrecognized traceiver error.

It should be noted that running the provided dragino examples works, so it can definitely work from this library, it's just a matter of figuring out the pin differences

System Info

Model: Raspberry Pi 3B+

No LSB modules are available.
Distributor ID:	Raspbian
Description:	Raspbian GNU/Linux 9.11 (stretch)
Release:	9.11
Codename:	stretch
Linux rpi3 4.19.66-v7+ #1253 SMP Thu Aug 15 11:49:46 BST 2019 armv7l GNU/Linux

[BUG] Issues using SPI and GPIO with

I am porting over the python for the waveshare 128x128 1.44in GPIO LCD display (ST7735S),

The pins that control the buttons are by default, value 1 when no input is provided, and are dropped to value 0

The moment i use a SPI function from this library, pins 21 and 20 (key 1 and key2 respectively) are set to 0 and their state cannot be altered until either the pi Reboots, or i run the original python code, which has a gpio.cleanup function that fixes this issue on runtime.

https://pastebin.com/L1kJXVax < main.go
https://pastebin.com/3mBfE0JD < lcd.go

Nice library but seems PWM is behaving a bit strangely

Perhaps it's just me but whenever I try to use PWM the BCM pin 2 changes from ALT0 to ALT2 and suddenly it's no longer possible to use ADC chips to for example read the value of a Rotary Potentiometer and then controlling a DC motor using PWM. Doesn't seem to matter if I use PWM on BCM pin 12 or BCM 13.

Using Raspberry PI 4.

Pi4 PWM frequency wrong

Hi,
I noticed some oddities with the PWM frequency when using this library, so I double-checked with a scope.. and indeed it's off.
e.g. when using pin.Freq(64000) I'd expect a frequency of 64khz. However, I get 1.8khz on my scope.
This seems to be because of a wrong assumption about the oscillator frequency. In rpio.go, it says

const sourceFreq = 19200000 // oscilator frequency`

However, this is not correct for the PI4. According to
https://raspberrypi.stackexchange.com/questions/100622/is-default-pwm-frequency-19-2mhz-in-raspberry-3#:~:text=1%20Answer&text=The%20crystal%20oscillator%20is%2019.2,has%20a%2054%20MHz%20oscillator
the PI4 has a frequency of 54Mhz. And indeed, changing the code to

const sourceFreq = 54000000 // oscilator frequency

fixes it somewhat. However, it is still wrong by a factor of 100 - I now get a 640Hz PWM instead of a 64k PWM.

Changing it to

const sourceFreq = 540000 // oscilator frequency

now finally gives a correct result (but I guess the method is wrong - I assume the real bug is somewhere further down, but didn't check further).

[Feature request / clarification] servo pulse width

Hey everyone,

first, thank you very much for creating this library. Right now, I try to build an autonomous drone and I would love use go-lang (I am a beginner in electronics and go-lang) for learning. Similar libraries written in in nodejs and python usually just use the c-library. They offer a mehod called setPulseWidth that uses set_servo_pulsewidth in C. Are there any plans to implement it in go-rpio?

Right now, I don't feel like I can help. But maybe this issue is also a good way to clearify things. In theory, I read that pulse width, duty cycle and frequency are related. Actually, it should be possible to use casual PWM in combination with duty cycle and frequency or am I wrong?

I just tried it, set the frequency to 50 and set a duty cycle like 50 % without success. Maybe you have an idea where to start or even better, how I can use the existing implementation to mimic the (servo-)pulseWidth implementation of other libraries.

Thanks in advance

(Keep up the good work!)

EdgeDetection crashes Raspberry Pi 3

Using Detect and running a very basic program on the Raspberry Pi 3, will result in the whole Raspberry Pi locking up (and needing a forced restart).
This only happens on a pin with very many rises/falls, currently I am using this for a RF receiver, so there are quite a lot of rises/falls.

The code I am using is this ...

package main

import (
	"fmt"
	"time"

	rpio "github.com/stianeikeland/go-rpio"
)

// This program is just going to be
// a POC of the sender working.
// This should and WILL be cleaned up
// I do not care, I will not fucking
// write the report without having
// the time to do this properly

// Raspberry Pi 3 GPIO
// https://i.imgur.com/PPFf2ul.png
const rx_pin_nr = 2

var preamble = [8]int{1, 0, 1, 0, 1, 0, 1, 0}
var sfd = [8]int{1, 0, 1, 0, 1, 0, 1, 1}
var rx_pin rpio.Pin

func main() {
	// initialize go-rpio
	err := rpio.Open()

	if err != nil {
		fmt.Println(err)
	}

	// set our pin as a output
	rx_pin = rpio.Pin(rx_pin_nr)
	rx_pin.Input()
	rx_pin.Detect(rpio.RiseEdge)

	for {
		// sendData(test)
		fmt.Println("Running stuff")
		time.Sleep(100 * time.Millisecond)
	}
}

func check_sync() {

}

Not even doing anything with it. I don't know what the solution would be, but I think that we could get the interrupt etc. if we used such a system as epoll (http://man7.org/linux/man-pages/man7/epoll.7.html), I know it is uses for another Go system for GPIO interaction here - https://godoc.org/github.com/kidoman/embd

Error in rpio.Open()

Hi!

I catch this when I try to open memory range for GPIO access in /dev/mem:
open /dev/mem: permission deniedpanic: runtime error: index out of range.

I try this script and add my user to group "gpio", but nothing changed.

How can I solve this problem?

How would I translate this Python PWM code to go with go-rpio?

I'm trying to convert some working Python code to run in go. The Python is as follows:

import RPi.GPIO as GPIO
import time

servoPIN = 13
GPIO.setmode(GPIO.BCM)
GPIO.setup(servoPIN, GPIO.OUT)

p = GPIO.PWM(servoPIN, 50) # GPIO 13 for PWM with 50Hz
p.start(2.5) # Initialization
try:
  while True:
    p.ChangeDutyCycle(5)
    time.sleep(0.5)
    p.ChangeDutyCycle(7.5)
    time.sleep(0.5)
    p.ChangeDutyCycle(10)
    time.sleep(0.5)
    p.ChangeDutyCycle(12.5)
    time.sleep(0.5)
    p.ChangeDutyCycle(10)
    time.sleep(0.5)
    p.ChangeDutyCycle(7.5)
    time.sleep(0.5)
    p.ChangeDutyCycle(5)
    time.sleep(0.5)
    p.ChangeDutyCycle(2.5)
    time.sleep(0.5)
except KeyboardInterrupt:
  p.stop()
  GPIO.cleanup()

This Python code works. The servo moves constantly.

So I tried translating the code to Go using go-rpio. I got to this:

package main

import (
	"fmt"
	rpio "github.com/stianeikeland/go-rpio"
	"time"
)
const PWM_PIN_NUMBER = 13

func main() {
	err := rpio.Open()
	if err != nil {
		panic("Opening the pin goes wrong")
	}

	defer rpio.Close()

	pin := rpio.Pin(PWM_PIN_NUMBER)
	fmt.Println(pin)
	pin.Mode(rpio.Pwm)
	pin.Freq(50)
	pin.DutyCycle(0, 50)

	for {
		fmt.Println(5)
		pin.DutyCycle(uint32(5), 50)
		time.Sleep(1 * time.Second)

		fmt.Println(7)
		pin.DutyCycle(uint32(7), 50)
		time.Sleep(1 * time.Second)

		fmt.Println(10)
		pin.DutyCycle(uint32(10), 50)
		time.Sleep(1 * time.Second)

		fmt.Println(12)
		pin.DutyCycle(uint32(12), 50)
		time.Sleep(1 * time.Second)

		fmt.Println(10)
		pin.DutyCycle(uint32(10), 50)
		time.Sleep(1 * time.Second)
	}
}

The code runs, but the servo doesn't move at all.

Does anybody know what I'm doing wrong here?

Pico

It's this package working with the newly released raspberry pi pico controllet?

Rpi no boot after pwm

I've launched code on my raspberry pi 3b+ which is simillar to this https://github.com/stianeikeland/go-rpio/blob/master/examples/pwm/pwm.go
on my raspberry pi 3b+

func main() {
        err := rpio.Open()
        if err != nil {
                os.Exit(1)
        }
        defer rpio.Close()

        pin := rpio.Pin(7)
        pin.Mode(rpio.Pwm)
        pin.Freq(60*60)
        pin.DutyCycle(0, 60)
        // the LED will be blinking at 60Hz
        // (source frequency divided by cycle length => 60*60/60 = 2000)
}

iirc it was exactly like this. After running it ssh freezed and after restarting raspberry, wont boot again. Do you know what could be the problem?

Error in ReadPin for higher pins.

go-rpio/rpio.go

Line 214 in 896db2e

if (mem[levelReg] & (1 << uint8(pin))) != 0 {

I know, that it does not matter much because pins with the number higher than 31 are not really accessible on board. But for consistency with WritePin, I think it should be fixed to:
if (mem[levelReg] & (1 << uint8(pin & 31))) != 0 {

New release

Hello, could a new tag be made? So RPI 4 works accordingly. Right now using:
github.com/stianeikeland/go-rpio/v4 v4.4.1-0.20200705092735-acc952dac3eb
also works for my modules file, but would be nice to have a more common way to approach this

Raspberry Pi Zero W compatibility issue

Tested on Raspberry Pi Zero W
OS Version: RASPBIAN STRETCH LITE (Release Date: 2018-06-27)
Kernel Version: Linux raspberrypi 4.14.52+ #1123 Wed Jun 27 17:05:32 BST 2018 armv6l GNU/Linux
Go Version: go1.10.3 linux/arm
Problems: I connect to pi via ssh, system freeze after initialize GPIO, but the same code works well on Raspberry Pi 3 which has the same OS Version, Kernel Version and Go Version.
sample code:

const (
	io1    = uint8(5)
	rst    = uint8(13)
	intIn  = uint(26)
	intOut = uint(21)
)
var outPin rpio.Pin
var inPin rpio.Pin
func startGPIO() {
	err := rpio.Open()
	if err != nil {
		log.Fatal(err)
	}
	log.Info("open rpio successfully")
	io1Pin := rpio.Pin(io1)
	io1Pin.Output()
	io1Pin.Low()

	rstPin := rpio.Pin(rst)
	rstPin.Output()
	rstPin.High()

	outPin = rpio.Pin(intOut)
	outPin.Input()
	outPin.Detect(rpio.FallEdge)

	inPin = rpio.Pin(intIn)
	inPin.Output()
	inPin.High()
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.