Creating a Photo Frame with Raspberry Pi 3 + Official 7-inch Touchscreen

Image credit: Tomokatsu Yukishita

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 シングルボードコンピュータ
thumbnail
Raspberry Pi(ラズベリー パイ) 3 Model B。

Raspberry Pi 3 Model Bは、Raspberry Pi Foundation(ラズベリーパイ財団)のシングルボードコンピュータです。 本バージョンでは、1.2GHz、64ビットのクアッドコアARMプロセッサにアップグレードし、802.11nのワイヤレスLAN、Bluetooth 4.1、Bluetooth Low Energyに対応させています。

Official Touchscreen

Raspberry Pi 公式 7" タッチスクリーン LCD Element14
thumbnail
・マルチタッチ静電容量型 - 最大で指10本のタッチをサポート
The official 7-inch touchscreen LCD supports multitouch with up to 10 fingers, an 800x480 resolution at 60 fps, and 24-bit RGB color. It connects to the Pi via a GPIO jumper and a ribbon cable. ・7インチディスプレイ
・800 x 480ピクセルの解像度 @ 60 フレーム/秒(fps)
・24ビットRGBカラー
・GPIOジャンパ - 付属のジャンパワイヤを使用してPiからディスプレイボードに電力を供給

https://www.amazon.co.jp/Raspberry-Pi-タッチスクリーン-LCD-Element14/dp/B01LC7U4XW?crid=H9B54FE4LVXV&keywords=raspberry+pi+7-inch+touch+screen+display&qid=1652495973&sprefix=raspberry+pi+touch+screen,aps,179&sr=8-5&linkCode=sl1&tag=snowunderco07-22&linkId=1ae04ad79661bfdd07526bcfb6b7673a&language=ja_JP&ref_=as_li_ss_tl

公式タッチスクリーン用ケース

Raspberry Pi & 7インチ LCDタッチスクリーン 拡張ボードケース ABS樹脂 (RSコンポーネンツ製) (黒)
thumbnail
RS Proのタッチスクリーンケースは、Raspberry PiボードとRaspberry Pi 7インチLCDタッチスクリーンを収納するように設計されています。 ボードとディスプレイを保護するこのケースには、黒色、白色、クリアのタイプが用意されています。 Raspberry Pi 3 Model B、Pi 2 Model B、B+を取り付けることが可能です。また、このケースはRaspberry Pi本体を後部に収納できるので、持ち運ぶ用途にピッタリです。
https://www.amazon.co.jp/Raspberry-Pi-7インチ-LCDタッチスクリーン-拡張ボードケース-ABS樹脂-(RSコンポーネンツ製)-黒/dp/B01N6786IE?__mk_ja_JP=カタカナ&crid=3UTDPBKHDO9B7&keywords=raspberry%2Bpi%2B7インチタッチスクリーン用ケース%2Bブラック&qid=1652496058&sprefix=raspberry%2Bpi%2Bscreen%2Bencrosue,aps,553&sr=8-11&th=1&linkCode=sl1&tag=snowunderco07-22&linkId=ab44bb9aa59af576356d1a13b71285a5&language=ja_JP&ref_=as_li_ss_tl

Connecting the Display

Follow the official manual to assemble the display.

Raspberry Pi Touch Display
thumbnail
The Raspberry Pi Touch Display is an LCD display that connects to the Raspberry Pi using the DSI connector. You can use both the Touch Display and an HDMI display output at the same time.
https://www.raspberrypi.com/documentation/accessories/display.html

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 オス-メス オス-オス メス –メス ブレッドボードジャンパーワイヤー
thumbnail
材質: copper-clad aluminum,PVC

長さ:約20cm / 8inch

オス端は標準0.1インチ(2.54mm)のメスソケットに挿入し、メス端は標準0.1インチ(2.54mm)のオスヘッダーに挿入するものです。

複数に接続するとき、ケーブルを分けることができます。

WINGONEER GY-30 BH1750FVIデジタル光強度センサモジュールI2Cラズベリーパイ
thumbnail
周囲の照明レベルを測定するBH1750FVIセンサー。 BH1750FVIは、キャリブレーションされたデジタル光センサーICで、入射光強度を測定し、16ビットのデジタル数に変換します。
https://www.amazon.co.jp/gp/product/B06XHKTL58?ie=UTF8&psc=1&linkCode=sl1&tag=snowunderco07-22&linkId=7b8397021a5481ccc0742ebd17a6b0f7&language=ja_JP&ref_=as_li_ss_tl

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
Raspberry Pi Zero, 1, 2 and 3 have three SPI controllers
https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#spi-hardware
GPIO and the 40-pin header
thumbnail
A powerful feature of the Raspberry Pi is the row of GPIO (general-purpose input/output) pins along the top edge of the board. A 40-pin GPIO header is found on all current Raspberry Pi boards, although it is unpopulated on Raspberry Pi Zero, Raspberry Pi Zero W, and Raspberry Pi Zero 2 W. The GPIO headers on all boards have a 0.1in (2.54mm) pin pitch.
https://www.raspberrypi.com/documentation/computers/os.html#gpio-and-the-40-pin-header

screen reader text
引用元: https://www.raspberrypi.com/documentation/computers/os.html#gpio-and-the-40-pin-header

Connection correspondence table

RaspberryPiRaspberry Pi PIN numberGY-30 BH1750FV
GPIO2 (SDA)3SDA
GPIO3 (SCL)5SCL
5V Power2VCC
Ground14ADO
Ground20GND

screen reader text
Photo when connected

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
thumbnail
Contribute to kujiraitakahiro/RaspberryPi development by creating an account on GitHub.
https://github.com/kujiraitakahiro/RaspberryPi/blob/master/bh1750fvi.py

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.

screen reader text
After installing the illuminance sensor

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インチタッチスクリーンの輝度を調整するプログラム(オブジェクト指向版)
thumbnail
GY-30 BH1750FVI 光センサー で明るさを取得して Raspberry Pi 公式7インチタッチスクリーンの輝度を調整するプログラム(オブジェクト指向版) - yukishita/lcdBrightness2
https://github.com/yukishita/lcdBrightness2

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.

Related