diff options
Diffstat (limited to 'docs/esp8266')
-rw-r--r-- | docs/esp8266/quickref.rst | 41 | ||||
-rw-r--r-- | docs/esp8266/tutorial/intro.rst | 4 | ||||
-rw-r--r-- | docs/esp8266/tutorial/onewire.rst | 6 | ||||
-rw-r--r-- | docs/esp8266/tutorial/pins.rst | 2 |
4 files changed, 36 insertions, 17 deletions
diff --git a/docs/esp8266/quickref.rst b/docs/esp8266/quickref.rst index 48543dfab6..d06fe5a6f1 100644 --- a/docs/esp8266/quickref.rst +++ b/docs/esp8266/quickref.rst @@ -23,14 +23,14 @@ Tab-completion is useful to find out what methods an object has. Paste mode (ctrl-E) is useful to paste a large slab of Python code into the REPL. -The ``machine`` module:: +The :mod:`machine` module:: import machine machine.freq() # get the current frequency of the CPU machine.freq(160000000) # set the CPU frequency to 160 MHz -The ``esp`` module:: +The :mod:`esp` module:: import esp @@ -40,7 +40,7 @@ The ``esp`` module:: Networking ---------- -The ``network`` module:: +The :mod:`network` module:: import network @@ -69,13 +69,13 @@ A useful function for connecting to your local WiFi network is:: pass print('network config:', wlan.ifconfig()) -Once the network is established the ``socket`` module can be used +Once the network is established the :mod:`socket <usocket>` module can be used to create and use TCP/UDP sockets as usual. Delay and timing ---------------- -Use the ``time`` module:: +Use the :mod:`time <utime>` module:: import time @@ -162,17 +162,18 @@ Use the ``machine.ADC`` class:: adc = ADC(0) # create ADC object on ADC pin adc.read() # read value, 0-1024 -SPI bus -------- +Software SPI bus +---------------- -The SPI driver is implemented in software and works on all pins:: +There are two SPI drivers. One is implemented in software (bit-banging) +and works on all pins:: from machine import Pin, SPI # construct an SPI bus on the given pins # polarity is the idle state of SCK # phase=0 means sample on the first edge of SCK, phase=1 means the second - spi = SPI(baudrate=100000, polarity=1, phase=0, sck=Pin(0), mosi=Pin(2), miso=Pin(4)) + spi = SPI(-1, baudrate=100000, polarity=1, phase=0, sck=Pin(0), mosi=Pin(2), miso=Pin(4)) spi.init(baudrate=200000) # set the baudrate @@ -189,6 +190,21 @@ The SPI driver is implemented in software and works on all pins:: spi.write_readinto(b'1234', buf) # write to MOSI and read from MISO into the buffer spi.write_readinto(buf, buf) # write buf to MOSI and read MISO back into buf + +Hardware SPI bus +---------------- + +The hardware SPI is faster (up to 80Mhz), but only works on following pins: +``MISO`` is GPIO12, ``MOSI`` is GPIO13, and ``SCK`` is GPIO14. It has the same +methods as the bitbanging SPI class above, except for the pin parameters for the +constructor and init (as those are fixed):: + + from machine import Pin, SPI + + hspi = SPI(1, baudrate=80000000, polarity=0, phase=0) + +(``SPI(0)`` is used for FlashROM and not available to users.) + I2C bus ------- @@ -239,15 +255,14 @@ The OneWire driver is implemented in software and works on all pins:: ow.scan() # return a list of devices on the bus ow.reset() # reset the bus ow.readbyte() # read a byte - ow.read(5) # read 5 bytes ow.writebyte(0x12) # write a byte on the bus ow.write('123') # write bytes on the bus ow.select_rom(b'12345678') # select a specific device by its ROM code -There is a specific driver for DS18B20 devices:: +There is a specific driver for DS18S20 and DS18B20 devices:: - import time - ds = onewire.DS18B20(ow) + import time, ds18x20 + ds = ds18x20.DS18X20(ow) roms = ds.scan() ds.convert_temp() time.sleep_ms(750) diff --git a/docs/esp8266/tutorial/intro.rst b/docs/esp8266/tutorial/intro.rst index 8c356b913f..32e9326b37 100644 --- a/docs/esp8266/tutorial/intro.rst +++ b/docs/esp8266/tutorial/intro.rst @@ -135,6 +135,10 @@ after it, here are troubleshooting recommendations: rate may be too high and lead to errors. Try a more common 115200 baud rate instead in such cases. +* If lower baud rate didn't help, you may want to try older version of + esptool.py, which had a different programming algorithm:: + pip install esptool==1.0.1 + * The ``--flash_size`` option in the commands above is mandatory. Omitting it will lead to a corrupted firmware. diff --git a/docs/esp8266/tutorial/onewire.rst b/docs/esp8266/tutorial/onewire.rst index c90044b7a8..c2cede9e38 100644 --- a/docs/esp8266/tutorial/onewire.rst +++ b/docs/esp8266/tutorial/onewire.rst @@ -6,19 +6,19 @@ The 1-wire bus is a serial bus that uses just a single wire for communication is a very popular 1-wire device, and here we show how to use the onewire module to read from such a device. -For the following code to work you need to have at least one DS18B20 temperature +For the following code to work you need to have at least one DS18S20 or DS18B20 temperature sensor with its data line connected to GPIO12. You must also power the sensors and connect a 4.7k Ohm resistor between the data pin and the power pin. :: import time import machine - import onewire + import onewire, ds18x20 # the device is on GPIO12 dat = machine.Pin(12) # create the onewire object - ds = onewire.DS18B20(onewire.OneWire(dat)) + ds = ds18x20.DS18X20(onewire.OneWire(dat)) # scan for devices on the bus roms = ds.scan() diff --git a/docs/esp8266/tutorial/pins.rst b/docs/esp8266/tutorial/pins.rst index 639267d2ee..a44f40d3a7 100644 --- a/docs/esp8266/tutorial/pins.rst +++ b/docs/esp8266/tutorial/pins.rst @@ -14,7 +14,7 @@ Here, the "0" is the pin that you want to access. Usually you want to configure the pin to be input or output, and you do this when constructing it. To make an input pin use:: - >>> pin = machine.Pin(0, machine.Pin.OUT, machine.Pin.PULL_UP) + >>> pin = machine.Pin(0, machine.Pin.IN, machine.Pin.PULL_UP) You can either use PULL_UP or None for the input pull-mode. If it's not specified then it defaults to None, which is no pull resistor. |