I have a simple wireless transmitter that I have set up as a remote with VirtualWire & Keypad.
I am trying to simplify my design, which is: 5V 16MHz ProMini, 3 AA battery pack, Velleman 4x4 matrix keypad, sparkfun 434 MHZ transmitter, 22K pullup resistors on the 4 Row pins.
I am measuring 9.22 mA current draw in idle mode, jumping to 14mA or so with a key press.
I have been looking to simplifly & reduce current draw. Reading here, it was suggested to have all unused pins be inputs with internal pullups enabled (declare pinModes as inputs, then digitalWrite High). I did that for the 9 unused pins and saw the current draw drop to 8.95 mA.
I tried doing the same for the keypad pins, figured the library would reset them as needed - only that didn't quite seem to work, as idle current draw jumped to 20mA.
Is there a way to turn on internal pullups for the keypad pins that the library calls out so I can 1: get rid of the external pullups, and 2: reduce current draw some more when there is nothing going on?
I am also looking into the Sleep modes to turn off the Analog/Digital Comparator and Analog VRef which are not needed.
I don't have a 3.3VPromini, want to get one of those and check the range/current draw with 3.7V Li Ion battery.
// transmitter_mine.pde//
// Simple example of how to use VirtualWire to transmit messages
// Implements a simplex (one-way) transmitter with Sparkfun module
// RF Link Transmitter - 434MHz, WRL-08946
// See VirtualWire.h for detailed API docs
// Author: Mike McCauley (mikem@open.com.au)
// Copyright (C) 2008 Mike McCauley
// $Id: transmitter.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $
// uses default pin 12 for transmit data
// modified to use input from Keypad to send character to the receiver,
// with 4x4 matrix
// define unused pins so can turn on internal pullups
int dpin0=0;
int dpin1=1;
int dpin2=2;
int dpin11=11;
int dpin14=14;
int dpin15=15;
int dpin16=16;
int dpin17=17;
int dpin18=18;
int dpin19=19;
// adding these caused higher current draw, commented out for now
/*
int dpin3=3;
int dpin4=4;
int dpin5=5;
int dpin6=6;
int dpin7=7;
int dpin8=8;
int dpin9=9;
int dpin10=10;
int dpin12=12;
int dpin13=13;
*/
#include <VirtualWire.h>
#include <Keypad.h>
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns
// Define the Keymap
char keys[ROWS][COLS] =
{
{ '1','2','3','A' }, // row 1
{ '4','5','6','B' }, // row 2
{ '7','8','9','C' }, // row 3
{ '*','0','#','D' }, // row 4
};
// Connect keypad ROW1, ROW2, ROW3 and ROW4 to these Arduino pins.
byte rowPins[ROWS] = { 3, 4, 5, 6 };
// Connect keypad COL1, COL2, COL3, COL4 to these Arduino pins.
byte colPins[COLS] = { 10, 9, 8, 7 };
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
#define ledPin 13
char msg[2];
void setup()
{
// define all the unused pins as inputs with internal pullups for lower power state
pinMode(dpin0, INPUT);
digitalWrite(dpin0, HIGH);
pinMode(dpin1, INPUT);
digitalWrite(dpin1, HIGH);
pinMode(dpin2, INPUT);
digitalWrite(dpin2, HIGH);
pinMode(dpin11, INPUT);
digitalWrite(dpin11, HIGH);
pinMode(dpin14, INPUT);
digitalWrite(dpin14, HIGH);
pinMode(dpin15, INPUT);
digitalWrite(dpin15, HIGH);
pinMode(dpin16, INPUT);
digitalWrite(dpin16, HIGH);
pinMode(dpin17, INPUT);
digitalWrite(dpin17, HIGH);
pinMode(dpin18, INPUT);
digitalWrite(dpin18, HIGH);
pinMode(dpin19, INPUT);
digitalWrite(dpin19, HIGH);
// tried adding the following, seemed to conflict with keypad library as current draw doubled
/*
pinMode(dpin3, INPUT);
digitalWrite(dpin3, HIGH);
pinMode(dpin4, INPUT);
digitalWrite(dpin4, HIGH);
pinMode(dpin5, INPUT);
digitalWrite(dpin5, HIGH);
pinMode(dpin6, INPUT);
digitalWrite(dpin6, HIGH);
pinMode(dpin7, INPUT);
digitalWrite(dpin7, HIGH);
pinMode(dpin8, INPUT);
digitalWrite(dpin8, HIGH);
pinMode(dpin9, INPUT);
digitalWrite(dpin9, HIGH);
pinMode(dpin10, INPUT);
digitalWrite(dpin10, HIGH);
pinMode(dpin12, INPUT);
digitalWrite(dpin12, HIGH);
pinMode(dpin13, INPUT);
digitalWrite(dpin13, HIGH);
*/
digitalWrite(ledPin, LOW);
// Serial.begin(9600) // for debugging only
// Serial.println("TX setup"); // for debugging only
// Initialise the IO and ISR
vw_setup(2000); // Bits per sec
}
void loop()
{
char key = keypad.getKey();
if(key) // same as if(key != NO_KEY)
{
Serial.println(key);
msg[0]=key;
// msg[1]=NULL; // only sending 1 byte, Rx works without this
digitalWrite(ledPin, true); // Flash a light to show transmitting
// Serial.println("sending: "); // for debugging only
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait until the whole message is gone
delay (1); // shortened flash time
digitalWrite(ledPin, false);
} // end of if(key)
} // end of void loop