Again, your descriptions are not detailed enough. What are these "voice commands" ? What do you want them to do? What do they actually do?
okay let me tell you clearly. Watch the video to understand. Buzzer beeping different frequencies depending to pressure changes. here is the code without screen. its works perfect when its coded without screen.
#include <toneAC.h>
#include <Wire.h>
#include <MS5611.h>
MS5611 ms5611; // MS5611 sensörü nesnesi
/*
Donanım bağlantıları:
- (GND) GND'ye
+ (VDD) 3.3V'ye
SCL A5 pinine
SDA A4 pinine
D9 ve D10 pinlerine Piezo Buzzer (toneAC.h kütüphanesi ile)
*/
#define NUM_PRESSURES 64
#define NUM_TOTALS 16
uint32_t pressure[NUM_PRESSURES];
uint32_t old_total[NUM_TOTALS];
int pressure_index = 0;
int total_index = 0;
uint32_t total;
int current_tone = 0;
int beep_time = 0;
void setup() {
// Seri iletişimi başlat
Serial.begin(9600);
// Başlangıç sesi çal
toneAC(388, 4);
delay(70);
toneAC(0);
delay(30);
toneAC(590, 4);
delay(70);
// MS5611 sensörünü başlat
if (!ms5611.begin()) {
Serial.println("MS5611 sensörü tespit edilemedi. Bağlantıları kontrol edin.");
while (1);
}
uint32_t p = ms5611.readPressure();
total = p * NUM_PRESSURES;
// İlk değeri kullanarak basınç dizisini başlat
for (int i = 0; i < NUM_PRESSURES; i++) {
pressure[i] = p;
}
// İlk toplam değeri kullanarak eski toplam dizisini başlat
for (int i = 0; i < NUM_TOTALS; i++) {
old_total[i] = total;
}
toneAC(0);
}
void loop() {
// Yeni basıncı oku ve toplam basıncı güncelle
total -= pressure[pressure_index];
pressure[pressure_index] = ms5611.readPressure(); // MS5611'den güncel basıncı oku
total += pressure[pressure_index];
// Basınç değişim hızını hesapla
int32_t rate = total - old_total[total_index];
old_total[total_index] = total;
// Basınç dizisinin ve toplam dizisinin indekslerini sıfırla
pressure_index++;
total_index++;
if (pressure_index >= NUM_PRESSURES) pressure_index = 0;
if (total_index >= NUM_TOTALS) total_index = 0;
// Basınç değişim hızına göre ton frekansını ayarla
if (rate < -50) {
if (beep_time < 5) {
toneAC(1000 - rate / 2); // Basınç değişimine bağlı olarak frekansı artır
} else {
toneAC(0); // Belirli bir süre sonra tonu kapat
}
} else if (rate > 50) {
// Basınç değişim hızına bağlı olarak frekansı belirle
float f = 1000.0 + 40000.0 * 1.0 / ((float)rate); // Yüksek frekanslar için formül
toneAC((int)f);
} else {
// Basınç değişim hızı küçükse tonu kapat
toneAC(0);
}
// beep_time'ı artır ve sıfırla
beep_time++;
if (beep_time >= 10) beep_time = 0;
}
And this code(WITHIUT BUZZER) OLED screen and ms5611 sensor ;
Screen shows current altitude, temprature, pressure.
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <MS5611.h> // https://github.com/jarzebski/Arduino-MS5611
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C // See datasheet for Address
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
MS5611 ms5611;
double referencePressure;
void setup() {
Serial.begin(9600);
// Initialize MS5611 sensor
Serial.println("Initialize MS5611 Sensor");
while (!ms5611.begin()) {
Serial.println("Could not find a valid MS5611 sensor, check wiring!");
delay(500);
}
// Initialize OLED Display
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
}
display.clearDisplay();
display.display();
delay(500);
// Get reference pressure for relative altitude
referencePressure = 101250;
// Check sensor settings
checkSettings();
delay(2000);
}
void checkSettings() {
Serial.print("Oversampling: ");
Serial.println(ms5611.getOversampling());
}
void loop() {
// Read true temperature & pressure
double realTemperature = ms5611.readTemperature();
long realPressure = ms5611.readPressure();
double realPressureKPa = realPressure / 1000.0; // Pa -> kPa dönüşümü
// Calculate altitude
float relativeAltitude = ms5611.getAltitude(realPressure, referencePressure);
// Print to Serial Monitor
Serial.println("--");
Serial.print("Temperature: ");
Serial.print(realTemperature);
Serial.println(" *C");
Serial.print("Pressure: ");
Serial.print(realPressureKPa, 2); // 2 ondalık basamak gösterimi
Serial.println(" kPa");
Serial.print("Relative Altitude: ");
Serial.print(relativeAltitude);
Serial.println(" m");
// Display on OLED
display.clearDisplay();
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.setTextSize(1);
display.print("Temp: ");
display.print(realTemperature);
display.print(" C");
display.setCursor(0, 20);
display.print("Pressure: ");
display.print(realPressureKPa, 2); // 2 ondalık basamak hassasiyeti
display.print(" kPa");
display.setCursor(0, 40);
display.print("Altitude: ");
display.print(relativeAltitude);
display.print(" m");
display.display();
delay(2000);
}
I did that also and screen started shown by "merhaba" on the screen. However, the response of the buzzer to pressure changes is very delayed. This is an undesirable situation.
I ordered gps module and sd-card module for this project to save flight time data to a sdcard. now im stuck here ![]()
you can watch the videos. you can understand what happens when I changed
values.
Downloads.zip (2.9 MB)
You really need a board with more ram than an atmega328 based Nano. The SD card will need 512 bytes of memory for a buffer, and the GPS generally needs serial data, so either SoftwareSerial on a Nano, or it can be done with Serial if you don't need the serial monitor.
You cannot use the Adafruit_SSD1306 library, it needs too much memory. There is the SSD1306Ascii library that needs no buffer in memory, but is limited to text. The U8g2 library has an u8x8 variant that allows text and limited bitmap images, or the full U8g2 library with a page buffer that only needs about 128 bytes of ram for the buffer.
See if this modified version of your code runs using the U8g2 library (you may need to install that through the IDE's library manager:
#include <Wire.h>
////#include <Adafruit_GFX.h>
////#include <Adafruit_SSD1306.h>
#include <toneAC.h>
#include <MS5611.h>
#include <U8g2lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
MS5611 ms5611; // MS5611 sensor object
#define SCREEN_WIDTH 128 // Screen width
#define SCREEN_HEIGHT 64 // Screen height
#define OLED_RESET -1 // Screen reset pin, this screen doesn't have a reset pin
#define NUM_PRESSURES 64
#define NUM_TOTALS 16
uint32_t pressure[NUM_PRESSURES];
uint32_t old_total[NUM_TOTALS];
int pressure_index = 0;
int total_index = 0;
uint32_t total;
int current_tone = 0;
int beep_time = 0;
// Create the OLED screen object
////Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
U8G2_SSD1306_128X64_NONAME_1_HW_I2C display(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
void setup() {
// Start serial communication
Serial.begin(9600);
// Initialize OLED screen (using address 0x3C)
////if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C
//// Serial.println(F("Failed to initialize OLED display"));
//// while (1); // Stop if the screen fails to initialize
////}
display.begin();
// Clear the OLED screen
////display.clearDisplay();
// Play startup sound
toneAC(388, 4);
delay(70);
toneAC(0);
delay(30);
toneAC(590, 4);
delay(70);
// Initialize the MS5611 sensor
if (!ms5611.begin()) {
Serial.println("MS5611 sensor not detected. Check the connections.");
while (1); // Stop if the sensor is not detected
}
uint32_t p = ms5611.readPressure();
total = p * NUM_PRESSURES;
// Initialize the pressure array with the first value
for (int i = 0; i < NUM_PRESSURES; i++) {
pressure[i] = p;
}
// Initialize the old_total array with the first total value
for (int i = 0; i < NUM_TOTALS; i++) {
old_total[i] = total;
}
toneAC(0);
// Display "Merhaba" (Hello) on the screen
////display.setTextSize(1); // Set text size
////display.setTextColor(SSD1306_WHITE); // Set text color to white
////display.setCursor(0, 0); // Set starting position (top left corner)
////display.print(F("Merhaba")); // Print "Merhaba" (Hello)
////display.display(); // Update the display
display.setFont(u8g2_font_6x10_tr);
display.firstPage();
do {
display.setCursor(0, 8);
display.print(F("Merhaba in setup"));
} while (display.nextPage());
delay(2000); // Display for 2 seconds
}
void loop() {
// Read new pressure and update the total pressure
total -= pressure[pressure_index];
pressure[pressure_index] = ms5611.readPressure(); // Read current pressure from MS5611
total += pressure[pressure_index];
// Calculate the pressure change rate
int32_t rate = total - old_total[total_index];
old_total[total_index] = total;
// Reset the indices for the pressure and total arrays
pressure_index++;
total_index++;
if (pressure_index >= NUM_PRESSURES) pressure_index = 0;
if (total_index >= NUM_TOTALS) total_index = 0;
// Adjust tone frequency based on the pressure change rate
if (rate < -50) {
if (beep_time < 5) {
toneAC(1000 - rate / 2); // Increase frequency based on pressure change
} else {
toneAC(0); // Turn off tone after a certain period
}
} else if (rate > 50) {
// Set frequency based on the pressure change rate
float f = 1000.0 + 40000.0 * 1.0 / ((float)rate); // Formula for higher frequencies
toneAC((int)f);
} else {
// Turn off the tone if the pressure change rate is small
toneAC(0);
}
// Increase beep_time and reset if necessary
beep_time++;
if (beep_time >= 10) beep_time = 0;
// Continuously display "Merhaba" on the screen
////display.clearDisplay(); // Clear the screen
////display.setCursor(0, 0); // Set starting position
////display.print(F("Merhaba")); // Print "Merhaba" (Hello)
////display.display(); // Update the display display.firstPage();
display.firstPage();
do {
display.setCursor(0, 8);
display.print(F("Merhaba in loop"));
} while (display.nextPage());
delay(500); // Wait for 500ms
}
Any advice you have? What should I use? It must be small as nano
There are multiple boards that are the same size as the Nano, often with the word "Nano" as part of their name. Adafruit also has their "Feather" line of boards of a similar size, including one with an ESP32 processor and a TFT display on the back, if you really want something compact.
I have done some analysis on your code that produces the beeps.
If NUM_PRESSURES is half of its previous value (32 not 64), then total will be approximately half also. Not exactly half, because the pressure readings will vary. But total is now the sum of 32 pressure values instead of 64 pressure values, so on average it will be about half what it would be for 64 values.
This means that rate will also be approximately half what it was previously. This makes it much less likely to be < -50 or > 50, and will also affect the frequency of the beeps, because they are calculated using rate.
For a quick fix, you could double the value of rate to compensate:
int32_t rate = 2 * (total - old_total[total_index]);
However, I think it would be better to re-design this code, because it has many faults:
- Changing the value of
NUM_PRESSURESandNUM_TOTALSbreaks the buzzer code, as we have seen. - Pressure readings are taken at maximum rate which loop() can execute, which is determined by the other code in loop(). For example, updating the OLED slows down loop() and this will also break the buzzer code.
- If you are able to save data to the SD card, this will also slow down loop() and break the buzzer code.
- If you upgrade the Nano to a faster Arduino with more memory, this will increase the speed of loop() and break the buzzer code.
If/when you re-design the buzzer code, I recommend:
- it should include some timing using millis() or micros(), so that the pressure readings are taken at a constant rate, not at whatever speed loop() executes.
- Use average pressure readings, not totals, to calculate the buzzer frequencies, so that you can change
NUM_PRESSURESandNUM_TOTALSas you like without affecting the buzzer frequencies. - Calculate
rateas a value which represents a change in Pascals per second, regardless of how many readings were averaged and how fast those readings were taken.