Raspberry Pi3 GPIO interface can be used directly drives the OLED screen
First, wiring
According to the Internet just to find the map you can see the Raspberry Pi GPIO pin order Interface 3
PS: 26pin front of the 26-pin GPIO
Pin Description The OLED screen, as shown in Table can be connected:
Raspberry | YOU ARE |
5V | VCC |
GND | GND |
SCL | SCL |
SDA | SDA |
Second, install the necessary tools
sudo apt-get install -y python-smbus
sudo apt-get install -y i2c-tools
After the installation is complete, run sudo raspi-config, will enable I2C interface
run
Sudo i2cdetect -and 1
If you have marked at 0x3c, then the I2C start successfully
Third, coded display
Raspberry python driver oled screen needs luna.oled library, can be installed directly pip
Code:
from luma.core.interface.serial import i2c from luma.oled.device import sh1106 from luma.core.render import canvas from PIL import ImageFont import time def stats(oled): font = ImageFont.load_default() with canvas(oled) as draw: localtime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) draw.text((2, 5), localtime, font=font, fill=255) def main(): serial = i2c(port=1, address=0x3C) oled = sh1106(serial) while True: stats (OLED) time.sleep(1) if __name__ == "__main__": main()