VL6180x not connecting by I2C to maple mini r2 by Baite

Working libraries, libraries being ported and related hardware
Post Reply
Nelejse
Posts: 5
Joined: Wed May 05, 2021 9:34 pm

VL6180x not connecting by I2C to maple mini r2 by Baite

Post by Nelejse »

Hi!
I have problem with my maple mini r2 by Baite. I try to use Vl6180x ToF sensor but I can't connect it to my board. I tried both I2C connections on the board (PB6,PB7 and PB10,PB11). I checked if my I2C is working at all and used examples I2C_scanner_wire and I2C_scanner_softwire. Using wire no device can be found and using softwire I get message that mostly all addresses are found. I don't know what to do. Tried to get answers by searching this forum and Roger's GitHub site but no results.
Thanks for your time and all responds.
Regards!
mrburnette
Posts: 615
Joined: Thu Dec 19, 2019 1:23 am
Answers: 6

Re: VL6180x not connecting by I2C to maple mini r2 by Baite

Post by mrburnette »

Using wire no device can be found and using softwire I get message that mostly all addresses are found.
Maybe you forgot about:
https://electronics.stackexchange.com/q ... al-pullups

Good read:
http://www.mosaic-industries.com/embedd ... ifications
Nelejse
Posts: 5
Joined: Wed May 05, 2021 9:34 pm

Re: VL6180x not connecting by I2C to maple mini r2 by Baite

Post by Nelejse »

Sorry for no response for so long. I bought couple of resistors and tried them out with no success. I am new with Maple Mini and I started to think about scanners examples in Arduino IDE. Are they compatible with Maple Mini? Because I tried many resistors from 10 Ohm to 50k Ohm. Now when I try to scan I2C there is no response in COM port. When I plug out connections from I2C during soft scanning I get information that all addresses are correct. I also tried to use example sketches from Pololu VL6180X also with no success. I would really appreciate any suggestion.
ag123
Posts: 1089
Joined: Thu Dec 19, 2019 5:30 am
Answers: 9

Re: VL6180x not connecting by I2C to maple mini r2 by Baite

Post by ag123 »

normally a few hundred ohms to say 1k-3kohm should be ok, some boards has those resistors done for you. use those module boads with the resistors on board if possible.
among the things, in the wire example, u'd need to run the example sketch in the l2c lib to scan for connected i2c, their address should show up in the i2c device list. if they don't it means they are not even detected.

For other cases it may help to setup a debug setup with st-link etc and debug away. tracing codes may give hints on what may be wrong.
that is quite an 'advanced' topic, there are some hints here:
https://github.com/stm32duino/wiki/wiki/How-to-debug

In more difficult cases a logic analyser may help, by literally measuring signals on the wire and ploting them on a chart. i made one here from stm32f401ccu blackpill board:
viewtopic.php?f=10&t=116
this is probably a 'last resort'. If you have a scope that'd be better, it is likely more than 99% of tinkerers won't have that expensive equipment.
Nelejse
Posts: 5
Joined: Wed May 05, 2021 9:34 pm

Re: VL6180x not connecting by I2C to maple mini r2 by Baite

Post by Nelejse »

Sorry I am very new to I2C, actually it is first time I am going to use it, so I don't even know what might be wrong. I guessed it's problem with my board but everything else work perfectly, also I tried bots I2C on maple mini and both don't work. I assumed it is rather strange that both pairs of pins don't work. I started checking my sensor but they seem to be fine. Could you explain a little more about your comment? For example what it means I should run scanner in I2C lib. Also if it comes about debugging I only use built in USB port to load sketches from Arduino IDE.
ag123
Posts: 1089
Joined: Thu Dec 19, 2019 5:30 am
Answers: 9

Re: VL6180x not connecting by I2C to maple mini r2 by Baite

Post by ag123 »

libmaple core is 'old' but that not many who are still using it still visited here often it seemed.
if you are using this library (Wire)
https://github.com/rogerclarkmelbourne/ ... aries/Wire
try out the example sketch alone
https://github.com/rogerclarkmelbourne/ ... anner_wire
this 'scanner' uses features of i2c such as 'ack' response, to test if a device is present at the address.
It need to find your device and tell you the address first.
once it finds the *address*, then check in your codes to see if the codes is connecting to the appropriate i2c address.

if the scanner don't list the addresses for the device, you have a connectivity problem with the device (sensor).
check wires etc to see that things are after all connected correctly.
and that you are using the correct i2c peripheral (e.g. i2c 1 or i2c 2 etc) and that those are connected at the correct *pins*

if the scanner works, you may want to write a little code like read a particular register using Wire(),
check the datasheet of the sensor for the register definitions. it should return some values you can expect.
e.g. there is register 0 that is supposed to return an ID, so that should return an ID.
according to the specs it is some value such as 0xB4 as a return value from a Wire.read(); from datasheet:
6.2 Register descriptions
6.2.1 IDENTIFICATION__MODEL_ID

Device model identification number. 0xB4 = VL6180X

keep the datasheets handy to lookup the pins
https://www.st.com/en/microcontrollers- ... 103cb.html
keep the *reference manual rm0008* handy in case you'd need to dig into how things work on stm32
https://www.st.com/resource/en/referenc ... ronics.pdf

and keep the datasheets / specs of the sensor handy
https://www.st.com/en/imaging-and-photo ... 6180x.html


one thing though we'd assume that you have no issues blinking the led etc.

always have a led blinking away to see that things are 'alive'

Code: Select all

void setup() {
	pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
	togglePin(LED_BUILTIN);
	delay(1);
}
ag123
Posts: 1089
Joined: Thu Dec 19, 2019 5:30 am
Answers: 9

Re: VL6180x not connecting by I2C to maple mini r2 by Baite

Post by ag123 »

other tricks i'd normally do includes, copy the 'drivers' and the scanner sketch into the sketch folder and try using them from there
https://github.com/rogerclarkmelbourne/ ... ire/Wire.h
https://github.com/rogerclarkmelbourne/ ... e/Wire.cpp
https://github.com/rogerclarkmelbourne/ ... r_wire.ino

do take note of codes like such
https://github.com/rogerclarkmelbourne/ ... Wire.h#L82

Code: Select all

extern TwoWire Wire;
and codes like this
https://github.com/rogerclarkmelbourne/ ... re.cpp#L65

Code: Select all

TwoWire::TwoWire(uint8 dev_sel, uint8 flags, uint32 freq) {
    
	if (dev_sel == 1) {
        sel_hard = I2C1;
    } else if (dev_sel == 2) {
        sel_hard = I2C2;
    } else {
        ASSERT(1);
    }
    dev_flags = flags;

	if (freq == 100000 && (flags & I2C_FAST_MODE))  // compatibility patch
		frequency = 400000;
	else
		frequency = freq;

}
and in the scanner codes
https://github.com/rogerclarkmelbourne/ ... re.ino#L27

Code: Select all

#include <Wire.h>

//use IIC2
//TwoWire WIRE2 (2,I2C_FAST_MODE);
//#define Wire WIRE2


void setup() {

  Serial.begin(115200);
  Wire.begin();
  Serial.println("\nI2C Scanner");
}


void loop() {
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++) {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.

    Wire.beginTransmission(address);
    error = Wire.endTransmission();
it'd be better to initialize your Wire instance as appropriate, in the scanner sketch e.g.

Code: Select all

#include <Wire.h>

TwoWire WIRE1 (1,I2C_FAST_MODE);
TwoWire WIRE2 (2,I2C_FAST_MODE);
// choose the appropriate wire pheriperial i2c 1 or i2c 2
#define Wire WIRE2

void setup() {

  Serial.begin(115200);
  Wire.begin();
  Serial.println("\nI2C Scanner");
}


void loop() {
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

it may be necessary to comment that extern in the Wire.h include to prevent picking up the incorrect Wire instance.
Post Reply

Return to “Libraries & Hardware”