Archive for the ‘CodeProject’ Category.

LED candle light with timer

LEDTimedCandle

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)
{
  sec8_counter++;

#ifdef USE_HEART_BEAT_LED  
  //flash heart beat LED
  digitalWrite(LED2, HIGH);
  delay(1);
  digitalWrite(LED2, LOW);
#endif
  
  if(sec8_counter>=HOUR_INTERVAL){
    sec8_counter=0;
    if(bLedIsOn==1){
      on_hours++;
      if(on_hours>=MAX_ON_HOURS){
        bLedIsOn=0; //switch to OFF mode
        off_hours=0;
      }
    }else{
      off_hours++;
      if(off_hours>=MAX_OFF_HOURS){
        bLedIsOn=1; //switch to ON mode
        on_hours=0;
      }
    }
  }
  wdt_reset();
}  // 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
  noInterrupts();
  if(bLedIsOn==1){
    doCandle();
  }else{
    digitalWrite (LED, LOW); //ensure LED is OFF
   goToSleep ();
  }
  interrupts();
}  // 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.

https://github.com/hjgode/LEDTimedCandle/tree/master

CREDITS to all that share their knowledge, especially:

https://github.com/MCUdude/MicroCore

http://forum.arduino.cc/index.php?topic=200590.0

https://electronics.stackexchange.com/questions/74840/use-avr-watchdog-like-normal-isr

http://www.ece.cmu.edu/~koopman/lfsr/index.html

NPAPI – a plugin to retrieve device information

Some times ago I wrote a barcode scanner NPAPI plugin for the HTML5 browser by zetakey. It is based on code supplied as MySensor in the motorola knowledge base. The plugin is for Windows Mobile 6.x based devices by Intermec and another one for M3 devices.

The MySensor plugin based on npruntime was the only sample I could get to compile and work correctly. The barcode scanner fork I wrote does also work very well. The new MyDevinfo plugin retrieves model code, battery level and WLAN RSSI value of the Intermec device and allows to present this information to a HTML5 browser user when needed.

npapi_simple

The above shows the web page of MyDevinfo_simple.htm.

Continue reading ‘NPAPI – a plugin to retrieve device information’ »

Development: Windows 10 UWP Wireless Label/Receipt printer demo

As I already wrote the small demo apps for wireless printing of Label and Receipts for Android and Windows Phone 8, I now wrote such demo now for Windows UWP. The applciation was tested on a Windows 10 Phone running Windows 10 Iot Enterprise Edition.

The code is based on the Windows Universal Sample app BTRFCommChat, but uses a different, single page layout.

layout_designer     wp_ss_20160811_0001   wp_ss_20160811_0003   wp_ss_20160811_0005

Continue reading ‘Development: Windows 10 UWP Wireless Label/Receipt printer demo’ »

Mobile Development – Start apps with another using injectDLL

I already posted one article about using injectDLL, one about subclassing a foreign window. This time injectDLL is used to start and stop an application when another app is started. Remember that every DLL listed inside the MULTI_SZ registry key HKLM\System\Kernel\injectDLL is loaded into every process.

I would like to add some battery and wifi indicator to a full screen Remote Desktop Mobile (RDM) session. There are two specialized applications that display a small bar graph on the right of the screen, one for the battery level and one for the WiFi RSSI.

tsshellwnd_normal_with_wifi_and_batt_monitor_bars

The upper right one is for the WLAN RSSI and the lower bar shows the battery charge level.

As these apps should only add there display when RDM ist started, I added them to an injectDLL.

Continue reading ‘Mobile Development – Start apps with another using injectDLL’ »