Author Topic: scan for slave address on i2c bus  (Read 2799 times)

m777

  • Newbie
  • *
  • Posts: 10
scan for slave address on i2c bus
« on: October 21, 2014, 02:08:47 PM »
Hello,

I need help in writing a code for scanning the slave address of a device in python.  I'm in the process of writing command bytes to a slave device.  My user interface is supposed to show: slave address found or not found.  Thanks in advance.

m777

  • Newbie
  • *
  • Posts: 10
Re: scan for slave address on i2c bus
« Reply #1 on: October 21, 2014, 05:35:25 PM »
Anybody out there who can help me?  If none, I'll use Arduino instead in my project.

richard

  • Administrator
  • Jr. Member
  • *****
  • Posts: 95
Re: scan for slave address on i2c bus
« Reply #2 on: October 21, 2014, 08:26:46 PM »
I addressed one of your questions in the setup and usage section:
http://www.circuitsforfun.com/smf/index.php?topic=68.0

Let me know if that helps you get started.

As for scanning specifically, I would need to see the data sheet for the device you are trying to scan for.
Most i2c devices that I have  worked with usually have a register you can read that will return some information about the device, ID, Version, etc.
Each device is different on what that register is and what / how it will return that information.

If you would like to share the component part number or link to a datasheet and any code you have developed so far I would be more than happy to help you out.

m777

  • Newbie
  • *
  • Posts: 10
Re: scan for slave address on i2c bus
« Reply #3 on: October 22, 2014, 02:04:17 PM »
Thank you so much for your help.  This will help me get started.  For the slave address scanning question, here is the link.
http://micrel.com.  search for part number MIC23156.   I can't attached the file because it's too big.  I appreciate your help.

riklaunim

  • Newbie
  • *
  • Posts: 48
Re: scan for slave address on i2c bus
« Reply #4 on: October 25, 2014, 11:47:54 AM »
I2C is slightly unusual on pyMCU than on Arduino and other following similar API. Thats makes is harder to copy-port the code. MicroPython on pyboard is better, but still, I don't like I2C for some reasons... serial rules :)

m777

  • Newbie
  • *
  • Posts: 10
Re: scan for slave address on i2c bus
« Reply #5 on: October 29, 2014, 03:26:40 PM »
Hello Richard

Here's the test code I use for i2c slave address scanning.  I'm not sure if this is the right way of doing it.
The scanning runs very slow around 1 second per loop.  If the address is 0x5B (decimal 91), it would take 91 seconds to find the address.  What is the best way to scan the slave address of a device faster?  I appreciate your help.  Thanks.

import pymcu
mb = pymcu.mcuModule()

for S_ADDR in range(0, 127):  # scan for device slave address
    ADDR = mb.i2cRead((S_ADDR << 1) + 1, 0x00, 1)
    result = str(ADDR)[1:-1]  # if address found, result to 0
    if result == '0':
        print 'slave address found'
        print S_ADDR
        break
    else:  # if not found, result is empty
        print 'slave address not found'
        print S_ADDR

m777

  • Newbie
  • *
  • Posts: 10
Re: scan for slave address on i2c bus
« Reply #6 on: November 07, 2014, 01:38:19 PM »
Does Pymcu has a function for scanning the slave address of any device?

m777

  • Newbie
  • *
  • Posts: 10
Re: scan for slave address on i2c bus
« Reply #7 on: December 08, 2014, 03:17:06 PM »
Hi Richard,

Can you add an i2c scan function?  I would like to use this board for testing the memory address of our parts by sending data bytes.  Thanks.