Posts tagged ‘code’

LED candle light with timer


I did a lot of research on battery powered LED candle lights circuits and code and was unable to find a time controlled LED candle light.

As I have some ATTiny13 left, I decided to use this little chip. As I want the LED to do a candle light for about 4hours and then stay of for another 20 hours, I need on timer and counter. Another timer/PWM is needed to immitate a candle flickering. But the ATTiny13 has only one timer. On the ATTiny13 you can either use the timer or PWM.

Fortunately the ATTiny has also a Watchdog timer that can be used to call an interrupt function. The watchdog runs with a separate 128kHz clock, independent from the CPU clock. The largest timeout is 8 seconds. So I need to count this 450 times to have one hour.

// watchdog interrupt
ISR (WDT_vect)

  //flash heart beat LED
  digitalWrite(LED2, HIGH);
  digitalWrite(LED2, LOW);
        bLedIsOn=0; //switch to OFF mode
        bLedIsOn=1; //switch to ON mode
}  // end of WDT_vect

The code makes the ATTiny13 sleep for another 8 seconds or light the LED. The ON phase is 4 hours and the sleep phase will be extended to 20 hours.

void loop ()
  //sleep 20 hours and work 4 hours
    digitalWrite (LED, LOW); //ensure LED is OFF
   goToSleep ();
}  // end of loop

The sequence starts with the ON phase, when power is applied. In the ON phase I measure about 3mA and in the OFF phase the circuit needs 300µA.

The circuit is documented in the Arduino code file. Running the ATTiny13 at lower clock than 9.6MHz did not change the power usage. But I switched to the 1.2MHz internal clock and disabled BOD (auto power down for low power) to get a longer runtime with two or three AA batteries.

UPDATE 2019/03/10: The wdt calculation is wrong and I changed the 450 cycles for one hour to 388. See github README for full update. The main issue is that the ATTiny13 datasheet says 128kHz but means 131072Hz and not 128000Hz and the wdt oscilator never cycles that fast but more or less at around 113000Hz.

CREDITS to all that share their knowledge, especially:

iTextSharp running on Compact Framework – Windows Mobile

PDF library iTextSharp working in Compact Framework 2: iTextSharpCF

Recently I needed a tool to combine several pictures into one file. First I thought about creating a memory bitmap and then BitBlit the source files into this single bitmap. Then I found an entry about iText and iTextSharp. This is a JAVA and .NET class library to create pdf files. As it seems very easy to use I decided to take a closer look. I found one message, where Marco states he has done a port for .NET compact framework and provided a patch to the sourceforge iTextSharp team. Unfortunately the iTextSharp team seems to ignore this port. So I started with iTextSharp and the patch to get iTextSharp running on Compact Framework.

The patch was done against version 4.0.1 of iTextSharp but there were still some rejects and some additional work to do. The main problem was the use of GetInstance where always the general WebRequest.Create(url); and then GetResponseStream() was used. A first workaround is to load the bitmap first and then provide this to doc.Add:

Continue reading ‘iTextSharp running on Compact Framework – Windows Mobile’ »