mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
commit
d5a59e7790
53
README.md
53
README.md
@ -27,7 +27,7 @@ $ ant dist
|
||||
|
||||
#### Basic Wiring functions ####
|
||||
|
||||
```pinMode```, ```digitalRead```, ```digitalWrite``` work as usual.
|
||||
```pinMode```, ```digitalRead```, ```digitalWrite```, ```analogWrite``` work as usual.
|
||||
|
||||
Pin numbers correspond directly to the esp8266 GPIO pin numbers. To read GPIO2,
|
||||
call ```digitalRead(2);```
|
||||
@ -35,7 +35,10 @@ call ```digitalRead(2);```
|
||||
GPIO0-GPIO15 can be ```INPUT```, ```OUTPUT```, ```INPUT_PULLUP```, and ```OUTPUT_OPEN_DRAIN```.
|
||||
GPIO16 can be ```INPUT``` or ```OUTPUT```.
|
||||
|
||||
```analogRead(0)``` reads the value of the ADC channel connected to the TOUT pin.
|
||||
```analogRead(A0)``` reads the value of the ADC channel connected to the TOUT pin.
|
||||
|
||||
```analogWrite(pin, value)``` enables software PWM on the given pin. PWM may be used on pins 0 to 15.
|
||||
Call ```analogWrite(pin, 0)``` to disable PWM on the pin.
|
||||
|
||||
Pin interrupts are supported through ```attachInterrupt```, ```detachInterrupt``` functions.
|
||||
Interrupts may be attached to any GPIO pin, except GPIO16. Standard Arduino interrupt
|
||||
@ -62,7 +65,13 @@ more than 20 milliseconds is not recommended.
|
||||
|
||||
```Serial``` object works much the same way as on a regular Arduino. Apart from hardware FIFO (128 bytes for TX and RX) HardwareSerial has additional 256-byte TX and RX buffers. Both transmit and receive is interrupt-driven. Write and read functions only block the sketch execution when the respective FIFO/buffers are full/empty.
|
||||
|
||||
By default the diagnostic output from WiFi libraries is disabled when you call ```Serial.begin```. To enable debug output again, call ```Serial.setDebugOutput(true);```
|
||||
```Serial``` uses UART0, which is mapped to pins GPIO1 (TX) and GPIO3 (RX). Serial may be remapped to GPIO15 (TX) and GPIO13 (RX) by calling ```Serial.swap();``` after ```Serial.begin();```. Calling ```swap``` again maps UART0 back to GPIO1 and GPIO3.
|
||||
|
||||
```Serial1``` uses UART1 which is a transmit-only UART. UART1 TX pin is GPIO2. To use ```Serial1```, call ```Serial1.begin```.
|
||||
|
||||
By default the diagnostic output from WiFi libraries is disabled when you call ```Serial.begin```. To enable debug output again, call ```Serial.setDebugOutput(true);```. To redirect debug output to ```Serial1``` instead, call ```Serial1.setDebugOutput(true);```.
|
||||
|
||||
Both ```Serial``` and ```Serial1``` objects support 5, 6, 7, 8 data bits, odd (O), even (E), and no (N) parity, and 1 or 2 stop bits. To set the desired mode, call ```Serial.begin(baudrate, SERIAL_8N1);```, ```Serial.begin(baudrate, SERIAL_6E2);```, etc.
|
||||
|
||||
#### WiFi(ESP8266WiFi library) ####
|
||||
|
||||
@ -91,6 +100,9 @@ Four samples are provided for this library.
|
||||
|
||||
Library for calling functions repeatedly with a certain period. Two examples included.
|
||||
|
||||
It is currently not recommended to do blocking IO operations (network, serial, file) from Ticker
|
||||
callback functions. Instead, set a flag inside the ticker callback and check for that flag inside the loop function.
|
||||
|
||||
#### EEPROM ####
|
||||
|
||||
This is a bit different from standard EEPROM class. You need to call ```EEPROM.begin(size)```
|
||||
@ -101,29 +113,43 @@ Size can be anywhere between 4 and 4096 bytes.
|
||||
whenever you wish to save changes to flash. ```EEPROM.end()``` will also commit, and will
|
||||
release the RAM copy of EEPROM contents.
|
||||
|
||||
EEPROM library uses one sector of flash located at 0x7b000 for storage.
|
||||
|
||||
Three examples included.
|
||||
|
||||
#### I2C (Wire library) ####
|
||||
|
||||
Only master mode works, and ```Wire.setClock``` has not been verified to give exactly correct frequency.
|
||||
Wire library currently supports master mode up to approximately 450KHz (at 80 MHz CPU clock).
|
||||
Before using I2C, pins for SDA and SCL need to be set by calling
|
||||
```Wire.pins(int sda, int scl)```, i.e. ```Wire.pins(0, 2);``` on ESP-01.
|
||||
```Wire.begin(int sda, int scl)```, i.e. ```Wire.begin(0, 2);``` on ESP-01.
|
||||
|
||||
#### SPI ####
|
||||
|
||||
An initial SPI support for the HSPI interface (GPIO12-15) was implemented by [Sermus](https://github.com/Sermus).
|
||||
The implementation supports the entire Arduino SPI API including transactions, except setting phase and polarity as it's unclear how to set them in ESP8266 yet.
|
||||
SPI library supports the entire Arduino SPI API including transactions, including setting phase and polarity.
|
||||
|
||||
#### ESP-specific APIs ####
|
||||
|
||||
APIs related to deep sleep and watchdog timer are available in the ```ESP``` object.
|
||||
|
||||
```ESP.deepSleep(microseconds, mode)``` will put the chip into deep sleep. ```mode``` is one of ```WAKE_DEFAULT```, ```WAKE_RFCAL```, ```WAKE_NO_RFCAL```, ```WAKE_RF_DISABLED```. (GPIO16 needs to be tied to RST to wake from deepSleep.)
|
||||
```ESP.deepSleep(microseconds, mode)``` will put the chip into deep sleep. ```mode``` is one of ```WAKE_RF_DEFAULT```, ```WAKE_RFCAL```, ```WAKE_NO_RFCAL```, ```WAKE_RF_DISABLED```. (GPIO16 needs to be tied to RST to wake from deepSleep.)
|
||||
|
||||
```ESP.wdtEnable()```, ```ESP.wdtDisable()```, and ```ESP.wdtFeed()``` provide some control over the watchdog timer.
|
||||
|
||||
```ESP.reset()``` resets the CPU.
|
||||
|
||||
```ESP.getFreeHeap()``` returns the free heap size.
|
||||
|
||||
```ESP.getChipId()``` returns the ESP8266 chip ID as a 32-bit integer.
|
||||
|
||||
Several APIs may be used to get flash chip info:
|
||||
|
||||
```ESP.getFlashChipId()``` returns the flash chip ID as a 32-bit integer.
|
||||
|
||||
```ESP.getFlashChipSize()``` returns the flash chip size, in bytes, as seen by the SDK (may be less than actual size).
|
||||
|
||||
```ESP.getFlashChipSpeed(void)``` returns the flash chip frequency, in Hz.
|
||||
|
||||
|
||||
#### OneWire (from https://www.pjrc.com/teensy/td_libs_OneWire.html) ####
|
||||
|
||||
Library was adapted to work with ESP8266 by including register definitions into OneWire.h
|
||||
@ -133,6 +159,7 @@ instead of the one that comes with the Arduino IDE (this one).
|
||||
#### mDNS responder (ESP8266mDNS library) ####
|
||||
|
||||
Allows the sketch to respond to multicast DNS queries for domain names like "foo.local".
|
||||
Currently the library only works on STA interface, AP interface is not supported.
|
||||
See attached example and library README file for details.
|
||||
|
||||
#### Other libraries (not included with the IDE)
|
||||
@ -150,16 +177,6 @@ Pick the correct serial port.
|
||||
You need to put ESP8266 into bootloader mode before uploading code (pull GPIO0 low and
|
||||
toggle power).
|
||||
|
||||
### Things not done yet ###
|
||||
|
||||
- analogWrite (PWM). ESP8266 has only one hardware PWM source. It is not yet clear how to use it with analogWrite API. Software PWM is also an option, but apparently it causes issues with WiFi connectivity.
|
||||
- pulseIn
|
||||
- I2C slave mode
|
||||
- WiFi.RSSI. SDK doesn't seem to have an API to get RSSI for the current network. So far the only
|
||||
way to obtain RSSI is to disconnect, perform a scan, and get the RSSI value from there.
|
||||
- Upload sketches via WiFi. Conceptually and technically simple, but need to figure out how to provide the best UX for this feature.
|
||||
- Samples for all the libraries
|
||||
|
||||
### Issues and support ###
|
||||
|
||||
Forum: http://www.esp8266.com/arduino
|
||||
|
@ -30,12 +30,12 @@
|
||||
#include "spi_flash.h"
|
||||
}
|
||||
|
||||
#define CONFIG_START_SECTOR 0x3C
|
||||
#define CONFIG_START_SECTOR 0x7b
|
||||
#define CONFIG_SECTOR (CONFIG_START_SECTOR + 0)
|
||||
#define CONFIG_ADDR (SPI_FLASH_SEC_SIZE * CONFIG_SECTOR)
|
||||
|
||||
EEPROMClass::EEPROMClass()
|
||||
: _data(0), _size(0)
|
||||
: _data(0), _size(0), _dirty(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ void EEPROMClass::end()
|
||||
|
||||
uint8_t EEPROMClass::read(int address)
|
||||
{
|
||||
if (address < 0 || address >= _size)
|
||||
if (address < 0 || (size_t)address >= _size)
|
||||
return 0;
|
||||
|
||||
return _data[address];
|
||||
@ -75,23 +75,35 @@ uint8_t EEPROMClass::read(int address)
|
||||
|
||||
void EEPROMClass::write(int address, uint8_t value)
|
||||
{
|
||||
if (address < 0 || address >= _size)
|
||||
if (address < 0 || (size_t)address >= _size)
|
||||
return;
|
||||
|
||||
_data[address] = value;
|
||||
_dirty = true;
|
||||
}
|
||||
|
||||
void EEPROMClass::commit()
|
||||
bool EEPROMClass::commit()
|
||||
{
|
||||
if (!_size || !_dirty)
|
||||
return;
|
||||
bool ret = false;
|
||||
if (!_size)
|
||||
return false;
|
||||
if(!_dirty)
|
||||
return true;
|
||||
|
||||
ETS_UART_INTR_DISABLE();
|
||||
spi_flash_erase_sector(CONFIG_SECTOR);
|
||||
spi_flash_write(CONFIG_ADDR, reinterpret_cast<uint32_t*>(_data), _size);
|
||||
ETS_UART_INTR_ENABLE();
|
||||
if(spi_flash_erase_sector(CONFIG_SECTOR) == SPI_FLASH_RESULT_OK) {
|
||||
if(spi_flash_write(CONFIG_ADDR, reinterpret_cast<uint32_t*>(_data), _size) == SPI_FLASH_RESULT_OK) {
|
||||
_dirty = false;
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
ETS_UART_INTR_ENABLE();
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint8_t * EEPROMClass::getDataPtr()
|
||||
{
|
||||
return &_data[0];
|
||||
}
|
||||
|
||||
|
||||
|
@ -33,9 +33,11 @@ class EEPROMClass
|
||||
void begin(size_t size);
|
||||
uint8_t read(int address);
|
||||
void write(int address, uint8_t val);
|
||||
void commit();
|
||||
bool commit();
|
||||
void end();
|
||||
|
||||
uint8_t * getDataPtr();
|
||||
|
||||
template<typename T> T &get(int address, T &t)
|
||||
{
|
||||
if (address < 0 || address + sizeof(T) > _size)
|
||||
|
@ -56,6 +56,10 @@ void TwoWire::begin(int sda, int scl){
|
||||
flush();
|
||||
}
|
||||
|
||||
void TwoWire::pins(int sda, int scl){
|
||||
twi_init(sda, scl);
|
||||
}
|
||||
|
||||
void TwoWire::begin(void){
|
||||
begin(SDA, SCL);
|
||||
}
|
||||
|
@ -51,6 +51,7 @@ class TwoWire : public Stream
|
||||
public:
|
||||
TwoWire();
|
||||
void begin(int sda, int scl);
|
||||
void pins(int sda, int scl) __attribute__((deprecated)); // use begin(sda, scl) in new code
|
||||
void begin();
|
||||
void begin(uint8_t);
|
||||
void begin(int);
|
||||
|
@ -74,7 +74,7 @@ recipe.objcopy.eep.pattern=
|
||||
## Create hex
|
||||
#recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex"
|
||||
|
||||
recipe.objcopy.hex.pattern="{compiler.tools.path}{compiler.esptool.cmd}" -eo "{build.path}/{build.project_name}.elf" -bo "{build.path}/{build.project_name}_00000.bin" -bm {build.flash_mode} -bf {build.flash_freq} -bz {build.flash_size} -bs .text -bs .data -bs .rodata -bc -ec -eo "{build.path}/{build.project_name}.elf" -es .irom0.text "{build.path}/{build.project_name}_40000.bin" -ec
|
||||
recipe.objcopy.hex.pattern="{compiler.tools.path}{compiler.esptool.cmd}" -eo "{build.path}/{build.project_name}.elf" -bo "{build.path}/{build.project_name}_00000.bin" -bm {build.flash_mode} -bf {build.flash_freq} -bz {build.flash_size} -bs .text -bs .data -bs .rodata -bc -ec -eo "{build.path}/{build.project_name}.elf" -es .irom0.text "{build.path}/{build.project_name}_10000.bin" -ec
|
||||
|
||||
## Compute size
|
||||
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
|
||||
@ -91,4 +91,4 @@ tools.esptool.path={runtime.ide.path}/hardware/tools/esp8266
|
||||
tools.esptool.upload.protocol=esp
|
||||
tools.esptool.upload.params.verbose=-vv
|
||||
tools.esptool.upload.params.quiet=
|
||||
tools.esptool.upload.pattern="{path}/{cmd}" {upload.verbose} -cd {upload.resetmethod} -cb {upload.speed} -cp "{serial.port}" -ca 0x00000 -cf "{build.path}/{build.project_name}_00000.bin" -ca 0x40000 -cf "{build.path}/{build.project_name}_40000.bin"
|
||||
tools.esptool.upload.pattern="{path}/{cmd}" {upload.verbose} -cd {upload.resetmethod} -cb {upload.speed} -cp "{serial.port}" -ca 0x00000 -cf "{build.path}/{build.project_name}_00000.bin" -ca 0x10000 -cf "{build.path}/{build.project_name}_10000.bin"
|
||||
|
Loading…
x
Reference in New Issue
Block a user