ESP8266 Support WIKI

User Tools

Site Tools


arduino-docs

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
arduino-docs [2015/04/01 20:53]
cimba007
arduino-docs [2015/07/19 01:19] (current)
apedro [EEPROM]
Line 8: Line 8:
  
 ==== Wire ==== ==== Wire ====
- 
 content content
  
 ==== EEPROM ==== ==== EEPROM ====
 +EEPROM functionality is similar to the standard Arduino library with the exception of having to declare memory size and committing writes.
 +===example===
 +<code c++>
 +#include <​EEPROM.h>​
  
-content+void setup() 
 +
 +     //​Init EEPROM, note the size requirement. I believe 4096B is the maximum available. 
 +     //You could use a smaller amount/​size. 
 +     ​EEPROM.begin(4096);​ 
 +     for( int i = 0; i < 4096; i++ ) 
 +     { 
 +          EEPROM.write(i,​i);​ 
 +     } 
 +     ​EEPROM.commit();​ //note here the commit! 
 +
 +</​code>​ 
 +NOTE: EEPROMAnything can be used with one simple modification. 
 +Find the EEPROMAnything.h and add EEPROM.commit();​ after the EEPROM.write(ee++,​ *p++); 
 + 
 +EEPROMAnything provides nice functionality to save any type of variable including structers. 
 +<code c++> 
 +#include <​EEPROMAnything.h>​ 
 + 
 +struct eepromInfoType 
 +
 +     ​uint8_t MyUnsigned8BitInt;​ 
 +     char MyCharArray[25] 
 +} myStructOriginal,​ myStructCopy;​ 
 + 
 +void setup() 
 +
 +     ​myStructOriginal.MyUnsigned8BitInt = 0; //assign some value 
 +     ​strcpy( myStructOriginal.MyCharArray,​ "Less than 25 chars" ); //assign some value 
 +     ​EEPROM_writeAnything( 0, myStructOriginal ); //remember to modify EEPROM_writeAnything by adding ​  ​.commit(). 
 +     //​Lets read it back 
 +     ​EEPROM_readAnything( 0, myStructCopy );         
 +
 + 
 +void loop() 
 +
 +//nothing here 
 +
 +</​code>​
  
 ===== ESP Specific Libs ===== ===== ESP Specific Libs =====
  
-===== SDK-API (1.0.0) ​=====+==== SDK-API (1.0.0) ====
  
 +
 +If you want to use some the the SDK-API functions have a look at this link
 +http://​bbs.espressif.com/​viewtopic.php?​f=5&​t=286
 +
 +The Documentation can be found here
 +http://​bbs.espressif.com/​download/​file.php?​id=253
 +
 +To use the API you have to include some header-files in your sketch. Below is a quick example of using the RTC-Memory-Write API to make a counter persistent even after using sleep + the following reset.
 +
 +<code c>
 +#include <​Streaming.h>​
 +
 +// Include API-Headers
 +extern "​C"​ {
 +#include "​ets_sys.h"​
 +#include "​os_type.h"​
 +#include "​osapi.h"​
 +#include "​mem.h"​
 +#include "​user_interface.h"​
 +#include "​cont.h"​
 +}
 +
 +// Counter
 +uint32_t i = 0;
 +// Temporary buffer
 +uint32_t b = 0;
 +
 +void setup() {
 +  Serial.begin(115200);​
 +  // Call API-Function
 +  system_deep_sleep_set_option(4);​
 +  // Call API-Function
 +  system_rtc_mem_read(64,&​b,​4) << endl;
 +  // Check if the value is within expected range
 +  if(b < 100000)
 +    i = b;
 +}
 +
 +int lap = 0;
 +void loop() {
 +  for(int c = 0; c < 50; c++)
 +  {
 +    Serial << i++ << " " << lap << endl;
 +    delay(10);
 +  }
 +  // Call API-Function
 +  system_rtc_mem_write(64,&​i,​4) << endl;
 +  delay(1000);​
 +  // Call API-Function
 +  system_deep_sleep(10000000);​
 +  lap++;
 +}
 +</​code>​
 ==== ESP8266WiFi ==== ==== ESP8266WiFi ====
  
-content+**Connect with static IP** 
 + 
 +If you experience problems regarding DNS resolving check out https://​github.com/​esp8266/​Arduino/​issues/​369 
 +<code c> 
 +#include <​ESP8266WiFi.h>​ 
 +#include <​WiFiClient.h>​ 
 +#include <​IPAddress.h>​ 
 +  
 +const char* ssid = "​.....";​ 
 +const char* password = "​.....";​ 
 +  
 +void setup(void) 
 +
 +  Serial.begin(115200);​ 
 + 
 + 
 +  // Connect to WiFi network 
 +  WiFi.begin(ssid,​ password);​ 
 +  //set static ip part 
 +  WiFi.config(IPAddress(192,​168,​1,​118),​ IPAddress(192,​168,​1,​1),​ IPAddress(255,​255,​255,​0));​ 
 + 
 +  // Wait for connection 
 +  while (WiFi.status() != WL_CONNECTED) { 
 +    delay(200);​ 
 +  } 
 +  
 +   
 +  Serial.println(WiFi.localIP());​ 
 +   
 +}
    
 +</​code>​
 ==== ESP8266mDNS ==== ==== ESP8266mDNS ====
  
arduino-docs.1427921621.txt.gz · Last modified: 2015/04/01 20:53 by cimba007