Hi there
I´m currently working on my owm Time Circuits from back to the Future.
The setup is as follows.
Wemos D1 Mini (Esp8266 12E) -> This chip drives 3 Led multiplexed drivers (Ht16k33) for each Time display. Also Im running a NTP poll server request to sync the time from the web. So no RTC or GPS for now (this may possibly change)
Arduino -> running the 4x3 keypad. Later the arduino will also run the Sounf FX of the digit pressing and startup and setting etc, also the arduino already logs each digit that is pressed and store the variable "date" in a char array.
Now I need the arduino to relay the char[14] to the esp.
I tried Hw Serial using TX/RX pins of the Esp8266 and using Sw serial on arduino, changing baudrates and nothing happened.
The arduino transmits the variable correctly (I think) If I connect a serial to usb converter in the TX/RX pins of arduino I see the info coming out.
Problem is to get the info in the ESP8266. I read something about CR and NL but I´m not quite sure how to implement.
Also if I use SWSerial on both chips do I still need to use CR and NL in the Esp?
Another idea was to use whe Wire library to fetch the char array from the arduino using the already implemented I2C comms but I dont know if this will or can interfere with the 3 I2C display drivers?
Sorry I tried to do research but I think it will be better to ask the community based on my setup and requirementes which will be the best way to use, and then search or ask for guidance in that direction.
Here is the sketch of the arduino keypad and sound controller that needs to relay the char variable to the esp
#include <everytime.h>
#include <Keypad.h>
#include <SoftwareSerial.h>
SoftwareSerial ESPserial(10, 11); // RX | TX
char Date[14];
byte date_count = 0;
const byte FILAS = 4; //four FILAS
const byte COLS = 3; //three columns
char keys[FILAS][COLS] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{' ', '0', ' '}
};
byte rowPins[FILAS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, FILAS, COLS);
void setup() {
Serial.begin(9600); // communication with the host computer
//while (!Serial) { ; }
// Start the software serial for communication with the ESP8266
ESPserial.begin(115200);
}
void loop() {
char customKey = customKeypad.getKey();
if (customKey) {
Date[date_count] = customKey;
date_count++;
Serial.print("Tecla :"); Serial.println(customKey);
}
if (date_count > 13)
{
clearDate();
}
every(1000)
{
Serial.print("Date count :"); Serial.println(date_count);
Serial.print("Date :"); Serial.println(Date);
ESPserial.write(Date);
Serial.println("");
}
}//Loop
void clearDate() {
while (date_count != 0) {
Date[date_count--] = 0;
}
return;
}
And here is the code of the ESP8266 that needs to receive the char variable from the arduino and then drive the 3 led displays. Not totally retrofited for the purpose at hand, just tested with serial monitor
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
//**************************************************************************Hora wifi
#include <TimeLib.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
const char ssid[] = "*******"; // your network SSID (name)
const char pass[] = "********"; // your network password
// NTP Servers:
static const char ntpServerName[] = "0.pool.ntp.org";
#define timeZone -3
WiFiUDP Udp;
unsigned int localPort = 8888; // local port to listen for UDP packets
time_t getNtpTime();
void sendNTPpacket(IPAddress &address);
//**************************************************************************Hora wifi
Adafruit_8x16matrix display[3] = Adafruit_8x16matrix();
int vsegundo, vminuto, vhora, vdia, vmes;
int anio; //variable año
String vDia;
String vAnio;
String vHora;
String vMinuto;
String fechaFuturo = "1026198509001";
String lastFechaFuturo = "1112195506381";
String fechaPasado;
String lastFechaPasado;
unsigned long previousMillis = 0;
unsigned long previousMillis2 = 0;
//unsigned long currentMillis = 0;
void setup() {
Serial.begin(9600);
//Wifi
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(2000);
Serial.print(".");
}
Serial.print("IP number assigned by DHCP is ");
Serial.println(WiFi.localIP());
Serial.println("Starting UDP");
Udp.begin(localPort);
Serial.print("Local port: ");
Serial.println(Udp.localPort());
Serial.println("waiting for sync");
setSyncProvider(getNtpTime);
setSyncInterval(500);
//Wifi
Serial.println("BTTF Time Circuits powering on");
display[0].begin(0x70); //Rojo
display[1].begin(0x71); //Verde
display[2].begin(0x72); //Amarillo
//display[1].setBrightness(15);
for (int i = 0; i <= 2; i++)
{
display[i].clear();
}
}//Cierra Setup
void loop()
{
if (Serial.available() > 2)
{
fechaFuturo = Serial.readString();
Serial.print("fechaFuturo: "); Serial.println(fechaFuturo);
Serial.print("lastFechaFuturo: "); Serial.println(lastFechaFuturo);
display[0].clear();
}
handleSerial();
mostrarRojo(0);
presentTime();
mostrarAmarillo(2);
AMPM();
if (millis() - previousMillis >= 1000)
{
HoraSerial();
Serial.print("Fecha Futuro: "); Serial.println(fechaFuturo);
Serial.print("Fecha Pasado: "); Serial.println(lastFechaFuturo);
previousMillis = millis();
}
if (millis() - previousMillis2 >= 500)
{
Blink();
previousMillis2 = millis();
WriteDisplay();
}
lastFechaFuturo = fechaFuturo;
}//Cierra Loop
I also considered to use a nodemcu to read the key inputs of the keypad and drive everything but the <keypad.h> library is not compatible with the <ESP8266WiFi.h> library. So my options are to use a wemos d1 mini and an arduino like proposed or to change the sketch of the Esp8266 to use a GPS module to sync the current time thus eliminating the need of the wifi library and enabling the chip to use the kepay library.
Thanks for your patience.