I2C sensor with WiPy2
Eric24 last edited by
Yes, this is a fairly complex device that requires a lot of initialization (although I would think reading back the model ID could be done without init, but who knows). We used this driver: https://github.com/luciengaitskell/python-adafruit-vl6180x/blob/master/i2c/vl6180x.py
We've since moved on from using this sensor (it's a very interesting device, but it did not work well in our particular application), but I had no problem communicating with it. In fact, the only problems I've ever had with I2C on any pycom device was with the lack of clock stretching support on the software-based I2C (and now that hardware-based I2C is supported, that's no longer a problem).
livius last edited by
If you look at C library
you must do much more work to work with this sensor
@robert-hh Thanks for that insight, that turned out to be exactly what's happening! And after doing a closer inspection in the datasheet I found this sentence:
"After the first data byte has been transferred, the index is automatically incremented by 1."
Now on to learning how to use that feature.
I might have missunderstood how it works, but how can I read a specific device register without it?
The machine-module documentation says in connection to readfrom_mem:
"Some I2C devices act as a memory device (or set of registers)", and I interpreted that to mean that it's the function to use when targeting a specific register.
Is that instead referring to devices with some other register functionality?
I just now tried doing
i2c.writeto(0x29, 0), which returned 1, and then
i2c.readfrom(0x29, 1), but it didn't return any useful values, mostly zeroes but sometimes other values. If I understood your suggestion correct that should have given me the 'b4' I want.
robert-hh last edited by
@SesamProductions So it looks as if instead just the first byte all registers of the first group are transferred. I wonder why you use i2c.readfrom_mem(), since this is not a memory device. I would expect that you first have to send the register address with i2c.writeto() and then read back the intended number of bytes with i2c.readfrom().
@livius Thanks for the tip, I had not noticed that there were new firmwares out. Unfortunately it didn't help.
Do I have to make any changes to my code with this?
I have now tried this with two different WIPy2 borads with the most recent firmware. I have also tried with two different identical sensor boards, as well as three other i2c-devices, none gives any sensible output to the WiPy, but all work well with Arduinos.
I did notice one thing that could possibly be relevant, although I have no idea how.
This is a readout made just after reboot:
>>> os.uname() (sysname='WiPy', nodename='WiPy', release='1.7.6.b1', version='v1.8.6-703-g5e80328a on 2017-07-05', machine='WiPy with ESP32') >>> from machine import I2C >>> i = I2C(0, I2C.MASTER) >>> i.scan() [41, 57, 87, 104] >>> i.readfrom_mem(0x29, 0, 1) b'\xb4' >>> i.readfrom_mem(0x29, 0, 1) b'\x01' >>> i.readfrom_mem(0x29, 0, 1) b'\x03' >>> i.readfrom_mem(0x29, 0, 1) b'\x01' >>> i.readfrom_mem(0x29, 0, 1) b'\x02' >>> i.readfrom_mem(0x29, 0, 1) b'r' >>> i.readfrom_mem(0x29, 0, 1) b'C' >>> i.readfrom_mem(0x29, 0, 1) b'\xe9' >>> i.readfrom_mem(0x29, 0, 1) b'\xa0'
The first response,
b'\xb4', is the correct one, but should not change. The commands are sent about one second apart.
The interesting thing is that the response sequence is always identical, with both sensors and both boards, it's always:
and so on.
I have absolutely no idea what's wrong or what to try next and will appreciate any help!
livius last edited by livius
try upgrade to recent firmware because now i2c is hardware implementation not software as was previously
(sysname='WiPy', nodename='WiPy', release='1.7.2.b1', version='v1.8.6-650-g9bacbbd4 on 2017-06-09', machine='WiPy with ESP32')
livius last edited by