<?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[[SOLVED] GNSS on Core2: BMM150 issue when using M5 events]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">I'm developing a program that uses the GPS and the Magnetometer (BMM150) of the GNSS Module.<br />
It works fine, but as soon as functions such as M5.BtnA.wasPressed(), screen touch or M5.Axp.GetBatVoltage(), the BMM150 communication seems broken.</p>
<p dir="auto">I tried with address 0x68 and 0x69 -&gt; same problem.<br />
I tried running the task on core 1 or core 0 -&gt;  same problem.</p>
<p dir="auto">DO YOU HAVE AN IDEA OF WHAT I'M DOING WRONG HERE?</p>
<h2>Examples of error displayed on the monitor.</h2>
<p dir="auto">After M5.Axp.GetBatVoltage() called:<br />
11:59:50.763 -&gt; E (22261) IMU: P:0 R 68 7C E:263</p>
<p dir="auto">After M5.BtnA.wasPressed() called:<br />
12:00:33.754 -&gt; E (16003) IMU: P:0 R 68 7C E:-1<br />
12:00:34.119 -&gt; E (16025) IMU: P:0 R 68 03 E:263<br />
12:00:34.149 -&gt; E (16038) IMU: P:0 R 68 03 E:263</p>
<h2>Source code to reproduce the issue.</h2>
<p dir="auto">M5Module_GNSS.h is available here: <a href="https://github.com/m5stack/M5Module-GNSS/tree/main/src" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/m5stack/M5Module-GNSS/tree/main/src</a></p>
<p dir="auto">#include &lt;M5Core2.h&gt;<br />
#include &lt;Arduino.h&gt;<br />
#include &lt;TinyGPS++.h&gt;<br />
#include &lt;Wire.h&gt;<br />
#include "M5Module_GNSS.h"</p>
<p dir="auto">#define BIM270_SENSOR_ADDR 0x68<br />
BMI270::BMI270 bmi270;</p>
<p dir="auto">#define WATCHDOG_TIMER   2000UL     // ms<br />
#define BATT_CHECK       20000UL     // ms - interval to check battery status</p>
<p dir="auto">// variables<br />
uint32_t  last_battery_check = 0;<br />
uint32_t  last_json = 0;</p>
<p dir="auto">bool isGPS = false;</p>
<p dir="auto">// GPS &amp; Magnetometer<br />
float biasX, biasY, rangeX, rangeY;<br />
int16_t magX, magY, magZ;<br />
int16_t minMagX, minMagY, maxMagX, maxMagY;<br />
// The TinyGPS++ object<br />
TinyGPSPlus gps;</p>
<p dir="auto">// functions<br />
void gps_task(void *pvParameters);<br />
void magneto_task(void *pvParameters);</p>
<p dir="auto">void updateBatteryLevel (void) {</p>
<p dir="auto">float batVoltage = M5.Axp.GetBatVoltage();<br />
float batPercentage = ( batVoltage &lt; 3.2 ) ? 0 : ( batVoltage - 3.2 ) * 100;<br />
Serial.printf("Battery %d\n", batPercentage);<br />
}</p>
<p dir="auto">// ------------------------------------------------ SETUP -----------------------------------------------</p>
<p dir="auto">void setup() {</p>
<p dir="auto">magX = 0;<br />
magY = 0;</p>
<p dir="auto">M5.begin(true, true, true, false, kMBusModeOutput);<br />
M5.Axp.SetLed(0);<br />
M5.Lcd.begin();</p>
<p dir="auto">xTaskCreatePinnedToCore(gps_task,<br />
"gps_task",<br />
10000,<br />
NULL,<br />
25,<br />
NULL,<br />
0);       // running on core 0</p>
<p dir="auto">xTaskCreatePinnedToCore(magneto_task,<br />
"magneto_task",<br />
10000,<br />
NULL,<br />
25,<br />
NULL,<br />
1);       // running on core 0</p>
<p dir="auto">return;<br />
}</p>
<p dir="auto">void magneto_task(void *pvParameters) {</p>
<p dir="auto">static int data, cpmt = 100;</p>
<p dir="auto">Serial.print("MAGNETO TASK STARTS\n");<br />
Wire.begin(21, 22, 100000);<br />
bmi270.init(I2C_NUM_0, BIM270_SENSOR_ADDR);</p>
<p dir="auto">while (1) {<br />
// DEBUG<br />
cpmt++;<br />
if ( cpmt &gt; 100 ) {<br />
Serial.print("•");<br />
cpmt = 0;<br />
};<br />
// Get Magnetometer data<br />
if (bmi270.magneticFieldAvailable()) {<br />
bmi270.readMagneticField(magX, magY, magZ);<br />
}<br />
if (cpmt ==0) Serial.printf("x %d y %d\n", magX, magY);<br />
delay(10);<br />
}<br />
}</p>
<p dir="auto">void gps_task(void *pvParameters) {</p>
<p dir="auto">static int data, cpmt = 100;<br />
Serial.print("GPS TASK STARTS\n");<br />
Serial2.begin(38400, SERIAL_8N1, 13, 14);</p>
<p dir="auto">while (1) {<br />
// DEBUG<br />
cpmt++;<br />
if ( cpmt &gt; 100 ) {<br />
Serial.print("+");<br />
cpmt = 0;<br />
};<br />
// Get GPS data<br />
while (Serial2.available() &gt; 0) {<br />
data = Serial2.read();<br />
<a href="//Serial.printf" target="_blank" rel="noopener noreferrer nofollow ugc">//Serial.printf</a>("%c", data);<br />
gps.encode(data);<br />
}<br />
isGPS = gps.location.isValid();<br />
delay(10);<br />
}<br />
}</p>
<p dir="auto">// ------------------------------------------------ LOOP -----------------------------------------------</p>
<p dir="auto">void loop() {</p>
<p dir="auto">static char            text[256];<br />
static uint32_t        msecs;</p>
<p dir="auto">M5.update();<br />
msecs = millis();</p>
<p dir="auto">// WATCHDOG<br />
if ((msecs - last_json) &gt; WATCHDOG_TIMER) {<br />
if (isGPS) sprintf(text, "GPS %d - ", gps.satellites.value());<br />
else sprintf(text, "Sat %d - ", gps.satellites.value());<br />
Serial.println(text);<br />
last_json = msecs;<br />
}</p>
<p dir="auto">// battery timer<br />
if ((msecs - last_battery_check) &gt; BATT_CHECK) {<br />
updateBatteryLevel();<br />
last_battery_check = msecs;<br />
}</p>
<p dir="auto">if (M5.BtnA.wasPressed()) {<br />
Serial.println("BtnA pressed");<br />
}</p>
<p dir="auto">if (M5.BtnB.wasPressed()) {<br />
Serial.println("BtnB pressed");<br />
}</p>
<p dir="auto">if (M5.BtnC.wasPressed()) {<br />
Serial.println("BtnB pressed");<br />
}</p>
<p dir="auto">return;<br />
}</p>
]]></description><link>https://community.m5stack.com/topic/6406/solved-gnss-on-core2-bmm150-issue-when-using-m5-events</link><generator>RSS for Node</generator><lastBuildDate>Wed, 29 Apr 2026 02:45:48 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/6406.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 01 May 2024 10:15:02 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [SOLVED] GNSS on Core2: BMM150 issue when using M5 events on Wed, 01 May 2024 17:19:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/felmue" aria-label="Profile: felmue">@<bdi>felmue</bdi></a> A million thanks!</p>
<p dir="auto">This was my issue. Your solution works like a charm.</p>
<p dir="auto">Thank you!</p>
]]></description><link>https://community.m5stack.com/post/25021</link><guid isPermaLink="true">https://community.m5stack.com/post/25021</guid><dc:creator><![CDATA[UnumDesignum]]></dc:creator><pubDate>Wed, 01 May 2024 17:19:41 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] GNSS on Core2: BMM150 issue when using M5 events on Wed, 01 May 2024 14:03:21 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="plugin-mentions-user plugin-mentions-a" href="/user/unumdesignum" aria-label="Profile: UnumDesignum">@<bdi>UnumDesignum</bdi></a></p>
<p dir="auto">the issue is probably that the internal I2C of M5Core2 library uses Wire<strong>1</strong> (and not Wire). See <a href="https://github.com/m5stack/M5Core2/blob/master/src/AXP.cpp#L108" target="_blank" rel="noopener noreferrer nofollow ugc">here</a>.</p>
<p dir="auto">In your <code>magneto_task</code> you initialize Wire with the same GPIOs (21, 22) so you end up with two I2C instances (Wire and Wire<strong>1</strong>) fighting for the same GPIOs.</p>
<p dir="auto">Try the following and see if that helps:</p>
<pre><code>//Wire.begin(21, 22, 100000);
//bmi270.init(I2C_NUM_0, BIM270_SENSOR_ADDR);
bmi270.init(I2C_NUM_1, BIM270_SENSOR_ADDR);
</code></pre>
<p dir="auto">Thanks<br />
Felix</p>
]]></description><link>https://community.m5stack.com/post/25018</link><guid isPermaLink="true">https://community.m5stack.com/post/25018</guid><dc:creator><![CDATA[felmue]]></dc:creator><pubDate>Wed, 01 May 2024 14:03:21 GMT</pubDate></item></channel></rss>