This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| en:iot-open:remotelab:sut:generalpurpose2:b6 [2020/04/28 19:20] – created pczekalski | en:iot-open:remotelab:sut:generalpurpose2:b6 [2020/07/20 12:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ==== B6: Presenting air pressure on the LCD ==== | ||
| + | In this scenario, you will present absolute air pressure reading, on the LCD screen. | ||
| + | === Target group === | ||
| + | Beginners | ||
| + | |||
| + | === Prerequisites === | ||
| + | You need to know, how to print and position text on the LCD display. | ||
| + | Use LCD I2C library to control it: | ||
| + | <code c> | ||
| + | #include < | ||
| + | </ | ||
| + | |||
| + | The air pressure sensor is Bosch BMP280 sensor, connected to the I2C bus, shared with LCD display. | ||
| + | To read data you may use a dedicated library (libraries): | ||
| + | |||
| + | <code c> | ||
| + | #include < | ||
| + | #include < | ||
| + | </ | ||
| + | === Scenario === | ||
| + | Once you initialise sensor and LCD display, read sensor data (air pressure) and then display them in the loop. Give each loop execution some 5-10s delay. | ||
| + | <note warning> | ||
| + | |||
| + | The first line of the LCD should display: "//Air pressure is://" | ||
| + | The second line should provide temperature within the "// | ||
| + | |||
| + | < | ||
| + | |||
| + | You will use '' | ||
| + | |||
| + | === Result === | ||
| + | You should be able to see air pressure readings on the LCD display using the video stream. Some fluctuations are natural.\\ | ||
| + | <note important> | ||
| + | |||
| + | === Start === | ||
| + | There are no special steps to be performed. | ||
| + | |||
| + | === Steps === | ||
| + | |||
| + | == Step 1 == | ||
| + | Include LCD and sensor driver libraries: | ||
| + | <code c> | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | </ | ||
| + | |||
| + | == Step 2 == | ||
| + | Instantiate software controler component for the LCD display: | ||
| + | <code c> | ||
| + | LiquidCrystal_I2C lcd(0x3F, | ||
| + | // | ||
| + | |||
| + | Adafruit_BMP280 bmp; | ||
| + | </ | ||
| + | |||
| + | == Step 3 == | ||
| + | Declare a buffer for '' | ||
| + | <code c> | ||
| + | char buffer [11]; | ||
| + | float pres; | ||
| + | </ | ||
| + | |||
| + | == Step 4 == | ||
| + | Initialize LCD and BMP sensors: | ||
| + | <code c> | ||
| + | ... | ||
| + | lcd.init(D2, | ||
| + | lcd.backlight(); | ||
| + | lcd.home(); | ||
| + | ... | ||
| + | if(!bmp.begin(0x76)) | ||
| + | { | ||
| + | lcd.print(" | ||
| + | delay(1000); | ||
| + | }; | ||
| + | lcd.home(); | ||
| + | bmp.setSampling(Adafruit_BMP280:: | ||
| + | Adafruit_BMP280:: | ||
| + | Adafruit_BMP280:: | ||
| + | Adafruit_BMP280:: | ||
| + | Adafruit_BMP280:: | ||
| + | ... | ||
| + | </ | ||
| + | The BMP sensor address is 0x76 and, if not initialised, | ||
| + | |||
| + | == Step 5 == | ||
| + | Read in the loop: | ||
| + | <code c> | ||
| + | ... | ||
| + | pres = bmp.readPressure()/ | ||
| + | ... | ||
| + | </ | ||
| + | '' | ||
| + | |||
| + | To convert float into the string with formatting use '' | ||
| + | <code c> | ||
| + | ... | ||
| + | sprintf(buffer," | ||
| + | ... | ||
| + | delay(5000); | ||
| + | ... | ||
| + | </ | ||
| + | <note tip>'' | ||
| + | '' | ||
| + | |||
| + | === Result validation === | ||
| + | Observe air pressure readings on the LCD. Note - small oscillations are natural - you can implement moving average (i.e. of 10 subsequent reads, FIFO model) to " | ||