<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[CoreS3 &amp; NCIR 2 UNIT not reading sensor correctly]]></title><description><![CDATA[<p dir="auto">I'm using Arduino IDE 2.3.4 &amp; 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 .</p>
<p dir="auto">#include &lt;M5CoreS3.h&gt;<br />
#include &lt;M5GFX.h&gt;<br />
#include &lt;M5UNIT_NCIR2.h&gt;<br />
#include &lt;M5Unified.h&gt;<br />
#include &lt;Preferences.h&gt;<br />
#include &lt;Wire.h&gt;</p>
<p dir="auto">// Objects<br />
M5GFX display;<br />
M5UNIT_NCIR2 ncir2;<br />
Preferences preferences;</p>
<p dir="auto">int16_t temperature;<br />
int16_t temperature_soc;</p>
<p dir="auto">uint16_t low_alarm_freq, high_alarm_freq, low_alarm_interval,<br />
high_alarm_interval, buzz_freq;<br />
uint8_t low_alarm_duty, high_alarm_duty, duty;<br />
int16_t low_alarm_temp, high_alarm_temp;</p>
<p dir="auto">// Global Variables<br />
float emissivity = 0.95;<br />
float tempAlert = 30.0;<br />
int currentPage = 0;<br />
bool needRedraw = true;   // Flag to control screen redraw</p>
<p dir="auto">#define M5UNIT_NCIR2_DEFAULT_ADDR 0x5A</p>
<p dir="auto">void setup() {<br />
auto cfg = M5.config();<br />
M5.begin(cfg);<br />
Serial.begin(115200); // Start serial communication<br />
ncir2.begin(&amp;Wire,1, 2, M5UNIT_NCIR2_DEFAULT_ADDR);</p>
<p dir="auto">// Load settings from preferences<br />
preferences.begin("settings", true);<br />
emissivity = preferences.getFloat("emissivity", 0.95);<br />
tempAlert = preferences.getFloat("tempAlert", 30.0);<br />
preferences.end();</p>
<p dir="auto">M5.Display.fillScreen(TFT_BLACK);<br />
}</p>
<p dir="auto">void loop() {<br />
M5.update();</p>
<p dir="auto">// Update the display only if necessary<br />
if (needRedraw) {<br />
if (currentPage == 0) {<br />
drawMainMenu();<br />
} else if (currentPage == 1) {<br />
drawSettingsPage();<br />
}<br />
needRedraw = false; // Reset redraw flag<br />
}</p>
<p dir="auto">// Handle touch input<br />
if (currentPage == 0) {<br />
handleMainMenuTouch();<br />
} else if (currentPage == 1) {<br />
handleSettingsTouch();<br />
}<br />
}</p>
<p dir="auto">// Main Menu<br />
void drawMainMenu() {<br />
M5.Display.fillScreen(TFT_BLACK);<br />
M5.Display.setTextSize(2);<br />
M5.Display.setCursor(10, 10);<br />
M5.Display.print("NCIR2 Temp Monitor");</p>
<p dir="auto">float temperature = ncir2.getTempValue(); // Now this line will work<br />
Serial.printf("Temperature Read: %.2f C\n", temperature); // Debug print<br />
M5.Display.setCursor(10, 50);<br />
M5.Display.printf("Temp: %.2f C", temperature);</p>
<p dir="auto">// Draw Settings button<br />
M5.Display.fillRect(10, 100, 200, 50, TFT_BLUE);<br />
M5.Display.setCursor(30, 120);<br />
M5.Display.setTextColor(TFT_WHITE);<br />
M5.Display.print("Settings");<br />
}</p>
<p dir="auto">void handleMainMenuTouch() {<br />
auto detail = M5.Touch.getDetail();<br />
if (detail.wasPressed()) {<br />
int x = detail.x;<br />
int y = detail.y;</p>
<pre><code>// Check if "Settings" button is pressed
if (x &gt;= 10 &amp;&amp; x &lt;= 210 &amp;&amp; y &gt;= 100 &amp;&amp; y &lt;= 150) {
  currentPage = 1;  // Navigate to Settings Page
  needRedraw = true; // Set redraw flag
}
</code></pre>
<p dir="auto">}<br />
}</p>
<p dir="auto">void drawSettingsPage() {<br />
M5.Display.fillScreen(TFT_BLACK);<br />
M5.Display.setTextSize(2);<br />
M5.Display.setCursor(10, 10);<br />
M5.Display.print("Settings");</p>
<p dir="auto">M5.Display.setCursor(10, 50);<br />
M5.Display.printf("Emissivity: %.2f", emissivity);<br />
M5.Display.setCursor(10, 80);<br />
M5.Display.printf("Alert Temp: %.2f C", tempAlert);</p>
<p dir="auto">// Draw adjustment buttons<br />
M5.Display.fillRect(10, 120, 80, 50, TFT_GREEN);<br />
M5.Display.setCursor(20, 140);<br />
M5.Display.setTextColor(TFT_WHITE);<br />
M5.Display.print("Emissivity +");</p>
<p dir="auto">M5.Display.fillRect(100, 120, 80, 50, TFT_RED);<br />
M5.Display.setCursor(110, 140);<br />
M5.Display.setTextColor(TFT_WHITE);<br />
M5.Display.print("Emissivity -");</p>
<p dir="auto">M5.Display.fillRect(10, 180, 80, 50, TFT_GREEN);<br />
M5.Display.setCursor(20, 200);<br />
M5.Display.setTextColor(TFT_WHITE);<br />
M5.Display.print("Temp +");</p>
<p dir="auto">M5.Display.fillRect(100, 180, 80, 50, TFT_RED);<br />
M5.Display.setCursor(110, 200);<br />
M5.Display.setTextColor(TFT_WHITE);<br />
M5.Display.print("Temp -");</p>
<p dir="auto">// Draw "Back" button<br />
M5.Display.fillRect(10, 250, 200, 50, TFT_BLUE);<br />
M5.Display.setCursor(30, 270);<br />
M5.Display.setTextColor(TFT_WHITE);<br />
M5.Display.print("Back");<br />
}</p>
<p dir="auto">void handleSettingsTouch() {<br />
auto detail = M5.Touch.getDetail();<br />
if (detail.wasPressed()) {<br />
int x = detail.x;<br />
int y = detail.y;</p>
<pre><code>// Check if "Back" button is pressed
if (x &gt;= 10 &amp;&amp; x &lt;= 210 &amp;&amp; y &gt;= 250 &amp;&amp; y &lt;= 300) {
  currentPage = 0;  // Navigate back to Main Menu
  needRedraw = true; // Set redraw flag
  return;
}

// Check if "+" buttons are pressed to adjust values
if (x &gt;= 10 &amp;&amp; x &lt;= 90 &amp;&amp; y &gt;= 120 &amp;&amp; y &lt;= 170) {
  emissivity += 0.01;  
  saveSettings();
  needRedraw = true; // Set redraw flag
}

if (x &gt;= 100 &amp;&amp; x &lt;= 180 &amp;&amp; y &gt;= 120 &amp;&amp; y &lt;= 170) {
  emissivity -= 0.01;  
  saveSettings();
  needRedraw = true; // Set redraw flag
}

if (x &gt;= 10 &amp;&amp; x &lt;= 90 &amp;&amp; y &gt;= 180 &amp;&amp; y &lt;= 230) {
  tempAlert += 1.0;  
  saveSettings();
  needRedraw = true; // Set redraw flag
}

if (x &gt;= 100 &amp;&amp; x &lt;= 180 &amp;&amp; y &gt;= 180 &amp;&amp; y &lt;= 230) {
  tempAlert -= 1.0;  
  saveSettings();
  needRedraw = true; // Set redraw flag
}
</code></pre>
<p dir="auto">}<br />
}</p>
<p dir="auto">void saveSettings() {<br />
preferences.begin("settings", false);<br />
preferences.putFloat("emissivity", emissivity);<br />
preferences.putFloat("tempAlert", tempAlert);<br />
preferences.end();<br />
}</p>
]]></description><link>https://community.m5stack.com/topic/7068/cores3-ncir-2-unit-not-reading-sensor-correctly</link><generator>RSS for Node</generator><lastBuildDate>Wed, 29 Apr 2026 02:45:25 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/7068.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 09 Dec 2024 00:07:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to CoreS3 &amp; NCIR 2 UNIT not reading sensor correctly on Mon, 09 Dec 2024 01:26:59 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/kuriko" aria-label="Profile: kuriko">@<bdi>kuriko</bdi></a> 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.</p>
]]></description><link>https://community.m5stack.com/post/27384</link><guid isPermaLink="true">https://community.m5stack.com/post/27384</guid><dc:creator><![CDATA[reptilepvp]]></dc:creator><pubDate>Mon, 09 Dec 2024 01:26:59 GMT</pubDate></item><item><title><![CDATA[Reply to CoreS3 &amp; NCIR 2 UNIT not reading sensor correctly on Mon, 09 Dec 2024 01:22:55 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/reptilepvp" aria-label="Profile: reptilepvp">@<bdi>reptilepvp</bdi></a><br />
I don't quite understand, according to the document, the I2C address of NCIR2 is 0x5A<br />
Maybe you should try leaving only the code for reading the temperature?</p>
]]></description><link>https://community.m5stack.com/post/27382</link><guid isPermaLink="true">https://community.m5stack.com/post/27382</guid><dc:creator><![CDATA[kuriko]]></dc:creator><pubDate>Mon, 09 Dec 2024 01:22:55 GMT</pubDate></item></channel></rss>