User Tools

Site Tools


check_device_i2c_address

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
check_device_i2c_address [2026/08/18 22:01] – [I2C Address Check] walkeradmincheck_device_i2c_address [2026/08/19 12:18] (current) – [I2C Address Check] walkeradmin
Line 7: Line 7:
 ===== Introduction ===== ===== Introduction =====
 \\  \\ 
-When you attach a device on the I2C bus, even though you might know it's address, it's a great idea to run a test to see if you can read it's actual address.+When you attach a device on the I2C bus, even though you might know it's address, it's a great idea to run a test to see if you can read it's actual address. The achieves two things, it proves  your wiring is good, because if you don't have the correct cabling, this script will fail, and it proves that the device does appear to function.
 \\  \\ 
 \\  \\ 
-In this example, I have an LCD address on I2C bus zero, and I know it's address is 3C0 Hex, which in decimal is 60.+In this example, I have an LCD address on I2C bus zero, and I know it's address is 3C0 Hex, which in decimal is 60. So this test will confirm that my assumptions about my device address is good.
 \\  \\ 
 \\  \\ 
Line 16: Line 16:
 ==== I2C Address Check ==== ==== I2C Address Check ====
 \\  \\ 
-Below is the code we need to run to check for devices on the I2C.+Below is the code we need to run to check for devices on the I2C. This script uses standard built in libraries, so you won't need to go hunting for any extra library files, you Pico (or RP2040 device) will be good to go.
  
-<code | download>+<code:python | download>
 from machine import Pin, I2C from machine import Pin, I2C
  
Line 29: Line 29:
   * i2c = I2C(0 - The Zero is for Bus 0   * i2c = I2C(0 - The Zero is for Bus 0
  
-The Pico has Bus 0 and Bus 1, and you should know which you used. +The Pico has Bus 0 and Bus 1, and you should know which you used. If you have connected your device to Bus 1, then change this zero  
-\\  + 
-  * scl=Pin(5), sda=Pin(4)+  * i2c = I2C(<color #ed1c24>0</color>, scl=Pin(5), sda=Pin(4), freq=200000) to a 1.
  
 These are the Pico pins your device is connected to, so scl(5) is Pico Pin 7 and sda(4)  is Pico pin 6. These are the Pico pins your device is connected to, so scl(5) is Pico Pin 7 and sda(4)  is Pico pin 6.
 +
 +  * scl=Pin(5), sda=Pin(4)
 +
 +If you run the code above, you will see something similar to below:
 \\  \\ 
 \\  \\ 
-If you run the code above, you will see something similar to below:+{{ :pico_i2c_address.png?800 |}}
 \\  \\ 
 +Here we can see the I2C address is listed as <color #00a2e8>60</color> and this is a Decimal address. 
 \\  \\ 
- 
 \\  \\ 
 +If you convert <color #00a2e8>60 Dec</color> to Hex, then you get <color #00a2e8>Hex 3C</color>, which is exactly the address the LCD is currently set to. 
 +\\  
 +\\  
 +----
check_device_i2c_address.1787090509.txt.gz · Last modified: by walkeradmin