3.5in LCD Display for Raspberry Pi Documentation
The 3.5in LCD Display for Raspberry Pi is a compact and high-resolution display module designed specifically for the Raspberry Pi single-board computer. This display module features a 3.5-inch TFT LCD screen with a resolution of 320x480 pixels, making it an ideal component for building interactive projects and devices.
Display Size: 3.5 inches
Resolution: 320x480 pixels
Interface: SPI
Power Supply: 5V
Compatible with Raspberry Pi models: Raspberry Pi 2, 3, and 4
To get started with the 3.5in LCD Display for Raspberry Pi, you'll need to:
1. Connect the display module to the Raspberry Pi using the provided ribbon cable.
2. Install the necessary libraries and drivers on your Raspberry Pi.
3. Write code to interact with the display module using the installed libraries.
### Example 1: Displaying an Image using Python
In this example, we'll use the `pygame` library to display an image on the 3.5in LCD Display.
Code:
```python
import pygame
import os
# Initialize pygame
pygame.init()
# Set the display mode
pygame.display.set_mode((320, 480))
# Load the image
image = pygame.image.load('image.jpg')
# Blit the image onto the screen
screen = pygame.display.get_surface()
screen.blit(image, (0, 0))
# Update the display
pygame.display.flip()
# Wait for 5 seconds
pygame.time.wait(5000)
# Quit pygame
pygame.quit()
```
Note: Make sure to replace `image.jpg` with the path to your desired image file.
### Example 2: Displaying Text using Python
In this example, we'll use the `pygame` library to display text on the 3.5in LCD Display.
Code:
```python
import pygame
import os
# Initialize pygame
pygame.init()
# Set the display mode
pygame.display.set_mode((320, 480))
# Set the font
font = pygame.font.SysFont('Arial', 24)
# Render the text
text_surface = font.render('Hello, World!', True, (255, 255, 255))
# Blit the text onto the screen
screen = pygame.display.get_surface()
screen.blit(text_surface, (50, 50))
# Update the display
pygame.display.flip()
# Wait for 5 seconds
pygame.time.wait(5000)
# Quit pygame
pygame.quit()
```
### Example 3: Creating a GUI using Tkinter
In this example, we'll use the `tkinter` library to create a simple GUI on the 3.5in LCD Display.
Code:
```python
import tkinter as tk
# Create a tkinter window
window = tk.Tk()
# Set the window size
window.geometry('320x480')
# Create a label
label = tk.Label(window, text='Hello, World!')
label.pack()
# Create a button
button = tk.Button(window, text='Click me!')
button.pack()
# Run the GUI event loop
window.mainloop()
```
Note: These code examples assume that you have the necessary libraries and drivers installed on your Raspberry Pi. Make sure to follow the manufacturer's instructions for installing the necessary software.