diff options
| author | Dan Halbert <halbert@halwitz.org> | 2018-02-27 22:03:52 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-02-27 22:03:52 -0500 |
| commit | 568c04e6afa8016062f685b2198c0209f62827f4 (patch) | |
| tree | d07b76119f715add462983b335797adf64b61249 /docs/wipy | |
| parent | 6a2379fd0bfe10017d8abc5c36ef1d470c0d9b27 (diff) | |
| parent | ea633117d01d94e8d56ed94344e4b3e46b4eef03 (diff) | |
Merge pull request #650 from tannewt/merge_2x3.0.0-alpha.2
Merge in commits from 2.x branch.
Diffstat (limited to 'docs/wipy')
| -rw-r--r-- | docs/wipy/general.rst | 385 | ||||
| -rw-r--r-- | docs/wipy/index.rst | 8 | ||||
| -rw-r--r-- | docs/wipy/quickref.rst | 218 | ||||
| -rw-r--r-- | docs/wipy/tutorial/blynk.rst | 19 | ||||
| -rw-r--r-- | docs/wipy/tutorial/index.rst | 18 | ||||
| -rw-r--r-- | docs/wipy/tutorial/intro.rst | 64 | ||||
| -rw-r--r-- | docs/wipy/tutorial/repl.rst | 130 | ||||
| -rw-r--r-- | docs/wipy/tutorial/reset.rst | 54 | ||||
| -rw-r--r-- | docs/wipy/tutorial/timer.rst | 70 | ||||
| -rw-r--r-- | docs/wipy/tutorial/wlan.rst | 71 |
10 files changed, 0 insertions, 1037 deletions
diff --git a/docs/wipy/general.rst b/docs/wipy/general.rst deleted file mode 100644 index f28edb4e4..000000000 --- a/docs/wipy/general.rst +++ /dev/null @@ -1,385 +0,0 @@ -General information about the WiPy -================================== - -No floating point support -------------------------- - -Due to space reasons, there's no floating point support, and no math module. This -means that floating point numbers cannot be used anywhere in the code, and that -all divisions must be performed using '//' instead of '/'. Example:: - - >>> r = 4 // 2 # this will work - >>> r = 4 / 2 # this WON'T - -Before applying power ---------------------- - -.. warning:: - - The GPIO pins of the WiPy are NOT 5V tolerant, connecting them to voltages higher - than 3.6V will cause irreparable damage to the board. ADC pins, when configured - in analog mode cannot withstand voltages above 1.8V. Keep these considerations in - mind when wiring your electronics. - -WLAN default behaviour ----------------------- - -When the WiPy boots with the default factory configuration starts in Access Point -mode with ``ssid`` that starts with: ``wipy-wlan`` and ``key: www.wipy.io``. -Connect to this network and the WiPy will be reachable at ``192.168.1.1``. In order -to gain access to the interactive prompt, open a telnet session to that IP address on -the default port (23). You will be asked for credentials: -``login: micro`` and ``password: python`` - -.. _wipy_telnet: - -Telnet REPL ------------ - -Linux stock telnet works like a charm (also on OSX), but other tools like putty -work quite well too. The default credentials are: **user:** ``micro``, **password:** ``python``. -See :ref:`network.server <network.server>` for info on how to change the defaults. -For instance, on a linux shell (when connected to the WiPy in AP mode):: - - $ telnet 192.168.1.1 - -.. _wipy_filesystem: - -Local file system and FTP access --------------------------------- - -There is a small internal file system (a drive) on the WiPy, called ``/flash``, -which is stored within the external serial flash memory. If a micro SD card -is hooked-up and mounted, it will be available as well. - -When the WiPy starts up, it always boots from the ``boot.py`` located in the -``/flash`` file system. On boot up, the current directory is ``/flash``. - -The file system is accessible via the native FTP server running in the WiPy. -Open your FTP client of choice and connect to: - -**url:** ``ftp://192.168.1.1``, **user:** ``micro``, **password:** ``python`` - -See :ref:`network.server <network.server>` for info on how to change the defaults. -The recommended clients are: Linux stock FTP (also in OSX), Filezilla and FireFTP. -For example, on a linux shell:: - - $ ftp 192.168.1.1 - -The FTP server on the WiPy doesn't support active mode, only passive, therefore, -if using the native unix ftp client, just after logging in do:: - - ftp> passive - -Besides that, the FTP server only supports one data connection at a time. Check out -the Filezilla settings section below for more info. - -FileZilla settings ------------------- -Do not use the quick connect button, instead, open the site manager and create a new -configuration. In the ``General`` tab make sure that encryption is set to: ``Only use -plain FTP (insecure)``. In the Transfer Settings tab limit the max number of connections -to one, otherwise FileZilla will try to open a second command connection when retrieving -and saving files, and for simplicity and to reduce code size, only one command and one -data connections are possible. Other FTP clients might behave in a similar way. - -.. _wipy_firmware_upgrade: - -Upgrading the firmware Over The Air ------------------------------------ - -OTA software updates can be performed through the FTP server. Upload the ``mcuimg.bin`` file -to: ``/flash/sys/mcuimg.bin`` it will take around 6s. You won't see the file being stored -inside ``/flash/sys/`` because it's actually saved bypassing the user file system, so it -ends up inside the internal **hidden** file system, but rest assured that it was successfully -transferred, and it has been signed with a MD5 checksum to verify its integrity. Now, reset -the WiPy by pressing the switch on the board, or by typing:: - - >>> import machine - >>> machine.reset() - -Software updates can be found in: https://github.com/wipy/wipy/releases (**Binaries.zip**). -It's always recommended to update to the latest software, but make sure to -read the **release notes** before. - -.. note:: - - The ``bootloader.bin`` found inside ``Binaries.zip`` is there only for reference, it's not - needed for the Over The Air update. - -In order to check your software version, do:: - - >>> import os - >>> os.uname().release - -If the version number is lower than the latest release found in -`the releases <https://github.com/wipy/wipy/releases>`_, go ahead and update your WiPy! - - -.. _wipy_boot_modes: - -Boot modes and safe boot ------------------------- - -If you power up normally, or press the reset button, the WiPy will boot -into standard mode; the ``boot.py`` file will be executed first, then -``main.py`` will run. - -You can override this boot sequence by pulling ``GP28`` **up** (connect -it to the 3v3 output pin) during reset. This procedure also allows going -back in time to old firmware versions. The WiPy can hold up to 3 different -firmware versions, which are: the factory firmware plus 2 user updates. - -After reset, if ``GP28`` is held high, the heartbeat LED will start flashing -slowly, if after 3 seconds the pin is still being held high, the LED will start -blinking a bit faster and the WiPy will select the previous user update to boot. -If the previous user update is the desired firmware image, ``GP28`` must be -released before 3 more seconds elapse. If 3 seconds later the pin is still high, -the factory firmware will be selected, the LED will flash quickly for 1.5 seconds -and the WiPy will proceed to boot. The firmware selection mechanism is as follows: - - -**Safe Boot Pin** ``GP28`` **released during:** - -+-------------------------+-------------------------+----------------------------+ -| 1st 3 secs window | 2nd 3 secs window | Final 1.5 secs window | -+=========================+=========================+============================+ -| | Safe boot, *latest* | | Safe boot, *previous* | | Safe boot, the *factory* | -| | firmware is selected | | user update selected | | firmware is selected | -+-------------------------+-------------------------+----------------------------+ - -On all of the above 3 scenarios, safe boot mode is entered, meaning that -the execution of both ``boot.py`` and ``main.py`` is skipped. This is -useful to recover from crash situations caused by the user scripts. The selection -made during safe boot is not persistent, therefore after the next normal reset -the latest firmware will run again. - -The heartbeat LED ------------------- - -By default the heartbeat LED flashes once every 4s to signal that the system is -alive. This can be overridden through the :mod:`wipy` module:: - - >>> import wipy - >>> wipy.heartbeat(False) - -There are currently 2 kinds of errors that you might see: - -1. If the heartbeat LED flashes quickly, then a Python script (eg ``main.py``) - has an error. Use the REPL to debug it. -2. If the heartbeat LED stays on, then there was a hard fault, you cannot - recover from this, the only way out is to press the reset switch. - -Details on sleep modes ----------------------- - -* ``machine.idle()``: Power consumption: ~12mA (in WLAN STA mode). Wake sources: - any hardware interrupt (including systick with period of 1ms), no special - configuration required. -* ``machine.sleep()``: 950uA (in WLAN STA mode). Wake sources are ``Pin``, ``RTC`` - and ``WLAN`` -* ``machine.deepsleep()``: ~350uA. Wake sources are ``Pin`` and ``RTC``. - -Additional details for machine.Pin ----------------------------------- - -On the WiPy board the pins are identified by their string id:: - - from machine import Pin - g = machine.Pin('GP9', mode=Pin.OUT, pull=None, drive=Pin.MED_POWER, alt=-1) - -You can also configure the Pin to generate interrupts. For instance:: - - from machine import Pin - - def pincb(pin): - print(pin.id()) - - pin_int = Pin('GP10', mode=Pin.IN, pull=Pin.PULL_DOWN) - pin_int.irq(trigger=Pin.IRQ_RISING, handler=pincb) - # the callback can be triggered manually - pin_int.irq()() - # to disable the callback - pin_int.irq().disable() - -Now every time a falling edge is seen on the gpio pin, the callback will be -executed. Caution: mechanical push buttons have "bounce" and pushing or -releasing a switch will often generate multiple edges. -See: http://www.eng.utah.edu/~cs5780/debouncing.pdf for a detailed -explanation, along with various techniques for debouncing. - -All pin objects go through the pin mapper to come up with one of the -gpio pins. - -For the ``drive`` parameter the strengths are: - - - ``Pin.LOW_POWER`` - 2mA drive capability. - - ``Pin.MED_POWER`` - 4mA drive capability. - - ``Pin.HIGH_POWER`` - 6mA drive capability. - -For the ``alt`` parameter please refer to the pinout and alternate functions -table at <https://raw.githubusercontent.com/wipy/wipy/master/docs/PinOUT.png>`_ -for the specific alternate functions that each pin supports. - -For interrupts, the ``priority`` can take values in the range 1-7. And the -``wake`` parameter has the following properties: - - - If ``wake_from=machine.Sleep.ACTIVE`` any pin can wake the board. - - If ``wake_from=machine.Sleep.SUSPENDED`` pins ``GP2``, ``GP4``, ``GP10``, - ``GP11``, GP17`` or ``GP24`` can wake the board. Note that only 1 - of this pins can be enabled as a wake source at the same time, so, only - the last enabled pin as a ``machine.Sleep.SUSPENDED`` wake source will have effect. - - If ``wake_from=machine.Sleep.SUSPENDED`` pins ``GP2``, ``GP4``, ``GP10``, - ``GP11``, ``GP17`` and ``GP24`` can wake the board. In this case all of the - 6 pins can be enabled as a ``machine.Sleep.HIBERNATE`` wake source at the same time. - -Additional Pin methods: - -.. method:: machine.Pin.alt_list() - - Returns a list of the alternate functions supported by the pin. List items are - a tuple of the form: ``('ALT_FUN_NAME', ALT_FUN_INDEX)`` - -Additional details for machine.I2C ----------------------------------- - -On the WiPy there is a single hardware I2C peripheral, identified by "0". By -default this is the peripheral that is used when constructing an I2C instance. -The default pins are GP23 for SCL and GP13 for SDA, and one can create the -default I2C peripheral simply by doing:: - - i2c = machine.I2C() - -The pins and frequency can be specified as:: - - i2c = machine.I2C(freq=400000, scl='GP23', sda='GP13') - -Only certain pins can be used as SCL/SDA. Please refer to the pinout for further -information. - -Known issues ------------- - -Incompatible way to create SSL sockets -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -SSL sockets need to be created the following way before wrapping them with. -``ssl.wrap_socket``:: - - import socket - import ssl - s = socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_SEC) - ss = ssl.wrap_socket(s) - -Certificates must be used in order to validate the other side of the connection, and also to -authenticate ourselves with the other end. Such certificates must be stored as files using the -FTP server, and they must be placed in specific paths with specific names. - -- The certificate to validate the other side goes in: **'/flash/cert/ca.pem'** -- The certificate to authenticate ourselves goes in: **'/flash/cert/cert.pem'** -- The key for our own certificate goes in: **'/flash/cert/private.key'** - -.. note:: - - When these files are stored, they are placed inside the internal **hidden** file system - (just like firmware updates), and therefore they are never visible. - -For instance to connect to the Blynk servers using certificates, take the file ``ca.pem`` located -in the `blynk examples folder <https://github.com/wipy/wipy/tree/master/examples/blynk>`_. -and put it in '/flash/cert/'. Then do:: - - import socket - import ssl - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_SEC) - ss = ssl.wrap_socket(s, cert_reqs=ssl.CERT_REQUIRED, ca_certs='/flash/cert/ca.pem') - ss.connect(socket.getaddrinfo('cloud.blynk.cc', 8441)[0][-1]) - -Incompatibilities in uhashlib module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Due to hardware implementation details of the WiPy, data must be buffered before being -digested, which would make it impossible to calculate the hash of big blocks of data that -do not fit in RAM. In this case, since most likely the total size of the data is known -in advance, the size can be passed to the constructor and hence the HASH hardware engine -of the WiPy can be properly initialized without needing buffering. If ``block_size`` is -to be given, an initial chunk of ``data`` must be passed as well. **When using this extension, -care must be taken to make sure that the length of all intermediate chunks (including the -initial one) is a multiple of 4 bytes.** The last chunk may be of any length. - -Example:: - - hash = uhashlib.sha1('abcd1234', 1001) # length of the initial piece is multiple of 4 bytes - hash.update('1234') # also multiple of 4 bytes - ... - hash.update('12345') # last chunk may be of any length - hash.digest() - -Unrelated function in machine module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -.. function:: main(filename) - - Set the filename of the main script to run after boot.py is finished. If - this function is not called then the default file main.py will be executed. - - It only makes sense to call this function from within boot.py. - -Adhoc way to control telnet/FTP server via network module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -The ``Server`` class controls the behaviour and the configuration of the FTP and telnet -services running on the WiPy. Any changes performed using this class' methods will -affect both. - -Example:: - - import network - server = network.Server() - server.deinit() # disable the server - # enable the server again with new settings - server.init(login=('user', 'password'), timeout=600) - -.. class:: network.Server(id, ...) - - Create a server instance, see ``init`` for parameters of initialization. - -.. method:: server.init(\*, login=('micro', 'python'), timeout=300) - - Init (and effectively start the server). Optionally a new ``user``, ``password`` - and ``timeout`` (in seconds) can be passed. - -.. method:: server.deinit() - - Stop the server - -.. method:: server.timeout([timeout_in_seconds]) - - Get or set the server timeout. - -.. method:: server.isrunning() - - Returns ``True`` if the server is running, ``False`` otherwise. - -Adhoc VFS-like support -~~~~~~~~~~~~~~~~~~~~~~ - -WiPy doesn't implement full MicroPython VFS support, instead following -functions are defined in ``uos`` module: - -.. function:: mount(block_device, mount_point, \*, readonly=False) - - Mounts a block device (like an ``SD`` object) in the specified mount - point. Example:: - - os.mount(sd, '/sd') - -.. function:: unmount(path) - - Unmounts a previously mounted block device from the given path. - -.. function:: mkfs(block_device or path) - - Formats the specified path, must be either ``/flash`` or ``/sd``. - A block device can also be passed like an ``SD`` object before - being mounted. - diff --git a/docs/wipy/index.rst b/docs/wipy/index.rst deleted file mode 100644 index 9b355d496..000000000 --- a/docs/wipy/index.rst +++ /dev/null @@ -1,8 +0,0 @@ -WiPy -================================== - -.. toctree:: - - quickref.rst - general.rst - tutorial/index.rst diff --git a/docs/wipy/quickref.rst b/docs/wipy/quickref.rst deleted file mode 100644 index f60c81f5f..000000000 --- a/docs/wipy/quickref.rst +++ /dev/null @@ -1,218 +0,0 @@ -.. _quickref_: - -Quick reference for the WiPy -============================ - -.. image:: https://raw.githubusercontent.com/wipy/wipy/master/docs/PinOUT.png - :alt: WiPy pinout and alternate functions table - :width: 800px - -General board control (including sleep modes) ---------------------------------------------- - -See the :mod:`machine` module:: - - import machine - - help(machine) # display all members from the machine module - machine.freq() # get the CPU frequency - machine.unique_id() # return the 6-byte unique id of the board (the WiPy's MAC address) - - machine.idle() # average current decreases to (~12mA), any interrupts wake it up - machine.sleep() # everything except for WLAN is powered down (~950uA avg. current) - # wakes from Pin, RTC or WLAN - machine.deepsleep() # deepest sleep mode, MCU starts from reset. Wakes from Pin and RTC. - -Pins and GPIO -------------- - -See :ref:`machine.Pin <machine.Pin>`. :: - - from machine import Pin - - # initialize GP2 in gpio mode (alt=0) and make it an output - p_out = Pin('GP2', mode=Pin.OUT) - p_out.value(1) - p_out.value(0) - p_out.toggle() - p_out(True) - - # make GP1 an input with the pull-up enabled - p_in = Pin('GP1', mode=Pin.IN, pull=Pin.PULL_UP) - p_in() # get value, 0 or 1 - -Timers ------- - -See :ref:`machine.Timer <machine.Timer>` and :ref:`machine.Pin <machine.Pin>`. -Timer ``id``'s take values from 0 to 3.:: - - from machine import Timer - from machine import Pin - - tim = Timer(0, mode=Timer.PERIODIC) - tim_a = tim.channel(Timer.A, freq=1000) - tim_a.freq(5) # 5 Hz - - p_out = Pin('GP2', mode=Pin.OUT) - tim_a.irq(trigger=Timer.TIMEOUT, handler=lambda t: p_out.toggle()) - -PWM (pulse width modulation) ----------------------------- - -See :ref:`machine.Pin <machine.Pin>` and :ref:`machine.Timer <machine.Timer>`. :: - - from machine import Timer - - # timer 1 in PWM mode and width must be 16 buts - tim = Timer(1, mode=Timer.PWM, width=16) - - # enable channel A @1KHz with a 50.55% duty cycle - tim_a = tim.channel(Timer.A, freq=1000, duty_cycle=5055) - -ADC (analog to digital conversion) ----------------------------------- - -See :ref:`machine.ADC <machine.ADC>`. :: - - from machine import ADC - - adc = ADC() - apin = adc.channel(pin='GP3') - apin() # read value, 0-4095 - -UART (serial bus) ------------------ - -See :ref:`machine.UART <machine.UART>`. :: - - from machine import UART - uart = UART(0, baudrate=9600) - uart.write('hello') - uart.read(5) # read up to 5 bytes - -SPI bus -------- - -See :ref:`machine.SPI <machine.SPI>`. :: - - from machine import SPI - - # configure the SPI master @ 2MHz - spi = SPI(0, SPI.MASTER, baudrate=200000, polarity=0, phase=0) - spi.write('hello') - spi.read(5) # receive 5 bytes on the bus - rbuf = bytearray(5) - spi.write_readinto('hello', rbuf) # send and receive 5 bytes - -I2C bus -------- - -See :ref:`machine.I2C <machine.I2C>`. :: - - from machine import I2C - # configure the I2C bus - i2c = I2C(baudrate=100000) - i2c.scan() # returns list of slave addresses - i2c.writeto(0x42, 'hello') # send 5 bytes to slave with address 0x42 - i2c.readfrom(0x42, 5) # receive 5 bytes from slave - i2c.readfrom_mem(0x42, 0x10, 2) # read 2 bytes from slave 0x42, slave memory 0x10 - i2c.writeto_mem(0x42, 0x10, 'xy') # write 2 bytes to slave 0x42, slave memory 0x10 - -Watchdog timer (WDT) --------------------- - -See :ref:`machine.WDT <machine.WDT>`. :: - - from machine import WDT - - # enable the WDT with a timeout of 5s (1s is the minimum) - wdt = WDT(timeout=5000) - wdt.feed() - -Real time clock (RTC) ---------------------- - -See :ref:`machine.RTC <machine.RTC>` :: - - from machine import RTC - - rtc = RTC() # init with default time and date - rtc = RTC(datetime=(2015, 8, 29, 9, 0, 0, 0, None)) # init with a specific time and date - print(rtc.now()) - - def alarm_handler (rtc_o): - pass - # do some non blocking operations - # warning printing on an irq via telnet is not - # possible, only via UART - - # create a RTC alarm that expires after 5 seconds - rtc.alarm(time=5000, repeat=False) - - # enable RTC interrupts - rtc_i = rtc.irq(trigger=RTC.ALARM0, handler=alarm_handler, wake=machine.SLEEP) - - # go into suspended mode waiting for the RTC alarm to expire and wake us up - machine.sleep() - -SD card -------- - -See :ref:`machine.SD <machine.SD>`. :: - - from machine import SD - import os - - # clock pin, cmd pin, data0 pin - sd = SD(pins=('GP10', 'GP11', 'GP15')) - # or use default ones for the expansion board - sd = SD() - os.mount(sd, '/sd') - -WLAN (WiFi) ------------ - -See :ref:`network.WLAN <network.WLAN>` and :mod:`machine`. :: - - import machine - from network import WLAN - - # configure the WLAN subsystem in station mode (the default is AP) - wlan = WLAN(mode=WLAN.STA) - # go for fixed IP settings - wlan.ifconfig(config=('192.168.0.107', '255.255.255.0', '192.168.0.1', '8.8.8.8')) - wlan.scan() # scan for available networks - wlan.connect(ssid='mynetwork', auth=(WLAN.WPA2, 'mynetworkkey')) - while not wlan.isconnected(): - pass - print(wlan.ifconfig()) - # enable wake on WLAN - wlan.irq(trigger=WLAN.ANY_EVENT, wake=machine.SLEEP) - # go to sleep - machine.sleep() - # now, connect to the FTP or the Telnet server and the WiPy will wake-up - -Telnet and FTP server ---------------------- - -See :ref:`network.Server <network.Server>` :: - - from network import Server - - # init with new user, password and seconds timeout - server = Server(login=('user', 'password'), timeout=60) - server.timeout(300) # change the timeout - server.timeout() # get the timeout - server.isrunning() # check whether the server is running or not - -Heart beat LED --------------- - -See :mod:`wipy`. :: - - import wipy - - wipy.heartbeat(False) # disable the heartbeat LED - wipy.heartbeat(True) # enable the heartbeat LED - wipy.heartbeat() # get the heartbeat state diff --git a/docs/wipy/tutorial/blynk.rst b/docs/wipy/tutorial/blynk.rst deleted file mode 100644 index b5a2f24a4..000000000 --- a/docs/wipy/tutorial/blynk.rst +++ /dev/null @@ -1,19 +0,0 @@ -Getting started with Blynk and the WiPy ---------------------------------------- - -Blynk is a platform with iOS and Android apps to control -Arduino, Raspberry Pi and the likes over the Internet. -You can easily build graphic interfaces for all your -projects by simply dragging and dropping widgets. - -There are several examples available that work out-of-the-box with -the WiPy. Before anything else, make sure that your WiPy is running -the latest software, check :ref:`OTA How-To <wipy_firmware_upgrade>` for instructions. - -1. Get the `Blynk library <https://github.com/wipy/wipy/blob/master/lib/blynk/BlynkLib.py>`_ and put it in ``/flash/lib/`` via FTP. -2. Get the `Blynk examples <https://github.com/wipy/wipy/tree/master/examples/blynk>`_, edit the network settings, and afterwards - upload them to ``/flash/lib/`` via FTP as well. -3. Follow the instructions on each example to setup the Blynk dashboard on your smartphone or tablet. -4. Give it a try, for instance:: - - >>> execfile('01_simple.py') diff --git a/docs/wipy/tutorial/index.rst b/docs/wipy/tutorial/index.rst deleted file mode 100644 index 816de27b5..000000000 --- a/docs/wipy/tutorial/index.rst +++ /dev/null @@ -1,18 +0,0 @@ -.. _wipy_tutorial_index: - -WiPy tutorials and examples -=========================== - -Before starting, make sure that you are running the latest firmware, -for instructions see :ref:`OTA How-To <wipy_firmware_upgrade>`. - -.. toctree:: - :maxdepth: 1 - :numbered: - - intro.rst - repl.rst - blynk.rst - wlan.rst - timer.rst - reset.rst diff --git a/docs/wipy/tutorial/intro.rst b/docs/wipy/tutorial/intro.rst deleted file mode 100644 index 3acc0510f..000000000 --- a/docs/wipy/tutorial/intro.rst +++ /dev/null @@ -1,64 +0,0 @@ -Introduction to the WiPy -======================== - -To get the most out of your WiPy, there are a few basic things to -understand about how it works. - -Caring for your WiPy and expansion board ----------------------------------------- - -Because the WiPy/expansion board does not have a housing it needs a bit of care: - - - Be gentle when plugging/unplugging the USB cable. Whilst the USB connector - is well soldered and is relatively strong, if it breaks off it can be very - difficult to fix. - - - Static electricity can shock the components on the WiPy and destroy them. - If you experience a lot of static electricity in your area (eg dry and cold - climates), take extra care not to shock the WiPy. If your WiPy came - in a ESD bag, then this bag is the best way to store and carry the - WiPy as it will protect it against static discharges. - -As long as you take care of the hardware, you should be okay. It's almost -impossible to break the software on the WiPy, so feel free to play around -with writing code as much as you like. If the filesystem gets corrupt, see -below on how to reset it. In the worst case you might need to do a safe boot, -which is explained in detail :ref:`here <wipy_boot_modes>`. - -Plugging into the expansion board and powering on -------------------------------------------------- - -The expansion board can power the WiPy via USB. The WiPy comes with a sticker -on top of the RF shield that labels all pins, and this should match the label -numbers on the expansion board headers. When plugging it in, the WiPy antenna -will end up on top of the SD card connector of the expansion board. A video -showing how to do this can be found `here <https://www.youtube.com/watch?v=47D9MZ9zFQw>`_. - -Expansion board hardware guide ------------------------------- - -The document explaining the hardware details of the expansion board can be found -`here <https://github.com/wipy/wipy/blob/master/docs/User_manual_exp_board.pdf>`_. - -Powering by an external power source ------------------------------------- - -The WiPy can be powered by a battery or other external power source. - -**Be sure to connect the positive lead of the power supply to VIN, and -ground to GND. There is no polarity protection on the WiPy so you -must be careful when connecting anything to VIN.** - -- When powering via ``VIN``: - - **The input voltage must be between 3.6V and 5.5V.** - -- When powering via ``3V3``: - - **The input voltage must be exactly 3V3, ripple free and from a supply capable - of sourcing at least 300mA of current** - -Performing firmware upgrades ----------------------------- - -For detailed instructions see :ref:`OTA How-To <wipy_firmware_upgrade>`. diff --git a/docs/wipy/tutorial/repl.rst b/docs/wipy/tutorial/repl.rst deleted file mode 100644 index e7b51f9c5..000000000 --- a/docs/wipy/tutorial/repl.rst +++ /dev/null @@ -1,130 +0,0 @@ -Getting a MicroPython REPL prompt -================================= - -REPL stands for Read Evaluate Print Loop, and is the name given to the -interactive MicroPython prompt that you can access on the WiPy. Using -the REPL is by far the easiest way to test out your code and run commands. -You can use the REPL in addition to writing scripts in ``main.py``. - -.. _wipy_uart: - -To use the REPL, you must connect to the WiPy either via :ref:`telnet <wipy_telnet>`, -or with a USB to serial converter wired to one of the two UARTs on the -WiPy. To enable REPL duplication on UART0 (the one accessible via the expansion board) -do:: - - >>> from machine import UART - >>> import os - >>> uart = UART(0, 115200) - >>> os.dupterm(uart) - -Place this piece of code inside your `boot.py` so that it's done automatically after -reset. - -Windows -------- - -First you need to install the FTDI drivers for the expansion board's USB to serial -converter. Then you need a terminal software. The best option is to download the -free program PuTTY: `putty.exe <http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html>`_. - -**In order to get to the telnet REPL:** - -Using putty, select ``Telnet`` as connection type, leave the default port (23) -and enter the IP address of your WiPy (192.168.1.1 when in ``WLAN.AP`` mode), -then click open. - -**In order to get to the REPL UART:** - -Using your serial program you must connect to the COM port that you found in the -previous step. With PuTTY, click on "Session" in the left-hand panel, then click -the "Serial" radio button on the right, then enter you COM port (eg COM4) in the -"Serial Line" box. Finally, click the "Open" button. - -Mac OS X --------- - -Open a terminal and run:: - - $ telnet 192.168.1.1 - -or:: - - $ screen /dev/tty.usbmodem* 115200 - -When you are finished and want to exit ``screen``, type CTRL-A CTRL-\\. If your keyboard does not have a \\-key (i.e. you need an obscure combination for \\ like ALT-SHIFT-7) you can remap the ``quit`` command: - -- create ``~/.screenrc`` -- add ``bind q quit`` - -This will allow you to quit ``screen`` by hitting CTRL-A Q. - -Linux ------ - -Open a terminal and run:: - - $ telnet 192.168.1.1 - -or:: - - $ screen /dev/ttyUSB0 115200 - -You can also try ``picocom`` or ``minicom`` instead of screen. You may have to -use ``/dev/ttyUSB01`` or a higher number for ``ttyUSB``. And, you may need to give -yourself the correct permissions to access this devices (eg group ``uucp`` or ``dialout``, -or use sudo). - -Using the REPL prompt ---------------------- - -Now let's try running some MicroPython code directly on the WiPy. - -With your serial program open (PuTTY, screen, picocom, etc) you may see a blank -screen with a flashing cursor. Press Enter and you should be presented with a -MicroPython prompt, i.e. ``>>>``. Let's make sure it is working with the obligatory test:: - - >>> print("hello WiPy!") - hello WiPy! - -In the above, you should not type in the ``>>>`` characters. They are there to -indicate that you should type the text after it at the prompt. In the end, once -you have entered the text ``print("hello WiPy!")`` and pressed Enter, the output -on your screen should look like it does above. - -If you already know some Python you can now try some basic commands here. - -If any of this is not working you can try either a hard reset or a soft reset; -see below. - -Go ahead and try typing in some other commands. For example:: - - >>> from machine import Pin - >>> import wipy - >>> wipy.heartbeat(False) # disable the heartbeat - >>> led = Pin('GP25', mode=Pin.OUT) - >>> led(1) - >>> led(0) - >>> led.toggle() - >>> 1 + 2 - 3 - >>> 4 // 2 - 2 - >>> 20 * 'py' - 'pypypypypypypypypypypypypypypypypypypypy' - -Resetting the board -------------------- - -If something goes wrong, you can reset the board in two ways. The first is to press CTRL-D -at the MicroPython prompt, which performs a soft reset. You will see a message something like:: - - >>> - PYB: soft reboot - MicroPython v1.4.6-146-g1d8b5e5 on 2015-10-21; WiPy with CC3200 - Type "help()" for more information. - >>> - -If that isn't working you can perform a hard reset (turn-it-off-and-on-again) by pressing the -RST switch (the small black button next to the heartbeat LED). During telnet, this will end -your session, disconnecting whatever program that you used to connect to the WiPy. diff --git a/docs/wipy/tutorial/reset.rst b/docs/wipy/tutorial/reset.rst deleted file mode 100644 index ece28498b..000000000 --- a/docs/wipy/tutorial/reset.rst +++ /dev/null @@ -1,54 +0,0 @@ -Reset and boot modes -==================== - -There are soft resets and hard resets. - - - A soft reset simply clears the state of the MicroPython virtual machine, - but leaves hardware peripherals unaffected. To do a soft reset, simply press - **Ctrl+D** on the REPL, or within a script do:: - - import sys - sys.exit() - - - A hard reset is the same as performing a power cycle to the board. In order to - hard reset the WiPy, press the switch on the board or:: - - import machine - machine.reset() - -Safe boot ---------- - -If something goes wrong with your WiPy, don't panic! It is almost -impossible for you to break the WiPy by programming the wrong thing. - -The first thing to try is to boot in safe mode: this temporarily skips -execution of ``boot.py`` and ``main.py`` and gives default WLAN settings. - -If you have problems with the filesystem you can :ref:`format the internal flash -drive <wipy_factory_reset>`. - -To boot in safe mode, follow the detailed instructions described :ref:`here <wipy_boot_modes>`. - -In safe mode, the ``boot.py`` and ``main.py`` files are not executed, and so -the WiPy boots up with default settings. This means you now have access -to the filesystem, and you can edit ``boot.py`` and ``main.py`` to fix any problems. - -Entering safe mode is temporary, and does not make any changes to the -files on the WiPy. - -.. _wipy_factory_reset: - -Factory reset the filesystem ----------------------------- - -If you WiPy's filesystem gets corrupted (very unlikely, but possible), you -can format it very easily by doing:: - - >>> import os - >>> os.mkfs('/flash') - -Resetting the filesystem deletes all files on the internal WiPy storage -(not the SD card), and restores the files ``boot.py`` and ``main.py`` back -to their original state after the next reset. - diff --git a/docs/wipy/tutorial/timer.rst b/docs/wipy/tutorial/timer.rst deleted file mode 100644 index c87ac4495..000000000 --- a/docs/wipy/tutorial/timer.rst +++ /dev/null @@ -1,70 +0,0 @@ -Hardware timers -=============== - -Timers can be used for a great variety of tasks, calling a function periodically, -counting events, and generating a PWM signal are among the most common use cases. -Each timer consists of two 16-bit channels and this channels can be tied together to -form one 32-bit timer. The operating mode needs to be configured per timer, but then -the period (or the frequency) can be independently configured on each channel. -By using the callback method, the timer event can call a Python function. - -Example usage to toggle an LED at a fixed frequency:: - - from machine import Timer - from machine import Pin - led = Pin('GP16', mode=Pin.OUT) # enable GP16 as output to drive the LED - tim = Timer(3) # create a timer object using timer 3 - tim.init(mode=Timer.PERIODIC) # initialize it in periodic mode - tim_ch = tim.channel(Timer.A, freq=5) # configure channel A at a frequency of 5Hz - tim_ch.irq(handler=lambda t:led.toggle(), trigger=Timer.TIMEOUT) # toggle a LED on every cycle of the timer - -Example using named function for the callback:: - - from machine import Timer - from machine import Pin - tim = Timer(1, mode=Timer.PERIODIC, width=32) - tim_a = tim.channel(Timer.A | Timer.B, freq=1) # 1 Hz frequency requires a 32 bit timer - - led = Pin('GP16', mode=Pin.OUT) # enable GP16 as output to drive the LED - - def tick(timer): # we will receive the timer object when being called - global led - led.toggle() # toggle the LED - - tim_a.irq(handler=tick, trigger=Timer.TIMEOUT) # create the interrupt - -Further examples:: - - from machine import Timer - tim1 = Timer(1, mode=Timer.ONE_SHOT) # initialize it in one shot mode - tim2 = Timer(2, mode=Timer.PWM) # initialize it in PWM mode - tim1_ch = tim1.channel(Timer.A, freq=10, polarity=Timer.POSITIVE) # start the event counter with a frequency of 10Hz and triggered by positive edges - tim2_ch = tim2.channel(Timer.B, freq=10000, duty_cycle=5000) # start the PWM on channel B with a 50% duty cycle - tim2_ch.freq(20) # set the frequency (can also get) - tim2_ch.duty_cycle(3010) # set the duty cycle to 30.1% (can also get) - tim2_ch.duty_cycle(3020, Timer.NEGATIVE) # set the duty cycle to 30.2% and change the polarity to negative - tim2_ch.period(2000000) # change the period to 2 seconds - - -Additional constants for Timer class ------------------------------------- - -.. data:: Timer.PWM - - PWM timer operating mode. - -.. data:: Timer.A -.. data:: Timer.B - - Selects the timer channel. Must be ORed (``Timer.A`` | ``Timer.B``) when - using a 32-bit timer. - -.. data:: Timer.POSITIVE -.. data:: Timer.NEGATIVE - - Timer channel polarity selection (only relevant in PWM mode). - -.. data:: Timer.TIMEOUT -.. data:: Timer.MATCH - - Timer channel IRQ triggers. diff --git a/docs/wipy/tutorial/wlan.rst b/docs/wipy/tutorial/wlan.rst deleted file mode 100644 index 434367cd9..000000000 --- a/docs/wipy/tutorial/wlan.rst +++ /dev/null @@ -1,71 +0,0 @@ -WLAN step by step -================= - -The WLAN is a system feature of the WiPy, therefore it is always enabled -(even while in ``machine.SLEEP``), except when deepsleep mode is entered. - -In order to retrieve the current WLAN instance, do:: - - >>> from network import WLAN - >>> wlan = WLAN() # we call the constructor without params - -You can check the current mode (which is always ``WLAN.AP`` after power up):: - - >>> wlan.mode() - -.. warning:: - When you change the WLAN mode following the instructions below, your WLAN - connection to the WiPy will be broken. This means you will not be able - to run these commands interactively over the WLAN. - - There are two ways around this:: - 1. put this setup code into your :ref:`boot.py file<wipy_filesystem>` so that it gets executed automatically after reset. - 2. :ref:`duplicate the REPL on UART <wipy_uart>`, so that you can run commands via USB. - -Connecting to your home router ------------------------------- - -The WLAN network card always boots in ``WLAN.AP`` mode, so we must first configure -it as a station:: - - from network import WLAN - wlan = WLAN(mode=WLAN.STA) - - -Now you can proceed to scan for networks:: - - nets = wlan.scan() - for net in nets: - if net.ssid == 'mywifi': - print('Network found!') - wlan.connect(net.ssid, auth=(net.sec, 'mywifikey'), timeout=5000) - while not wlan.isconnected(): - machine.idle() # save power while waiting - print('WLAN connection succeeded!') - break - -Assigning a static IP address when booting ------------------------------------------- - -If you want your WiPy to connect to your home router after boot-up, and with a fixed -IP address so that you can access it via telnet or FTP, use the following script as /flash/boot.py:: - - import machine - from network import WLAN - wlan = WLAN() # get current object, without changing the mode - - if machine.reset_cause() != machine.SOFT_RESET: - wlan.init(WLAN.STA) - # configuration below MUST match your home router settings!! - wlan.ifconfig(config=('192.168.178.107', '255.255.255.0', '192.168.178.1', '8.8.8.8')) - - if not wlan.isconnected(): - # change the line below to match your network ssid, security and password - wlan.connect('mywifi', auth=(WLAN.WPA2, 'mywifikey'), timeout=5000) - while not wlan.isconnected(): - machine.idle() # save power while waiting - -.. note:: - - Notice how we check for the reset cause and the connection status, this is crucial in order - to be able to soft reset the WiPy during a telnet session without breaking the connection. |
