<?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] M5StickCPlus and BMM150 (ENV II Hat) do not work]]></title><description><![CDATA[<p dir="auto">Hi all,</p>
<p dir="auto">I'm working on getting magnetometer data with a M5StickC Plus and ENV II Hat.<br />
I found that I2C communication between M5StickC Plus and BMM150 is not working as expected, and am wondering if you can provide some guidance to make it work.</p>
<p dir="auto">I'm using a sample code at<br />
<a href="https://github.com/m5stack/M5StickC-Plus/tree/master/examples/Hat/ENVII_SHT30_BMP280" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/m5stack/M5StickC-Plus/tree/master/examples/Hat/ENVII_SHT30_BMP280</a></p>
<p dir="auto">I tried it as is. It did not work (the code stopped running somewhere)<br />
I added Wire.begin(0, 26) in the setup function since the hat is connected to G0 and G26. This got the same result.</p>
<p dir="auto">Then, I dug into where the code stopped.<br />
It stopped at BMM150::initialize &gt; set_op_mode &gt; suspend_to_sleep_mode &gt; set_power_control_bit &gt; i2c_read<br />
In i2c_read, when the code called Wire.requestFrom(BMM150_I2C_Address, 1), it did not return.<br />
How can I fix the issue?</p>
<p dir="auto">Here is a minimal code to reproduce the issue.</p>
<pre><code>#include &lt;M5StickCPlus.h&gt;
#define BMM150_I2C_Address  0x10  // These are copied from bmm150_defs.h
#define BMM150_POWER_CONTROL_ADDR 0x4B

void setup() {
  M5.begin();
  Wire.begin(0, 26);
  delay(3000);  // Make sure to avoid any race conditions
  Serial.println("Start setup");
  uint8_t reg_data = i2c_read(BMM150_POWER_CONTROL_ADDR);
}

void loop() {
  delay(1000);
  Serial.println("loop");
}

uint8_t i2c_read(short address)
{
    uint8_t byte;
    int result;
    Wire.beginTransmission(BMM150_I2C_Address);
    result = Wire.endTransmission();
    Serial.printf("%d\n", result); // This sometimes gets 2: NACK, which is a bit strange

    Wire.beginTransmission(BMM150_I2C_Address);
    result = Wire.endTransmission();
    Serial.printf("%d\n", result);  // This gets 0: Success

    Wire.beginTransmission(BMM150_I2C_Address);
    Wire.write(address);
    result = Wire.endTransmission();
    Serial.printf("%d\n", result); // This gets 0: Success

    Wire.beginTransmission(BMM150_I2C_Address);
    Serial.println("call Wire.requestFrom");
    Wire.requestFrom(BMM150_I2C_Address, 1, 0);
    Serial.println("call returned"); // This is never called
    byte = Wire.read();
   
    Wire.endTransmission();
    return byte;
}
</code></pre>
]]></description><link>https://community.m5stack.com/topic/5751/solved-m5stickcplus-and-bmm150-env-ii-hat-do-not-work</link><generator>RSS for Node</generator><lastBuildDate>Tue, 28 Apr 2026 21:59:35 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/5751.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 28 Oct 2023 16:15:09 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [SOLVED] M5StickCPlus and BMM150 (ENV II Hat) do not work on Thu, 02 Nov 2023 03:43:28 GMT]]></title><description><![CDATA[<p dir="auto">I found a solution.<br />
An example you can find at <a href="https://www.waveshare.com/wiki/BMM150_3-Axis_Magnetometer_Sensor" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.waveshare.com/wiki/BMM150_3-Axis_Magnetometer_Sensor</a> (the one linked from Example Demo) with a proper modification worked with BMM150 in Env II Hat. Here is the procedure.</p>
<ul>
<li>Download the zip file from the Example Demo link.</li>
<li>Open bmm150_Arduino.ino under Arduino &gt; bmm150_Arduino</li>
<li>Search Wire.begin() in the code (you can find one in the line 149)</li>
<li>Change it to Wire.begin(0, 26)<br />
This is necessary if you are using a Hat version of ENV II HAT, which is connected to the GPIO pin side of the M5Stick variants. If you are using ENV II Hat connected the Grove port, you don't need to change it.</li>
</ul>
<p dir="auto">After this modification, the code should work.</p>
]]></description><link>https://community.m5stack.com/post/22629</link><guid isPermaLink="true">https://community.m5stack.com/post/22629</guid><dc:creator><![CDATA[eulic_]]></dc:creator><pubDate>Thu, 02 Nov 2023 03:43:28 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] M5StickCPlus and BMM150 (ENV II Hat) do not work on Tue, 31 Oct 2023 06:26:44 GMT]]></title><description><![CDATA[<p dir="auto">Thanks <a class="plugin-mentions-user plugin-mentions-a" href="/user/gavin67890" aria-label="Profile: gavin67890">@<bdi>gavin67890</bdi></a> !<br />
Yes. We can make the SHT30 and BMP280 in that way, but not BMM150 unfortunately.<br />
I think the example code for BMM150 is fundamentally broken and M5Stack does not plan to fix it since ENV II Hat is EOL. I will look into an example code from Bosch, which is the manufacture of the BMM150 chip.</p>
]]></description><link>https://community.m5stack.com/post/22615</link><guid isPermaLink="true">https://community.m5stack.com/post/22615</guid><dc:creator><![CDATA[eulic_]]></dc:creator><pubDate>Tue, 31 Oct 2023 06:26:44 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] M5StickCPlus and BMM150 (ENV II Hat) do not work on Mon, 30 Oct 2023 09:59:02 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/eulic_" aria-label="Profile: eulic_">@<bdi>eulic_</bdi></a>,</p>
<p dir="auto">I adapted what is below from the M5Stack examples for StickC (non-Plus) and ENVII hat to work on an Atom. The only real changes I made were to write out to serial instead of LCD and use the LEDs of the Atom, so it might help you fault find. NB Library and pins need changed to suit your StickC Plus. It's a bit rough and ready, but it certainly worked on ENVII with Atom and StickC.</p>
<pre><code>#include &lt;M5Atom.h&gt; // Swap out for StickC library
#include "M5_ENV.h"
#include &lt;Adafruit_BMP280.h&gt;
#include "Adafruit_Sensor.h"

SHT3X sht30; // SHT3X sht30;
Adafruit_BMP280 bme; // Adafruit_BMP280 bme;

float tmp      = 0.0;
float hum      = 0.0;
float pressure = 0.0;

void setup() {
    M5.begin(true, false, true);             // Init M5Atom
    delay(1500);
    // M5.Lcd.setRotation(3);  // Rotate the screen.
    // M5.dis.fillpix(0xFF0000); //LEDs of atom to black
    Wire.end();
    Wire.begin(19, 22); // Swap out for StickC 0, 26
    sht30.init();
    Serial.println(F("ENVII Unit(SHT30 and BMP280) test...\n"));
}

void loop() {

    while (!bme.begin(0x76)) {  // Init the sensor of bme
        Serial.println("Could not find a valid BMP280 sensor, check wiring!");
    }
    // M5.dis.fillpix(0x00FF00); // Turns atom leds green
    pressure = bme.readPressure();  // Stores the pressure gained by BMP.

    sht30.get();           // Obtain the data of shT30.
    tmp = sht30.cTemp;     // Store the temperature obtained from shT30
    hum = sht30.humidity;  // Store the humidity obtained from the SHT30
    // M5.Lcd.setCursor(0, 20);
    // M5.Lcd.fillRect(0, 20, 100, 60,
                  //  BLACK);  // Fill the screen with black (to clear the screen).
    Serial.printf("Temp: %2.1f  \r\nHumi: %2.0f%%  \r\nPressure:%2.0fPa\r\n",
                  tmp, hum, pressure);
    delay(2000);
}</code></pre>
]]></description><link>https://community.m5stack.com/post/22612</link><guid isPermaLink="true">https://community.m5stack.com/post/22612</guid><dc:creator><![CDATA[gavin67890]]></dc:creator><pubDate>Mon, 30 Oct 2023 09:59:02 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] M5StickCPlus and BMM150 (ENV II Hat) do not work on Sun, 29 Oct 2023 00:36:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/teastain" aria-label="Profile: teastain">@<bdi>teastain</bdi></a> Thank you for your comment Terry!<br />
I initially had all variables and, unfortunately, it did not work either.<br />
Wire.begin(0, 26) is necessary because I'm using Hat that connects to GPIO pins not Grove port. Wire.begin start I2C communications using the Grove port by default not G0 and 26 on the Hat connecter side.</p>
<p dir="auto">When I checked I2C addresses with I2C_Tester example, With Wire.begin(), it listed only three internal devices. With Wire.begin(0, 26), it listed three additional devices in ENV III Hat including BMM150 at 0x10.</p>
<p dir="auto">Btw, sht3x has Wire.begin() in its constructer. So, it's better not to have the sht3x instance if not necessary. It could lead to confusing results.</p>
]]></description><link>https://community.m5stack.com/post/22603</link><guid isPermaLink="true">https://community.m5stack.com/post/22603</guid><dc:creator><![CDATA[eulic_]]></dc:creator><pubDate>Sun, 29 Oct 2023 00:36:50 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] M5StickCPlus and BMM150 (ENV II Hat) do not work on Sat, 28 Oct 2023 23:50:35 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/eulic_" aria-label="Profile: eulic_">@<bdi>eulic_</bdi></a> Could be related to these includes and begins:</p>
<pre><code>#include "bmm150.h"
#include "bmm150_defs.h"
SHT3X sht3x;
BMM150 bmm = BMM150();
bmm150_mag_data value_offset;
Adafruit_BMP280 bme;
</code></pre>
<p dir="auto">With the StickCPlus include you should not need to add Wire.begin(0, 26);</p>
<p dir="auto">Also I don't understand the three</p>
<pre><code>Wire.beginTransmission(BMM150_I2C_Address);
</code></pre>
<p dir="auto">-Terry</p>
]]></description><link>https://community.m5stack.com/post/22602</link><guid isPermaLink="true">https://community.m5stack.com/post/22602</guid><dc:creator><![CDATA[teastain]]></dc:creator><pubDate>Sat, 28 Oct 2023 23:50:35 GMT</pubDate></item></channel></rss>