Difference between revisions of "TiLDA MK3/Run Code"

From EMF Badge
Jump to navigation Jump to search
(→‎Option 1: REPL: fix broken link to micropython repl tutorial)
 
(One intermediate revision by one other user not shown)
Line 4: Line 4:
 
REPL stands for "[https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop Read–eval–print loop]" and allows you to run python code, line by line. This is a great way to see effects of certain hardware commands instantly and to test basic python features.  
 
REPL stands for "[https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop Read–eval–print loop]" and allows you to run python code, line by line. This is a great way to see effects of certain hardware commands instantly and to test basic python features.  
  
This allows you to run code, line by line, on the badge and to see the effects instantly. Follow https://micropython.org/doc/tut-repl or follow step 1-4 on the [[TiLDA_MK3/Get_Started|Get Started]] guide.  
+
This allows you to run code, line by line, on the badge and to see the effects instantly. Follow https://docs.micropython.org/en/latest/pyboard/pyboard/tutorial/repl.html or follow step 1-4 on the [[TiLDA_MK3/Get_Started|Get Started]] guide.  
  
 
<strong>Note:</strong> This will only work if you have an empty <code>main.py</code> on your badge to stop the home screen from taking over instantly. If an app or script is already running you will not get a REPL that you can use to program, but simple debug output instead. Remember to remove it afterwards if you want to use the home screen again.
 
<strong>Note:</strong> This will only work if you have an empty <code>main.py</code> on your badge to stop the home screen from taking over instantly. If an app or script is already running you will not get a REPL that you can use to program, but simple debug output instead. Remember to remove it afterwards if you want to use the home screen again.
Line 16: Line 16:
  
 
Remember to remove your main.py afterwards if you want to use the home screen again.
 
Remember to remove your main.py afterwards if you want to use the home screen again.
 +
 +
On Linux you can use this script to automatically mount the TILDA -> sync files from a local directory -> safely eject: https://gist.github.com/IVBakker/fbab508c336397323d6c1caef8cdc46c
  
 
= Option 3: pyboard.py =
 
= Option 3: pyboard.py =

Latest revision as of 01:22, 2 March 2017

This video is meant for the micropython board, but most of it works similar on the TiLDA: https://micropython.org/

Option 1: REPL

REPL stands for "Read–eval–print loop" and allows you to run python code, line by line. This is a great way to see effects of certain hardware commands instantly and to test basic python features.

This allows you to run code, line by line, on the badge and to see the effects instantly. Follow https://docs.micropython.org/en/latest/pyboard/pyboard/tutorial/repl.html or follow step 1-4 on the Get Started guide.

Note: This will only work if you have an empty main.py on your badge to stop the home screen from taking over instantly. If an app or script is already running you will not get a REPL that you can use to program, but simple debug output instead. Remember to remove it afterwards if you want to use the home screen again.

You can also press Ctrl-C to stop the currently running app and get to the python prompt.

Option 2: Copying files

You can also copy your code to main.py on your badge, safely eject and then reset the badge via the button. To debug it you can use the serial console (see option 1) which will show you all text printed via print() and errors.

Note: It's very important to always correctly "eject" the usb storage before pressing the reset button, otherwise your filesystem is going to corrupt and you might have to factory reset your badge

Remember to remove your main.py afterwards if you want to use the home screen again.

On Linux you can use this script to automatically mount the TILDA -> sync files from a local directory -> safely eject: https://gist.github.com/IVBakker/fbab508c336397323d6c1caef8cdc46c

Option 3: pyboard.py

You can also use micropythons's pyboard.py script to automatically run a full local file of code without having to worry about copying it line-by-line or ejecting your device.

You can find a quick introduction on how to set it up here.

This option is very useful as a build script with your editor, it allows you to quickly test whether your app is working.

Note: While this option works even if you run the home screen, it works slightly better if you have an empty main.py on your badge.

Sublime Text 2 build script

OSX:

{
    "shell_cmd": "/path/to/your/pyboard.py --device /dev/tty.usbmodem* $file"
}