大家好,这篇是我参加电子测光表项目的成果贴。
本次项目的系统框图如下:
具体的硬件连接为如下
实物使用杜邦线连接,电源接口不足,将几个外设的电源线焊接在一起
由于adafruit这块开发板提供了相当多的例程和资料,所以基础任务的开发过程还是相当轻松的。
首先找到我这块esp32-s3的官方资料,网址如下Overview | Adafruit ESP32-S3 TFT Feather | Adafruit Learning System
有硬件介绍,开发环境介绍及教程,跟着一步一步来,就完成开发环境搭建了,然后根据github上的例程,简单修改一下示例代码,依次驱动按键,bh1750,舵机,以及屏幕显示。Adafruit_CircuitPython_Bundle/libraries at main · adafruit/Adafruit_CircuitPython_Bundle · GitHub
基本组件驱动完成之后,就可以将驱动代码整合起来,实现基础任务功能,
基础任务:
1 编程实现按键状态的采集
2 编程实现数字光传感器BH1750的数据读取
3 基于屏幕驱动函数实现字符的显示,例如显示Hello EEPW & DigiKey;也可显示自己喜欢的名言警句
4 实现光强信息的屏幕显
基本功能实现代码:
import time import math import board import adafruit_bh1750 import digitalio import terminalio from adafruit_display_text import bitmap_label import displayio from adafruit_motor import servo import pwmio pwm = pwmio.PWMOut(board.A5, duty_cycle=2 ** 15, frequency=50) my_servo = servo.Servo(pwm) i2c = board.I2C() sensor = adafruit_bh1750.BH1750(i2c) def calculate_ev(lux): return 2 + math.log(lux / 10, 2) if lux > 0 else 0 def calculate_shutter_speed(ev, aperture, iso): base_shutter_speed = (aperture ** 2) / (2 ** ev) adjusted_shutter_speed = base_shutter_speed * (100 / iso) return adjusted_shutter_speed button_up = digitalio.DigitalInOut(board.A2) button_up.direction = digitalio.Direction.INPUT button_up.pull = digitalio.Pull.UP button_down = digitalio.DigitalInOut(board.A3) button_down.direction = digitalio.Direction.INPUT button_down.pull = digitalio.Pull.UP group = displayio.Group() board.DISPLAY.root_group = group lux_label = bitmap_label.Label(terminalio.FONT, text="", scale=2) lux_label.x = 10 lux_label.y = 10 group.append(lux_label) shutter_label = bitmap_label.Label(terminalio.FONT, text="", scale=2) shutter_label.x = 10 shutter_label.y = 40 group.append(shutter_label) aperture_label = bitmap_label.Label(terminalio.FONT, text="", scale=2) aperture_label.x = 10 aperture_label.y = 70 group.append(aperture_label) iso_label = bitmap_label.Label(terminalio.FONT, text="", scale=2) iso_label.x = 10 iso_label.y = 100 group.append(iso_label) aperture = 3.5 iso = 100 while True: lux = sensor.lux ev = calculate_ev(lux) if not button_up.value: iso = min(iso * 2, 6400) time.sleep(0.2) elif not button_down.value: iso = max(iso // 2, 100) time.sleep(0.2) shutter_speed = calculate_shutter_speed(ev, aperture, iso) lux_label.text = f"lux: {lux:.1f}" shutter_label.text = f"shutter: 1/{int(1 / shutter_speed)}s" if shutter_speed > 0 else "shutter: --" aperture_label.text = f"aperture: f/{aperture:.1f}" iso_label.text = f"ISO: {iso} EV: {ev}"
运行效果如下:
实时获取测光值,并显示出来,默认设置ISO为100(可以通过按键调节ISO值),光圈为3.5,快门速度随光强而变化,依据公式:
以上就是我本次项目的展示内容,希望eepw越办越好。