Raspberry Pi Zero 2W - How To Enable I2C and OLED Display Example
Raspberry Pi Zero 2W - How To Enable I2C and OLED Display Example
in
8–10 minutes
• What is Raspberry Pi ?
• Pi Zero 2W
• Features
• Prerequisites
• Coding
• Conclusion
What is Raspberry Pi ?
The device features USB ports, HDMI output, GPIO pins for
hardware projects, and network connectivity, making it a
powerful and flexible tool for numerous applications.
Features
• Raspberry Pi Zero 2W
• Heat Sinks
• Cables
Circuit Diagram
Hardware Interfacing
Raspberry Pi Zero 2W
+3.3V VCC
GND GND
Prerequisites
Now, connect the OLED display as per the circuit diagram, and
run the following command to see if your Raspberry Pi can see
the display or not -
i2cdetect -y 1
Now that we have setup all the necessary things by which we'll
be able to communicate to the I2C display. Now lets move onto
necessary libraries through which we can get something printed
onto the display.
Lets make a project folder and move into it using the respective
commands-
mkdir oled_display
cd oled_display
After that we need git, to copy the examples from a github repo.
Get git by using this -
sudo apt install git -y
and followed by the cloning of the library to local from github by
-
git clone https://github.com/rm-hull/
luma.examples.git
After done installing these, you can make your own python
program or head into luma.examples/examples to try out pre-
written programs on the OLED display by using command -
cd luma.examples/examples and then
python [the file name you want to try].py
Coding
def main():
# Create I2C interface
serial = i2c(port=1, address=0x3C)
# Create device
device = ssd1306(serial)
if __name__ == "__main__":
main()
After saving the code you can run it by using command -
python disp.py
Conclusion
Hence, after all this setting up and example. You'll have basic
knowledge on how to setup and work with OLED display in
Raspberry PI Zero 2W. If there is any problem or error's arising,
feel free to refer the video which is present on youtube
practically walking you through the process step by step.