title: How to control PWM pin on Raspi in Go, like I do in Python?
body: <p>I've got a Raspberry Pi 3B with which I want to control a motor using <a href="https://en.wikipedia.org/wiki/Pulse-width_modulation" rel="nofollow noreferrer">PWM</a>. In Python this works great to gradually increase the voltage of a GPIO pin from 0% to 100% (100% == 3.3V):</p>
  <pre><code>import RPi.GPIO as GPIO
  from time import sleep
  
  PWM_PIN = 13
  
  GPIO.setmode(GPIO.BCM)
  GPIO.setup(PWM_PIN, GPIO.OUT)
  
  p = GPIO.PWM(PWM_PIN, 1000)
  p.start(0)
  
  for i in range(101):
      print(i)
      p.ChangeDutyCycle(i)
      sleep(0.1)
  
  sleep(5)  # Keep the voltage at 100% for 5 seconds, after which the program ends
  </code></pre>
  <p>Since I'm writing my program in Go I now want to do the same thing (or similar) in Go. So this is my shot at it.</p>
  <pre><code>package main
  
  import (
      &quot;fmt&quot;
      &quot;time&quot;
      rpio &quot;github.com/stianeikeland/go-rpio&quot;
  )
  
  const (
      PWM_PIN = 13
  )
  
  func main() {
      err := rpio.Open()
      if err != nil {
          panic(err)
      }
  
      motor_pin_pwm := rpio.Pin(PWM_PIN)
      motor_pin_pwm.Mode(rpio.Pwm)
      motor_pin_pwm.Freq(1000)
      motor_pin_pwm.DutyCycle(0, 100)
      
      fmt.Println(&quot;Waiting...&quot;)
      time.Sleep(5 * time.Second)
      fmt.Println(&quot;Start the increase...&quot;)
  
      for i := 1; i &lt;= 100; i++ {
          fmt.Println(i)
          motor_pin_pwm.DutyCycle(uint32(i), 100)
          time.Sleep(100 * time.Millisecond)
      }
      time.Sleep(5 * time.Second)
  }
  </code></pre>
  <p>There's <a href="https://github.com/stianeikeland/go-rpio/blob/master/examples/pwm/pwm.go" rel="nofollow noreferrer">an example of using go-rpio to control PWM here</a>. The example is meant to control a LED instead of a motor, but I guess the code should be very similar (if not the same). The example uses different values, so I messed around with the values a bit but with no results.</p>
  <p>What am I missing here?</p>