IDS KIT

THIS PAGE IS A BETA VERSION - ERRORS MAY OCCUR

write to mads@hobye.dk if you find any errors

Getting started // setting up the board

Setting up ESP32 for the first time requires installing the necessary libraries, probably USB drivers. Have a look at the links below for instructions: https://learn.hobye.dk/development/esp32/setup-the-board 

If you are using the old board (DevKIT) then you can find diagrams and code here

Get the onboard LED to blink


#define ONBOARD_LED  2


void setup() {

  pinMode(ONBOARD_LED,OUTPUT);

}


void loop() {

  delay(1000);

  digitalWrite(ONBOARD_LED,HIGH);

  delay(100);

  digitalWrite(ONBOARD_LED,LOW);

}


Get a LED to blink

The resistor is not a requirement for testing - you can connect it directly. If you are making a permanent installation it is neccesary for preventing the LED to burn out quickly.


#define LED_PIN  16


void setup() {

  pinMode(LED_PIN,OUTPUT);

}


void loop() {

  delay(1000);

  digitalWrite(LED_PIN,HIGH);

  delay(1000);

  digitalWrite(LED_PIN,LOW);

}


dim led see her: https://randomnerdtutorials.com/esp32-pwm-arduino-ide/

Dim the led

#define LED_PIN  23


// setting PWM properties

const int freq = 5000;

const int ledChannel = 0;

const int resolution = 8;


void setup() {

  // configure LED PWM functionalitites

  ledcSetup(ledChannel, freq, resolution);

  

  // attach the channel to the GPIO to be controlled

  ledcAttachPin(LED_PIN, ledChannel);

}   


void loop() {

     ledcWrite(ledChannel, 155);

     delay(1000);

     ledcWrite(ledChannel, 255);

     delay(1000);

}


dim led see her: https://randomnerdtutorials.com/esp32-pwm-arduino-ide/

Dim with potmeter

#define LED_PIN  23


// setting PWM properties

const int freq = 5000;

const int ledChannel = 0;

const int resolution = 8;


void setup() {

  // configure LED PWM functionalitites

  ledcSetup(ledChannel, freq, resolution);

  

  // attach the channel to the GPIO to be controlled

  ledcAttachPin(LED_PIN, ledChannel);

  Serial.begin(9600);

}   


void loop() {


    // Serial.println();

     ledcWrite(ledChannel, analogRead(26)/16);

    

}

dim led see her: https://randomnerdtutorials.com/esp32-pwm-arduino-ide/

Push button

A push button is a simple way to create interaction. It can be used to create different outputs depending on the length of the push, the amount of pushes, etc. 

Attach one wire from the button to a digital pin (in the example we have used digital pin 3), and the other to the ground. To test the circuit, use the following code:

int btn_pin = 17;


void setup()  {

  pinMode(btn_pin, INPUT_PULLUP);

  Serial.begin(9600);

}

 

void loop()  {

  boolean btnPressed = !digitalRead(btn_pin);

  if(btnPressed == true)  {

    Serial.println("button has been pressed.");    

  }

}

Button event


int btn_pin = 17;

boolean btnPressedOld = false;


void setup()  {

  pinMode(btn_pin, INPUT_PULLUP);

  Serial.begin(9600);

}




void loop()  {


  boolean btnPressed = !digitalRead(btn_pin);

  if (btnPressedOld == false)

  {

    if (btnPressed == true)  {

      Serial.println("button has been pressed.");

      delay(100);

    }

  }

  btnPressedOld = btnPressed;

}

Toggle the onboard led on/off


int btn_pin = 17;

boolean btnPressedOld = false;

boolean toggleOn = false;

#define ONBOARD_LED  2



void setup()  {

  pinMode(btn_pin, INPUT_PULLUP);

  Serial.begin(9600);

  pinMode(ONBOARD_LED,OUTPUT);

}


void loop()  {

  boolean btnPressed = !digitalRead(btn_pin);

  if (btnPressedOld == false)

  {

    if (btnPressed == true)  {

      toggleOn = !toggleOn;

      Serial.println("button has been pressed.");

      Serial.println(toggleOn);

      delay(100);

    }

  }

  digitalWrite(ONBOARD_LED,toggleOn);

  btnPressedOld = btnPressed;

}

Count the number of presses


int btn_pin = 17;

boolean btnPressedOld = false;

int btnCounterPressed = 0;


void setup()  {

  pinMode(btn_pin, INPUT_PULLUP);

  Serial.begin(9600);

  btnCounterPressed = 0;

}


void loop()  {

  boolean btnPressed = !digitalRead(btn_pin);

  if (btnPressedOld == false)

  {

    if (btnPressed == true)  {

      Serial.println("button has been pressed.");

      btnCounterPressed++;

      Serial.println(btnCounterPressed);

      delay(100);

    }

  }

  btnPressedOld = btnPressed;

}

Potentiometer

A potentiometer is a mechanical device providing a resistance, which can be read as an analogue value using Arduino. When the knob of the potentiometer is turned, the amount of resistance varies, creating increasing and decreasing values. This can be used the same way we use knobs on e.g. speakers to turn up or down the volume. 

The three wires of the potentiometer go to ground, 5v and one of the analogue pins (in this example A0).  

Use this code to read the value in the serial monitor:

int potPin =33;


void setup() {

  Serial.begin(9600);

}

 

void loop() {

  int sensorValue = analogRead(potPin);

  Serial.println(sensorValue);

  delay(100);

}

For using a piezo as a buzzer look here

https://esp32io.com/tutorials/esp32-button-piezo-buzzer

Piezo -  as a knock sensor

The Piezo is a sensor which produces AC voltage when in movement. It can be used both as a source of input and output. It creates input when moved, flickered or shaken (could be by the knock of a hand, by a sound wave, etc.) and can be used for interactions where differing intensities or types of movement gives different outputs.

Connect ground to ground and power to analog pin 0, using a 1 M ohm resistor (breadboard is optional).

Use the following code to read the values (ADC) and convert into voltage:

const int PIEZO_PIN = 33;

 

void setup()  {

  Serial.begin(9600);

}

 

void loop()  {

  int piezoADC = analogRead(PIEZO_PIN);

  float piezoV = piezoADC / 1023.0 * 5.0;

  Serial.println(piezoV);

}

You have already been presented to the int and boolean variables. Read here for more information about the float variable, or here for the const variable.

OBS! For using analog input you can ONLY use the pins with an ADC channel AND if you plan to use WIFI then you need to use a pin with ADC1. When you use WIFI, ADC2 will be disabled. 

Use a joystick

The joystick is a combination of one button and two potentiometers. 

const int BTN_PIN = 35;

const int VER_PIN = 34;

const int HOR_PIN = 33;


void setup()  {

  Serial.begin(9600);

  pinMode(BTN_PIN, INPUT);

}


void loop()  {

  Serial.println(digitalRead(BTN_PIN));

  Serial.println(analogRead(VER_PIN));

  Serial.println(analogRead(HOR_PIN)); 

}

Warning the order on the black joystick button is different. On the black joystick the 

GND = GND

V5 = VCC = 3x3V

VRX = HOR

VRY= VER

SW = SEL

MPU: Sensing movement and direction

The MPU is a version of an IMU (inertia measurement unit) sensor, which can measure three-dimensional movement and positions. The MPU is a combination of an accelerometer (measures gravitational acceleration) and a gyroscope (measures rotational velocity). 

Install the library “MPU6050” by Adafruit – it might ask you to install a series of other libraries in order for this to run. 

Go to – File – Examples – Adafruit MPU6050 – and chose the example called “plotter” in order to read the values from the accelerometer in the serial plotter.

You need to install the MPU6050_tockn library


#include <MPU6050_tockn.h>

#include <Wire.h>


MPU6050 mpu6050(Wire);


void setup() {

  Serial.begin(9600);

  Wire.begin();

  mpu6050.begin();

  mpu6050.calcGyroOffsets(true);

}


void loop() {

  mpu6050.update();

  Serial.print("angleX : ");

  Serial.print(mpu6050.getAngleX());

  Serial.print("\tangleY : ");

  Serial.print(mpu6050.getAngleY());

  Serial.print("\tangleZ : ");

  Serial.println(mpu6050.getAngleZ());

}

Before displaying text on the LCD, you need to find the LCD I2C address. So follow this guide to set it up properly:

https://iotbyhvm.ooo/i2c-lcd-esp32-arduino-ide/

OBS: Pin 22 is the SCL pin and pin 21 is the SDA pin.



https://randomnerdtutorials.com/esp32-ssd1306-oled-display-arduino-ide/


http://www.getmicros.net/esp8266-and-128-x-32-oled-example.php

RGB LED

https://esp32io.com/tutorials/esp32-rgb-led