6块钱整一个最便宜的光电门计时器
1、接线图:
2、电路图:
3、phyphox界面:
可以做哪些实验?这是显然的。安装在轨道一侧,或许可用。咋不全用中断干这件事呢?可能是性能的原因吧,全用中断就出各种不可解释。价格低有价格低的用法。这种光电开关多少钱?大约3元一个,两个6块。
ESP32端虽然是Arduino里面编写的,但是phyphox端不能用ino来导入。因为已经改动相当之多。
ino:
/*
使用对射式光电开关模块制作自己的光电门
不同型号对射式光电开关输出有效量不同
FC-33在有障碍物遮挡时输出高电平HIGH,无遮挡时输出低电平LOW,这里结合中断使用
由于中断过于灵敏,致使计数易出现误差.这里遮挡光的累积时间是自下降沿起,并使用loop循环来判断的
*/
#include <phyphoxBle.h>
int pin32 = 32; //ESP32所有GPIO都可作为中断
int pin33 = 33;
float time1 = 0.00;
float time32 = 0.00;
float time33 = 0.00;//time32、time33记录两光电门初时刻,time1当前时刻
float T32 = 0.00;
float T33 = 0.00;
void setup() {
Serial.begin(9600);
pinMode(pin32, INPUT_PULLUP);//将中断的引脚设置为输入PULLUP模式
pinMode(pin33, INPUT_PULLUP);//将中断的引脚设置为输入PULLUP模式
attachInterrupt(digitalPinToInterrupt(pin32), start32, RISING); //引脚32电平上升沿触发,开始遮挡
attachInterrupt(digitalPinToInterrupt(pin33), start33, RISING); //引脚33电平上升沿触发,开始遮挡
PhyphoxBLE::start("MxxBLE");
PhyphoxBleExperiment plotRandomValues; //generate experiment on Arduino which plot random values
plotRandomValues.setTitle("Random Number Plotter");
plotRandomValues.setCategory("阿璇实验创作集");
plotRandomValues.setDescription("北京市和平街第一中学,梅晓璇。使用对射式光电开关制作光电门。两光电计时器拉入32和33引脚。");
PhyphoxBleExperiment::View firstView;
firstView.setLabel("FirstView"); //Create a "view"
PhyphoxBleExperiment::Graph firstGraph; //Create graph which will plot random numbers over time
firstGraph.setLabel("Random number over time");
firstGraph.setUnitX("s");
firstGraph.setUnitY("");
firstGraph.setLabelX("time");
firstGraph.setLabelY("random number");
firstGraph.setChannel(0, 1);
firstView.addElement(firstGraph); //attach graph to view
plotRandomValues.addView(firstView); //Attach view to experiment
PhyphoxBLE::addExperiment(plotRandomValues);
}
void loop() {
time1 = millis();
if (digitalRead(pin32) == HIGH) {//T33不会再变化
T32 = time1 - time32;
Serial.print(T32); Serial.print("\t"); Serial.print(T33);
float tt=abs(time33 - time32);
PhyphoxBLE::write(T32, T33, tt);
}
if (digitalRead(pin33) == HIGH) {//T32不会再变化
T33 = time1 - time33;
Serial.print(T32); Serial.print("\t"); Serial.print(T33);
float tt=abs(time33 - time32);
PhyphoxBLE::write(T32, T33, tt);
}
//复位T32、T33由phyphox一端来负责,phyphox里面“删除数据”即复位
PhyphoxBLE::poll();
}
void start32() {
time32 = millis();//记初时
}
void start33() {
time33 = millis();//记初时
}
.phyphox:
Main
Input
Output
Views
Analysis
Export
→
XML
Download/Transfer
This is just a preview of the generated phyphox file. If you are done, just download the file using the button at the bottom.
phyphox file content
<phyphox xmlns="http://phyphox.org/xml" xmlns:editor="http://phyphox.org/editor/xml" version="1.7" editor:version="1.0" locale="">
<title>对射光电计时器</title>
<category>阿璇实验创作集</category>
<description>北京市和平街第一中学,梅晓璇。使用对射式光电开关制作光电门。两光电计时器分别接入ESP32的32和33引脚。</description>
<data-containers>
<container size="10" static="false">CH4</container>
<container size="10" static="false">CH5</container>
<container size="10" static="false">CH0</container>
<container size="1000" static="false">CH3</container>
<container size="1000" static="false">Action 1</container>
<container size="1000" static="false">CH1</container>
<container size="1000" static="false">CH2</container>
</data-containers>
<input>
<bluetooth editor:uuid="101" editor:posx="100" editor:posy="250" mode="notification" rate="1" subscribeOnStart="false">
<output char="cddf1002-30f7-4671-8b43-5e40ba53514a" conversion="float32LittleEndian" offset="0">CH1</output>
<output char="cddf1002-30f7-4671-8b43-5e40ba53514a" conversion="float32LittleEndian" offset="4">CH2</output>
<output char="cddf1002-30f7-4671-8b43-5e40ba53514a" conversion="float32LittleEndian" offset="8">CH3</output>
<output char="cddf1002-30f7-4671-8b43-5e40ba53514a" conversion="float32LittleEndian" offset="12">CH4</output>
<output char="cddf1002-30f7-4671-8b43-5e40ba53514a" conversion="float32LittleEndian" offset="16">CH5</output>
<output char="cddf1002-30f7-4671-8b43-5e40ba53514a" conversion="string" extra="time">CH0</output>
</bluetooth>
</input>
<output>
</output>
<analysis sleep="0" onUserInput="false">
</analysis>
<views>
<view label="计时面板">
<info editor:uuid="159" editor:posx="0" editor:posy="0" label="说明:光电门1指的是接入ESP32的32引脚的光电计时器,光电门2接入33引脚。记录的时间为挡光片从开始遮挡至离开光电门的时间差。" >
</info>
<separator editor:uuid="157" editor:posx="0" editor:posy="0" height="3" color="000000">
</separator>
<info editor:uuid="392" label="光电门1计时:" >
</info>
<value editor:uuid="155" editor:posx="414" editor:posy="136" label="t1:" size="1" precision="2" scientific="false" unit="毫秒(ms)" factor="1" >
<input>CH1</input>
</value>
<separator editor:uuid="429" height="3" color="000000">
</separator>
<info editor:uuid="448" label="光电门2计时:" >
</info>
<value editor:uuid="156" editor:posx="420" editor:posy="250" label="t2:" size="1" precision="2" scientific="false" unit="毫秒(ms)" factor="1" >
<input>CH2</input>
</value>
<separator editor:uuid="226" height="3" color="000000">
</separator>
<info editor:uuid="571" label="光电门1、2间时间差:" >
</info>
<value editor:uuid="558" editor:posx="430.0333251953125" editor:posy="380.6499938964844" label="t12:" size="1" precision="2" scientific="false" unit="毫秒(ms)" factor="1" >
<input>CH3</input>
</value>
<info editor:uuid="609" label="说明:光电门1、2时间差指从第1个光电门开始挡光至第2个光电门开始挡光的时间差。只有两个光电门都被使用且挡光片经过第2个光电门后,此值才有意义。" >
</info>
<separator editor:uuid="590" height="3" color="000000">
</separator>
<info editor:uuid="497" label="很不幸:由于技术原因,当前两光电门在计时的时候,数据会偶有影响,但只有正在计时的光电门数据才是有效的,而且,两光电门测量的数据并不会因此而出现错误。测量结果仍然是可信的。为避免这种影响,可以在光电计数器上贴上“光电门1”、“光电门2”标签。" >
</info>
</view>
</views>
<export>
</export>
</phyphox>