I am using oled and spectral sensor together but they are not working with the code i wrote

they both communicate using I2C .. my sensor is taking reading but oled is not working within loop () pls help ...
#include <Wire.h>
#include <U8x8lib.h>
#include <Adafruit_AS7341.h>

Adafruit_AS7341 as7341;

// Define the OLED display
U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(/* clock=/ A5, / data=/ A4, / reset=*/ U8X8_PIN_NONE);

void setup() {
Serial.begin(9600);

// Initialize the OLED display
u8x8.begin();
u8x8.setFont(u8x8_font_chroma48medium8_r);
u8x8.print("F1 ");

if (!as7341.begin()){
Serial.println("Could not find AS7341");
while (1) { delay(10); }
}

as7341.setATIME(100);
as7341.setASTEP(999);
as7341.setGain(AS7341_GAIN_256X);
}

void loop() {
uint16_t readings[12];
float counts[12];

if (!as7341.readAllChannels(readings)){
Serial.println("Error reading all channels!");
return;
}

for(uint8_t i = 0; i < 12; i++) {
if(i == 4 || i == 5) continue;
counts[i] = as7341.toBasicCounts(readings[i]);
}

// Print to Serial Monitor
Serial.print("F1 415nm : ");
Serial.println(counts[0]);
u8x8.clear();
u8x8.setCursor(0, 0);

u8x8.print("F1 415nm: ");
u8x8.print(counts[0]);
Serial.print("F2 515nm : ");
Serial.println(counts[1]);
u8x8.setCursor(0, 2);
u8x8.print("F2 515nm: ");
u8x8.print(counts[1]);
Serial.println();

// Display on OLED

delay(500);
}

Welcome to the forum

You started a topic in the Uncategorised category of the forum whose description is

:warning: DO NOT CREATE TOPICS IN THIS CATEGORY :warning:

Your topic has been moved to a more relevant category

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

1 Like

Did you try any of the example projects testing just the OLED?

yes ..both are working independently

Independently as in only when one or the other is hooked up, or they are both hooked up and only using code for one device?

I recommend you read the forum guidelines and post your code accordingly using code tags. How to get the best out of this forum What you have posted appears as just gibberish. This is possibly both a hardware and software problem, post an annotated schematic showing exactly how it is wired. It is important to show all ground, power connections as well as power sources.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.