@kuriko i wanted the code to read in Fahrenheit . But also the issue is that it’s the reading the i2c connection but in UIFlow it does.
Latest posts made by reptilepvp
-
RE: CoreS3 & NCIR 2 UNIT not reading sensor correctly
-
CoreS3 & NCIR 2 UNIT not reading sensor correctly
I'm using Arduino IDE 2.3.4 & having the issue with the unit reading the temperature data. If I use UIFLOW the sensor works perfect but whenever I try to get it to read thru IDE. It constantly just reads 2784 degree's. If I use the user demos . It picks up the i2c addy as the default 0x5A. Please help if possible, this is my code .
#include <M5CoreS3.h>
#include <M5GFX.h>
#include <M5UNIT_NCIR2.h>
#include <M5Unified.h>
#include <Preferences.h>
#include <Wire.h>// Objects
M5GFX display;
M5UNIT_NCIR2 ncir2;
Preferences preferences;int16_t temperature;
int16_t temperature_soc;uint16_t low_alarm_freq, high_alarm_freq, low_alarm_interval,
high_alarm_interval, buzz_freq;
uint8_t low_alarm_duty, high_alarm_duty, duty;
int16_t low_alarm_temp, high_alarm_temp;// Global Variables
float emissivity = 0.95;
float tempAlert = 30.0;
int currentPage = 0;
bool needRedraw = true; // Flag to control screen redraw#define M5UNIT_NCIR2_DEFAULT_ADDR 0x5A
void setup() {
auto cfg = M5.config();
M5.begin(cfg);
Serial.begin(115200); // Start serial communication
ncir2.begin(&Wire,1, 2, M5UNIT_NCIR2_DEFAULT_ADDR);// Load settings from preferences
preferences.begin("settings", true);
emissivity = preferences.getFloat("emissivity", 0.95);
tempAlert = preferences.getFloat("tempAlert", 30.0);
preferences.end();M5.Display.fillScreen(TFT_BLACK);
}void loop() {
M5.update();// Update the display only if necessary
if (needRedraw) {
if (currentPage == 0) {
drawMainMenu();
} else if (currentPage == 1) {
drawSettingsPage();
}
needRedraw = false; // Reset redraw flag
}// Handle touch input
if (currentPage == 0) {
handleMainMenuTouch();
} else if (currentPage == 1) {
handleSettingsTouch();
}
}// Main Menu
void drawMainMenu() {
M5.Display.fillScreen(TFT_BLACK);
M5.Display.setTextSize(2);
M5.Display.setCursor(10, 10);
M5.Display.print("NCIR2 Temp Monitor");float temperature = ncir2.getTempValue(); // Now this line will work
Serial.printf("Temperature Read: %.2f C\n", temperature); // Debug print
M5.Display.setCursor(10, 50);
M5.Display.printf("Temp: %.2f C", temperature);// Draw Settings button
M5.Display.fillRect(10, 100, 200, 50, TFT_BLUE);
M5.Display.setCursor(30, 120);
M5.Display.setTextColor(TFT_WHITE);
M5.Display.print("Settings");
}void handleMainMenuTouch() {
auto detail = M5.Touch.getDetail();
if (detail.wasPressed()) {
int x = detail.x;
int y = detail.y;// Check if "Settings" button is pressed if (x >= 10 && x <= 210 && y >= 100 && y <= 150) { currentPage = 1; // Navigate to Settings Page needRedraw = true; // Set redraw flag }
}
}void drawSettingsPage() {
M5.Display.fillScreen(TFT_BLACK);
M5.Display.setTextSize(2);
M5.Display.setCursor(10, 10);
M5.Display.print("Settings");M5.Display.setCursor(10, 50);
M5.Display.printf("Emissivity: %.2f", emissivity);
M5.Display.setCursor(10, 80);
M5.Display.printf("Alert Temp: %.2f C", tempAlert);// Draw adjustment buttons
M5.Display.fillRect(10, 120, 80, 50, TFT_GREEN);
M5.Display.setCursor(20, 140);
M5.Display.setTextColor(TFT_WHITE);
M5.Display.print("Emissivity +");M5.Display.fillRect(100, 120, 80, 50, TFT_RED);
M5.Display.setCursor(110, 140);
M5.Display.setTextColor(TFT_WHITE);
M5.Display.print("Emissivity -");M5.Display.fillRect(10, 180, 80, 50, TFT_GREEN);
M5.Display.setCursor(20, 200);
M5.Display.setTextColor(TFT_WHITE);
M5.Display.print("Temp +");M5.Display.fillRect(100, 180, 80, 50, TFT_RED);
M5.Display.setCursor(110, 200);
M5.Display.setTextColor(TFT_WHITE);
M5.Display.print("Temp -");// Draw "Back" button
M5.Display.fillRect(10, 250, 200, 50, TFT_BLUE);
M5.Display.setCursor(30, 270);
M5.Display.setTextColor(TFT_WHITE);
M5.Display.print("Back");
}void handleSettingsTouch() {
auto detail = M5.Touch.getDetail();
if (detail.wasPressed()) {
int x = detail.x;
int y = detail.y;// Check if "Back" button is pressed if (x >= 10 && x <= 210 && y >= 250 && y <= 300) { currentPage = 0; // Navigate back to Main Menu needRedraw = true; // Set redraw flag return; } // Check if "+" buttons are pressed to adjust values if (x >= 10 && x <= 90 && y >= 120 && y <= 170) { emissivity += 0.01; saveSettings(); needRedraw = true; // Set redraw flag } if (x >= 100 && x <= 180 && y >= 120 && y <= 170) { emissivity -= 0.01; saveSettings(); needRedraw = true; // Set redraw flag } if (x >= 10 && x <= 90 && y >= 180 && y <= 230) { tempAlert += 1.0; saveSettings(); needRedraw = true; // Set redraw flag } if (x >= 100 && x <= 180 && y >= 180 && y <= 230) { tempAlert -= 1.0; saveSettings(); needRedraw = true; // Set redraw flag }
}
}void saveSettings() {
preferences.begin("settings", false);
preferences.putFloat("emissivity", emissivity);
preferences.putFloat("tempAlert", tempAlert);
preferences.end();
} -
RE: Change NCIR 2 from C to F
@felmue I apologize for sounding stupid & not doing my research. But could you possiblely show me where I need to put that in my code? I thought I put the formula in right. But I guess not .
i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000)
ncir2_0 = NCIR2Unit(i2c0, 0x5A)
ncir2_0.set_buzzer_control(0)
ncir2_0.set_rgb_led(0xcc33cc)
ncir2_0.set_emissivity_value(0.95)def loop():
global DopeMete, Battery, Temperature, label5, label0, line0, label1, line2, label2, line1, label3, label4, i2c0, ncir2_0
M5.update()
label2.setText(str("%.2f"%float((((ncir2_0.get_temperature_value) * 9) / 5 + 32))))
label3.setText(str(ncir2_0.get_emissivity_value))
label4.setText(str(ncir2_0.get_button_status))
label5.setText(str(Power.getBatteryLevel())) -
Change NCIR 2 from C to F
How would I go about changing the NCIR 2 unit to read from celsius to fahrenheit? Any help would be great