Introduction To Microcontrollers Final1
Introduction To Microcontrollers Final1
Data types Anatomy of a program Sketches- setup and loop Logic AND, OR, NOT Whats in the kit? Ohms Law Resistor Color Coding Pull Up and Pull Down
Circuit Construction
The Arduino
What is an Arduino
So what is a microcontroller?
Essentially, a microcontroller is a small computer on a single integrated circuit. The microcontroller has a simple CPU comprised of clock timers, input/output ports, and memory.
Uses:
automatically controlled products and devices automobile engine control systems implantable medical devices remote controls office machines appliances power tools And more and more and more
Vs.
Arduino
Expandability
Easy to attach Ethernet shields, sensors, etc.
Easy Setup
All you need is a standard USB cable for programming and power
Breakout board
Circuit creation is made easy by not having to do any soldering
Inexpensive Powerful
Fueled by the Atmega328 microcontroller
The learnin
Variables
A variable is how you store a value within a program Examples: Hackrva = awesome;
Assigns the string (a data type) Awesome to hackrva
Hackrva = 2;
Assigns the integer 2 to the variable hackrva. Further: hackrva = hackrva + 2;
NOW: hackrva = 4
Data types
Data types are an important foundation to programming. For example, if you want a program to count to 10 then you want:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
LOGIC Gates
Logic comes into play when working and thinking on a binary level. They are essentially operations like +, -, *, / except on a binary numbers.
In fact using logic is how you CREATE +,-,*,/ wellyou also need about 5000 transistors. The foundation basic gates are: AND, OR, NOT
AND
INPUT A 0 0 1 1 B 0 1 0 1 OUTPUT A AND B 0 0 0 1
Example: We want LED3 to come on when LED1 and LED2 are both on: If LED2 = 1 AND LED1 = 1 then LED3 = 1
OR
Example: We want LED3 to come on when either LED1 and LED2 are both on:
If LED2 = 1 OR LED1 = 1 then LED3 = 1 INPUT A 0 0 1 1 B 0 1 0 1 OUTPUT A OR B 0 1 1 1
NOT (invert)
INPUT A 0 1 OUTPUT NOT A 1 0
Example: We want LED3 to be the opposite of its current state (if off then on and if on then off):
LED3 = NOT LED3;
Anatomy of a Program
Lowest (if you write this you have too much free time)
Machine Code all patterns of 0s and 1s The microcontroller might see: 0001001010010100101001001010001010101010 And from this it will know a specific command.
A program.
Basic life of a program:
User writes a program in C (a high level language) A compiler will then take that code and converts it into Assembly language Then an assembler will take that code and turn it into machine code.
We are using an Arduino IDE, or integrated development environment, so we will write code using Arduinos language and it will take care of the rest! Easy Peazy
Programming Languages
Obviously, not every programming language is the same. Each language differs in a way that makes it particularly good for something. Arduino is no different. Arduino has been simplified specifically to make it easy to program the Arduino microcontroller. Anatomy of an Arduino Program:
Arduino calls every program a Sketch (maybe they feel like that makes them edgy to be different) Sketches are comprised of a SETUP and a LOOP section Setup: Only Runs once and is used to set necessary registers and pins Loop: This is the rest of the sketch and by default when a sketch finishes in this language it repeats the entire sketch. Essentially looping-a concept we will cover later.
CIRCUIT CONSTRUCTION
5 100 ohm resistors - They can be used to protect pin outputs when starting out 5 1K resistors - Good for use as LED limiting resistors 5 10K resistors - Great for pullups & pulldowns
Which resistor?
Using Ohms we can determine exactly which resistor is best but it is always best to be safe than sorry.
The higher the resistance the dimmer the LED will
Time to build!
Program 1
Program 2
Program 3