Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 15:23 15 Sep 2026 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : PicoMite i2c scanner

Author Message
Calli
Regular Member

Joined: 20/10/2021
Location: Germany
Posts: 74
Posted: 06:10pm 28 Oct 2021
Copy link to clipboard 
Print this post

I did a i2c scanner like i2cdetect in linux.

Maybe helpfull for stuff :) (I try to get a VL53L0X to talk to me)


' i2cdetect like program

' Set Pins!
SetPin gp8, gp9, I2C

' Open first I2C
I2C open 100, 200


' Prep table
Print "     0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F"

' loop col/row
For y=0 To 7
 Print Hex$(y,2);": ";
 For x=0 To 15
   addr = y*16+x               ' calc address
   I2C write addr, 0, 1, &H00  ' write zerp to that adress
   If MM.I2C=0 Then            ' check for errors
     Print Hex$(addr,2);" ";   ' found one!
  Else
    Print "-- ";               ' nothing here..
  EndIf
 Next x
 Print
Next y

I2C close  ' clean up


Output:


    0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
00: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
01: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
02: -- -- -- -- -- -- -- -- -- 29 -- -- -- -- -- --
03: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
04: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
05: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
06: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
07: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --



Best,
Carsten
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 9128
Posted: 06:19pm 28 Oct 2021
Copy link to clipboard 
Print this post

That looks useful, thanks. :)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1769
Posted: 06:42pm 28 Oct 2021
Copy link to clipboard 
Print this post

Hi Carsten,

welcome to the TBS!
Your scanner seems very usefull and good looking!

I hope there will be a lot more code examples!

FYI: A similar scanner was one of my first projects for MMBasic too.

Best regards
Michael
Edited 2021-10-29 04:44 by twofingers
‚My name is Ozymandias, king of kings
Look on my works, ye Mighty, and despair!‘
Nothing beside remains. Round the decay
Of that colossal wreck, boundless and bare
The lone and ...
 
Calli
Regular Member

Joined: 20/10/2021
Location: Germany
Posts: 74
Posted: 08:03pm 28 Oct 2021
Copy link to clipboard 
Print this post

  twofingers said  Hi Carsten,

welcome to the TBS!
Your scanner seems very usefull and good looking!

I hope there will be a lot more code examples!

FYI: A similar scanner was one of my first projects for MMBasic too.

Best regards
Michael


Sharing is caring :)

Thanks!

Carsten
 
steview_de
Newbie

Joined: 02/11/2022
Location: Germany
Posts: 12
Posted: 08:21pm 07 Dec 2022
Copy link to clipboard 
Print this post

Hey Calli,
thanks for the useful code.
Due to "OPTION  xxx" i dont need SetPin and I2C open for my purpose.

"Stevie"
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 3379
Posted: 09:14pm 07 Dec 2022
Copy link to clipboard 
Print this post

Here is a PicoMite System I2C and I2C2 Address Scanner.
Print "PicoMite System I2C and I2C2 Address Scanner"
'
SDA = 4 : SCL = 5 ' I2C2 pins. Change pins to your usage, 0 if no I2C2
' (Do NOT use GP numbers, standard Pico RP2040 module pin numbers only)
Print
again = 1
Print "For System I2C"
Scan
If SDA Then
  SetPin SDA, SCL, i2c2
  I2C2 open 100,1000
  Print "For I2C2 - SDA = Pin("SDA"), SCL = Pin("SCL")"
  again = 0
  Scan
  I2C2 close
 Else
  Print "I2C2 not configured"
EndIf
'
Sub Scan
 Print "     0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F" ' Prep table
' loop col/row
 For y=0 To 7
  Print Hex$(y,2);": ";
  For x=0 To 15
   addr = y*16+x               ' calc address
   If again Then
     On Error Skip 3
     I2C write addr, 0, 1, &H00  ' write 0 to that adress
    Else
     I2C2 write addr, 0, 1, &H00  ' write 0 to that adress
   EndIf
   If MM.Errno = 0 Then
     If MM.I2C=0 Then            ' check for errors
       Print Hex$(addr,2);" ";   ' found one!
       device=addr
      Else
       Print "-- ";               ' nothing here..
     EndIf
    Else
     Print " I2C not configured"
   EndIf
  Next x

'  -------------- Add your favorite devices here ------------------

  If device = &H68 Then : Print "RTC DS3232, DS1307 etc"; : device=0 : EndIf
  If (device > &H49) And (device < &H58) Then : Print "24Cxx EEPROM"; : device=0 : EndIf
  If device = &H3C Then : Print "LCD SSD1306"; : device=0 : EndIf

  Print
 Next y
 Print
End Sub
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026