Skip to content
Est. 2021 · Boulder, CO

How to use a 1.54 inch 128x64 OLED with a pressure sensor?

aadmin Bloran
To interface a 1.54 inch 128x64 OLED display with a pressure sensor, you need to wire the sensor to a microcontroller—typically an Arduino or ESP32—and then use the OLED to visualize the pressure readings in real time. The display, which uses a 128x64 pixel matrix and communicates via SPI, offers a fast refresh rate of around 30-60 frames per second, making it ideal for showing live sensor data like pressure curves, bar graphs, or numeric values. The pressure sensor, such as the BMP280 or MPX5700, outputs analog voltage or I2C/SPI data, which the microcontroller reads and converts into pressure units (e.g., kPa or psi). For a practical setup, connect the OLED’s VCC to 3.3V or 5V (depending on the module), GND to ground, SCK to the microcontroller’s SPI clock pin (e.g., pin 13 on Arduino Uno), MOSI to pin 11, and CS to a digital pin like pin 10. The pressure sensor’s analog output goes to an analog input pin, such as A0. Use the Adafruit SSD1306 library for the 1.54 inch 128x64 oled display to initialize it with SPI.begin() and set the display dimensions. For the sensor, read the analog value with analogRead() and map it to pressure using the sensor’s datasheet—for example, the BMP280 has a range of 300-1100 hPa with a resolution of 0.01 hPa. Display the data by clearing the buffer, drawing text or shapes with display.setTextSize() and display.print(), then calling display.display(). This setup gives you a live pressure monitor with minimal latency, and you can adjust the refresh rate by adding a delay(100) in the loop.

Hardware Wiring and Compatibility

When connecting the 1.54 inch 128x64 OLED display to a pressure sensor, the wiring depends on the sensor type. For analog sensors like the MPX5700AP (0-700 kPa, output 0.2-4.7V), use a voltage divider if the microcontroller runs at 3.3V to avoid exceeding the analog input limit. The OLED’s SPI interface requires four pins: SCK, MOSI, CS, and DC (data/command). On an Arduino Uno, map SCK to pin 13, MOSI to pin 11, CS to pin 10, and DC to pin 9. The RESET pin can be tied to a digital pin or the Arduino’s reset line. For I2C-based pressure sensors like the BMP280 (3.3V logic, 1.8-3.6V supply), connect SDA to A4 and SCL to A5 on Uno, but keep the OLED on SPI to avoid bus conflicts. The BMP280 has a typical accuracy of ±1 hPa and a noise level of 0.02 hPa RMS, which the OLED can display as a 3-digit value with one decimal place. Use a 10 µF capacitor across the sensor’s VCC and GND to filter noise, especially if the power supply is shared with the OLED, which draws about 20 mA during operation. The OLED’s brightness can be adjusted via software with setContrast(), but keep it between 0x00 and 0xFF to prevent flicker at low values. For battery-powered projects, the OLED’s sleep mode reduces current to 0.1 mA, which you can trigger with display.ssd1306_command(SSD1306_DISPLAYOFF) between readings.

Software Implementation with Data Visualization

To display pressure data, use the Adafruit GFX library for shapes and text. Initialize the OLED with Adafruit_SSD1306 display(128, 64, &SPI, DC, CS, RST); and call display.begin(SSD1306_SWITCHCAPVCC, 0x3C) for I2C or skip the address for SPI. For the sensor, read the analog value and convert to voltage: float voltage = analogRead(sensorPin) * (5.0 / 1023.0); then apply the sensor’s transfer function. For the MPX5700, pressure (kPa) = (voltage - 0.2) * (700 / 4.5). For the BMP280, use the Adafruit_BMP280 library to get pressure in Pa: float pressure = bmp.readPressure() / 100.0F; to convert to hPa. The OLED can show a bar graph by drawing a rectangle with display.fillRect(0, 40, map(pressure, minPressure, maxPressure, 0, 128), 10, WHITE); where minPressure and maxPressure are set to 950 and 1050 hPa for atmospheric readings. For numeric display, use display.setCursor(0, 0); display.print(pressure, 1); display.println(" hPa");. The refresh rate should be limited to 10 Hz to avoid flicker, achievable with a delay(100) in the loop. For a rolling graph, store the last 128 readings in an array and draw lines between points with display.drawLine(i, 64 - prevReading, i+1, 64 - currentReading, WHITE);. This gives a 128-point history across the screen width, updating every 100 ms for a 12.8-second window. The OLED’s pixel response time is under 10 µs, so no ghosting occurs at this rate.

Calibration and Accuracy Considerations

Pressure sensors require calibration to offset manufacturing tolerances. For the BMP280, the factory calibration is stored in internal registers, but you can apply a two-point calibration at known pressures (e.g., 1013.25 hPa at sea level and 900 hPa at 1000 m altitude). Use the OLED to display raw and calibrated values side-by-side: display.print("Raw: "); display.print(rawPressure); display.print(" Cal: "); display.print(calibratedPressure);. For analog sensors, the ADC’s resolution (10-bit on Uno, 12-bit on ESP32) introduces quantization error. At 5V reference, the Uno’s step size is 4.88 mV, which for the MPX5700 translates to 0.76 kPa per step. You can improve this by using an external ADC like the ADS1115 (16-bit, 0.076 mV resolution) and display the data on the OLED with four decimal places. The OLED’s text size can be set to 1 (5x7 pixels) for small values or 2 (10x14 pixels) for readability. For a 128x64 display, size 1 fits 21 characters per line, and size 2 fits 10 characters. Use display.setTextSize(2) for the pressure value and display.setTextSize(1) for units. The display’s contrast can be adjusted with display.ssd1306_command(SSD1306_SETCONTRAST); display.ssd1306_command(0x80); to optimize visibility in different lighting. For outdoor use, the OLED’s brightness at 100% is about 100 cd/m², which is readable in direct sunlight if the contrast is set to 0xBF. The pressure sensor’s response time (typically 1 ms for BMP280) is faster than the OLED’s update rate, so no data loss occurs.

Power Management and Data Logging

In battery-powered systems, the OLED and pressure sensor can be duty-cycled to save power. The OLED consumes 20 mA when active, but you can put it in sleep mode with display.ssd1306_command(SSD1306_DISPLAYOFF); and wake it with display.ssd1306_command(SSD1306_DISPLAYON);. The BMP280’s standby current is 0.1 µA in sleep mode, and it can be set to measure at 1 Hz with a current of 2.7 µA. Use an ESP32’s deep sleep mode to wake every 10 seconds, read the sensor, update the OLED, then sleep again. The OLED’s initialization takes 100 ms, so the total active time per cycle is 200 ms, giving an average current of 0.4 mA (20 mA * 0.2 s / 10 s). For data logging, store pressure readings in the microcontroller’s EEPROM (e.g., 1024 bytes on Uno) or an SD card via SPI. The OLED can display the number of logged samples: display.print("Samples: "); display.print(sampleCount);. For a rolling log, use a circular buffer of 256 readings and draw a histogram on the OLED with display.drawFastVLine(x, 64 - height, height, WHITE); where height is scaled to the pressure range. The 1.54 inch 128x64 oled display’s 128 columns allow for 128 histogram bars, each representing one sample. If the sensor reads at 10 Hz, the histogram covers 12.8 seconds. For longer trends, compress the data by averaging every 10 readings into one bar, covering 128 seconds. The OLED’s SPI speed is up to 10 MHz, so data transfer from the microcontroller to the display takes 0.1 ms per frame, leaving plenty of time for sensor reads.

Multi-Sensor Integration and Advanced Features

You can combine the pressure sensor with a temperature sensor (e.g., the BMP280 includes temperature) and display both on the OLED. Use the top half for pressure and bottom half for temperature: display.setCursor(0, 0); display.print("P: "); display.print(pressure, 1); display.println(" hPa"); display.setCursor(0, 32); display.print("T: "); display.print(temperature, 1); display.println(" C");. The OLED’s 64 rows allow for two 32-pixel sections, each with size 1 text (8 rows per character) for 4 lines of text. For a weather station, use a barometric pressure trend indicator: draw an arrow pointing up if pressure rises >1 hPa in 3 hours, down if it falls, or horizontal if stable. Implement this by storing the last 1080 readings (3 hours at 10 Hz) in an array and comparing the average of the first 10 to the last 10. The OLED can display a small icon: display.fillTriangle(64, 10, 60, 20, 68, 20, WHITE); for up arrow. For altitude estimation, use the barometric formula: altitude (m) = 44330 * (1 - (pressure / 1013.25)^(1/5.255)). Display this on the OLED with display.print("Alt: "); display.print(altitude, 0); display.println(" m");. The accuracy is ±1 m at sea level, but degrades with temperature changes. The OLED’s 128x64 resolution can show a 10-character string for altitude with size 2 text, plus a small graph of altitude over time. For a pressure-based altimeter, use a moving average filter with 10 samples to smooth noisy readings: float sum = 0; for (int i = 0; i < 10; i++) sum += readings[i]; float avg = sum / 10.0;. The OLED updates every 100 ms, so the filter introduces a 1-second delay, which is acceptable for altitude changes. The 1.54 inch 128x64 oled display’s wide viewing angle (160 degrees) allows you to see the data from any angle, which is useful for handheld devices.

Common Pitfalls and Troubleshooting

One common issue is the OLED not initializing due to incorrect SPI pins. Verify that the CS and DC pins are not floating—use pull-up resistors (10 kΩ) to VCC if needed. The pressure sensor’s analog output may be noisy if the wiring is long; use shielded cables or a 100 nF capacitor between the sensor’s output and ground. On the software side, the OLED’s buffer may overflow if you update it too fast—always call display.clearDisplay() before drawing new data, and use display.display() only once per loop. For the BMP280, the I2C address is 0x76 or 0x77, and you can check it with an I2C scanner. If the OLED shows random pixels, reset it with display.ssd1306_command(SSD1306_DISPLAYON); after initialization. The pressure sensor’s datasheet specifies a maximum voltage of 3.6V for the BMP280, so never use 5V logic without a level shifter. The OLED’s SPI interface is 3.3V tolerant, but 5V logic can damage it—use a voltage divider on the MOSI line if the microcontroller runs at 5V. For the MPX5700, the output voltage is ratiometric to the supply, so use a stable 5V reference. The OLED’s contrast can be adjusted in software, but setting it too high (above 0xCF) may cause ghosting at high temperatures. The 1.54 inch 128x64 oled display’s lifetime is 50,000 hours at 25°C, but it drops to 10,000 hours at 80°C, so avoid placing it near heat sources. If the pressure sensor drifts over time, recalibrate it every 6 months by comparing it to a known reference and adjusting the offset in the code. The OLED’s SPI bus can be shared with other devices, but use separate CS pins to avoid conflicts. For a robust setup, use a 100 µF capacitor across the power supply to prevent voltage drops during OLED updates.

a
About the author
admin
Writing from the Boulder compounding lab. Reviewed by the Bloran clinical advisory board.
More from Bloran