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

Commit 94bf860

Browse files
authored
Add files via upload
1 parent 71d1efd commit 94bf860

File tree

1 file changed

+55
-60
lines changed

1 file changed

+55
-60
lines changed

README.md

Lines changed: 55 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# ESP8266 TimerInterrupt Library
1+
# ESP8266_ISR_Servo Library
22

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.
44

5-
Why do we need this Hardware Timer Interrupt?
5+
Why do we need this ISR-based Servo control?
66

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().
88

99
So your function might not be executed, and the result would be disastrous.
1010

@@ -26,10 +26,10 @@ https://www.arduino.cc/reference/en/language/functions/external-interrupts/attac
2626
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.
2727

2828
## 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`.
3333

3434
## More useful Information
3535

@@ -42,15 +42,16 @@ The timer1 counters can be configured to support automatic reload.
4242

4343
## New from v1.0.2
4444

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.
4647
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
4748
Therefore, their executions are not blocked by bad-behaving functions / tasks.
4849
This important feature is absolutely necessary for mission-critical tasks.
4950

50-
The `ISR_Timer_Complex` example will 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+
5455
This non-being-blocked important feature is absolutely necessary for mission-critical tasks.
5556
You'll see blynkTimer Software is blocked while system is connecting to WiFi / Internet / Blynk, as well as by blocking task
5657
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
6465
How to use:
6566

6667
```
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
7170
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"
7572
76-
volatile uint32_t lastMillis = 0;
73+
int servoIndex1 = -1;
74+
int servoIndex2 = -1;
7775
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()
10777
{
10878
Serial.begin(115200);
10979
Serial.println("\nStarting");
80+
81+
servoIndex1 = ISR_Servo.setupServo(D8);
82+
servoIndex2 = ISR_Servo.setupServo(D7);
11083
111-
// Interval in microsecs
112-
if (ITimer.attachInterruptInterval(TIMER_INTERVAL_MS * 1000, TimerHandler))
113-
Serial.println("Starting ITimer OK, millis() = " + String(millis()));
84+
if (servoIndex1 != -1)
85+
Serial.println("Setup Servo1 OK");
11486
else
115-
Serial.println("Can't set ITimer correctly. Select another freq. or interval");
87+
Serial.println("Setup Servo1 failed");
11688
89+
if (servoIndex2 != -1)
90+
Serial.println("Setup Servo2 OK");
91+
else
92+
Serial.println("Setup Servo2 failed");
11793
}
11894
119-
void loop()
95+
void loop()
12096
{
121-
97+
int position;
98+
99+
if ( ( servoIndex1 != -1) && ( servoIndex2 != -1) )
100+
{
101+
for (position = 0; position <= 180; position++)
102+
{
103+
// goes from 0 degrees to 180 degrees
104+
// in steps of 1 degree
105+
ISR_Servo.setPosition(servoIndex1, position);
106+
ISR_Servo.setPosition(servoIndex2, 180 - position);
107+
// waits 15ms for the servo to reach the position
108+
delay(50 /*15*/);
109+
}
110+
111+
for (position = 180; position >= 0; position--)
112+
{
113+
// goes from 180 degrees to 0 degrees
114+
ISR_Servo.setPosition(servoIndex1, position);
115+
ISR_Servo.setPosition(servoIndex2, 180 - position);
116+
// waits 15ms for the servo to reach the position
117+
delay(50 /*15*/);
118+
}
119+
}
122120
}
123121
124122
```
@@ -132,10 +130,7 @@ void loop()
132130

133131
For current version v1.0.2
134132

135-
1. Basic hardware timers for ESP8266.
136-
2. Fix compatibility issue causing compiler error while using Arduino IDEs before 1.8.10 and ESP8266 cores 2.5.2 and before
137-
3. More hardware-initiated software-enabled timers
138-
4. Longer time interval
133+
1. Basic 16 ISR-based servo controllers using 1 hardware timer for ESP8266.
139134

140135

141136
## Contributing

0 commit comments

Comments
 (0)