Skip to content

Chikurin1014/GPIOlib-for-ESP32Arduino

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GPIO_lib-for-ESP32Arduino

Library for using GPIO of ESP32 on Arduino

Installation

Add this statement to platform.ini on you project:

lib_deps = https://github.com/Tokoroten2003/GPIOlib-for-ESP32Arduino.git

and run:

$ pio init

Usage

You can use types of GPIO:

  • DigitalIn
  • DigitalOut
  • AnalogIn
  • AnalogOut

DigitalIn

Include DigitalIn.hpp

#include "DigitalIn.hpp"

Initialize like this:

gpio::DigitalIn digital_in(/* pin number */);

In setup(), you need to call DigitalIn::setup() on each pins you defined.

void setup() {
    digital_in0.setup();
    digital_in1.setup();
    // ...
}

If you want to read value on a pin, call DigitalIn::read() on it.

void loop() {
    uint8_t value = digital_in.read(); // returns 0 / 1
}

DigitalOut

Include DigitalOut.hpp

#include "DigitalOut.hpp"

Initialize like this:

gpio::DigitalOut digital_out(/* pin number */);

In setup(), you need to call DigitalOut::setup() on each pins you defined.

void setup() {
    digital_out0.setup();
    digital_out1.setup();
    // ...
}

If you want to output value to a pin, call DigitalOut::write() on it.

void loop() {
    uint8_t value = HIGH; //  HIGH / LOW / unsigned integral number
    digital_out.write(value);
}

AnalogIn

Include AnalogIn.hpp

#include "AnalogIn.hpp"

Initialize like this:

gpio::AnalogIn analog_in(/* pin number */);

In setup(), you need to call AnalogIn::setup() on each pins you defined.

void setup() {
    analog_in0.setup();
    analog_in1.setup();
    // ...
}

If you want to output value to a pin, call AnalogIn::read() on it.

void loop() {
    int value = analog_in.read(); // returns integral number (0 ~ 4095)
}

AnalogOut

Include AnalogOut.hpp

#include "AnalogOut.hpp"

Initialize like this:

gpio::AnalogOut analog_out(/* pin number */, /* ch */,/* freq */, /* resol bits */);
  • ch ... pwm channel
  • freq ... pwm frequancy
  • resol bits ... resolution bits (resolution: 2^resol bits)

In setup(), you need to call AnalogOut::setup() on each pins you defined.

void setup() {
    analog_out0.setup();
    analog_out1.setup();
    // ...
}

If you want to output value to a pin, call AnalogOut::write() on it.

void loop() {
    analog_out.write(64); // unsinged integral number (0 ~ 2^resol bits - 1)
}

setupPins()

This function is not allowed before c++17

You can use setupPins() to setup multiple pins at the same time.

gpio::AnalogIn pin0(0);
gpio::AnalogOut pin1(2);
gpio::DigitalIn pin2(4);
gpio::DigitalOut pin3(5);
void setup() {
    gpio::setupPins(pin0, pin1, pin2, pin3); // setup pin0, pin1, pin2 and pin3 at the same time
}

About

Library for using GPIO-pins of ESP32 on Arduino

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages