Pages: [1]   Go Down
Author Topic: Arduino does not boot... sometimes?!?  (Read 484 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 104
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi!

I took my Arduino and build a device with it. I "hardwired" the Arduino board (since
I need the USB-Port) inside a box as a permanent installation.
To recieve a feedback that that Arduino is booted and ready I implemented a soundbuzzer
that beeps, when the Arduino is ready to recieve commands via USB.
The problem is that the Arduino does not boot/beep when USB is plugged in, <<sometimes>>. It also
does not accept any commands when it has not beeped.
Only when I upload the sketch again it works for a few times then this behaviour happens again.
I allready replaced the atmega (because after a while it didnt work anymore even when uploaded the sketch again)
but with the new one it happens again and now Im afraid that it will die too... smiley-sad
(Since I dont really know what the problem is I hope this is not the wrong forum)

This is my initialisation code:
Code:
//////////////////////////////////////////
// scribLAB´s CNC Control ////////////////
//////////////////////////////////////////

// SETUPS --------------------------------------------
#include <string.h>
#include "AxisCtrl.h"
#include <EEPROM.h>
#include "Speaker.h"
#include "ToolRemote.h"

//Axis Control
///////////////////////////
AxisCtrl x(12,9,7,200,0.8,10);
AxisCtrl y(11,9,6,200,0.8,30);
AxisCtrl z(10,9,8,200,0.8,40);

Speaker sp(5);
ToolRemote toolRemote(3,4);

//AxisControlButtons
///////////////////////////
boolean homeAll = false;
boolean homeZ = false;
boolean calibrateZ = false;
boolean selfTest = false;
int ledPin = 13;
long x2 = 0;
long y2 = 0;
long z2 = 0;
//Communication
///////////////////////////
String gCodeCmd = "G01";
String planeSel = "XY";
String cmdString;
boolean serialHandshake = false;
boolean cmdComplete;
boolean readyForNextCmd = true;
boolean otherCmdRecieved = false;
// SETUPS --------------------------------------------

void setup() {
  //Serial conncetion
  sp.begin();
  toolRemote.begin();
  sp.playStart();
  cmdString.reserve(200);  
  Serial.begin(115200);
  Serial.println("Init machine...#");
  x.begin();
  x.setDirOverride(true);
  y.begin();
  z.begin();
  Serial.println("Machine ready.#");
  pinMode(ledPin,OUTPUT);
  //Establish contact
  Serial.write("R");
}

What could be the problem? Software, hardware? :\

Thanks in advance!
« Last Edit: September 04, 2012, 08:32:29 am by asuryan » Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 525
Posts: 26535
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Try and narrow down where it gets stuck.
When you open the serial monitor, do your Serial.prints & writes work?
Is the code actually making it to the last line of setup?
Use the output LED as a test point too.
move the
pinMode(ledPin,OUTPUT);
farther up in setup.
Do things like after every library call make it blink on for a half second, off half second, see where the problem is.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What could be the problem? Software, hardware?
Those are the usual two choices. I'm voting for software, though.

Starting here:
Code:
String gCodeCmd = "G01";
String planeSel = "XY";
String cmdString;
Get rid of this crap. Use a char array, of a known size, and reject any input data that is larger than that size.

Although, given that you don't have a loop() function, never mind.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 104
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks guys for your replies!

move the
pinMode(ledPin,OUTPUT);
farther up in setup.

I made this change and moved the pinMode() up and it seems that this was the problem. It
seems to boot everytime until now.
Just for knowledge purposes: why should one make all pinModes() first before doing other
setup stuff?

Thanks!
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 525
Posts: 26535
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

pin 13 is also the SCK pin for SPI transfers.
Which you don't appear to be using, but it may have been interfering with the other libraries called out first.
Having it called before you started making library calls my have removed the interference.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Full Member
***
Karma: 0
Posts: 104
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you very much for explanation! smiley
Logged

Pages: [1]   Go Up
Jump to: