ESP32 with max98357a board works. But I can't use void loop() function for other purposes - esp32

I have been learning how to program in esp32 using arduino IDE.
I couldn't figure out how to use max98357a board with Esp32-DevKitC. I have tried "Audio.h" and "AudioTools.h" libraries but not is changed.
My first attempt was just testing voice output. My code is below:
#include "Arduino.h"
#include "WiFi.h"
#include "Audio.h"
// Digital I/O used
#define I2S_DOUT 26 // DIN connection
#define I2S_BCLK 27 // Bit clock
#define I2S_LRC 14 // Left Right Clock
Audio audio;
String ssid = "MYCROFT";
String password = "145678abc789";
void setup() {
Serial.begin(115200);
WiFi.disconnect();
WiFi.mode(WIFI_STA);
WiFi.begin(ssid.c_str(), password.c_str());
while (WiFi.status() != WL_CONNECTED) delay(1500);
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
audio.setVolume(21); // 0...21
// audio.connecttohost("http://www.wdr.de/wdrlive/media/einslive.m3u");
// audio.connecttohost("http://macslons-irish-pub-radio.com/media.asx");
// audio.connecttohost("http://mp3.ffh.de/radioffh/hqlivestream.aac"); // 128k aac
// audio.connecttohost("http://mp3.ffh.de/radioffh/hqlivestream.mp3"); // 128k mp3
audio.connecttohost("http://vis.media-ice.musicradio.com/CapitalMP3"); // 128k mp3
// audio.connecttospeech("Wenn die Hunde schlafen, kann der Wolf gut Schafe stehlen.", "de");
// audio.connecttohost("http://media.ndr.de/download/podcasts/podcast4161/AU-20190404-0844-1700.mp3"); // podcast
}
void loop()
{
audio.loop();
}
It works as intended but when I try to add some commands to the loop function, It stops working.
I mean if I change the loop function as below, it stops connecting to the audio stream.
void loop()
{
delay(3000);
Serial.println("Hello");
audio.loop();
}
Is it possible to use max98357a with some additional codes apart from just simple audio.loop().

The delay(3000) instruction causes the microprocessor to do nothing but sit & wait for 3 seconds. Not even interrupts are serviced so audio is lost.

Related

Exception handling for `Brownout detector was trigerred`

I'm using ESP-IDF as framework.
I know that Brownout detector was trigerred error is come from low voltage detector that detect low voltage occurs. Usually the MCU will restart automatically when that error occurs.
Yes that detector can be setup, but can I handle that error in software like how esp-idf handle error with using convention esp_err_t? So I can just continue the runtime in my MCU without restarted by such error.
What I mean handle is like how high level programming using try-catch concept.
It doesn't make any sense to try to "catch" a brownout.
When brownout detection triggers, it means that the ESP32 isn't getting enough power to run reliably. If it can't run reliably, it's not helpful to try to catch an exception indicating that because the exception handler also wouldn't run reliably.
If you're seeing this problem, there's one fix for it and that's to supply enough power to your ESP32 and whatever circuitry you have it connected to. That's it, that's what you do. That means figure out how much current the entire project draws and use a power source that's rated to supply more than that amount of current. If you're using a "wall wart" AC/DC adapter, use one that's rated for a lot more current as many of them can't deliver what they promise to.
The CPU is reset after this error occurs. There may be a way to find out the reason for the reset when the CPU restarts. As with STM32 MCUs, the RCC (Reset and Clock Controller) register can be read. During my research I found a solution that can be used with ESP32.
#include <rom/rtc.h>
void print_reset_reason(RESET_REASON reason)
{
switch (reason)
{
/**<1, Vbat power on reset*/
case 1 : Serial.println ("POWERON_RESET");break;
/**<3, Software reset digital core*/
case 3 : Serial.println ("SW_RESET");break;
/**<4, Legacy watch dog reset digital core*/
case 4 : Serial.println ("OWDT_RESET");break;
/**<5, Deep Sleep reset digital core*/
case 5 : Serial.println ("DEEPSLEEP_RESET");break;
/**<6, Reset by SLC module, reset digital core*/
case 6 : Serial.println ("SDIO_RESET");break;
/**<7, Timer Group0 Watch dog reset digital core*/
case 7 : Serial.println ("TG0WDT_SYS_RESET");break;
/**<8, Timer Group1 Watch dog reset digital core*/
case 8 : Serial.println ("TG1WDT_SYS_RESET");break;
/**<9, RTC Watch dog Reset digital core*/
case 9 : Serial.println ("RTCWDT_SYS_RESET");break;
/**<10, Instrusion tested to reset CPU*/
case 10 : Serial.println ("INTRUSION_RESET");break;
/**<11, Time Group reset CPU*/
case 11 : Serial.println ("TGWDT_CPU_RESET");break;
/**<12, Software reset CPU*/
case 12 : Serial.println ("SW_CPU_RESET");break;
/**<13, RTC Watch dog Reset CPU*/
case 13 : Serial.println ("RTCWDT_CPU_RESET");break;
/**<14, for APP CPU, reseted by PRO CPU*/
case 14 : Serial.println ("EXT_CPU_RESET");break;
/**<15, Reset when the vdd voltage is not stable*/
case 15 : Serial.println ("RTCWDT_BROWN_OUT_RESET");break;
/**<16, RTC Watch dog reset digital core and rtc module*/
case 16 : Serial.println ("RTCWDT_RTC_RESET");break;
default : Serial.println ("NO_MEAN");
}
}
void setup() {
Serial.begin(115200);
delay(2000);
Serial.println("CPU0 reset reason: ");
print_reset_reason(rtc_get_reset_reason(0));
Serial.println("CPU1 reset reason: ");
print_reset_reason(rtc_get_reset_reason(1));
}
void loop() {}
Related Links
GitHub - How can I read the reset reason?
https://www.esp32.com/viewtopic.php?t=6855 says look at the components/esp_system/port/brownout.c for how to catch the interrupt. Set the high 2.8V threshold so you'll have a bit of time. The default is the low 2.43V threshold and often doesn't have time to print the entire ~40 character message. Pre-erase flash if you are trying to save something.
Use a bigger power supply capacitor--100uF is probably too small.
A use-case for this might look like a GPS that wants to save some warm-start data if it can, but doesn't want to wear out the flash by saving it all the time. If the data is missing or corrupt, there is a recovery procedure that just takes longer.
Anti-pattern: don't depend on the brownout detector to put a system in a safe state. Those big capacitors get smaller over time.
edit: actual testing, 4700uf does not provide a reliable 1/30 second, but 2 X 4700uF does. (Just a wroom32, nothing else.) I think 10,000uF is a heavy lift for my wall-wart to start up.
0 idle0=12954 idle1=25465 FPS=29.9967 sampleRate= 306822.9
0 idle0=12954 idle1=25465 FPS=30.0003 sampleRate= 306836.3
2.80V Brownout...warning...
1 idle0=14692 idle1=23489 FPS=30.0012 sampleRate= 306848.5
1 idle0=14692 idle1=23489 FPS=29.9976 sampleRate= 306859.1
2.43V Brownout...restart...
ets Jul 29 2019 12:21:46
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:6664
load:0x40078000,len:14848
load:0x40080400,len:3792
0x40080400: _init at ??:?
entry 0x40080694
I (27) boot: ESP-IDF v4.4.3-dirty 2nd stage bootloader
I (27) boot: compile time 07:37:04
I (27) boot: chip revision: 3
I (30) boot_comm: chip revision: 3, min. bootload�
The 2 X 4700uF carried the CPU pretty far into the reboot.
Here's the quick and dirty test code; it needs some thought about what should happen if there is a temporary brownout that doesn't trip the reset, and maybe a bit more understanding of how to return from the interrupt. It was retriggering immediately before I set the lower voltage in the isr. The calling code can test the static counter in the 30 FPS loop; above it is the 0 or 1 at the start of the line.
// modified from components/esp_system/port/brownout.c
// Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "esp_private/system_internal.h"
#include "driver/rtc_cntl.h"
#include "esp_rom_sys.h"
#include "soc/soc.h"
#include "soc/cpu.h"
#include "soc/rtc_periph.h"
#include "hal/cpu_hal.h"
#include "hal/brownout_hal.h"
#include "sdkconfig.h"
#if defined(CONFIG_ESP32_BROWNOUT_DET_LVL)
#define BROWNOUT_DET_LVL CONFIG_ESP32_BROWNOUT_DET_LVL
#elif defined(CONFIG_ESP32S2_BROWNOUT_DET_LVL)
#define BROWNOUT_DET_LVL CONFIG_ESP32S2_BROWNOUT_DET_LVL
#elif defined(CONFIG_ESP32S3_BROWNOUT_DET_LVL)
#define BROWNOUT_DET_LVL CONFIG_ESP32S3_BROWNOUT_DET_LVL
#elif defined(CONFIG_ESP32C3_BROWNOUT_DET_LVL)
#define BROWNOUT_DET_LVL CONFIG_ESP32C3_BROWNOUT_DET_LVL
#elif defined(CONFIG_ESP32H2_BROWNOUT_DET_LVL)
#define BROWNOUT_DET_LVL CONFIG_ESP32H2_BROWNOUT_DET_LVL
#else
#define BROWNOUT_DET_LVL 0
#endif
#if SOC_BROWNOUT_RESET_SUPPORTED
#define BROWNOUT_RESET_EN true
#else
#define BROWNOUT_RESET_EN false
#endif // SOC_BROWNOUT_RESET_SUPPORTED
int sBrownOut = 0;
extern void esp_brownout_disable(void);
extern void my_esp_brownout_disable(void);
#ifndef SOC_BROWNOUT_RESET_SUPPORTED
static void my_rtc_brownout_isr_handler(void *arg)
{
sBrownOut++;
brownout_hal_intr_clear();
// change to level 0...prevents immediate retrigger...
brownout_hal_config_t cfg = {
.threshold = 0,//BROWNOUT_DET_LVL,
.enabled = true,
.reset_enabled = BROWNOUT_RESET_EN,
.flash_power_down = true,
.rf_power_down = true,
};
brownout_hal_config(&cfg);
if(sBrownOut==1){
esp_rom_printf("\r\n2.80V Brownout...warning...\r\n");
}
else{
esp_cpu_stall(!cpu_hal_get_core_id());
esp_reset_reason_set_hint(ESP_RST_BROWNOUT);
esp_rom_printf("\r\n2.43V Brownout...restart...\r\n");
esp_restart_noos();
}
return; // dead code follows...
/* Normally RTC ISR clears the interrupt flag after the application-supplied
* handler returns. Since restart is called here, the flag needs to be
* cleared manually.
*/
brownout_hal_intr_clear();
/* Stall the other CPU to make sure the code running there doesn't use UART
* at the same time as the following esp_rom_printf.
*/
esp_cpu_stall(!cpu_hal_get_core_id());
esp_reset_reason_set_hint(ESP_RST_BROWNOUT);
esp_rom_printf("\r\n***Brownout detector was triggered\r\n\r\n");
esp_restart_noos();
}
#endif // not SOC_BROWNOUT_RESET_SUPPORTED
void my_esp_brownout_init(void)
{
esp_brownout_disable();
brownout_hal_config_t cfg = {
.threshold = 7,//BROWNOUT_DET_LVL, // level 7 is the highest voltage, earliest possible warning, most time left...
.enabled = true,
.reset_enabled = BROWNOUT_RESET_EN,
.flash_power_down = false, // if this does what it says,
.rf_power_down = false, // probably don't want it first time
};
brownout_hal_config(&cfg);
#ifndef SOC_BROWNOUT_RESET_SUPPORTED
rtc_isr_register(my_rtc_brownout_isr_handler, NULL, RTC_CNTL_BROWN_OUT_INT_ENA_M);
brownout_hal_intr_enable(true);
#endif // not SOC_BROWNOUT_RESET_SUPPORTED
}
void my_esp_brownout_disable(void)
{
brownout_hal_config_t cfg = {
.enabled = false,
};
brownout_hal_config(&cfg);
#ifndef SOC_BROWNOUT_RESET_SUPPORTED
brownout_hal_intr_enable(false);
rtc_isr_deregister(my_rtc_brownout_isr_handler, NULL);
#endif // not SOC_BROWNOUT_RESET_SUPPORTED
}

ESP32 Welcome screen transition to another screen?

I'm making a simple car gauge, I want to add a little personal touch nothing special.
Setup: ESP32 and ST7735S with no SD card.
At the beginning I want to add a boot screen ( picture- I use flash memory for this because I have no SD card tftIcons.ino)
After like 5s I want to transition from picture to my gauges ( simple print code for now) But I don't know how to stich these two together to get what I want.
The code for Welcome screen/ Boot is:
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include "bitmaps.h"
#include "bitmapsLarge.h"
// For the breakout, you can use any 2 or 3 pins
// These pins will also work for the 1.8" TFT shield
#define TFT_CS 5
#define TFT_RST 4 // you can also connect this to the Arduino reset
// in which case, set this #define pin to 0!
#define TFT_DC 2
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
void setup() {
tft.initR(INITR_BLACKTAB);
tft.setRotation(0);
tft.fillScreen(ST7735_BLACK);
//Case 2: Multi Colored Images/Icons
int h = 160,w = 128, row, col, buffidx=0;
for (row=0; row<h; row++) { // For each scanline...
for (col=0; col<w; col++) { // For each pixel...
//To read from Flash Memory, pgm_read_XXX is required.
//Since image is stored as uint16_t, pgm_read_word is used as it uses 16bit address
tft.drawPixel(col, row, pgm_read_word(evive_in_hand + buffidx));
buffidx++;
} // end pixel
}
}
void loop() {
}
The code for the gauges is:
#include <SPI.h>
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#define TFT_CS 5
#define TFT_RST 4 // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC 2
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
float p = 3.1415926;
void setup(void) {
Serial.begin(9600);
Serial.print(F("Hello! ST77xx TFT Test"));
// Use this initializer if using a 1.8" TFT screen:
tft.initR(INITR_BLACKTAB); // Init ST7735S chip, black tab
tft.setRotation(1); // set display orientation
}
void loop() {
tft.fillScreen(ST77XX_BLACK);
print_text(20,5,"1.54",5,ST77XX_GREEN);
print_text(70,50,"BAR",2,ST77XX_GREEN);
print_text(5,90,"Temp motora: 81'C",1,ST77XX_WHITE);
print_text(5,100,"Temp usisa: 30'C",1,ST77XX_BLUE);
print_text(146,116,"AM",1,ST77XX_WHITE);
delay(5000);
}
void print_text(byte x_pos, byte y_pos, char *text, byte text_size, uint16_t color) {
tft.setCursor(x_pos, y_pos);
tft.setTextSize(text_size);
tft.setTextColor(color);
tft.setTextWrap(true);
tft.print(text);
}
Can someone tell me how can I make when I power on ESP32 to show Welcome screen/ boot screen for 5s, then automatically transition to Gauges screen ?
EDIT: When I join these two
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#include "bitmaps.h"
#include "bitmapsLarge.h"
// For the breakout, you can use any 2 or 3 pins
// These pins will also work for the 1.8" TFT shield
#define TFT_CS 5
#define TFT_RST 4 // you can also connect this to the Arduino reset
// in which case, set this #define pin to 0!
#define TFT_DC 2
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
void setup() {
tft.initR(INITR_BLACKTAB);
tft.setRotation(0);
tft.fillScreen(ST7735_BLACK);
//Case 2: Multi Colored Images/Icons
int h = 160,w = 128, row, col, buffidx=0;
for (row=0; row<h; row++) { // For each scanline...
for (col=0; col<w; col++) { // For each pixel...
//To read from Flash Memory, pgm_read_XXX is required.
//Since image is stored as uint16_t, pgm_read_word is used as it uses 16bit address
tft.drawPixel(col, row, pgm_read_word(evive_in_hand + buffidx));
buffidx++;
} // end pixel
}
delay(5000); // Delay 5s, then run the code down?
}
// Timer
float p = 3.1415926;
Serial.begin(9600);
Serial.print(F("Hello! ST77xx TFT Test"));
// Use this initializer if using a 1.8" TFT screen:
tft.initR(INITR_BLACKTAB); // Init ST7735S chip, black tab
tft.setRotation(1); // set display orientation
void loop() {
tft.fillScreen(ST77XX_BLACK);
print_text(20,5,"1.54",5,ST77XX_GREEN);
print_text(70,50,"BAR",2,ST77XX_GREEN);
print_text(5,90,"Temp motora: 81'C",1,ST77XX_WHITE);
print_text(5,100,"Temp usisa: 30'C",1,ST77XX_BLUE);
print_text(146,116,"AM",1,ST77XX_WHITE);
delay(5000);
}
void print_text(byte x_pos, byte y_pos, char *text, byte text_size, uint16_t color) {
tft.setCursor(x_pos, y_pos);
tft.setTextSize(text_size);
tft.setTextColor(color);
tft.setTextWrap(true);
tft.print(text);
}
I get exit status 1
'Serial' does not name a type
#include <SPI.h>
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include "bitmaps.h"
#include "bitmapsLarge.h"
#define TFT_CS 5
#define TFT_RST 4 // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC 2
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
float p = 3.1415926;
void setup(void) {
Serial.begin(9600);
Serial.print(F("Hello! ST77xx TFT Test"));
tft.initR(INITR_BLACKTAB);
tft.setRotation(0);
tft.fillScreen(ST7735_BLACK);
//Case 2: Multi Colored Images/Icons
int h = 160,w = 128, row, col, buffidx=0;
for (row=0; row<h; row++) { // For each scanline...
for (col=0; col<w; col++) { // For each pixel...
//To read from Flash Memory, pgm_read_XXX is required.
//Since image is stored as uint16_t, pgm_read_word is used as it uses 16bit address
tft.drawPixel(col, row, pgm_read_word(evive_in_hand + buffidx));
buffidx++;
} // end pixel
}
delay(5000);
// Use this initializer if using a 1.8" TFT screen:
tft.initR(INITR_BLACKTAB); // Init ST7735S chip, black tab
tft.setRotation(1); // set display orientation
}
void loop() {
tft.fillScreen(ST77XX_BLACK);
print_text(20,5,"1.54",5,ST77XX_GREEN);
print_text(70,50,"BAR",2,ST77XX_GREEN);
print_text(5,90,"Temp motora: 81'C",1,ST77XX_WHITE);
print_text(5,100,"Temp usisa: 30'C",1,ST77XX_BLUE);
print_text(146,116,"AM",1,ST77XX_WHITE);
delay(5000);
}
void print_text(byte x_pos, byte y_pos, char *text, byte text_size, uint16_t color) {
tft.setCursor(x_pos, y_pos);
tft.setTextSize(text_size);
tft.setTextColor(color);
tft.setTextWrap(true);
tft.print(text);
}
I fount out how. You can only have one void setup and void loop. You cant c/p stich two together

Issue with Interfacing atmega328p with Bluetooth

I’m trying to interface atmega328p with Blutooth HC-0.
I was following the example in Atmega328P datasheet in USART section.
The code is simply trying to send a letter 'b' to Bluetooth terminal on mobile phone and receive a letter. If the received letter is 'a', an LED on PORTB0 will turn on, if the letter is 'c', the LED will turn off. But unfortunately nothing is working.
Connection between atmega328P and HC-05 is as follows:
HC-05 -> Atmega328P
RXD -> pin3
TXD -> pin2
GND -> pin8
VCC -> pin7
Bluetooth light is turning on and off, and is connected successfully to mobile phone but no data is received, and when the letters 'a' and 'c' are sent nothing happens with LED connected to PORTB0.
The code is shown here. Thank you for any help!
#define F_CPU 16000000UL // Clock Speed
#define BAUD 9600
#define MYUBRR F_CPU/16/BAUD-1
#include <stdint.h>
#include <avr/io.h>
#include <util/delay.h>
char data;
char data2 = 'b';
void USART_Init(unsigned int ubrr)
{
/* Set baud rate */
UBRR0H = (unsigned char)(ubrr>>8);
UBRR0L = (unsigned char)(ubrr);
/* Enable receiver and transmitter */
UCSR0B = (1<<RXEN0)|(1<<TXEN0);
/* Set frame format: 8data, 2stop bit */
UCSR0C = (1<<USBS0)|(3<<UCSZ00);
}
char USART_Receive(void)
{
/* Wait for data to be received */
while ( !(UCSR0A & (1<<RXC0)) );
/* Get and return received data from buffer */
return UDR0;
}
void USART_Transmit(char data)
{
/* Wait for empty transmit buffer */
while ( !( UCSR0A & (1<<UDRE0)) );
/* Put data into buffer, sends the data */
UDR0 = data;
}
int main(void)
{
DDRB = 0b00000001;
PORTB = 0b00000000;
USART_Init(MYUBRR);
while (1) {
data = USART_Receive();
USART_Transmit(data2);
if (data == 'a') {
PORTB = 0b00000001;
} else if (data == 'c') {
PORTB = 0b00000000;
}
}
}

How to configure PlatformIO for ESP32-SOLO-1?

I've a simple led blinking example which I'm trying to run on a ESP32-SOLO-1 but as soon I flash it with the program I get the following message from the serial monitor:
E (102) cpu_start: Running on single core chip, but application is built with dual core support.
E (102) cpu_start: Please enable CONFIG_FREERTOS_UNICORE option in menuconfig.
abort() was called at PC 0x400829d2 on core 0
Here's the code
#include <Arduino.h>
#define LED_BUILTIN 2
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
And the platformio.ini config:
[env:esp-wrover-kit]
platform = espressif32
board = esp-wrover-kit
monitor_speed = 115200
framework = arduino
build_flags = -D CONFIG_FREERTOS_UNICORE
Adding the build flag CONFIG_FREERTOS_UNICORE has no effect.

ESP32 failing to detect PN532 NFC module

I've been struggling for the past few days to get the Elechouse PN532 V3 module working with an ESP32 over I2C. The PN532 module itself works fine with a Raspberry Pi.
This is the circuit (not actually using SparkFun ESP32 board, just for reference)
And this is the code I'm trying to run
#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h>
#include <NfcAdapter.h>
PN532_I2C pn532i2c(Wire);
PN532 nfc(pn532i2c);
void setup(void) {
Serial.begin(115200);
Serial.println("Hello!");
Wire.begin(18, 19);
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
Serial.print("Didn't find PN53x board");
while (1); // halt
}
// Got ok data, print it out!
Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX);
Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC);
Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
// Set the max number of retry attempts to read from a card
// This prevents us from waiting forever for a card, which is
// the default behaviour of the PN532.
nfc.setPassiveActivationRetries(0xFF);
// configure board to read RFID tags
nfc.SAMConfig();
Serial.println("Waiting for an ISO14443A card");
}
void loop(void) {
boolean success;
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
// Wait for an ISO14443A type cards (Mifare, etc.). When one is found
// 'uid' will be populated with the UID, and uidLength will indicate
// if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);
if (success) {
Serial.println("Found a card!");
Serial.print("UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
Serial.print("UID Value: ");
for (uint8_t i=0; i < uidLength; i++)
{
Serial.print(" 0x");Serial.print(uid[i], HEX);
}
Serial.println("");
// Wait 1 second before continuing
delay(1000);
}
else
{
// PN532 probably timed out waiting for a card
Serial.println("Timed out waiting for a card");
}
}
And finally the serial output: Didn't find PN53X board
Any ideas what I'm doing wrong?
EDIT: libraries im using https://github.com/elechouse/PN532 and the ESP32 dev board is a Wemos Lolin32 Lite clone.
I don't have any of this hardware to verify this, but from 'PN532-PN532_HSU\NDEF\README.md'
For the Adafruit Shield using I2C
#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h>
#include <NfcAdapter.h>
PN532_I2C pn532_i2c(Wire);
NfcAdapter nfc = NfcAdapter(pn532_i2c);
Try using the above in your code? I'd also suggest you review the PN532 I2C examples in more depth. The PN532 I2C library code defines a 'wakeup' function:
void PN532_I2C::wakeup()
{
delay(500); // wait for all ready to manipulate pn532
}
The comment makes me believe the device may require a significant delay (500ms) before it's ready to talk.
Best of luck.
sda and scl are 21 and 22
also make sure that you changed mode to I2C (those jumpers on PN532 module):
doc - page 3
I have this now working with an M5STACK grey core, the common issue was the I2C bus would lock up on a reset or re program. Use a spare I/O pin and connect to the PN532 reset pin, hold this low on boot, initialize I2C bus then drive reset high after 100mS problem solved no more bus conflicts.

Resources