################## Physical Computing ################## .. toctree:: :hidden: introduction_to_python/index raspberry_pi/index raspberry_pi_pico/index quick_start_guide shell_commands references.rst .. admonition:: Precap The term 'physical computing' started to spread in 2004 with the release of the book *Physical Computing: Sensing and Controlling the Physical World with Computers* by Dan O'Sullivan and Tom Igoe. To a certain amount it replaced the preceeding term 'mechatronics' used by engineers. Raspberry Pi series of boards that are either single-board computers (SBCs) or microcontroller unitys (MCU)consists of a . The objective of this course is to develop basic skills using the `Raspberry Pi Zero W `__ single-board computer (SBC) with the `Python 3 `__ programming language. It is split into several sections, each with a focus on a different aspect of the different hardware interfacing standards that a shared amongs other SBCs and microcontroller units (MCU) like e.g. Arduino. The sections are: .. rst-class:: strong-references * :doc:`introduction_to_python/index`: An introduction to the fundamental elements of the programming language. .. introduction/quick_intro_to_python raspberry_pi/index esp8266_esp32/index glossary.rst .. .. table:: :class: lecture-directory :width: 100% :widths: 10 80 10 +------+--------+-------------------------------+ | | Read | Watch | +======+========+===============================+ | *GPIO: Digital and analog input and output* | +------+--------+-------------------------------+ | | |TX01| | `11’48” `__ | +------+--------+-------------------------------+ | *Digital output* | +------+--------+-------------------------------+ | AP11 | |AP11| | 12’18” | +------+--------+-------------------------------+ | QZ11 | |QZ11| | | +------+--------+-------------------------------+ | *Digital input* | +------+--------+-------------------------------+ | AP12 | |AP12| | 9’22” | +------+--------+-------------------------------+ | *Analog output* | +------+--------+-------------------------------+ | AP13 | |AP13| | 9’22” | +------+--------+-------------------------------+ | *Analog input* | +------+--------+-------------------------------+ | AP14 | |AP14| | 7’44” | +------+--------+-------------------------------+ | AP15 | |AP15| | 7’44” | +------+--------+-------------------------------+ .. | *GPIO: Digital and analog input and output* | +------+--------+-----------------------------+ .. |TX01| replace:: `Overview `__ |br| Almost all The function of each ‘general purpose input output’ (GPIO) terminals can be configured by software. It can be used to control simple components like LEDs, solenoids, DC motors, RC servos, or sense the state of push buttons, photoelectric or temperature sensors, magenetic switches, etc. .. |AP11| replace:: `LED pulse `__ |br| Connect an LED and control its state (dark or lit) by using a GPIO channel as digital output. .. |QZ11| replace:: `LED pulse `__ |br| Change the wiring from AP11 so that it works with the modified code. .. |AP12| replace:: `Push button `__ |br| Connect a push button an sense its state (pushed or released) by using a GPIO channel as digital input. .. |AP13| replace:: `LED PWM `__ |br| Connect an LED and control its brightness by using a GPIO channel as pulse-width modulated (PWM) output. |br| **NOTE:** Only a few MCUs or SBCs have built in digital-to-analog converters (DAC), but all support PWM (one variant of DAC) which only requires a digital output. .. |AP14| replace:: `Potentiometer `__ |br| Connect a potentiometer and read its value (a voltage corresponding to the rotation of the axis) with an analog-to-digital converter (ADC). |br| **NOTE:** Most MCUs or SBCs have built in ADCs – the Raspberry Pi not, so it requires an external ADC. .. |AP15| replace:: `Temperature sensor `__ |br| Connect a temperature sensor and read its value (a voltage corresponding to the temperature) with an analog-to-digital converter (ADC). |br| **NOTE:** Most MCUs or SBCs have built in ADCs – the Raspberry Pi not, so it requires an external ADC. .. table:: :class: lecture-directory :width: 100% :widths: 10 80 10 +------+--------+----------------------------------+ | | Read | Watch | +======+========+==================================+ | *Short distance serial communication interfaces* | +------+--------+----------------------------------+ | TX20 | |TX20| | 12’22” | +------+--------+----------------------------------+ | *I2C* | +------+--------+----------------------------------+ | AP21 | |AP21| | 12’22” | +------+--------+----------------------------------+ | *SPI* | +------+--------+----------------------------------+ | AP22 | |AP22| | 12’22” | +------+--------+----------------------------------+ | *SPI like* | +------+--------+----------------------------------+ | AP23 | |AP23| | 12’22” | +------+--------+----------------------------------+ .. |TX20| replace:: `Overview `__ |br| Selected GPIO terminals can be configured used to communicate with components that use a serial communication interface like UART, I2C, I2S, SPI, CAN. Common examples are e.g. small displays, environment sensors, RFID readers, GPS receivers, etc. .. |AP21| replace:: `7-segment LED display `__ |br| Connecting the 4-digit 7-segment LED display used in this application directly would require 14 wires (and GPIO channels) to control all included 34 LEDs. The printed carrier board (PCB) has a HT16K33 LED controller on its backside which has an I2C interface. This way the number of required wires to connect the display is 4: 2 for power supply and 2 for the the I2C interface. .. |AP22| replace:: `128x64 pixels OLED display `__ |br| Connect an OLED display and control its 8,129 pixels with only 7 wires and the supplied software library. .. |AP23| replace:: `DotStar LED Strips `__ |br| Connect a DotStar LED strip to the SPI bus and control 8 RGB LEDs individually with only 2 wires (+ 2 for power). The communication works with a subset of the SPI standard. .. csv-table:: GPIO: Digital and analog input and output :width: 100% :widths: 90 10 :header: Read, Watch :class: lecture-directory "`Introduction `__ |br| The function of the 'general purpose input output' (GPIO) terminals can be configured by software. It can be used to control simple components like LEDs, solenoids, DC motors, RC servos, or sense the state of push buttons, photoelectric or temperature sensors, magenetic switches, etc.", `12'18" `__ "*Digital Output* |br| *AP1* **Application** `LED pulse `__ |br| Connect an LED and control its state (dark or lit) by using a GPIO channel as digital output. |br| *QZ1* **Quiz** `LED pulse `__ |br| Change the wiring from AP1 so that it fits with the modified code.", `12'18" `__ "*Digital Input* |br| *AP2* **Application** `Push button `__ |br| Connect a push button an sense its state (pushed or released) by using a GPIO channel as digital input.", `—` "*Analog output / Pulse width modulation (PWM)* |br| *AP3* **Application** `LED PWM `__ |br| Connect an LED and control its brightness by using a GPIO channel as PWM output. |br| *NOTE:* True analog output (= a continuosly controllable voltage output) requires a digital-to-analog converter (DAC) and is usually not integreated in popular MCUs or SBCs.", `—` "*Analog input* |br| *AP4* **Application** `Potentiometer `__ |br| Connect a potentiometer and read its current value (rotation of the axis) with an analog-to-digital converter (ADC). |br| *NOTE:* Most MCUs or SBCs have built in ADCs – the Raspberry Pi not, so it requires an external ADC.", `—` "`Short distance serial communication interfaces `__ |br| Selected GPIO terminals can be configured used to communicate with components that use a serial communication interface like UART, I2C, I2S, SPI, CAN. Common examples are e.g. small displays, environment sensors, RFID readers, GPS receivers, etc.", `12'18" `__ "*I2C* |br| AP5 **Application** `7-segment LED display `__ |br| Connecting the 4-digit 7-segment LED display used in this application directly would require 14 wires (and GPIO channels) to control all included 34 LEDs. The printed carrier board (PCB) has a HT16K33 LED controller on its backside which has an I2C interface. This way the number of required wires to connect the display is 4: 2 for power supply and 2 for the the I2C interface.", `—` "*SPI* |br| AP6 **Application** `128x64 pixels OLED display `__ |br| Connect an OLED display and control its 8,129 pixels with only 7 wires and the supplied software library.", — "*SPI like* |br| AP7 **Application** `DotStar LED Strips `__ |br| Connect a DotStar LED strip to the SPI bus and control 8 RGB LEDs individually with only 2 wires. The communication works with a subset of the SPI standard.", — "`Remote control using internet networking standards `__ |br| There are several ways to control a MCU or SBC remotely. Two very common ways are using internet networking standards." "*Local webserver* |br| AP8 **Application** `Direct control using a local webserver `__ |br| Configure an MCUs or SBCs with WiFi so that You can connect directly & without any other network equipment with e.g. a smartphone, setup a minimal web server and use the smartphone to control the MCU or SBC.", `—` "*Message Queue Telemetry Transport (MQTT)* |br| AP9 **Application** `Indirect control using a remote server `__ |br| Connect an MCU or SBC to a network and control it with e.g. Your smartphone over an additional server. A common way is to use the MQTT standard sometimes also referred to as the internet-ot-things (IoT) protocol.", — .. **Exercise** `31-led_fade.py `__, `8'05" `__ **Exercise** `32-rgb_led_set_hex_value.py `__, `8'05" `__ **Exercise** `32-rgb_led_set_hex_value.py `__, `8'05" `__ **Exercise** `33-rgb_led_color_cycle.py `__, `8'05" `__ **Exercise** `34-rc_servo_swivel.py `__, `8'05" `__ "**Exercise** `21-push_button.py `__ |br| **Exercise** `22-push_button_with_irq.py `__ |br| **Exercise** `23-push_button_with_irq_led_toggle.py `__", `8'05" `__ Connecting the 4-digit 7-segment LED display used in this application directly would require 14 wires (and GPIO channels) to control all included 34 LEDs. The printed carrier board (PCB) has a HT16K33 LED controller on its backside which has an I2C interface. This way the number of required wires to connect the display is 4: 2 for power supply and 2 for the the I2C interface.