Skip to content
Field Notes

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

By adminMostick Editorial

How to Use a 1.54 Inch 128x64 OLED with a Color Sensor

To get a 1.54 inch 128x64 oled display working with a color sensor, you need to wire them to a microcontroller like an Arduino or ESP32, then write code that reads the sensor’s RGB data and renders it on the OLED as a color patch or text. The key is matching the sensor’s output (usually I2C or analog) with the OLED’s SPI or I2C interface. For example, a TCS34725 color sensor outputs 16-bit red, green, blue, and clear values via I2C, while the 1.54-inch OLED with 128x64 pixels uses SPI for fast updates. You’ll connect the sensor’s SDA and SCL to the Arduino’s I2C pins (A4 and A5 on Uno), and the OLED’s CS, DC, MOSI, SCK, and RST to digital pins. Power both with 3.3V or 5V, depending on your module. The OLED’s SSD1309 or SH1106 driver needs a library like Adafruit_SSD1306 or u8g2, while the sensor uses Adafruit_TCS34725. In your setup, initialize the OLED with 128x64 resolution, set the sensor’s integration time to 50ms for moderate accuracy, and in the loop, read the sensor’s RGB values, convert them to 8-bit (0-255) by dividing the 16-bit data by 256, then display a filled rectangle on the OLED with those RGB values. For instance, if the sensor reads red=1200, green=800, blue=600, the OLED shows a rectangle with RGB(4,3,2) after scaling. You can also overlay the raw numbers as text. The OLED’s SPI speed can be set to 8 MHz for smooth updates, and the sensor’s I2C clock to 100 kHz. This setup works for color matching, object sorting, or ambient light analysis. The 1.54 inch 128x64 oled display has a 0.91-inch active area, 0.96mm pixel pitch, and 10000:1 contrast ratio, making it ideal for real-time color visualization. On the hardware side, use a 10kΩ pull-up resistor on the sensor’s I2C lines if your module lacks them, and add a 100µF capacitor across the OLED’s power pins to filter noise. The OLED draws about 20mA when displaying a white screen, while the sensor uses 2.5mA. For a portable project, a 3.7V LiPo battery with a 3.3V regulator works, but ensure the OLED’s logic voltage matches the sensor’s—most 1.54-inch OLEDs accept 3.3V to 5V, while the TCS34725 runs at 3.3V. If you use an ESP32, the OLED’s SPI pins can be mapped to GPIO 18 (SCK), 23 (MOSI), 5 (CS), 17 (DC), and 16 (RST), and the sensor’s I2C to GPIO 21 (SDA) and 22 (SCL). This gives you Wi-Fi for remote color monitoring, like sending the RGB data to a smartphone app. The OLED’s refresh rate is around 30 frames per second with SPI, so you can update the color display every 33ms, but the sensor’s conversion time (50ms for high resolution) limits the loop to 20Hz. For faster response, set the sensor’s integration time to 2.4ms, but then the color accuracy drops to 8-bit resolution. You can also calibrate the sensor by reading a white reference (e.g., a white card) and adjusting the RGB gain in software. The OLED’s 128x64 pixels give you 8192 pixels, enough to show a 64x64 color square with 64x64 resolution, or a 32x32 square with text labels. For a color picker application, read the sensor’s data, map it to the OLED’s gamma-corrected brightness (e.g., use a lookup table for non-linear LED response), and display the color as a filled circle. The sensor’s clear channel helps with ambient light compensation—subtract the clear value from the RGB to get true color. In practice, if you place the sensor against a red object, the OLED shows a red patch with R=255, G=0, B=0, but the actual values might be R=200, G=30, B=20 due to sensor noise. You can smooth this with a moving average filter over 5 samples. The OLED’s SPI interface uses 4-wire mode (CS, DC, MOSI, SCK) plus RST, and you can daisy-chain multiple devices if you use separate CS lines. The sensor’s I2C address is 0x29 by default, but you can change it to 0x28 by grounding the ADDR pin. For a dual-sensor setup, use two TCS34725 modules with different addresses, and switch between them in code. The OLED’s contrast register (0x81) can be set from 0 to 255, but for color display, keep it at 128 to avoid washout. The sensor’s gain can be set to 1x, 4x, 16x, or 60x; for indoor lighting, 4x works well, while for sunlight, use 1x. The OLED’s power consumption is 0.08W at 5V, and the sensor adds 0.0125W, so a 2000mAh battery lasts about 20 hours. For a weather station, combine the color sensor with a temperature sensor (like DHT22) and display both on the OLED—show the temperature as a number and the color as a background gradient. The OLED’s 128x64 resolution means you can fit 4 lines of 16-pixel text (using a 8x8 font) or 2 lines of 32-pixel text. For a color histogram, read the sensor every 100ms, store the RGB values in an array, and plot them as a bar chart on the OLED. The OLED’s SSD1309 driver supports page addressing mode, which is faster for partial updates. You can also use the OLED’s hardware scrolling for a moving color wave. The sensor’s IR filter (in the TCS34725) blocks infrared light, so it works well under fluorescent or LED lighting. For a calibration routine, place the sensor on a known color (e.g., a Pantone card) and store the RGB values in EEPROM. Then, in the field, the OLED shows the matched color name. The OLED’s viewing angle is 160 degrees, so you can see the color from the side. The sensor’s field of view is about 60 degrees, so hold it 1-2 cm from the object. For a robot arm, mount the sensor on the gripper and the OLED on the base, and use I2C over a long cable (up to 1 meter with shielded wire). The OLED’s SPI can handle up to 10 MHz, but for long wires, drop to 1 MHz to avoid signal loss. The sensor’s I2C bus can be extended with a PCA9548A multiplexer if you have multiple sensors. The OLED’s 1.54-inch size is 36.5mm x 27.5mm, with a 0.96mm pixel pitch, so each color square is about 0.96mm wide. For a high-density display, use the OLED’s 128x64 pixels to show a 16x16 grid of 8x8 pixel color squares, each representing a different sensor reading. The sensor’s RGB data is 16-bit, but you can downsample to 12-bit for faster display. The OLED’s SSD1309 driver has a built-in charge pump for 3.3V operation, so you don’t need an external boost converter. For a color sorter, read the sensor, compare the RGB values to a threshold (e.g., if R>200 and G<100, it’s red), and display the result on the OLED with a text message like “Red object detected”. The OLED’s response time is 10ms, so it updates instantly. The sensor’s conversion time is 50ms, so the loop runs at 20Hz. For a faster loop, use the sensor’s interrupt pin to trigger a read when data is ready. The OLED’s SPI uses 4 pins, so you can use a 5-pin header (including VCC and GND). The sensor’s I2C uses 2 pins, so you can share the bus with other devices. For a multi-sensor array, use an I2C multiplexer like TCA9548A to read 8 sensors, and display the average color on the OLED. The OLED’s 128x64 resolution can show a 8x8 grid of 16x16 pixel color squares, each representing a sensor. The sensor’s gain and integration time affect the color accuracy; for critical applications, use a white balance calibration with a reference white point. The OLED’s contrast can be adjusted per pixel, but for uniform color, use a constant contrast. The sensor’s clear channel helps with ambient light; divide the RGB by the clear value to get normalized colors. In a dark room, the clear value is low, so the colors are saturated. The OLED’s 1.54-inch size is small enough for a handheld device, but large enough to read text. The sensor’s TCS34725 has a 3.8mm x 2.2mm die, so it fits in a small package. For a wearable, use a 128x64 OLED with a flexible PCB and a color sensor on a wristband. The OLED’s SPI can be driven by a 3.3V microcontroller like the Teensy 4.0, which has 600 MHz clock speed, for 60 fps updates. The sensor’s I2C can be clocked at 400 kHz for fast reads. The OLED’s pixel colors are monochrome (white, blue, or yellow), so you can only show grayscale colors, not true RGB. But you can simulate colors by using dithering patterns—for example, a 2x2 checkerboard for 50% gray, or a 4x4 pattern for 256 shades. The sensor’s RGB data maps to grayscale by weighting: Gray = 0.299*R + 0.587*G + 0.114*B. Then, display this as a grayscale bar on the OLED. For a color sensor, the OLED’s monochrome nature limits the display, but you can show the RGB values as numbers, or use a color wheel with text labels. The OLED’s 128x64 pixels can show a 64x64 pixel image of the object’s color map, but it’s grayscale. For a more colorful display, use a 1.54-inch OLED with RGB pixels (like a 128x64 RGB OLED), but those are rare and expensive. The standard 1.54-inch OLED is monochrome, so focus on data visualization. The sensor’s I2C address can be scanned with a scanner sketch. The OLED’s SPI can be initialized with the Adafruit_SSD1306 library, which sets the display size to 128x64. The sensor’s library reads the RGB data as 16-bit integers. In the loop, you can print the values to the serial monitor for debugging. The OLED’s drawPixel function updates one pixel at a time, but for a rectangle, use fillRect. The sensor’s getRGB function returns the raw data. For a color picker, map the sensor’s RGB to the OLED’s grayscale by using a formula like Gray = (R+G+B)/3. Then, display a square with that gray level. The OLED’s brightness can be set with the setContrast function. The sensor’s integration time can be set to 2.4ms, 24ms, 50ms, 101ms, 154ms, or 700ms. For a fast response, use 2.4ms, but the data is noisy. For a stable reading, use 50ms. The OLED’s refresh rate is 30 fps, so a 50ms sensor read gives 20 fps. You can also use the sensor’s interrupt pin to trigger a read. The OLED’s SPI uses 4-wire mode, but you can also use 3-wire mode if you combine MOSI and MISO. The sensor’s I2C uses 2 wires. For a long-distance setup, use I2C with a differential driver like PCA9615. The OLED’s 1.54-inch size has a 0.96mm pixel pitch, so each pixel is 0.96mm wide. The sensor’s TCS34725 has a 3.8mm x 2.2mm active area. For a precise color measurement, place the sensor 1mm from the object. The OLED’s display area is 36.5mm x 27.5mm, so you can fit a 32x32 pixel color square with 0.96mm resolution. The sensor’s color data is in the CIE 1931 color space, but you can convert to sRGB for display. The OLED’s grayscale is linear, so you need to gamma-correct the sensor data. The sensor’s gain can be set to 1x, 4x, 16x, or 60x. For a bright object, use 1x; for a dark object, use 60x. The OLED’s contrast can be set from 0 to 255. For a color display, use a contrast of 128. The sensor’s clear channel can be used for automatic gain control. The OLED’s power consumption is 20mA, so a 500mAh battery lasts 25 hours. The sensor’s power consumption is 2.5mA, so it adds 0.125 hours. For a battery-powered project, use a deep sleep mode for the microcontroller. The OLED’s SPI can be put to sleep with a display off command. The sensor’s I2C can be powered down with a GPIO pin. For a color sensor, the OLED’s monochrome display is a limitation, but you can use it to show the color name, like “Red”, “Green”, “Blue”, or “Yellow”. The sensor’s RGB values can be mapped to color names using a lookup table. For example, if R>200 and G<100 and B<100, it’s red. The OLED’s 128x64 pixels can show 4 lines of 16-pixel text. For a color name, use a large font. The sensor’s data can be logged to an SD card via SPI. The OLED’s SPI can be shared with the SD card if you use separate CS pins. For a data logger, read the sensor every second, display the color on the OLED, and save the RGB values to a file. The OLED’s 1.54-inch size is small, but it’s readable. The sensor’s TCS34725 has a 2.5V to 3.6V supply voltage, so use a 3.3V regulator. The OLED’s SSD1309 has a 3.3V to 5V supply voltage. For a 5V Arduino, use a level shifter for the SPI lines. The sensor’s I2C lines are 3.3V, so use a level shifter if the Arduino is 5V. The OLED’s SPI can be level-shifted with a 74LVC245. For a simple project, use a 3.3V Arduino like the Pro Mini. The OLED’s 1.54-inch size has a 0.91-inch active area, so it’s small. The sensor’s TCS34725 has a 2.5mm x 2.5mm package. For a compact design, use a PCB with both components. The OLED’s SPI pins are 0.1-inch pitch, so use a breadboard. The sensor’s I2C pins are also 0.1-inch pitch. For a permanent project, solder the wires. The OLED’s 128x64 resolution is 8192 pixels, so you can display a 64x64 pixel image of the object’s color. The sensor’s RGB data is 16-bit, so you can display it as a 16-bit grayscale image. The OLED’s grayscale is 8-bit, so you need to downsample. The sensor’s clear channel can be used for exposure control. The OLED’s contrast can be set to match the sensor’s gain. For a color sensor, the OLED’s monochrome display is a challenge, but you can use it to show the color as a pattern. The sensor’s RGB data can be used to control an RGB LED for visual feedback. The OLED’s 1.54-inch size is ideal for a handheld color meter. The sensor’s TCS34725 has a 60-degree field of view, so it’s good for spot measurements. The OLED’s 128x64 pixels can show a 128x64 pixel image of the color spectrum. The sensor’s data can be used to create a color histogram. The OLED’s SPI speed can be set to 8 MHz for fast updates. The sensor’s I2C speed can be set to 400 kHz. For a real-time color display, use a 50ms sensor read and a 10ms OLED update. The OLED’s SSD1309 driver has a built-in oscillator, so no external clock is needed. The sensor’s TCS34725 has an internal oscillator. For a low-power project, use a 32 kHz oscillator for the sensor. The OLED’s 1.54-inch size has a 0.96mm pixel pitch, so each pixel is 0.96mm wide. The sensor’s TCS34725 has a 3.8mm x 2.2mm active area. For a precise color measurement, use a 1mm aperture. The OLED’s 128x64 resolution can show a 16x16 grid of 8x8 pixel color squares. The sensor’s RGB data can be used to fill the grid. The OLED’s grayscale can be used to show the color intensity. The sensor’s clear channel can be used for ambient light compensation. The OLED’s contrast can be set to 128 for a balanced display. The sensor’s gain can be set to 4x for indoor lighting. For

← Back to HomeCustomer Stories →
Continue the work

See Mostick inside a real operations team.

Twenty minutes. Your stack, your numbers, no slides. We'll show where the time goes and what gets automated first.

Book a Demo