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 :

Lidar et Lidar TF 03


Sujet :

Arduino

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Expert confirmé

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

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 935
    Par défaut
    ah oui c'est louche alors

  2. #2
    Membre confirmé
    Homme Profil pro
    Directeur technique
    Inscrit en
    Janvier 2021
    Messages
    159
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Directeur technique

    Informations forums :
    Inscription : Janvier 2021
    Messages : 159
    Par défaut Jay M
    Bonjour Jay,

    bon capteur recu...
    alors ca ne tourne qu'avec l'arduino uno...
    broche 5 du capteur sur digital 2 de l'arduino
    je n'ai pas de beep au buzzer

    j'ai mesurer au metre les distances le capteur ne ce trompe pas....
    pour le Nano ...apparement il n'y aurait pas assez de memoire quand je televerse....

  3. #3
    Expert confirmé

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

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 935
    Par défaut
    Ok bonne nouvelle

    Pour le beep c’est normal car je ne fais qu’une impulsion. Faut remettre tone()

    Pour la nano, il doit y avoir autre chose, c’est exactement le même processeur et le sketch est minimal donc pas de souci à attendre.

    Pouvez vous poster le message d’erreur du compilateur (complet)

  4. #4
    Membre confirmé
    Homme Profil pro
    Directeur technique
    Inscrit en
    Janvier 2021
    Messages
    159
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Directeur technique

    Informations forums :
    Inscription : Janvier 2021
    Messages : 159
    Par défaut Jay M
    Nom : Capture arduino.PNG
Affichages : 146
Taille : 93,6 Ko

    voilà le message d'erreur avec l'arduino Nano

  5. #5
    Expert confirmé

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

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 935
    Par défaut
    le projet est fun - autant j'aime explorer et prototyper pour m'amuser autant j'ai passé l'age de gérer les soucis d'industrialisation (la partie chiante)
    Je pense que si vous voulez en faire un produit et le commercialiser / maintenir, il serait pas mal de trouver un freelance un peu costaud qui puisse s'impliquer à fond (et comme vous l'avez peut-être compris je n'ai pas besoin de rémunération supplémentaire)

    pour revenir au projet:

    - ce que vous appelez tilt, c'est une version avec le servo qui balaye une zone ?

    - un des soucis de la notification de beep distribuée c'est de choisir la bonne radio: le module HC12 utilise un port série mais votre XL-MaxSonar-WRC1 aussi si on veut une lecture précise. il n'y a qu'un seul port Série hardware sur les Nano. si on le prend pour la mesure de distance par exemple, ça veut dire qu'il faudra débrancher le module pendant le téléchargement de code (pénible mais jouable).

    - la consommation électrique des modules distants restera élevée (module radio + écran + audio + arduino). il faudra trouver un moyen de les allumer en même temps que le radar

    - Quand vous dites
    on garde les different paliers: beep a partir de 8 m, 6, 5, 4, 3 ,2 beep continue (chaque palier une fréquence de beep différentes)
    vous voulez dire que ta tonalité du son entendu est à des fréquences différentes suivant la distance (plus ou moins aigu) ou vous voulez dire (comme j'avais précédemment et comme c'est fait sur les voitures) que les beeps sont plus ou moins rapprochés suivant la distance restante?

  6. #6
    Expert confirmé

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

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 935
    Par défaut Usage d'un Servo
    Je n'ai pas mes Arduinos mais j'ai mes outils de bricolage
    J'ai fait un petit test avec un mètre laser avec point rouge (donc zone très précise): Même en étant incliné on arrive à avoir une lecture de distance cohérente - donc c'est peut-être jouable.

    Le code que vous postez fait un "sweep" (balayage) entre 0 et 180° puis dans l'autre sens.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
      for (pos = 0; pos <= 180; pos += 1) { // aller de 0 a 180 degrés
    ...
      for (pos = 180; pos >= 0; pos -= 1) { //
    donc il suffit régler le 0 et 180 dans les boucles et mettre autre chose si on veut se balader entre 2 valeurs.

    Pour chaque angle il lit une distance, effectue l'affichage puis fait un beep s'il le faut (L'auteur du code aurait pu faire une fonction de lecture et affichage de distance mais l'auteur à préféré dupliquer le code)

    Sur une Nano il se peut que la bibliothèque Servo soit en conflit avec la fonction tone() - faudra que je teste quand je peux.

    je vais voir si je peux vous taper un bout de code à tester

  7. #7
    Membre confirmé
    Homme Profil pro
    Directeur technique
    Inscrit en
    Janvier 2021
    Messages
    159
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Directeur technique

    Informations forums :
    Inscription : Janvier 2021
    Messages : 159
    Par défaut Jay M
    ahhhhh! ouf j'ai eu peur que vous me laissiez tomber....!

    j'ai synthétisé un peu notre discussion....

    il faut que le client éventuel parte dans l'idée que les infos données par le systeme ne sont QU INDICATIVE....

    il faudrait 2 code....
    un avec tilt et un sans tilt
    on garde les different paliers: beep a partir de 8 m, 6, 5, 4, 3 ,2 beep continue (chaque palier une frequence de beep differente)
    on redistribue l'infos beep pour un ou 2 endroit different (poste pilote )
    et puisqu'on est dans l'infos pour le pilote.... j'ai commandé des petit ecran "oled" pour arduino, je fait un adhesif transparent qui represente le cul du bateau en haut et en bas le quai, entre les 2 on affiche la distance....

    j'ai regardé les doc Maxsonar, il dise qu'on peux les utiliser en duo... est ce que ca apporterait un avantage...

    ah oui ...Bonne Vadrouille...

  8. #8
    Expert confirmé

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

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 935
    Par défaut
    OK, ça peut toujours servir même si avoir différents chipset série ça ne change pas grand chose.
    Le plus standard c'est le "FTDI Adaptateur Convertisseur FT232RL USB à TTL" qui supporte 3.3V ou 5V mais pas sur les pins Tx/Rx.

    Avec un composant 5V pas de souci, mais quand on travaille avec des puces 3.3V, c'est bien d'avoir un adaptateurs USB configurable en 3,3V, alimentation ET signaux. Gros plus s'il offre RTS ou CTS en plus de la sortie DRT. Et s'ils ont une sortie 3.3V boostée pour alimenter un module externe c'est Byzance

    --> ceux là sont bien (et pas cher)

    Si vous avez reçu vos HC12, essayez de tester en situation réelle le montage suivant:

    Branchements:

    HC12 <------> Nano
    Vcc <------> 5V
    GND <------> GND
    Rx <------> 2
    Tx <------> 3
    Set <------> 4

    On va utiliser la configuration d'usine, donc pas forcément la plus appropriée, mais ça permet de démarrer.

    Vous prenez 2 ordinateurs (idéalement portables), vous branchez sur le port USB la Nano et chargez le code suivant sur chacun des arduino:
    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
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    // Author: Jay M for Arduino forums. 
    // Standard MIT License applies. https://opensource.org/licenses/mit-license.php
     
    const uint8_t hc12RxPin  = 2;  // connnected to uno acting as Tx
    const uint8_t hc12TxPin  = 3;  // connnected to uno acting as Rx
    const uint8_t hc12SetPin = 4;  // used to go to AT mode if connected to GND (10kΩ internal pullup, could float)
    const long hc12Bbaud = 9600;   // default HC12 speed. OK with Software Serial.
     
    #include <SoftwareSerial.h>
    SoftwareSerial HC12(hc12TxPin, hc12RxPin);
     
    void setATCommandMode(bool activate)
    {
      digitalWrite(hc12SetPin, activate ? LOW : HIGH);
      delay(activate ? 40 : 80); // according to specifications (40ms to be active, 80ms to save changes upon exit)
    }
    const uint8_t messageMaxSize = 50;
    char serialMessage[messageMaxSize + 1] = {'\0'}; // +1 for trailing '\0'
    byte serialMessageIndex = 0;
     
    boolean gotSerialMessage(const char endMarker = '\n')
    {
      boolean messageReady = false;
     
      int r = Serial.read(); // -1 si erreur, sinon notre charactère
      if (r != -1) {
        if (r == endMarker) {
          serialMessageIndex = 0;
          messageReady = true;
        } else if (r != '\r') { // ignore CR
          serialMessage[serialMessageIndex++] = (char) r;
          serialMessage[serialMessageIndex] = '\0'; // maintain cString
          if (serialMessageIndex >= messageMaxSize) serialMessageIndex = messageMaxSize - 1; // don't overrflow
        }
      }
      return messageReady;
    }
     
    void setup() {
      pinMode(hc12SetPin, OUTPUT);
      Serial.begin(115200);
      HC12.begin(hc12Bbaud);
      setATCommandMode(false);
    }
     
    void loop() {
      if (gotSerialMessage()) HC12.println(serialMessage);
      while (HC12.available()) Serial.write(HC12.read());
    }
     
     
    /* DOCUMENTATION:
     
        The HC-12 module has four serial port transparent transmission modes, expressed as FU1, FU2, FU3, and FU4.
        In operation, these modes hide all the details of wireless communications from attached devices.
        The factory default working mode of the system is FU3 full-speed mode, and in this mode the baud rate in
        the air is automatically adjusted according to baud rate that the serial port has been set to.
        The usable communication distance will be the farthest at the lowest baud rate.
        Different modes can not transmit data to each other, and the user should select the optimal mode according
        to practical circumstances.
     
        The modules are usually operated in pairs, with data transmitted by means of a half-duplex link.
        For successful wireless transmission, the transparent transmission mode, serial port baud rate, and wireless
        communication channel of the two paired modules must be set the same.
        The factory default module setting are: FU3, 9,600bps (8N1: 8 data bits, no parity, 1 stop bit),
        CH001 (433.4MHz), 20dBm power (100mW).
        The number of bytes that can be continuously sent to the serial port of the module is unlimited in modes FU1 and FU3.
        However, considering ambient interference and other factors, if thousands of data bytes are sent continuously,
        some number of bytes may be lost. Therefore, the attached equipment at each end of the link should have some sort
        of response and resending mechanism to avoid information loss
     
        Serial port Baud rate: 1200 2400    4800 9600     19,200 38,400     57600 115200
        baud rate in the air:  5000         15000         58000             236000
        Wireless sensitivity:  -117dBm      -112dBm       -107dBm           -100dBm
        every -6dB ==> distance will be reduced by half
     
        AT COMMANDS:
        AT+Bxxxx    Change the serial port baud rate
        AT+Cxxx     Change wireless communication channel. xxx = 001 to 127. if > 100 distance cannot be guaranteed
                    channel 001 is at 433.4MHz then add 400KHz per additional channel number
        AT+FUx      Change the serial port transparent transmission mode FU1, FU2, FU3, and FU4
        AT+Px       Set the transmitting power of the module, with x selectable from 1 to 8 (default value is 8)
                    1         2         3         4         5         6         7         8
                    -1 dBm    2 dBm     5 dBm     8 dBm     11 dBm    14 dBm    17 dBm    20 dBm
                    0.8mW     1.6mW     3.2mW     6.3mW     12mW      25mW      50mW      100mW
     
        AT+Ry       Obtain parameter B, C, F, and P for baud rate, communication channel, F mode, and transmitting power
        AT+RX       Obtain all parameters from the module
        AT+Udps     Set data bits (d), parity (p=N,O,E), and stop bits (s=1,2,3)
        AT+V        Request firmware version information
        AT+SLEEP    enter sleep mode upon exiting from command mode, working current of about 22µA. Enter command mode to exit sleep.
        AT+DEFAULT  Module to factory default values
        AT+UPDATE   waiting for a software update. reboot to exit.
     
        more details at https://opencircuit.shop/resources/file/0f8d974f31fd813604c4d3fb0e9004ec3b483706466/HC-12-Datasheet.pdf
     
    */
    - Vous ouvrez la console série de l'IDE à 115200 bauds avec envoi de NL/CR (new line, carriage return) sur chacun des portables
    - vous tapez un petit texte genre "Hello World" dans la zone de saisie en haut de la console série et vous validez
    - Si tout va bien vous devriez voir le message s'afficher dans la console série de l'autre portable
    - essayez de vous éloigner de plus en plus pour voir la portée. ça ne marchera pas si vous êtes trop près (au moins 1 à 2m minimum entre les modules avec le niveau de puissance émise par défaut)

    la transmission dans l'air se fait à 15000 bauds. Si on envoie des modification de distance deux fois par seconde entre le capteur et le poste de pilotage avec un petit protocole sur moins d'une dizaine d'octets on n'abusera pas de la bande passante.

    Concernant la consommation, on peut envoyer une commande (AT+SLEEP) au module HC-12 et il se met en sommeil. Sa consommation tombe à 22µA.
    Donc dans un deuxième temps ce sera un truc à explorer en faisant aussi dormir l'Arduino et en le réveillant depuis votre télécommande sans fil qui doit consommer peu.

    A vous de jouer

  9. #9
    Membre confirmé
    Homme Profil pro
    Directeur technique
    Inscrit en
    Janvier 2021
    Messages
    159
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Directeur technique

    Informations forums :
    Inscription : Janvier 2021
    Messages : 159
    Par défaut Jay M
    Bonjour Jay,

    du fer a souder je suis passé a la meca et a la stratification pendant 2 jours...

    alors, j'ai trouvé des petits émetteur récepteur 433 qui pouraient faire l'affaire... (taux de transfert data 20Khz) pour du buzzer ca devrait etre bon...

    pour les distances du module GPS (on en a discuté avec pas mal de plaisancier) et il s'avere que 100m c'est un peu "Large" pour eux...
    le bon compromis serait Nos 20 M et ensuite 36M et 54M (puisque qu'on fonctionne de 6 en 6)
    avec les premières distance c'etait assez simple car par de GND: 20m; si GND sur pin 4: 50m et si GND sur pin 5:100m

    là c'est un peu plus "hard" car d’après mes calcul pour 36m il faut 2 pin a GND en même temps...

    je suis entrain de faire des essais avec le Lidar de chez Benawake, le TF mini Plus, a 120cm j'ai une fenetre de 10cm x 10cm...

  10. #10
    Expert confirmé

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

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 935
    Par défaut
    Je me doutais qu'il faut de temps en temps que vous lâchiez les trucs fun pour vous occuper du business

    Citation Envoyé par Stantedy Voir le message
    pour les distances du module GPS (on en a discuté avec pas mal de plaisancier) et il s'avere que 100m c'est un peu "Large" pour eux...
    On n'est pas contraint réellement par la formule tous les 6m, j'ai mis cela comme je peux mettre autre chose. Dans un des codes on fait
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    uint32_t maxDistance()
    {
      uint8_t dipSwitchByte = (digitalRead(pinDistance2) << 1) | digitalRead(pinDistance1);
      switch (dipSwitchByte) {
        case 0b10: return 50;   // 50m
        case 0b01: return 100;  // 100m
      }
      return 20;   // 20m
    }
    donc si le couple (pinDistance2, pinDistance1) vaut
    (GND, GND) ou (HIGH, HIGH): on retourne 20m
    (HIGH, GND) on retourne 50m
    (LOW, HIGH) on retourne 100m

    en conservant ce code, vous mettez les valeurs que vous voulez à la place de 20, 50 et 100, on pourrait même différencier les 2 premiers et retourner 2 valeurs différentes au lieu des 20m

    Donc, si vous me confirmez que vous êtes capable de piloter 2 entrées, soit HIGH, soit LOW, vous me donnez les valeurs en m que vous voulez voir affecter aux différentes configurations des pins (4 possibles) et on modifie le code pour cela

  11. #11
    Membre confirmé
    Homme Profil pro
    Directeur technique
    Inscrit en
    Janvier 2021
    Messages
    159
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Directeur technique

    Informations forums :
    Inscription : Janvier 2021
    Messages : 159
    Par défaut Jay M
    Bonjour Jay,

    arff oui, les client bateau ce reveille tout doucement... en espérant que ce soit pas comme la saison dernière ...

    j'ai recu: un afficheur LCD https://www.amazon.fr/gp/product/B07...?ie=UTF8&psc=1
    pour le radar c'est peux etre bien pour voir les distances peux etre meme pour le GPS (uniquement pour peaufiner le systeme )

    et j'ai recu ca aussi: https://www.amazon.fr/gp/product/B07...?ie=UTF8&psc=1

    ca j'en ai 200 : contrôleur USB CH340 Nano 3.0 ATmega328P Compatible pour Arduino Nano CH340C pilote USB Nano V3.0 ATmega328

    et les GPS 200 aussi...

    GPS:
    alors oui: pour la commutation électronique ca fonctionne Nickel (un simple quadruple interrupteur 4066) qui met a GND les pin a notre guise.

    les distances, on fait 20;30;et 50m

    PS: il faudra me communiquer votre adresse postal par mail .... contact@4g-boatprotect.com (pour cette aide precieuse que vous m'offrez...)

  12. #12
    Expert confirmé

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

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 935
    Par défaut
    Salut les 2 liens sont identiques - écran 16x02 en I2C, donc c'est simple à intégrer. Ce ne sont pas des foudres de guerre en terme de rapidité d'affichage mais largement suffisants. Je vous recommande cette bibliothèque LiquidCrystal_I2C (il y en a plusieurs différentes)

    Citation Envoyé par Stantedy Voir le message
    alors oui: pour la commutation électronique ca fonctionne Nickel (un simple quadruple interrupteur 4066) qui met a GND les pin a notre guise.
    les distances, on fait 20;30;et 50m
    OK - vous utilisez quelle version du code? pouvez vous la repartager? je peux ajouter le code pour 20/30/50 et faire une version LCD

    vous achetez par 200 pièces on dirait ! ça fait du stock dans les armoires


    PS/ pas la peine pour l'adresse - ça profite à toute la communauté.

  13. #13
    Membre confirmé
    Homme Profil pro
    Directeur technique
    Inscrit en
    Janvier 2021
    Messages
    159
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Directeur technique

    Informations forums :
    Inscription : Janvier 2021
    Messages : 159
    Par défaut Jay M
    bonjour Jay
    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
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    void setup() {
      // put your setup code here, to run once:
     
    }
     
    void loop() {
      // put your main code here, to run repeatedly:
     
    }// if you use an Arduino with only one Serial port, uncomment this line
    #define USE_SW_SERIAL
     
    #ifdef USE_SW_SERIAL
    #include <SoftwareSerial.h>
    const uint8_t RXPin = 2; // the arduino pin on which to receive serial data from your GPS
    const uint8_t TXPin = 3; // the arduino pin on which to transmit serial data to your GPS
    SoftwareSerial gpsSerial(RXPin, TXPin);
    #else
    #define gpsSerial Serial1   // otherwise define here which Hardware Serial Port to use
    #endif
     
    // define your GPS baud rate (9600 is the default for GPS Neo 7M)
    const uint32_t GPSBaud = 9600;
     
    // The pins setting the distance threshold
    const uint8_t pinDistance1 = 4;
    const uint8_t pinDistance2 = 5;
     
    // the pin triggering the alert. HIGH by default, turns LOW when distance is above threshold
    const uint8_t alertPin = 9;
     
    // the pin for the sound (a simple piezo) pin --- (piezo +) [piezo] (piezo -) ---- GND
    const uint8_t piezoPin = 10;
     
    // --------------------------------------------------------------
     
    #include <TinyGPS++.h>  // download from   <a href="https://github.com/mikalhart/TinyGPSPlus" target="_blank">https://github.com/mikalhart/TinyGPSPlus</a>
    TinyGPSPlus gps;
    double recordedLatitude;
    double recordedLongitude;
     
    double HaversineDistance(const double lat1, const double long1,  const double lat2, const double long2)
    {
      double latRad1 = radians(lat1);
      double latRad2 = radians(lat2);
      double lonRad1 = radians(long1);
      double lonRad2 = radians(long2);
     
      double half_diffLa = (latRad2 - latRad1) / 2.0;
      double s_half_diffLa = sin(half_diffLa);
     
      double half_doffLo = (lonRad2 - lonRad1) / 2.0;
      double s_half_doffLo = sin(half_doffLo);
     
      double computation = asin(sqrt(s_half_diffLa * s_half_diffLa + cos(latRad1) * cos(latRad2) * s_half_doffLo * s_half_doffLo));
      return 2.0 * 6372795.0 * computation;
    }
     
    bool feedGPS()
    {
      bool gotFix = false;
      while (gpsSerial.available() > 0)
        if (gps.encode(gpsSerial.read())) {
          gotFix = true;
          break;
        }
      return gotFix;
    }
     
    uint32_t maxDistance()
    {
      uint8_t dipSwitchByte = (digitalRead(pinDistance2) << 1) | digitalRead(pinDistance1);
      switch (dipSwitchByte) {
        case 0b10: return 50;   // 50m
        case 0b01: return 100;  // 100m
      }
      return 20;   // 20m
    }
     
    void checkPosition()
    {
      static bool firstFix = true;
      static bool alert = false;
     
      if (gps.location.isValid()) {
        Serial.print(F("Position: ")); Serial.print(gps.location.lat());
        Serial.write(','); Serial.println(gps.location.lng());
     
        if (firstFix) {
          recordedLatitude  = gps.location.lat();
          recordedLongitude = gps.location.lng();
          tone(piezoPin, 1000, 200);
          delay(210);
          tone(piezoPin, 1000, 200);
          firstFix = false;
          Serial.print(F("Recorded Position = "));
          Serial.print(recordedLatitude, 6); Serial.write(','); Serial.print(recordedLongitude, 6);
          Serial.print(F("\t(Alerte @"));
          Serial.print(maxDistance()); Serial.println(F(" m)"));
        } else {
          //  we already recorded our start position
          double distance = HaversineDistance(gps.location.lat(), gps.location.lng(), recordedLatitude, recordedLongitude);
          Serial.print(F("Distance from origin: ")); Serial.print(distance); Serial.print(F(" m\t(Alerte @"));
          Serial.print(maxDistance()); Serial.println(F(" m)"));
     
          if (distance >= maxDistance()) {
            if (!alert) {
              digitalWrite(alertPin, LOW);
              alert = true;
              tone(piezoPin, 300, 100);
              delay(120);
              tone(piezoPin, 100, 100);
              Serial.print(F("alert distance = ")); Serial.println(distance);
            }
          } else {
            if (alert) {
              digitalWrite(alertPin, HIGH);
              tone(piezoPin, 300, 100);
              delay(120);
              tone(piezoPin, 600, 100);
              Serial.print(F("Distance back in range : ")); Serial.println(distance);
            }
            alert = false;
          }
        }
      }
    }
     
    void setup() {
      pinMode(pinDistance1, INPUT_PULLUP);
      pinMode(pinDistance2, INPUT_PULLUP);
      pinMode(alertPin, OUTPUT);
      pinMode(piezoPin, OUTPUT);
      digitalWrite(alertPin, HIGH); // will go low in case of Alert
      Serial.begin(115200);
      gpsSerial.begin(GPSBaud);
      tone(piezoPin, 2000, 100);
    }
     
    void loop() {
      if (feedGPS()) checkPosition();
    }

  14. #14
    Expert confirmé

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

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 935
    Par défaut


    Bon c’est en forgeant qu’on devient forgeron

    Pour le buzzer essayez avec ça. C’est un copier coller du code précédent j’ai juste remis tone (non testé)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     tone(buzzPin, 1500, 50); //  beep a 1500 Hz pendant 50ms
    au lieu de l’impulsion de 30ms sur la pin

    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
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    #define USE_SW_SERIAL // comment this line out if you don't use Software Serial
     
    #ifdef USE_SW_SERIAL
    #include <SoftwareSerial.h>
    const uint8_t RXPin = 2; // the arduino pin on which to receive serial data from your XL-MaxSonar-WRC1
    const uint8_t TXPin = 3; // the arduino pin on which to transmit serial data to your XL-MaxSonar-WRC1 (unused, don't connect)
    SoftwareSerial maxSonar(RXPin, TXPin);
    #else
    #define maxSonar Serial // otherwise define here which Hardware Serial Port to use
    #endif
     
    // define your baud rate (9600 is the default for XL-MaxSonar-WRC1)
    const uint32_t sonarBaudRate = 9600;
     
    const byte buzzPin = 8;
    const unsigned int maxDistanceBeep = 600;  // in cm. Start beeping if distance less than 6 m
    const unsigned int minDistanceBeep =  40;  // in cm. continuous beep if distance less than 40 cm
    uint16_t distance = 2 * maxDistanceBeep;   // large value to avoid beeping at first
     
     
    // very crude XL-MaxSonar-WRC1 reading interface based on https://www.robotshop.com/media/files/PDF/datasheet-mb7060.pdf
    // Serial @ 9600 8N1 (0 - Vcc)
    // Frame format: Rxxxx<CR> where xxxx is the distance in cm, start marker is 'R', end marker is a carriage return (ASCII 13)
    enum : byte {STARTMARKER, PAYLOAD, ENDMARKER} parserState = STARTMARKER;
     
    bool acquisition() {
      static uint16_t payloadDistance;
      static uint8_t payloadByteCount;
      bool acquired = false;
     
      int rec = maxSonar.read();
      if (rec != -1) {
        uint16_t byteReceived = rec & 0xFF;
        switch (parserState) {
          case STARTMARKER:
            if (byteReceived == 'R') {
              payloadByteCount = 0;
              payloadDistance = 0;
              parserState = PAYLOAD;
            }
            break;
     
          case PAYLOAD:
            if ((byteReceived >= '0') && (byteReceived <= '9')) {
              payloadDistance = 10 * payloadDistance + (byteReceived - '0');
              if (++payloadByteCount >= 4) parserState = ENDMARKER;
            } else if (byteReceived == 'R') { // handle double 'R'
              payloadByteCount = 0;
              payloadDistance = 0;
            } else parserState = STARTMARKER;
            break;
     
          case ENDMARKER:
            if (byteReceived == '\r') {
              acquired = true;
              distance = payloadDistance;
              parserState = STARTMARKER;
            } else if (byteReceived == 'R') {
              payloadByteCount = 0;
              payloadDistance = 0;
              parserState = PAYLOAD;
            } else parserState = STARTMARKER;
            break;
        }
      }
      return acquired;
    }
     
    void printDistance() {
      Serial.print(F("Distance = "));
      Serial.print(distance);
      Serial.println(F(" cm"));
    }
     
    void audioFeedback(uint16_t dist) {
      static uint32_t lastTrigger;
     
      if (dist > maxDistanceBeep) digitalWrite(buzzPin, LOW); // pin LOW = pas de beep
      else if (dist < minDistanceBeep) digitalWrite(buzzPin, HIGH); // pin HIGH = beep continu
      else {
        if (millis() - lastTrigger >= dist) {
          tone(buzzPin, 1500, 50); //  beep a 1500 Hz pendant 50ms
          lastTrigger = millis();
        }
      }
    }
     
    void setup() {
      Serial.begin(115200);
      maxSonar.begin(sonarBaudRate);
      pinMode(buzzPin, OUTPUT);
      pinMode(LED_BUILTIN, OUTPUT);
    }
     
    void loop() {
      if (acquisition()) printDistance();
      audioFeedback(distance);
    }

  15. #15
    Expert confirmé

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

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 935
    Par défaut
    Vous avez bien changé le type de carte et le port série dans le menu?

  16. #16
    Membre confirmé
    Homme Profil pro
    Directeur technique
    Inscrit en
    Janvier 2021
    Messages
    159
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Directeur technique

    Informations forums :
    Inscription : Janvier 2021
    Messages : 159
    Par défaut Jay M
    .........! quel con! le port com.... !
    ca tourne !
    pour le buzzer je change quoi pour avoir le son... au moins j’apprends un peu...

  17. #17
    Expert confirmé

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

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 935
    Par défaut
    Salut

    Je rentre aujourd’hui et je repars prendre l’air (ca sent le confinement autant en profiter un peu avant !) la semaine prochaine - je vais essayer de regarder ce qui est faisable ce week end

  18. #18
    Expert confirmé

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

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 935
    Par défaut
    une bonne fée (modérateur ?) a mis en forme votre code on dirait

    voilà la version modifiée avec 20/30/50m et 1, 2 ou 3 beeps lors du franchissement de seuil. (ou vouliez vous entendre 1,2,3 beeps lors du choix d'un seuil?)
    J'ai pas testé donc je vous laisse essayer

    si vous voulez modifier les distances maintenant il y a un tableau qui les mémorise dans l'ordre
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    const uint16_t distanceThreshold[3] = {20, 30, 50}; // define the 3 thresholds in meters
    il suffit de changer les valeurs pour définir les 3 seuils.

    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
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    #define USE_SW_SERIAL
     
    #ifdef USE_SW_SERIAL
    #include <SoftwareSerial.h>
    const uint8_t RXPin = 2; // the arduino pin on which to receive serial data from your GPS
    const uint8_t TXPin = 3; // the arduino pin on which to transmit serial data to your GPS
    SoftwareSerial gpsSerial(RXPin, TXPin);
    #else
    #define gpsSerial Serial1 // otherwise define here which Hardware Serial Port to use
    #endif
     
    // define your GPS baud rate (9600 is the default for GPS Neo 7M)
    const uint32_t GPSBaud = 9600;
     
    // The pins setting the distance threshold
    const uint8_t pinDistance1 = 4;
    const uint8_t pinDistance2 = 5;
    const uint16_t distanceThreshold[3] = {20, 30, 50}; // define the 3 thresholds in meters
     
    // the pin triggering the alert. HIGH by default, turns LOW when distance is above threshold
    const uint8_t alertPin = 9;
     
    // the pin for the sound (a simple piezo) pin --- (piezo +) [piezo] (piezo -) ---- GND
    const uint8_t piezoPin = 10;
     
    // --------------------------------------------------------------
     
    #include <TinyGPS++.h> // download from https://github.com/mikalhart/TinyGPSPlus
    TinyGPSPlus gps;
    double recordedLatitude;
    double recordedLongitude;
     
    double HaversineDistance(const double lat1, const double long1, const double lat2, const double long2)
    {
      double latRad1 = radians(lat1);
      double latRad2 = radians(lat2);
      double lonRad1 = radians(long1);
      double lonRad2 = radians(long2);
     
      double half_diffLa = (latRad2 - latRad1) / 2.0;
      double s_half_diffLa = sin(half_diffLa);
     
      double half_doffLo = (lonRad2 - lonRad1) / 2.0;
      double s_half_doffLo = sin(half_doffLo);
     
      double computation = asin(sqrt(s_half_diffLa * s_half_diffLa + cos(latRad1) * cos(latRad2) * s_half_doffLo * s_half_doffLo));
      return 2.0 * 6372795.0 * computation;
    }
     
    bool feedGPS()
    {
      bool gotFix = false;
      while (gpsSerial.available() > 0)
        if (gps.encode(gpsSerial.read())) {
          gotFix = true;
          break;
        }
      return gotFix;
    }
     
    uint8_t maxDistanceIndex()
    {
      uint8_t dipSwitchByte = (digitalRead(pinDistance2) << 1) | digitalRead(pinDistance1);
      switch (dipSwitchByte) {
        case 0b10: return 1; // distanceThreshold[1] = 30m
        case 0b01: return 2; // distanceThreshold[2] = 50m
      }
      return 0; // distanceThreshold[0] = 20m
    }
     
    void checkPosition()
    {
      static bool firstFix = true;
      static bool alert = false;
     
      if (gps.location.isValid()) {
        Serial.print(F("Position: ")); Serial.print(gps.location.lat(),6);
        Serial.write(','); Serial.println(gps.location.lng(),6);
     
        uint8_t distanceIndex = maxDistanceIndex();
     
        if (firstFix) {
          recordedLatitude = gps.location.lat();
          recordedLongitude = gps.location.lng();
          tone(piezoPin, 1000, 200);
          delay(210);
          tone(piezoPin, 1000, 200);
          firstFix = false;
          Serial.print(F("Recorded Position = "));
          Serial.print(recordedLatitude, 6); Serial.write(','); Serial.print(recordedLongitude, 6);
          Serial.print(F("\t(Alerte @"));
          Serial.print(distanceThreshold[distanceIndex]); Serial.println(F(" m)"));
        } else {
          // we already recorded our start position
          double distance = HaversineDistance(gps.location.lat(), gps.location.lng(), recordedLatitude, recordedLongitude);
          Serial.print(F("Distance from origin: ")); Serial.print(distance); Serial.print(F(" m\t(Alert @"));
          Serial.print(distanceThreshold[distanceIndex]); Serial.println(F(" m)"));
     
     
          if (distance >= distanceThreshold[distanceIndex]) {
            if (!alert) {
              digitalWrite(alertPin, LOW);
              alert = true;
              for (uint8_t i = 0; i < distanceIndex + 1; i++) { // 1 beep for Threshold 0, 2 beeps for Threshold 1 and 3 beeps for Threshold 2
                tone(piezoPin, 300, 100);
                delay(120);
                tone(piezoPin, 100, 100);
                delay(120);
              }
              Serial.print(F("Distance alert = ")); Serial.println(distance);
            }
          } else {
            if (alert) {
              digitalWrite(alertPin, HIGH);
              tone(piezoPin, 300, 100);
              delay(120);
              tone(piezoPin, 600, 100);
              Serial.print(F("Distance back in range : ")); Serial.println(distance);
            }
            alert = false;
          }
        }
      }
    }
     
    void setup() {
      pinMode(pinDistance1, INPUT_PULLUP);
      pinMode(pinDistance2, INPUT_PULLUP);
      pinMode(alertPin, OUTPUT);
      pinMode(piezoPin, OUTPUT);
      digitalWrite(alertPin, HIGH); // will go low in case of Alert
      Serial.begin(115200);
      gpsSerial.begin(GPSBaud);
      tone(piezoPin, 2000, 100);
    }
     
    void loop() {
      if (feedGPS()) checkPosition();
    }
    Qu'est-ce que vous voulez voir sur l'écran LCD? Vous ne disposez que de 16 colonnes et 2 lignes, je pensais à un truc comme ça:
    Nom : ecran.png
Affichages : 142
Taille : 353,0 Ko

    voici la version associée (ce coup ci avec des beeps à chaque changement de seuil de distance: 1 beep = 20m, 2 beeps = 30m; 3 beeps = 50m)
    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
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    #include <LiquidCrystal_I2C.h>  // https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library
    // Set the LCD address to 0x27 for a 16 chars and 2 line display
     LiquidCrystal_I2C lcd(0x27, 16, 2);    // use LiquidCrystal_I2C lcd(0x3f, 20, 4); for a 20x4
     
    #define USE_SW_SERIAL
     
    #ifdef USE_SW_SERIAL
    #include <SoftwareSerial.h>
    const uint8_t RXPin = 2; // the arduino pin on which to receive serial data from your GPS
    const uint8_t TXPin = 3; // the arduino pin on which to transmit serial data to your GPS
    SoftwareSerial gpsSerial(RXPin, TXPin);
    #else
    #define gpsSerial Serial1 // otherwise define here which Hardware Serial Port to use
    #endif
     
    // define your GPS baud rate (9600 is the default for GPS Neo 7M)
    const uint32_t GPSBaud = 9600;
     
    // The pins setting the distance threshold
    const uint8_t pinDistance1 = 4;
    const uint8_t pinDistance2 = 5;
    const uint16_t distanceThreshold[3] = {20, 30, 50}; // define the 3 thresholds in meters
     
    // the pin triggering the alert. HIGH by default, turns LOW when distance is above threshold
    const uint8_t alertPin = 9;
     
    // the pin for the sound (a simple piezo) pin --- (piezo +) [piezo] (piezo -) ---- GND
    const uint8_t piezoPin = 10;
     
    // --------------------------------------------------------------
     
    #include <TinyGPS++.h> // download from https://github.com/mikalhart/TinyGPSPlus
    TinyGPSPlus gps;
    double recordedLatitude;
    double recordedLongitude;
     
    double HaversineDistance(const double lat1, const double long1, const double lat2, const double long2)
    {
      double latRad1 = radians(lat1);
      double latRad2 = radians(lat2);
      double lonRad1 = radians(long1);
      double lonRad2 = radians(long2);
     
      double half_diffLa = (latRad2 - latRad1) / 2.0;
      double s_half_diffLa = sin(half_diffLa);
     
      double half_doffLo = (lonRad2 - lonRad1) / 2.0;
      double s_half_doffLo = sin(half_doffLo);
     
      double computation = asin(sqrt(s_half_diffLa * s_half_diffLa + cos(latRad1) * cos(latRad2) * s_half_doffLo * s_half_doffLo));
      return 2.0 * 6372795.0 * computation;
    }
     
    bool feedGPS()
    {
      bool gotFix = false;
      while (gpsSerial.available() > 0)
        if (gps.encode(gpsSerial.read())) {
          gotFix = true;
          break;
        }
      return gotFix;
    }
     
    void updateLcdGPS()
    {
      static double previousLat = -1, previousLong = -1;
      double lcdLat = gps.location.lat();
      double lcdLong =  gps.location.lng();
      char tmpBuffer[16];
     
      Serial.print(F("Position: ")); Serial.print(lcdLat, 6);
      Serial.write(','); Serial.println(lcdLong, 6);
     
      if (lcdLat != previousLat) {
        dtostrf(lcdLat, 10, 6, tmpBuffer);
        lcd.setCursor(0, 0);
        lcd.print(tmpBuffer);
        previousLat = lcdLat;
      }
     
      if (lcdLong != previousLong) {
        dtostrf(lcdLong, 10, 6, tmpBuffer);
        lcd.setCursor(0, 1);
        lcd.print(tmpBuffer);
        previousLong = lcdLong;
      }
     
    }
     
    void updateLcdThreshold(uint16_t t)
    {
      static uint16_t previousThreshold = 1000;
      char tmpBuffer[16];
     
      if (t != previousThreshold) {
        dtostrf(t, 3, 0, tmpBuffer);
        lcd.setCursor(11, 0);
        lcd.print(F("S"));
        lcd.print(tmpBuffer);
        lcd.write('m');
        Serial.print(F("Alert @")); Serial.print(t); Serial.println(F(" m"));
        previousThreshold = t;
      }
    }
     
     
    void updateLcdDistance(double distance)
    {
      static uint16_t previousDistance = 10000;
      char tmpBuffer[16];
     
      if (((uint16_t) distance) != previousDistance) {
        Serial.print(F("Distance from origin: ")); Serial.println(distance);
     
        dtostrf(distance, 3, 0, tmpBuffer);
        lcd.setCursor(11, 1);
        lcd.print(F("D"));
        lcd.print(tmpBuffer);
        lcd.write('m');
        previousDistance = distance;
      }
    }
     
    uint8_t thresholdIndex()
    {
      uint8_t dipSwitchByte = (digitalRead(pinDistance2) << 1) | digitalRead(pinDistance1);
      switch (dipSwitchByte) {
        case 0b10: return 1; // distanceThreshold[1] = 30m
        case 0b01: return 2; // distanceThreshold[2] = 50m
      }
      return 0; // distanceThreshold[0] = 20m
    }
     
    void checkThreshold()
    {
      static uint8_t oldIndex = 255;
      uint8_t tidx = thresholdIndex();
      if (tidx != oldIndex) {
        updateLcdThreshold(distanceThreshold[tidx]);
        for (uint8_t i = 0; i < tidx + 1; i++) { // 1 beep for Threshold 0, 2 beeps for Threshold 1 and 3 beeps for Threshold 2
          tone(piezoPin, 2000, 100);
          delay(150);
        }
        oldIndex = tidx;
      }
    }
     
    void checkPosition()
    {
      static bool firstFix = true;
      static bool alert = false;
     
      if (gps.location.isValid()) {
     
        uint8_t tidx = thresholdIndex();
     
        if (firstFix) {
          recordedLatitude = gps.location.lat();
          recordedLongitude = gps.location.lng();
          Serial.print(F("Recorded "));
          updateLcdGPS();
          updateLcdDistance(0);
          tone(piezoPin, 1000, 200);
          delay(210);
          tone(piezoPin, 1000, 200);
          firstFix = false;
        } else {
          // we already recorded our start position
          double distance = HaversineDistance(gps.location.lat(), gps.location.lng(), recordedLatitude, recordedLongitude);
          updateLcdGPS();
          updateLcdDistance(distance);
     
          if (distance >= distanceThreshold[tidx]) {
            if (!alert) {
              digitalWrite(alertPin, LOW);
              alert = true;
              for (uint8_t i = 0; i < tidx + 1; i++) { // 1 beep for Threshold 0, 2 beeps for Threshold 1 and 3 beeps for Threshold 2
                tone(piezoPin, 300, 100);
                delay(150);
                tone(piezoPin, 100, 100);
                delay(150);
              }
              Serial.print(F("Distance alert = ")); Serial.println(distance);
            }
          } else {
            if (alert) {
              digitalWrite(alertPin, HIGH);
              tone(piezoPin, 300, 100);
              delay(120);
              tone(piezoPin, 600, 100);
              Serial.print(F("Distance back in range : ")); Serial.println(distance);
            }
            alert = false;
          }
        }
      }
    }
     
    void setup() {
      pinMode(pinDistance1, INPUT_PULLUP);
      pinMode(pinDistance2, INPUT_PULLUP);
      pinMode(alertPin, OUTPUT);
      pinMode(piezoPin, OUTPUT);
      digitalWrite(alertPin, HIGH); // will go low in case of Alert
      Serial.begin(115200);
      gpsSerial.begin(GPSBaud);
      lcd.begin();
      lcd.backlight();
      lcd.print(F(" GPS ALERT V2.0"));
      delay(1000);
      lcd.clear();
    }
     
    void loop() {
      checkThreshold();
      if (feedGPS()) checkPosition();
    }
    (il n'y a pas les ':' après S ou D dans l'affichage car ça ne tient pas tout sur 16 caractères sinon)

  19. #19
    Membre confirmé
    Homme Profil pro
    Directeur technique
    Inscrit en
    Janvier 2021
    Messages
    159
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Directeur technique

    Informations forums :
    Inscription : Janvier 2021
    Messages : 159
    Par défaut Jay M
    Bonjour Jay,

    super je vais essayer...

    au niveau de la connectique avec le nouveau code, on ne change rien? toujours pin 4 et 5 pour la sélection de distance?
    quand au LCD je le branche ou? et apres avoir fait mes test je peux le débrancher sans que l'arduino ne s'affole...?

    ps je vais peux être prévoir une antenne GPS déporté (car selon le bateau je vais peux etre de temps a autre avoir un problème d'acquisition ...)
    si vous connaissez une bonne antenne que je pourrais utiliser sans avoir a modifier le code....

  20. #20
    Expert confirmé

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

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 935
    Par défaut
    Citation Envoyé par Stantedy Voir le message
    au niveau de la connectique avec le nouveau code, on ne change rien? toujours pin 4 et 5 pour la sélection de distance?
    On touche rien en effet. J'ai conservé l'ancien câblage.

    Citation Envoyé par Stantedy Voir le message
    quand au LCD je le branche où ? et apres avoir fait mes test je peux le débrancher sans que l'arduino ne s'affole...?
    L'écran LCD s'alimente depuis la broche 5V et GND. Pour la partie contrôle, l'écran utilise la norme I2C. Au dos du shied vous devrez avoir deux broches marquées SCL et SDA. Sur un UNO ou NANO vous connectez SDA sur la broche A4 et SCL sur la broche A5. Sur un Arduino Mega ce serait les pins 20 (SDA) et 21 (SCL).

    Si l'écran n'est pas là ce n'est pas un souci pour le code, ça va balancer des ordres mais ça n'attend pas de réponses de l'écran donc ça fonctionnera. Après c'est toujours bien de débrancher de l'électronique avec l'alimentation coupée


    Citation Envoyé par Stantedy Voir le message
    ps je vais peux être prévoir une antenne GPS déporté (car selon le bateau je vais peut-être de temps à autre avoir un problème d'acquisition ...)
    si vous connaissez une bonne antenne que je pourrais utiliser sans avoir a modifier le code....
    J'ai déjà utilisé celle ci, il en existe aussi avec Base magnétique.
    Nom : antenne.png
Affichages : 265
Taille : 66,8 Ko
    comme son connecteur est une Prise SMA
    Nom : connecteur.png
Affichages : 243
Taille : 25,2 Ko
    il vous faudra un adaptateur SMA Femelle <---> prise IPX (on en trouve plein sur Amazon)
    Nom : adaptateur.png
Affichages : 264
Taille : 85,6 Ko

    Ça vient en remplacement de l'antenne céramique et permet donc de déporter l'antenne dans une zone plus "à l'air libre".

    Sinon vous trouvez des module NEO7M directement avec antenne céramique intégrée et prise SMA, ça fait une connexion plus solide (visée) directement sur la carte.

    PS/ On mélange les 2 sujets là. Cette discussion devrait plutôt avoir lieu dans le thread sur le NEO7M

Discussions similaires

  1. Réponses: 6
    Dernier message: 09/05/2024, 12h11
  2. Réponses: 3
    Dernier message: 22/05/2020, 20h30
  3. [Débutant] I2c - NI 8451 - Lidar Lite v3 - write to register
    Par RT team dans le forum MATLAB
    Réponses: 0
    Dernier message: 28/02/2018, 11h52

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