2017年3月16日星期四

ESP8266 arduino库的一些学习

http://esp8266.github.io/Arduino/versions/2.3.0/doc/reference.html

  1. Digital IO 兼容arduino pinMode, digitalRead, digitalWrite. 状态可为INPUT, OUTPUT, INPUT_PULLUP. 16脚可以设置为为INPUT, OUTPUT, INPUT_PULLDOWN. 启动时所有的引脚默认配置是INPUT.
  2.  GPIO6-11脚不能使用, 原因是因为模块内部, 引脚连接到了SPI Flash芯片上,  如果是QIO模式,会使用6-11脚, DIO模式, 可以使用9和11. 
  3. 支持attachInterrupt, detachInterrupt引脚中断,除了16脚, 中断可以使用所有的其它引脚,中断类型支持CHANGE, RISING, FALLING.
  4. Analog input, 可读入模块电源电压, 或ADC电压, 电压范围是0-1.0V, 如果使用ESP.getVcc()读取VCC电压,则ADC脚不能有接线, 另外ADC_MODE(ADC_VCC);要写在程序中, 最好是在函数外, #include后边.
  5. Analog output analogWrite(pin, value), 用来将引脚做为PWM输出, 数值可为0-PWMRANGE, 0可关断PWM, 默认PWMRANGE=1023, 可以使用analogWriteRange(new_range)改变.
  6. Timing and delays millis(), micros(), 分别显示reset后的毫秒和微秒. delay(ms)暂停程序但wifi和tcpip仍然工作, delayMicroseconds(us)暂停程序微秒. 当wifi连接后, 有大量的代码需要在程序后台运行, wifi和tcp/ip库在每次loop()完成后, 有机会控制一些挂起的事件或运行delay(),  如果你的loop()程序没有调用delay()而使用的时间超过了50ms, 你可能需要增加调用delay()来保证wifi堆栈工作正常. 这里有个yield()等于delay(0), delayMicroseconds(),如果超过20毫秒不推荐使用.
  7. Serial 使用与arduino相同, 使用gpio1(tx), gpio3(rx). 也可以调用Serial.begin()后使用Serial.swap重新映射到gpio15(tx), gpio13(rx),再次调用Serial.swap后恢复gpio1与gpio3. Serial1 使用gpio(tx), 但是无法接收数据, 因为RX脚被用于闪存芯片连接,可能使用用Serial1.begin()调用. 如果serial1没有使用并且serial没有交换, 在调用Serial.begin后,调用Serial.set_tx(2)可以将gpio映射为UART0的tx, 或直接调用Serial.begin(baud, config, mode,2). 默认当你调用Serial.begin后, wifi库的诊断输出是关闭的. 为了重新打开debug输出, 调用Serial.setDebugOutput(true), 如果用serial1输出debug, 调用Serial1.setDebugOut(true). 你仍然需要使用Serial.setDebugOutput(true)来打开printf()功能. Serial与Serial1支持5,6,7,8数据位, odd(o), even(E), no parity(N), 1或2停止位, 你可以使用Serial.begin(baudrate, SERIAL_8N1), Serial.begin(baudrate, Serial_6E2)等来设置你所希望的串口方式. Serial[1].baudRate(), 可以获取端口速率
  8. Progmem 程序中的字符都会占用内存空间, 最好的办法是使用宏与FPSTR(),这里有一个举例
String response1; 
response1 += F("http:"); 
... 
String response2; 
response2 += F("http:");

const char HTTP[] PROGMEM = "http:"; 
... 
{ String response1; 
 response1 += FPSTR(HTTP); 
 ... String response2; 
 response2 += FPSTR(HTTP); 
}

http://esp8266.github.io/Arduino/versions/2.3.0/doc/libraries.html


没有评论: