logo elektroda
logo elektroda
X
logo elektroda

DIY barograph/barometer with BME280 and Arduino Nano - how to build cheaply and get up and running w

JanuszArtur 2940 10
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • I bought a barometer. The seller said there was a mistake, not 50pln but 500pln it was supposed to be. He refunded the money.

    I bought another one - broken, it's sitting under the kitchen table waiting for a return label.

    I bought a third one - a new USSR, but it didn't survive transport....
    So much for the basic question "why do this, isn't it easier to buy on the alegro?", or: "they are available online - why waste time?".

    I found the projects SECRET and closed on the electrode, so had to look elsewhere. It was supposed to be simple, easy, clear, not very expensive.

    I rummaged through my resources. I had a display (about 50pln), a Nano (about 12pln), and for 4pln I bought an I2C SPI BMP280 3.3V pressure transmitter.
    I used this development: Link but it proved problematic to use the AdaFruit BME280 product because of the price (over 70pln cheapest I could find).

    I have converted the code to the following, as the regular BME280 does not support all the commands as the AdaFruit does:
    
    #include <LiquidCrystal_I2C.h>
    #include <Wire.h>
    #include "GyverButton.h"
    #include <BME280I2C.h>                      
    #define BTN_PIN 3                            
    #define BASE_PERIOD 675000                   
    #define MIN_VAL 990                          
    #define MAX_VAL 1035                         
    LiquidCrystal_I2C lcd(0x27, 20, 4);          
    GButton butt1(BTN_PIN);
    BME280I2C bme;                               
    uint32_t tmr1, tmr2;                         
    uint32_t set_period = BASE_PERIOD;           
    int16_t plot_array[20];                      
    uint16_t base_array[128];                    
    int16_t value, delta;                        
    byte interval = 1 ;                          
    void setup() {
      read_all();
      attachInterrupt(1, isr, CHANGE);
      butt1.setDebounce(80);                     
      butt1.setTimeout(300);                     
      lcd.init();
      lcd.backlight();
      lcd.clear();
      Wire.begin();
      if (!bme.begin()) { // Initialization of the BME280 sensor
        lcd.setCursor(3, 1);
        lcd.print(F("NIE WIDZE CZUJKI"));
        lcd.setCursor(7, 2);
        lcd.print(F("BME280"));
        while (1);
      }
      if (!digitalRead(BTN_PIN)) {                         
        for (byte i = 0; i < 128; i++) base_array[i] = 0;  
        update_all();                                      
        lcd.setCursor(4, 1);                               
        lcd.print(F("KASUJ HISTORIE"));
        lcd.setCursor(8, 2);
        lcd.print(F("<OK>"));
      }
      while (!digitalRead(BTN_PIN));
      lcd.clear();
      initPlot();                                
      float pres, temp, hum;
      bme.read(pres, temp, hum);
      value = round(pres);                        
      base_array[0] = value;
      get_data();
    }
    void isr() {                                  
      butt1.tick();
    }
    void loop() {
      butt1.tick();                               
      if (butt1.isClick()) {                      
        interval *= 2;                            
        if (interval > 8) interval = 1;
        set_period = BASE_PERIOD * interval;      
        get_data();                               
      }
      if (millis() - tmr1 >= BASE_PERIOD) {       
        tmr1 = millis();                          
        for (int i = 126; i >= 0; i--) {          
          base_array[i + 1] = base_array[i];
        }
        float pres, temp, hum;
        bme.read(pres, temp, hum);
        value=round(pres);                                     
        base_array[0] = value;                                 
        update_all();                                          
      }
      if (millis() - tmr2 >= set_period) {                     
        tmr2 = millis();                                       
        get_data();
      }
    }
    void get_data() {                                           
      for (int i = 15; i >= 0; i--) {
        drawPlot(0, 3, 16, 4, MIN_VAL, MAX_VAL, (base_array[i * interval]));
      }
      delta = ((base_array[0]) - (base_array[15 * interval]));  
      screen_data(value, delta, (interval * 3));                
    }
    void screen_data(int value, int delta, byte interval) {    
      lcd.setCursor(16, 0);
      lcd.print(int(value));
      lcd.setCursor(17, 2);
      if (delta == value) delta = 0;
      if (delta > 0) {
        lcd.print("+");
      } else if (delta < 0) {
        lcd.print("-");
      } else if (delta == 0) {
        lcd.print(" ");
      }
      lcd.setCursor(18, 2);
      lcd.print(abs(delta));
      if (abs(delta) < 10) {
        lcd.setCursor(19, 2);
        lcd.print(" ");
      }
      lcd.setCursor(17, 1);
      lcd.print("hPa");
      lcd.setCursor(17, 3);
      lcd.print(interval);
      (interval < 10) ? lcd.print("h ") : lcd.print("h");
    }
    void initPlot() {
      byte row8[8] = {0b11111,  0b11111,  0b11111,  0b11111,  0b11111,  0b11111,  0b11111,  0b11111};
      byte row7[8] = {0b00000,  0b11111,  0b11111,  0b11111,  0b11111,  0b11111,  0b11111,  0b11111};
      byte row6[8] = {0b00000,  0b00000,  0b11111,  0b11111,  0b11111,  0b11111,  0b11111,  0b11111};
      byte row5[8] = {0b00000,  0b00000,  0b00000,  0b11111,  0b11111,  0b11111,  0b11111,  0b11111};
      byte row4[8] = {0b00000,  0b00000,  0b00000,  0b00000,  0b11111,  0b11111,  0b11111,  0b11111};
      byte row3[8] = {0b00000,  0b00000,  0b00000,  0b00000,  0b00000,  0b11111,  0b11111,  0b11111};
      byte row2[8] = {0b00000,  0b00000,  0b00000,  0b00000,  0b00000,  0b00000,  0b11111,  0b11111};
      byte row1[8] = {0b00000,  0b00000,  0b00000,  0b00000,  0b00000,  0b00000,  0b00000,  0b11111};
      lcd.createChar(0, row8);
      lcd.createChar(1, row1);
      lcd.createChar(2, row2);
      lcd.createChar(3, row3);
      lcd.createChar(4, row4);
      lcd.createChar(5, row5);
      lcd.createChar(6, row6);
      lcd.createChar(7, row7);
    }
    void drawPlot(byte pos, byte row, byte width, byte height, int min_val, int max_val, int fill_val) {
      for (byte i = 0; i < width; i++) {
        plot_array[i] = plot_array[i + 1];
      }
      fill_val = constrain(fill_val, min_val, max_val);
      plot_array[width - 1] = fill_val;
      for (byte i = 0; i < width; i++) {
        int infill, fract;
        infill = floor((float)(plot_array[i] - min_val) / (max_val - min_val) * height * 10);
        fract = (infill % 10) * 8 / 10;
        infill = infill / 10;
        for (byte n = 0; n < height; n++) {
          if (n < infill && infill > 0) {
            lcd.setCursor(i, (row - n));
            lcd.write(0);
          }
          if (n >= infill) {
            lcd.setCursor(i, (row - n));
            if (fract > 0) lcd.write(fract);
            else lcd.write(16);
            for (byte k = n + 1; k < height; k++) {
              lcd.setCursor(i, (row - k));
              lcd.write(16);
            }
            break;
          }
        }
      }
    }
    void update_all() {
      eeprom_update_block((void*)&base_array, 0, sizeof(base_array));
    }
    void read_all() {
      eeprom_read_block((void*)&base_array, 0, sizeof(base_array));
    }
    
    .

    I connected a 5kOhm potentiometer to the I2C converter jumper so that I could 'adjust the brightness' of the display.
    Power supply with samsung cable - I cut off the broken USB-C end.
    A bend from a broken power supply.
    3D printing I made ABS. SolidWorks, STEP, STL files - attached.
    Works cool. Recommended.
    It looks like this:

    Black barometer in a rectangular casing with an LCD display, set on a red background. .

    Black electronic DIY project with a cable on a red background. .

    DIY digital barometer with LCD display in a black casing. .

    LCD screen showing pressure readings and bar graph .

    LCD display showing barometer data. .

    LCD display with pressure graph and data .

    3D render of a housing with three separate components, part of an electronic project. .

    3D case design for a barometer created in CAD software. .

    LCD display layout with dimension details. .

    IF YOU WOULD LIKE, please suggest changing the code as described below.

    TO:
    - The dream would be that the graph would be scaled for each interval (3, 6, 12, 24h) and start with the minimum measured pressure value as the minimum of the Y axis and end with the maximum measured pressure value and this would be the MAX of the Y axis.

    Of course, this is a redesign. Not my design. The author is Mirko Pavleski. I only adapted to the poor-elements.

    Cool? Ranking DIY
    Do you have a problem with Arduino? Ask question. Visit our forum Arduino.
    About Author
    JanuszArtur
    Level 14  
    Offline 
    JanuszArtur wrote 301 posts with rating 93. Live in city Warszawa. Been with us since 2007 year.
  • ADVERTISEMENT
  • #2 21422190
    Jawi_P
    Level 36  
    JanuszArtur wrote:
    I bought a barometer. The seller said there was a mistake, it was not 50pln but 500pln. He refunded the money.

    I bought another one - broken, it's sitting under the kitchen table waiting for a return label.

    Bought a third - new USSR, but it didn't survive transport...
    .
    I don't think I understand you quite well, but for a foreigner you handle Polish quite well. A little more and you'll be ok.
    As for "hardware" - you could also think about some ESP32, already with a built-in display. OLED/TFTs look much better than the clunky ones on HD44780. And they have very narrow bezels.
  • ADVERTISEMENT
  • #3 21422360
    efi222
    Level 19  
    For such small changes in the graph, you could try displaying it on an automatic scale. This looks more dynamic (pictorial).
  • ADVERTISEMENT
  • #4 21422553
    JanuszArtur
    Level 14  
    Jawi_P wrote:
    What about "hardware" - you could also think about some ESP32, already with built-in display. OLED/TFT
    .
    Super. Please quote me an ESP32 with already built-in display of the same - or larger size, at a similar price. I would be happy to buy a 4x20 OLED for 50pln in the BIG version. Will you provide a link or are you just writing what to write?
    Once again:
    - simple = uncomplicated
    - easy to install
    - clear = you can see from a few metres the trend of changes
    - low cost = max 150pln total

    Regards!

    Added after 2 [minutes]:

    efi222 wrote:
    For such small changes in the graph, you could try displaying it on an auto scale. This looks more dynamic (pictorial).



    yes, will you write a modification? :) So long as it's in 'open code', no hex or other secrets.
  • #5 21422660
    efi222
    Level 19  
    JanuszArtur wrote:
    yes, you will write a modification?
    .
    You've written that you've rewritten a ready-made one, so keep trying to make modifications yourself.
    JanuszArtur wrote:
    the dream would be....
    .
    You can dream on, or take matters into your own hands :) .
    I am an amateur with no connection to programming or electronics and I know full well that sometimes it is hard. But you have to try to achieve your goal. :)
  • ADVERTISEMENT
  • #6 21425096
    Anonymous
    Level 1  
  • #7 21441489
    vodiczka
    Level 43  
    JanuszArtur wrote:
    I purchased a barometer. The seller said there was a mistake, not 50pln but 500pln it was supposed to be. He returned the cash.
    .
    That what?
  • #8 21441698
    efi222
    Level 19  
    My understanding is this:
    The author of the topic found the barometer in an online shop for 50pln and ordered it. The seller realised that the price displayed was wrong and that the barometer actually costs 500pln. For the author, the amount was too high and he cancelled the purchase. The seller refunded 50pln.
    But maybe I am wrong :) .
    I had a similar case once....
  • #9 21441727
    vodiczka
    Level 43  
    This may have been the case, but juxtaposed with the next two cases, it looks like an invention of the author rather than actual problems related to the purchase of three barometers consecutively. In addition, he wrote
    JanuszArtur wrote:
    On the electrode I found SECRET and closed projects, so had to look elsewhere.
    .
    He built it, it works, ''honour and glory to him'', confabulation unnecessary.
  • #10 21443202
    JanuszArtur
    Level 14  
    vodiczka wrote:
    JanuszArtur wrote:
    I purchased a barometer. The seller stated that there was a mistake, not 50pln but 500pln it was supposed to be. He refunded the cash.
    .
    That what?
    .
    I stated at the beginning the reason why I got pissed....m and instead of buying more junk, I looked and did. One of the barometers purchased is lying under the table still waiting for a return label. The prints dotted around - it indicates something.

    Usually when someone looks on the electrode, the first response is 'why make one, isn't it better to buy one? so I described the need to build one at the beginning, because it was impossible to buy one....
  • #11 21443363
    efi222
    Level 19  
    JanuszArtur wrote:
    the first responses are of the type: 'why make one, isn't it better to buy one
    .
    Maybe not the first, but it's a fact. Consumer visits to this section are not that uncommon at all. I understand the comparison of the presented design with factory equipment. I just don't know what the proposal to buy the device instead of constructing it myself is supposed to serve. And here we have a peculiar paradox, where the author in the DIY section explains in the introduction why he built the device and not bought a ready-made one....

Topic summary

The discussion revolves around the challenges faced by a user in purchasing barometers, leading to the decision to build a DIY barograph/barometer using an Arduino Nano and a BMP280 pressure sensor. The user initially encountered issues with purchased barometers, including incorrect pricing and damage during transport. They sought a cost-effective and straightforward solution, ultimately utilizing existing components: a display, an Arduino Nano, and a BMP280 sensor. Participants in the forum suggested alternatives like the ESP32 with built-in displays and discussed the merits of DIY projects versus purchasing ready-made devices. The conversation emphasized the importance of simplicity, clarity, and low cost in the design of the barometer.
Summary generated by the language model.
ADVERTISEMENT