<?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[M5Stack and I2C distance sensor ks103]]></title><description><![CDATA[<p dir="auto">Hi all, I'm trying to work with <a href="http://www.dauxi.com/KS10X-V110_EN.pdf" target="_blank" rel="noopener noreferrer nofollow ugc">This</a> I2C sensor and with the followin sketch:</p>
<pre><code>#include &lt;Wire.h&gt;
#define KS103ADD  0x74
word distance = 0;
void setup()
{
//    Wire.begin();
  Wire.begin(22, 21);//M5STACK: SCL,SDA giallo,bianco
  Serial.begin(115200);
  Wire.beginTransmission(KS103ADD);
  Wire.write(byte(0x02));
  Wire.write(0x72);   // 发送降噪指令
  Wire.endTransmission();
  delay(1000);
}
void loop()
{
  if (Serial.read() == 's') {
    while (Serial.read() != 'o') {
      KS103_read();
      Serial.print(distance);
      Serial.print("mm");
      Serial.println();
      delay(250);
    }
  }
  delay(1000);
}

word KS103_read() {
  Wire.beginTransmission(KS103ADD);
  Wire.write(byte(0x02));
  Wire.write(0xbc);     //Range is set to 10m with temperature compensation
  Wire.endTransmission();
  delay(1);
  Wire.beginTransmission(KS103ADD);
  Wire.write(byte(0x02));
  Wire.endTransmission();
  Wire.requestFrom(KS103ADD, 2);
  if (2 &lt;= Wire.available())
  {
    distance = Wire.read();
    distance =  distance &lt;&lt; 8;
    distance |= Wire.read();
  }
}

</code></pre>
<p dir="auto">I have this output:</p>
<pre><code>0mm
0mm
0mm
0mm
0mm
0mm
0mm
0mm
0mm
0mm
0mm

</code></pre>
<p dir="auto">My question is:<br />
are they present the pull-up resistors in the M5Stack (black 2018.3) I2C section?</p>
]]></description><link>https://community.m5stack.com/topic/1742/m5stack-and-i2c-distance-sensor-ks103</link><generator>RSS for Node</generator><lastBuildDate>Sat, 09 May 2026 17:30:51 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/1742.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 04 Mar 2020 09:07:56 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to M5Stack and I2C distance sensor ks103 on Wed, 04 Mar 2020 22:21:30 GMT]]></title><description><![CDATA[<p dir="auto">now it works:</p>
<pre><code>/*
   http://www.dauxi.com/KS10X-V110_EN.pdf

   11101000
   https://www.arduino.cc/en/Tutorial/SFRRangerReader


*/
#include &lt;M5Stack.h&gt;
#include &lt;Wire.h&gt;

#define KS103ADD  0x74 // questo è quello che da lo scanner IIC
//#define KS103ADD  0xE8 // questo è quello che da all'inizio il led verde 11101000    back green led Short flash twice will be “1”, slow flash once will be “0”
word dist = 0;
void setup()
{
  Wire.begin();
//    Wire.begin(22, 21);//M5STACK: 22/SCL/GIALLO ,21/SDA/BIANCO
  Serial.begin(115200);
  //inizio comando
  Wire.beginTransmission(KS103ADD);
  Wire.write(byte(0x02));
  Wire.write(0x72);   // Invia istruzioni per la riduzione del rumore
  Wire.endTransmission();
  // fine comando
  delay(2000);
}
void loop()
{
  // if (Serial.read() == 's') {
  //  while (Serial.read() != 'o') {
  KS103_read();
  Serial.print(dist/10);
  Serial.print(" cm");
  Serial.println();
  delay(250);
  //}
  //}
  // delay(1000);
}

void KS103_read() {
  // step 1: instruct sensor to read echoes
  Wire.beginTransmission(KS103ADD);  // transmit to device
  // the address specified in the datasheet is (0xE8)
  // but i2c adressing uses the high 7 bits so it's  (0x74)
  Wire.write(byte(0x02)); // sets register pointer to echo #1 register (0x02)
  Wire.write(0xbc);     //Range is set to 10m with temperature compensation
  Wire.endTransmission();

  // step 2: wait for readings to happen
  //  delay(1);
  delay(70);   // datasheet suggests at least 65 milliseconds

  // step 3: instruct sensor to return a particular echo reading
  Wire.beginTransmission(KS103ADD);  // transmit to device 
  Wire.write(byte(0x02));  // sets register pointer to echo #1 register (0x02)
  Wire.endTransmission();  // stop transmitting

  // step 4: request reading from sensor
  Wire.requestFrom(KS103ADD, 2);  // request 2 bytes from slave device

  // step 5: receive reading from sensor
  if (2 &lt;= Wire.available()) // if two bytes were received
  {
    dist = Wire.read(); // receive high byte (overwrites previous reading)
    dist =  dist &lt;&lt; 8;  // shift high byte to be high 8 bits
    dist |= Wire.read(); // receive low byte as lower 8 bits
  }
}
</code></pre>
]]></description><link>https://community.m5stack.com/post/7677</link><guid isPermaLink="true">https://community.m5stack.com/post/7677</guid><dc:creator><![CDATA[cepics]]></dc:creator><pubDate>Wed, 04 Mar 2020 22:21:30 GMT</pubDate></item></channel></rss>