I am now having trouble getting started with i2c on the teensy 4.1. Based on this:
https://github.com/robert-hh/micropytho ... ickref.rst
I believe i2c hardware port 0 refers to pins 18 (sda) and 19 (scl). I have those pins along with ground and 3.3V connected to a level shifter with an Arduino Uno on the other side (GND, 5V, A4 (sda) and A5 (scl) on the Uno side). I have used this same setup with i2c and a pyboard and everything worked fine.
I am trying to run this simple upython code:
>>> from machine import I2C
>>> i2c = I2C(0, 400_000)
>>> i2c.scan()
[]
>>> i2c.writeto(0x04, b'12')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 19] ENODEV
Since the scan returns nothing, it is not surprising that the writeto fails. As long as I have the pins right, I don't know what could be going wrong.
Any help appreciated.
Thanks,
Ryan
[teensy41] i2c problems
Re: [teensy41] i2c problems
Most probably the pull-up resistors arte missing. PyBoard has 4k7 Ohm pull-up resistors on the board, Teensy does not have such. One remark: the Teensy port runs I2C only in master mode.
Re: [teensy41] i2c problems
Thanks Robert. I would have never thought to check the pullups. I guess I have been spoiled by the devices I have used. This is my first time using a teensy.
For some reason, scan still doesn't work. Not sure if I would have to program my Arduino to follow some protocol there. But I can send a message and have it echoed back based on how I programmed the Arduino. So, it is working.
Thanks again,
Ryan
For some reason, scan still doesn't work. Not sure if I would have to program my Arduino to follow some protocol there. But I can send a message and have it echoed back based on how I programmed the Arduino. So, it is working.
Thanks again,
Ryan
Re: [teensy41] i2c problems
During scan only the address is sent, and the device responds with ACK or NAK.
Re: [teensy41] i2c problems
So, I forgot to include external pullup resistors in a custom arduino shield I made with a level shifter and everything worked fine. I think this is because my level shifter has pullup resistors in it (thought maybe 10K instead of 4k7):
https://learn.sparkfun.com/tutorials/bi ... d-overview
Am I interpreting that correctly? Are 10k pullups good enough between a Teensy 4.1 and an Arduino?
Thanks,
Ryan
https://learn.sparkfun.com/tutorials/bi ... d-overview
Am I interpreting that correctly? Are 10k pullups good enough between a Teensy 4.1 and an Arduino?
Thanks,
Ryan
Re: [teensy41] i2c problems
The one transistor level shifter used for I2C includes pull-up resistors. And 10k is fine for short wires and moderate speed. If you increase the wire length or the frequency, you will need lower pull-up resistors values.
Re: [teensy41] i2c problems
Thanks again. So I pretty much got lucky.
As far as wire length, I'm talking two to three inches maximum as the teensy is plugged into a shield that's mounted on top of the Arduino. So it can only get 3 inches away worse case.
I think you're saying it would always be safer to have stronger pull-ups.
As far as wire length, I'm talking two to three inches maximum as the teensy is plugged into a shield that's mounted on top of the Arduino. So it can only get 3 inches away worse case.
I think you're saying it would always be safer to have stronger pull-ups.
Re: [teensy41] i2c problems
As long as it works it's fine. 10k is a common value at breakout boards. For a better decision, you would have to analyze the signals with an oscilloscope.