2018-09-27 08:27:57 +01:00
|
|
|
.. _wipy_quickref:
|
2015-06-10 22:29:56 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2018-09-27 08:27:57 +01:00
|
|
|
Below is a quick reference for CC3200/WiPy. If it is your first time
|
|
|
|
working with this board please consider reading the following sections first:
|
|
|
|
|
|
|
|
.. toctree::
|
|
|
|
:maxdepth: 1
|
|
|
|
|
|
|
|
general.rst
|
|
|
|
tutorial/index.rst
|
|
|
|
|
2015-10-14 11:32:01 +01:00
|
|
|
General board control (including sleep modes)
|
|
|
|
---------------------------------------------
|
|
|
|
|
2015-10-19 14:19:34 +01:00
|
|
|
See the :mod:`machine` module::
|
2015-06-10 22:29:56 +01:00
|
|
|
|
2015-10-14 11:32:01 +01:00
|
|
|
import machine
|
2015-06-10 22:29:56 +01:00
|
|
|
|
2015-10-14 11:32:01 +01:00
|
|
|
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)
|
2015-06-10 22:29:56 +01:00
|
|
|
|
2015-10-26 19:41:14 +00:00
|
|
|
machine.idle() # average current decreases to (~12mA), any interrupts wake it up
|
2019-01-30 03:15:51 +00:00
|
|
|
machine.lightsleep() # everything except for WLAN is powered down (~950uA avg. current)
|
2015-10-14 11:32:01 +01:00
|
|
|
# wakes from Pin, RTC or WLAN
|
|
|
|
machine.deepsleep() # deepest sleep mode, MCU starts from reset. Wakes from Pin and RTC.
|
2015-06-10 22:29:56 +01:00
|
|
|
|
|
|
|
Pins and GPIO
|
|
|
|
-------------
|
|
|
|
|
2015-10-14 11:32:01 +01:00
|
|
|
See :ref:`machine.Pin <machine.Pin>`. ::
|
2015-06-10 22:29:56 +01:00
|
|
|
|
2015-10-14 11:32:01 +01:00
|
|
|
from machine import Pin
|
2015-06-10 22:29:56 +01:00
|
|
|
|
2015-10-21 10:06:26 +01:00
|
|
|
# initialize GP2 in gpio mode (alt=0) and make it an output
|
2015-09-03 10:25:44 +01:00
|
|
|
p_out = Pin('GP2', mode=Pin.OUT)
|
2015-09-04 13:36:52 +01:00
|
|
|
p_out.value(1)
|
|
|
|
p_out.value(0)
|
2015-06-10 22:29:56 +01:00
|
|
|
p_out.toggle()
|
2015-09-03 10:25:44 +01:00
|
|
|
p_out(True)
|
2015-06-10 22:29:56 +01:00
|
|
|
|
2015-07-28 22:03:53 +01:00
|
|
|
# make GP1 an input with the pull-up enabled
|
2015-10-14 11:32:01 +01:00
|
|
|
p_in = Pin('GP1', mode=Pin.IN, pull=Pin.PULL_UP)
|
2015-09-03 10:25:44 +01:00
|
|
|
p_in() # get value, 0 or 1
|
2015-06-10 22:29:56 +01:00
|
|
|
|
|
|
|
Timers
|
|
|
|
------
|
|
|
|
|
2018-07-29 15:19:41 +01:00
|
|
|
See :ref:`machine.TimerWiPy <machine.TimerWiPy>` and :ref:`machine.Pin <machine.Pin>`.
|
2017-01-28 08:55:48 +00:00
|
|
|
Timer ``id``'s take values from 0 to 3.::
|
2015-06-10 22:29:56 +01:00
|
|
|
|
2015-10-14 11:32:01 +01:00
|
|
|
from machine import Timer
|
|
|
|
from machine import Pin
|
2015-06-10 22:29:56 +01:00
|
|
|
|
2016-02-14 12:46:04 +00:00
|
|
|
tim = Timer(0, mode=Timer.PERIODIC)
|
2015-06-10 22:29:56 +01:00
|
|
|
tim_a = tim.channel(Timer.A, freq=1000)
|
2016-02-14 12:46:04 +00:00
|
|
|
tim_a.freq(5) # 5 Hz
|
2019-12-04 04:02:54 +00:00
|
|
|
|
2015-10-21 10:06:26 +01:00
|
|
|
p_out = Pin('GP2', mode=Pin.OUT)
|
2016-08-22 19:59:31 +01:00
|
|
|
tim_a.irq(trigger=Timer.TIMEOUT, handler=lambda t: p_out.toggle())
|
2015-06-10 22:29:56 +01:00
|
|
|
|
|
|
|
PWM (pulse width modulation)
|
|
|
|
----------------------------
|
|
|
|
|
2015-10-14 11:32:01 +01:00
|
|
|
See :ref:`machine.Pin <machine.Pin>` and :ref:`machine.Timer <machine.Timer>`. ::
|
2015-06-10 22:29:56 +01:00
|
|
|
|
2015-10-14 11:32:01 +01:00
|
|
|
from machine import Timer
|
2015-06-10 22:29:56 +01:00
|
|
|
|
2016-02-23 19:18:45 +00:00
|
|
|
# timer 1 in PWM mode and width must be 16 buts
|
|
|
|
tim = Timer(1, mode=Timer.PWM, width=16)
|
2019-12-04 04:02:54 +00:00
|
|
|
|
2016-02-23 19:18:45 +00:00
|
|
|
# enable channel A @1KHz with a 50.55% duty cycle
|
|
|
|
tim_a = tim.channel(Timer.A, freq=1000, duty_cycle=5055)
|
2015-06-10 22:29:56 +01:00
|
|
|
|
|
|
|
ADC (analog to digital conversion)
|
|
|
|
----------------------------------
|
|
|
|
|
2019-09-04 06:05:03 +01:00
|
|
|
See :ref:`machine.ADCWiPy <machine.ADCWiPy>`. ::
|
2015-06-10 22:29:56 +01:00
|
|
|
|
2015-10-14 11:32:01 +01:00
|
|
|
from machine import ADC
|
2015-06-10 22:29:56 +01:00
|
|
|
|
2015-09-15 18:54:58 +01:00
|
|
|
adc = ADC()
|
|
|
|
apin = adc.channel(pin='GP3')
|
|
|
|
apin() # read value, 0-4095
|
2015-06-10 22:29:56 +01:00
|
|
|
|
|
|
|
UART (serial bus)
|
|
|
|
-----------------
|
|
|
|
|
2015-10-20 15:24:25 +01:00
|
|
|
See :ref:`machine.UART <machine.UART>`. ::
|
2015-06-10 22:29:56 +01:00
|
|
|
|
2015-10-20 15:24:25 +01:00
|
|
|
from machine import UART
|
2015-10-14 11:32:01 +01:00
|
|
|
uart = UART(0, baudrate=9600)
|
2015-06-10 22:29:56 +01:00
|
|
|
uart.write('hello')
|
|
|
|
uart.read(5) # read up to 5 bytes
|
|
|
|
|
|
|
|
SPI bus
|
|
|
|
-------
|
|
|
|
|
2015-10-14 11:32:01 +01:00
|
|
|
See :ref:`machine.SPI <machine.SPI>`. ::
|
2015-06-10 22:29:56 +01:00
|
|
|
|
2015-10-20 15:24:25 +01:00
|
|
|
from machine import SPI
|
2015-06-10 22:29:56 +01:00
|
|
|
|
2021-06-12 05:51:05 +01:00
|
|
|
# configure the SPI controller @ 2MHz
|
|
|
|
spi = SPI(0, SPI.CONTROLLER, baudrate=2_000_000, polarity=0, phase=0)
|
2015-09-15 18:54:58 +01:00
|
|
|
spi.write('hello')
|
|
|
|
spi.read(5) # receive 5 bytes on the bus
|
|
|
|
rbuf = bytearray(5)
|
2016-12-21 02:48:20 +00:00
|
|
|
spi.write_readinto('hello', rbuf) # send and receive 5 bytes
|
2015-06-10 22:29:56 +01:00
|
|
|
|
|
|
|
I2C bus
|
|
|
|
-------
|
|
|
|
|
2015-10-20 15:24:25 +01:00
|
|
|
See :ref:`machine.I2C <machine.I2C>`. ::
|
2015-06-10 22:29:56 +01:00
|
|
|
|
2015-10-20 15:24:25 +01:00
|
|
|
from machine import I2C
|
2015-06-10 22:29:56 +01:00
|
|
|
# configure the I2C bus
|
2017-04-18 04:20:07 +01:00
|
|
|
i2c = I2C(baudrate=100000)
|
2021-06-12 05:51:05 +01:00
|
|
|
i2c.scan() # returns list of peripheral addresses
|
|
|
|
i2c.writeto(0x42, 'hello') # send 5 bytes to peripheral with address 0x42
|
|
|
|
i2c.readfrom(0x42, 5) # receive 5 bytes from peripheral
|
|
|
|
i2c.readfrom_mem(0x42, 0x10, 2) # read 2 bytes from peripheral 0x42, peripheral memory 0x10
|
|
|
|
i2c.writeto_mem(0x42, 0x10, 'xy') # write 2 bytes to peripheral 0x42, peripheral memory 0x10
|
2015-06-10 22:29:56 +01:00
|
|
|
|
|
|
|
Watchdog timer (WDT)
|
|
|
|
--------------------
|
|
|
|
|
2015-10-14 11:32:01 +01:00
|
|
|
See :ref:`machine.WDT <machine.WDT>`. ::
|
2015-06-10 22:29:56 +01:00
|
|
|
|
2015-10-14 11:32:01 +01:00
|
|
|
from machine import WDT
|
2015-06-10 22:29:56 +01:00
|
|
|
|
|
|
|
# enable the WDT with a timeout of 5s (1s is the minimum)
|
2015-09-15 18:54:58 +01:00
|
|
|
wdt = WDT(timeout=5000)
|
|
|
|
wdt.feed()
|
|
|
|
|
2015-06-10 22:29:56 +01:00
|
|
|
Real time clock (RTC)
|
|
|
|
---------------------
|
|
|
|
|
2015-10-14 11:32:01 +01:00
|
|
|
See :ref:`machine.RTC <machine.RTC>` ::
|
2015-06-10 22:29:56 +01:00
|
|
|
|
2015-10-14 11:32:01 +01:00
|
|
|
from machine import RTC
|
2015-06-10 22:29:56 +01:00
|
|
|
|
2016-08-22 19:59:31 +01:00
|
|
|
rtc = RTC() # init with default time and date
|
2015-10-14 11:32:01 +01:00
|
|
|
rtc = RTC(datetime=(2015, 8, 29, 9, 0, 0, 0, None)) # init with a specific time and date
|
|
|
|
print(rtc.now())
|
2015-06-10 22:29:56 +01:00
|
|
|
|
2015-10-14 11:32:01 +01:00
|
|
|
def alarm_handler (rtc_o):
|
|
|
|
pass
|
|
|
|
# do some non blocking operations
|
|
|
|
# warning printing on an irq via telnet is not
|
|
|
|
# possible, only via UART
|
2015-06-10 22:29:56 +01:00
|
|
|
|
2015-10-14 11:32:01 +01:00
|
|
|
# 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)
|
2015-06-10 22:29:56 +01:00
|
|
|
|
|
|
|
# go into suspended mode waiting for the RTC alarm to expire and wake us up
|
2019-01-30 03:15:51 +00:00
|
|
|
machine.lightsleep()
|
2015-06-10 22:29:56 +01:00
|
|
|
|
|
|
|
SD card
|
|
|
|
-------
|
|
|
|
|
2015-10-14 11:32:01 +01:00
|
|
|
See :ref:`machine.SD <machine.SD>`. ::
|
2015-06-10 22:29:56 +01:00
|
|
|
|
2015-10-14 11:32:01 +01:00
|
|
|
from machine import SD
|
2015-09-16 13:09:51 +01:00
|
|
|
import os
|
2015-06-10 22:29:56 +01:00
|
|
|
|
2015-09-16 13:09:51 +01:00
|
|
|
# clock pin, cmd pin, data0 pin
|
|
|
|
sd = SD(pins=('GP10', 'GP11', 'GP15'))
|
2015-10-14 11:32:01 +01:00
|
|
|
# or use default ones for the expansion board
|
|
|
|
sd = SD()
|
2015-09-16 13:09:51 +01:00
|
|
|
os.mount(sd, '/sd')
|
2015-06-10 22:29:56 +01:00
|
|
|
|
|
|
|
WLAN (WiFi)
|
|
|
|
-----------
|
|
|
|
|
2015-10-14 11:32:01 +01:00
|
|
|
See :ref:`network.WLAN <network.WLAN>` and :mod:`machine`. ::
|
2015-06-10 22:29:56 +01:00
|
|
|
|
2015-10-14 11:32:01 +01:00
|
|
|
import machine
|
2015-06-10 22:29:56 +01:00
|
|
|
from network import WLAN
|
|
|
|
|
|
|
|
# configure the WLAN subsystem in station mode (the default is AP)
|
2015-11-10 00:10:50 +00:00
|
|
|
wlan = WLAN(mode=WLAN.STA)
|
2015-06-10 22:29:56 +01:00
|
|
|
# go for fixed IP settings
|
2015-11-10 00:10:50 +00:00
|
|
|
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():
|
2015-06-10 22:29:56 +01:00
|
|
|
pass
|
2015-11-10 00:10:50 +00:00
|
|
|
print(wlan.ifconfig())
|
2015-06-10 22:29:56 +01:00
|
|
|
# enable wake on WLAN
|
2015-11-10 00:10:50 +00:00
|
|
|
wlan.irq(trigger=WLAN.ANY_EVENT, wake=machine.SLEEP)
|
2015-06-10 22:29:56 +01:00
|
|
|
# go to sleep
|
2019-01-30 03:15:51 +00:00
|
|
|
machine.lightsleep()
|
2015-06-10 22:29:56 +01:00
|
|
|
# now, connect to the FTP or the Telnet server and the WiPy will wake-up
|
|
|
|
|
2015-10-19 14:19:34 +01:00
|
|
|
Telnet and FTP server
|
|
|
|
---------------------
|
|
|
|
|
2018-10-01 05:08:02 +01:00
|
|
|
See :class:`network.Server` ::
|
2015-10-19 14:19:34 +01:00
|
|
|
|
2016-02-22 21:51:22 +00:00
|
|
|
from network import Server
|
2015-10-19 14:19:34 +01:00
|
|
|
|
2015-10-26 19:41:14 +00:00
|
|
|
# init with new user, password and seconds timeout
|
2016-02-22 21:51:22 +00:00
|
|
|
server = Server(login=('user', 'password'), timeout=60)
|
2015-10-19 14:19:34 +01:00
|
|
|
server.timeout(300) # change the timeout
|
|
|
|
server.timeout() # get the timeout
|
2016-08-01 00:52:00 +01:00
|
|
|
server.isrunning() # check whether the server is running or not
|
2015-10-19 14:19:34 +01:00
|
|
|
|
2015-10-20 15:24:25 +01:00
|
|
|
Heart beat LED
|
|
|
|
--------------
|
2015-06-10 22:29:56 +01:00
|
|
|
|
2015-10-19 14:19:34 +01:00
|
|
|
See :mod:`wipy`. ::
|
2015-06-10 22:29:56 +01:00
|
|
|
|
2015-10-19 14:19:34 +01:00
|
|
|
import wipy
|
2015-06-10 22:29:56 +01:00
|
|
|
|
2015-10-19 14:19:34 +01:00
|
|
|
wipy.heartbeat(False) # disable the heartbeat LED
|
|
|
|
wipy.heartbeat(True) # enable the heartbeat LED
|
|
|
|
wipy.heartbeat() # get the heartbeat state
|