分享

第一个Phyphox-ESP32测距实验

 新用户5228KeDY 2021-10-10

第一个Phyphox-ESP32测距实验

前些天得到Phyphox的BLE蓝牙扩展库,一直想找一点儿时间尝试个例子。Phyphox自身有测量距离的功能,即声呐(Sonar)测距实验。不是太准确,但基本也可使用。

不使用手机传感器而使用外接传感器,测量距离的,首选激光飞行时间传感器(Tof),其次超声波传感器(UltraSonic)。但不论哪种传感器,不使用滤波和限幅,这些传感器都不易直接使用。这里作为一个测试,用的超声波传感器,开发板是ESP32。

测量结果,缓慢在传感器前方移动日记本,粗测移动速度,每秒1.4cm,和实际情况差不多:

很简单的代码创作的实验,不设置缓存数据,数据是不能导出的。估计以后能够把实验文件以.phyphox文件导出来,接着再导入到phyphox editor编辑器里面去,再进行一些专门的设置:

实际实验使用的器材,超声波是常见的HC-SR04,性能最弱的一种:

ESP32程序烧录比Arduino UNO烧录要麻烦一些,时间也要久。Arduino IDE烧录log:

程序代码:

#include <phyphoxBle.h> 

int TrigPin = 12;
int EchoPin = 14;
float dist;

void setup()
{
   Serial.begin(115200);
   pinMode(TrigPin, OUTPUT);
   pinMode(EchoPin, INPUT);
   
   PhyphoxBLE::start("MyDevice");

   //Experiment
   PhyphoxBleExperiment plotDtValues;   //创建一个实验实例

   plotRandomValues.setTitle("Distance Number");
   plotRandomValues.setCategory("Arduino Experiments");
   plotRandomValues.setDescription("phyphox-ESP32-HCSR04 Distance");

   //View
   PhyphoxBleExperiment::View firstView;
   firstView.setLabel("FirstView"); //Create a "view"

   //Graph
   PhyphoxBleExperiment::Graph firstGraph;     
   firstGraph.setLabel("Distance over time");
   firstGraph.setUnitX("s");
   firstGraph.setUnitY("m");
   firstGraph.setLabelX("time");
   firstGraph.setLabelY("Distance");
   firstGraph.setChannel(0,1);

   firstView.addElement(firstGraph);
   plotRandomValues.addView(firstView);
   PhyphoxBLE::addExperiment(plotDtValues);

}


void loop()
{
  digitalWrite(TrigPin, LOW);
  delayMicroseconds(5);
  digitalWrite(TrigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(TrigPin, LOW);
  dist = pulseIn(EchoPin, HIGH) / 58.00;  
  float DisValue = dist/100.0;

  PhyphoxBLE::write(DisValue);
  delay(500);

  PhyphoxBLE::poll();
}

    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章