Shop OBEX P1 Docs P2 Docs Learn Events
Debug I2C Scanner and BNO086 oddity — Parallax Forums

Debug I2C Scanner and BNO086 oddity

Made a version of the I2C Scanner in P2 Library from @JonnyMac that uses Debug instead of serial output. This was for my convenience when using Prop Tool.

Seems to be fine with AMG8833 IR grid sensor.
But, when used with BNO086 both it and the original version of the scanner have issues after the first run. The first run always works as it should but later runs mess up...

The Library version gives this sometimes on second run:

P2 I2C Devices
-- dddd_aaa_0 (8-bit) format

   00 02 04 06 08 0A 0C 0E
10 .. .. .. .. .. .. .. ..
20 .. .. .. .. .. .. .. ..
30 .. .. .. .. .. .. .. ..
40 .. .. .. .. .. .. .. ..
50 .. .. .. .. .. .. .. ..
60 .. .. .. .. .. .. .. ..
70 .. .. .. .. .. .. .. ..
80 .. .. .. .. .. .. .. ..
90 .. .. .. 96 98 .. .. ..
A0 .. .. .. .. .. .. .. ..
B0 .. .. .. .. .. .. .. ..
C0 .. .. .. .. .. .. .. ..
D0 .. .. .. .. .. .. .. ..
E0 .. .. .. .. .. .. .. ..

Devices: 2

This is wrong, should only be "96"

Can also give this:

P2 I2C Devices
-- dddd_aaa_0 (8-bit) format

   00 02 04 06 08 0A 0C 0E
10 .. .. .. .. .. .. .. ..
20 .. .. .. .. .. .. .. ..
30 .. .. .. .. .. .. .. ..
40 .. .. .. .. .. .. .. ..
50 .. .. .. .. .. .. .. ..
60 .. .. .. .. .. .. .. ..
70 .. .. .. .. .. .. .. ..
80 .. .. .. .. .. .. .. ..
90 .. .. .. 96 !

Not even sure how this is possible. Sometimes just gives the "!" after "10".
There's not even a "!" in the code, so don't see how this can be.

For the debug version, it just starts showing a device present on all addresses.
How this can be and also be different is also a mystery...

Anyway, seem to have fixed whatever this is by adding a few starts and stops after probing.
But, it doesn't work for the library version, no idea how this can be either...

Anyway, thinking something strange with BNO086 i2c interface...

«1

Comments

  • RaymanRayman Posts: 15,365

    Found a nice 7-bit device address list on Adafruit:
    https://learn.adafruit.com/i2c-addresses/the-list

    Was thinking about starting one, but much better to just use this.
    7-bit seems to be the standard for this kind of list?

    There's a more official looking one here, but it is pretty useless (although the C++ source code could be useful):
    https://i2cdevices.org/devices

  • RaymanRayman Posts: 15,365
    edited 2025-06-14 15:32

    Retested the Library version after just changing baud to 230400 and I2c pins and got this on second run:

    P2 I2C Devices
    -- dddd_aaa_0 (8-bit) format
    
       00 02 04 06 08 0A 0C 0E
    10 .. .. .. .. .. .. .. ..
    20 .. .. .. .. .. .. .. ..
    30 .. .. .. .. .. .. .. ..
    40 .. .. .. .. .. .. .. ..
    50 .. .. .. .. .. .. .. ..
    60 .. .. .. .. .. .. .. ..
    70 .. .. .. .. .. .. .. ..
    80 .. .. .. .. .. .. .. ..
    90 .. .. .. 96 98 9A 9C 9E
    A0 A0 A2 A4 A6 A8 AA AC AE
    B0 B0 B2 B4 B6 B8 BA BC BE
    C0 C0 C2 C4 C6 C8 CA CC CE
    D0 D0 D2 D4 D6 D8 DA DC DE
    E0 E0 E2 E4 E6 E8 EA EC EE
    
    Devices: ?
    
    Done
    

    This is more like what the debug version above used to do before adding start and stop loop...
    Wonder if changing baud has something to do with it... No, same at original baud.

    BNO086 device is just weird ...

  • @Rayman said:
    Found a nice 7-bit device address list on Adafruit:
    https://learn.adafruit.com/i2c-addresses/the-list

    Was thinking about starting one, but much better to just use this.
    7-bit seems to be the standard for this kind of list?

    >

    The 8th bit is used to distinguish between write or read.

  • JonnyMacJonnyMac Posts: 9,378

    As Christof points out, there are 8-bits in the I2C packet, plus a 9th bit for the ACK/NAK. I started with I2C a long time ago using EEPROMS, and those early datasheets always showed 8 bits, though it was indicated that bit0 was for R/W.

    I happened to have an I2C sensor sitting on my desk so I connected it. When everything is working okay, you should see something like this.

    Note that I show the addresses in the matrix as 8-bit, but to help the Schmarschmino crowd I also list them in that format.

    I've been using debug a bit more lately so I'll see if I can convert that program to use a debug window.

  • RaymanRayman Posts: 15,365

    @JonnyMac Used your I2C scanner many times and it's always worked great. This BNO086 thing is first device that acts weird.

    Maybe there's some kind of hardware issue here, but it's just a P2 board connected to Sparkfun BNO086 module over a QWIIC connector...
    Kind of acting like a power issue, maybe should look into that...

  • RaymanRayman Posts: 15,365
    edited 2025-06-15 08:57

    Ok, the serial output above with "!" seems to be a power issue. Switched to another USB port on this laptop and now it acts exactly like with debug (before adding the start/stop loop). That is, first run OK. Second run OK until after it finds it, then thinks something on every address after it. Later runs, thinks something on every address.

    This is a new laptop and did notice earlier that a thumbdrive didn't work with the port was using. Think it must not be providing good power...

    But, it seems the BNO086 is known to be flaky with I2C interface. There's a note in datasheet that you can't do polling with BNO086, if you want to do polling, you should use BNO085. Also, Sparkfun has notes that you have to connect up reset and interrupt lines to use I2C interface with BNO086.

    Reads to me like you can't just talk to the BNO086 whenever you want. You have to wait for interrupt to go low first. And, maybe you have to hard reset the device before it will let you do that.

  • RaymanRayman Posts: 15,365

    Slightly improved version of the debug scanner.
    Loops every second.

    Wish could do the matrix view, but that would take some effort...

  • JonnyMacJonnyMac Posts: 9,378
    edited 2025-06-15 15:23

    Wish could do the matrix view, but that would take some effort...

    Wasn't too bad. It would be nice to have more DEBUG demos to go along with Chip's minimal documentation.

    I used the terminal debug window. That said, most of the debug windows graphic images which is why there is no scroll-back capability, so I removed the devices list that shows the 7-bit version of the devices found.

    (see updated code below)

  • JonnyMacJonnyMac Posts: 9,378
    edited 2025-06-15 15:29

    Here's a version that matches the original (using PST). It would be nice if the term debug window allowed character color to change on-the-fly.

  • RaymanRayman Posts: 15,365
    edited 2025-06-15 16:15

    @JonnyMac Very nice! Didn't know about this "scan" thing. Just what is needed for things like this. That is useful info.

    Seems to work. But, my version of the driver maybe doesn't have "PU_EXT".
    Ok though 'cause had to change anyway:
    I2C_PU = i2c.PU_15K 'PU_EXT

    460 x 563 - 32K
  • JonnyMacJonnyMac Posts: 9,378
    edited 2025-06-16 15:48

    That is the P2 terminal debug window. Kind of works like an old school text terminal. It would be nice if @cgracey would add

    • row/column positioning
    • foreground/background color updates

    I think with these changes one could mimic ANSI terminal behavior.

  • RaymanRayman Posts: 15,365

    Just searched the P2 Spin2 docs for the word "scan" and can't find it... Is it there somewhere?

  • JonnyMacJonnyMac Posts: 9,378
    edited 2025-06-15 20:16

    You have to give your debug windows a name -- I called this one scan.

    Here's my setup for that debug terminal window:

  • RaymanRayman Posts: 15,365

    @JonnyMac
    Think that was enough info to fulfill my wish of using debug like a serial terminal.

    This seems to work...

  • RaymanRayman Posts: 15,365

    Wishing could do yellow on midnight blue, but can't?

  • JonnyMacJonnyMac Posts: 9,378

    That's a really great idea, Ray, and it will help me with my current work project -- so I'm borrowing it! I added the ability to set the window size and font size in the start() method. I scraped a bunch of my code for simple, hopefully useful, output routines. If we can get Chip to add foreground and background color change on-the-fly, this could be really nice.

  • RaymanRayman Posts: 15,365

    @JonnyMac That is nice. Another option for the start() parameters might be to set them in a CON section. Then, use the OBJ section to overwrite the objects constants. Like this:

    OBJ  
    
         pwm       : "PWM_Driver" | p = 8, w = 4  'instantiate "PWM_Driver.spin2" as "pwm" with parameters
    

    Like this way, when remember about it, because can set the parameters or not set them as needed.

  • You can change colors, but only between 4 that you have to declare up-front

  • RaymanRayman Posts: 15,365

    Thanks @Wuerfel_21
    What am I doing wrong?

  • JonnyMacJonnyMac Posts: 9,378

    Like this way, when remember about it, because can set the parameters or not set them as needed.

    I will probably update my version so that passing -1 as an argument sets the default -- I've done that in many objects.

    You can change colors, but only between 4 that you have to declare up-front

    I saw that but have not seen a practical example of defining the color sets, and there is only four sets which seems kind of limiting. That said, I do have a method in my current object that allows one to use the default color sets.

    I changed my standard color to cyan-on-black since green-on-black is in the default color set (#2)

  • You just put up to 8 colors (foreground/background pairs) after color, like color white black red black green black yellow black

  • RaymanRayman Posts: 15,365

    @Wuerfel_21 Ok, thanks. That works, except "modal" colors, which have to assume means a hex value, seems to be broke.
    Can get around that limitation to some extent by specifying the brightness after. Not really happy about not being able to use a hex value though...

  • RaymanRayman Posts: 15,365
    edited 2025-06-17 04:24

    So, with this hacked version of "jm_fullduplexserial", called "DebugSerial", can use the original I2C scanner by just changing the object, one line.

    Maybe this could work with keyboard input too? Think maybe...

  • JonnyMacJonnyMac Posts: 9,378
    edited 2025-06-17 05:18

    I added methods for configuring the color set values and the background, though using a level with background (which should be possible) causes issues.

    Still, this seems serviceable.

  • RaymanRayman Posts: 15,365

    Got it to wait for keystroke then erase screen and then redo I2C scan.
    Think this is all that is needed for now... Feeling good about it...

  • JonnyMacJonnyMac Posts: 9,378

    Nice! I added colors to my variant and it made me smile a bit -- reminded me of the mid-80s when I worked at Toro and we were using IBM 5150s for golf course irrigation control. We used Turbo Pascal to create a screen painter that would allow us to save the display memory (80 cols x 25 rows with colors) to a file that could be loaded later. I kind of wish we could use that old IBM font in the debug terminal -- that would be fun!

  • RaymanRayman Posts: 15,365

    Ok, one last think want to try...

    Took that 7-bit address list from web and turned from C++ to something that compiles with PropTool in a dat section.
    Maybe not too hard to use to create a "suspect" list from found devices?

  • RaymanRayman Posts: 15,365

    Got it. Lists suspects from 7-bit address in list mode.
    Not exactly well tested but that first result, the IR camera, is correct...

  • JonnyMacJonnyMac Posts: 9,378
    edited 2025-06-17 15:47

    Very cool. By the way, you might want to change that file to ra_i2c_scanner.spin2 because that's all your work and you should get credit for it.

  • RaymanRayman Posts: 15,365

    Am wondering if the 7-bit address is the defacto standard these days. Have seen both 8-bit and 7-bit in the past. Maybe it's all 7-bit now? Hope so, but maybe not...

Sign In or Register to comment.