You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 29, 2023. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+55-60Lines changed: 55 additions & 60 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
-
# ESP8266 TimerInterrupt Library
1
+
# ESP8266_ISR_Servo Library
2
2
3
-
This library enables you to use Interrupt from Hardware Timers on an ESP8266-based board.
3
+
This library enables you to use 1 Hardware Timer on an ESP8266-based board to control up to 16 servo motors.
4
4
5
-
Why do we need this Hardware Timer Interrupt?
5
+
Why do we need this ISR-based Servo control?
6
6
7
-
Imagine you have a system with a mission-critical function, measuring water level and control the sump pump or doing something much more important. You normally use a software timer to poll, or even place the function in loop(). But what if another function is blocking the loop() or setup().
7
+
Imagine you have a system with a mission-critical function, controlling a robot arm or doing something much more important. You normally use a software timer to poll, or even place the function in loop(). But what if another function is blocking the loop() or setup().
8
8
9
9
So your function might not be executed, and the result would be disastrous.
2. Typically global variables are used to pass data between an ISR and the main program. To make sure variables shared between an ISR and the main program are updated correctly, declare them as volatile.
27
27
28
28
## Installation
29
-
1. Navigate to (https://github.com/khoih-prog/ESP8266TimerInterrupt) page.
30
-
2. Download the latest release `ESP8266TimerInterrupt-master.zip`.
31
-
3. Extract the zip file to `ESP8266TimerInterrupt-master` directory
32
-
4. Copy whole folder to Arduino libraries' directory such as `.Arduino/libraries/ESP8266TimerInterrupt-master`.
29
+
1. Navigate to (https://github.com/khoih-prog/ESP8266_ISR_Servo) page.
30
+
2. Download the latest release `ESP8266_ISR_Servo-master.zip`.
31
+
3. Extract the zip file to `ESP8266_ISR_Servo-master` directory
32
+
4. Copy whole folder to Arduino libraries' directory such as `.Arduino/libraries/ESP8266_ISR_Servo-master`.
33
33
34
34
## More useful Information
35
35
@@ -42,15 +42,16 @@ The timer1 counters can be configured to support automatic reload.
42
42
43
43
## New from v1.0.2
44
44
45
-
Now with these new `16 ISR-based timers`, the maximum interval is practically unlimited (limited only by unsigned long miliseconds)
45
+
Now these new `16 ISR-based Servo controllers` just use one ESP8266 Hardware Timer. The number 16 is just arbitrarily chosen, and depending
46
+
on application, you can increase that number to 32, 48, etc. without problem.
46
47
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
47
48
Therefore, their executions are not blocked by bad-behaving functions / tasks.
48
49
This important feature is absolutely necessary for mission-critical tasks.
49
50
50
-
The `ISR_Timer_Complex` examplewill demonstrate the nearly perfect accuracy compared to software timers by printing the actual
51
-
elapsed millisecs of each type of timers.
52
-
Being ISR-based timers, their executions are not blocked by bad-behaving functions / tasks, such as connecting to WiFi, Internet
53
-
and Blynk services. You can also have many `(up to 16)` timers to use.
51
+
The `MultipleServos` example, which controls 6 servos independently, will demonstrate the nearly perfect accuracy.
52
+
Being ISR-based servo controllers, their executions are not blocked by bad-behaving functions / tasks, such as connecting to WiFi, Internet
53
+
and Blynk services.
54
+
54
55
This non-being-blocked important feature is absolutely necessary for mission-critical tasks.
55
56
You'll see blynkTimer Software is blocked while system is connecting to WiFi / Internet / Blynk, as well as by blocking task
56
57
in loop(), using delay() function as an example. The elapsed time then is very unaccurate
@@ -64,61 +65,58 @@ in loop(), using delay() function as an example. The elapsed time then is very u
64
65
How to use:
65
66
66
67
```
67
-
//These define's must be placed at the beginning before #include "ESP8266TimerInterrupt.h"
68
-
#define TIMER_INTERRUPT_DEBUG 1
69
-
70
-
#include "ESP8266TimerInterrupt.h"
68
+
#define TIMER_INTERRUPT_DEBUG 1
69
+
#define ISR_SERVO_DEBUG 1
71
70
72
-
#ifndef LED_BUILTIN
73
-
#define LED_BUILTIN 2 // Pin D4 mapped to pin GPIO2/TXD1 of ESP8266, NodeMCU and WeMoS, control on-board LED
74
-
#endif
71
+
#include "ESP8266_ISR_Servo.h"
75
72
76
-
volatile uint32_t lastMillis = 0;
73
+
int servoIndex1 = -1;
74
+
int servoIndex2 = -1;
77
75
78
-
void ICACHE_RAM_ATTR TimerHandler(void)
79
-
{
80
-
static bool toggle = false;
81
-
static bool started = false;
82
-
83
-
if (!started)
84
-
{
85
-
started = true;
86
-
pinMode(LED_BUILTIN, OUTPUT);
87
-
}
88
-
89
-
#if (TIMER_INTERRUPT_DEBUG > 0)
90
-
if (lastMillis != 0)
91
-
Serial.println("Delta ms = " + String(millis() - lastMillis));
92
-
lastMillis = millis();
93
-
#endif
94
-
95
-
//timer interrupt toggles pin LED_BUILTIN
96
-
digitalWrite(LED_BUILTIN, toggle);
97
-
toggle = !toggle;
98
-
}
99
-
100
-
#define TIMER_INTERVAL_MS 1000
101
-
102
-
// Init ESP8266 timer 0
103
-
ESP8266Timer ITimer;
104
-
105
-
106
-
void setup()
76
+
void setup()
107
77
{
108
78
Serial.begin(115200);
109
79
Serial.println("\nStarting");
80
+
81
+
servoIndex1 = ISR_Servo.setupServo(D8);
82
+
servoIndex2 = ISR_Servo.setupServo(D7);
110
83
111
-
// Interval in microsecs
112
-
if (ITimer.attachInterruptInterval(TIMER_INTERVAL_MS * 1000, TimerHandler))
0 commit comments