-
1Construction- Wiring
- We began the wiring of this project by first joining the GND terminals of every button, which will be connected to the expansion board's GND.
- We next connected each switch's I/O pin by following the wiring diagram. We use 8 GPIO as we are using 8 switches.
- The expansion board's battery connector was soldered with battery terminals.
-
2CODE
After finalizing the wiring connection process, we uploaded the below code into the XIAO EXP32 S3 board.
#include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define SSD1306_I2C_ADDRESS 0x3C // Declaration for SSD1306 display connected using I2C (default address 0x3C) Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT); const int buttonPins[] = {0, 1, 2, 6, 7, 8, 9, 10}; // Button pins const int buttonCount = 8; const int speakerPin = D3; // Speaker pin // Define frequencies for each button const int frequencies[8] = {523, 587, 659, 698, 784, 880, 988, 1047}; // C5 to C6 void setup() { // Initialize the display if (!display.begin(SSD1306_I2C_ADDRESS, 0x3C)) { for (;;); } display.display(); delay(2000); // Pause for 2 seconds display.clearDisplay(); display.setTextSize(4); display.setTextColor(SSD1306_WHITE); display.setCursor(5, 20); display.println(F("SYNTH")); display.display(); // Initialize button pins as input with pull-up resistors for (int i = 0; i < buttonCount; i++) { pinMode(buttonPins[i], INPUT_PULLUP); } pinMode(speakerPin, OUTPUT); noTone(speakerPin); // Ensure the speaker is off initially } void loop() { bool buttonPressed = false; for (int i = 0; i < buttonCount; i++) { int buttonState = digitalRead(buttonPins[i]); if (buttonState == LOW) { // Button pressed tone(speakerPin, frequencies[i]); // Play tone // Flash the display with button press info display.clearDisplay(); display.setTextSize(2); display.setTextColor(SSD1306_WHITE); display.setCursor(0, 0); display.print("Button "); display.print(i + 1); // Display button index (1-based) display.println(" pressed"); display.display(); buttonPressed = true; } } // Turn off the speaker if no button is pressed if (!buttonPressed) { noTone(speakerPin); } else { delay(100); // Hold the display for a short period display.clearDisplay(); display.display(); // Clear the display after a button press } delay(100); // Debounce delay }
Here's a short breakdown for the code.
#include <Wire.h>#include <Adafruit_GFX.h>#include <Adafruit_SSD1306.h>
These libraries are included to control the I2C communication (
Wire.h
) and to interface with the SSD1306 OLED display (Adafruit_GFX.h
andAdafruit_SSD1306.h
).const int buttonPins[] = {0, 1, 2, 6, 7, 8, 9, 10}; // Button pinsconst int buttonCount = 8;const int speakerPin = D3; // Speaker pinconst int frequencies[8] = {523, 587, 659, 698, 784, 880, 988, 1047}; // C5 to C6
This specifies the GPIO pins used for buttons and the speaker. Also defines the frequencies corresponding to each button, representing musical notes from C5 to C6.
-
3Final Assembly
- Following the completion of the electronics and coding, we began the main assembly procedure, which begins with the battery positioned between the two frames. The Xiao expansion board is then installed in its location, and it is fastened in place with M2 screws.
- The button board is then positioned and fastened in place with M2 screws.
The assembly process is now complete.
-
4Result
Thus, this project's end result is a functional synth that works like a standard synth yet is incredibly compact and portable.
This project's size and the fact that we were able to combine everything into a very small package are its best features. However, there are some issues with this setup, such as the output buzzer's low volume.
Additionally, we are using an expansion board, which takes up space and has other parts like an RTC and SD card reader. To further reduce the project's size, we can create a customized board, which will be significantly smaller. This is what version 2 will be focusing on.
All the details regarding this project, including files, are attached, which you can download.
Leave a comment if you need any help regarding this project. This is it for today, folks.
Thanks to Seeed Studio Fusion for supporting this project.
Seeed Fusion PCBService offers one-stop prototyping for PCB manufacture and PCB assembly, and as a result, they produce superior-quality PCBs and fast turnkey PCBAs within 7 working days.
You guys can check them out if you need great PCB and stencil service for less cost and great quality.
And I'll be back with a new project pretty soon!
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.