Hello,
I have got arduino pro mico (leonardo) clone 5V version 16 mhz (i have got 20 of them from different batches, also i do own a standard "big" oryginal Leonardo.
There is Atmega 32u4 on them.
Ihave build a RFID reader with it.
RFID RC522 connected over SPI, pins 9,10,15,16,GND,VCC just standard configuration for this module.
Piezo beeper with generator build in connected to PIN 8 and gnd
I use software serial, pins 2TX, 3RX, baud 9600, HC-06 bluetooth module connected to that serial interface.
I'm also using keyboard.h to turn the USB controleer in to the HID keyboard to print out the serial number on computer .
I'm using library for RC522 to dump the UID of NFC tag and then using Keyboard.print, and myserial.print sending that UID to the keyboard and serial (to the Bluetooth module)
Also im doing BEEP setting the PIN8 for 200 milisec high, there is piezo beeper with build in generator, so i only need to power it up with 5V to get sound.
Ewerything was working well 3 weeks ago, and on some readers i have programmed in that time it still works, Now using the same sketch I do expierience the problem:
When i upload the sketch weverything works well.
When i unplug the device form USB (power) and i plug it again there is a problem:
The keyboard part (printing to HID keayboard) works fine.
The BEEP part works... but the delay 200ms is ignored, it beeps over a second.
And the softwareserial part does not work , it sends some trash to serial instead of proper UID number, exactly 80 80 80 80 80 80 80 80 80 when I'm checking on serial monitor over bluetooth.
Same problem occures on the devices that do work with firmware flashed 3 weeks ago (the same sketch, no changes), and when i upload the sketch now it has problems as described.
I have 20 boards and all have the same syptoms. Tested on clean installed OS with clean installed versions of arduino IDE, tested with different combinations of versions of library es and IDE....
So problem is not a hardware because the hardware works fine... until flashing the sketch and turning off power.
Does anyone have similar problem ?
#include <SPI.h>
#include <MFRC522.h>
#include <Keyboard.h>
#include <SoftwareSerial.h>
#define RST_PIN 9
#define SS_PIN 10
MFRC522 mfrc522(SS_PIN, RST_PIN);
SoftwareSerial btSerial(3, 2);
int incomingByte = 0;
int beep = 8;
void setup() {
// Serial.begin(9600);
// while (!Serial);
btSerial.begin(9600);
pinMode( beep, OUTPUT);
SPI.begin();
mfrc522.PCD_Init();
}
void loop() {
if ( ! mfrc522.PICC_IsNewCardPresent())
if ( ! mfrc522.PICC_ReadCardSerial())
Push_dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
Keyboard_print_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
digitalWrite(beep, HIGH);
delay(200);
digitalWrite(beep, LOW);
}
void Keyboard_print_byte_array(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
Keyboard.print(buffer[i] < 0x10 ? "0" : "");
Keyboard.print(buffer[i], HEX);
}
}
char Header[4] = {0x55, 0xFF, 0xFF, 0xFF};
char Endpoint[2] = {0xFF, 0xAA};
void Push_dump_byte_array(byte *buffer, byte bufferSize) {
for(int i = 0; i < 4; ++i){
btSerial.print(Header[i]);
}
for(byte i = 0; i < bufferSize; i++) {
btSerial.print((char)buffer[i]);
}
for(int i = 0; i < 2; ++i){
btSerial.print(Endpoint[i]);
}
}