Arduino爱好者

 找回密码
 立即注册

QQ登录

只需一步,快速开始

楼主: eagler8

[经验] 【Arduino】168种传感器模块系列实验(125)---WeMos D1开发板

[复制链接]
 楼主| 发表于 2019-9-26 11:40 | 显示全部楼层
[mw_shl_code=arduino,true]/*
【Arduino】108种传感器模块系列实验(资料+代码+图形+仿真)
实验一百二十五: 升级版 WeMos D1 R2 WiFi UNO 开发板 基于ESP8266
项目:无延迟闪烁LED
*/

int ledState = LOW;

unsigned long previousMillis = 0;
const long interval = 1000;

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    if (ledState == LOW) {
      ledState = HIGH;  // Note that this switches the LED *off*
    } else {
      ledState = LOW;  // Note that this switches the LED *on*
    }
    digitalWrite(LED_BUILTIN, ledState);
  }
}[/mw_shl_code]
 楼主| 发表于 2019-9-26 11:52 | 显示全部楼层
[mw_shl_code=arduino,true]/*
【Arduino】108种传感器模块系列实验(资料+代码+图形+仿真)
实验一百二十五: 升级版 WeMos D1 R2 WiFi UNO 开发板 基于ESP8266
项目:ESP8266闪烁,由Daniel Salazar轮询超时
*/

#include <olledTimeout.h>

void ledOn() {
  digitalWrite(LED_BUILTIN, LOW);   // Turn the LED on (Note that LOW is the voltage level
}

void ledOff() {
  digitalWrite(LED_BUILTIN, HIGH);  // Turn the LED off by making the voltage HIGH
}

void ledToggle() {
  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));  // Change the state of the LED
}


esp8266::polledTimeout::periodicFastUs halfPeriod(500000); //use fully qualified type and avoid importing all ::esp8266 namespace to the global namespace

// the setup function runs only once at start
void setup() {
  Serial.begin(115200);

  Serial.println();
  Serial.printf("periodic/oneShotMs::timeMax()     = %u ms\n", (uint32_t)esp8266::polledTimeout::periodicMs::timeMax());
  Serial.printf("periodic/oneShotFastMs::timeMax() = %u ms\n", (uint32_t)esp8266::polledTimeout::periodicFastMs::timeMax());
  Serial.printf("periodic/oneShotFastUs::timeMax() = %u us\n", (uint32_t)esp8266::polledTimeout::periodicFastUs::timeMax());
  Serial.printf("periodic/oneShotFastNs::timeMax() = %u ns\n", (uint32_t)esp8266::polledTimeout::periodicFastNs::timeMax());

#if 0 // 1 or debugging polledTimeoutf
  Serial.printf("periodic/oneShotMs::rangeCompensate     = %u\n", (uint32_t)esp8266::polledTimeout::periodicMs::rangeCompensate);
  Serial.printf("periodic/oneShotFastMs::rangeCompensate = %u\n", (uint32_t)esp8266::polledTimeout::periodicFastMs::rangeCompensate);
  Serial.printf("periodic/oneShotFastUs::rangeCompensate = %u\n", (uint32_t)esp8266::polledTimeout::periodicFastUs::rangeCompensate);
  Serial.printf("periodic/oneShotFastNs::rangeCompensate = %u\n", (uint32_t)esp8266::polledTimeout::periodicFastNs::rangeCompensate);
#endif

  pinMode(LED_BUILTIN, OUTPUT);     // Initialize the LED_BUILTIN pin as an output

  using esp8266::polledTimeout:neShotMs; //import the type to the local namespace

  //STEP1; turn the led ON
  ledOn();

  //STEP2: wait for ON timeout
  oneShotMs timeoutOn(2000);
  while (!timeoutOn) {
    yield();
  }

  //STEP3: turn the led OFF
  ledOff();

  //STEP4: wait for OFF timeout to assure the led is kept off for this time before exiting setup
  oneShotMs timeoutOff(2000);
  while (!timeoutOff) {
    yield();
  }

  //Done with STEPs, do other stuff
  halfPeriod.reset(); //halfPeriod is global, so it gets inited on sketch start. Clear it here to make it ready for loop, where it's actually used.
}


// the loop function runs over and over again forever
void loop() {
  if (halfPeriod) {
    ledToggle();
  }
}[/mw_shl_code]
 楼主| 发表于 2019-9-26 12:05 | 显示全部楼层
[mw_shl_code=arduino,true]/*
【Arduino】108种传感器模块系列实验(资料+代码+图形+仿真)
实验一百二十五: 升级版 WeMos D1 R2 WiFi UNO 开发板 基于ESP8266
项目:测试ide的eeprom设置是否与硬件匹配
*/

void setup(void) {
  Serial.begin(115200);
}

void loop() {

  uint32_t realSize = ESP.getFlashChipRealSize();
  uint32_t ideSize = ESP.getFlashChipSize();
  FlashMode_t ideMode = ESP.getFlashChipMode();

  Serial.printf("Flash real id:   %08X\n", ESP.getFlashChipId());
  Serial.printf("Flash real size: %u bytes\n\n", realSize);

  Serial.printf("Flash ide  size: %u bytes\n", ideSize);
  Serial.printf("Flash ide speed: %u Hz\n", ESP.getFlashChipSpeed());
  Serial.printf("Flash ide mode:  %s\n", (ideMode == FM_QIO ? "QIO" : ideMode == FM_QOUT ? "QOUT" : ideMode == FM_DIO ? "DIO" : ideMode == FM_DOUT ? "DOUT" : "UNKNOWN"));

  if (ideSize != realSize) {
    Serial.println("Flash Chip configuration wrong!\n");
  } else {
    Serial.println("Flash Chip configuration ok.\n");
  }

  delay(5000);
}[/mw_shl_code]
 楼主| 发表于 2019-9-26 12:06 | 显示全部楼层
15.jpg
 楼主| 发表于 2019-9-26 12:32 | 显示全部楼层
[mw_shl_code=arduino,true]/*
【Arduino】108种传感器模块系列实验(资料+代码+图形+仿真)
实验一百二十五: 升级版 WeMos D1 R2 WiFi UNO 开发板 基于ESP8266
项目:将内置LED连接到Sigma Delta源,呼吸灯
*/

#include "sigma_delta.h"

void setup() {

  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT); // blinkie & sigma-delta mix
  uint32_t reqFreq = 1000;
  uint32_t realFreq;

  realFreq = sigmaDeltaSetup(0, reqFreq); // chose a low frequency

  Serial.println();
  Serial.println("Start Sigma Delta Example\n");
  Serial.printf("Frequency = %u\n", realFreq);

}

void loop() {

  uint8_t duty, iRepeat;

  Serial.println("Attaching the built in led to the sigma delta source now\n");
  Serial.printf("Current duty = %i, prescaler = %i\n", sigmaDeltaRead(), sigmaDeltaGetPrescaler());
  sigmaDeltaAttachPin(LED_BUILTIN);

  Serial.println("Dimming builtin led...\n");
  for (iRepeat = 0; iRepeat < 10; iRepeat++) {
    for (duty = 0; duty < 255; duty = duty + 5) {
      sigmaDeltaWrite(0, duty);
      delay(10);
    }

    for (duty = 255; duty > 0; duty = duty - 5) {
      sigmaDeltaWrite(0, duty);
      delay(10);
    }

  }

  Serial.println("Detaching builtin led & playing a blinkie\n");
  sigmaDeltaDetachPin(LED_BUILTIN);
  for (iRepeat = 0; iRepeat < 20; iRepeat++) {
    digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
    delay(500);
  }
}[/mw_shl_code]
 楼主| 发表于 2019-9-26 12:34 | 显示全部楼层
16.jpg
 楼主| 发表于 2019-9-26 13:00 | 显示全部楼层
[mw_shl_code=arduino,true]/*
【Arduino】108种传感器模块系列实验(资料+代码+图形+仿真)
实验一百二十五: 升级版 WeMos D1 R2 WiFi UNO 开发板 基于ESP8266
项目:Station模式下的操作实例,查询IP地址
*/

#include <ESP8266WiFi.h>

#define AP_SSID "eagler8" //这里改成你的wifi名字
#define AP_PSW  "zy156721"//这里改成你的wifi密码

void setup(){
  //设置串口波特率,以便打印信息
  Serial.begin(9600);

  //启动STA模式,并连接到wifi网络
  WiFi.begin(AP_SSID, AP_PSW);

  Serial.print(String("Connecting to ")+AP_SSID);
  //判断网络状态是否连接上,没连接上就延时500ms,并且打出一个点,模拟连接过程
  while (WiFi.status() != WL_CONNECTED){
    delay(500);
    Serial.print(".");
  }
  Serial.println("");

  Serial.print("Connected, IP address: ");
  //输出station IP地址,这里的IP地址由DHCP分配
  Serial.println(WiFi.localIP());
  Serial.println("Setup End");
}

void loop() {
}[/mw_shl_code]
 楼主| 发表于 2019-9-26 13:04 | 显示全部楼层
17 (1).jpg
发表于 2019-10-30 15:55 | 显示全部楼层
能否出一个教程,D1板实现无线通讯,将板子读到的数据传到网上。谢谢!
 楼主| 发表于 2019-10-31 11:00 | 显示全部楼层
CJ111 发表于 2019-10-30 15:55
能否出一个教程,D1板实现无线通讯,将板子读到的数据传到网上。谢谢!

谢谢鼓励,这个板是超出传感器与模块系列实验的一个尝试,没有更多的学习与研究了,不好意思
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino爱好者

GMT+8, 2023-2-1 01:53 , Processed in 0.073202 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表