Welcome

My name is Greg Winn I am a web developer, specializing in web application development. Take a look at some of my projects, then drop me a line.

Winn A1 Microcontroller Arduino pre loaded

It’s purple and thin! This is a minimal design (1” x 2”) to the ATmega328p pre loaded with Arduino. This is a 5V Arduino running the 16MHz bootloader. The Winn A1 is meant for users that understand the limitations of system voltage (5V), lack of connectors, and USB off board.

All components are thew hole (no SMD). This board connects directly to the FTDI Basic Breakout board and supports auto-reset. The Winn A1 is extremely affordable ($14.99) and offers most all the features of a standard Arduino Pro or Mini.

Checkout the Winn A1!


Lastest Posts

extconf.rb failed Posted on 30 November 2014.

Winn A1 now on Amazon Posted on 05 September 2014.

Bootloading an ATTiny85 Posted on 24 August 2014.

Winn A1 coming very soon Posted on 15 August 2014.

Rails API CORS Posted on 20 April 2014.

Using yStock Posted on 21 April 2013.

Active Merchant Posted on 17 October 2012.

View older articles.

My Gems

Most of my projects can be followed on Github (@gregwinn)

LnkdtoGo

This is a wrapper for the Lnkdto API. This gem gives to access to both single url and batch url requests.

Gem Version Build Status

YStock

This Ruby gem named Ystock will pull stock information such as price, volume, and change from Yahoo! & Google Finance.

Gem Version Build Status

Watchdog Arduino

Posted on 01 December 2014

Watchdog on Android

Power saving with ATTiny

I have been working on many small projects that run off of battery power and need to save every little mA they can. Most of the projects are using ATTiny’s with Arduino, so using the built in power saving options work well. Below are some examples of basic power saving options you have when creating your next low power project.


Options shown not using an inturupt pin.

8 Second delay

This example blinks an LED on pin 0 of the ATTiny every 8 seconds.

#include <avr/sleep.h>
#include <avr/wdt.h>

#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

int pinLed = 0;
volatile boolean f_wdt = 1;

void setup(){
  pinMode(pinLed,OUTPUT);
  setup_watchdog(9);
}

void loop(){
  if (f_wdt==1) {
    f_wdt=0;

    digitalWrite(pinLed, 50);
    delay(500);
    digitalWrite(pinLed,LOW);

    // Set any pins used to input to lower power usage.
    pinMode(pinLed,INPUT);
    system_sleep();

    // Set them back to OUTPUT
    pinMode(pinLed,OUTPUT);
  }
}

void system_sleep() {
  cbi(ADCSRA,ADEN);                    // switch Analog to Digitalconverter OFF

  set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode
  sleep_enable();

  sleep_mode();

  sleep_disable(); 
  sbi(ADCSRA,ADEN);                    // switch Analog to Digitalconverter ON
}

// 0=16ms, 1=32ms,2=64ms,3=128ms,4=250ms,5=500ms
// 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec
void setup_watchdog(int ii) {

  byte bb;
  int ww;
  if (ii > 9 ) ii=9;
  bb=ii & 7;
  if (ii > 7) bb|= (1<<5);
  bb|= (1<<WDCE);
  ww=bb;

  MCUSR &= ~(1<<WDRF);
  // start timed sequence
  WDTCR |= (1<<WDCE) | (1<<WDE);
  // set new watchdog timeout value
  WDTCR = bb;
  WDTCR |= _BV(WDIE);
}
  
// Watchdog Interrupt Service / is executed when watchdog timed out
ISR(WDT_vect) {
  f_wdt=1;
}

Power saving INPUTS

By setting all the OUTPUTS to INPUTS the ATTiny chip will save a good amount of power thus aiding in saving battery with in sleep mode. Make sure you set every OUTPUT to INPUT before sleep then back to OUTPUT so you are able to use them again.

Setting the timer

Arduino WDT

    WDTCSR = bit (WDIE) | bit (WDP2) | bit (WDP1);    // About 1 Second
    WDTCSR = bit (WDIE) | bit (WDP2) | bit (WDP1) | bit (WDP0);   // About 2 Seconds
    WDTCSR = bit (WDIE) | bit (WDP3);     // About 4 Seconds
    WDTCSR = bit (WDIE) | bit (WDP3) | bit (WDP0);    // About 8 Seconds

Warning about timers

Various fuse settings make a big difference to the wake-up time. Some wake-up times are quite long (eg. 65 mS) because they are designed to allow the crystal clock to settle. If you are trying to save power, taking 65 mS to wake up, add 1 to a counter, and go back to sleep, is a lot. You would want to look at a “wake-up” fuse setting that is appropriate for the type of clock source you are using.

Be sure to check the datasheet for your specific ATTiny chipset.