-->
Page 2 of 2

Re: I2C Scanner example

PostPosted: Thu Aug 04, 2016 8:02 am
by trackerj
It's a nEXT Evo board, big brother (or sister) of this one + AN-1 extension board

Re: I2C Scanner example

PostPosted: Sat Aug 27, 2016 12:02 am
by trackerj
Updated code to reflect the latest great I2C feature, the i2c.setup() function !

Will change the default pins for the i2c interface.
i2c.setup({SDA}, {SCL})

Now you can define your I2C bus pins as you wish!

Code: Select alli2c.setup(4,5)

for address = 1 to 127
 i2c.begin(address)
 stat = i2c.end()

 if stat < 1 then
  'print stat
  wprint "Found I2C device at address: 0x" & hex(address)
  wprint " - > " & address
  wprint " <br>"
 endif

next

wait


Also updated the ESPBasic i2c_scanner() example article to reflect the new great feature.

Re: I2C Scanner example

PostPosted: Thu Oct 20, 2016 8:49 pm
by russm
Don't want to take too far off topic but I tried this to find my Wii Nunchuck and no joy. Do I need pullups on the default GPIO00 and GPIO02? Any help would be great. TIA

Re: I2C Scanner example

PostPosted: Thu Oct 20, 2016 11:26 pm
by russm
I figured it out. Scanner worked fine, identified Wii Nunchuck as address 82. Here is code to read the 6 bytes. Now to put them together correctly to do something with them.

Code: Select allmemclear

let address = 82  '82 which is what was scanned
i2c.setup(D3,D4)
i2c.begin(82)
i2c.write(64)
i2c.write(0)

i2c.end()
'delay 10

i2c.begin(82)
i2c.write(0)
i2c.end()
i2c.requestfrom(82,6)
b1 = (val(i2c.read()) xor 23) + 23
b2 = (val(i2c.read()) xor 23) + 23
b3 = i2c.read()
b4 = i2c.read()
b5 = i2c.read()
b6 = i2c.read()

print b1
print b2
print b3
print b4
print b5
print b6