Introduction to microcontrollers

From Knowledge Kitchen
Jump to navigation Jump to search


Levels of computing devices

Microprocessors

  • small size
  • low power consumption
  • limited computation resources
  • usually a single IC with limited memory, no data storage, no built-in communications, digital-only inputs and outputs, and runs at a relatively slow lock speed

Microcontrollers

Prototyping platforms

  • Come with companion software in a high-level language
  • Come with additional circuitry to make adding peripherals to the microcontroller easy
  • Make it easy to program and extend the capabilities of microcontrollers

Computers

  • microprocessors, microcontrollers, and microcontroller prototyping platforms re all types of computers
  • all consist of the same basic parts
    • processor - executes instructions
    • memory - stores instructions and data
    • ports - interface the computer to its periferals
    • bus - the communications pathway among the processor, memory, and ports
  • when laypeople use the term 'computer', they are usually referring to a desktop or laptop personal computer
    • but this is just one example
    • a laptop is no more a computer than a smart phone or a programmable thermostat

Arduino hardware

Digital pins

  • can be set as either input or output

input pins

    • read voltage levels between 0 and 5V
    • can sink (i.e. input) up to 40mA of current
    • convert voltage readings to LOW or HIGH values in software
    • unconnected pins may have erratic voltage readings
      • pull-down resistors tie disconnected input pins to 0V
        • 10Ω is a common value
      • pull-up resistors tie disconnected input pins to 5V
        • Arduino Uno has built-in 20Ω pull-up resistors that can be activated in oftware

output pins

    • output current at 5V when activated in software
    • can source (i.e. output) up to 40mA of current to a circuit

serial pins

  • avoid using TX/RX pins - they serve a dual purpose that may interfere
Analog input pins


Analog pins

input pins

  • use an analog-to-digital converter (ADC)
  • read in voltage levels between 0 and 5V
  • convert voltage reading to a number between 0 and 1023

output pins

  • do not have a DAC - digital to analog converter
  • work via pulse-width modulation instead
    • sends pulses of 5V at 488 Hz (assuming we are using the Arduino's default 16 MHz clock speed)
      • this pulse frequency can be changed in Arduino settings
    • software values from 0 to 255 in software are converted to changes in the duty cycle of the pulses.

Pin diagram

Convenient diagram of all Arduino pins


Arduino software

Top-level functions

Core functions to run a program:

  • setup()
  • loop()

More functions

See the full list of Arduino built-in functions


What links here