Skip to main content

setting up pwm

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.

Comments

Popular posts from this blog

json messaging (2/2)

Took a good 2 hours to change all the messages into JSON format and make it work. But it is done. All is JSON. Using it like a map, currently with three key-value pairs: "id" : for entering a session ID of another session if needed. Currently used for the web client to receive a acknowledge response to confirm that the target received the message (mainly for testing purposes). "type" : probably the most functional data going through all this. Current types are STARTUP_TYPE - for when the target sends its initial message, the server uses this to mark which session is the target. REQUEST_TYPE - for when the web client sends a request to the target. Server uses this to send request to target. ACK_TYPE - for when the target finishes carrying out the requests and sends an acknowledgement of the completion of the request to the server. Server uses this to send confirmation to the web client  MISC_MSG_TYPE - for anything else. DEBUG_TYPE - current...

come back

The last couple of weeks have been quite refreshing. The drive for learning and trying out new things has never been higher. Currently fascinated with Node.js; Javascript truly isn't the make-a-website-pretty script I had known anymore.  Playing around with back-end and front-end frameworks. Currently playing around with Sails.js, and once I get used to that, I am looking forward to trying out Angular.JS as a front-end framework. Other than that, currently have couple of other random APIs (non-Node.js) I would like to play around with, but I'm just keeping them up in my browser tabs to that I'll get to them eventually. In addition, I reviewed the Android Developer tutorial again--hoping to try making something in that end as well.

adding a servo

Since I don't have any lock that works based on a digital signal, it seemed appropriate to at least have something in place that would emulate the behavior of such a lock, and I thought that a servo would be a good substitute. (note: a servo is a device with which one can control a specific rotational position) Connecting a servo to the current circuit isn't too much of a challenge, as it just requires a single output connection along with the ground/power. Making the servo also just requires an addition of a few lines of code, using the Servo library . A simple video of the servo in action: Now, at least with a locking behavior in place, the one visible functionality that needs to be addressed is the device's ability to distinguish between a "standby" state (no alcohol/no breathing in: should be in "lock" mode) and a "open" state (no alcohol/breathing in: should be in "open" mode).