01 Microcontrollers
Microcontrollers (MCUs) are small computers that only run a single program. MCUs are different from single-board computers like the Raspberry Pi, which run a full operating system.
Hardware
We use the following two microcontrollers in this course:
- Feather HUZZAH ESP8266
- Feather nRF52840 Express
Input and Output
To interact with the “real world” microcontrollers use GPIO (general-purpose input and output) pins. These pins can be used to attach sensors (e.g. temperature sensor) or actuators (e.g. an LED) which can then be read from/written to by the MCU. Pins are only named by their numbers and need to be setup correctly before they can be used in the program.
pinMode(<pin>, <type>) // configure <pin> to be input or output
digitalRead(<pin>)
analogRead(<pin>)
digitalWrite(<pin>)
analogWrite(<pin>)
Sensors
Sensors are used to read data. They convert physical properties to electrical signals.
A sensor can either be digital (0 or 1) or analog (e.g. 0 - 1024).
Actuators
Actuators are used to write data. They convert electrical signals to physical properties.
Actuators can also be either digital (on or off) or analog (PWM, pulse-width modulation).
Examples
stateDiagram [*] --> on on --> off: press off --> on: press
Kitchen Timer
As an exercise we implemented a simple kitchen timer. The user should be able to set a timer, start it and once it reaches zero an alarm should trigger.