Page 1 of 2

Examples (similar to Arduino)

Posted: Fri Aug 15, 2014 1:31 pm
by mithru
Hey there,

I'm working on a bunch of working examples for simple functions that could be used as part of the 'Getting Started' guide. Similar to Arduino's examples folder from where every beginner's helloWorld into Arduino is Examples > Basics > Blink

The purpose of this is for beginners to easily look up working code and try to replicate it for their projects.

I've only just begun playing with uPy. So there are only a few examples for now and it's likely I may have messed up in a few places - have a look and let me know if there's something wrong.

Will be working on adding more to this repo on weekends and after work - my way of getting using to this (haven't coded python in quite a while as well). Contributions are welcome. :)

https://github.com/mithru/MicroPython-Examples

Re: Examples (similar to Arduino)

Posted: Fri Aug 15, 2014 3:41 pm
by dhylands
Following your lead, I also created a repository of some sample code I've written.
https://github.com/dhylands/upy-examples

Feel free to use/rework any of this that might be expanded into more tutorial like material.

Re: Examples (similar to Arduino)

Posted: Sat Aug 16, 2014 1:48 pm
by mithru
Thanks! Looks good. I'll update the repository and re-arrange the order such that the learning curve is not too steep.

Re: Examples (similar to Arduino)

Posted: Tue Aug 19, 2014 8:51 am
by yllumi
Is there anyone can give me some example of using ADC class from any device like potensiometer or distance sensor?

Re: Examples (similar to Arduino)

Posted: Tue Aug 19, 2014 1:29 pm
by mithru
Check out the 'Potentiometer' example in here:

https://github.com/mithru/MicroPython-E ... /02.Inputs

Re: Examples (similar to Arduino)

Posted: Tue Aug 19, 2014 10:20 pm
by yllumi
mithru wrote:Check out the 'Potentiometer' example in here:

https://github.com/mithru/MicroPython-E ... /02.Inputs
That's great! Thanks, mithru

Re: Examples (similar to Arduino)

Posted: Thu Aug 21, 2014 4:02 pm
by kfricke
mithru wrote:Check out the 'Potentiometer' example in here:

https://github.com/mithru/MicroPython-E ... /02.Inputs
IMHO it is not that reasonable to split an example into the two scripts 'boot.py' and 'main.py'. As far as i do understand the 'boot.py' should only influence basic bahaviour of your pyBoard and not be used as a place to initialize the "program" on it. It feels like you are using the 'boot.py' like the 'setup()' method on Arduino.
To describe it further, I'd say that you should only alter the 'boot.py' to change fundamental things like enabling different USB features (serial console over USB and mass storage).

Re: Examples (similar to Arduino)

Posted: Thu Aug 21, 2014 4:25 pm
by dhylands
I'd also recommend having the files named after the example rather calling them main.py

Then you could copy several of them to your sdcard and just import them to run the example

Re: Examples (similar to Arduino)

Posted: Thu Aug 21, 2014 5:01 pm
by mithru
Got it. Makes sense. Thanks for the feedback, guys. Will update this tomorrow evening my time.
EDIT: Changes have been made.

Re: Examples (similar to Arduino)

Posted: Sun Oct 26, 2014 6:47 am
by danpeirce
dhylands wrote:Following your lead, I also created a repository of some sample code I've written.
https://github.com/dhylands/upy-examples

Feel free to use/rework any of this that might be expanded into more tutorial like material.
I was looking for an example like https://github.com/dhylands/upy-example ... c_test2.py

In trying to understand the example. One point I am confused about is the line 25

Code: Select all

def ic_cb(tim):
I was thinking the timer object here was called ic as assigned in line 18. I have been looking at https://micropython.org/doc/module/pyb/Timer but perhaps I am missing something?

Code: Select all

ic = pyb.Timer(2, pin=ic_pin, mode=pyb.Timer.IC, channel=4,
    prescaler=83, period=0x0fffffff,
    ic_polarity=pyb.Timer.IC_POLARITY_BOTH)