104mm x 60mm x 35mm (L x W x H)
104mm x 60mm x 35mm (L x W x H)
80g
1.8m
DPI (Dots Per Inch) | 1000 |
Raspbian, Windows, macOS
USB 2.0
5V, 100mA (max)
Conclusion
The Raspberry Pi Official Mouse Black is a high-quality, ergonomic mouse designed specifically for use with Raspberry Pi single-board computers. Its precise optical sensor, three-button design, and scrolling wheel make it an ideal choice for users requiring accurate and comfortable pointing and navigation. With its compact size, durable construction, and official Raspberry Pi certification, this mouse is a great addition to any Raspberry Pi-based project or setup.
Raspberry Pi Official Mouse Black Documentation
Overview
The Raspberry Pi Official Mouse Black is a high-quality, compact, and plug-and-play mouse designed specifically for use with Raspberry Pi boards. This mouse is a great addition to any Raspberry Pi project, providing a reliable and precise pointing device for interacting with your Raspberry Pi-based system.
Technical Specifications
Interface: USB
Resolution: 1000 dpi
Buttons: 3 (Left, Right, Middle)
Compatibility: Raspberry Pi boards (all models)
Code Examples
### Example 1: Basic Mouse Usage with Python (Raspberry Pi OS)
This example demonstrates how to use the Raspberry Pi Official Mouse Black with Python to read mouse events and movements.
Code:
```python
import pygame
# Initialize pygame
pygame.init()
# Create a pygame window
screen = pygame.display.set_mode((640, 480))
# Get the mouse object
mouse = pygame.mouse
while True:
# Handle events
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.MOUSEMOTION:
# Get the mouse position
x, y = mouse.get_pos()
print(f"Mouse moved to ({x}, {y})")
elif event.type == pygame.MOUSEBUTTONDOWN:
# Get the mouse button state
button_state = mouse.get_pressed()
if button_state[0]: # Left button
print("Left button pressed")
elif button_state[1]: # Middle button
print("Middle button pressed")
elif button_state[2]: # Right button
print("Right button pressed")
# Update the screen
pygame.display.flip()
```
### Example 2: Using the Mouse with a Raspberry Pi-based Robot (Python)
This example demonstrates how to use the Raspberry Pi Official Mouse Black with a Raspberry Pi-based robot to control its movements.
Assumptions:
You have a Raspberry Pi-based robot with motor drivers and a USB connection to the Raspberry Pi.
You have installed the necessary libraries for your robot's motor drivers.
Code:
```python
import RPi.GPIO as GPIO
import time
# Set up GPIO mode
GPIO.setmode(GPIO.BCM)
# Set up motor pins
left_motor_forward = 17
left_motor_backward = 23
right_motor_forward = 24
right_motor_backward = 25
# Set up mouse
mouse = pygame.mouse
try:
while True:
# Get the mouse position
x, y = mouse.get_pos()
# Control the robot's movements based on mouse position
if x > 320: # Move forward
GPIO.output(left_motor_forward, GPIO.HIGH)
GPIO.output(right_motor_forward, GPIO.HIGH)
elif x < 320: # Move backward
GPIO.output(left_motor_backward, GPIO.HIGH)
GPIO.output(right_motor_backward, GPIO.HIGH)
elif y > 240: # Turn left
GPIO.output(left_motor_forward, GPIO.HIGH)
GPIO.output(right_motor_backward, GPIO.HIGH)
elif y < 240: # Turn right
GPIO.output(left_motor_backward, GPIO.HIGH)
GPIO.output(right_motor_forward, GPIO.HIGH)
# Update the motors
time.sleep(0.1)
GPIO.output(left_motor_forward, GPIO.LOW)
GPIO.output(left_motor_backward, GPIO.LOW)
GPIO.output(right_motor_forward, GPIO.LOW)
GPIO.output(right_motor_backward, GPIO.LOW)
except KeyboardInterrupt:
GPIO.cleanup()
```
These examples demonstrate the ease of use and versatility of the Raspberry Pi Official Mouse Black in various contexts. By following these examples, you can integrate the mouse into your Raspberry Pi-based projects and take advantage of its precision and reliability.