Hi,
first time here.
I am using a seeeduino XIAO on the expansion board (Seeeduino XIAO Expansion board - Seeed Wiki), using Arduino IDE to upload the program on mac.
I connected a AS7262 color sensor in I2C and I get the data in the OLED but… I need to have the serial monitor open in the notebook to see the data in the OLED, if not, OLED is black, Any idea?
#include <Arduino.h>
#include <U8g2lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // High speed I2C
// U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); //Low spped I2C
#include "Adafruit_AS726x.h"
//create the object
Adafruit_AS726x ams;
//buffer to hold raw values
uint16_t sensorValues[AS726x_NUM_CHANNELS];
//buffer to hold calibrated values (not used by default in this example)
//float calibratedValues[AS726x_NUM_CHANNELS];
void setup() {
u8g2.begin();
Serial.begin(9600);
while(!Serial);
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
//begin and make sure we can talk to the sensor
if(!ams.begin()){
Serial.println("could not connect to sensor! Please check your wiring.");
while(1);
}
}
void loop() {
//read the device temperature
// uint8_t temp = ams.readTemperature();
//ams.drvOn(); //uncomment this if you want to use the driver LED for readings
ams.startMeasurement(); //begin a measurement
//wait till data is available
bool rdy = false;
while(!rdy){
delay(5);
rdy = ams.dataReady();
}
//ams.drvOff(); //uncomment this if you want to use the driver LED for readings
//read the values!
ams.readRawValues(sensorValues);
//ams.readCalibratedValues(calibratedValues);
// Serial.print("Temp: "); Serial.print(temp);
// Serial.print(" Violet: "); Serial.print(sensorValues[AS726x_VIOLET]);
// Serial.print(" Blue: "); Serial.print(sensorValues[AS726x_BLUE]);
// Serial.print(" Green: "); Serial.print(sensorValues[AS726x_GREEN]);
// Serial.print(" Yellow: "); Serial.print(sensorValues[AS726x_YELLOW]);
// Serial.print(" Orange: "); Serial.print(sensorValues[AS726x_ORANGE]);
// Serial.print(" Red: "); Serial.print(sensorValues[AS726x_RED]);
// Serial.println();
// Serial.println();
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_amstrad_cpc_extended_8f); // choose a suitable font
u8g2.setCursor(0,10); // write something to the internal memory
u8g2.print(sensorValues[AS726x_ORANGE], DEC);
u8g2.sendBuffer(); // transfer internal memory to the display
delay(1000);
}```
Best