Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some problems about rfid_Cloner_2 (buttons) #4

Open
cx4 opened this issue Jan 15, 2019 · 17 comments
Open

some problems about rfid_Cloner_2 (buttons) #4

cx4 opened this issue Jan 15, 2019 · 17 comments

Comments

@cx4
Copy link

cx4 commented Jan 15, 2019

I don't know what reason I confirm and delete buttons are not sensitive,Use the resistor has direction requirement?

@michalmonday
Copy link
Owner

Hello, in the GUI.cpp there's the following line:
gui_mode = MODE_INTRO;

You could change it into the following:
gui_mode = MODE_BUTTON_CALIBRATION_VIEW;

After uploading the code and turning on the device it should look like this:
image

Make sure to test it with battery instead of USB cable (it affects the analog input reading).

Only 1 (analog) pin is used to receive input of all the buttons (using voltage dividers). It would be all fine but the battery voltage is decreasing over time and the readings when specific buttons are pressed also decrease. To tackle that problem I added 10K resistor that is constantly dividing voltage (producing constant readings - "51" visible on the image above), it allows to constantly monitor the voltage and automatically calibrate the buttons in real time.

I would do the following in this case:

  • make sure the resistors have the correct values (220 - "decline", 470 - "accept")
  • observe what is the expected and actual analog reading for both of these buttons. If the reading is off and that is the reason for the buttons to not work then there are 2 possibilities:
  1. Set #define INPUT_TOLERANCE 0.12 (in Buttons.cpp) to a slightly higher value.
    (INPUT_TOLERANCE is how far from the expected the reading can be and still get classified as some button, e.g. If reading is: 113 and expected reading is 100, then with INPUT_TOLERANCE equal to 0.12 the button press would not be noticed. If INPUT_TOLERANCE was increased to 0.14 then the button press would be registered. The tolerance cannot be set too high, otherwise buttons will interfere with each other, however 0.12 is very safe value I think and it could be increased.)
  2. Change buttonMap initial expected_read value (also in Buttons.cpp) to match readings of your buttons.
ButtonMap buttonMap[BUTTON_COUNT] = {
 50.5, BUTTON_NONE, "NONE", [](){},
 100.0, BUTTON_UP, "UP", [](){},
 191.0, BUTTON_DOWN, "DOWN", [](){},
 315.0, BUTTON_LEFT, "LEFT", [](){},
 449.0, BUTTON_RIGHT, "RIGHT", [](){},
 629.0, BUTTON_YES, "ACCEPT", [](){},
 871.0, BUTTON_NO, "DECLINE", [](){},
};

@michalmonday michalmonday changed the title some problems about rfid_Cloner_2 some problems about rfid_Cloner_2 (buttons) Jan 15, 2019
@cx4
Copy link
Author

cx4 commented Jan 17, 2019

Thank you very much. But yesterday when uploading firmware accidentally broke oled, there is no more simple way like rfid_Clone_1, copy cloning, through the led reminder and two buttons (one to read card and one to write card) way to achieve. Based on esp8266

@michalmonday
Copy link
Owner

michalmonday commented Jan 17, 2019

It would be kind of waste to not use display after all this soldering:p, are you sure that the display is not going to work? Did it get like physically broken? (I remember that when I was playing with display like this I was almost sure it won't work anymore but it turned out the connections were wrong).

You could use the first version with NodeMcu and it should work, what you'd have to do is:

  • connect the rfid module the way it is shown in the 2nd version of the cloner
  • change this part of the 1st version code:
#define RST_PIN 8 
#define SS_PIN 10 

replace it with:

#define RST_PIN D3
#define SS_PIN D8
  • use D4 and SD3 pins to connect LEDs, and use D0 pin to connect the button + change the code accordingly, so it looks like:
#define BTN_PIN D0
#define LED_YELLOW_PIN D4
#define LED_GREEN_PIN SD3

Zener diodes used in the first version won't be required because NodeMcu has 3.3V pin.

@cx4
Copy link
Author

cx4 commented Jan 17, 2019

I change the code with Cloner_1 . But uploading firmware , there is an error, SD3 was not declared in this scope . and how to use D4 and SD3 to connect LEDs .
Thank you very much for your help.

@michalmonday
Copy link
Owner

My bad, SD3 is not defined, you could use pin 10, which is SD3:

#define LED_GREEN_PIN 10 //SD3

Just in case if it is confusing why pin 10 is "SD3" here's a diagram: link

@michalmonday
Copy link
Owner

michalmonday commented Jan 17, 2019

I just pressed some keyboard shortcut (or touched the touchpad...) and closed the issue by accident

@cx4
Copy link
Author

cx4 commented Jan 18, 2019

Thank you. Another problem is how to connection the leds and button with esp8266

@michalmonday
Copy link
Owner

You could take a look at the first version wiring and connect it the same way but to different pins
https://github.com/michalmonday/RFID-cloner/tree/master/rfidCloner#wiring
wiring image
So instead of using pins 9, 5, 4 and RAW, use:

  • D0 (button)
  • SD3 (green)
  • D4 (yellow)
  • 3.3V (red)

@cx4
Copy link
Author

cx4 commented Jan 19, 2019

If I am too stupid. I checked that all the link lines were correct, the green and yellow lights were on and the red light was on, but when I pressed the button there was no response, and I now wonder if my 8266 board was broken, although the firmware upload was fine.

@michalmonday
Copy link
Owner

michalmonday commented Jan 19, 2019

I just found out that I didn't include pinMode(pin, OUTPUT); for both of the led pins, maybe that is the reason why it doesn't work right now with NodeMcu, but that's just a guess, anyway...

What I would do is to verify that everything is connected properly:

  1. I would upload the code below:
#define BTN_PIN D0
#define LED_YELLOW_PIN D4
#define LED_GREEN_PIN 10

void setup() {
  pinMode(BTN_PIN, INPUT_PULLUP);
  pinMode(LED_YELLOW_PIN, OUTPUT);
  pinMode(LED_GREEN_PIN, OUTPUT);
  Serial.begin(9600);

}

void loop() {
  delay(500);
  digitalWrite(LED_YELLOW_PIN, HIGH);
  digitalWrite(LED_GREEN_PIN, HIGH);
  delay(500);
  digitalWrite(LED_YELLOW_PIN, LOW);
  digitalWrite(LED_GREEN_PIN, LOW);
  
  bool button_state = digitalRead(BTN_PIN);
  Serial.println("Button state is:" + String(button_state));
}

It should toggle both LEDs every half second and print the state of the button every 1 second (that can be read in Arduino IDE -> Tools -> Serial Monitor)

  1. If the LEDs are working properly and the button is responsive I would upload example provided by rfid library to make sure that the RC522 module is connected and working properly (Arduino IDE -> File -> Examples -> MFRC522 -> DumpInfo).
    You'll have to change the 2 lines below in that example:
constexpr uint8_t RST_PIN = 9;          // Configurable, see typical pin layout above
constexpr uint8_t SS_PIN = 10;         // Configurable, see typical pin layout above

into:

constexpr uint8_t RST_PIN = D3;         
constexpr uint8_t SS_PIN = D8;        

After uploading that example you'll have to open serial monitor and present a card to the rfid reader module, information about the card should be displayed in the serial monitor.

@cx4
Copy link
Author

cx4 commented Jan 19, 2019

Thank you very much. You're responding so quickly. But don't you sleep? it's supposed to be 1: 00 in the morning in Britain. take care

@michalmonday
Copy link
Owner

michalmonday commented Jan 19, 2019

I just noticed that I made another mistake at the:
https://github.com/michalmonday/RFID-cloner/tree/master/rfidCloner%202#wiring

This is wrong:
image

SCK should be D5 and SS should be D8, MISO should be D6 and MOSI should be D7, sorry about it...

Btw usually go to sleep around 2-3am, just a sleeping pattern like that

@cx4
Copy link
Author

cx4 commented Jan 21, 2019

It doesn't work. I decided to buy a arduino nano board to try.

@michalmonday
Copy link
Owner

If you'd like to try to make it work with esp then just let me know on discord (michalmonday#3687), I'm sure something can be done...

@cx4
Copy link
Author

cx4 commented Jan 21, 2019

Because I can't write C ++, I want to try it with micropython.

@ghost
Copy link

ghost commented Jul 31, 2022

Sorry for my english not good. I'm using google translate to comment here. Why do you have to use resistors for buttons? Why don't we fight the esp pins directly?

@michalmonday
Copy link
Owner

Hi, thanks to resistors (that act as voltage dividers) all the buttons can be read by using a single pin (as seen on image below). This project used a display and a RFID module, both using a lot of pins. But I think that using an input shift register would probably be a better solution, mostly because the voltage differs depending on the battery level, I tried to take that into account in the code (by scaling expected voltage ranges for each button based on baseline voltage level) but I'm not sure if it's a robust method, it seemed to work in my case though.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants