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 :

UNO - Affichage avec SSD1306


Sujet :

Arduino

Mode arborescent

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    955
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 955
    Par défaut UNO - Affichage avec SSD1306
    Bonjour à tous

    Je sollicite votre aide pour le croquis suivant
    celui-ci a pour but de décoder puis d'afficher une température issue d'un capteur étanche de piscine (WT0122) à l'aide d'un arduino UNO et d'un afficheur SSD1306
    https://www.made-in-china.com/showro...r-WT0122-.html

    le croquis du récepteur :
    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
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    #define DEBUG
    #include <PubSubClient.h> 
    #include <SPI.h>
    #include <Wire.h>  // Only needed for Arduino 1.6.5 and earlier
    #include <Adafruit_GFX.h>
    #include <Adafruit_SSD1306.h>
     
    // Initialize the OLED display using Wire library
    #define SCREEN_WIDTH 128 // OLED display width, in pixels
    #define SCREEN_HEIGHT 64 // OLED display height, in pixel
    #define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
    #define SCREEN_ADDRESS 0x3C //
    Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
    
    #define ledPin 13  //Arduino: Onboard LED = digital pin 13 
    #define inputPin 3
    
    #define DATA_SIZE 120
    #define SEPARATOR_HIGH 9500 //Délai pour la partie haute du PREAMBLE en microsecondes
    #define SEPARATOR_LOW 4500 //Délai pour la partie basse du PREAMBLE en microsecondes
    #define NOISE_TRESHOLD 200 //Délai minimum d'une impulsion en microsecondes
    #define SEP_WAIT 11000
    
    unsigned long t1, t0;
    unsigned short durationH;
    unsigned short durationL;
    unsigned int pwL[DATA_SIZE];
    unsigned int pwH[DATA_SIZE];
    unsigned char resDec[DATA_SIZE/4];
    unsigned long lastReception = 0;
    
    //***********************************************************
    unsigned short CalculateLimits(unsigned short* zeroH, unsigned short* oneH)
    {
      unsigned short sampling[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
      unsigned short max = 0;
      unsigned short min = 0xFFFF;
      unsigned short retVal = 0;
      
      for(int i=0, j=0; (i < DATA_SIZE) && (j < 16); i++, j++)
      {
        if ((pwH[i] > NOISE_TRESHOLD) && (pwH[i] < SEPARATOR_HIGH))
          sampling[j] = pwH[i];
        else
          j=-1;
      }
    
      if (sampling[15] != 0)
      {
        for(int j=0; j < 16; j++)
        {
          if (max < sampling[j])
            max = sampling[j];
          if (min > sampling[j])
            min = sampling[j];
        }
        retVal = (min + max) / 2;
        *zeroH = min;
        *oneH = max;
        #ifdef DEBUG
            Serial.print("Zero High Pulse Width:");
            Serial.println(min);
            Serial.print("One High Pulse Width:");
            Serial.println(max);
        #endif
      }
      else
      {
        #ifdef DEBUG
          Serial.print("Incorrect data sequence. ");
        #endif
        retVal = 0;
      }
      if (max < min + (min / 10)) //Diff is lees than 10% betwen the two values
      {
        #ifdef DEBUG
          Serial.print("SHORT (");
          Serial.print(min);
          Serial.print(") and LONG (");
          Serial.print(max);
          Serial.println(") pulse cannot be distinguished.");
        #endif
        retVal = 0;
      }
      return retVal;
    }
    
    //************************************************
    void BCDDecode(unsigned short PW_limit)
    {
      int j = 0;
      unsigned char decVal = 0;
      int decIdx = 0;
      memset(resDec,0,sizeof(resDec));
       
      #ifdef DEBUG
        Serial.print("BCD: ");
      #endif
      for(int i=0; (i < DATA_SIZE) && (pwH[i] > NOISE_TRESHOLD); i++)
      {
        if ((pwH[i] > SEPARATOR_HIGH))
        {
          #ifdef DEBUG
            Serial.println("");
          #endif
          if (decIdx != 0)
          {
            #ifdef DEBUG
               Serial.print("0x"); 
               for (int k = 0; k <= decIdx; k++)
                 Serial.print(resDec[k],HEX);
               Serial.println("");
            #endif
            decIdx = 0;
          }
          #ifdef DEBUG
            Serial.print("h(");Serial.print(pwH[i]);Serial.print(")");
          #endif
          j = 0;
          decVal = 0;
        }
        else if (pwH[i] > PW_limit)
        {
          #ifdef DEBUG
            Serial.print(1);
          #endif
          j++;
          decVal = decVal * 2 + 1;
        }
        else if (pwH[i] > NOISE_TRESHOLD)
        {
          #ifdef DEBUG
            Serial.print(0);
          #endif
          j++;
          decVal = decVal * 2;
        }
        if (j%4 == 0)
        {
          #ifdef DEBUG
            Serial.print(" ");
          #endif
          if (j != 0)
          {
            resDec[decIdx] = decVal;
            decIdx++;
            decVal = 0;
          }
        }
      }
      #ifdef DEBUG
        Serial.println("");
      #endif
      if (decIdx != 0)
      {
         Serial.print("0x"); 
         for (int k = 0; k <= decIdx; k++)
           Serial.print(resDec[k],HEX);
         float tVal = (367 - (resDec[4] * 0x10 + resDec[5])) / 10.0;
         Serial.println();
         Serial.println(tVal);
    	  
         delay(1000); 
        
      }
    }
    
    //***************************************************************
    void ShowResults()
    {
      unsigned short zeroH = 0, oneH = 0;
      unsigned short PW_limit = CalculateLimits(&zeroH, &oneH);
      if (PW_limit && (zeroH > 650) && (zeroH < 900) && (oneH > 1800) && (oneH < 2500))
      {
        #ifdef DEBUG
          Serial.print("PW_limit:"); Serial.println(PW_limit);
        #endif
        BCDDecode(PW_limit);
      }
      Serial.println("-------------");
    }
    
    
    //******* SETUP ****************************** 
    void setup() {
      Serial.begin(115200);
      Serial.println("Start...");
      
      /*
      if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
        Serial.println(F("SSD1306 allocation failed"));
        for(;;); // Don't proceed, loop forever
      }
      */
      display.display();
      delay(2000); // Pause for 2 seconds
      // Clear the buffer
      display.clearDisplay();
    
      Serial.println();
      pinMode(inputPin, INPUT);
      delay(200);
    }
    
    //************** LOOP ***************************
    void loop()
    {
      bool headReceived = false;
      bool bStop = false;
      int i = 0;
      memset(pwH, 0, sizeof(pwL));
      memset(pwL, 0, sizeof(pwH));
      do
      {
        durationH = pulseIn(inputPin, HIGH);
        t1 = micros();
        durationL = t1 - t0 - durationH;
        t0 = t1;
        if (headReceived == true)
        {
          if (durationH > NOISE_TRESHOLD)
          {  // correct pulse saved
            pwL[i] = durationL;
            pwH[i] = durationH;
            i++;
          }
          else 
          { // incorrect pulse received
            bStop = true;
            i++;
          }
        }
            
        if ((durationH > SEPARATOR_HIGH) && (durationH < SEPARATOR_HIGH + 500) && (headReceived == false))
        { // header detected
          headReceived = true;
          pwL[i] = durationL;
          pwH[i] = durationH;
          i++;
     
        }
      }while((i < DATA_SIZE) && !bStop);
    
      if (i > 24) // more than 24 bit received
        ShowResults(); 
     
    }

    Le programme tel que créée , affiche la température issue du capteur sous cette forme (voir image)
    mais si je veux utiliser le SSD1306 pour un affichage local , le programme ne fonctionne plus
    il ne reconnait pas le SSD1306 et bloque ici

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
      if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
        Serial.println(F("SSD1306 allocation failed"));
        for(;;); // Don't proceed, loop forever
      }
    Je précise que préalablement j'ai testé à l'aide d'un exemple de la bibliothèque cet élément ( <Adafruit_SSD1306.h> )
    sans aucun problème avec le même câblage
    Images attachées Images attachées  

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

Discussions similaires

  1. problème d'affichage avec printf
    Par sorari dans le forum C++
    Réponses: 12
    Dernier message: 08/03/2005, 18h30
  2. Réponses: 6
    Dernier message: 19/10/2004, 13h46
  3. Resolution d'affichage avec x11
    Par cosmos38240 dans le forum Applications et environnements graphiques
    Réponses: 4
    Dernier message: 06/06/2004, 23h26
  4. Pb affichage avec un PaintBox (pour eviter scintillement)
    Par juan64 dans le forum C++Builder
    Réponses: 7
    Dernier message: 08/04/2004, 09h21
  5. Problème d'affichage avec trace
    Par WriteLN dans le forum Flash
    Réponses: 10
    Dernier message: 22/10/2003, 16h59

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