SOLVED* Took out the serial crap output from ESP.
My UNO tends to operate REALLY slow, lag of 0-4 seconds (alteranating) when it’s hooked up thru serial to ESP12. I pull the rx and tx and things respond quick again. I’m stumped why the thing is slowing down so much, I only am transmitting 5 bytes / sec to the ESP and the ESP is sending about at same rate.
Here is code for ESP 1/1
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
const char* ssid = "JMR";
const char* password = "crystal2965";
WiFiUDP Udp;
unsigned int localUdpPort = 8888; // local port to listen on
char receivedChars[255]; // buffer for incoming packets
char replyPacket[] = "Hi there! Got the message :-)"; // a reply string to send back
boolean newData;
int numChars = 255;
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.printf("Connecting to %s ", ssid);
IPAddress ip(192, 168, 1, 137);
IPAddress gw(192, 168, 1, 254);
IPAddress dns(192, 168, 1, 254);
IPAddress sn(255, 255, 255, 0);
WiFi.config(ip, gw, sn, dns);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println(" connected");
Udp.begin(localUdpPort);
Serial.printf("Now listening at IP %s, UDP port %d\n", WiFi.localIP().toString().c_str(), localUdpPort);
}
void recvWithEndMarker() {
static byte ndx = 0;
char endMarker = '\n';
char rc;
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
}
}
}
void showNewData() {
if (newData == true) {
sendUDP();
Serial.print("This just in ... ");
Serial.println(receivedChars);
newData = false;
}
}
void sendUDP() {
Udp.beginPacket("192.168.1.139", 8888);
Udp.write(receivedChars);
Udp.endPacket();
}
void pingOut() {
Udp.beginPacket("192.168.1.139", 8888);
Udp.write("ping");
Udp.endPacket();
}
void loop() {
recvWithEndMarker();
showNewData();
sendUDP();
pingOut();
delay(500);
}
Here is code for UNO 1/4
//*****************************************************************************************************************************************************************
// -1: InputPullup, 0: Not installed, 1: Input Positive, 2: OUTPUT
const int installed[20] = { 0, 0, 1, -1, -1, -1, -1, 2, 2, -1, 1, 2, 2, 2, 2, 2, -1, 2, 0, 0 };
const char* pinNames[20] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "A0", "A1", "A2", "A3", "A4", "A5" };
const char* ssNames[20] = { "Rx", "Tx", "pr7", "mc7", "bo7", "dr7", "pb7", "PX7", "HO8", "c8r", "gl7", "LG8", "LR8", "RS7", "AL7", "PW7", "rd8", "LB8", "SCL", "SDA" };
const int pr7 = 2, bo7 = 4, pb7 = 6, c8r = 9, LG8 = 11, RS7 = 13, PW7 = A1, LB8 = A3 ;
const int mc7 = 3, dr7 = 5, PX7 = 7, HO8 = 8, gl7 = 10, LR8 = 12, AL7 = A0, rd8 = A2;
// *****************************************************************************************************************************************************************
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
// *******
// ******
float pirActivity;
int arrMax = 20, beeps, beepLen, beepRepeat, beepRepeatS, dirc, doorOpens, doorOpenTime, doorState, entering, iPing, i, iG, iBeep, hookedUp, loops, loops2, pr8Hits, parsed, pexUnlock, powerBoostInc, target;
int redState[3], redRun[3], redIntervalOn[3], redIntervalOff[3];
int beepInterval;
long unsigned doorMS, eventTime, hertz, pexPush, beepMS, redCycle[3], pirMS, c8rTimer, runOn, runTotal, lastMillis, ESPReset;
String eventName, beepEvent;
String eventSound;
int now[20] = { 0 } ; //Set prior to parse
int was[20] = { 0 } ; //Set after parse
int distanceA[8] = { 0 };
long unsigned last[20] = { 0 }; //Millis of last trigger (state change)
long flashStop[3];
const int beepArrSize = 40; // Carefully set this, can cause corruption!
const int deBounceMS = 30; // Debounce delay
const int delayMS = 10; //Loop Delay
const int loopsMax = 5; //Secondary Loop Divider
const long unsigned noKeysDelay1 = 10000; // Delay to unlock once
const long unsigned noKeysDelay = 300000; // Delay to unlock second time
const int delayDoorOpen = 20100; // Please Close Door Delay
const int c8rTimerMax = 180123; // Time to run powerBoost
// ***********************************************************
void setup() {
// put your setup code here, to run once:
digitalWrite(AL7, HIGH);
digitalWrite(PW7, HIGH);
digitalWrite(RS7, HIGH);
pexPush = 99999999L;
pexUnlock = 2;
digitalWrite(PX7, LOW);
//flash("blue", 500, 2000, -1);
doorMS = 999100200L;
loops = 0;
for (i = 0; i < arrMax; i++) {
// Array init loop
// Set pin-modes based on installed flags
if (installed[i] == -1) {
pinMode(i, INPUT_PULLUP);
}
if (installed[i] == 0) {
pinMode(i, INPUT_PULLUP);
}
if (installed[i] == 1) {
pinMode(i, INPUT);
}
if (installed[i] == 2) {
pinMode(i, OUTPUT);
}
}
if ((digitalRead(pb7) == LOW) && (digitalRead(dr7) == LOW)) hookedUp = 1;
if (hookedUp == 0) {
Serial.begin(115200); // Serial flag - serial doesn't run on Project.
}
hookedUp = 1;
if (hookedUp == 0) {
eventName = "Node 7 - PC Mode.";
}
if (hookedUp == 1) eventName = "Node 7 - Init.";
lcd.init();
lcd.print(eventName);
lcd.backlight();
beep(1); // Start Chime
}
// **************
void beepRepeatSet() {
//BeepRepeatSet: Add 1x000 where x is 2^(x-1) times to repeat
char hertzA[6];
char hertzR;
int hertzI, hertzLen;
itoa(hertzA, hertz, 10);
hertzLen = strlen(hertzA);
hertzR = hertzA[2];
hertzI = atoi(hertzR);
beepRepeat = 2 ^ (hertzI - 1);
if ((hertzI < 2) || (hertzLen < 6)) beepRepeat = 0;
Serial.println(beepRepeat);
}
void loop0() {
// Most rapid loop. Ran in place of delays.
//Serial.print(millis());
flash("0", 0, 0, 0); // Cycle flashing
}