Author Topic: [SOLVED] [newbie] How do pins work? How to talk with sensors?  (Read 1057 times)

0 Members and 1 Guest are viewing this topic.

Offline WinfriedTopic starter

  • Contributor
  • Posts: 24
  • Country: fr
[SOLVED] [newbie] How do pins work? How to talk with sensors?
« on: November 06, 2022, 10:10:37 am »
Hello,

I have two newbie questions:

1. I see that on boards, the same I/O pin has different names (eg. IO17 = I/O/T, RTC_IO17, DAC1, ADC2_CH6, UART1_TX). I would like to understand why. Does each pin use a different voltage + current? Can each only be used for a specific task?

2. It seems there are several protocols to talk to a sensor (Modbus, I2C, SPI, UART, possibly others.) Is there a good article that explains the differences, and how to work with each?

FWIW, I need to interact with a sensor through the serial port (UART?).

Thank you.
« Last Edit: November 06, 2022, 01:24:25 pm by Winfried »
 

Offline pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3712
  • Country: nl
Re: [newbie] How do pins work? How to talk with sensors?
« Reply #1 on: November 06, 2022, 10:28:07 am »
Within a microcontroller there can be many peripherals having different functions. Like UART, SPI, I2C, timers, etc. To make things more flexible most also have a way to connect one of these peripherals to an io pin. These are often called alternate functions.

That is why you see multiple signal names next to an io pin. It can be one of these functions based on the settings in the MCU.

You are misusing the term protocols in your second question. I2C, SPI, UART, CAN, etc. are hardware interfaces that connect your MCU to a sensor. It then depends on the sensor what the communication protocol over this hardware interface is.

Modbus on the other hand is a protocol. It can work on top of some of the hardware interfaces mentioned above.

Without knowing which sensor you want to connect with, there is no good referral to be made.


Offline Psi

  • Super Contributor
  • ***
  • Posts: 9954
  • Country: nz
Re: [newbie] How do pins work? How to talk with sensors?
« Reply #2 on: November 06, 2022, 10:41:29 am »
In the old days you only had one feature per pin.  But it was annoying because if you didn't need that feature those pins were totally useless to you. Also you could only have as many features in the chip that you had pins to use for them.

So they decide to routed the signals to all pins with internal switches that you can control in software.
Then they can add even more features and you can select the ones you need and connect them to the pins that suit your design.
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline WinfriedTopic starter

  • Contributor
  • Posts: 24
  • Country: fr
Re: [newbie] How do pins work? How to talk with sensors?
« Reply #3 on: November 06, 2022, 01:24:03 pm »
Thanks very much. This page also makes it clear that different components on a board share pins.

It's to communicate with a CO2 sensor ("Communication: UART (Modbus)")
 

Offline WattsThat

  • Frequent Contributor
  • **
  • Posts: 767
  • Country: us
Re: [SOLVED] [newbie] How do pins work? How to talk with sensors?
« Reply #4 on: November 06, 2022, 02:49:30 pm »
Don’t overlook the fact that the one UART of the ESP32 is used for the USB connection. That is needed to get your firmware image loaded into the device and for serial prints to the console for debugging.

Low speed serial devices like your sensor will usually work ok with “software serial” were the UART hardware functionality is duplicated with software.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf