Difference between revisions of "BakeBit - Light Sensor"

From FriendlyELEC WiKi
Jump to: navigation, search
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
[[BakeBit - Light Sensor/zh|查看中文]]
 
[[BakeBit - Light Sensor/zh|查看中文]]
  
==介绍==
+
==Introduction==
 
[[File:BakeBit - Light Sensor.jpg|thumb|Light Sensor]]
 
[[File:BakeBit - Light Sensor.jpg|thumb|Light Sensor]]
*BakeBit - Light Sensor是一个光敏电阻模块,主要器件是一个光敏电阻。光敏电阻的制作材料具有在特定波长的光照射下,其阻值迅速减小的特性。
+
* The BakeBit - Light Sensor is a photoresistor module. The resistance of a photoresistor decreases with increasing incident light intensity.
*这是由于光照产生的载流子都参与导电,在外加电场的作用下作漂移运动,电子奔向电源的正极,空穴奔向电源的负极,从而使光敏电阻器的阻值迅速下降。在电源激励下,输出端分压减小。
+
* If incident light on a photoresistor exceeds a certain frequency, photons absorbed by the semiconductor give bound electrons enough energy to jump into the conduction band. The resulting free electrons (and their hole partners) conduct electricity, thereby lowering resistance.
  
==特性==
+
==Hardware Spec==
* 使用标准的2.0mm 4 Pin BakeBit接口
+
* Standard 2.0mm pitch 4-Pin BakeBit Interface
* PCB尺寸(mm):20x24
+
* PCB dimension(mm): 20 x 24
* 模拟信号输出
+
* Analog Outpu
 
[[File:BakeBit - Light Sensor_PCB.png | frameless|350px|BakeBit - Light Sensor]]
 
[[File:BakeBit - Light Sensor_PCB.png | frameless|350px|BakeBit - Light Sensor]]
  
* 引脚说明:
+
* Pin Description:
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
|名称 || 描述
+
|Pin || Description
 
|-
 
|-
|GND  ||
+
|GND  || Ground
 
|-
 
|-
|5V    || 电源5V
+
|5V    || 5V Supply Voltage
 
|-
 
|-
|NC    ||
+
|NC    || Ground
 
|-
 
|-
|SIG  || 信号
+
|SIG  || Signal
 
|}
 
|}
== 示例程序:Smart Lighting ==
 
  
利用亮度传感器,聪明地控制灯光(灯用LED Bar来模拟),环境越暗就让灯越亮,环境亮度足够时,就将灯变暗或者熄灭。
+
== Code Sample: Smart Lighting ==
本示例需要配合[[BakeBit - LED Bar]]使用。
+
  
=== 硬件连接 ===
+
By running this code sample your system adjusts the LEDs on the LED module(LED Bar) according to surrounding lightness. When the surrounding environment becomes darker the LEDs will be brighter. When the surrounding becomes bright enough the LEDs will be completely off.
简单的将[[BakeBit - LED Bar]]模块插入 D3 接口,将[[BakeBit - Light Sensor]]插入 A0 接口,如下面这样:
+
A [[BakeBit - LED Bar]] module is needed in this test case.
 +
 
 +
=== Hardware Setup ===
 +
Connect the [[BakeBit - LED Bar]] module to the NanoHat Hub's D3 and the [[BakeBit - Light Sensor]] module to the NanoHat Hub's A0:
  
 
::{| class="wikitable"
 
::{| class="wikitable"
Line 39: Line 40:
 
|}
 
|}
  
=== 示例源代码 ===
+
=== Source Code ===
  
 
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
Line 114: Line 115:
  
  
=== 运行示例 ===
+
=== Run Code Sample ===
 
   
 
   
假设你已经参考[http://wiki.friendlyarm.com/bakebit bakebit教程]安装了BakeBit源代码,<br />
+
Before you run the code sample you need to follow the steps in [http://wiki.friendlyarm.com/bakebit bakebit tutorial] to install the BakeBit package.<br />
要运行示例程序,可以在开发板上进入 BakeBit/Software/Python目录,运行bakebit_prj_SmartLighting.py:
+
Enter the "BakeBit/Software/Python" directory and run the "bakebit_prj_SmartLighting.py" program:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
cd ~/BakeBit/Software/Python
 
cd ~/BakeBit/Software/Python
Line 123: Line 124:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
=== 运行结果 ===
+
=== Observation ===
  
测试时可用物品盖住光敏电阻模拟环境变暗,或者用手机电筒照射模拟环境变亮,然后观察LED Bar的变化。<br />
+
When you cover the smart lighting’s photo sensor or make the surrounding environment brighter the LEDs will be on or off.<br />
LED Bar上被点亮的LED个数由当前环境的光线决定,越暗,被点亮的就最多。
+
The LEDs on the LED Bar module will be turned on or off according to surrounding environment’s lightness. When the the surrounding environment becomes darker more LEDs will be turned on otherwise the LEDs will be off.
  
==相关资料==
+
==Resources==
 
*[Schematic]([http://wiki.friendlyarm.com/wiki/images/e/e8/06-SCHEMATIC_Light_Sensor.pdf BakeBit - Light Sensor.pdf])
 
*[Schematic]([http://wiki.friendlyarm.com/wiki/images/e/e8/06-SCHEMATIC_Light_Sensor.pdf BakeBit - Light Sensor.pdf])
*[BakeBit Github项目](https://github.com/friendlyarm/BakeBit)
+
*[BakeBit Github Project Page](https://github.com/friendlyarm/BakeBit)
*[BakeBit Starter Kit手册](http://wiki.friendlyarm.com/bakebit/bakebit_starter_kit_manual_cn.pdf)
+
*[BakeBit Starter Kit User's Manual](http://wiki.friendlyarm.com/bakebit/bakebit_starter_kit_manual_en.pdf)
 +
 
 +
==Update Log==
 +
===December-13-2016===
 +
* Released English version
 +
 
 +
===Jan-19-2017===
 +
* Renamed "NEO-Hub" to "NanoHat-Hub"
 +
 
 +
===Jan-20-2017===
 +
* Renamed "NanoHat-Hub" to "NanoHat Hub"

Latest revision as of 08:17, 20 January 2017

查看中文

1 Introduction

Light Sensor
  • The BakeBit - Light Sensor is a photoresistor module. The resistance of a photoresistor decreases with increasing incident light intensity.
  • If incident light on a photoresistor exceeds a certain frequency, photons absorbed by the semiconductor give bound electrons enough energy to jump into the conduction band. The resulting free electrons (and their hole partners) conduct electricity, thereby lowering resistance.

2 Hardware Spec

  • Standard 2.0mm pitch 4-Pin BakeBit Interface
  • PCB dimension(mm): 20 x 24
  • Analog Outpu

BakeBit - Light Sensor

  • Pin Description:
Pin Description
GND Ground
5V 5V Supply Voltage
NC Ground
SIG Signal

3 Code Sample: Smart Lighting

By running this code sample your system adjusts the LEDs on the LED module(LED Bar) according to surrounding lightness. When the surrounding environment becomes darker the LEDs will be brighter. When the surrounding becomes bright enough the LEDs will be completely off. A BakeBit - LED Bar module is needed in this test case.

3.1 Hardware Setup

Connect the BakeBit - LED Bar module to the NanoHat Hub's D3 and the BakeBit - Light Sensor module to the NanoHat Hub's A0:

Smart Lighting-1.jpg Smart Lighting-2.jpg

3.2 Source Code

import time
import bakebit
 
# Connect the BakeBit Light Sensor to analog port A0
# SIG,NC,VCC,GND
light_sensor = 0
 
# Connect the BakeBit LED Bar to digital port D3
# DI,DCKI,VCC,GND
ledbar = 3
 
 
lowThreshold = 500
highTreshold = 600
 
bakebit.pinMode(light_sensor,"INPUT")
bakebit.pinMode(ledbar,"OUTPUT")
time.sleep(.2)
bakebit.bakeBitLedBar_Init(ledbar, 0, 5)
time.sleep(.5)
old_color = 0
 
while True:
    try:
        light_count = 0
 
        # Get sensor value
        sensor_value = bakebit.analogRead(light_sensor)
        if sensor_value > highTreshold:
            f=(1023-highTreshold)/4
            light_count =  (sensor_value-highTreshold)/f+1
 
            # turn on ledbar
            color16bit = bakebit.Green
            if light_count > 1:
                color16bit = color16bit | (bakebit.Green << 3)
            if light_count > 2:
                color16bit = color16bit | (bakebit.Green << 6)
            if light_count > 3:
                color16bit = color16bit | (bakebit.Green << 9)
            if light_count > 4:
                color16bit = 0
                color16bit = color16bit | bakebit.Blue
                color16bit = color16bit | (bakebit.Blue << 3)
                color16bit = color16bit | (bakebit.Blue << 6)
                color16bit = color16bit | (bakebit.Blue << 9)
                color16bit = color16bit | (bakebit.Blue << 12)
 
            if color16bit != old_color:
                old_color = color16bit
                lowBits = color16bit & 255
                highBits = (color16bit & (255 << 8)) >> 8
                bakebit.bakeBitLedBar_Show(ledbar, highBits, lowBits)
 
        elif sensor_value < lowThreshold:
            # turn off ledbar
            bakebit.bakeBitLedBar_Show(ledbar, 0, 0)
 
        print("sensor_value = %d light_count =%d" %(sensor_value,  light_count))
        time.sleep(.5)
 
    except KeyboardInterrupt:
        bakebit.bakeBitLedBar_Release(ledbar)
        time.sleep(.2)
        break
    except IOError:
        print ("Error")

Github


3.3 Run Code Sample

Before you run the code sample you need to follow the steps in bakebit tutorial to install the BakeBit package.
Enter the "BakeBit/Software/Python" directory and run the "bakebit_prj_SmartLighting.py" program:

cd ~/BakeBit/Software/Python
sudo python bakebit_prj_SmartLighting.py

3.4 Observation

When you cover the smart lighting’s photo sensor or make the surrounding environment brighter the LEDs will be on or off.
The LEDs on the LED Bar module will be turned on or off according to surrounding environment’s lightness. When the the surrounding environment becomes darker more LEDs will be turned on otherwise the LEDs will be off.

4 Resources

5 Update Log

5.1 December-13-2016

  • Released English version

5.2 Jan-19-2017

  • Renamed "NEO-Hub" to "NanoHat-Hub"

5.3 Jan-20-2017

  • Renamed "NanoHat-Hub" to "NanoHat Hub"