Microcontroller Programming & Hardware Introduction

40
WELCOME TO MICRO- CONTROLLER PROGRAMMING & HARDWARE INTRODUCTION With this class, you will begin learning how to create custom software defined hardware devices and start building your own electronic devices Brought To You By Your Local Make Space www.MakeSpace.io Class Instructor Joseph Sanchez 6/24/2014

description

Introduction to microcontrollers namely and more specifically, Arduino. This course is also an introduction to hardware.

Transcript of Microcontroller Programming & Hardware Introduction

Page 1: Microcontroller Programming & Hardware Introduction

WELCOME TO MICRO-CONTROLLER

PROGRAMMING & HARDWARE

INTRODUCTION

With this class, you will begin learning how to create custom software defined

hardware devices and start building your own electronic devices

Brought To You By Your Local Make

Space

www.MakeSpace.io

Class Instructor

Joseph Sanchez

6/24/2014

Page 2: Microcontroller Programming & Hardware Introduction

FIRST, LET’S LOOK AT

WHAT KIND OF THINGS

ONE MAY BE ABLE TO

CREATE WITH THESE

SOON- TO-BE LEARNED

ABILITIES…

Make these soon one might

Page 3: Microcontroller Programming & Hardware Introduction

ONE MIGHT….

build cool robots!

Page 4: Microcontroller Programming & Hardware Introduction

make an automated beverage dispenser

ONE MIGHT….

Page 5: Microcontroller Programming & Hardware Introduction

build an automated watering system for plants

ONE MIGHT….

Page 6: Microcontroller Programming & Hardware Introduction

Build a digital harp that uses lasers as strings,a techno-inspired led helmet and more!

ONE MIGHT….

Page 7: Microcontroller Programming & Hardware Introduction

MICRO-CONTROLLERS, PROGRAMMING AND ADDITIONAL HARDWARE WILL HELP YOU IN THE CREATION OF ALL OF THESE DEVICES AND MORE!

Wouldn’t those type of abilities make you happy?

GREAT LET’S START LEARNING!

Page 8: Microcontroller Programming & Hardware Introduction

GETTING STARTED THE BASICS

Page 9: Microcontroller Programming & Hardware Introduction

WHAT IS A MICROCONTROLLER

A microcontroller (sometimes abbreviated µC, uC or MCU) is a small computer on a single integrated circuit containing a processor core, memory, and programmable inputs and outputs. Program memory is also often included on chip, as well as a typically small amount of RAM.

Page 10: Microcontroller Programming & Hardware Introduction

SO, WHAT IS AN ARDUINO? Arduino uses a microcontroller. It often referred to as a development

board. It is an open-source electronics

prototyping platform based on flexible, easy-to-use hardware and software. It's intended for artists, designers and hobbyists.

Page 11: Microcontroller Programming & Hardware Introduction

OTHER DEV BOARD OPTIONS There additional options for

development boards other than Arduino like…

Raspberry Pi Beagle

……And Many More!

Page 12: Microcontroller Programming & Hardware Introduction

BUT FOR NOW,WE WILL JUST BE FOCUSING ON THE ARDUINO

Page 13: Microcontroller Programming & Hardware Introduction

The internal voltage reference options may not be used if an external reference voltage is being applied to the AREF pin.

Arduino

GETTING TO KNOW THE BOARD

Page 14: Microcontroller Programming & Hardware Introduction

TX/RX more on these communicationports a little later

GETTING TO KNOW THE BOARD

Page 15: Microcontroller Programming & Hardware Introduction

Rx = (received data)Tx = (transmit data)

These additional input and output ports are for serial data.

They allow you to do things like connect two Arduinos together

so they can communicate!

COMMUNICATION PORTS

Page 16: Microcontroller Programming & Hardware Introduction

SO WHAT KIND OF DEVICES COULD WE USE WITH OUR INPUTS

AND OUTPUTS?

Gadgets, sensors and motors oh

my!

Page 17: Microcontroller Programming & Hardware Introduction

HARDWARE COMES IN AN ASSORTMENTOF FLAVORS… There is already a ton of sensors, motors, and other

electrical devices to use in combination with your Arduino

These additional devices help our devices see, feel, measure, manipulate and hear our surroundings.

The more information you know about the availability of these devices, the better you can create a solution for the task you are trying to accomplish with your Arduino.

Page 18: Microcontroller Programming & Hardware Introduction

HERE IS A SHORT LIST OF

HARDWARE TO START BUILDING

YOUR KNOWLEDGE

BASE…

Page 19: Microcontroller Programming & Hardware Introduction

LED L.E.D which stands for light emitting diode. Is a diode that illuminates when current is applied through it.

Page 20: Microcontroller Programming & Hardware Introduction

RESISTOR Resistors come in a variety of sizes and they are used to reduce current flow, and, at the same time, act to lower voltage levels within circuits.

Schematic Representations of Resistors

Page 21: Microcontroller Programming & Hardware Introduction

RELAY

Relays are devices which allow us to complete or disconnect a circuit based on an input voltage. Based on the rating of the relay, you can switch a variety of voltages and amperages.

Relays could be used to :

-Turn on water pumps-Turn off lights or appliances in your house

Page 22: Microcontroller Programming & Hardware Introduction

ELECTRIC MOTOR

Electric motors spin when voltage is applied.

If you reverse the power in (most) motors, the motor direction will reverse.

Take for example our 3D printers – They require to go in one direction and then reverse to control the printing.

Page 23: Microcontroller Programming & Hardware Introduction

SERVO MOTORS

Servo motors move similarly, but they allow you to control how they turn more specifically. They use degrees or values which may be translated into degrees allowing the gear to rotate.

For instance, you could rotate 45 degrees with one command or even a 360 degree turn as well as everything in between.

Page 24: Microcontroller Programming & Hardware Introduction

PHOTOCELLS OR PHOTORESISTOR

Photocells are variable resistors where the resistance decreases with the increasing amount of light you shine onto it.

A great example of using a photocell would be a laser trip wire. In order to achieve this, we would place a laser towards the photocell and if something would come in between the two, the resistance would increases. By doing so, we could perform an action like sounding An alarm.

Page 25: Microcontroller Programming & Hardware Introduction

HUMIDITY SENSOR

Humidity sensors do just as they sound, they detect the levels of humidity in the air. So, depending on the level of moisture in the air, a value decreases or increases.

Page 26: Microcontroller Programming & Hardware Introduction

POTENTIOMETERPotentiometers are devices that use variable resistors along with a turning mechanism to increase or decrease resistance.

In order to achieve this, you would add a positive connection to left connection(1) and ground to the right(3). Then, as you twisted the knob, the middle connection’s value(2) would increase or decrease depending on the orientation of your rotation.

All the way counter clockwise = 0 All the way clockwise = 255

And anything inbetween during rotation

Page 27: Microcontroller Programming & Hardware Introduction

GYROSCOPE

Gyroscopes which have been ever increasing in their popularity due to smart phones and personal drones, allow us to sense the tilt and rotation of a device.

Page 28: Microcontroller Programming & Hardware Introduction

SO, IF YOU GET AN IDEA FOR SOMETHING TO BUILD, THERE IS A GOOD CHANCE THERE IS A PIECE

OF HARDWARE TO HELP YOU ACCOMPLISH YOUR GOAL!

And that’s just the some of the available devices……

Page 29: Microcontroller Programming & Hardware Introduction

SO HOW DO WE GET THESE DEVICES TO DO

WHAT WE WANT?

Well, that’s where the programming comes in…

Page 30: Microcontroller Programming & Hardware Introduction

I HAVE NEVER PROGRAMMED BEFORE, IS IT

EASY TO LEARN?

Well luckily, you have come to the right place!

Today, you will get hands on experience to get you started using the Arduino and by the end of this class you will have successfully written your first few programs.

Page 31: Microcontroller Programming & Hardware Introduction

SO HOW DO YOU PROGRAM AN ADRUINO?

We will be using the an IDE specifically made for programming our Adruinos.

IDE stands for integrated development environment.

This is where we will write the code that is stored and ran on our microcontroller.

Page 32: Microcontroller Programming & Hardware Introduction

NOW, LET’S CODE OUR FIRST PROGRAM!

Page 33: Microcontroller Programming & Hardware Introduction

SETTING UP OUR PROGRAM

void setup() {

}

Whatever code you add between the curly brackets of void setup will be ran prior to the main program.

In our development window, type the following code:

Page 34: Microcontroller Programming & Hardware Introduction

YOU CAN THINK OF THE LOOP AS THE MAIN STAGE OR MAIN PROGRAM AREA

void loop() {

}

Void loop is where your main program lives. It is aptly named loop because that’s exactly what happens when it reaches the end of the code – it will LOOP and start over .

Next, under void setup type the following code:

Page 35: Microcontroller Programming & Hardware Introduction

void setup() {

}

void loop() {

}

Before the setup, we can call in Libraries which are often times pre-written code to help us with what we are trying to achieve.

It is stored as an external file and then called into the program.

An example of calling in the SD library which helps with processing an SD card would show as:

#SD.H

A QUICK MENTION ABOUT LIBRARIES

Page 36: Microcontroller Programming & Hardware Introduction

void setup() {

}

void loop() {

blinkLED(); }

After the loop, we can add functionsFunctions are ways to migrate code outside of the main program. Then, you call them independently into the code where needed. You always precede a function with void.

Now type out the code.

And then call the function blinkLED into the loop by adding:

blinkLED();

No void needed when adding the function reference

void blinkLED() {

}

NOW ADD A FUNCTION CALLED BLINKLEDAND PLACE A REFERENCE

TO IT WITHIN YOUR MAIN PROGRAM

Page 37: Microcontroller Programming & Hardware Introduction

digitalWrite is used to set the state of a pin to HIGH or LOW (or 0 -255 if using PWM)

So write the following in your blinkLED function:

digitalWrite(8, HIGH); delay(1000);

This would make pin 8 turn “on” which would illuminate an LED connected to the pin

Then add digitalWrite(8,LOW);delay(1000);

directly below it. This would produce the opposite result and turn off the connected LED

NOW LET’S ADD CODE INTO OUR FUNCTION

Page 38: Microcontroller Programming & Hardware Introduction

NOW SET PIN 8 TO OUTPUT

In order to let the program know that we are using pin 8 as an output instead of an input add the following code within the setup()

pinMode(8,OUTPUT);

Page 39: Microcontroller Programming & Hardware Introduction

SO, WHEN YOU PUT IT ALL TOGETHER IT SHOULD LOOK LIKE THIS

Page 40: Microcontroller Programming & Hardware Introduction

NOW LET’S HOOK UP OUR HARDWARE AND TRY OUR CODE!

AFTER ALL, THIS ISN’T CALLED

FOR NOTHING!