Based on the hardware features of Wio Terminal (2.4-inch LCD screen, physical buttons, efficient processor) and Arduino open-source ecosystem, this project realizes an immersive F1 racing game. Players control the car to avoid obstacles by pressing buttons, the game difficulty increases dynamically with the score, combined with professional racing graphics rendering and physical collision detection to reproduce the real track racing experience.
1. Core features include:a. Three-lane track system
b. Dynamic obstacle generation
c. Push-button control of the car's movement
d. Dynamic increase in game difficulty
e. Professional racing graphics rendering
2. Hardware Design and Connectivity2.1 Core Hardware
Main Control Device :Wio Terminal (equipped with ATSAMD51P19 chip, 120MHz main frequency, 320×240 resolution screen)
Input Device : WIO_KEY_A: left shift control
WIO_KEY_C: right shift control
WIO_KEY_B: game restart
Power Supply :USB Type-C power supply
2.2 Hardware Features Using
screen rendering: directly call the TFT_eSPI library to drive the LCD to achieve a smooth 60fps screen.
Physical buttons: use the internal pull-up resistor to trigger the action by detecting a low level through digitalRead().
Performance optimization: SAMD51P19's 192KB RAM supports real-time computation of complex game states.
3. Environment Configuration Stepsa. Install the board support package:
// IDE操作路径
Tools → Board → Boards Manager → 搜索"Wio Terminal" → 安装
b. Library dependency installation :
Sketch → Include Library → Manage Libraries → 搜索安装TFT_eSPI
4. Game Core Logic Implementationa. Game Engine Architecture
void loop() {
if (gameRunning) {
updateGame(); // 状态更新
drawGame(); // 图形渲染
delay(50); // 20fps帧率控制
} else {
gameOverScreen();
}
}
b. Key Technology Realization
Track and Vehicle Model
Three-lane system: coordinate calculation is based on the dynamic allocation of screen width.
const int LANES[3] = {
(SCREEN_WIDTH - ROAD_WIDTH)/2 + ROAD_WIDTH/6, // 左
SCREEN_WIDTH/2, // 中
(SCREEN_WIDTH - ROAD_WIDTH)/2 + ROAD_WIDTH*5/6 // 右
};
Racing car rendering : drawing body, tires, lights in layers (fillRect+fillCircle combination)
Obstacle system
Dynamic generation : generating cones in random lanes every 1.2 seconds (obstacleInterval)
Collision detection : based on lane alignment and Y-axis position determination (simplified enveloping box algorithm)
if (obstacles[i].lane == currentLane &&
obstacles[i].y > SCREEN_HEIGHT - CAR_HEIGHT - 10) {
gameRunning = false; // 碰撞触发
}
Difficulty curve :
if (score % 5 == 0) gameSpeed++; // 每5分加速
c. Graphics Rendering Optimization
Layered drawing strategy :
graph TD
A[清屏] --> B[绘制道路]
B --> C[绘制车道线]
C --> D[绘制障碍物]
D --> E[绘制赛车]
E --> F[绘制UI]
UI component : real-time display of score, speed, lanes and obstacle intervals (see drawGame() function)
5. Innovative interaction design5.1 Control programs
Physical Feedback Enhancement
Vibration Motor Integration (Extended Suggestion):
// 碰撞时触发振动
void crashFeedback() {
digitalWrite(VIBRATION_PIN, HIGH);
delay(200);
digitalWrite(VIBRATION_PIN, LOW);
}
(requires connection of vibration motor to GPIO pins)
6. Performance testing and optimization6.1 Key indicators
6.2 Collision Detection Optimization (Comparison of Algorithms)
// 优化后:添加距离阈值判定
if (abs(obstacles[i].y - carY) < CAR_HEIGHT/2 + OBSTACLE_SIZE/2) {
// 精确碰撞判定
}
7. Expansion directiona. network battle function Synchronize the data of two machines through Wio Terminal's WiFi module (RTL8720DN).
WiFiUDP Udp; // 建立UDP连接
Udp.beginPacket(serverIP, port);
Udp.write(gameState); // 发送游戏状态
b. Sensory feedback system Integrated IMU (LIS3DHTR) to simulate the effect of track bumps.
c. Sound Enhancement Using buzzer to play engine sound (PWM frequency modulation)
d. Data persistence MicroSD card to save high score records (SD.h library implementation)
8. Fault ResolutionTrouble:
Compilation Error: Type Conversion Failure & Library Conflict
Problem:
While compiling the code, the following error occurs:
error: could not convert 'lis.LIS3DHTR<TwoWire>::begin(Wire1, 24)' from 'void' to 'bool'
if(!lis.begin(Wire1)) { ... } // Attempt to use void as bool
Additionally, a library conflict is reported:
Multiple libraries found for "Adafruit_ZeroDMA.h"
Used: Seeeduino package library
Not used: User's local library
Cause Analysis:
1. Type Mismatch in Sensor Initialization
a. The begin() function of the LIS3DHTR library returns void (no value), but your code attempts to use it as a bool in an if(!lis.begin(...)) condition.
b. Arduino expects conditional checks (e.g., if) to evaluate a boolean value, but void cannot be converted to bool.
2. Library Conflict
a. The compiler detects two copies of Adafruit_ZeroDMA.h: Used : Bundled with Seeeduino SAMD boards package (Arduino15\packages\Seeeduino\...).
i. Ignored : User-installed library in Documents\Arduino\libraries.
Solution:
1. Fix Sensor Initialization
Modify the code to remove the invalid boolean check :
// Before (Error)
if(!lis.begin(Wire1)) { // ❌ Attempts to convert void to bool
Serial.println("LIS3DHTR init failed");
while(1);
}
// After (Corrected)
lis.begin(Wire1); // ✅ Direct initialization (returns void)
// Add explicit connection check if needed
if (lis.getDeviceID() != 0x33) { // Check device ID
Serial.println("LIS3DHTR not detected!");
while(1);
}
Explanation :
● begin() only initializes hardware and has no return value. Use getDeviceID() to verify connectivity.
● For LIS3DHTR, valid device ID is 0x33 (hex).
2. Resolve Library Conflict
Delete or rename the conflicting local library :
● Navigate to: C:\Users\seeed\Documents\Arduino\libraries\
● Remove or rename the folder Adafruit_Zero_DMA_Library.
● Restart Arduino IDE to ensure the correct library (Seeeduino package version) is used.
3. Verify Hardware Connections
Ensure the sensor is correctly wired to Wio Terminal:
Note : Use 3.3V power (not 5V) to avoid damaging LIS3DHTR.
9. Project SummaryThis project verifies the feasibility of Wio Terminal as an embedded gaming platform:
a. All-in-one design: screen + input device + processor are highly integrated, reducing the number of external modules.
b. Development efficiency: Arduino ecosystem provides rich graphic libraries (TFT_eSPI) and hardware abstraction layers.
c. Educational value: complete coverage of core concepts such as state machine design, physics simulation, human-computer interaction, etc.
Future iterations: can be combined with TinyML frameworks (e.g., TensorFlow Lite Micro) to realize gesture-controlled steering, and to explore the innovative application of AI in embedded games.
reference resource
How to install an Arduino library | Seeed Studio Wiki
https://wiki.seeedstudio.com/Wio-Terminal-FS-Overview/
Fonts | Seeed Studio Wiki
Comments