UART or I2C sensor version?



  • Hello!
    The tfmini is an IR lidar sensor. There is a UART and an I2C version, quite at the same price.
    For my project, I need 2 tfmini hooked up to an Arduino UNO with a +/- 1m cable.
    I've been doing some tests with 2 tfmini UART versions and it works fine following the example "TFmini_Arduino_SoftwareSerial_Multiple" from https://github.com/TFmini/TFmini-Arduino
    I need to build more occurrences of my UNO with 2 tfminis, and want to try the I2C version of the tfmini.
    As I am no specialist of communication protocols, I'd like to know what could be the theoretical pros and cons of using either of these protocols (mostly regarding reliability and the cables lengths, but I might miss some other important criteria).
    Thanks a lot!


  • Mod

    @od1 i2c supports multiple devices on the same cable (if the devices can configure address).
    Uart can support longer cables, but both can support 10m.

    Both can be used with software (bit-banging) which means you are not limited to the hardware serial/i2c.



  • Hi @mfalkvidd and thanks for your quick answer 🙂


  • Plugin Developer

    This is a matter of personal taste, but I always prefer serial devices.

    • They are easier to connect with simple wiring, since you can use any pin as software serial.
    • I also like that if you use multiple serial devices, you can keep the code you need to a minimum. I usually only implement (read: copy-paste) the commands that I really need. E.g. for GSM modems of for serial TFT screens. That can save some space.
    • Finally, I get the feeling what with serial it's easier to integrate in future unknown scenarios. E.g. attach a sensor to a USB-to-serial device.

    I'd love to hear counter arguments to this actually.


  • Hardware Contributor

    @alowhum your are also missing the longer cables as uart is more resistant to interference.

    The limits I see are:

    1. when you need to use software serial with high baudrate, I don't think a poor uno will handle well multiple software serials at 115k ?
      If it has to process the data and store/send it, it might miss some data as software serial has no hardware input buffer.
      Of course if sensors don't need to run simultaneously then this will not be a problem.

    2. pin usage. Each sensor using 2 pins can be a limit. Should not be in this case on a uno, but I have the problem on ESP32, I had to make a daughter board with an attiny to convert uart sensors to i2c, now I can have as many as I want.


  • Hardware Contributor

    exactly.
    like mfalkvidd and nca78 said, i2c is a bus, not the case of the serial comm you use. and serial devices are usually not very low power.

    again I agree, serial sw is maybe ok for a simple device, else it has very poor performance. bad idea for lcd fast refresh, or sampling sensors etc. I avoid it as much as I can (I think I don't have any projects using it though)

    same as nca78 I have a few projects when I use all esp32 pins, and I use serial, i2c and spi a lot, even canbus, ..hopefully I have not used serial interface only!

    better use the right tech for a project 😉


  • Plugin Developer

    @nca and @scalz Thanks! Very interesting, good points.


Log in to reply
 

Suggested Topics

  • 87
  • 9
  • 5
  • 3
  • 8
  • 10

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts