# ESP32 Basic *** ## ESP32 pinout ![image alt](https://lastminuteengineers.b-cdn.net/wp-content/uploads/iot/ESP32-Pinout.png) ## GPIO ### define the GPIO pin ```cpp #define LED1 13 // GPIO Pin 13 #define BTN1 12 // GPIO Pin 12 ``` ### Set-up the GPIO Pin Mode * `pinMode(pin, mode)` * mode * `OUTPUT` * `INPUT` * `INPUT_PULLUP` #### Example ```cpp void setup(){ // set pin 13 as output pinMode(LED1, OUTPUT); // usually inside setup() // set pin 12 as input pinMode(LED1, INPUT); // usually inside setup() } ``` ### Read from the pin * `digitalRead(pin);` * Example * `digitalRead(BTN1);` ### Write to the pin * `digitalWrite(pin, state);` * state: * `HIGH` * `LOW` * Example * `digitalWrite(LED1, HIGH);` *** ## PWM * `analogWrite(pin, value);` * value is between 0 to 255 * No need to set/modify the pre-scaler and counter values ## UART * Breifly talk about what is UART * Require 2 pins for Input and Output * TX , Transmit * RX , Receive * Connection * TX -> RX * RX -> TX * Output bit-stream * usually encoded as a byte * `unsigned char` * `uint8_t` * Asychronized Communciation * Object `Serial` is existed ### Set-up the UART with baudrate ```cpp Serial.begin(115200); // Serial1 be uart1 ``` #### Example ```cpp Serial.printf("Hello World"); ``` *** # Reference : https://lastminuteengineers.com/esp32-pinout-reference/