Pioreactor / rpi_hardware_pwm

Access the hardware PWM of a Raspberry Pi
Other
58 stars 13 forks source link

PWM Set mode problem #3

Closed oussamajegham closed 2 years ago

oussamajegham commented 2 years ago

As you know to work with Hardware PWM you must enable it at /boot/config.txt .I did that and i set GPIO 19 as PWM1 . it works well . but I notice that after the Raspberry Pi boots the GPIO 19 gives a value . to stop that I used (sudo nano /etc/rc.local) to set GPIO at LOW state after startup , and it works . Now the Raspberry pi startups while GPIO 19 is LOW , but the problem is when I start the script the PWM is not working any more , a check GPIO states using gpio readall command . and I notice that the GPIO 19 still Output . It seems that the GPIO still at ALT1 position. So how can I change the GPIO to ALT5 to work with PWM ? what must i write in python code to select ALT5 for GPIO19

Notice: To understand what ALT mean check this LINK

This is my code :

from time import sleep
from rpi_hardware_pwm import HardwarePWM
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)

GPIO.setup(37, GPIO.OUT)
pwm = HardwarePWM(1, hz=500) # Hardware PWM1 GPIO 19 (use sudo nano /boot/config.txt to change )
pwm.start(100) 

for i in range (40,71,1): 
   pwm.change_duty_cycle(i)
   print(i)
   sleep(0.12)

GPIO.output(37, GPIO.HIGH)      # relay is on 

try:
 while True :

  a=int(input())                   
  if (a == 0):
    GPIO.output(37, GPIO.LOW)

  pwm.change_duty_cycle(a)

except:                     
   pwm.stop()
   GPIO.cleanup()
CamDavidsonPilon commented 2 years ago

Hi @0U55AMA, I'll try to help. First, what do you by:

but I notice that after the Raspberry Pi boots the GPIO 19 gives a value

What value? Like it outputs a HIGH?