IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Arduino Discussion :

Un Serial.println récalcitrant


Sujet :

Arduino

  1. #1
    Membre confirmé
    Homme Profil pro
    Coach
    Inscrit en
    Novembre 2019
    Messages
    228
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Coach

    Informations forums :
    Inscription : Novembre 2019
    Messages : 228
    Par défaut Un Serial.println récalcitrant
    Bonjour,

    Sans doute une erreur stupide (que j'arrive à contourner) mais je voudrais comprendre pourquoi j'ai une erreur de compilation....

    Voici le problème:
    J'ai une constante appelée "length" déclarée avant mon void setup.
    Dans mon void setup j'initialise un tableau appelé "fir1_Coeffs" qui comporte un nombre d'éléments égal à "length", ceci grâce à une boucle "For".
    Lorsque l'index "i" de cette boucle For arrive à la valeur "length" je voudrais afficher "Serial.println("Length= ", length);", et là ça plante à la compilation (alors que le Serial.println qui précède immédiatement celui-ci passe sans problème)...
    J'ai même déclaré "i" en global, mais rien n'y fait.
    Pourtant on peut bien faire afficher la valeur d'un entier après une chaîne de caractère: je l'ai fait des millions de fois...

    J'arrive à m'en passer, mais je ne comprends pas pourquoi ! vu que ça fait longtemps que je traîne ça, je finis par ne plus voir ma bêtise...

    Voici le code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
     
    const int length = 57;	// définition de la longueur du filtre, i.e le nombre de coefficients
     
    // Liste des 57 coefficients bruts donnés par lesite arc.id.au de calcul des fltres
    float Coeffs_Bruts[] = { -0.000220, 0.000395, -0.000589, 0.000753, -0.000817, 0.000696, -0.000308,
     -0.000416, 0.001510, -0.002950, 0.004644, -0.006416, 0.008012, -0.009109, 0.009343, -0.008340, 
    0.005765, -0.001367, -0.004979, 0.013234, -0.023175, 0.034397, -0.046329, 0.058275, -0.069471, 
    0.079153, -0.086631, 0.091355, 0.907029, 0.091355, -0.086631, 0.079153, -0.069471, 0.058275, 
    -0.046329, 0.034397, -0.023175, 0.013234, -0.004979, -0.001367, 0.005765, -0.008340, 0.009343, 
    -0.009109, 0.008012, -0.006416, 0.004644, -0.002950, 0.001510, -0.000416, -0.000308, 0.000696, 
    -0.000817, 0.000753, -0.000589, 0.000395, -0.000220};
     
    // The declaration below seems similar to the "struct" declaration used in the Teensy FIR Filter example
    // but the "const" approach has been said to be more optimized than the éstruct" approach
     
    //remplacer "length" par 57 ne change rien: toujours le Warning à la compilation
    int short fir1_Coeffs[length]; // définition du tableau de constantes que l'on va calculer
    								// à partir de la liste "Coeffs_Bruts" du dessus
     
     
     
     
    //const int myInput = AUDIO_INPUT_MIC;  // removed from the Teensy FIR example
    const int myInput = AUDIO_INPUT_LINEIN; // because my correct input is not MIC
    			// d'autres exemples utilisent myInput = AUDIO_INPUT_LINEIN;
    			// avec un diagramme AudioDesignTool dans le domaine digital aussi
    			// par ex le prog "Invert Phase Audio Signal"
     
    unsigned long last_time = millis(); // copied from the Teensy FIR example
     
    EXTMEM char bigBuffer[1000000]; // pour utiliser les 2 puces PSRAM additionnelles
    								// bigBuffer pourra être renommé si besoin
     
    void setup()
    {
    	Serial.begin(9600);	//copied from the Teensy FIR Filter example
    	delay(300);			//copied from the Teensy FIR Filter example
     
    	strcpy(bigBuffer, "Hello World");	// initialize the bigBuffer with
    										// anything we may want
     
    	//transfère les Coeffs_Bruts dans le tableau LPF_Coeffs, sous forme "short"
     
    	for (int i=1 ; i<=length ; i++) {
    		fir1_Coeffs[i] == (short) (32768 * Coeffs_Bruts[i]);
     
    		// cette boucle if ne passe pas à la compilation, faudra demander pourquoi
    		if (i == length){
    			Serial.println("Tableau fir1_Coeffs initialisé");
    			Serial.println("Length= ", length);
    		}
    		//
     
    	} //fin du remplissage du tableau fir1_Coeffs
    et les messages d'erreur:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
     
    sketch_FIR_009:132: error: no matching function for call to 'println(const char [9], const int&)'
        Serial.println("Length= ", length);
                                         ^
    In file included from E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/Stream.h:24:0,
                     from E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/HardwareSerial.h:115,
                     from E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/WProgram.h:46,
                     from C:\Users\Michel\AppData\Local\Temp\arduino_build_5467\pch\Arduino.h:6:
    E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/Print.h:133:9: note: candidate: size_t Print::println(unsigned char, int) <near match>
      size_t println(unsigned char n, int base) { return print(n, base) + println(); }
             ^
    E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/Print.h:133:9: note:   conversion of argument 1 would be ill-formed:
    \\DS1821\Datas\ELECTRONIQUE\TEENSY\Essais pgm\sketch_FIR_009\sketch_FIR_009.ino:132:37: warning: invalid conversion from 'const char*' to 'unsigned char' [-fpermissive]
        Serial.println("Length= ", length);
                                         ^
    In file included from E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/Stream.h:24:0,
                     from E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/HardwareSerial.h:115,
                     from E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/WProgram.h:46,
                     from C:\Users\Michel\AppData\Local\Temp\arduino_build_5467\pch\Arduino.h:6:
    E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/Print.h:135:9: note: candidate: size_t Print::println(int, int) <near match>
      size_t println(int n, int base)   { return print(n, base) + println(); }
             ^
    E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/Print.h:135:9: note:   conversion of argument 1 would be ill-formed:
    \\DS1821\Datas\ELECTRONIQUE\TEENSY\Essais pgm\sketch_FIR_009\sketch_FIR_009.ino:132:37: warning: invalid conversion from 'const char*' to 'int' [-fpermissive]
        Serial.println("Length= ", length);
                                         ^
    In file included from E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/Stream.h:24:0,
                     from E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/HardwareSerial.h:115,
                     from E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/WProgram.h:46,
                     from C:\Users\Michel\AppData\Local\Temp\arduino_build_5467\pch\Arduino.h:6:
    E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/Print.h:137:9: note: candidate: size_t Print::println(unsigned int, int) <near match>
      size_t println(unsigned int n, int base) { return print(n, base) + println(); }
             ^
    E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/Print.h:137:9: note:   conversion of argument 1 would be ill-formed:
    \\DS1821\Datas\ELECTRONIQUE\TEENSY\Essais pgm\sketch_FIR_009\sketch_FIR_009.ino:132:37: warning: invalid conversion from 'const char*' to 'unsigned int' [-fpermissive]
        Serial.println("Length= ", length);
                                         ^
    In file included from E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/Stream.h:24:0,
                     from E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/HardwareSerial.h:115,
                     from E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/WProgram.h:46,
                     from C:\Users\Michel\AppData\Local\Temp\arduino_build_5467\pch\Arduino.h:6:
    E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/Print.h:139:9: note: candidate: size_t Print::println(long int, int) <near match>
      size_t println(long n, int base)  { return print(n, base) + println(); }
             ^
    E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/Print.h:139:9: note:   conversion of argument 1 would be ill-formed:
    \\DS1821\Datas\ELECTRONIQUE\TEENSY\Essais pgm\sketch_FIR_009\sketch_FIR_009.ino:132:37: warning: invalid conversion from 'const char*' to 'long int' [-fpermissive]
        Serial.println("Length= ", length);
                                         ^
    In file included from E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/Stream.h:24:0,
                     from E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/HardwareSerial.h:115,
                     from E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/WProgram.h:46,
                     from C:\Users\Michel\AppData\Local\Temp\arduino_build_5467\pch\Arduino.h:6:
    E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/Print.h:141:9: note: candidate: size_t Print::println(long unsigned int, int) <near match>
      size_t println(unsigned long n, int base) { return print(n, base) + println(); }
             ^
    E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/Print.h:141:9: note:   conversion of argument 1 would be ill-formed:
    \\DS1821\Datas\ELECTRONIQUE\TEENSY\Essais pgm\sketch_FIR_009\sketch_FIR_009.ino:132:37: warning: invalid conversion from 'const char*' to 'long unsigned int' [-fpermissive]
        Serial.println("Length= ", length);
                                         ^
    In file included from E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/Stream.h:24:0,
                     from E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/HardwareSerial.h:115,
                     from E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/WProgram.h:46,
                     from C:\Users\Michel\AppData\Local\Temp\arduino_build_5467\pch\Arduino.h:6:
    E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/Print.h:143:9: note: candidate: size_t Print::println(int64_t, int) <near match>
      size_t println(int64_t n, int base)  { return print(n, base) + println(); }
             ^
    E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/Print.h:143:9: note:   conversion of argument 1 would be ill-formed:
    \\DS1821\Datas\ELECTRONIQUE\TEENSY\Essais pgm\sketch_FIR_009\sketch_FIR_009.ino:132:37: warning: invalid conversion from 'const char*' to 'int64_t {aka long long int}' [-fpermissive]
        Serial.println("Length= ", length);
                                         ^
    In file included from E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/Stream.h:24:0,
                     from E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/HardwareSerial.h:115,
                     from E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/WProgram.h:46,
                     from C:\Users\Michel\AppData\Local\Temp\arduino_build_5467\pch\Arduino.h:6:
    E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/Print.h:145:9: note: candidate: size_t Print::println(uint64_t, int) <near match>
      size_t println(uint64_t n, int base)  { return print(n, base) + println(); }
             ^
    E:\Programmes\Arduino\hardware\teensy\avr\cores\teensy4/Print.h:145:9: note:   conversion of argument 1 would be ill-formed:
    \\DS1821\Datas\ELECTRONIQUE\TEENSY\Essais pgm\sketch_FIR_009\sketch_FIR_009.ino:132:37: warning: invalid conversion from 'const char*' to 'uint64_t {aka long long unsigned int}' [-fpermissive]
        Serial.println("Length= ", length);
                                         ^
    Plusieurs bibliothèque trouvées pour "SD.h"
    Utilisé : E:\Programmes\Arduino\hardware\teensy\avr\libraries\SD
    Non utilisé : E:\Programmes\Arduino\libraries\SD
    Merci

  2. #2
    Membre Expert

    Homme Profil pro
    Directeur de projet
    Inscrit en
    Mai 2013
    Messages
    1 581
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Directeur de projet
    Secteur : Service public

    Informations forums :
    Inscription : Mai 2013
    Messages : 1 581
    Par défaut
    Bonjour,

    Saif erreur de lecture de ma part, l'indice i de remplissage va de 1 à length mais un tableau de taille length va de 0 à length -1.

    Salutations

  3. #3
    Responsable Arduino et Systèmes Embarqués


    Avatar de f-leb
    Homme Profil pro
    Enseignant
    Inscrit en
    Janvier 2009
    Messages
    13 120
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Sarthe (Pays de la Loire)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Janvier 2009
    Messages : 13 120
    Billets dans le blog
    47
    Par défaut
    Bonsoir,

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Serial.println("Length= ", length);
    Je pense que ça passera avec :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    Serial.print("Length= ");
    Serial.println(length);
    Le second paramètre d'un Serial.print() est réservé au formatage :
    Syntax
    Serial.print(val),
    Serial.print(val, format).

  4. #4
    Membre confirmé
    Homme Profil pro
    Coach
    Inscrit en
    Novembre 2019
    Messages
    228
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Coach

    Informations forums :
    Inscription : Novembre 2019
    Messages : 228
    Par défaut
    Bon, je me fais vieux c'est indubitable....

    Désolé de vous avoir dérangé pour un truc aussi stupide ! Je le passe en résolu,

    Merci et bonne soirée

  5. #5
    Responsable Arduino et Systèmes Embarqués


    Avatar de f-leb
    Homme Profil pro
    Enseignant
    Inscrit en
    Janvier 2009
    Messages
    13 120
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Sarthe (Pays de la Loire)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Janvier 2009
    Messages : 13 120
    Billets dans le blog
    47
    Par défaut
    Hé ben on est au moins deux à être déjà tombé dans ce piège

    Sinon, tu peux faire avec sprintf() :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    char buffer[15];
     
    sprintf(buffer, "Length = %d", length);
    Serial.println(buffer);

  6. #6
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 881
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 881
    Par défaut
    et sur ESP vous pouvez utiliser sans vous ennuyer avec le buffer intermédiaire

  7. #7
    Membre confirmé
    Homme Profil pro
    Coach
    Inscrit en
    Novembre 2019
    Messages
    228
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Coach

    Informations forums :
    Inscription : Novembre 2019
    Messages : 228
    Par défaut
    waouh, bravo les amis, c'est puissant ce sprintf !!

    Pour ceux qui liraient ces lignes, il y a une explication complète sur son usage et les paramètres de la fonction sprintf ici: https://www.programmingelectronics.com/sprintf-arduino/

    Merci à vous

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [DB2 V7 & V8] equivalent du type SERIAL
    Par geoffrey_k dans le forum DB2
    Réponses: 3
    Dernier message: 05/07/2004, 14h09
  2. Update récalcitrant !
    Par Jeannotc dans le forum Bases de données
    Réponses: 10
    Dernier message: 16/06/2004, 18h28
  3. [JSP]include JSP via out.println ?
    Par MSP dans le forum Servlets/JSP
    Réponses: 2
    Dernier message: 13/05/2004, 08h07
  4. Un "0" récalcitrant
    Par bidson dans le forum XMLRAD
    Réponses: 4
    Dernier message: 20/04/2004, 13h56
  5. Problème de serialization
    Par bruno270579 dans le forum Entrée/Sortie
    Réponses: 3
    Dernier message: 30/04/2003, 18h11

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo