By now I am running a handful of projects powered by USB power banks. Connecting one of the banks the UNO the start message is printed from within Setup. Then the first message from within loop() comes incomplete and the UNO is stuck there. Pressing the Reset button on the UNO board then makes the sketch start.
The troubeling power bank is my smallest one, some 2600 mAh. The others, working well, are of 5 000, 6 000 and 12 000 mAh.
I bought the small pwr bank in order to mount it inside the rather small project box.
Is there any lasting setup that can be done to the UNO to make it start from this small pwr bank?
Sketchused is:
#include<arduino.h>
#include <SMT172.h>
//I2C for LCD
//boolean debug = false;
//#include <SoftwareSerial.h>
#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>
//#define BACKLIGHT_PIN 13
hd44780_I2Cexp mylcd; // declare lcd object: auto locate & config exapander chip
// LCD geometry
#define LCD_COLS 16
#define LCD_ROWS 2
// The TinyGPS++ object
uint32_t LastSensorUpdate;
unsigned long sec_1_diff_measure_time;
unsigned long sec_10_diff_measure_time;
unsigned long minute_1_diff_measure_time;
unsigned long minute_10_diff_measure_time;
float sec_1_diff_measure_data = -1.1;
float sec_10_diff_measure_data = -1.1;
float minute_1_diff_measure_data = -1.1;
float minute_10_diff_measure_data = -1.1;
unsigned long mill_tmp;
//The setup function is called once at startup of the sketch
void setup() {
pinMode(8, INPUT_PULLUP);
// pinMode(4, OUTPUT);//+5 to measuring UNO
// pinMode(6, OUTPUT);//+5 to measuring UNO
// digitalWrite(6, HIGH);//+5 to measuring UNO
Serial.begin(115200);
Serial.println(F("Temperature sketch SMT172"));
//1Hz 90% dutycycle
pinMode(9, OUTPUT); // Set digital pin 9 (D9) to an output
TCCR1A = _BV(COM1A1) | _BV(COM1A0) | _BV(WGM11); // Enable the PWM output OC1A on digital pins 9 and invert output
TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS12); // Set fast PWM and prescaler of 256 on timer 1
ICR1 = 62499; // Set the PWM frequency to 1Hz: 16MHz/(256 * 1Hz) - 1 = 62499
OCR1A = 6249; // Set the duty-cycle to 10%: 62499 / 10 = 6249
delay(10);//allow pwm timers to start
//Send temp via I2C to LCD
int status;
status = mylcd.begin(LCD_COLS, LCD_ROWS);
if (status) // non zero status means it was unsuccesful
{
status = -status; // convert negative status value to positive number
// begin() failed so blink error code using the onboard LED if possible
hd44780::fatalError(status); // does not return
}
mylcd.clear();
// initalization was successful, the backlight should be on now
// Print start message to the LCD
mylcd.print("Started");
sec_1_diff_measure_time = /*tmp_millis + */1000;
sec_10_diff_measure_time = /*tmp_millis + */10000;
minute_1_diff_measure_time = /*tmp_millis + */60000;
minute_10_diff_measure_time = /*tmp_millis + */600000;
}
// The loop function is called in an endless loop
void loop()
{
float tmp_temp;
mill_tmp = millis();
// read the sensor every 500 millisecond
if ((unsigned long) (millis() - LastSensorUpdate) >= 500)
{
LastSensorUpdate = millis();
SMT172::startTemperature(0.002);
repeat:
switch (SMT172::getStatus()) {
case 0: goto repeat; // O Dijkstra, be merciful onto me, for I have sinned against you :)
case 1:
// Serial.print(F("Measuring time [ms]: "));
// Serial.println(SMT172::getTime() * 1e3, 2); // convert to milliseconds
// Serial.print(F("Sensor frequency [Hz]: "));
// Serial.println(SMT172::getFrequency(), 2);
// Serial.print(F("Duty cycle [%]: "));
// Serial.println(SMT172::getDutyCycle() * 100, 2);
tmp_temp = SMT172::getTemperature();
mill_tmp = millis();
mylcd.setCursor(0, 0);
mylcd.print(tmp_temp, 2);
// mylcd.print(F(" [C]"));
mylcd.print(" [C]");
if (sec_1_diff_measure_data < 0.0)//Initiate
{
sec_1_diff_measure_data = tmp_temp;
sec_10_diff_measure_data = tmp_temp;
minute_1_diff_measure_data = tmp_temp;
minute_10_diff_measure_data = tmp_temp;
sec_1_diff_measure_time = mill_tmp + 1000;
sec_10_diff_measure_time = mill_tmp + 10000;
minute_1_diff_measure_time = mill_tmp + 60000;
minute_10_diff_measure_time = mill_tmp + 600000;
}
else
{
if (mill_tmp > sec_1_diff_measure_time )
{
// Serial.print("1 Sec value "); Serial.print(tmp_temp);Serial .print(" ");Serial.println(mill_tmp/1000);
sec_1_diff_measure_time = mill_tmp + 1 * 1000;//Set next measure time
mylcd.setCursor(10, 0); mylcd.print(" ");
mylcd.setCursor(10, 0); mylcd.print(tmp_temp - sec_1_diff_measure_data, 2); // mylcd.print(" ");
sec_1_diff_measure_data = tmp_temp;
}
if (mill_tmp > sec_10_diff_measure_time )
{
Serial.print("10 Sec value "); Serial.print(tmp_temp); Serial .print(" "); Serial.println(mill_tmp / 1000);
sec_10_diff_measure_time = mill_tmp + 10 * 1000;//Set next measure time
mylcd.setCursor(0, 1); mylcd.print(" ");
mylcd.setCursor(0, 1); mylcd.print(tmp_temp - sec_10_diff_measure_data, 2);// mylcd.print(" ");
sec_10_diff_measure_data = tmp_temp;
}
if (mill_tmp > minute_1_diff_measure_time )
{
Serial.print("1 Min value "); Serial.print(tmp_temp); Serial .print(" "); Serial.println(mill_tmp / 1000);
minute_1_diff_measure_time = mill_tmp + 60000;//Set next measure time
mylcd.setCursor(6, 1); mylcd.print(" ");
mylcd.setCursor(6, 1); mylcd.print(tmp_temp - minute_1_diff_measure_data, 2);// mylcd.print(" ");
minute_1_diff_measure_data = tmp_temp;
}
if (mill_tmp > minute_10_diff_measure_time )
{
Serial.print("10 Min value "); Serial.print(tmp_temp); Serial .print(" "); Serial.println(mill_tmp / 1000);
minute_10_diff_measure_time = mill_tmp + 600000;//Set next measure time
mylcd.setCursor(12, 1); mylcd.print(" ");
mylcd.setCursor(12, 1); mylcd.print(tmp_temp - minute_10_diff_measure_data, 1);// mylcd.print(" ");
minute_10_diff_measure_data = tmp_temp;
}
}
// mylcd.setCursor(0, 3); mylcd.print(mill_tmp / 1000); mylcd.print(" "); mylcd.print(minute_1_diff_measure_time / 1000);
// mylcd.setCursor(16, 3); mylcd.print(mill_tmp / 1000);
// Serial.print(F("Error [mK]: "));
// Serial.println(SMT172::getError() * 1000, 2);
// Serial.println();
break;
case 2: Serial.println("No Sensor");
Serial.println();
mylcd.clear();
mylcd.setCursor(0, 1);
mylcd.print("No Sensor");
}
delay(500);
}
}