<?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[Bus already started, M5Stick vs DEVKIT 1]]></title><description><![CDATA[<p dir="auto">Hello to all,</p>
<p dir="auto">The M5StickCPlus2 has a weird behaviour in regards to the I2c bus.</p>
<p dir="auto">Before my M5Stick arrived, I tested the M5Stack Mini Scale with my Esp32 (Doit Devkit 1) successfully with the following code.</p>
<pre><code>#include &lt;Arduino.h&gt;
#include &lt;M5Unified.h&gt;
#include "UNIT_SCALES.h"

#include &lt;WiFi.h&gt;
#include &lt;PubSubClient.h&gt;

#include &lt;InfluxDbClient.h&gt;
#include &lt;InfluxDbCloud.h&gt;

#define millis_between_readings 500

// WiFi
const char* ssid = ".....";
const char* password = "....";

#if defined(ESP32)
  #include &lt;WiFiMulti.h&gt;
  WiFiMulti wifiMulti;
  #define DEVICE "ESP32"
#elif defined(ESP8266)
  #include &lt;ESP8266WiFiMulti.h&gt;
  ESP8266WiFiMulti wifiMulti;
  #define DEVICE "ESP8266"
#endif


#define INFLUXDB_URL "....."
#define INFLUXDB_TOKEN "....."
#define INFLUXDB_ORG "...."
#define INFLUXDB_BUCKET "...."
  
// Time zone info
#define TZ_INFO "UTC2"
  
// Declare InfluxDB client instance with preconfigured InfluxCloud certificate
InfluxDBClient client(INFLUXDB_URL, INFLUXDB_ORG, INFLUXDB_BUCKET, INFLUXDB_TOKEN, InfluxDbCloud2CACert);
  
// Declare Data point
Point sensorP("ESP32_1");

UNIT_SCALES scales;


void setup()
{

  M5.begin();
  
  // Setup wifi
  Serial.print("Connecting to WiFi: [");
  Serial.print(ssid);
  Serial.print("] password: [");
  Serial.print(password);
  Serial.print("]");
  Serial.println();
  Serial.print("Connecting to wifi");

  WiFi.mode(WIFI_STA);
  wifiMulti.addAP(ssid, password);

  WiFi.disconnect();
  delay(1);
  while (wifiMulti.run() != WL_CONNECTED) {
    Serial.println(WiFi.status());
    Serial.print(" ");
    delay(1000);
  }

  Serial.println("Connected to the Wi-Fi network");
    // Accurate time is necessary for certificate validation and writing in batches
  // We use the NTP servers in your area as provided by: https://www.pool.ntp.org/zone/
  // Syncing progress and the time will be printed to Serial.
  timeSync(TZ_INFO, "pool.ntp.org", "time.nis.gov");

    // Check server connection
  if (client.validateConnection()) {
    Serial.print("Connected to InfluxDB: ");
    Serial.println(client.getServerUrl());
  } else {
    Serial.print("InfluxDB connection failed: ");
    Serial.println(client.getLastErrorMessage());
  }

  sensorP.addTag("device", DEVICE);
  sensorP.addTag("sensorType", "HT711");

  
  while (!scales.begin(&amp;Wire, 21, 22, DEVICE_DEFAULT_ADDR))
  {
    Serial.println("scales connect error");
    M5.Lcd.print("scales connect error");
    delay(1000);
  }
}

char *toCharArray(String str)
{
  return &amp;str[0];
}

void loop()
{
  // Clear fields for reusing the point. Tags will remain the same as set above.
  sensorP.clearFields();


  
  // Delay between measurements.
  sensorP.addField("weight", scales.getWeight());
  sensorP.addField("gap",  scales.getGapValue());
  sensorP.addField("adc",  scales.getRawADC());
  // Write point
  if (!client.writePoint(sensorP)) {
    Serial.print("InfluxDB write failed: ");
    Serial.println(client.getLastErrorMessage());
  }
  
  Serial.println("Pausing till next reading");
  delay(millis_between_readings);
}

</code></pre>
<p dir="auto">Here is a picture of the wiring I used to bridge the gap between the M5 connector and the Devkit 1. (Green: VIN, Gray: GND, Purple: D21, White D22).</p>
<p dir="auto"><img src="/assets/uploads/files/1724657569158-img_8720.jpg" alt="IMG_8720.jpg" class=" img-fluid img-markdown" /></p>
<p dir="auto">Anyone any idea what these two boards work differently?</p>
<p dir="auto">Greetings Pascal</p>
]]></description><link>https://community.m5stack.com/topic/6731/bus-already-started-m5stick-vs-devkit-1</link><generator>RSS for Node</generator><lastBuildDate>Mon, 04 May 2026 00:01:20 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/6731.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 26 Aug 2024 07:35:02 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Bus already started, M5Stick vs DEVKIT 1 on Mon, 26 Aug 2024 13:08:42 GMT]]></title><description><![CDATA[<p dir="auto">For the sake of completeness, I found my error.</p>
<p dir="auto">I assumed, due to the writing on the back, that the ports must be 21/22. However, the SDA/SCL ports for the groove port are 32/33.</p>
<pre><code>while (!scales.begin(&amp;Wire, 32, 33, DEVICE_DEFAULT_ADDR))
  {
    Serial.println("scales connect error");
    M5.Lcd.print("scales connect error");
    delay(1000);
  }
</code></pre>
<p dir="auto">Changing the ports in the scales.begin fixed the error.</p>
<p dir="auto">Greetings Pascal</p>
]]></description><link>https://community.m5stack.com/post/26230</link><guid isPermaLink="true">https://community.m5stack.com/post/26230</guid><dc:creator><![CDATA[PascalS]]></dc:creator><pubDate>Mon, 26 Aug 2024 13:08:42 GMT</pubDate></item></channel></rss>