|
Forum Index : Microcontroller and PC projects : PicoMite i2c scanner
| Author | Message | ||||
| Calli Regular Member Joined: 20/10/2021 Location: GermanyPosts: 74 |
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 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 KingdomPosts: 9128 |
That looks useful, thanks. :) Mick Zilog Inside! nascom.info for Nascom & Gemini |
||||
| twofingers Guru Joined: 02/06/2014 Location: GermanyPosts: 1769 |
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: GermanyPosts: 74 |
Sharing is caring :) Thanks! Carsten |
||||
| steview_de Newbie Joined: 02/11/2022 Location: GermanyPosts: 12 |
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: AustraliaPosts: 3379 |
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) 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 Next y End Sub |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2026 |