dbrosy
Posts: 4
Joined: Sun Aug 30, 2015 6:46 am

i2cdetect

Wed Sep 09, 2015 9:56 am

Is there a tool for detecting devices connected to i2c bus?

I'm looking for something for windows iot and don't mind if its just c#

i have seen seen demo videos but no actual tools

cheers,

Damian

haroldpulcher
Posts: 58
Joined: Tue Jun 09, 2015 8:08 pm
Contact: Website

Re: i2cdetect

Wed Sep 09, 2015 1:26 pm

I would head over to the windowsondevices.com site:

http://ms-iot.github.io/content/en-US/w ... stTool.htm

It is a tool that you need to compile and load onto the rpi that is a command line interface to the i2c stuff.

Pretty low level, but it may help.

ricl
Posts: 657
Joined: Wed Aug 26, 2015 11:55 am

Re: i2cdetect

Wed Sep 09, 2015 1:42 pm

ricl : F/gamma = ma : Law ii(a) : https://climatedatablog.wordpress.com/2016/01/02/an-energy-challenge-2016/ #AnEnergyChallenge2016

User avatar
DougieLawson
Posts: 35836
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: i2cdetect

Wed Sep 09, 2015 4:32 pm

dbrosy wrote:Is there a tool for detecting devices connected to i2c bus?
The normal way you do it is to write to each address from 0x00 to 0x7F and see which devices give any reply.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

vidalsasoon
Posts: 2
Joined: Sun Aug 16, 2015 1:46 pm
Location: Montreal

Re: i2cdetect

Sun Sep 27, 2015 1:46 pm

I didn't find one for C# so I made a primitive one. Basically it tries to read some data from each address and returns either "success" or "failed" for the hex address.

Code: Select all

		public async Task<bool> FindI2CAddressesAsync(Func<Message, Task> onMessageReceived)
		{
			string aqs = I2cDevice.GetDeviceSelector("I2C1");

			var i2CDevices = await DeviceInformation.FindAllAsync(aqs).AsTask().ConfigureAwait(false);
			if (i2CDevices.Count == 0)
			{
				await onMessageReceived(new Message("bus not found")).ConfigureAwait(false);
				return false;
			}

			for (byte slaveAddress = 0x00; slaveAddress <= 0x7F; slaveAddress++)
			{

				var settings = new I2cConnectionSettings(slaveAddress)
				{
					BusSpeed = I2cBusSpeed.FastMode,
					SharingMode = I2cSharingMode.Shared
				};

				foreach (var i2CDevice in i2CDevices)
				{
					var i2CDeviceDetails = await I2cDevice.FromIdAsync(i2CDevice.Id, settings).AsTask().ConfigureAwait(false);

					try
					{
						var testCommand = new byte[] { 0x00, 0x0 };
						i2CDeviceDetails.Read(testCommand);

						await onMessageReceived(new Message($"SlaveAddress: {settings.SlaveAddress:X} SUCCESS \n"));
					}
					catch(Exception)
					{
						await onMessageReceived(new Message($"SlaveAddress: {settings.SlaveAddress:X} FAILED \n"));
					}
				}
			}

			return false;
		}

Return to “Windows 10 for IoT”