Go Down

Topic: Arduino UNO does not boot with thermistor program (Read 374 times) previous topic - next topic

mickystar

Hi all,
I am relatively new with Arduino and with MCU programming. I am using an Arduino UNO rev 3 board I bought just 3 days ago.

I have a problem with a simple program written to test the thermistor included in the kit I just bought. The program still needs to be fix in the details but it's working for now.

Code is as follow:
Code: [Select]

int stato = 0;
int prev_stato = 0;
int vai = 0;
int therm;
float temp;
char buffer[5];

#define THERM_PIN   0 
#define bottone 7

const int temps[] = { 171,172,173,174,175,176,176,177,178,179,180,181,182,183,183,184,185,186,187,189,190,191,191,192,193,194,195,196,197,198,198,199,200,201,202,203,204,205,205,206,207,208,209,210,211,212,213,213,214,215,216,217,218,219,220,220,221,222,223,224,225,226,227,228,228 };

void setup() {
  pinMode(13, OUTPUT);
  pinMode(bottone, INPUT);
  Serial.begin(19200);
}

void loop() {

therm = analogRead(THERM_PIN)-416;
temp = (float)temps[therm]/10;
stato = digitalRead(bottone);

if ((stato == HIGH) && (prev_stato == LOW)) {
  vai = 1 - vai;
  delay(15);
}

if (vai == 1) {
 
  Serial.print(temp, 1);
  Serial.println("C");
 
 
  Serial.print("#S|LOGTEST|[");
  Serial.print(itoa((temp), buffer, 10));
  Serial.println("]#");
 
  delay(500);
}

prev_stato = stato;

}


The program is working without problems when just uploaded to the Arduino.
But if I unplug and plug again the Arduino to the PC, the program does not seem to start. I get no data via the serial port and the TX led on the board is not blinking.
If I upload the program again from the IDE then it works fine.

The problem does not happen with simple test programs such as led blinking. The Arduino boots and the led starts blinking. So the problem should be in the program I suppose.

Can it be the serial connection that does not get initialized after re-plug of the board?

Thank you very much  :)

LarryD

Quote
Can it be the serial connection that does not get initialized after re-plug of the board?

Yes
The way you have it in your schematic isn't the same as how you have it wired up!

mickystar


Quote
Can it be the serial connection that does not get initialized after re-plug of the board?

Yes


Thank you,
So is there a program function in order to get the serial communication as soon as the Arduino is plugged again to the PC? 

PaulS

Quote
So is there a program function in order to get the serial communication as soon as the Arduino is plugged again to the PC?

Unless you've modified the Arduino, opening the serial connection on the PC end will reset the Arduino. If the Arduino uses Serial.begin() in setup(), communication will be established.

Go Up