My program has a function that starts at the end of another. The issue is, when I start the system with the USB of the ARDUINO conected to PC it works just fine. But when I take off the USB and put on the DC jack of a Power Supply it just go through that last function and starts the program again.
I don't understand what the power supply would affect the program.
It's a musical keyboard, where the keys are pressed by Solenoids. It has 2 modes, Manual and Automatic... on Automatic, with the Power Supply, it plays very softly the "Happy Christmas" by John Lennon.
On Manual, after pressing 10 keys, it should replay the sequence you pressed before, and it does, with the USB (but it has no capacity to push the solenoids, so I have to use a Power Supply). But with the Power Supply, after pressing the 10 keys, it goes to the beggining of the program, that is the selection of Manual/Automatic.
I think its not the PS, because it plays the Automatic mode and plays the keys while you are pressing the sequence of 10.
My program is very long and it's in portuguese, I will copy the function that is not working.
void reproduzir(int bpm) { // this is not happening with the PS, for some reason.
int i;
lcd.clear();
lcd.home();
lcd.print("Sequencia completa");
delay(1000);
lcd.setCursor(0,1);
lcd.print("Reproduzindo...");
delay(1000);
for(i=1;i<11;i++) {
digitalWrite(notasaida[notamanual[i]], HIGH);
delay(bpm);
digitalWrite(notasaida[notamanual[i]], LOW);
delay(bpm);
}
delay(1000);
}
It's regulated DC Power Supply, delivers 12V and 1A. I have measured the Vin and 5V, its very close to nominal.
My question is, why it would affect just this part of the program and not the rest. The demand of current in this part of program is not higher or anything. And even if so the USB delivers much less Voltage and Current. I can't get the logic of this.
And even if so the USB delivers much less Voltage and Current. I can't get the logic of this.
If the Arduino draws more current than the power supply can deliver, the voltage drops off. Below a certain level, the Arduino says "Not enough!" and resets.
If the Arduino draws more current than the power supply can deliver, the voltage drops off. Below a certain level, the Arduino says "Not enough!" and resets.
Yes, I know it. But guess what: with the USB plugged in the system, at any part of the program that demand pushing the solenoids, it draws more current than the USB can deliver and the voltage drops off. It drops off so that the LCD 16x2 almosts fades off. But it doesn't happen with the Power Supply, ever.
When you are running with the Arduino powered by your power supply and not through the USB port, how is the supply connected to the Arduino?
If you connect it to the power jack on a UNO or any similar Arduino that is designed to have an unregulated supply, it will go through a voltage regulator which will drop the voltage by around 2V. So you need to connect at least a 7V supply here, in order for your processor to get a healthy 5V supply. If you think this may be your problem, I suggest you look at the spec for your Arduino board to see whether there is any way to connect a regulated 5V supply without going through the 5V regulator. Maybe you can just connect your regulated 5V supply to the 5V pin. But check before you try it - it would be a shame to blow something up.
External (non-USB) power can come either from an AC-to-DC adapter (wall-wart) or battery. The adapter can be connected by plugging a 2.1mm center-positive plug into the board's power jack. Leads from a battery can be inserted in the Gnd and Vin pin headers of the POWER connector.
That's what I am doing. a AC-to-DC adapter, with 12V/1A connected with 2.1mm center positive plug.
Why would the voltage drop at this specific part of the program, its not different of the Automatic part that plays Happy Christmas.
The driving of Solenoids comes from these lines:
digitalWrite(notasaida[notamanual[i]], HIGH); // 'notasaida' is the array of outputs of the 25 solenoids, comes from 1 to 25.
delay(bpm); // notamanual is the array of 10 positions that were pressed before.
digitalWrite(notasaida[notamanual[i]], LOW); // bpm is the 'beats per second' that were defined before.
delay(bpm);
It's exacly the same lines that plays individual note while pressing each one of the 10 notes that will be replayed after the 10th.
It's exacly the same lines that plays individual note while pressing each one of the 10 notes that will be replayed after the 10th.
It looks, then, like the power supply is not the issue. The code, then, must be. How are the notasaida and notamanual arrays defined? How are they populated?
It must be the program... But the weird thing is that it works perfect with USB.
The arrays are defined like these:
uint8_t notamanual[10]; // each position contains the value of the positions of the array below.
int notasaida[] = { // each position are pointed to a output. If I want to press the 10th key, the system will make the 34 pin HIGH
0, 19, 20, 21, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 37, 39, 41, 43, 45, 47, 49, 51, 53, 46, 50, 48};
At this point, to get any meaningful help, you're going to have to post the whole sketch. Use the attach facility in additional options if it's too big to fit in a post.
RaphaelAmin:
That's what I am doing. a AC-to-DC adapter, with 12V/1A connected with 2.1mm center positive plug.
...
It's exacly the same lines that plays individual note while pressing each one of the 10 notes that will be replayed after the 10th.
Have you measured how much current your solenoids are drawing through the on-board regulator? While your supply is capable of providing 1A and the on-board 5V regulator is rated for 1A, the lack of heat sink limits the actual max current.
Dropping from 12V to 5V puts a large voltage drop across the regulator. You'll be lucky to get 500mA out of it before it starts shutting down. Which might explain why USB appears to work and the external supply does.
It must be the program... But the weird thing is that it works perfect with USB.
If it is the code it will misbehave no matter how it is powered. Therefore your problem must be one of hardware. What exactly in the hardware is yet to be established.
If you are talking about taking more current than can safely be deliverer from the USB then you have a bad system anyway so you should not be powering it from the USB.
The USB power and your external power supply will behave very differently when operated out of specification. Just because your power supply is rated at 1A and the USB is rated at 0.5A does not mean your power supply will behave better that the USB at say 2A load.
You need to post a schematic of what you have.
Is the extra current flowing through the internal arduino regulator when it is powered by the external power supply. Is the regulator getting hot. The surge capacity of the arduino regulator is limited by the small bulk decoupling capacitors. My bet is that you will have to supply your solenoids directly through an external supply.
I undertand now. The 5V of USB doesn't need the regulator of the board ... this is the difference between the USB and de DC PS. This may cause bad behavior when drawing more current than the regulator system can take, what doesn't occour with the USB.
But my point is that the whole program works just fine until that point, when the program start driving the solenoinds in the sequence I had choose before.
In the automatic mode I have made an chord, that is, more than one solenoid active at the same time. (3 to be more exact) This is the program's peak of current I think, and... it works!
Maybe the 'bpm' variable on delay could be missing something and could be zero. But it's not possible because it wouldn't work with USB too.
I could test a lot of things but I have reached my deadline, and right now I doesn't have access to the project, only 1 hour before the presentation. The professor will undertand... I hope. But anyway, I keep trying to find out what the problem is and I will fix it no matter what.
But my point is that the whole program works just fine until that point,
Hardly a surprise that your code works up to the point where you overload the power supply. I bet if you replaced the solenoids with LEDs all of it would work all the time.
The overload of current I think would be the part that 3 solenoids are active, and not only one. But this part works. And even if it was only one, other parts of program that drives one solenoid works fine. (like the automatic mode that plays 2 entire songs)
I bet it is a stupid mistake I made and I can't figure out. Happens all the time! :~