We have upgraded the community system as part of the upgrade a password reset is required for all users before login in.

Python Examples on github



  • Good evening.

    I have downloaded a few of the python examples from the Onion GitHub page to try out. The first one I tried to use PWM.py just kicked out an error as follows:

    root@Omega-172E:/Python-PWM/onion# python PWM.py
    Traceback (most recent call last):
    File "PWM.py", line 5, in <module>
    from onion import I2C
    ImportError: No module named onion

    Am I missing something? Is there a module I have to download before using the examples?

    Thanks in advance for any info.



  • Hi @Daniel-Wright, we have updated our python libraries. Please view instruction here: https://wiki.onion.io/Tutorials/Libraries/PWM-Expansion-Library#using-the-python-module on how to use it to control the PWM Expansion.

    Cheers!



  • @Boken-Lin I have looked at the page you have linked to, but it doesn't have what I was looking for. It basically tells you the basics of programming for the expansions. There are no usable examples for the servo dock.

    The examples I wanted to use from the GitHub page actually have usable examples of positioning a servo. That's what I have been looking for. The other examples just tell how to set frequency, duty cycle, etc. I can do that from the app on the omega screen. That is only good for running an led or a motor or something.

    I was looking for an example that actually showed me how to move a servo to a specific position or use a joystick to move the servo. The example on GitHub looks like it shows setting servo positions but it won't run…
    Thanks in advance for any help.



  • Hi @Daniel-Wright, Ah, I see what you are looking for. The reason that we have shown instructions on how to turn servo to a given angle is because we have found out that each servo has different settings, and would requite different duty cycle to get to a given angle. So with the old python library, unless you are using the same servo motor that we were using, you would still need to adjust the duty cycle to get to the angle that you want. This will also depend on the type of servo you choose to use (180 degrees, 360 degrees, or continuous). The library mentioned in the dependency error you posted is https://github.com/OnionIoT/Python-I2C. However, the main problem is that this package depends on a package on OpenWRT called smbus, which has been broken for the current release of OpenWRT.

    I think the best option for your project might be to test out the servo motor that you are planning to use with the PWM Control Console App. Try adjusting the values to the angles that you wish to use, and setting those duty cycles using the new python libraries. On our end we might also be able to add a couple of functions to directly set the angles for the most commonly used servo motors.



  • Good morning @Boken-Lin,

    Thank you for your reply. That i helpful. My experience has mainly been with the Arduino platform and the PicAxe platform so all this python programing and stuff is fairly new to me… I'm learning though.

    I can't wait for the Cloud thing to be available and see what kind of info and projects end up on there.

    Any tips on learning python and stuff easier???
    Thanks again.



  • @Daniel-Wright The way that I learnt Python was by reading this book: http://learnpythonthehardway.org. It's an intimidating title, but it's not as hard as you might think, and it does a great job of building up some good habits when you are writing code in Python.

    Hope it helps!
    Cheers!


Log in to reply
 

Looks like your connection to Community was lost, please wait while we try to reconnect.