Closed alphanumeric007 closed 2 years ago
The two things are not cross compatible and probably wont ever be. You'd need to use both with their respective libraries.
(I suppose it's possible to make Pimoroni I2C's interface compatible with machine.I2C
somewhat, but it really only exists as a pointer to an instance of the C++ I2C wrapper and doesn't implement any IO functionality visible to the Python layer)
Pimoroni I2C was written primarily to serve the C++ libraries and then wrapped in MicroPython so the code between C++ / MicroPython bindings wouldn't have to diverge too much.
That's pretty well what Hel Gibbons told be. I could have sworn I had the VEML6075 working with the other breakouts? If so I've lost that file / info somewhere along the way. How much work is it to make a Pimoroni Micro Python library for the VEML6075?
Have I got a PR for you - https://github.com/pimoroni/pimoroni-pico/pull/361
Turns out most of machine.I2C
is implemented as an extmod which is inherited by the port-specific version responsible for implementing how I2C transfer actually happen.
I can borrow that code, extending Pimoroni I2C to be completely interchangeable with machine.I2C()
.
The downside of this is a potential memory leak on the Pimoroni I2C object. We should probably try to use m_new
to alloc this into MicroPython's memory so the GC will at least clean up the used memory, even if it doesn't call the class deconstructor.
Releases here - https://github.com/pimoroni/pimoroni-pico/actions/runs/2339289458
magic:
>>> import pimoroni_i2c
>>> PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
>>> i2c = pimoroni_i2c.PimoroniI2C(**PINS_BREAKOUT_GARDEN, baudrate=2_000_000)
>>> dir(i2c)
['__class__', 'readinto', 'start', 'stop', 'write', 'init', 'readfrom', 'readfrom_into', 'readfrom_mem', 'readfrom_mem_into', 'scan', 'writeto', 'writeto_mem', 'writevto']
>>> i2c.scan()
[41]
>>>
That worked, as near as I can tell anyway. I'm getting values back, and no error messages. Breaks my dual display setup though? ImportError: no module named 'st7789'
Yup, it'll need merged in to main along with the dual display stuff for it all to work together :grimacing:
I had feeling it was something like that. Thanks again Phil, =) I'll be watching for this to all become official.
Because I am a glutton for punishment I have also changed every single one of our I2C based sensors to accept machine.I2C
and internally promote it to PimoroniI2C
so things work both ways around... this has some drawbacks explained in my PR but also tidies up a few things for the better.
I would generally recommend using PimoroniI2C
since it doesn't rely on magically creating new I2C objects behind the scenes, but on the off chance anyone expects machine.I2C
to work (a perfectly reasonable expectation to be fair)... it now should.
If you want to see if it explodes with any of your sensors using machine.I2C
and/or PimoroniI2C
you can find builds here:
https://github.com/pimoroni/pimoroni-pico/actions/runs/2344622982
I'm broadly keen to avoid not-invented-here syndrome and get us closer to MicroPython rather than weird-Pimoroni-distorted-MicroPython. This has been a wild ride.
Thanks Phil. Downloading as I type this. This is what all my pestering is in aid of. https://forums.pimoroni.com/t/pi-pico-based-weather-station-project/19503/2
I've merged everything into main and released a beta build for you - and others - to try out: https://github.com/pimoroni/pimoroni-pico/releases/tag/v1.18.8
Awesome, downloading now. Should have the Pico Lip 16mb image tested before the day is out.
Just dropped that new uf2 file to my Pico Lipo 16mb. Everything still works and I now have my UV sensor working. =)
I can't thank you enough for taking the time to do all this. All I have left sensor wise is the rain gauge and wind speed and direction. I'm not expecting any issues there, lots of code out there for that stuff.
Thank you- it's invaluable to have someone other than me actually trying these changes and feeding back so quickly!
And, of course, an awesome project to justify them :laughing:
I have a Pimoroni VEML6076 UV sensor breakout that I want to use in Micro Python on a Pi Pico. It's discontinued so there is no Pimoroni Micro Python library. I have found one that does work in Micro Python using machine i2c.
The library file is as follows
The pickle I'm in is the above won't work if I try to use the Pimoroni i2c. If I substitute in the following: from pimoroni_i2c import PimoroniI2C PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5} PINS_PICO_EXPLORER = {"sda": 20, "scl": 21} i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN) I get AttributeError: 'pimoroni_i2c' object has no attribute 'readfrom_mem_into'
And if I try to use any of the Pimoroni i2c breakouts with machine i2c
from breakout_bme280 import BreakoutBME280 bme = BreakoutBME280(i2c) I get ValueError: BreakoutBME280: Bad i2C object?
Any help with this would be greatly appreciated.