I have a problem connecting arduino mega and esp32. My purpose for esp32 is to provide WIFI and send data to googlesheets or any spreadsheets. And all my components are connected to arduino mega
Welcome to the forum
How are the 2 boards connected and what sketches are running on them ?
my components are connected to arduino mega: Servo 9g, LCD, RFID, Keypad, and rtc. and I want the esp32 to connect to wifi and sends data from arduino to spreadsheet. This is for my project its attendance thing
The simplest connection between the boards to transfer data would be a serial link. The Mega has 4 of them so that is relatively easy
Before doing that I suggest that you get the ESP32 connected to WiFi and sending data to a spreadsheet such as Google Sheets
Yes, I've done that but sending data from arduino to esp32 for sending data to spreadsheet is the challenging part, but I have no idea how. I've search some but couldn't do. Thanks btw
Connect pin 18 of the Mega (Tx for Serial1) to pin 3 (Rx for Serial) of the ESP32. The connection needs to go through a voltage converter to convert 5v from the Mega to 3.3V for the ESP32. Connect GND on the Mega to GND on the ESP32
Once that is done you can print or write data from the Mega to the ESP32
yea thanks a lot, but now
sending the specific data like the rfid tag and send it to esp32 for it to display to google sheet....
What is it that you have done ?
How many data items are there that you want to send from MEGA to ESP32? Please, give an example like:
123, 12.45, Forum, ....
like uid tag number, name of student based on the tag #, time in and out
Can you give an alphanumerical example?
#include <Keypad.h>
#include <Wire.h>
#include <SPI.h>
#include <MFRC522.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
#define SS_PIN 53
#define RST_PIN 48
#define BUZZER_PIN 31
SoftwareSerial Data(13,14);
MFRC522 mfrc522(SS_PIN, RST_PIN);
LiquidCrystal_I2C lcd(0x27, 20, 4);
Servo myservo;
int servoPin=13;
int val;
const byte ROW_NUM = 4;
const byte COLUMN_NUM = 4;
char keys [ROW_NUM][COLUMN_NUM] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte pin_rows[ROW_NUM] = {9,8,7,6};
byte pin_column[COLUMN_NUM]{5,4,3,2};
Keypad keypad = Keypad(makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM);
void setup() {
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
lcd.begin(20,4);
lcd.backlight();
lcd.init();
myservo.attach(13);
pinMode(BUZZER_PIN, OUTPUT);
lcd.setCursor(4,0);
lcd.print("Welcome To");
lcd.setCursor(6,1);
lcd.print("ST12P1");
lcd.setCursor(4,2);
lcd.print("ATTENDANCE");
lcd.setCursor(5,3);
lcd.print("HALLPASS");
}
void loop() {
if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Card UID:");
for (byte i = 0; i < mfrc522.uid.size; i++) {
lcd.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0": "");
lcd.print(mfrc522.uid.uidByte[i],HEX);
}
lcd.setCursor(0,2);
lcd.print("1.ATTENDANCE");
lcd.setCursor(0,3);
lcd.print("2. HALLPASS");
tone();
}
char key = keypad.getKey();
if (key == '1'){
handleAttendance();
} else if (key =='2'){
handleHallpass();
} else {
// lcd.clear();
// lcd.print("Invalid Option");
// Start();
}
mfrc522.PICC_HaltA();
}
void handleAttendance() {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("ATTENDANCE MARKED");
lcd.setCursor(5,1);
for (byte i = 0; i < mfrc522.uid.size; i++) {
lcd.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0": "");
lcd.print(mfrc522.uid.uidByte[i],HEX);
}
delay(500);
tone();
delay(500);
lcd.clear();
Start();
delay(1000);
}
void handleHallpass() {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("HALLPASS GRANTED");
lcd.setCursor(5,1);
for (byte i = 0; i < mfrc522.uid.size; i++) {
lcd.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0": "");
lcd.print(mfrc522.uid.uidByte[i],HEX);
}
move_servo();
delay(2000);
move_servo();
delay(500);
return_servo();
delay(500);
lcd.clear();
Start();
}
void Start() {
lcd.setCursor(4,0);
lcd.print("Welcome To");
lcd.setCursor(6,1);
lcd.print("ST12P1");
lcd.setCursor(4,2);
lcd.print("ATTENDANCE");
lcd.setCursor(5,3);
lcd.print("HALLPASS");
}
void tone(){
tone(BUZZER_PIN, 1000);
delay(500);
noTone(BUZZER_PIN);
}
void move_servo() {
myservo.write(180);
delay(1000);
myservo.write(180);;
delay(1000);
}
void return_servo() {
myservo.write(0);
delay(1000);
myservo.write(0);
}
void Serialdata() {
if (Data.available() > 0) {
// Read RFID tag data
String tagData = Data.readStringUntil('\n');
// Send RFID tag data to ESP32
Serial.println(tagData);
}
}
this my code in my arduino mega and I want to send the rfid datas to the esp-wroom-32 to send it to google sheets
To send the card UID to the ESP32 which is connected to pins 18 and 19, add Serial1.print(.....) after each lcd.print(.....).
Something like
for (byte i = 0; i < mfrc522.uid.size; i++) {
lcd.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0": "");
Serial1.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0": "");
lcd.print(mfrc522.uid.uidByte[i],HEX);
Serial1.println(mfrc522.uid.uidByte[i],HEX);
}
thanks a lot.
do you know how to send data from esp32 to arduino mega to print strings like the name and uid only?
I'm not familiar with the ESP32; I do know that it supports multiple HardwareSerial ports. Maybe 'SoftwareSerial' does not name a type; did you mean 'HardwareSerial'? - #5 by gfvalvo helps to configure a second serial port for communication with the Mega.
do you know how to send esp-wroom-32 to google sheets??
No.
if you do a web search for esp32 googlesheets you will get plenty of links
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.