blob: 646ecbc23736d6a78397e2d585b3743c21bba79c [file] [log] [blame]
Damien George3eece292015-06-04 23:53:26 +01001Getting a MicroPython REPL prompt
2=================================
Damien Georged19c2562014-09-25 17:21:59 +01003
4REPL stands for Read Evaluate Print Loop, and is the name given to the
Damien George3eece292015-06-04 23:53:26 +01005interactive MicroPython prompt that you can access on the pyboard. Using
Damien Georged19c2562014-09-25 17:21:59 +01006the REPL is by far the easiest way to test out your code and run commands.
7You can use the REPL in addition to writing scripts in ``main.py``.
8
9To use the REPL, you must connect to the serial USB device on the pyboard.
10How you do this depends on your operating system.
11
12Windows
13-------
14
15You need to install the pyboard driver to use the serial USB device.
16The driver is on the pyboard's USB flash drive, and is called ``pybcdc.inf``.
17
18To install this driver you need to go to Device Manager
19for your computer, find the pyboard in the list of devices (it should have
20a warning sign next to it because it's not working yet), right click on
21the pyboard device, select Properties, then Install Driver. You need to
22then select the option to find the driver manually (don't use Windows auto update),
23navigate to the pyboard's USB drive, and select that. It should then install.
24After installing, go back to the Device Manager to find the installed pyboard,
25and see which COM port it is (eg COM4).
Damien Georgeb27c9872015-01-06 16:09:49 +000026More comprehensive instructions can be found in the
27`Guide for pyboard on Windows (PDF) <http://micropython.org/resources/Micro-Python-Windows-setup.pdf>`_.
28Please consult this guide if you are having problems installing the driver.
Damien Georged19c2562014-09-25 17:21:59 +010029
30You now need to run your terminal program. You can use HyperTerminal if you
31have it installed, or download the free program PuTTY:
Damien George6e6dfdc2014-11-02 23:37:02 +000032`putty.exe <http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html>`_.
Damien Georged19c2562014-09-25 17:21:59 +010033Using your serial program you must connect to the COM port that you found in the
34previous step. With PuTTY, click on "Session" in the left-hand panel, then click
35the "Serial" radio button on the right, then enter you COM port (eg COM4) in the
36"Serial Line" box. Finally, click the "Open" button.
37
38Mac OS X
39--------
40
41Open a terminal and run::
42
43 screen /dev/tty.usbmodem*
44
Damien George88d30542014-10-31 01:37:19 +000045When you are finished and want to exit screen, type CTRL-A CTRL-\\.
Damien Georged19c2562014-09-25 17:21:59 +010046
47Linux
48-----
49
50Open a terminal and run::
51
52 screen /dev/ttyACM0
53
54You can also try ``picocom`` or ``minicom`` instead of screen. You may have to
55use ``/dev/ttyACM1`` or a higher number for ``ttyACM``. And, you may need to give
56yourself the correct permissions to access this devices (eg group ``uucp`` or ``dialout``,
57or use sudo).
58
59Using the REPL prompt
60---------------------
61
Damien George3eece292015-06-04 23:53:26 +010062Now let's try running some MicroPython code directly on the pyboard.
Damien Georged19c2562014-09-25 17:21:59 +010063
64With your serial program open (PuTTY, screen, picocom, etc) you may see a blank
65screen with a flashing cursor. Press Enter and you should be presented with a
Damien George3eece292015-06-04 23:53:26 +010066MicroPython prompt, i.e. ``>>>``. Let's make sure it is working with the obligatory test::
Damien Georged19c2562014-09-25 17:21:59 +010067
68 >>> print("hello pyboard!")
69 hello pyboard!
70
71In the above, you should not type in the ``>>>`` characters. They are there to
72indicate that you should type the text after it at the prompt. In the end, once
73you have entered the text ``print("hello pyboard!")`` and pressed Enter, the output
74on your screen should look like it does above.
75
76If you already know some python you can now try some basic commands here.
77
78If any of this is not working you can try either a hard reset or a soft reset;
79see below.
80
81Go ahead and try typing in some other commands. For example::
82
83 >>> pyb.LED(1).on()
84 >>> pyb.LED(2).on()
85 >>> 1 + 2
86 3
87 >>> 1 / 2
88 0.5
89 >>> 20 * 'py'
90 'pypypypypypypypypypypypypypypypypypypypy'
91
92Resetting the board
93-------------------
94
95If something goes wrong, you can reset the board in two ways. The first is to press CTRL-D
Damien George3eece292015-06-04 23:53:26 +010096at the MicroPython prompt, which performs a soft reset. You will see a message something like ::
Damien Georged19c2562014-09-25 17:21:59 +010097
98 >>>
99 PYB: sync filesystems
100 PYB: soft reboot
101 Micro Python v1.0 on 2014-05-03; PYBv1.0 with STM32F405RG
102 Type "help()" for more information.
103 >>>
104
105If that isn't working you can perform a hard reset (turn-it-off-and-on-again) by pressing the RST
106switch (the small black button closest to the micro-USB socket on the board). This will end your
107session, disconnecting whatever program (PuTTY, screen, etc) that you used to connect to the pyboard.
108
109If you are going to do a hard-reset, it's recommended to first close your serial program and eject/unmount
110the pyboard drive.