shaoziyang / microbit-lib

all kinds of microbit python drives, libs, examples, etc.
MIT License
48 stars 39 forks source link

Need for pullup resistors on SDA and SCL pins #6

Open randmor opened 5 years ago

randmor commented 5 years ago

Last year I had no problem making an I2C_1602_LCD display work with your MicroPython driver. But when I tried it again just yesterday, I found that the software no longer worked. I kept getting an error message like "Line 25 OSError I2C write error -1010". Looking at your code, I decided it must be the wrong I2C address, so I found a couple of I2C_1602_LCD displays with known IC2 Addresses (0x27 and 0x3f) which I then tried to make work with the software changing the line which read "LCD_I2C_ADDR=63" to the appropriate decimal value (63 for 0x3F boards and 39 for 0x27 boards) and still could not make the software work. Anyways, I started over from scratch, with all new hardware, and still no luck. Then I remembered I had another Micro:bit breakout board (a Chinese made ElecFreaks Micro:bit Breakout board called "OCTOPUS Bit v 1.6". When I replaced the SparkFun Micro:bit breakout board with the ElecFreaks board, your MicroPython I2C_1602_LCD driver magically worked. So, I guess last year I was using the ElecFreaks Micro:bit breakout board.

So, then I wondered what the difference might be. After a bit more research on the Internet, I came across an article that says a pull-up resistor of from 5K ohms to 20K ohms is sometimes needed, especially when multiple I2C devices are attached to the same bus. So, I tried two 12K ohm pull-up resistors on the SDA and SCL pins of the SparkFun Micro:bit breakout board, and found it would now work with your I2C_1602_LCD driver. I first tried pulling it up to +3V and later tried pulling the 2 pins up to +5V. In both cases, that was enough pull-up to make the 1602_LCD work.

So, if you have other folks having problems running your MicroPython I2C_1602_LCD drivers on their Micro-bit board, advise them to try a pull-up resistor between SDA and +5V and SCL and +5V. Anything in the range of 5K ohm and 20K ohm should work.

shaoziyang commented 5 years ago

micro:bit use a 4.7K resistor in the board, it is suit for most case. If you meet I2C pullup resistor problem, the resistor in board may not work. Internal weak pullup has no effect for micro:bit hardware I2C, and micropython for micro:bit does not support software I2C now.

And which version of micro:bit do you using? Old version 1.3B or new version 1.5?

randmor commented 5 years ago

Thanks for your feedback.  I don't know how to tell which version of the Micro:bit boards I have. I checked my invoice, the box they came in, and on the board itself, but I saw no indication of a version number. The invoice shows that I ordered and received them six months ago (not one year ago as I had thought).  I did locate a Micro:bit schematic on Version 1.3B and it does show two 4.7K ohm pull-up resistors on SDA and SCL as you said. I imagine the newer version of the board has the same, or better. But, the schematic also shows two other devices on the Micro:bit that share this same I2C bus: the FreeScale MAG3110 magnetometer chip and the FreeScale MMA8653FC accelerometer chip. So, the limit of the Micro:bit's internal pull-up might be easier to reach when you factor these two devices in, and the fact that I was using a SparkFun Micro:bit Break-out board and a foot long 4-wire ribbon of jumper wire between the MB-102 solder-less breadboard and the I2C_1602_LCD display. Given this longer wiring route, the added circuit capacitance could exceed the amount the engineers were assuming when they came up with when they calculated the 4.7K ohm values.  All I know is that with multiple Micro:bit boards (likely same lot), with multiple SparkFun Micro:bit breakout board I consistently get a MicroPython error, but with my single Elec-Freak Micro:bit breakout board, the same software (still burned into FLASH memory on the Micro:bit boards) magically work. I can only conclude that the potential exists where by Micro:bit experimenters can run into problems with the Micro:bit's I2C interface that can be easily resolved by adding a couple 10K pull-up resistors. This information should be general knowledge to the Micro:bit user community.  This problem was never with your software, which I am happy you have made available thru GetHub. Thank you for this and your other Python modules which makes it possible to teach kids more advanced topics than is covered in the basic "Read-the-Docs" MicroPython tutorials.  Have a Happy New Year, -William Moore

   On Thursday, December 27, 2018, 6:13:52 PM PST, shaoziyang notifications@github.com wrote:

micro:bit use a 4.7K resistor in the board, it is suit for most case. If you meet I2C pullup resistor problem, the resistor in board may not work. Internal weak pullup has no effect for micro:bit hardware I2C, and micropython for micro:bit does not support software I2C now.

And which version of micro:bit do you using? Old version 1.3B or new version 1.5?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

shaoziyang commented 5 years ago

I think you still use old version micro:bit, because new version has only ship three month ago. The most different is sensor chip, but function is same.

New version micro:bit with small label in the back, and has only one sensor chip:

image

image

shaoziyang commented 5 years ago

The problem may cause by LCD1602 module, My LCD1602 is work fine without external res, maybe 4.7K res in micro:bit is too large for some LCD1602 module.