diff options
Diffstat (limited to 'docs/pyboard')
-rw-r--r-- | docs/pyboard/quickref.rst | 21 | ||||
-rw-r--r-- | docs/pyboard/tutorial/usb_mouse.rst | 28 |
2 files changed, 34 insertions, 15 deletions
diff --git a/docs/pyboard/quickref.rst b/docs/pyboard/quickref.rst index 2a1429cb05..3d08ae9109 100644 --- a/docs/pyboard/quickref.rst +++ b/docs/pyboard/quickref.rst @@ -3,6 +3,12 @@ Quick reference for the pyboard =============================== +The below pinout is for PYBv1.0. You can also view pinouts for +other versions of the pyboard: +`PYBv1.1 <http://micropython.org/resources/pybv11-pinout.jpg>`__ +or `PYBLITEv1.0-AC <http://micropython.org/resources/pyblitev10ac-pinout.jpg>`__ +or `PYBLITEv1.0 <http://micropython.org/resources/pyblitev10-pinout.jpg>`__. + .. image:: http://micropython.org/resources/pybv10-pinout.jpg :alt: PYBv1.0 pinout :width: 700px @@ -14,14 +20,25 @@ See :mod:`pyb`. :: import pyb - pyb.delay(50) # wait 50 milliseconds - pyb.millis() # number of milliseconds since bootup pyb.repl_uart(pyb.UART(1, 9600)) # duplicate REPL on UART(1) pyb.wfi() # pause CPU, waiting for interrupt pyb.freq() # get CPU and bus frequencies pyb.freq(60000000) # set CPU freq to 60MHz pyb.stop() # stop CPU, waiting for external interrupt +Delay and timing +---------------- + +Use the :mod:`time <utime>` module:: + + import time + + time.sleep(1) # sleep for 1 second + time.sleep_ms(500) # sleep for 500 milliseconds + time.sleep_us(10) # sleep for 10 microseconds + start = time.ticks_ms() # get value of millisecond counter + delta = time.ticks_diff(start, time.ticks_ms()) # compute time difference + LEDs ---- diff --git a/docs/pyboard/tutorial/usb_mouse.rst b/docs/pyboard/tutorial/usb_mouse.rst index ac1de6e275..6f8831edb4 100644 --- a/docs/pyboard/tutorial/usb_mouse.rst +++ b/docs/pyboard/tutorial/usb_mouse.rst @@ -13,23 +13,23 @@ will look something like this:: import pyb #pyb.main('main.py') # main script to run after this one - #pyb.usb_mode('CDC+MSC') # act as a serial and a storage device - #pyb.usb_mode('CDC+HID') # act as a serial device and a mouse + #pyb.usb_mode('VCP+MSC') # act as a serial and a storage device + #pyb.usb_mode('VCP+HID') # act as a serial device and a mouse To enable the mouse mode, uncomment the last line of the file, to make it look like:: - pyb.usb_mode('CDC+HID') # act as a serial device and a mouse + pyb.usb_mode('VCP+HID') # act as a serial device and a mouse If you already changed your ``boot.py`` file, then the minimum code it needs to work is:: import pyb - pyb.usb_mode('CDC+HID') + pyb.usb_mode('VCP+HID') -This tells the pyboard to configure itself as a CDC (serial) and HID -(human interface device, in our case a mouse) USB device when it boots -up. +This tells the pyboard to configure itself as a VCP (Virtual COM Port, +ie serial port) and HID (human interface device, in our case a mouse) +USB device when it boots up. Eject/unmount the pyboard drive and reset it using the RST switch. Your PC should now detect the pyboard as a mouse! @@ -41,7 +41,8 @@ To get the py-mouse to do anything we need to send mouse events to the PC. We will first do this manually using the REPL prompt. Connect to your pyboard using your serial program and type the following:: - >>> pyb.hid((0, 10, 0, 0)) + >>> hid = pyb.USB_HID() + >>> hid.send((0, 10, 0, 0)) Your mouse should move 10 pixels to the right! In the command above you are sending 4 pieces of information: button status, x, y and scroll. The @@ -52,7 +53,7 @@ Let's make the mouse oscillate left and right:: >>> import math >>> def osc(n, d): ... for i in range(n): - ... pyb.hid((0, int(20 * math.sin(i / 10)), 0, 0)) + ... hid.send((0, int(20 * math.sin(i / 10)), 0, 0)) ... pyb.delay(d) ... >>> osc(100, 50) @@ -100,9 +101,10 @@ In ``main.py`` put the following code:: switch = pyb.Switch() accel = pyb.Accel() + hid = pyb.USB_HID() while not switch(): - pyb.hid((0, accel.x(), accel.y(), 0)) + hid.send((0, accel.x(), accel.y(), 0)) pyb.delay(20) Save your file, eject/unmount your pyboard drive, and reset it using the RST @@ -112,7 +114,7 @@ the mouse around. Try it out, and see if you can make the mouse stand still! Press the USR switch to stop the mouse motion. You'll note that the y-axis is inverted. That's easy to fix: just put a -minus sign in front of the y-coordinate in the ``pyb.hid()`` line above. +minus sign in front of the y-coordinate in the ``hid.send()`` line above. Restoring your pyboard to normal -------------------------------- @@ -121,9 +123,9 @@ If you leave your pyboard as-is, it'll behave as a mouse everytime you plug it in. You probably want to change it back to normal. To do this you need to first enter safe mode (see above), and then edit the ``boot.py`` file. In the ``boot.py`` file, comment out (put a # in front of) the line with the -``CDC+HID`` setting, so it looks like:: +``VCP+HID`` setting, so it looks like:: - #pyb.usb_mode('CDC+HID') # act as a serial device and a mouse + #pyb.usb_mode('VCP+HID') # act as a serial device and a mouse Save your file, eject/unmount the drive, and reset the pyboard. It is now back to normal operating mode. |