I have a home made arduino board using a ATMega328P.
I have attached 3 servos and a Sharp IR sensor.
The servos are powered by a seperate power supply to the microcontroller and Sharp IR sensor.
The power supply in both cases is a bank of 4 AA rechargable batteries.
This seemed to work fine but my programming was not up to scratch, resulting in the robot crashing.
Last night, following a lot of testing to determine optimum sensor angles and distances where I was getting good results I suddenly started having some really bizzarre results.
LED continues to blink as programmed in the setup loop… Other times it may read in a command (I use serial to send commands to the chip) once and then hang. Other times the board seems to reset itself. other times I get complete gobbldygook output on the serial console. I even loaded a new, simple blink sketch. The Arduino IDE reported the upload succesfull but the LED was still blinking in the pattern as specified in the initial program’s setup loop as mentioned above. After removing and re-applying the power to the Arduino clone it seemed the new blink sketch had succesfully uploaded as the blink pattern was as specified by the new sketch.
Can anyone give me any idea why this may suddenly be happening? Have I fried my chip or could there be another cause? Is it possible my power supply is flat and therefore not providing enough current? How would I measure this given I have rechargeable batteries and apparantly the voltage they give does not degrade as it does in standard disposables?
I was under the impression that the voltage supplied by rechargables does not degrade, so my bank would still measure about 4.8V even with fairly flat batteries, or am I mistaken?
Anyway, is this bizzarre type of behaviour typical for an underpowered system?
I don’t think you’ve fried your chip, it’s most likely due to the battery voltage now being too low to run reliably at 16MHz. You might wish to run your processor at 8MHz or less so that it can work reliably at lower voltages. This will also lower the current consumption so that the batteries last longer.
KE7GKP:
It seems simple enough to just measure the power supply voltages with a meter. You cannot do this kind of experimenting without a meter. Fortunately, you can get them for very low prices.
Rechargeable batteries run on the low side anyway (for example 1.2V vs. 1.5V primary cell) and four of them in series may only be 4.8V. So it seems quite possible that you have run them down below the reliable voltage level. I would consider revising the power scheme.
Old NiCd cells were 1.2V, newer NiMH are more like 1.35V, fading down towards 1.2V as they discharge - 4 NiMH cells is usually fine for "about 5V". Shouldn't crash till the cells are totally discharged. But of course if you don't know measure the voltage all bets are off!
The thing is it was working fine for a long time, running the servos and scanning and returning the values...
Not sure what the fuse settings are...
I have disconnected everything except my input button (which toggles states) and my serial read process and it croaks on the serial read. Sometimes I get serial output that looks like it is puking the program code... My error or output strings are in clear text and then a lot of gobldy-gook special chars which I think may be the printable version of the byte? code in the controller.
I removed all the components, and have slowly been adding them again, and the following procedure seems to be causing the weird behaviour even though I am not yet calling it in my code!! It is just present in the code.
Am I misusing pointers etc? I wish to return the values in bestAngle and bestDistance to the caller.
//Will scan for path and return angle and distance
void scanForPath(int* bestAngle, int* bestDistance) {
writeDebug( "scanForPath bestDistance: " + String(*bestDistance) );
stop(); //stop bot just in case
neckServo.write(90); //look foreward
int distance;
//scan left first
for (int i=90; i > 10; i--) {
neckServo.write(i);
delay(25); //delay 25 millis to allow servo to arrive at position
distance = getSensorDistance();
if ( distance < *bestDistance ) {
writeDebug("Better distance right: " + String(distance));
*bestDistance = distance;
*bestAngle = i;
}
}
for (int i=10; i < 170; i++) {
//scan to the right
neckServo.write(i);
delay(5); //delay 5 millis to allow servo to arrive at position
distance = getSensorDistance();
if ( distance < *bestDistance ) {
writeDebug("Better distance left sweep: " + String(distance));
*bestDistance = distance;
*bestAngle = i;
}
}
} //scanForPath(int* bestAngle, int* bestDistance) {
SRAM is where all your variables, arrays, and strings are stored and manipulated. The Arduino Uno board has but 2K bytes of SRAM, the Mega board 4K. There is a way to store read only strings in FLASH memory where your program is stored, using PROGMEM functions.
I can't tell whether you are misusing pointers without seeing the code you use to call function scanForPath.
Does the code still malfunction when you comment out the two writeDebug lines? If you might be exhausting RAM then you should avoid using the String class.