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 problem #16

Closed
yorklai opened this issue Jul 26, 2016 · 20 comments
Closed

pwm problem #16

yorklai opened this issue Jul 26, 2016 · 20 comments

Comments

@yorklai
Copy link

yorklai commented Jul 26, 2016

i use 4.4 or 4.3 firmware:
I follow your sample will found error:

import CHIP_IO.SOFTPWM as SPWM
SPWM.start("XIO-P7", 50)
SPWM.set_duty_cycle("XIO-P7", 25.5)
Traceback (most recent call last):
File "", line 1, in
RuntimeError: You must start() the PWM channel first

@ervinoro
Copy link

this is just recently fixed problem: #14

@xtacocorex
Copy link
Owner

Well, I didn't verify in my spwmtest.py script of changing the duty cycle that way, so there could still be an issue. Will try to look this over tonight.

@hbradio
Copy link
Collaborator

hbradio commented Jul 26, 2016

Let me know what you find if you check it out tonight, @xtacocorex. I didn't retest that case either, but it can look at it tomorrow morning if it is indeed a legit bug.

@xtacocorex
Copy link
Owner

@yorklai, what version of CHIP_IO are you using?

What happens if you do the following from the Python shell:
import CHIP_IO.GPIO as GPIO
print GPIO.VERSION

I'm running 0.2.1 and this isn't an issue. I believe @aninternetof fixed it yesterday for Issue#14.

@yorklai
Copy link
Author

yorklai commented Jul 27, 2016

I try Pocketchip (4.3 firmware):

Python 2.7.9 (default, Mar 1 2015, 13:48:22)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import CHIP_IO.GPIO as GPIO
print GPIO.VERSION
0.2.1

try SOFTPWM sample code:

Python 2.7.9 (default, Mar 1 2015, 13:48:22)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import CHIP_IO.SOFTPWM as SPWM
SPWM.start("XIO-P7", 50)
SPWM.set_duty_cycle("XIO-P7", 25.5)Traceback (most recent call last):
File "", line 1, in
RuntimeError: You must start() the PWM channel first

2016-07-27 9:52 GMT+08:00 Robert Wolterman notifications@github.com:

@yorklai https://github.com/yorklai, what version of CHIP_IO are you
using?

What happens if you do the following from the Python shell:
import CHIP_IO.GPIO as GPIO
print GPIO.VERSION

I'm running 0.2.1 and this isn't an issue. I believe @aninternetof
https://github.com/aninternetof fixed it yesterday for Issue#14.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#16 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ALzCrr-aENS8kpSbocFt7b0GENKl9zNCks5qZrnXgaJpZM4JVRnM
.

@yorklai
Copy link
Author

yorklai commented Jul 27, 2016

The C.H.I.P 4.4 firmware (any) have bug:

Pocketchip(4.3 firmware):

chip@chip:/sys/class/pwm/pwmchip0$ lsdevice export npwm power
subsystem uevent unexport
chip@chip:/sys/class/pwm/pwmchip0$

C.H.I.P (4.4 Gui no limit firmware):

chip@chip:~$ cd /sys
chip@chip:/sys$ cd class
chip@chip:/sys/class$ cd pwm
chip@chip:/sys/class/pwm$ ls
chip@chip:/sys/class/pwm$ ls -l
total 0
chip@chip:/sys/class/pwm$

2016-07-27 19:54 GMT+08:00 York Lai york.star@gmail.com:

I try Pocketchip (4.3 firmware):

Python 2.7.9 (default, Mar 1 2015, 13:48:22)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import CHIP_IO.GPIO as GPIO
print GPIO.VERSION
0.2.1

try SOFTPWM sample code:

Python 2.7.9 (default, Mar 1 2015, 13:48:22)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import CHIP_IO.SOFTPWM as SPWM
SPWM.start("XIO-P7", 50)
SPWM.set_duty_cycle("XIO-P7", 25.5)Traceback (most recent call last):
File "", line 1, in
RuntimeError: You must start() the PWM channel first

2016-07-27 9:52 GMT+08:00 Robert Wolterman notifications@github.com:

@yorklai https://github.com/yorklai, what version of CHIP_IO are you
using?

What happens if you do the following from the Python shell:
import CHIP_IO.GPIO as GPIO
print GPIO.VERSION

I'm running 0.2.1 and this isn't an issue. I believe @aninternetof
https://github.com/aninternetof fixed it yesterday for Issue#14.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#16 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ALzCrr-aENS8kpSbocFt7b0GENKl9zNCks5qZrnXgaJpZM4JVRnM
.

@hbradio
Copy link
Collaborator

hbradio commented Jul 27, 2016

@yorklai, regarding the "RuntimeError: You must start() the PWM channel first", I think I've figured out what is going on.

If you first tried with the old version of CHIP_IO (v0.1.1), then you hit a bug and the code exited. When it did this, it left the GPIO exported, because SPWM.cleanup() was never called.

So now when you try to run with the fixed code, the command SPWM.start("XIO-P7", 50) seems like it is running successfully, but it is failing to add XIO-P7 to the list of running PWMs because the gpio has already been exported. Then when SPWM looks for it on the list of running PWMS, it can't find it and throws the RuntimeError.

I'll work on a commit that makes SPWM.start() throw an error instead of failing silently if the gpio has already been exported. To fix your problem you'll need to:

  • sudo echo 415 > /sys/class/gpio/unexport
  • Try your code again. Make sure to add SPWM.cleanup() to the end of your test script.

@hbradio
Copy link
Collaborator

hbradio commented Jul 27, 2016

Ok, if the GPIO is already exported, it looks like it fails here, as it should.

@xtacocorex, I'm not super familiar with the error system. Does that add_error_msg print or log to somewhere?

@fordsfords
Copy link
Collaborator

fordsfords commented Jul 27, 2016

I can answer that one. It adds text to a global string buffer (error_msg_buff). It is a way that a descriptive error message can be passed back up to the python layer. So some utility function several layers down can detect a problem and add some text to that buffer. It returns an error, and its caller might add some more text to give it context (i.e. what it was trying to do when it call the lower-level function which detected the error), and that caller returns an error. And so on, until it makes it to the C code which interfaces with python. At that point, a final error message string is formatted and passed back to Python, using get_error_msg(). For example, in py_gpio.c the function "static PyObject *py_setup_channel(..." contains the code:

   if (gpio_export(gpio) < 0) {
      char err[2000];
      snprintf(err, sizeof(err), "Error setting up channel %s, maybe already exported? (%s)", channel, get_error_msg());
      PyErr_SetString(PyExc_RuntimeError, err);
      return NULL;
   }

The built-up error message is included in parentheses.

@yorklai
Copy link
Author

yorklai commented Jul 28, 2016

Dear Sir,

 I boot pocket (4.3 firmware) then try:

chip@chip:/etc/NetworkManager/system-connections$ sudo echo 415 >
/sys/class/gpio/unexport
-bash: /sys/class/gpio/unexport: Permission denied
chip@chip:/etc/NetworkManager/system-connections$
chip@chip:/etc/NetworkManager/system-connections$ sudo su
root@chip:/etc/NetworkManager/system-connections# sudo echo 415 >
/sys/class/gpio/unexportecho: write error: Invalid argument

2016-07-28 2:35 GMT+08:00 Brady Hurlburt notifications@github.com:

@yorklai https://github.com/yorklai, regarding the "RuntimeError: You
must start() the PWM channel first", I think I've figured out what is going
on.

If you first tried with the old version of CHIP_IO (v0.1.1), then you hit
a bug and the code exited. When it did this, it left the GPIO exported,
because SPWM.cleanup() was never called.

So now when you try to run with the fixed code, the command SPWM.start("XIO-P7",
50) seems like it is running successfully, but it is failing to add
XIO-P7 to the list of running PWMs because the gpio has already been
exported. Then when SPWM looks for it on the list of running PWMS, it can't
find it and throws the RuntimeError.

I'll work on a commit that makes SPWM.start() throw an error instead of
failing silently if the gpio has already been exported. To fix your problem
you'll need to:

  • sudo echo 415 > /sys/class/gpio/unexport
  • Try your code again. Make sure to add SPWM.cleanup() to the end of
    your test script.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#16 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ALzCrkXKRF_B1vWBxMLDD_czymsyUVSbks5qZ6UBgaJpZM4JVRnM
.

@xtacocorex
Copy link
Owner

When you did the sudo su, you got root access. sudo doesn't work when you're root.

Have you tried rebooting since you pulled the latest CHIP_IO code?
What happens if you do run spwmtest.py from within the test directory? You need a test wire hooked between XIO-P7 and CSID0 for that to run.

If that script runs correctly, you should be good to go.

@hbradio
Copy link
Collaborator

hbradio commented Jul 28, 2016

@fordsfords, thanks! I need to add pretty much exactly that same get_err_msg() code to my py_softpwm.c file. That would have made @yorklai's problem much more easily identifiable. I'll try to commit that sometime today.

@hbradio
Copy link
Collaborator

hbradio commented Jul 28, 2016

Ok, I think I've got it. Would sometime mind looking over my commit in hotfix/SPWM_Issue_16?

@hbradio
Copy link
Collaborator

hbradio commented Jul 28, 2016

For this kind of situation, have we considered having a cleanup_all() function to unexport all GPIO, instead of just the ones registered in CHIP_IO's currently exported list?
It would be a somewhat powerful/dangerous function, but during development it's not uncommon to exit your script before reaching the cleanup(), and then you're left with stranded GPIO that you have to manually unexport before trying your script again.

@xtacocorex
Copy link
Owner

Will try to test your hotfix when I can, might not be able to get to it tonight though.

@fordsfords
Copy link
Collaborator

Can I reply to this email?

I just wrote a simple shell script to close everything. I don't think a close all in the GPIO library is a good idea. But I won't object if I am out-voted. :-)

On Jul 28, 2016, at 7:58 AM, Brady Hurlburt notifications@github.com wrote:

For this kind of situation, have we considered having a cleanup_all() function to unexport all GPIO, instead of just the ones registered in CHIP_IO's currently exported list?
It would be a somewhat powerful/dangerous function, but during development it's not uncommon to exit your script before reaching the cleanup(), and then you're left with stranded GPIO that you have to manually unexport before trying your script again.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

@fordsfords
Copy link
Collaborator

Oh, I guess I already added that script to the repo. Named "unexport_all.sh", it is in the parent directory.

@hbradio
Copy link
Collaborator

hbradio commented Jul 29, 2016

A script like that works for me! It's probably a good middle-ground.

@xtacocorex
Copy link
Owner

Just tested with by exporting a GPIO and then trying to start SPWM on it. Error messages are displayed. I updated the spwmtest.py to check for this issue. Will commit spwmtest.py, update the version/changelog stuff, then merge to master.

@yorklai
Copy link
Author

yorklai commented Aug 1, 2016

Very Thanks! I try last version is no any error message!

chip@chip:~$ sudo python
Python 2.7.9 (default, Mar 1 2015, 13:48:22)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import CHIP_IO.SOFTPWM as SPWM
print SPWM.VERSION
0.2.2
SPWM.start("XIO-P7", 50)
SPWM.set_duty_cycle("XIO-P7", 25.5)
SPWM.set_frequency("XIO-P7", 10)
SPWM.stop("XIO-P7")
SPWM.cleanup()
SPWM.start("XIO-P7", 50, 2000, 1)

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

5 participants