Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Commit

Permalink
v1.2.0 for new ESP32 core
Browse files Browse the repository at this point in the history
### Releases v1.2.0

1. Update to use with ESP32 core v2.0.5+. 
2. Convert to `h-only` style
3. Use `allman astyle` and add `utils`
  • Loading branch information
khoih-prog authored Nov 17, 2022
1 parent 24e63e7 commit 2500e2e
Show file tree
Hide file tree
Showing 22 changed files with 2,051 additions and 648 deletions.
31 changes: 27 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p
Please ensure to specify the following:

* Arduino IDE version (e.g. 1.8.19) or Platform.io version
* `ESP32` Core Version (e.g. ESP32 core v2.0.5)
* `ESP32-S2` Board type (e.g. ESP32S2_DEV Module, ESP32_S2_Saola, etc.)
* Contextual information (e.g. what you were trying to achieve)
* Simplest possible steps to reproduce
Expand All @@ -27,28 +28,50 @@ Please ensure to specify the following:

```
Arduino IDE version: 1.8.19
ESP32 core v2.0.3
ESP32 core v2.0.5
ESP32S2_DEV Module
OS: Ubuntu 20.04 LTS
Linux xy-Inspiron-3593 5.13.0-44-generic #49~20.04.1-Ubuntu SMP Wed May 18 18:44:28 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Linux xy-Inspiron-3593 5.15.0-52-generic #58~20.04.1-Ubuntu SMP Thu Oct 13 13:09:46 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Context:
I encountered a crash while trying to use the Timer Interrupt.
I encountered a crash while using this library
Steps to reproduce:
1. ...
2. ...
3. ...
4. ...
```

### Additional context

Add any other context about the problem here.

---

### Sending Feature Requests

Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful.

There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/ESP32_S2_ISR_Servo/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them.

---

### Sending Pull Requests

Pull Requests with changes and fixes are also welcome!

Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux)

1. Change directory to the library GitHub

```
xy@xy-Inspiron-3593:~$ cd Arduino/xy/ESP32_S2_ISR_Servo_GitHub/
xy@xy-Inspiron-3593:~/Arduino/xy/ESP32_S2_ISR_Servo_GitHub$
```

2. Issue astyle command

```
xy@xy-Inspiron-3593:~/Arduino/xy/ESP32_S2_ISR_Servo_GitHub$ bash utils/restyle.sh
```

257 changes: 172 additions & 85 deletions README.md

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@

[![arduino-library-badge](https://www.ardu-badge.com/badge/ESP32_S2_ISR_Servo.svg?)](https://www.ardu-badge.com/ESP32_S2_ISR_Servo)
[![GitHub release](https://img.shields.io/github/release/khoih-prog/ESP32_S2_ISR_Servo.svg)](https://github.com/khoih-prog/ESP32_S2_ISR_Servo/releases)
[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/khoih-prog/ESP32_S2_ISR_Servo/blob/master/LICENSE)
[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/khoih-prog/ESP32_S2_ISR_Servo/blob/main/LICENSE)
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing)
[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/ESP32_S2_ISR_Servo.svg)](http://github.com/khoih-prog/ESP32_S2_ISR_Servo/issues)


<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Donate to my libraries using BuyMeACoffee" style="height: 50px !important;width: 181px !important;" ></a>
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://img.shields.io/badge/buy%20me%20a%20coffee-donate-orange.svg?logo=buy-me-a-coffee&logoColor=FFDD00" style="height: 20px !important;width: 200px !important;" ></a>
<a href="https://profile-counter.glitch.me/khoih-prog/count.svg" title="Total khoih-prog Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog/count.svg" style="height: 30px;width: 200px;"></a>
<a href="https://profile-counter.glitch.me/khoih-prog-ESP32_S2_ISR_Servo/count.svg" title="ESP32_S2_ISR_Servo Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog-ESP32_S2_ISR_Servo/count.svg" style="height: 30px;width: 200px;"></a>


---
---

## Table of Contents

* [Changelog](#changelog)
* [Releases v1.2.0](#releases-v120)
* [Releases v1.1.1](#releases-v111)
* [Releases v1.1.0](#releases-v110)

Expand All @@ -20,6 +28,12 @@

## Changelog

### Releases v1.2.0

1. Update to use with ESP32 core v2.0.5+.
2. Convert to `h-only` style
3. Use `allman astyle` and add `utils`

### Releases v1.1.1

1. Add support to new Adafruit board QTPY_ESP32S2
Expand Down
129 changes: 67 additions & 62 deletions examples/ESP32_S2_ISR_MultiServos/ESP32_S2_ISR_MultiServos.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
ESP32_S2_ISR_MultiServos.ino
For ESP32_S2 boards
Written by Khoi Hoang
Built by Khoi Hoang https://github.com/khoih-prog/ESP32_ISR_Servo
Built by Khoi Hoang https://github.com/khoih-prog/ESP32_S2_ISR_Servo
Licensed under MIT license
The ESP32 has two timer groups, each one with two general purpose hardware timers. All the timers
are based on 64 bits counters and 16 bit prescalers
The timer counters can be configured to count up or down and support automatic reload and software reload
They can also generate alarms when they reach a specific value, defined by the software.
The value of the counter can be read by the software program.
Now these new 16 ISR-based PWM servo contro uses only 1 hardware timer.
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
Therefore, their executions are not blocked by bad-behaving functions / tasks.
This important feature is absolutely necessary for mission-critical tasks.
Notes:
Special design is necessary to share data between interrupt code and the rest of your program.
Variables usually need to be "volatile" types. Volatile tells the compiler to avoid optimizations that assume
Expand Down Expand Up @@ -78,7 +78,6 @@
#include "ESP32_S2_ISR_Servo.h"

//See file .../hardware/espressif/esp32/variants/(esp32|doitESP32devkitV1)/pins_arduino.h
#define LED_BUILTIN 2 // Pin D2 mapped to pin GPIO2/ADC12 of ESP32, control on-board LED
#define PIN_LED 2 // Pin D2 mapped to pin GPIO2/ADC12 of ESP32, control on-board LED

#define PIN_D0 0 // Pin D0 mapped to pin GPIO0/BOOT/ADC11/TOUCH1 of ESP32
Expand Down Expand Up @@ -133,71 +132,77 @@ int servoIndex2 = -1;

void setup()
{
Serial.begin(115200);
while (!Serial);
Serial.begin(115200);

while (!Serial && millis() < 5000);

delay(500);

Serial.print(F("\nStarting ESP32_S2_ISR_MultiServos on ")); Serial.println(ARDUINO_BOARD);
Serial.println(ESP32_S2_ISR_SERVO_VERSION);

//Select ESP32 timer USE_ESP32_TIMER_NO
ESP32_ISR_Servos.useTimer(USE_ESP32_TIMER_NO);
Serial.print(F("\nStarting ESP32_S2_ISR_MultiServos on "));
Serial.println(ARDUINO_BOARD);
Serial.println(ESP32_S2_ISR_SERVO_VERSION);

//Select ESP32 timer USE_ESP32_TIMER_NO
ESP32_ISR_Servos.useTimer(USE_ESP32_TIMER_NO);

servoIndex1 = ESP32_ISR_Servos.setupServo(PIN_D3, MIN_MICROS, MAX_MICROS);
servoIndex2 = ESP32_ISR_Servos.setupServo(PIN_D4, MIN_MICROS, MAX_MICROS);
servoIndex1 = ESP32_ISR_Servos.setupServo(PIN_D3, MIN_MICROS, MAX_MICROS);
servoIndex2 = ESP32_ISR_Servos.setupServo(PIN_D4, MIN_MICROS, MAX_MICROS);

if (servoIndex1 != -1)
Serial.println(F("Setup Servo1 OK"));
else
Serial.println(F("Setup Servo1 failed"));
if (servoIndex1 != -1)
Serial.println(F("Setup Servo1 OK"));
else
Serial.println(F("Setup Servo1 failed"));

if (servoIndex2 != -1)
Serial.println(F("Setup Servo2 OK"));
else
Serial.println(F("Setup Servo2 failed"));
if (servoIndex2 != -1)
Serial.println(F("Setup Servo2 OK"));
else
Serial.println(F("Setup Servo2 failed"));
}

void loop()
{
int position;

if ( ( servoIndex1 != -1) && ( servoIndex2 != -1) )
{
for (position = 0; position <= 180; position++)
{
// goes from 0 degrees to 180 degrees
// in steps of 1 degree

if (position % 30 == 0)
{
Serial.print(F("Servo1 pos = ")); Serial.print(position);
Serial.print(F(", Servo2 pos = ")); Serial.println(180 - position);
}

ESP32_ISR_Servos.setPosition(servoIndex1, position);
ESP32_ISR_Servos.setPosition(servoIndex2, 180 - position);
// waits 30ms for the servo to reach the position
delay(30);
}

delay(5000);

for (position = 180; position >= 0; position--)
{
// goes from 180 degrees to 0 degrees
if (position % 30 == 0)
{
Serial.print(F("Servo1 pos = ")); Serial.print(position);
Serial.print(F(", Servo2 pos = ")); Serial.println(180 - position);
}

ESP32_ISR_Servos.setPosition(servoIndex1, position);
ESP32_ISR_Servos.setPosition(servoIndex2, 180 - position);
// waits 30ms for the servo to reach the position
delay(30);
}

delay(5000);
}
int position;

if ( ( servoIndex1 != -1) && ( servoIndex2 != -1) )
{
for (position = 0; position <= 180; position++)
{
// goes from 0 degrees to 180 degrees
// in steps of 1 degree

if (position % 30 == 0)
{
Serial.print(F("Servo1 pos = "));
Serial.print(position);
Serial.print(F(", Servo2 pos = "));
Serial.println(180 - position);
}

ESP32_ISR_Servos.setPosition(servoIndex1, position);
ESP32_ISR_Servos.setPosition(servoIndex2, 180 - position);
// waits 30ms for the servo to reach the position
delay(30);
}

delay(5000);

for (position = 180; position >= 0; position--)
{
// goes from 180 degrees to 0 degrees
if (position % 30 == 0)
{
Serial.print(F("Servo1 pos = "));
Serial.print(position);
Serial.print(F(", Servo2 pos = "));
Serial.println(180 - position);
}

ESP32_ISR_Servos.setPosition(servoIndex1, position);
ESP32_ISR_Servos.setPosition(servoIndex2, 180 - position);
// waits 30ms for the servo to reach the position
delay(30);
}

delay(5000);
}
}
Loading

0 comments on commit 2500e2e

Please sign in to comment.