Giter Site home page Giter Site logo

rpi_hardware_pwm's Introduction


CI

The Pioreactor is a mostly open source, affordable, and extensible bioreactor platform. The goal is to enable biologists, educators, DIYers, biohackers, and enthusiasts to be able to reliably control and study microorganisms.

We hope to empower the next generation of builders, similar to the Raspberry Pi's influence on our imagination (in fact, at the core of our hardware is a Raspberry Pi). However, the builders in mind are those who are looking to use biology, or computer science, or both, to achieve their goals. For research, the affordable price point enables fleets of Pioreactors to study large experiment spaces. For educators and students, the Pioreactor is a learning tool to study a wide variety of microbiology, electrical engineering, and computer science principles. For enthusiasts, the control and extensibility of the Pioreactor gives them a platform to build their next project on-top of.

Where can I get one?

Purchase on our website.

Documentation

All the documentation is available on our docs site.

rpi_hardware_pwm's People

Contributors

camdavidsonpilon avatar colinpate avatar kdmcmullan avatar suriyan 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

Watchers

 avatar  avatar  avatar  avatar  avatar

rpi_hardware_pwm's Issues

dtoverlay=pwm-2chan has no effect on RPi 5

I added dtoverlay=pwm-2chan to /boot/config.txt on a Raspberry Pi 5, but lsmod | grep pwm does not show any output.
Also there is no pwm-signal generated either on GPIO19 or 18.

PWM Set mode problem

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()

Question: frecvency

how to read this: pwm.change_frequency(25_000)?
25Hz or 25kHz?
if answer is 25Hz what means _000?

Invalid argument Error on change_frequency

Hi there,

When trying to change frequency I get an Invalid Argument error:

p = HardwarePWM(1, hz=200)
p.start(0)
p.change_duty_cycle(80)
p.change_frequency(50)
Traceback (most recent call last):
  File "/home/pi/.pycharm_helpers/pydev/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec
    exec(exp, global_vars, local_vars)
  File "<input>", line 1, in <module>
  File "/usr/local/lib/python3.7/dist-packages/rpi_hardware_pwm/__init__.py", line 98, in change_frequency
    self.change_duty_cycle(self._duty_cycle)
  File "/usr/local/lib/python3.7/dist-packages/rpi_hardware_pwm/__init__.py", line 91, in change_duty_cycle
    self.echo(dc, os.path.join(self.pwm_dir, "duty_cycle"))
  File "/usr/local/lib/python3.7/dist-packages/rpi_hardware_pwm/__init__.py", line 66, in echo
    f.write(f"{m}\n")
OSError: [Errno 22] Invalid argument

Frequency Setting off target

Using Rigol DS1054Z oscilloscope to measure the PWM output, I found to get 50.0hz, I had to set HardWarePWM to 46.7hz.
Setting function to 50hz, which is what is expected for SG-90 servos (really 20mS period), I was getting an output of 53.6hz or 18.66mS.

Otherwise I found this really easy to use and much more stable than software PWM that comes with Python library RPi.GPIO.
Too bad RPi only comes with 2 PWM channels, shared with the audio features of the RPi. I would have loved to use this for controlling RGB LED and get more stable results when using vPython.

Something similar to Mock.GPIO would have been nice

In my code I have this for the regular gpios:
try:
import RPi.GPIO as GPIO
except:
import Mock.GPIO as GPIO # If not running on rpi, mock gpio

Something similar for the hardware pwm would have been great!

rpi-hardware-pwm not working on RPi5

Just installed a fresh new raspbian OS and set up rpi-hardware-pwm. Python version is 3.11.2. Previously before updates the my code was doing just fine. Everything worked as expected. But now that I updated it the pwm_bcm2835 doesnt show up and if I run my code it gives me an error.

from rpi_hardware_pwm import HardwarePWM
import time

# Initialize the PWM channel on chip  2, channel  1, with a frequency of  50Hz
servo = HardwarePWM(pwm_channel=0, hz=50, chip=2)

def angleToSteps(angle):
    # This function converts an angle to a duty cycle.
    # You might need to adjust the formula based on your specific servo's requirements.
    # The original code uses a correction factor of  0.88, but this might need to be adjusted for your setup.
    correctionFactor =  0.9
    dutycycle =  2.4 + (angle /  18) * correctionFactor
    print(f"angle={angle}, dutycycle={dutycycle}")
    return dutycycle

def moveServo(angle, sleepVal):
    # Change the duty cycle to move the servo to the specified angle
    servo.change_duty_cycle(angleToSteps(angle))
    time.sleep(sleepVal)  # Wait for the servo to move
    servo.change_duty_cycle(0)  # Reset the duty cycle to stop the servo


try:
    servo.start(0.0)
    moveServo(0.0, 1.5)

    isTestAngleInput = True
    isTestAngleRange = False #False

    while isTestAngleInput:
        angle = float(input('Enter angle between  0 &  180 (enter angle<0 to exit): '))
        if angle<0:
            break
        moveServo(angle, 1.5)
        #time.sleep(1)  # Wait for a second before asking for the next angle
    if isTestAngleRange:
        for x in range(180):
            moveServo(x, 0.1)

finally:
    servo.stop()  # Stop the PWM signal
    print("Servo Stop")

The error I get is

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/niekas7/Desktop/zipas/testai/hardwarePWMangle.py", line 5, in <module>
    servo = HardwarePWM(pwm_channel=0, hz=50, chip=2)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/niekas7/.local/lib/python3.11/site-packages/rpi_hardware_pwm/__init__.py", line 62, in __init__
    self.change_frequency(hz)
  File "/home/niekas7/.local/lib/python3.11/site-packages/rpi_hardware_pwm/__init__.py", line 121, in change_frequency
    self.echo(int(per), os.path.join(self.pwm_dir, "period"))
  File "/home/niekas7/.local/lib/python3.11/site-packages/rpi_hardware_pwm/__init__.py", line 78, in echo
    with open(file, "w") as f:
OSError: [Errno 22] Invalid argument

No PWM output on GPIO12 (PWM0)

HI,

Thanks for the effort in putting the library up.

I have issues getting the PWM to output. I followed all the steps and i can see that the pwm module is correctly initialized with grep on terminal. But I do not get any output on the pin... This is my overlay : dtoverlay=pwm-2chan,pin=12,func=4,pin2=13,func2=4

I actively use GPIO 18, GPIO 13 and GPIO 19 could it be that PWM when instanciated necessarily is routed to all pins defined in overlay and some conflict is happening that I am not aware of ?

Thanks for any tip

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.