Introduction To Physical Computing (Part 2) PDF
Document Details
Uploaded by TopNotchBanjo8176
The University of Sydney
Eduardo Velloso
Tags
Summary
This document is a set of lecture notes for a course on physical computing, specifically covering part 2. It explores various aspects of physical computing, introducing concepts like microcontrollers, Arduino programming, and electronic components. The study material examines topics, including the basics of electricity, electronic components, and methods of interfacing various electronic parts. The document also includes examples of using Arduino, code demonstrations, and details alternative methods like using delta-sigma modulation instead of standard PWM.
Full Transcript
COMP5047 INTRODUCTION TO PHYSICAL COMPUTING (part 2) Eduardo Velloso Recap Microcontrollers (Arduino, ESP32) Electricity basics (voltage, current, resistance, Ohm’s law, short circuits) Arduino programming setup() and loop() digitalRead() and digitalWrite()...
COMP5047 INTRODUCTION TO PHYSICAL COMPUTING (part 2) Eduardo Velloso Recap Microcontrollers (Arduino, ESP32) Electricity basics (voltage, current, resistance, Ohm’s law, short circuits) Arduino programming setup() and loop() digitalRead() and digitalWrite() Pins Digital x analogue High x low Electronic components (LEDs, batteries, buttons, breadboards, datasheets, pullup/down resistors) TRAFFIC LIGHT 2s 1s 2s REFACTORING THE CODE rewrite the code to make it more clear TRAFFIC LIGHT 2s Pause 1s 2s use build-in pull up resistor, so hIGH when in the delay, no value or reacts will be used What’s the problem? https://www.arduino.cc/reference/en/language/functions/time/delay/ Solution: use a timer Counting presses …but in practice this fails Switches are mechanical components They bounce when you press, so the same press might register multiple times whenever you press the switch, there is some level of bouncing of the switch. 4x presses What we want What we get Debouncing the value only be recorded not within certain windows ANALOG OUTPUT DIGITAL ANALOG INPUT digitalRead() analogRead() OUTPUT digitalWrite() analogWrite() Digital Output Limitation: Arduino can only output digital signals (0 or 1, i.e., low or high). However, sometimes we need to simulate analog values (continuous range between 0 and 1). Solution: PWM (Pulse Width Modulation): PWM allows Arduino to approximate analog signals by rapidly switching between high (1) and low (0) states. The average output value depends on the proportion of time spent in the high state versus the low state. How PWM Works: The hidden truth: Duty Cycle: The percentage of time the signal stays high during each cycle determines the average value. Example: 50% duty cycle → High and Low states are equal, resulting in an average value of 0.5. Frequency: The Arduino sends these pulses very quickly, at several cycles per second, to create a smooth perceived signal. Hardware Considerations: Arduinos are digital only! Not every Arduino pin supports PWM; only certain pins are designed for it. PWM is the most basic technique for simulating analog output, though other methods exist. Arduino only output digital values How can we get analogue values? PWM: Pulse Width Modulation So the the Arduino has a 16 bit analogue digital to analogue converter, and that means that it can. So 16 bits means that it can encode 256 values, so 255 would be 10 would be zero, and anything between will be a percentage of 255. So 127 and 28. That's half of 256. So that's at 50%. 255 means 1; 0 means 0, and anything between 0 and 255 is the percentage of 255 An R GB LED is three LED S in one. So inside an R GB LED you have a blue, red and green LE LED S inside and you are controlling the how bright each of them are. And by mixing those colours, you get any arbitrary colour More options on the ESP32 LEDC API Library to control LEDS Works on 16 channels instead of the 18 pins You can then attach pins to channels Delta-sigma modulation module Similar to PWM, but instead of varying the duration of the pulses, it varies the frequency of pulses with the same duration Digital-to-analog converter Real analog signals Two 8-bit DACs in pins 25 and 26 https://makeabilitylab.github.io/physcomp/esp32/led-fade.html ANALOG INPUT DIGITAL ANALOG INPUT digitalRead() analogRead() OUTPUT digitalWrite() analogWrite() What is a Potentiometer? A potentiometer is a type of variable resistor used to measure or control voltage. Common examples include sliders or knobs for adjusting input values. Structure: Resistive Band: Contains a resistive material that determines its resistance. Three Pins: Pin 1: Connects to ground. Pin 2 (Middle Pin): Captures the output voltage based on the wiper's position. Pin 3: Connects to VCC (positive voltage supply). How It Works: The potentiometer functions as a voltage divider: The wiper (the part that moves along the resistive band) adjusts the resistance. Extreme Positions: Wiper at one end: Output = 0V (no resistance). Wiper at the other end: Output = full voltage (maximum resistance). Middle Positions: Output voltage is proportional to the wiper's position on the resistive band. What is the highest voltage possible on the potentiometer? What is the highest value read by the Arduino? Other analogue sensors Photoresistor Phototransistor Temperature Flex Force Joystick Accelerometer Gyroscope Magnetometer (acceleration) (angular velocity) (magnetic flux) MECHANICAL ACTUATION Sop here Stepper motor DC motor Servo motor When to use them Servo Motor Precise control over position, speed, and torque, especially in robotics, CNC machines, and automation. Stepper Motor Open-loop control systems where precise movement in small steps is required, such as 3D printers, CNC machines, cameras. DC Motor Precise positioning not crucial, like fans and conveyors DC Motor DC Motor Simplest electric motor Rotates 360 degrees but you cannot precisely control its angle Two challenges It typically requires more current than a microcontroller can provide Needs an external power supply You need to control the current that flows back as it powers down Needs a diode or a motor controller chip Stepper motor Stepper motor Open loop Full rotation Precise control Controlled with a motor driver Send pulse -> Rotate one step (200 steps/rotation) Servo Servomotor Rotary actuator for precise control of angles Motor + pot + control circuit Low power servos can be powered directly from the microcontroller More powerful ones/multiple ones require an external power supply You can still control it from your microcontroller, but the red wire must be connected to an external supply Limited range: typically around 180 degrees 3 wires Red: Vcc Brown: Ground Orange: Control First test the photoresistor: what are the min and max values it outputs? Then map them to the servo angles Why do we need the 10K resistor?