Lemontree

[Solicitation Order] ESP_NOW low power switch

 
Overview

Project Description

  • ESP-NOW is a connectionless Wi-Fi communication protocol defined by Espressif Systems. In ESP-NOW, application data is encapsulated in action frames from each provider and then transferred from one Wi-Fi device to another without connection. CTR and CBC-MAC Protocol (CCMP) can be used to secure action frames. ESP-NOW is widely used in smart lighting, remote control, sensors and other fields

  • Most of the open source projects are about the WiFi function of ESP8266, and there is basically no ESP_NOW protocol. I think this ESP_NOW is actually very good. In terms of power consumption, response speed and signal coverage, it is stronger than the 315M/433M module. At the same time, it automatically With verification, packet loss and errors rarely occur in actual measurements.

  • The production of the ESP_NOW gateway is also simpler than the 315M/433M module. Just use another ESP8266 or ESP32.

    • -

Project function introduction

  • In terms of hardware, ESP8266 is used as the sending end of the ESP_NOW switch. When the switch is not pressed, ESP8266 is in a permanent sleep state. When the switch is pressed, it resets the chip and latches the pressed switch. After the chip starts, it reads You can determine which button was pressed by taking the port status, and at the same time send data through the ESP_NOW protocol. After the data is sent, it enters the sleep state again.

  • In terms of power consumption, it is about 20mA when transmitting and less than 5uA when sleeping. If it is not switched on and off very frequently, a 200mAH lithium battery is estimated to last for one year.

    • -

Project properties

At present, the project has been tested, functions normally, and has been put into use. oaHa5R.jpg

  • [x] Schematic design

  • [x] PCB diagram design

  • [x] PCB proofing

  • [x] Welding test

  • [x] Functional testing

  • [x] Program testing

    • -

Circuit explanation

oabZz6.jpg

The more innovative part of the circuit is the circuit that resets and latches the IO status at the same time. When the switch is pressed, RST can be reset and the corresponding port is pulled high. After the ESP8266 detects the port, the port level is pulled low. , release the latch state.


software

#include 
extern "C" {
#include 
}
#define espNowSwitchID  0x01
#define WIFI_CHANNEL 1
#define SEND_TIMEOUT 10000
#define SW1 14
#define SW2 12
#define SW3 13
#define K4  4

uint8_t remoteMac[] = {0x1A, 0xFE, 0x34, 0xCB, 0x68, 0x45};
/*发送数据定义
   D0: espNow ID[0-255]
   D1: keyValue[0-3]
   D2: AD使能 0-未采集 1-已采集
   D3-D4: AD数据[电池电压]

*/
uint8_t transferData[8] = {espNowSwitchID};//
volatile boolean readingSent;

uint8_t keyValue = 0;
void setup() {
  if (digitalRead(SW1))keyValue = 1;
  if (digitalRead(SW2))keyValue = 2;
  if (digitalRead(SW3))keyValue = 3;
  pinMode(SW1, OUTPUT);
  pinMode(SW2, OUTPUT);
  pinMode(SW3, OUTPUT);
  digitalWrite(SW1, LOW);
  digitalWrite(SW2, LOW);
  digitalWrite(SW3, LOW);
  WiFi.mode(WIFI_STA);
  WiFi.begin();
  if (esp_now_init() != 0) {
    ESP.restart();
  }
  delay(1); // This delay seems to make it work more reliably???

  esp_now_set_self_role(ESP_NOW_ROLE_CONTROLLER);
  esp_now_add_peer(remoteMac, ESP_NOW_ROLE_SLAVE, WIFI_CHANNEL, NULL, 0);
  esp_now_register_send_cb([](uint8_t* mac, uint8_t status) {
    readingSent = true;
  });

  sendReading();
}

void loop() {
  if (readingSent || (millis() > SEND_TIMEOUT)) {
    ESP.deepSleep(0);
  }
}

void sendReading() {
  readingSent = false;
  transferData[1] = keyValue;
  esp_now_send(NULL, transferData, 8);
}

picture

oaH08x.jpg oaHDxK.jpg


Precautions

  • There is a problem with the packaging of HT7333 in the PCB! ! ! Remember to transfer here

    • -



参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2025-05-10 16:33:41

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
community

Robot
development
community

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号