Wemos D1 Mini (serial connection doesnt work until reset)
Posted: Fri Nov 26, 2021 6:39 am
I'm rlly about to switch to Arduino. So many bugs and problems with these ESP bullshit boards..
I have a simple script. nothing much to say about it it just sends serial data by "Serial.print".
I plug the board into my computer and open a serial monitor program. It doesnt work until I press the reset button on the board, then it gets the serial data. WTH? I wanna built a device that's installed permanently and I don't wanna press the reset button everytime it gets powered on. On Arduino that works just fine.
I have a simple script. nothing much to say about it it just sends serial data by "Serial.print".
I plug the board into my computer and open a serial monitor program. It doesnt work until I press the reset button on the board, then it gets the serial data. WTH? I wanna built a device that's installed permanently and I don't wanna press the reset button everytime it gets powered on. On Arduino that works just fine.
Code: Select all
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN D8
#define RST_PIN D3
MFRC522 rfid(SS_PIN, RST_PIN);
MFRC522::MIFARE_Key key;
void setup() {
pinMode(D1, OUTPUT);
digitalWrite(D1, LOW);
Serial.begin(9600);
SPI.begin();
rfid.PCD_Init();
rfid.PCD_SetAntennaGain(rfid.RxGain_max);
Serial.println("B");
digitalWrite(D1, HIGH);
}
void loop() {
if ( ! rfid.PICC_IsNewCardPresent())
return;
if ( ! rfid.PICC_ReadCardSerial())
return;
char str[32] = "";
array_to_string(rfid.uid.uidByte, 4, str);
Serial.println(str);
rfid.PICC_HaltA();
rfid.PCD_StopCrypto1();
}
void array_to_string(byte array[], unsigned int len, char buffer[])
{
for (unsigned int i = 0; i < len; i++)
{
byte nib1 = (array[i] >> 4) & 0x0F;
byte nib2 = (array[i] >> 0) & 0x0F;
buffer[i*2+0] = nib1 < 0xA ? '0' + nib1 : 'A' + nib1 - 0xA;
buffer[i*2+1] = nib2 < 0xA ? '0' + nib2 : 'A' + nib2 - 0xA;
}
buffer[len*2] = '\0';
}