ESP32解析433和315遥控代码..........持续研究中。

16 17脚通过二极管直连22 23脚。

#include <RCSwitch.h>

#include "EEPROM.h"

#define R315 23

#define R433 22

#define led_pin  12

#define LED2 13

const int R315EN = 16;

const int R433EN = 17;

EEPROMClass eeprom_xuhao("eeprom0");  //unsigned long decimal, unsigned int length, unsigned int delay, unsigned int* raw, unsigned int protocol

EEPROMClass eeprom_leixing("eeprom1");

EEPROMClass eeprom_shuju("eeprom2");

EEPROMClass eeprom_changdu("eeprom3");

EEPROMClass eeprom_maikuan("eeprom4");

EEPROMClass eeprom_xieyi("eeprom5");

int address = 1;

int i;

//RCSwitch mySwitch = RCSwitch();

RCSwitch myShou315 = RCSwitch();  //收

RCSwitch myShou433 = RCSwitch();  //收


 

//uint num;

uint value;

uint xuhao, shuju, changdu, maikuan, xieyi, leixing;

uint L315=315;

uint L433=433;

void setup() {


 

  Serial.begin(115200);

  Serial.println("\nTesting EEPROM Library\n");

  if (!eeprom_xuhao.begin(0x200)) {

    Serial.println("Failed to initialise EEPROM");

    Serial.println("Restarting...");

    delay(1000);

    ESP.restart();

  }

  if (!eeprom_leixing.begin(0x200)) {

    Serial.println("Failed to initialise EEPROM");

    Serial.println("Restarting...");

    delay(1000);

    ESP.restart();

  }

  if (!eeprom_shuju.begin(0x200)) {

    Serial.println("Failed to initialise EEPROM");

    Serial.println("Restarting...");

    delay(1000);

    ESP.restart();

  }

  if (!eeprom_changdu.begin(0x200)) {

    Serial.println("Failed to initialise EEPROM");

    Serial.println("Restarting...");

    delay(1000);

    ESP.restart();

  }

  if (!eeprom_maikuan.begin(0x200)) {

    Serial.println("Failed to initialise EEPROM");

    Serial.println("Restarting...");

    delay(1000);

    ESP.restart();

  }

  if (!eeprom_xieyi.begin(0x200)) {

    Serial.println("Failed to initialise EEPROM");

    Serial.println("Restarting...");

    delay(1000);

    ESP.restart();

  }


 

  Serial.print("EEPROM-length:");

  Serial.println(eeprom_xuhao.length());

  Serial.println(eeprom_leixing.length());

  Serial.println(eeprom_shuju.length());

  Serial.println(eeprom_changdu.length());

  Serial.println(eeprom_maikuan.length());

  Serial.println(eeprom_xieyi.length());



 

  pinMode(R315EN, OUTPUT);

  pinMode(R433EN, OUTPUT);

  //pinMode(led_pin, OUTPUT);

  pinMode(LED2, OUTPUT);

  delay(1000);

  address = 1;

  while (address < eeprom_shuju.length()) {

    leixing = eeprom_leixing.readUInt(address);

    shuju = eeprom_shuju.readUInt(address);

    changdu = eeprom_changdu.readUInt(address);

    maikuan = eeprom_maikuan.readUInt(address);

    xieyi = eeprom_xieyi.readUInt(address);





 

    Serial.print("      地址=");

    Serial.print(address);

    Serial.print("      类型=");

    Serial.print(leixing);

    Serial.print("     数据=");

    Serial.print(shuju);

    Serial.print("     长度=");

    Serial.print(changdu);

    Serial.print("    脉宽=");

    Serial.print(maikuan);

    Serial.print("     协议=");

    Serial.println(xieyi);

    address += sizeof(unsigned int);

  }


 

  address = eeprom_xuhao.readUInt(0);

  Serial.print(" 上次写入数据地址为:");

  Serial.println(address);

  myShou315.enableReceive(R315);

  myShou433.enableReceive(R433);

  delay(1000);

  Serial.println("Ready to receive.");

 //eeprom_init();

}


 

//-----------------------------------------------------------------------

void loop() {



 

  shou315();

 // digitalWrite(LED1, HIGH);  //16脚

  digitalWrite(LED2, LOW);   //16脚

                             // digitalWrite(R315EN,HIGH);

                             // digitalWrite(R433EN,LOW);

  shou433();

 // digitalWrite(LED1, LOW);   //16脚

  digitalWrite(LED2, HIGH);  //16脚

}




 

void shou315() {

  digitalWrite(R315EN, LOW);   //16脚

  digitalWrite(R433EN, HIGH);  //   17脚接收315

  delay(100);


 

  if (myShou315.available())

  {

    value = myShou315.getReceivedValue();

    leixing = eeprom_leixing.readUInt(address);

    shuju = eeprom_shuju.readUInt(address);

    Serial.print("接收数据类型为:");

    Serial.println("315");

    Serial.print("接收数据为:");

    Serial.println(value);

    if ((value == shuju) && (leixing == 315)) {

      Serial.println(" -------------------------------------重复接收-------------------------------------------------- ");

  Serial.println("");

      // Serial.print("    数据长度为:");

      // Serial.print(myShou315.getReceivedBitlength());

      // Serial.print("bit ");

      // Serial.print("  Protocol: ");

      // Serial.println(myShou315.getReceivedProtocol());

      // Serial.print(" / ");

      // // Serial.println(myShou315.getReceivedDelay());

      // Serial.println("");

      // Serial.println("");

      myShou315.resetAvailable();

    } else {


 

      Serial.println("-------------------------------新数据接收成功-----------------------------");

      shuju = myShou315.getReceivedValue();

      changdu = myShou315.getReceivedBitlength();

      maikuan = myShou315.getReceivedDelay();

      xieyi = myShou315.getReceivedProtocol();



 

      address += sizeof(unsigned int);

         init_address() ;

      eeprom_xuhao.writeUInt(0, address);  //写地址

      eeprom_leixing.writeUInt(address, L315);

      eeprom_shuju.writeUInt(address, shuju);

      eeprom_changdu.writeUInt(address, changdu);

      eeprom_maikuan.writeUInt(address, maikuan);

      eeprom_xieyi.writeUInt(address, xieyi);

      eeprom_xuhao.commit();

      eeprom_leixing.commit();

      eeprom_shuju.commit();

      eeprom_changdu.commit();

      eeprom_maikuan.commit();

      eeprom_xieyi.commit();




 

      Serial.print("   写入地址");

      Serial.print(address);

      Serial.print("      的类型:");

      Serial.print(leixing);

      Serial.print("     数据:");

      Serial.print(shuju);

      Serial.print("     长度:");

      Serial.print(changdu);

      Serial.print("    脉宽:");

      Serial.print(maikuan);

      Serial.print("     协议:");

      Serial.println(xieyi);

      delay(5);

     

      Serial.println("-------------------------------写入数据成功---------------------------");

      myShou315.resetAvailable();

    }

  }

}



 

void shou433() {

  digitalWrite(R315EN, HIGH);

  digitalWrite(R433EN, LOW);  //接收315

  delay(100);


 

  if (myShou433.available())

  {


 

   value = myShou433.getReceivedValue();

    leixing = eeprom_leixing.readUInt(address);

    shuju = eeprom_shuju.readUInt(address);

    Serial.print(" 接收数据类型为:");

    Serial.println("433");

    Serial.print("   数据为:");

    Serial.println(value);

    if ((value == shuju) && (leixing == 433)) {

      Serial.println(" -----------------重复接收---------------------------- ");

   

      myShou433.resetAvailable();

    } else {


 

      Serial.println("-------------------新数据接收成功------------------------");


 

      //myShou433.getReceivedValue(), myShou433.getReceivedBitlength(), myShou433.getReceivedDelay(), myShou433.getReceivedRawdata(),myShou433.getReceivedProtocol());

      shuju = myShou433.getReceivedValue();

      changdu = myShou433.getReceivedBitlength();

      maikuan = myShou433.getReceivedDelay();

      xieyi = myShou433.getReceivedProtocol();



 

      address += sizeof(unsigned int);

      init_address() ;

      eeprom_xuhao.writeUInt(0, address);  //写地址

      eeprom_leixing.writeUInt(address, L433);

      eeprom_shuju.writeUInt(address, shuju);

      eeprom_changdu.writeUInt(address, changdu);

      eeprom_maikuan.writeUInt(address, maikuan);

      eeprom_xieyi.writeUInt(address, xieyi);

      eeprom_xuhao.commit();

      eeprom_leixing.commit();

      eeprom_shuju.commit();

      eeprom_changdu.commit();

      eeprom_maikuan.commit();

      eeprom_xieyi.commit();




 

      Serial.print("   写入地址");

      Serial.print(address);

      Serial.print("      的类型:");

      Serial.print("433");

      Serial.print("     数据:");

      Serial.print(shuju);

      Serial.print("     长度:");

      Serial.print(changdu);

      Serial.print("    脉宽:");

      Serial.print(maikuan);

      Serial.print("     协议:");

      Serial.println(xieyi);

      delay(5);

     

      Serial.println("-------------------------写入数据成功-----------------------------");

      myShou433.resetAvailable();

    }

  }

}

void init_address() {


 

  if (address > 1280) {

    address = 1;

    // for (i = 0; i < 300; i++) {

    //EEPROM.write(i, 0);

    // }

  }

}

void eeprom_init() {

  for (i = 0; i < eeprom_xuhao.length(); i++) {

    eeprom_shuju.writeByte(i, 0);

   // Serial.println(i);

  }

   for (i = 0; i < eeprom_shuju.length(); i++) {

    eeprom_shuju.writeByte(i, 0);

  //  Serial.println(i);

  }

    for (i = 0; i < eeprom_leixing.length(); i++) {

    eeprom_leixing.writeByte(i, 0);

  //  Serial.println(i);

  }

    for (i = 0; i < eeprom_changdu.length(); i++) {

    eeprom_changdu.writeByte(i, 0);

   // Serial.println(i);

  }

    for (i = 0; i < eeprom_maikuan.length(); i++) {

    eeprom_maikuan.writeByte(i, 0);

  //  Serial.println(i);

  }

    for (i = 0; i < eeprom_xieyi.length(); i++) {

    eeprom_xieyi.writeByte(i, 0);

   // Serial.println(i);

  }

  eeprom_xuhao.writeUInt(0, 1);

    address=1;

    eeprom_xuhao.commit();

      eeprom_leixing.commit();

      eeprom_shuju.commit();

      eeprom_changdu.commit();

      eeprom_maikuan.commit();

      eeprom_xieyi.commit();

  delay(10);

Serial.println("数据清空完毕");

}

  • 15
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
将一个 ONNX 模型部署到 ESP32 上需要多个步骤。下面是一个大致的流程: 1. 将 ONNX 模型转换为 TensorFlow Lite 模型。 2. 在 TensorFlow 加载 TensorFlow Lite 模型。 3. 通过 TensorFlow Lite for Microcontrollers 库将模型编译为 C++ 代码。 4. 在 ESP32 上运行编译后的 C++ 代码。 下面是一个简单的示例代码,用于演示如何在 ESP32 上加载 TensorFlow Lite 模型并运行推理: ```cpp #include "tensorflow/lite/micro/kernels/micro_ops.h" #include "tensorflow/lite/micro/kernels/micro_utils.h" #include "tensorflow/lite/micro/micro_mutable_op_resolver.h" #include "tensorflow/lite/micro/micro_error_reporter.h" #include "tensorflow/lite/micro/all_ops_resolver.h" #include "tensorflow/lite/micro/micro_interpreter.h" #include "tensorflow/lite/schema/schema_generated.h" #include "tensorflow/lite/version.h" #include "model_data.h" // 定义模型输入和输出张量的维度 constexpr int kTensorArenaSize = 100 * 1024; uint8_t tensor_arena[kTensorArenaSize]; int main() { // 创建一个 MicroErrorReporter 对象,用于报告错误 static tflite::MicroErrorReporter micro_error_reporter; tflite::ErrorReporter* error_reporter = &micro_error_reporter; // 加载 TensorFlow Lite 模型 const tflite::Model* model = tflite::GetModel(model_data); if (model == nullptr) { TF_LITE_REPORT_ERROR(error_reporter, "Failed to load model"); return 1; } // 创建一个 AllOpsResolver 对象,用于解析模型的所有操作 static tflite::AllOpsResolver resolver; // 分配一块内存来保存张量数据 static tflite::MicroMutableOpResolver micro_op_resolver(&resolver); static tflite::MicroInterpreter static_interpreter(model, micro_op_resolver, tensor_arena, kTensorArenaSize, error_reporter); tflite::MicroInterpreter* interpreter = &static_interpreter; // 分配张量缓冲区 TfLiteStatus allocate_status = interpreter->AllocateTensors(); if (allocate_status != kTfLiteOk) { TF_LITE_REPORT_ERROR(error_reporter, "AllocateTensors() failed"); return 1; } // 获取输入张量 TfLiteTensor* input = interpreter->input(0); // 填充输入张量 // ... // 运行推理 interpreter->Invoke(); // 获取输出张量 TfLiteTensor* output = interpreter->output(0); // 处理输出张量 // ... return 0; } ``` 在上面的代码,`model_data.h` 包含了 TensorFlow Lite 模型的数据。你需要将 ONNX 模型转换为 TensorFlow Lite 模型,并将其保存为 C++ 头文件。转换模型的方法可以参考 TensorFlow 官方文档。 此外,你还需要在 ESP32 上安装 TensorFlow Lite for Microcontrollers 库,并且根据你的开发板和环境进行配置。具体的步骤可以参考 TensorFlow 官方文档。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值