Examples (similar to Arduino)

Showroom for MicroPython related hardware projects.
Target audience: Users wanting to show off their project!
mithru
Posts: 7
Joined: Fri Aug 15, 2014 12:22 pm
Location: Singapore

Examples (similar to Arduino)

Post by mithru » Fri Aug 15, 2014 1:31 pm

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

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Examples (similar to Arduino)

Post by dhylands » Fri Aug 15, 2014 3:41 pm

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.

mithru
Posts: 7
Joined: Fri Aug 15, 2014 12:22 pm
Location: Singapore

Re: Examples (similar to Arduino)

Post by mithru » Sat Aug 16, 2014 1:48 pm

Thanks! Looks good. I'll update the repository and re-arrange the order such that the learning curve is not too steep.

User avatar
yllumi
Posts: 37
Joined: Tue Aug 19, 2014 8:41 am
Location: Bandung, West Java, Indonesia
Contact:

Re: Examples (similar to Arduino)

Post by yllumi » Tue Aug 19, 2014 8:51 am

Is there anyone can give me some example of using ADC class from any device like potensiometer or distance sensor?

mithru
Posts: 7
Joined: Fri Aug 15, 2014 12:22 pm
Location: Singapore

Re: Examples (similar to Arduino)

Post by mithru » Tue Aug 19, 2014 1:29 pm

Check out the 'Potentiometer' example in here:

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

User avatar
yllumi
Posts: 37
Joined: Tue Aug 19, 2014 8:41 am
Location: Bandung, West Java, Indonesia
Contact:

Re: Examples (similar to Arduino)

Post by yllumi » Tue Aug 19, 2014 10:20 pm

mithru wrote:Check out the 'Potentiometer' example in here:

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

User avatar
kfricke
Posts: 342
Joined: Mon May 05, 2014 9:13 am
Location: Germany

Re: Examples (similar to Arduino)

Post by kfricke » Thu Aug 21, 2014 4:02 pm

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).

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Examples (similar to Arduino)

Post by dhylands » Thu Aug 21, 2014 4:25 pm

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

mithru
Posts: 7
Joined: Fri Aug 15, 2014 12:22 pm
Location: Singapore

Re: Examples (similar to Arduino)

Post by mithru » Thu Aug 21, 2014 5:01 pm

Got it. Makes sense. Thanks for the feedback, guys. Will update this tomorrow evening my time.
EDIT: Changes have been made.

User avatar
danpeirce
Posts: 5
Joined: Fri Jul 11, 2014 8:15 pm
Location: Richmond BC Canada
Contact:

Re: Examples (similar to Arduino)

Post by danpeirce » Sun Oct 26, 2014 6:47 am

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)

Post Reply