We have upgraded the community system as part of the upgrade a password reset is required for all users before login in.

Arduino Dock: I2C and Serial



  • Hey all,

    I'm fairly new to the Omega platform but quite amazed by the versatility.

    I've been trying to receive measurement data acquired by the Arduino on the Arduino Dock 2.
    The Omega acts as the master, the arduino as a "regular" i2c slave.

    It's working fine, however I've experienced problems when trying to also send debug output via the serial interface.

    Here's my arduino sketch:

    #include <Wire.h>
    
    byte reg = 0;
    
    void setup() {
      // put your setup code here, to run once:
      Wire.begin(0x09);
      Serial.begin(9600);
      Wire.onReceive(receiveEvent);
      Wire.onRequest(requestEvent);
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
    
    }
    
    void receiveEvent() {
      reg = Wire.read();
    }
    
    void requestEvent() {
      Wire.write(reg);
      //Serial.println("Hello World");
    }
    
    

    I can detect the slave by executing i2cdetect -y 0, and i2cdump -y 0 0x09 will give me the expected output where each register has the value of its address.

    However as soon as I uncomment the Serial.println, the read fails. i2cdump will just show garbage and i2cget weirdly fails every other execution, where the other one returns 0x00.

    Does anyone have an idea on why the serial interface interferes with the i2c interface?
    I'm quite sure I did this before on a regular arduino, so I'm surprised it doesn't work.



  • First off all, I don't have Arduino Exp.
    I am using Omega2+ and Arduino UNO with level-shifter.

    Followed the connection info from:
    https://docs.onion.io/omega2-docs/arduino-dock-2.html

    UART1 <=> Serial Pins &
    I2C <=> I2C with level-shifter.
    Didn't do the SPI part of the wiring.

    root@Omega-745F:~# i2cdetect -y 0
    0 1 2 3 4 5 6 7 8 9 a b c d e f
    00: -- -- -- -- -- -- 09 -- -- -- -- -- --

    The following is output, even with Serial.println( ) commented
    root@Omega-745F:~# i2cdump -y -r 0x20-0x7F 0 0x09 b
    0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
    20: 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f !"#$%&'()*+,-./
    30: 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 0123456789:;<=>?
    40: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO
    50: 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f PQRSTUVWXYZ[]^_
    60: 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f `abcdefghijklmno
    70: 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f pqrstuvwxyz{|}~?

    When I removed the pull-ups (SCL & SCA to Vcc), I encountered problems.

    In GPIO mode, internal pull-ups can be pro grammatically enabled for AVR328P pins. When using for I2C, pull-up needs to be provided externally. I am not sure if Arduino Exp board has pull-up resisters for I2C pins implemented on the pcb, most probably not. It doesn't make sense since the board also provides regular Arduino header and the end user may want to use the I2C pins for other stuff? I am not familiar with Arduino IDE ..does the Wire library configure the pull-up ?

    root@Omega-745F:~# i2cdump -y -r 0x20-0x7F 0 0x09 b
    0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
    20: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XXXXXXXXXXXXXXXX
    30: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XXXXXXXXXXXXXXXX
    40: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XXXXXXXXXXXXXXXX
    50: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XXXXXXXXXXXXXXXX
    60: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XXXXXXXXXXXXXXXX
    70: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XXXXXXXXXXXXXXXX

    Thanks..



  • I figured out the solution to the original question myself now: Apparently writing to serial within the requestEvent messes with the i2c bus.
    I guess it's some kind of problem arising from the collision of ISRs.



  • Serial.println() inside requestEvent() always fails, even with NUL str, Serial.println("").

    root@Omega-745F:~# i2cdump -y -r 0x30-0x32 0 0x09 b
    0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
    30: 0c XX 0c ?X?

    where as Serial.println() inside receiveEvent() can print one or two characters, for eg,

    void receiveEvent() {
    reg = Wire.read();
    Serial.println(reg, HEX);
    }

    to a certain volume of data.

    root@Omega-745F:~# i2cdump -y -r 0x30-0x32 0 0x09 b
    0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
    30: 30 31 32 012
    root@Omega-745F:~# i2cdump -y -r 0x30-0x3F 0 0x09 b
    0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
    30: 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 0123456789:;<=>?

    root@Omega-745F:~# i2cdump -y -r 0x40-0x4F 0 0x09 b
    0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
    40: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO

    root@Omega-745F:~# i2cdump -y -r 0x30-0x41 0 0x09 b
    0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
    30: XX 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f X123456789:;<=>?
    40: 40 41 @A

    If there is more data, it fails..
    root@Omega-745F:~# i2cdump -y -r 0x30-0x45 0 0x09 b
    0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
    30: XX 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f X123456789:;<=>?
    40: 40 41 42 00 00 00 @AB...

    root@Omega-745F:~# i2cdump -y -r 0x30-0x4F 0 0x09 b
    0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
    30: 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 0123456789:;<=>?
    40: 40 41 00 00 00 00 02 XX 00 00 00 00 00 00 00 24 @A....?X.......$

    It fails every time if a long str such as "Hello, World!" is to be printed, even inside receiveEvent().

    It is not a problem associated with ARD Dock; I am not using ARD Dock at all..

    Thanks..



Looks like your connection to Community was lost, please wait while we try to reconnect.