Jump to content

Dara Ó hEidhin

Members
  • Posts

    2
  • Joined

  • Last visited

Posts posted by Dara Ó hEidhin

  1. Based on page 174 in the usermanual (https://drive.google.com/file/d/1TogN8KUzQKUH1DTtjWBQA1aFVhquG_PJ/view?pli=1)


    install the python rpc library

    pip install rpyc


    log in as root and create the following server.py file

    # server.py

    # server.py
    import rpyc
    from rpyc.utils.server import ThreadedServer
    from subprocess import  PIPE, run
    
    @rpyc.service
    class TestService(rpyc.Service):
        PINS = {2:"pwmchip5"}
    
        def bash(self, cmdstr:str):
            '''Run shell command
    
            Args:
                cmdstr (str): shell command string
            '''
            try:
                cmd = run(
                    cmdstr, stdout=PIPE, encoding="ascii", shell=True
                )
            except Exception as e:
                print(cmdstr)
                print(e)
    
        @rpyc.exposed
        def pwm(self, pin: int, period: int, duty_cycle: int) -> str:
            '''Set PWM 
    
            Args:
                pin (int): wiringpi pin number
                period (int): set period
                duty_cycle (int): set duty cycle
    
            Returns:
                str: _description_
            '''
            chip = self.PINS[pin]
            c1 = f"echo 0 > /sys/class/pwm/{chip}/export"
            c2 = f"echo {period} > /sys/class/pwm/{chip}/pwm0/period"
            c3 = f"echo {duty_cycle} > /sys/class/pwm/{chip}/pwm0/duty_cycle"
            c4 = f"echo 1 > /sys/class/pwm/{chip}/pwm0/enable"
    
            for cmdstr in [c1,c2,c3,c4]:
                self.bash(cmdstr)
    
    
            return f"Success: {pin=} {period=} {duty_cycle=} {chip=}"
        
        @rpyc.exposed
        def disable(self) -> str:
            self.bash("echo 0 > /sys/class/pwm/{chip}/pwm0/enable")
    
            return 'Success'
        
    print('starting PWM server')
    server = ThreadedServer(TestService, port=18811)
    server.start()

     

    This can be automatically started at boot and as root using crontab

    Then use the following snippet as the regular non root user

    import rpyc
    
    connection = rpyc.connect("localhost", 18811)
    print(connection.root.pwm(2, 20000000, 5000000))

     

    This creates a 50Hz where the pwm arguments are (pin, period, duty_cycle)

    you may need to add to or edit line 8 in the server code to set up your pwm pins

    PINS = {2:"pwmchip5"}

    You may need to enable these pins as per page 172 of the doc above (see image below)

    image.png.4d00d357160d20fb11a01f4d24a3b65a.png

  2. For anyone else here's what worked for me.

    1. Download latest armbian image from here
    https://www.armbian.com/orangepi-5/
    2. Follow the instructions at the youtube video below to install the image to EMMC. Ensure you use the armbian image. This image won't load as mentioned above

    3. Burn the same image to sdcard and install sdcard in pi 5b. I used Rufus on Win11 (https://rufus.ie/en/)
    4. Boot up. SD card boots as default
    5. Edit the armbianEnv.txt file in the /boot folder and replace the line:

    fdtfile=rockchip/rk3588s-orangepi-5.dts 
    with
    fdtfile=rockchip/rk3588s-orangepi-5b.dts
    6. reboot
    7. NB! unmount the current /boot folder using the following command in terminal

    sudo umount /boot

    This unmounts the current boot partition stored in the sdcard

    8. use terminal to open gparted

    sudo gparted

    9. Select the EMMC drive from the top right dropdown
    10. Right-click on boot partition and mount on /boot. This mounts the boot partition of the emmc drive
    11. edit txt file as per 5. above
    12. shutdown and remove sdcard
    13. reboot

    14. using terminal run the command below to setup pi. Bluetooth/Wifi were working perfectly

    sudo armbian-config

     15. Still working on GPIO access ..... 😶‍🌫️. If anyone has any tips to get this working through Python please let me know.
     

     

     

     

×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines