0
\$\begingroup\$

I am a student of Electronics and Telecommunication. For personal projects and learning, I would like to learn how to build embedded systems (like the once that we see on those cool projects). So here is the catch, my college will teach the basics of microcontroller in 3rd year, and that too Intel 8086. I want to learn ARM microcontrollers like how do you build boards with sensors integrated into them and how to communicate between multiple processors. I have no idea about any of those technical stuff (like I2C, SPI, UART, Clock, PWM, etc.). It's not like I have never heard about them, but I am sure I don't know enough to start building an embedded system. I have worked with Arduino and RPi (this has to count).

After reading a few blogs on Microcontrollers, I know datasheets are used to figure out the value of the resistor, capacitor, and other things. And this brings me to my question again: how do you integrate other sensors with the main processors.

Side note: I know this not the best way to learn things like jumping directly on to an advance topic without knowing the basic, but I need to learn this right now.

I know many people have asked questions on "how to get started with microcontrollers," and I have read them, but none of them answered what I wanted to know.

I am new here, so please don't throw this question out.

\$\endgroup\$
9
  • \$\begingroup\$ BTW everyone starts with an Arduino :) \$\endgroup\$
    – user253751
    Mar 11, 2021 at 9:45
  • 8
    \$\begingroup\$ @user253751 I sincerely hope that isn't true. \$\endgroup\$
    – Lundin
    Mar 11, 2021 at 10:07
  • \$\begingroup\$ "like how do you build boards" is a very different subject from how do you program an ARM MCU. PCB CAD is a big area of it's own. \$\endgroup\$
    – Lundin
    Mar 11, 2021 at 10:09
  • \$\begingroup\$ @Lundin For now let's just say it is built on a breadboard😁😁 \$\endgroup\$
    – Momobear
    Mar 11, 2021 at 10:21
  • 1
    \$\begingroup\$ You should reword your heading to match your actual question about integrating sensors with ARM processors. This is a very open ended question and needs a bit more clarification. There are dozens of different ways to interface sensors. The easies way to learn is to go to sites like adafruit.com or sparkfun.com and read some of their tutorials. \$\endgroup\$ Mar 11, 2021 at 10:43

1 Answer 1

4
\$\begingroup\$

And this brings me to my question again: how do you integrate other sensors with the main processors.

  1. You read the datasheet of the sensor.
  2. You learn what you have to do in order to make the sensor work.
  3. You program the microcontroller to do that.

For example:

  1. The sensor has a clock wire and a data wire (or "line" or "pin"). The datasheet says it reads an 8-bit value, and outputs the next bit on the data wire every time the clock wire goes high. The most-significant bit (MSB) is first. After 8 bits are read, the sensor takes the next reading.

  2. To get the value from the sensor, you would need to make the clock wire high (and then low again) 8 times, and check whether the data wire is high or low in between each pulse.

  3. You write the code:

     result = 0;
     for(int k = 0; k < 8; k++) {
         output(SENSOR_CLOCK, 1);
         output(SENSOR_CLOCK, 0);
         if(input(SENSOR_DATA))
             result |= 1 << k;
     }
    
  4. You test it and realize your sensor readings are nonsense. You realize your code reads the LSB first instead of the MSB first, so you change it to result |= 1 << (7 - k) and it works. Just like any other program, don't expect to get it right the first time!

Now, you will often find that your microcontroller can't do the thing you need it to do. A good example is analog sensors, which don't just output high or low, but any voltage in between. Some microcontrollers have analog pins which can read analog values. Others don't. And the ones which do have them have a limited amount, and you might need more sensors than that, and they have limited precision, and you might need a more accurate measurement. So you research and buy an analog-to-digital converter (ADC). Now you connect the sensor to the analog side of the ADC, and you connect the digital side to the microcontroller, and you follow steps 1-4 according to the datasheet of the ADC, because the ADC is acting as a "voltage sensor". And this lets your microcontroller read the voltage going into the ADC, which tells it the original thing you were trying to sense.

Or, you might have a digital sensor, but it uses a different voltage than the microcontroller. In this case you'll need to build a little circuit to translate the voltage, so that when your microcontroller outputs 3.3V (high), the sensor receives 1.8V (its version of high), and when your microcontroller outputs 0V, the sensor receives 0V.

You might have an analog sensor where the voltage only changes a tiny bit, and you might want to build an analog amplifier to make the change bigger before you convert it to digital.

These are some of the problems you may run into when connecting a sensor to a microcontroller. The exact problems you'll run into depend on the type of sensor. They are all different.

I have no idea about any of those technical stuff (like I2C, SPI, UART, Clock, PWM, etc.)

Then you learn as you go. I2C, SPI, and UART are all digital protocols that a lot of chips use to talk to other chips. A protocol is a way that communication happens, like the "clock and data protocol" I used as an example at the beginning. They tell you how to communicate.

SPI and I2C are pretty similar to the "clock and data protocol". UART is quite different, it doesn't have a clock and you read the bits based on a time delay. PWM is a way to emulate an analog output signal, so instead of outputting let's say 3.5V, you output 5V 70% of the time and 0V 30% of the time, and it averages out to 3.5V.

Note that every protocol has two sides - one chip is in control, and the other chip is responding to it. As the microcontroller, most of the time you're the controlling side. You are telling everything else what to do. But sometimes you're the responding side, like if your gadget connects to a computer, and the computer tells your gadget what to do. In this case, it's good to remember that you can read the protocol "in reverse". If the protocol says the controlling side makes the clock high and then low and then inputs a bit, you'd better figure out that you need to output a bit before the clock goes low (i.e. after it goes high) so that the controlling device can read it.

It's not like I have never heard about them, but I am sure I don't know enough to start building an embedded system.

Then learn as you go. "Okay, this sensor needs an I2C connection. What does that actually mean?" The datasheet shouldn't just say "I2C", it should also include timing diagrams showing you exactly which wires have to go high and low in which order. Great! Implement that diagram, and you've implemented I2C.

After reading a few blogs on Microcontrollers, I know datasheets are used to figure out the value of the resistor, capacitor, and other things

This falls into the analog stuff I was talking about above. You don't know, in general. It depends on the specific sensor. Often you don't need any extra resistors or capacitors.

Also this wouldn't be specific to microcontrollers. If you're designing analog circuitry, it's the same skillset, no matter whether you're doing it for a microcontroller to read a sensor, or for something completely different. If you want to smooth out a PWM signal with a resistor/capacitor (RC filter) it's the same as smoothing out any other signal with an RC filter. Don't forget you can simulate these things on your computer! CircuitJS (a.k.a. "falstad") is a popular simulator for beginners due to its ease of use and interactive nature, though note that it doesn't simulate more advanced concepts like parasitic components.

\$\endgroup\$
9
  • \$\begingroup\$ So let's say that I have 3 microcontrollers: one for collecting data, one for receiving and sending signals, and the last one for communicating with both of them and analysing the data, so how do I go about communicating with the other 2 IC. \$\endgroup\$
    – Momobear
    Mar 11, 2021 at 10:34
  • \$\begingroup\$ And does the arm microcontrollers follow the same steps as the ones you have provided in your answer? \$\endgroup\$
    – Momobear
    Mar 11, 2021 at 10:36
  • 1
    \$\begingroup\$ @Gurkirat Do you really need 3 microcontrollers for that? Why not just 1? \$\endgroup\$
    – user253751
    Mar 11, 2021 at 11:02
  • \$\begingroup\$ @Gurkirat well, you have a system, so you need to do some systems design; pick a bus for communication depending on how fast and reliable you need it to be and what you're familiar with. However, for your 3-microcontroller situation I'd say "use one big microcontroller instead" \$\endgroup\$
    – pjc50
    Mar 11, 2021 at 12:03
  • \$\begingroup\$ @user253751 I haven't encountered such a situation, but just a scenario, if ever I need it. \$\endgroup\$
    – Momobear
    Mar 11, 2021 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.