# Raspberry Pi GPIOzero 1. [Materials needed](#materials-needed) 2. [GPIO pinout](#gpio_pinout) 3. [Analog vs. Digital](#analog-vs-digital) 4. [Blink](#blink) 5. [LED PWM](#led-pwm) 6. [Button](#button) 7. [Combining everything](#combining-everything) Your Raspberry Pi is more than just a small computer, it is a hardware prototyping tool! The RPi has **bi-directional I/O pins**, which you can use to drive LEDs, spin motors, or read button presses. To drive the RPi's I/O lines requires a bit or programming. You can use a [variety of programing languages](http://elinux.org/RPi_GPIO_Code_Samples), but we decided to use a really solid, easy tools for driving I/O: **Python**. ### Materials needed * Raspberry Pi 3 B * [Breadboard](https://www.sparkfun.com/products/12002?_ga=1.251311686.1915117394.1476705504) * [Jumper Wires(M/F)](https://www.sparkfun.com/products/12794) * [Momentary Pushbutton Switch](https://www.sparkfun.com/products/9190?_ga=1.213562324.1915117394.1476705504) * [Resistors](https://www.sparkfun.com/products/11507?_ga=1.213562324.1915117394.1476705504) * [2 LEDs](https://www.sparkfun.com/products/9590?_ga=1.213548756.1915117394.1476705504) ### GPIO Pinout Raspberry has its GPIO over a standard male header on the board. From the first models to the latest, the header has expanded from 26 pins to 40 pins while maintaining the original pinout.
##### Comparison chart
||Analog |Digital|
|:------|:-------|:-------|
|**Signal**| Analog signal is a continuous signal which represents physical measurements.| Digital signals are discrete time signals generated by digital modulation.|
|**Waves**| Denoted by sine waves.| Denoted by square waves.|
|**Representation**| Uses continuous range of values to represent information.| Uses discrete or discontinuous values to represent information.|
|**Example**| Human voice in air, analog electronic devices.| Computers, CDs, DVDs, and other digital electronic devices.|
|**Technology**| Analog technology records waveforms as they are.| Samples analog waveforms into a limited set of numbers and records them.|
|**Data transmissions**|Subjected to deterioration by noise during transmission and write/read cycle.|Can be noise-immune without deterioration during transmission and write/read cycle.|
|**Response to Noise**| More likely to get affected reducing accuracy| Less affected since noise response are analog in nature|
|**Flexibility**| Analog hardware is not flexible.|Digital hardware is flexible in implementation.|
|**Uses**|Can be used in analog devices only. Best suited for audio and video transmission.| Best suited for Computing and digital electronics.|
|**Applications**|Thermometer|PCs, PDAs|
|**Bandwidth**| Analog signal processing can be done in real time and consumes less bandwidth.| There is no guarantee that digital signal processing can be done in real time and consumes more bandwidth to carry out the same information.|
|**Memory**| Stored in the form of wave signal.|Stored in the form of binary bit.|
|**Power**| Analog instrument draws large power.| Digital instrument drawS only negligible power.|
|**Cost**|Low cost and portable.| Cost is high and not easily portable.|
|**Impedance**| Low |High order of 100 megaohm|
|**Errors**|Analog instruments usually have a scale which is cramped at lower end and give considerable observational errors.| Digital instruments are free from observational errors like parallax and approximation errors.|
### Blink
We will start with a very easy example, the classic "Blink" example, later we will do the same with our Arduino and see the differences.
##### Hardware Setup
We start assembling the circuit as shown in the diagram below.

##### Code
For the code we are going to use the [GPIOzero](https://gpiozero.readthedocs.io/en/stable/) library which is a on the GPIO library (https://sourceforge.net/p/raspberry-gpio-python/wiki/Home/).
1. From your laptop's terminal connect to the RPi
2. Create a folder called "code" and inside it a file called "blinker.py":
```bash
$ mkdir code
$ cd code
$ nano blinker.py
```
Note: you may not need to create a new folder everytime for the script. I.e. once you have created the folder code, you can create the scripts within the folder with nano