how to hack electronics

Download How to hack electronics

Post on 21-Apr-2017

3.065 views

Category:

Devices & Hardware

1 download

Embed Size (px)

TRANSCRIPT

  • ~Henri Matisse

    Drawing is putting a line round an idea

  • Hacking is giving form to an idea

  • Hack to Learn

  • Hack to Communicate

  • Hack to Do

  • Hack to Do Think

  • How to Hack ElectronicsPLANNING-NESS 2014

  • Hi. Im Robert Gallup

  • AgendaMad Cap First Hacks

    Electricity + Electronics Hacking Switches + Knobs + Smart LEDs

    Project? Wrap Up

  • Feel Free to Wander

  • ?

  • EYour Hackers Kit

    BREADBOARDSTEALTH CASE RESISTOR LED

    SMA

    RT LED

    BUTTON KNOBJUMPER WIRES TRINKET

  • Microcontroller

  • >Put the Trinket in the Breadboard

  • >Connect the Trinket to your Computer

    Glowing at FirstPower Indicator

  • >Download Software

    http://www.robertgallup.com/download/planningness2014-mac.zip

    Unzip Arduino Software

    Note: There are also downloads for -windows, and -linux

  • Start Arduino

  • >Mac OS X: Security Settings

    Open Preferences Unlock, and change Allow apps to Anywhere

    Run IMPORTANT: Reset security settings

    1 2 3 4

  • >Configure the Software for Your Board

  • >Configure the Programmer

  • >Add the Planning-ness Examples

    1

    2 Select planningness2014 in the Libraries folder from the class software download

  • >If it works,

  • ?

  • >Load the LEDBlink Example

  • >The Sketch Window

    Sketch (program)

  • >Run the Sketch on your Trinket

    1 2

    Press Reset

    Press the Run button

    LED glows

  • Wait. What?!

  • >The Blink

    Blinking

  • ESketch Structure (Recipe)

    // Svoid setup() { pinMode(1, OUTPUT); } !// Loopvoid loop() { digitalWrite(1, HIGH); delay(500); digitalWrite(1, LOW); delay(500); }

    Statements

    Comment

  • ESketch Walkthrough (See the Comments)

    // Setup runs once at the beginning void setup() { pinMode(1, OUTPUT); // Pin #1 is output } !// Loop runs over and over again forever void loop() { digitalWrite(1, HIGH); // turn the LED on delay(1000); // wait for a second digitalWrite(1, LOW); // turn the LED off delay(1000); // wait for a second }

  • (Change the Blinking SpeedHack 01:

    1. Change the blink speedHint: edit the blink sketch to change the blink delay from 1 second to 1/4 second (note: 1 second = 1000 milliseconds). Then run the sketch again.

    2. Stretch: Make a short on, longer off blink Hint: the delay times dont have to be the same.

  • EYour First Circuit

    Jumper Wire

    LEDResistor

  • >Wire Up an LED

    5V#2

    #1

    #0USB

    RST#3

    #4

    GNDBAT

    JUM

    PER

    WIR

    E

  • EA Note about Breadboards

    The rift separates the two sides

    All of the contact points in the same row are connected

  • (An LED on Another PinHack 02:

    1. Rewire your hack to move the LED to Trinket pin #2.

    2. In the blink sketch, change the LED pin to match. Hint: You may have to change more than one line

  • (A SolutionHack 02:

    // Setup runs once void setup() { pinMode(2, OUTPUT); // Pin #2 is output } !// Loop repeats forever void loop() { digitalWrite(2, HIGH); // turn the LED on delay(1000); // wait for a second digitalWrite(2, LOW); // turn the LED off delay(1000); // wait for a second }

  • (Another Way, VariableHack 02:

    // Declarations int pinLED = 2; !// Setup runs once at the beginning void setup() { pinMode(pinLED, OUTPUT); // Pin is output } !// Loop runs over and over again forever void loop() { digitalWrite(pinLED, HIGH); // turn the LED on delay(1000); // wait for a second digitalWrite(pinLED, LOW); // turn the LED off delay(1000); // wait for a second }

    pinLED = 2

    Declare Variable

  • EVariable Declaration

    TYPE VALUENAME

    int pinLED = 2;

  • Libraries Make It Easier

  • >Add the BobaBlox Library

    1

    2 Select BobaBlox Folder from the class software download

  • >Load and Run the LEDBlinkPinLibrary Example

  • EWhats Different About This Sketch?

    // Include the library #include !// Declarations LED boardLED(1); // Declare an LED on pin #1 !// Setup runs once at the beginning void setup() { } !// Loop repeats forever. Use the blink method to blink boardLED void loop() { boardLED.blink(); }

  • ELED Variable Declaration

    TYPE PINNAME

    LED boardLED(1);

  • EUsing a Function (method)

    NAME METHOD NAME

    boardLED.blink();

  • EAnother Version of the Blink Method

    # TIMES

    boardLED.blink(1, 100);

    DELAY

  • (An LED on Another PinHack 03:

    1. Change the library Blink sketch to use an LED on pin #3Hint: You can add a 2nd LED, or move the LED you connected in the previous hack.

  • (Fast BlinkHack 04:

    1. Change the library sketch to blink faster Hint: look at the example of the LED blink method that uses two parameters, times and delay.

  • (Blink Morse CodeHack 05:

    1. Load and run the SOS sketch from planningness2014 examples.Note: In Morse Code, S is dot-dot-dot, O is dash-dash-dash.

    2. Change the sketch so it blinks CQ. Hint: In Morse Code, C is dot-dash-dot-dash, Q is dash-dash-dot-dash. Note: CQ is a little like YO in the ham radio world.

  • EFor the Wanderer: Examples

  • EFor the Wanderer: Reference

  • ?

  • Chips + Circuits

  • EA Microcontroller

    !

    !

    microcontroller Input: temperature, motion, touch,

    ACTUATORS

    SENSORS

    PROGRAM

    Output: light, motor, sound, heat,

  • E

    +5V (Regulated)

    0

    1

    2

    Digital I/O

    Ground

    4

    3

    LED (Pin 1)

    USB

    Reset Button

    Power LEDADAFRUITTRINKET

    The Trinket Basic Connections (pinout)

    I/O Pins connect the microcontroller to power, sensors, and actuators.

  • Electronics

  • EElectricity Starts with Electrons

    Electrons are negative (but, nice)

    -

    -

  • ESometimes Electrons Mingle

    In conductive materials, electrons are free to float

    --

    ---

    -

    -

    - -

  • EMix in Some Universal Forces

    NegativePositive

    +-

    Like Yin+Yang, or Good+Evil, one comes with the other

  • EElectricity = Motivated Electrons

    -

    -

    -

    - -

    - -

    -+-

    Electrons are attracted by a positive force

  • EVoltage (volts) = How Motivated

    -

    +

    -

    -

    -

    -

  • ECurrent (amps) = How Many

    +-

    --

    -

    - -- -

    -- -

    -

    --

    -

    -

  • Volts Jolt! Current Kills!

  • EActually, Current is a Little Twisted

    +-

    ++

    +

    ++

    ++

    + ++

    +

    ++

    +

    +

    Current flows positive to negative

  • But, Not Without a Circuit

    +

  • This is a Schematic, BTW

    +

  • Circuits use Components

  • EComponent: Resistor

    +

    HEAT

    VOLTAGE DROP

    + + +++ ++

    +++

  • EComponent: LED (Light Emitting Diode)

    CATHODE / -

    +

    ANODE / +

    -

  • ?

  • More Hacks

  • EThe Button (Digital Input)

  • EComponent: Button (Switch)

    CONNECTED

    1

    2PIN GND

    PIN

    GND

  • >Wiring Up a Single Button

    5V#2

    #1

    #0USB

    RST#3

    #4

    GNDBAT

    JUM

    PER

    WIR

    E JUM

    PER WIRE

  • ELoad / Run the ButtonLED Example

    // Declarations LED boardLED(1); Button pushButton(2); int buttonState; !// Setup runs once at the beginning void setup() { } !// Loop repeats forever void loop() { // Read the switch. Set LED on/off according to button state buttonState = pushButton.isDown(); if (buttonState == 1) { boardLED.on(); } else { boardLED.off(); } }

  • EPushbutton Variable Declaration

    TYPE PINNAME

    Button pushButton(1);

  • EPushbutton isDown Method

    NAME METHOD NAME

    pushButton.isDown();

  • EOther Pushbutton Methods

    pushButton.isDown(); pushButton.isUp(); pushButton.isPressed(); pushButton.isReleased();

  • EBranching (One Thing or Another)

    if (buttonState == 1) { boardLED.on(); } else { boardLED.off(); }

  • EThe If statement (if/then/else)

    if (condition) {

    } else {

    }

    if condition is true

    if condition is false

    conditions:(a == b)(a < b)(a > b)(a = b)(a != b)

  • (Reverse the LogicHack 06:

    1. Reverse the logic in the buttonLED sketch. I.e. make the LED go OFF when the button is pressed. Hint: there are two ways to do this

    2. Stretch: make the LED blink when the button is pressed.Hint: what other LED functions do you have to work with?

  • EThe Knob (Analog Input)

  • EComponent: Knob (Potentiometer)

    +5V

    GND

    Analog Pin

    +5V GND

    Analog Pin

  • EAnalog to Digital Converter (ADC)

    ADCVoltage Values (0-1032)

    0, 25, 100, 300, 100, 1023

  • E

    +5V (USB)

    0

    1

    2