char progmem stop run after few times

Hi.
I am doing some project.
it seems simple but i am still stuck in the problem TT…
The Arduino Uno is connected to power relay(Controllable Four Outlet Power Relay Module version 2 [(Power Switch Tail Alternative)] : ID 2935 : $29.95 : Adafruit Industries, Unique & fun DIY electronics and kits)
and there is the mini thermal printer.
so when I push the button, lighting (which is plugged in power relay) is off and the thermal printer works.
and normally lighting in on if there is no interrupt(push a button).
the code works well. but when I push the button after 1hr? of 2hrs, light is ‘off’ and never ‘on’ again. and the printer doesn’t work.
and the weird thing is … after 10 min. the light turns on and the printer works without any input.
I run the simple code. it doesn’t stop and run very well. so I guess it is not power problem…
the code is quite long… if you have time, please look at this.
I will be very appreciated if you give me some advice.
Thank you!!

#include "Adafruit_Thermal.h"
#include "SoftwareSerial.h"
#define TX_PIN 6 // Arduino transmit  YELLOW WIRE  labeled RX on printer
#define RX_PIN 5 // Arduino receive   GREEN WIRE   labeled TX on printer
#include <avr/pgmspace.h>
SoftwareSerial mySerial(RX_PIN, TX_PIN); // Declare SoftwareSerial obj first
Adafruit_Thermal printer(&mySerial);     // Pass addr to printer constructor
// Then see setup() function regarding serial & printer begin() calls.


const char fortune_0[] PROGMEM = "The significance of a man is not in what he attains, but rather what he longs to attain.-Khalil Gibran";
const char fortune_1[] PROGMEM = "People seek within a short span of life to satisfy a thousand desires, each of which is insatiable.-Oliver Goldsmith";
const char fortune_2[] PROGMEM = "While man's desires and aspirations stir he cannot choose but err.-Johann Wolfgang von Goethe";
const char fortune_3[] PROGMEM = "It is much easier to suppress a first desire than to satisfy those that follow.-Benjamin Franklin"; 
const char fortune_4[] PROGMEM = "When desire dies, fear is born.-Baltasar Gracián y Morales";
const char fortune_5[] PROGMEM = "If you desire many things, many things will seem few.-Benjamin Franklin";  
const char fortune_6[] PROGMEM = "Life is a progress from want to want, not from enjoyment to enjoyment.-Samuel Johnson"; 
const char fortune_7[] PROGMEM = "It is said that desire is a product of the will, but the converse is in fact true: will is a product of desire.-Denis Diderot";
const char fortune_8[] PROGMEM = "Desire is the essence of a man.-Baruch Spinoza"; 
const char fortune_9[] PROGMEM = "Life contains but two tragedies. One is not to get your heart's desire; the other is to get it.-Socrates";  
const char fortune_10[] PROGMEM = "All human activity is prompted by desire.-Bertrand Russell";
const char list_0[] PROGMEM = "travel all around the world."; 
const char list_1[] PROGMEM = "walk/Dance barefoot in the rain."; 
const char list_2[] PROGMEM = "be friend a stranger."; 
const char list_3[] PROGMEM = "see the Northern Lights.";  
const char list_4[] PROGMEM = "go on a blind date!!"; 
const char list_5[] PROGMEM = "to be famous"; 
const char list_6[] PROGMEM = "create my dream home";
const char list_7[] PROGMEM = "change the world"; 
const char list_8[] PROGMEM = "see everyone equeally";  
// this table is in ordinary memory but has pointers
// that reference the flash PROGMEM
const char* const fortune_tab[] PROGMEM = { 
  fortune_0,
  fortune_1,
  fortune_2,
  fortune_3,
  fortune_4,
  fortune_5,
  fortune_6,
  fortune_7,
  fortune_8, 
  fortune_9, 
  fortune_10
  };

char fortune[150];// make sure this is large enough for longest string
const char* const list_tab[] PROGMEM = {
  list_0,
  list_1,
  list_2,
  list_3,
  list_4,
  list_5,
  list_6,
  list_7,
  list_8

};

char list[50];
char random_number[6];
int n=0;
int rn=0;
int r=0;
int led=1;

const int buttonPin = 7;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin
volatile int buttonState = HIGH;
int lastButtonState =HIGH;

void setup() {
mySerial.begin(19200);  // Initialize SoftwareSerial 
while(!mySerial);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);    // set the LED off
pinMode(buttonPin, INPUT);
digitalWrite(buttonPin, HIGH); // set pullup on

}

void loop() {
buttonState = digitalRead(buttonPin);
 if (buttonState == LOW)
 {
   digitalWrite(ledPin, LOW);    // button feedback
   getFortune();
   printFortune();
 }
 else {
    // turn LED off:
    digitalWrite(ledPin,HIGH);      
    lastButtonState = HIGH;
}
}


void getFortune() {
r=random(11);
strcpy_P(fortune, (char*)pgm_read_word(&(fortune_tab[r])));
int ra=random(9);
strcpy_P(list, (char*)pgm_read_word(&(list_tab[ra])));
rn=random(100);
itoa(rn, random_number, 10); // convert int to char 10 = decimal base
}

void printFortune() 
{
printer.justify('C');
printer.setSize('S'); 
printer.println(F("# Welcome #"));
printer.setSize('M');
printer.println(""); 
printer.setSize('S');
printer.println(fortune); 
printer.println("");
printer.setSize('S');
printer.println(list); 
printer.setSize('M');
printer.println("");
printer.setSize('L');
printer.print("Lucky number "); 
printer.setSize('M');
printer.println(""); 
printer.setSize('L');
printer.print(random_number); 

printer.println(""); 
printer.println("");

The code you posted cannot compile, so any reason why it doesn’t run or function as you expect is pure conjecture.

hum...do you have any suggestion??

yulisung:
hum...do you have any suggestion??

Isn't it obvious?
Post your code.

i have posted my code above...

yulisung:
i have posted my code above...

But the code is incomplete, so cannot compile. So we can't test it.

oh, that is complete code. I forgot to attach '}' at the end.

yulisung:
oh, that is complete code. I forgot to attach '}' at the end.

Post the complete code.

Thank you for the reply.
the thermal printer’ power is connected to the extension cord which is from wall power outlet.
and it is connected to Arduino Uno by using the jumper wire.
and Arduino Uno uses another power cord.

#include "Adafruit_Thermal.h"
#include "SoftwareSerial.h"
#define TX_PIN 6 // Arduino transmit  YELLOW WIRE  labeled RX on printer
#define RX_PIN 5 // Arduino receive   GREEN WIRE   labeled TX on printer
#include <avr/pgmspace.h>
SoftwareSerial mySerial(RX_PIN, TX_PIN); // Declare SoftwareSerial obj first
Adafruit_Thermal printer(&mySerial);     // Pass addr to printer constructor
// Then see setup() function regarding serial & printer begin() calls.


const char fortune_0[] PROGMEM = "The significance of a man is not in what he attains, but rather what he longs to attain.-Khalil Gibran";
const char fortune_1[] PROGMEM = "People seek within a short span of life to satisfy a thousand desires, each of which is insatiable.-Oliver Goldsmith";
const char fortune_2[] PROGMEM = "While man's desires and aspirations stir he cannot choose but err.-Johann Wolfgang von Goethe";
const char fortune_3[] PROGMEM = "It is much easier to suppress a first desire than to satisfy those that follow.-Benjamin Franklin"; 
const char fortune_4[] PROGMEM = "When desire dies, fear is born.-Baltasar Gracián y Morales";
const char fortune_5[] PROGMEM = "If you desire many things, many things will seem few.-Benjamin Franklin";  
const char fortune_6[] PROGMEM = "Life is a progress from want to want, not from enjoyment to enjoyment.-Samuel Johnson"; 
const char fortune_7[] PROGMEM = "It is said that desire is a product of the will, but the converse is in fact true: will is a product of desire.-Denis Diderot";
const char fortune_8[] PROGMEM = "Desire is the essence of a man.-Baruch Spinoza"; 
const char fortune_9[] PROGMEM = "Life contains but two tragedies. One is not to get your heart's desire; the other is to get it.-Socrates";  
const char fortune_10[] PROGMEM = "All human activity is prompted by desire.-Bertrand Russell";
const char list_0[] PROGMEM = "travel all around the world."; 
const char list_1[] PROGMEM = "walk/Dance barefoot in the rain."; 
const char list_2[] PROGMEM = "be friend a stranger."; 
const char list_3[] PROGMEM = "see the Northern Lights.";  
const char list_4[] PROGMEM = "go on a blind date!!"; 
const char list_5[] PROGMEM = "to be famous"; 
const char list_6[] PROGMEM = "create my dream home";
const char list_7[] PROGMEM = "change the world"; 
const char list_8[] PROGMEM = "see everyone equeally";  
// this table is in ordinary memory but has pointers
// that reference the flash PROGMEM
const char* const fortune_tab[] PROGMEM = { 
  fortune_0,
  fortune_1,
  fortune_2,
  fortune_3,
  fortune_4,
  fortune_5,
  fortune_6,
  fortune_7,
  fortune_8, 
  fortune_9, 
  fortune_10
  };

char fortune[150];// make sure this is large enough for longest string
const char* const list_tab[] PROGMEM = {
  list_0,
  list_1,
  list_2,
  list_3,
  list_4,
  list_5,
  list_6,
  list_7,
  list_8

};

char list[50];
char random_number[6];
int n=0;
int rn=0;
int r=0;
int led=1;

const int buttonPin = 7;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin
volatile int buttonState = HIGH;
int lastButtonState =HIGH;

void setup() {
mySerial.begin(19200);  // Initialize SoftwareSerial 
while(!mySerial);

pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);    // set the LED off
pinMode(buttonPin, INPUT);
digitalWrite(buttonPin, HIGH); // set pullup on

}

void loop() {
buttonState = digitalRead(buttonPin);
 if (buttonState == LOW)
 {
   digitalWrite(ledPin, LOW);    // button feedback
   getFortune();
   printFortune();
 }
 else {
    // turn LED off:
    digitalWrite(ledPin,HIGH);      
    lastButtonState = HIGH;
}
}


void getFortune() {
r=random(11);
strcpy_P(fortune, (char*)pgm_read_word(&(fortune_tab[r])));
int ra=random(9);
strcpy_P(list, (char*)pgm_read_word(&(list_tab[ra])));
rn=random(100);
itoa(rn, random_number, 10); // convert int to char 10 = decimal base
}

void printFortune() 
{
printer.justify('C');
printer.setSize('S'); 
printer.println(F("# Welcome to fabulous #"));

printer.setSize('L');        // Set type size, accepts 'S', 'M', 'L'
printer.println(F("Desire world"));
printer.setSize('M');
printer.println(""); 
printer.setSize('S');
printer.println(fortune); 
printer.println("");
printer.setSize('L');
printer.println("I desire"); 
printer.setSize('S');
printer.println(list); 
printer.setSize('M');
printer.println("");
printer.setSize('L');
printer.print("Lucky number "); 
printer.setSize('M');
printer.println(""); 
printer.setSize('L');
printer.print(random_number); 
printer.setSize('L');
printer.println(""); 
printer.println(""); 
printer.println(""); 
}

grouds?? i don't know what it is.. ::slight_smile:

but my connection is the same as the image.

it looks like this.
and the black and red wire on the left is connected to power directly.

no cut green wire.
the image just is weird.
never mind it.
green is connected to ~5, yellow to ~6

yes the code works fine for me as well.
but i doesn't work when i push the button after 1 hr.

Ok, let see the same problem happens or not.
Thank you!!

What are the memory stats returned when you compile?

my Arduino uno is not powered by USB...PC..
Hum anyway thank you for testing the code!!!
i will test it with another power outlet on the wall..