Posts: 15
Threads: 3
Joined: Dec 2023
Reputation:
0
Hello,
I have an A8S card.
This card has an buzzer or beep at GPIO 2
I have a software that search for a valid wifi, using wifi events. After each disconnection it will try the next available wifi until it can get an ip. Sometimes there is no wifi at all and the system loop for ever.
The use of pin 2 seams to have a conflict with the wifi.
When the system loop the beep turn on, even I switch it to off.
Is that any means to switch off the beep ?
I can provide code if this is needed
Many thanks for your help.
Best regards
Thierry
Posts: 15
Threads: 3
Joined: Dec 2023
Reputation:
0
01-16-2024, 05:06 PM
(This post was last modified: 01-16-2024, 05:21 PM by Vorms.)
Many thanks for yur reply.
You will find the minimum script to do the troble.
If you run the script, the buzzer make a lot of noise.
#include "esp_wifi.h"
#include <WiFi.h>
#define BEEP 2
void WiFiStationConnected(WiFiEvent_t event, WiFiEventInfo_t info){
Serial.printf("%lu:: Connected to AP successfully, SSID: %s, level: %d [dB]\r\n", millis(), WiFi.SSID().c_str(), WiFi.RSSI());
}
void WiFiStationDisconnected(WiFiEvent_t event, WiFiEventInfo_t info){
Serial.println(F("Disconnected from WiFi"));
connectToNextNetwork();
}
void WiFiGotIP(WiFiEvent_t event, WiFiEventInfo_t info){
IPAddress ip = WiFi.localIP();
Serial.printf("WiFi connected, IP address: %d.%d.%d.%d, level: %d [dB]\r\n", ip[0], ip[1], ip[2], ip[3], WiFi.RSSI());
} // WiFiGotIP
void setup(){
pinMode(BEEP, OUTPUT); // TEST THIERRY
digitalWrite(BEEP, false);
Serial.begin(115200);
while(!Serial){
;
}
delay(1000);
Serial.println("Starting..");
WiFi.onEvent(WiFiStationConnected, ARDUINO_EVENT_WIFI_STA_CONNECTED); // version 2.0x
WiFi.onEvent(WiFiGotIP, ARDUINO_EVENT_WIFI_STA_GOT_IP); // version 2.0x
WiFi.onEvent(WiFiStationDisconnected, ARDUINO_EVENT_WIFI_STA_DISCONNECTED); //version 2.0x
connectToNextNetwork();
} // setup
void connectToNextNetwork(){
WiFi.disconnect(true, true);
WiFi.begin("truc", "machin");
}
void loop() {
;
}
Hello again,
I reduce the code to produce the beep noise:
#include "esp_wifi.h"
#include <WiFi.h>
#define BEEP 2
void setup(){
pinMode(BEEP, OUTPUT); // TEST THIERRY
digitalWrite(BEEP, false);
Serial.begin(115200);
while(!Serial){
;
}
delay(1000);
Serial.println("Starting..");
}
void loop() {
WiFi.begin("truc", "machin");
delay(1000);
}
Posts: 6,294
Threads: 806
Joined: Oct 2020
Reputation:
153
you can use digitalWrite(BEEP, false); or digitalWrite(BEEP, true); // whether can turn off beep?
Posts: 15
Threads: 3
Joined: Dec 2023
Reputation:
0
Hello,
Thanks for your reply.
Unfortunatly, digitalWrite(BEEP, false) doesn't solve the problem.
You can try the very small piece of code already joined.
To solve this problem, You have to pinMode after the wifi got an ip. And then after you can do digitalWrite(BEEP, false).
Please try the code I joigned ...
Best regards
Thierry
Posts: 6,294
Threads: 806
Joined: Oct 2020
Reputation:
153
how about digitalWrite(BEEP, true) ?
Posts: 15
Threads: 3
Joined: Dec 2023
Reputation:
0
digitalWrite(BEEP, true) doesn't solve the problem.
it's seams that WiFi.begin modify several times the pin 2 even any PinMode or digitalWrite instruction.
it's like a "feature" of the ESP32.
The solution I find is AFTER the wifi got an Ip, do the pinmode and digitalWrite for the pin 2.