Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PWM issue on pi5 #28

Open
TheSkangel opened this issue Oct 9, 2024 · 3 comments
Open

PWM issue on pi5 #28

TheSkangel opened this issue Oct 9, 2024 · 3 comments

Comments

@TheSkangel
Copy link

Hello, I'm currently trying to run the PWM example on my pi5 but I keep getting the following error:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PWMerrorCode.pwmErrorOpen
#0      _checkError (package:dart_periphery/src/pwm.dart:120)
#1      PWM._openPWM (package:dart_periphery/src/pwm.dart:165)
#2      new PWM (package:dart_periphery/src/pwm.dart:150)
#3      main (package:flutter_pi_demo_app/main.dart:42)
#4      _runMain.<anonymous closure> (dart:ui/hooks.dart:301)
#5      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297)
#6      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184)

I'm using the GPIO18 and the following code:

import 'package:dart_periphery/dart_periphery.dart';
import 'dart:io';

void main() {
setCustomLibrary("/usr/local/lib/libperiphery_arm64.so");
  final pwm = PWM(2, 2);
  try {
    print('start');
    print(pwm.getPWMinfo());
    pwm.setPeriodNs(10000000);
    pwm.setDutyCycleNs(8000000);
    print(pwm.getPeriodNs());
    pwm.enable();
    print("Wait 20 seconds");
    sleep(Duration(seconds: 20));
    pwm.disable();
  } finally {
    pwm.dispose();
    print('end');
  }
 }

I tried accessing the provided documentation for pwm in the example but it seems like the provided url was hacked and now points to another website...
Linux kernel Linux 6.6.31+rpt-rpi-2712 aarch64
configurations are dtoverlay=pwm,pin=18,func=2.

I also tried using pwm directly with a bash file and there it works just fine:

#!/bin/bash
CHANNEL=2
CHIP=pwmchip2
PWM=pwm$CHANNEL

echo $CHANNEL > /sys/class/pwm/$CHIP/export
sleep 1
echo 1000 > /sys/class/pwm/$CHIP/$PWM/period
echo 500 > /sys/class/pwm/$CHIP/$PWM/duty_cycle
echo 1 > /sys/class/pwm/$CHIP/$PWM/enable

Does anybody had this issue before or does know how to fix it?

@pezi
Copy link
Owner

pezi commented Oct 9, 2024

dart_periphery comes will all needed libs on board.
// setCustomLibrary("/usr/local/lib/libperiphery_arm64.so");
What happens when you comment out this line?

@TheSkangel
Copy link
Author

TheSkangel commented Oct 9, 2024

I'm still getting the same error whether I set a custom library or use the libperiphery.so which is shared.

@pezi
Copy link
Owner

pezi commented Oct 9, 2024

Thanks for the hijacked PWM website - I wiil replace the URL.

I added your dtoverlay=pwm,pin=18,func=2 defintion to my RPI.

But on my RPI3 (32bit) this definition creates a
/sys/class/pwm/pwmchip0/pwm0
device tree

and the demo works: https://github.com/pezi/dart_periphery/blob/main/example/pwm_example.dart
dart pwm_example.dart

PWM 0, chip 0 (period=0.000000 sec, duty_cycle=nan%, polarity=normal, enabled=false)
10000000
Wait 20 seconds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants