Creating a Photo Frame with Raspberry Pi 3 + Official 7-inch Touchscreen
Introduction
Previously, I created a photo frame using a Raspberry Pi. This time, since I had a Raspberry Pi 3 and a 7-inch touchscreen available, I decided to make another photo frame using these components.
Items Needed
Raspberry Pi 3
Raspberry Pi 3 Model B シングルボードコンピュータ
Official Touchscreen
Raspberry Pi 公式 7" タッチスクリーン LCD Element14
公式タッチスクリーン用ケース
Raspberry Pi & 7インチ LCDタッチスクリーン 拡張ボードケース ABS樹脂 (RSコンポーネンツ製) (黒)
Connecting the Display
Follow the official manual to assemble the display.
Raspberry Pi Touch Display
Attach the Raspberry Pi to the back of the display, connecting the ribbon cable for data and red/black wires for power. Ensure the connections are oriented correctly: red to the 5V pin and black to the GND pin.
The following image shows how to attach the Raspberry Pi to the back of the Touch Display (if required), and how to connect both the data (ribbon cable) and power (red/black wires) from the Raspberry Pi to the display. If you are not attaching the Raspberry Pi to the back of the display, take extra care when attaching the ribbon cable to ensure it is the correct way round. The black and red power wires should be attached to the GND and 5v pins respectively.
Ref : https://www.raspberrypi.com/documentation/accessories/display.html
Adjusting Display Settings
By default, the display may be upside down. To fix this, edit /boot/config.txt to include:
pi@raspi3-photo:~ $ sudo vi /boot/config.txt
lcd_rotate=2
Python Program for Slideshow
Reuse a previously created Python script to run a slideshow on the photo frame.
Reducing Brightness
The screen is too bright by default. Adjust the brightness using the following command:
Reducing Brightness
Adjust the screen brightness using the following command:
root@raspi3-photo:~# echo "100" | sudo tee /sys/class/backlight/rpi_backlight/brightness
You want to adjust the display brightness according to ambient light.
Once you can change the brightness, you’ll naturally want to adjust the display brightness to match the ambient light.
ELEGOO 120pcs多色デュポンワイヤー、arduino用ワイヤ—ゲ—ジ28AWG オス-メス オス-オス メス –メス ブレッドボードジャンパーワイヤー
WINGONEER GY-30 BH1750FVIデジタル光強度センサモジュールI2Cラズベリーパイ
So, I decided to purchase the GY-30 BH1750FVI light sensor. I also bought some jumper wires along with it.
Raspberry Pi and SPI Connection
Connect the purchased GY-30 BH1750FVI optical sensor to Raspberry Pi via SPI. Connect referring to the official documentation.
SPI hardware
GPIO and the 40-pin header
Connection correspondence table
RaspberryPi | Raspberry Pi PIN number | GY-30 BH1750FV |
---|---|---|
GPIO2 (SDA) | 3 | SDA |
GPIO3 (SCL) | 5 | SCL |
5V Power | 2 | VCC |
Ground | 14 | ADO |
Ground | 20 | GND |
Read data of optical sensor (SPI)
Let’s check if the connected light sensor works. I’ll try writing it in Python.
#!/usr/bin/python3
import smbus
Bus = smbus.SMBus(1)
Addr = 0x23
LxRead = Bus.read_i2c_block_data(Addr,0x11)
print("Illuminance: "+str(LxRead[1]* 10)+" lx")
LxRead2 = Bus.read_i2c_block_data(Addr,0x10)
print("Luminance: " + str((LxRead2[0] * 256 + LxRead2[1]) / 1.2))
The above program was based on Opensourcetech blog.
RaspberryPi/bh1750fvi.py at master · kujiraitakahiro/RaspberryPi
It is also published on GitHub.
When I executed it immediately, I was able to obtain the brightness.
root@raspi3-photo:~# python br.py
Illuminance: 1650 Lux
Brightness: 990.8333333333334
Automatically adjust display brightness according to ambient brightness
At this point, we will create a program that automatically adjusts the display brightness according to the acquired brightness. Adjusting the brightness was easy, so I created a Python program that runs at a 10ms cycle.
The mechanism is simple: define the target display brightness for each brightness, and increment/decrement the display brightness once according to the obtained brightness.
SPI cannot be obtained too early
SPI communication using the SMBus described above is performed, but if the loop speed is too fast, values cannot be obtained correctly. Therefore, I decided to acquire the data every 300ms.
GY-30 BH1750FVI Light Sensor Installation
The installation location was installed on the protruding part of the back. Of course, I think it’s better to install it in a place where it can get a lot of light.
Created program
The created program is published on GitHub.
2022/5/25 Rebuilt with object orientation.
GitHub - yukishita/lcdBrightness2: GY-30 BH1750FVI 光センサー で明るさを取得して Raspberry Pi 公式7インチタッチスクリーンの輝度を調整するプログラム(オブジェクト指向版)
Demonstration
This is a demo video of the program I created.
summary
By adding a GY-30 BH1750FVI light sensor to the Raspberry Pi 3 + official 7-inch touch screen, I was able to create a photo frame that supports changing the brightness.
isues
no issues currently.