光电门传感器

来自Labplus盛思维基百科
跳转至: 导航搜索
blue:bit-光电门传感器

概述

Photogate Time是测量触发时刻和触发结束时刻的时间模块。

技术参数

  • 工作电压:VCC 3.3-5V
  • I2C数字信号输出
  • 时间范围 : 0~
  • 解析度: 10微秒
  • 精度: 2%
  • 模块尺寸:24x46x7.5mm

引脚定义/接口说明

VCC 电源
SDA I2C数据
SCL I2C时钟
GND
  • 拨动开关,可选择模块的I2C地址,用于避免与其他I2C设备地址冲突。注意,重新选择I2C地址后,需要重新上电才能生效!
  • 触发信号的输入接口
VCC 电源
CH0 NA(未用)
CH1 触发信号输入
GND
  • CH1引脚可接入任意数字输入传感器

使用教程

  • 在程序编程中需要注意拨动开关地址和程序中的地址一致!
  • 计算信号的正脉宽时间,当输入信号由低变高为触发开始点,由高变低位触发触发结束点,计算之间的时间差。

掌控板

图形化编程

光电门.png

代码编程

from mpython import *
import bluebit

a = bluebit.DelveBit(0x50)

while True:
    print(a.photo_gate())

Arduino

include <Wire.h>
int reading = 0;
int reading0 = 0;
int reading1 = 0;
int reading2 = 0;
int reading3 = 0;
int reading4 = 0;
long trigger_begin;
long trigger_end; 
float  trigger_time;
void Get_Photogate_value(char address)  
{
  Wire.requestFrom(0x51, 5); 
  if (5 <= Wire.available())
  {
       reading0 = Wire.read();
       reading1 = Wire.read();
       reading2 = Wire.read();
       reading3 = Wire.read();
       reading4 = Wire.read();
       if(reading0==1)
       {
         trigger_begin = reading1*16777216  + reading2*65536 + reading3*256 + reading4;
         //Serial.println(1);
         //Serial.println(trigger_begin);
       } 
       if(reading0==0)
       {
         trigger_end = reading1*16777216  + reading2*65536 + reading3*256 + reading4;
         //Serial.println(0);
         //Serial.println(trigger_end);
         trigger_time = (float)(trigger_end - trigger_begin)/2041667;     //250000    2041667
         Serial.println(trigger_time);         
       }
  
}
void setup()
{
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output
}

void loop()
{
  Get_Photogate_value(0x51);
}


版本历史记录

Version Date 新增/删除/修复