Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: Teensy 4.0 and I2C

  1. #1
    Junior Member
    Join Date
    Sep 2021
    Posts
    2

    Teensy 4.0 and I2C

    What would cause an I2C scan to show all addresses being active when there should be no for this to happen? That is what happens when I run my simple I2C bus scanner script on a Teensy 4.0. I have never seen this before.
    Code:
    # Import all board pins.
    from machine import SoftI2C, Pin
    from micropython import const
    
    HW_I2C0_SDA                     = const(18)
    HW_I2C0_SCL                     = const(19)
    
    HW_I2C1_SDA                     = const(17)
    HW_I2C1_SCL                     = const(16)
    
    TP_SDA = Pin(HW_I2C0_SDA)
    TP_SCL = Pin(HW_I2C0_SCL)
    
    # Create the I2C interface.
    i2c = SoftI2C(sda=TP_SDA, scl=TP_SCL, freq=400000)
    
    print()
    print("Simple I2C bus scanner")
    print()
    
    scan = i2c.scan()
    
    if scan:
    	print("Devices on the I2C bus:")
    
    	for addr in scan:
    		print("\tDecimal: {0:3d}, Hex: {1}".format(addr, hex(addr)))
    else:
      print("There are no devices on the I2C bus")
    
    print()

    8-Dale
    Last edited by hybotics; 09-10-2021 at 08:48 PM. Reason: Added code

  2. #2
    Senior Member
    Join Date
    Apr 2020
    Location
    DFW area in Texas
    Posts
    297
    Quote Originally Posted by hybotics View Post
    What would cause an I2C scan to show all addresses being active when there should be no for this to happen? That is what happens when I run my simple I2C bus scanner script on a Teensy 4.0. I have never seen this before.
    Code:
    # Import all board pins.
    from machine import SoftI2C, Pin
    from micropython import const
    
    HW_I2C0_SDA                     = const(18)
    HW_I2C0_SCL                     = const(19)
    
    HW_I2C1_SDA                     = const(17)
    HW_I2C1_SCL                     = const(16)
    
    TP_SDA = Pin(HW_I2C0_SDA)
    TP_SCL = Pin(HW_I2C0_SCL)
    
    # Create the I2C interface.
    i2c = SoftI2C(sda=TP_SDA, scl=TP_SCL, freq=400000)
    
    print()
    print("Simple I2C bus scanner")
    print()
    
    scan = i2c.scan()
    
    if scan:
    	print("Devices on the I2C bus:")
    
    	for addr in scan:
    		print("\tDecimal: {0:3d}, Hex: {1}".format(addr, hex(addr)))
    else:
      print("There are no devices on the I2C bus")
    
    print()

    8-Dale
    Did you post the actual source that you are building & loading into the T4.0 ?? Are you using the Arduino IDE to build ?? What you posted does not build in the Arduino IDE & throws syntax errors on the first line.

    I must be missing something obvious . . . I'd like to help, but will need more info to make that possible !!

    Mark J Culross
    KD5RXT

  3. #3
    Member
    Join Date
    Aug 2018
    Location
    Brisbane, Australia
    Posts
    77
    Umm Mark. Its python not C++

  4. #4
    Junior Member
    Join Date
    Sep 2021
    Posts
    2
    Quote Originally Posted by kd5rxt-mark View Post
    Did you post the actual source that you are building & loading into the T4.0 ?? Are you using the Arduino IDE to build ??
    It is Micropython code that runs right on an MCU.

    Quote Originally Posted by kd5rxt-mark View Post
    What you posted does not build in the Arduino IDE & throws syntax errors on the first line.
    Of course, it does not build in the Arduino IDE. I am surprised that you did not recognize it is not Arduino code.
    MicroPython v1.16-236-gb51e7e9d0 on 2021-08-21; Teensy 4.0 with MIMXRT1062DVJ6A

    8-Dale

  5. #5
    Senior Member
    Join Date
    Apr 2020
    Location
    DFW area in Texas
    Posts
    297
    Quote Originally Posted by hybotics View Post
    It is Micropython code that runs right on an MCU.


    MicroPython v1.16-236-gb51e7e9d0 on 2021-08-21; Teensy 4.0 with MIMXRT1062DVJ6A

    8-Dale
    8-Dale:

    I was missing something very obvious !! I have not used MicroPython, so not recognizable as such to me. Sorry (both that I didn't recognize it & that I can't be of any help) !!

    Mark J Culross
    KD5RXT

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •