-->
Page 2 of 4

Re: Talking clock that self-discharges audio for blind peopl

PostPosted: Wed Jan 12, 2022 12:46 pm
by GalactusX31
rpiloverbd wrote:I see. In my opinion, Raspberry pi could be a better choice for this project. RPI has larger memory. Moreover, there are many python libraries that are used to integrate the Pi with google.

Thanks for the advice, unfortunately I don't have a raberry pi module and I don't know its programming or construction.

My goal is to make this project using the microcontrollers that I named in the previous post, more accessible and (more or less) easier to program and understand.

Re: Talking clock that self-discharges audio for blind peopl

PostPosted: Thu Jan 13, 2022 9:21 am
by rpiloverbd
Got your point. All the best with the project. Would love to see it after it is completed.

Re: Talking clock that self-discharges audio for blind peopl

PostPosted: Fri Jan 14, 2022 1:33 pm
by GalactusX31
Just a little update, this is the process I'm using to read the language configuration file; I think this is necessary because when YOU READ or WRITE the "language", in your own language, it is read and written differently ... you know, have you tried to "READ" a word or phrase using the "accent" of another language, sounds weird right?

I know that this code needs many improvements, that's why I put it here, waiting for your suggestions, corrections, critics and improvements.

Code: Select all#include <SD.h>
#include <SPI.h>
//-----------------------------------------------------------------------
//  This portion of code is only for testing
//  using the messages through the serial port.
#define debugprogram 1 // 1: Send messages to serial port
                       // 0: Disable serial messaging

#if debugprogram == 1
#define PRINT(x)    Serial.print(x)
#define PRINTLN(x)  Serial.println(x)
#else
#define PRINT(x)
#define PRINTLN(x)
#endif
//-----------------------------------------------------------------------

File root;  //  Needed to use the SD library

int tasks     = 0;  //  Multipurpose variable to control the "ReadFile"
                    //  function and other aspects of module programming
int FileLines = 0;  //  variable that stores the number of lines in a file

String chosenlanguage;  //  Variable that stores the selected language

//------------------------[ void ReadFile ]------------------------------
//  General purpose function, which encompasses
//  everything related to reading and writing files
//-----------------------------------------------------------------------

void ReadFile( String FileName, int ReadFileOpcion ) {
    // FileName: Function target file name
    // ReadFileOption: option to use only one function and simplify programming

  root = SD.open( "/" + FileName + ".txt", FILE_READ );
 
  int LineNumRead = 1;
  bool found = false; //
 
  if ( root.available() > 0 ) {
    PRINTLN ( "File: \" " + FileName + " \" exist, accessing ...\n" );
    while (root.available() > 0 ) {
      switch ( ReadFileOpcion ) {
        case 1: { // This function only serves to "count" the lines in the desired file
       
          String FL = root.readStringUntil( '\n' ); //  Read the selected file "line-by-line" using line feed as limit
          LineNumRead += 1; //  Every time it reaches the end of a line, we increase the value of "lines read" counter.
          }
          FileLines = LineNumRead - 1;

        break;
        case 2: {
          String FL = root.readStringUntil( '\n' ); //  Read the selected file "line-by-line" using line feed as limit

          int init = FL.indexOf('-');
          String lang1 = FL.substring( 0, init ); //  Get the content of the entire line
          PRINTLN("Actual line: " + String(LineNumRead));

          if ( lang1 == chosenlanguage ) {
            found = true; // 
            PRINTLN("- CODE: " + chosenlanguage + ", exist in line: " + LineNumRead + ", inside of file: " + FileName);
            PRINTLN("- The languages translated for this code are as follows:");

            while ( found == true ) { //init > 0 ){
              int last = FL.indexOf( ',',init + 1 );
              if ( last < 0){ break; }  //  Force to etect if there are no more separators, and we exit the process
              String lang2 = FL.substring( init+1, last ); // Detect the following subString within the current reading
                                                           // line and pass it to the serial port (or for any other use,
                                                           // for example: enter these text strings in a menu).
              PRINTLN ( " * " + lang2 );
              init = last;  //  We assign the next "initial" position, the "end" of the previous one,
                            //  in this way we can reuse the code without adding anything new
            }
          }
        }
        LineNumRead += 1;
      }
      if ( found == true ) {  //  If the language CODE is found, please stop reading / searching, so we make this process
                              //  faster and we don't waste time reading the rest of the file
        PRINTLN("CODE language found!");
        break;
      }
    }
 
    if ( found != true && ReadFileOpcion == 2){ //  If we read the "languages" file and we do not find the CODE, we launch an alert
      PRINTLN("- The selected CODE language: " + chosenlanguage + " is not present in file: " + FileName);
    }
 
  } else {  //  If the "languages" file is not found, we launch an alert, this can be used later to "download" this file from the internet cloud
    PRINTLN("The file cannot be read or does not exist\n");
  }
 
  LineNumRead = 1;
  root.close(); //  Force to close any open file, in this case "root"
}

void setup(){
  Serial.begin(112500); // Initialize the serial port
 
  SD.begin(5);  // Initialize the SD module

  chosenlanguage = "en"; // We select the default language
 
  tasks = 1;
}
//  We use the variable "tasks", to tell the program where to start
void loop(){
  switch (tasks) { 
    case 1:
      ReadFile("languages",1);  //  Count the lines present in the file "languages.txt"
      ReadFile("languages",2);  //  Find the language CODE in the file, and load the translated languages for it
      tasks += 1;
    break;
  }
}

Language File:
Image
After running the program on the ESP32:
Image
I'm trying not to use "Strings" and use "string" objects, but I have to learn its correct handling better, my programming knowledge is all self-learning, so if your eyes burn when you see my way of programming, I'm sorry :lol: .

I have tried to use the BBCODE [spoiler] [/spoiler], but it is disabled in the forum?

Re: Talking clock that self-discharges audio for blind peopl

PostPosted: Sat Jan 15, 2022 7:05 pm
by GalactusX31
Another small advance... and a small setback... I have found that Arduino and special characters are not good friends, for example if I want to use the letter "Ñ", when creating files or directories using the SD library, this one creates the names in a... weird way, let me show you:

Image
I have been searching all day for a way to be able to use special characters, but literally nothing about it, just some lazy answers about "replacing" those special characters with their equivalent in ASCII code... could someone tell me a way to do it ? I mean, to be able to use those special characters?