Hammer-Head7 / Arduino

0 stars 0 forks source link

距離センサー VL53L0Xのエラー対処方法 #1

Open Hammer-Head7 opened 1 year ago

Hammer-Head7 commented 1 year ago

VL53L0Xを使用した時に「Failed to detect and initialize sensor!」とエラーが出てしまいました。 その対処方法がほとんど英語の文献でわかりづらかったので、開発の参考になるようここに忘備録として置いておきます。 個人開発なので間違っている可能性もあります。それについてはご容赦お願いします。 ちなみに私が使っているマイコンとセンサーについては下記に記載しておきます。

使用Arduino  ・ESP8266(LOLIN (WEMOS) D1 R2 & mini)(Aliexpress) 購入先URL:https://ja.aliexpress.com/item/32843721010.html?spm=a2g0o.order_list.0.0.1875585aLgJ1qW&gatewayAdapt=glo2jpn

センサー  ・VL53L0X(スイッチサイエンス) 購入先URL:https://www.switch-science.com/products/2894?variant=42381945798854

Hammer-Head7 commented 1 year ago

エラーが出た時はこんな感じでした

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Soft WDT reset

stack>>>

ctx: cont sp: 3ffffdf0 end: 3fffffc0 offset: 01a0 3fffff90: 3fffdad0 3ffee64c 3ffee4f8 4020106c
3fffffa0: feefeffe 00000000 3ffee6a0 40202a18
3fffffb0: feefeffe feefeffe 3ffe85e0 40100db1
<<<stack<<<

--------------- CUT HERE FOR EXCEPTION DECODER --------------- c_⸮rS⸮fJ⸮j⸮Failed to detect and initialize sensor!

Hammer-Head7 commented 1 year ago

現在は動作しており、変更前と変更後のプログラムをここに記載しておきます。 次のコメントにて配線の変更点を記載しておきます。

変更前プログラム

/* This example shows how to use continuous mode to take range measurements with the VL53L0X. It is based on vl53l0x_ContinuousRanging_Example.c from the VL53L0X API.

The range readings are in units of mm. */

include

include

VL53L0X sensor;

void setup() { Serial.begin(9600); Wire.begin();

sensor.setTimeout(500); if (!sensor.init()) { Serial.println("Failed to detect and initialize sensor!"); while (1) {} }

// Start continuous back-to-back mode (take readings as // fast as possible). To use continuous timed mode // instead, provide a desired inter-measurement period in // ms (e.g. sensor.startContinuous(100)). sensor.startContinuous(); }

void loop() { Serial.print(sensor.readRangeContinuousMillimeters()); if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }

Serial.println(); }

変更後プログラム

/* This example shows how to use continuous mode to take range measurements with the VL53L0X. It is based on vl53l0x_ContinuousRanging_Example.c from the VL53L0X API.

The range readings are in units of mm. */

include

include

VL53L0X sensor;

void setup() { Serial.begin(9600); delay(50); //←変更箇所 Wire.begin();

sensor.setTimeout(500); if (!sensor.init()) { Serial.println("Failed to detect and initialize sensor!"); while (1) {} }

// Start continuous back-to-back mode (take readings as // fast as possible). To use continuous timed mode // instead, provide a desired inter-measurement period in // ms (e.g. sensor.startContinuous(100)). sensor.startContinuous(); }

void loop() { Serial.print(sensor.readRangeContinuousMillimeters()); if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }

Serial.println(); }

Hammer-Head7 commented 1 year ago

そして、配線については以下のようになります。 変更前

VCC- 3V3 GND- G SDA- D2 SCL - D1 XSHUT - × GPIO - ×

変更後 VCC- 5 ← 変更箇所 GND- G SDA- D2 SCL - D1 XSHUT - RST ← 変更箇所 GPIO - ×

Hammer-Head7 commented 1 year ago

プログラムを変えた理由 3V3PINを使用する時、立ち上がったESP8266はすぐには3.3Vにはならず、少し時間をかけて、3.3Vになるそう。

以下参考URL https://arduino.stackexchange.com/questions/78209/failed-to-boot-vl53l0x-vl53l0x-error-6

配線を変更した理由 複数使用するときに起動するための電流値もしくは電圧値が足りなくなる可能性が有るので、5Vに配線し直しました。←動作するけど、取得データ値が65535になる。 ↑この問題3V3でも接続がちゃんとできていれば反応しました。 また、XSHUTについてはI2Cのアドレスを識別するために必要らしい?(まあ本当かどうかは知らんけど....)

以下参考URL https://github.com/pololu/vl53l0x-arduino/issues/33

Hammer-Head7 commented 1 year ago

私が分かったのはこの辺ぐらいです。 まとめ

皆さんの手助けになれば幸いです。ではでは ✋