Editing Tutorial AutoRun

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 14: Line 14:
 
* write your code as a module that can be executed by calling a function. call this function from main.
 
* write your code as a module that can be executed by calling a function. call this function from main.
  
== Related Components ==
+
== Examples of main.py ==  
 
 
The components are related to the [[LMUBox]]. For more components, see the [[Hardware List]]. Many of the pages on actuators and sensor include additional examples.
 
 
 
=== Microcontroller ===
 
* [[ESP32 Web Kit]] with integrated OLED Display from Heltec
 
 
 
=== Sensors (and physical controllers) ===
 
* [[Switch]]
 
 
 
= Instructional Videos =
 
 
 
== How to Autorun MicroPython code ==
 
This shows how to use main.py as entry point to shart your MicroPython code. It looks at how to stop a running program with a terminal program (e.g. Putty). We introduce how to add a boot selector switch.
 
 
 
There is a video on Youtube (29:23) that shows the software: https://youtu.be/kzgUN_h1bqw
 
 
 
<youtube>https://youtu.be/kzgUN_h1bqw</youtube>
 
 
 
 
 
= Examples of main.py =  
 
  
 
== Code Example: code in main.py ==  
 
== Code Example: code in main.py ==  
Line 51: Line 31:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
== Code Example: function in module and called from main.py ==  
+
== Code Example: function in moduele and called from main.py ==  
 
<syntaxhighlight lang="python" line='line'>
 
<syntaxhighlight lang="python" line='line'>
 
# main.py - example how to call a function (with your code) from the main.py file
 
# main.py - example how to call a function (with your code) from the main.py file
Line 59: Line 39:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
== Code Example: selectively call function in module from main.py - boot switch ==  
+
= Instructional Videos =
[[File:BootSelektor.JPG|300px]]
+
 
<syntaxhighlight lang="python" line='line'>
+
== How to Autorun MicroPython code ==
# main.py - example how to call a function (with your code) from the main.py file
+
This shows how to use main.py as entry point to shart your MicroPython code. It looks at how to stop a running program with a terminal program (e.g. Putty). We introduce how to add a boot selector switch.
# the function is only called if Pin26 is '1' (connected to 3.3V)
 
# if Pin26 is '0' the function will not be callwd
 
# we assume you have a function mymain() defined in a module mycode.py
 
import mycode
 
from machine import Pin
 
  
p26 = Pin(26, Pin.IN)
+
There is a video on Youtube (29:23) that shows the software: https://youtu.be/kzgUN_h1bqw
  
if (p26.value()==1):
+
<youtube>https://youtu.be/kzgUN_h1bqw</youtube>
    mycode.mymain()
 
</syntaxhighlight>
 

Please note that all contributions to Sketching with Hardware at LMU Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see My wiki:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)