About a year ago I built a small project. It works, but sometimes behaves a bit weird. So I'm hoping someone here has an idea what's wrong.
The project it a printer, that prints a random ticket when a button is pressed.
The problem: the printer prints sometimes on it's own. It it strange, because the text is random, which means the whole process is started, as if someone pressed the button...
Function: When the button is pressed, the arduino accesses the SD-card, counts the lines, generates a random number, seeks the line on the SD-card accordingly and prints it.
Has anybody an idea what the cause for this bug could be?
Thank you for your help!
Sorry, of course I meant 230V through a 5V power supply.
The Arduino gets powered through the Vcc (as labeled on the board), and it works fine with 5V. As shown in the drawing, they're all connected to a common ground. However, this is not the problem.
Why are you using software serial? Pro Micro has an available hardware serial port. Unlike Uno, Nano etc, the RX/TX pins are not used for uploading & serial monitor. That hardware serial port is available to use, and if there is a hardware serial port available, it should always be used in preference to software serial.
Apologies if our comments don't seem relevant to your immediate problem, but we are reviewing the code & schematic you posted, and if we don't mention something important, we might forget.
I kept as close as possible to the example code provided by adafruit. I myself have no deeper understanding of these things. On a side note, prototyping was done on a arduino uno, and only when it worked I installed it on the micro pro. That's also the reason why in my drawing the ports for both boards are labeled.
I will then change this connection to the "raw" pin.
And a picture of my actual wiring isn't possible, as everythink is built into a very small space in a 3d printed part. It looks like a bomb, you wouldn't see a thing in there.
To solve this, I could connect my power supply which is fixed to 5V to the Vcc and use 6 AA batteries (9V) on the raw. Then everything is within specs?
I have re-checked your code and schematic. I can't see a reason why pin 2 would read high unless the button was pressed. So I think the problem could be faulty wiring, and the pin is floating.
Are you certain that the pulldown resistor is 220R? Could it in fact be 220K or 2M2? Such high values could leave the pin vulnerable to interference which could cause "phantom" button presses.
You could try removing the resistor and connecting the button from pin 2 to ground and use INPUT_PULLUP mode.
Yes, that's possible.
Will your circuit run on 3xAA non-rechargeable batteries? This is below 5V, but might still work if connected to the Vcc pin.
Another possibility is 4xAA NiMH batteries connected to the Vcc pin. In theory this could be above 5.5V which could damage the Arduino, but when I have tested this it has never been above that. It may depend on the charger you use to charge the cells.
I checked the resistor and it is 220k. Big mistake there from me. I swapped it with a 330, as I couldn't find a 220. (This should also work is think?)
I haven't used the INPUT-PULLUP so far and I think I will leave this as it is.
For the power supply, I decided to do a redesign and use a 9V power supply and 9V batterie. It works, but due to bad soldering i fried the arduino. I also forgot about the SD-card reader, which must not exceed 5.5V, so I will include a step down converter.
For now, I can't test wether the resistor fixed the problem. So I will come back to this when I got to change everything.
The exact value of pull-up and pull-down resistors is not critical. A normal/typical value would be 4K7 or 10K. 220R or 330R is a little low, but will work. 220K is too high, as you seem to have found.
I hope you mean 6xAA, not a rectangular PP3 size 9V battery.
But even with 6xAA batteries, almost half the battery capacity will be wasted.
For battery powered circuits, I prefer to use 3.3V components and a low-drop-out 3.3V regulator. Then, a li-po battery pack or 3x or 4x NiMH AA or AAA batteries can be used. (I never normally use non-rechargeable batteries these days.)