Skip to content

Commit 2deed0e

Browse files
waveshare-esp32-s3-touch-lcd-2: power off camera at boot to conserve power
By default, it turns on at reset, making it hot and consume more current.
1 parent 6745a09 commit 2deed0e

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

internal_filesystem/boot.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
LCD_BL = 1
2727

2828
I2C_BUS = 0
29-
I2C_FREQ = 100000
29+
I2C_FREQ = 400000
3030
TP_SDA = 48
3131
TP_SCL = 47
3232
TP_ADDR = 0x15
@@ -87,4 +87,21 @@
8787
import mpos.battery_voltage
8888
mpos.battery_voltage.init_adc(5, 262 / 100000)
8989

90+
# On the Waveshare ESP32-S3-Touch-LCD-2, the camera is hard-wired to power on,
91+
# so it needs a software power off to prevent it from staying hot all the time and quickly draining the battery.
92+
try:
93+
from machine import Pin, I2C
94+
i2c = I2C(1, scl=Pin(16), sda=Pin(21)) # Adjust pins and frequency
95+
devices = i2c.scan()
96+
print("Scan of I2C bus on scl=16, sda=21:")
97+
print([hex(addr) for addr in devices]) # finds it on 60 = 0x3C after init
98+
camera_addr = 0x3C # for OV5640
99+
reg_addr = 0x3008
100+
reg_high = (reg_addr >> 8) & 0xFF # 0x30
101+
reg_low = reg_addr & 0xFF # 0x08
102+
power_off_command = 0x42 # Power off command
103+
i2c.writeto(camera_addr, bytes([reg_high, reg_low, power_off_command]))
104+
except Exception as e:
105+
print(f"Warning: powering off camera got exception: {e}")
106+
90107
print("boot.py finished")

0 commit comments

Comments
 (0)