There's always an obstacle..
I implemented the pwm module as described in the link in the previous post, but oddly enough, it didn't work.
The error I received:
AttributeError: 'module' object has no attribute 'PWM'
After some time scratching my head, I came to the realization that somehow my python was running an older version of the RPi.GPIO library, as PWM control was a pretty recent addition to the library.
And indeed it was.
Not really sure what's happening in detail, but it seems that there are two different... entities? that manage libraries for Python. One is through the usual "apt-get" command and the other is "pip." It appears that Python looks at "pip" first, and it currently linked RPi.GPIO to a really old version of the library.
Uninstalling that older version ("pip uninstall RPi.GPIO") and using the version I obtained through apt-get ("apt-get install python-rpi.gpio") solved this.
Now, a less-hacky implementation of PWM.
Note that the PWM offered in this library is a software-driven PWM, meaning that the cycles it counts are based on the cycle count of the process (program). This can be inaccurate because programs can be put "on hold" by the operating system during heavy load, and during this time on hold, it stops counting. Because PWM relies on timing, this could cause "jitters" in the devices that read the signal. A better implementation is a hardware-driven PWM, which uses the clock cycles in the physical board to count.
For now, I think the software-driven PWM will be fine.
Time's up for working on this today; I'll change messages into JSON next time, I guess.
Time's up for working on this today; I'll change messages into JSON next time, I guess.
Comments
Post a Comment