S3 Mini Pro Lolin Simple Projects + Bonus Catching Pumpkins Game!
by Bits4Bots in Circuits > Microcontrollers
262 Views, 3 Favorites, 0 Comments
S3 Mini Pro Lolin Simple Projects + Bonus Catching Pumpkins Game!
Whether you're new to microcontrollers or an experienced maker, these projects lay a solid foundation for further exploration into the S3 Mini Pro's advanced features, such as Wi-Fi, Bluetooth, and advanced I/O handling. There's so much more to come with this powerful microcontroller—this is just the beginning!
This project was created to provide content for the new S3 Mini Pro a WiFi & BLE board based on the ESP32-S3FH4R2 with 0.85 inch TFT Screen and IMU. Since there are not many tutorials available yet, I wanted to dive in with three fun LED projects.
Supplies
Buy your board here:
https://www.tindie.com/products/bits4bots/s3-mini-pro-v100-lolin-wifi-bluetooth-iot/
https://www.aliexpress.com/item/3256807173247391.html
and you'll need some 3mm LED.
Get your software here:
https://www.wemos.cc/en/latest/s3/s3_mini_pro.html#tutorials
Arduino IDE Setup
- Download the latest Arduino IDE
- Open the platform by double clicking to icon
- Under "Tools" - "Boards" add the ESP32 by Espressif
- esp32 arduino package
*Use the Development release link
Additional libraries may need to be installed for certain projects.
- TFT_eSPI
- AdaFruit
- etc.
Blink Sketch
The Blink sketch is one of the simplest and most common starting projects for working with microcontrollers. It demonstrates how to control a digital output pin by turning an LED on and off at a regular interval. Here's how it works:
Overview:
- Pin 37 is used as the digital output pin to which the LED is connected.
- The LED is powered using the 3V pin from the microcontroller.
- The sketch alternates between turning the LED on and off, creating a blinking effect.
Downloads
Blink the Built-in RGB LED
/*
Modified by: Bits4Bots LLC - Larsha Johnson
BlinkRGB
Demonstrates usage of onboard RGB LED on the S3 Mini Pro ESP dev boards.
Calling digitalWrite(RGB_BUILTIN, HIGH) will use hidden RGB driver.
RGBLedWrite demonstrates control of each channel:
void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val)
WARNING: After using digitalWrite to drive RGB LED it will be impossible to drive the same pin
with normal HIGH/LOW level
*/
//#define RGB_BRIGHTNESS 64 // Change white brightness (max 255)
// the setup function runs once when you press reset or power the board
void setup() {
// No need to initialize the RGB LED
pinMode(7, OUTPUT); //Provide power to the WS2812B-0807 IC (RGB LED)
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(7, HIGH); //Send power to the WS2812B-0807 IC
#ifdef RGB_BUILTIN
//digitalWrite(RGB_BUILTIN, HIGH); // Turn the RGB LED white
//delay(1000);
//digitalWrite(RGB_BUILTIN, LOW); // Turn the RGB LED off
// delay(1000);
neopixelWrite(RGB_BUILTIN, RGB_BRIGHTNESS, 0, 0); // Red
delay(1000);
neopixelWrite(RGB_BUILTIN, 0, 0, RGB_BRIGHTNESS); // Green - normally (0, 255, 0) is displayed as green but there internal wiring is flipped
delay(1000);
neopixelWrite(RGB_BUILTIN, 0, RGB_BRIGHTNESS, 0); // Blue - normally (0, 0, 255) is displayed as blue but there internal wiring is flipped
delay(1000);
//neopixelWrite(RGB_BUILTIN, 0, 0, 0); // Off / black
//delay(1000);
#endif
}
How It Works:
This code controls the onboard RGB LED on the S3 Mini Pro ESP32 microcontroller and demonstrates how to use the digitalWrite function to turn it on/off as well as how to control each color channel (red, green, blue) individually using the neopixelWrite function.
Breakdown of the code:
- Comment Section
- The comments describe the functionality of the code. It highlights that the onboard RGB LED is controlled using digitalWrite for basic on/off functionality, and neopixelWrite is used for controlling the color intensities of the RGB LED.
- There's a warning that after using digitalWrite to control the RGB LED, it won't be possible to drive the same pin with a simple HIGH/LOW signal.
- Setup Function
- pinMode(7, OUTPUT);: This configures pin 7 as an output. Pin 7 provides power to the RGB LED driver chip, which is the WS2812B-0807 IC.
- This means that the RGB LED will be ready to receive signals for color control.
- Loop Function
- The loop() function repeats continuously, providing power and alternating the RGB LED colors.
- digitalWrite(7, HIGH);: Sends power to the WS2812B RGB driver IC (via pin 7), making the RGB LED ready to operate.
- digitalWrite(RGB_BUILTIN, HIGH);: Turns the onboard RGB LED on, setting it to white because all color channels (R, G, B) are active at full intensity.
- delay(1000);: Introduces a 1-second delay before proceeding to the next command.
- digitalWrite(RGB_BUILTIN, LOW);: Turns off the RGB LED (all color channels are turned off).
- The next section demonstrates controlling each color channel individually with the neopixelWrite function:
- neopixelWrite(RGB_BUILTIN, RGB_BRIGHTNESS, 0, 0);: This command sets the RGB LED to red by turning on the red channel and turning off the green and blue channels.
- neopixelWrite(RGB_BUILTIN, 0, RGB_BRIGHTNESS, 0);: This sets the RGB LED to green.
- neopixelWrite(RGB_BUILTIN, 0, 0, RGB_BRIGHTNESS);: This sets the RGB LED to blue.
- neopixelWrite(RGB_BUILTIN, 0, 0, 0);: This turns off the RGB LED completely (black/off).
- Each of these color-changing steps is followed by a 1-second delay (delay(1000);).
Functions Explained:
- digitalWrite(pin, value):
- This is a standard Arduino function that sets the voltage on a specified pin to either HIGH (3.3V/5V) or LOW (0V).
- Here, it is used to turn the RGB LED on/off as well as provide power to the WS2812B IC.
- neopixelWrite(pin, red_val, green_val, blue_val):
- This custom function is used to control the individual red, green, and blue channels of the RGB LED.
- The values red_val, green_val, and blue_val specify the brightness of each color channel. The intensity typically ranges from 0 (off) to 255 (full brightness).
- In this case, RGB_BRIGHTNESS is used to define the brightness (default is 64).
Key Takeaways:
- The code first turns the RGB LED white, turns it off, then cycles through the red, green, and blue colors using the neopixelWrite function.
- The onboard RGB LED can be controlled using both basic HIGH/LOW digital commands and by setting specific color intensities for each channel.
This code is useful for learning how to control multicolor LEDs and can be extended to create more complex lighting patterns or effects.
Concept:
- By combining the three basic color channels (red, green, and blue), you can create a variety of colors. For now, this sketch simply demonstrates how to turn each channel on and off individually.
Extending the Sketch:
- You could modify this sketch to create custom colors by turning on multiple channels at once (e.g., red and green together will create yellow).
This basic project is a great way to explore RGB color control and how to manipulate the built-in RGB LED on your S3 Mini Pro ESP32.
Draw a Circle With Text - or Image
The Draw a Circle sketch for the S3 Mini Pro ESP32 with a TFT display demonstrates how to use the Adafruit GFX library to draw a simple geometric shape—a circle—on the screen. This sketch shows how to set up the display, define coordinates, and draw a circle using the built-in graphics functions of the library.
How It Works:
- Library Setup:
- The sketch begins by including the necessary libraries: Adafruit_GFX (for graphics functions) and Adafruit_ST7735 (for the specific TFT display you're using).
- Pin Definitions:
- TFT_CS, TFT_RST, TFT_DC, and TFT_BL represent the control pins for the TFT display. These are essential for communication between the microcontroller and the display.
Take a look at page 5 of the schematic to understand the TFT pinout.
- Display Initialization:
- Inside setup(), the display is initialized with tft.initR(INITR_BLACKTAB); which prepares the screen for drawing. The screen is then cleared with a black background using tft.fillScreen(ST77XX_BLACK);.
- Drawing the Circle:
- The circle is drawn using the tft.drawCircle() function. Here’s the breakdown:
- x_center: The x-coordinate of the circle's center, calculated as half the display width.
- y_center: The y-coordinate of the circle's center, slightly shifted upward by 10 pixels to leave room for the message at the bottom.
- radius: The radius of the circle, set to 30 pixels.
- ST77XX_WHITE: The color of the circle, set to white.
- Displaying a Message:
- The tft.setCursor() function is used to set the position where text will be printed. In this case, the text is placed near the bottom of the screen.
- The tft.print() function then prints the message "Circle drawn!" on the display.
Key Functions:
- tft.drawCircle(x_center, y_center, radius, color):
- This function draws a circle on the display. It takes the x and y coordinates of the center, the radius, and the color of the circle as arguments.
- tft.setCursor(x, y):
- Sets the position where text will appear on the screen.
- tft.print("Text"):
- Prints the specified text at the current cursor position.
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Library for the ST7735 TFT screen
#include <SPI.h>
// Define the pins for your display (adjust these to your setup)
#define TFT_CS 35 // Chip select pin
#define TFT_RST 34 // Reset pin
#define TFT_DC 36 // Data/Command pin
#define TFT_BL 33 // Backlight pin (TFT_BL/IO33)
// Create an instance of the display
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
void setup() {
// Initialize the backlight pin
pinMode(TFT_BL, OUTPUT);
digitalWrite(TFT_BL, HIGH); // Turn on the backlight
// Initialize the display
tft.initR(INITR_BLACKTAB); // Specific initialization for the ST7735 screen
tft.fillScreen(ST77XX_BLUE); // Clear the screen with black background
// Set the circle's parameters
int x_center = tft.width() / 2; // X center of the circle
int y_center = (tft.height() / 2) - 10; // Y center of the circle, shifted up by 24 pixels (3 rows)
int radius = 26; // Radius of the circle
// Set text color and size
tft.setTextColor(ST77XX_WHITE);
tft.setTextSize(2);
// Draw a circle
tft.drawCircle(x_center, y_center, radius, ST77XX_WHITE);
// Optionally display a message on the screen
tft.setCursor(0, 0);
tft.print("A Circle! Bits4Bots");
}
void loop() {
// The loop remains empty for this demo
}
Download the file to draw a circle on the screen or the Bits4BotsTM logo.
I used an images to byte array online converter (C++, Arduino) to generate my robot logo. The TFT screen is 128 x 128 pixels.
Concept:
- This sketch demonstrates how to display basic shapes and text on a TFT screen. Drawing a circle is just one of the many graphics functions provided by the Adafruit GFX library, which also supports lines, rectangles, triangles, and more.
Conclusion:
The Draw a Circle sketch is a great introduction to using graphical displays with the S3 Mini Pro ESP32. It shows how to combine graphics and text to create interactive or informative outputs on a small screen, which can be extended for more complex applications like games, data visualization, or custom user interfaces.
Conclusion
The three starter projects—Blink, BlinkRGB Built-in, and Draw a Circle—serve as a great introduction to the capabilities of the S3 Mini Pro ESP32. These projects demonstrate the microcontroller's versatility, ease of use, and compatibility with the Arduino IDE. With Blink, you get started with basic GPIO control, while BlinkRGB introduces you to the built-in RGB functionality, showcasing the microcontroller’s built-in features. Finally, Draw a Circle highlights its capability to interact with external peripherals, like a TFT display, for more complex graphical output.
Catching Pumpkins Game
Falling Pumpkins Game: Rules and Gameplay
Objective:
The goal of the game is to catch falling pumpkins by pressing the correct button corresponding to the column where the pumpkin is falling. Each successful catch increases your score, while missing a pumpkin results in a game over.
Game Setup:
- Start Screen:
- The game begins with a title screen that displays "Catch the Pumpkin!" along with an image of a big pumpkin.
- After a brief delay, the game screen clears, and the player is taken to the gameplay screen.
- Gameplay Screen:
- The screen is divided into three vertical columns where pumpkins can fall:
- Column 0: Left
- Column 1: Center
- Column 2: Right
- Pumpkins fall from the top of the screen toward the bottom.
Game Rules:
- Falling Objects:
- A pumpkin randomly falls from the top of the screen at regular intervals (every 1 second).
- The pumpkin will fall in one of the three columns.
- Catching Pumpkins:
- Players need to press the corresponding button when the pumpkin reaches the bottom of the screen:
- Left Button (IO0): For pumpkins falling in Column 0 (left).
- Center Button (IO47): For pumpkins falling in Column 1 (center).
- Right Button (IO48): For pumpkins falling in Column 2 (right).
- If the player presses the correct button as the pumpkin reaches the bottom, they successfully catch the pumpkin, and their score increases by 1.
- Game Over:
- If a pumpkin reaches the bottom of the screen without being caught (i.e., the player presses the wrong button or fails to press any button), the game ends.
- A game over screen displays the message "Game Over!" along with the player's final score.
Scoring:
- The player earns 1 point for each pumpkin caught.
- The score is displayed on the game over screen, allowing players to see how well they did.
Strategy Tips:
- Anticipate the Fall: Pay close attention to where the pumpkin is falling and be ready to react quickly.
- Button Press Timing: Timing is crucial; press the button as the pumpkin approaches the bottom to maximize your chances of catching it.
Conclusion:
The Falling Pumpkins Game is a simple yet engaging game that tests players' reaction times and button-pressing accuracy. It provides a fun Halloween-themed experience, making it suitable for all ages. Enjoy catching as many pumpkins as you can! 🎃