element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Blog RaspiWatt: discover power consumption using a Kill-A-Watt & Pi
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
GPIO Pinout
Raspberry Pi Wishlist
Comparison Chart
Quiz
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: fustini
  • Date Created: 5 Apr 2013 3:24 AM Date Created
  • Views 9152 views
  • Likes 2 likes
  • Comments 33 comments
Related
Recommended
  • rpiintermediate
  • hack
  • raspi
  • ladyada
  • raspberry_pi
  • rpi
  • adafruit

RaspiWatt: discover power consumption using a Kill-A-Watt & Pi

fustini
fustini
5 Apr 2013
imageWant to build this project?
View Parts

 

Say you want to know how much electricity an appliance like an air purifier is consuming?

image

You can hook it up to the nifty Kill-A-Watt power meter (aka KaW).  The KaW will keep track of and display the killowatt-hours, or kWh, used by the plugged in device.

imageimage

However, the total will be reset anytime the KaW is unplugged and loses power.  Limor Fried (aka ladyada) recognized this shortcoming and created the clever Tweet-A-Watt project back in 2009. She modded the KaW into a wireless data logger by soldering a XBee wireless module to the KaW's op-amp chip:

image

image

The XBee's built-in ADC reads the power sensor signals inside the KaW and transmits it to a receiver XBee module connected to a computer via USB.  This diagram by ladyada gives a good sense of the architecture:

image

(source: http://www.ladyada.net/make/tweetawatt/)

 

The Tweet-A-Watt (TaW) is an awesome project, but I felt it's requirement to have a computer receive the data was cumbersome and power hungry.  Thankfully, we now live in an world of powerful, tiny & cheap single board computers (SBCs) like the Raspberry Pi .  I decided to use the Pi in place of a traditional computer.  I also used the Adafruit LCD Pi Plate to display the power usage data. and the Adafruit Pi Box enclosure to protect the Pi (which has a convenient "convertible" mode to accommodate the LCD Pi Plate on top):

image

The receiver XBee module connects to the Pi via a FTDI USB-to-serial cable :

image

Ladyada used Google AppEngine for graphing the TaW data, but I decided to take advantage of the newer Cosm graphing service (formerly named Pachube).  Here is a screenshot of my RaspiWatt Cosm feed showing Watts, kWh, and USD$ (based on the cost of a kWh for my power company):

image

Here is the list of parts I used if you are interested in building your own "RaspiWatt":

 

SKU Qty NamePurpose

53W5739

1Adafruit Tweet-A-Watt starter pack Includes 2 XBee radio modules and adapter boards; components to mod the XBee transmitter; FTDI USB-to-serial cable

07P6545

1Kill-A-Watt P4400 power meter Power meter which the XBee transmitter taps into
44W34651Adafruit Pi Box enclosure Protects Pi and has 'convertible' mode to accommodate the LCD Pi Plate
52W90851Adafruit RGB LCD Pi Plate Displays current power usage; intend to use it's buttons to create simple UI

53W5726

1

Adafruit Stacking Header

to replace the header that comes with the above Plate, it allows the Cobbler to be used
44W34971

Adafruit Pi Cobbler

to connect additional sensors to log to Cosm like temperature, humidity, etc

56T0250

1Full-size breadboard to construct additional sensor circuits
43W53021Raspberry Pi Model B replaces the TaW "traditional" computer

 

You can Add to Cart on Newark element14 all of the above (excluding the Raspberry Pi Model B).

 

My Pi is currently running a Python program named wattcher_cosm.py which is based on ladyada's original TaW wattcher.py program.  bonnie555 has been a big help in developing it for the RaspiWatt project, and it incorporates code from Adafruit's Cosm tutorial and their LCD Pi Plate tutorial.  In future posts, I'll describe in more detail how I assembled the hardware and provide instructions for installing the software on the Pi.

 

Cheers,

Drew

http://twitter.com/pdp7

 

 

 

 

Product Name*DescriptionSupplier
Raspberry Pi Model B Raspberry Pi model BRaspberry Pi
Buy Now
Optical mouse Basic USB optical mouseIONE / Pro Signal
Buy Now
Raspberry Pi Power Supply 120-240v to 5V power supply with micro USB connectorRaspberry Pi
Buy Now
Keyboard Basic USB keyboardGear Head / A4 Tech
Buy Now
Pre-programmed 4GB SD card 4GB Class 4 SD card preloaded with Debian 6 LinuxSamsung
Buy Now
Adafruit Tweet-A-Watt starter pack Includes 2 XBee radio modules and adapter boards, components to mod the XBee transmitter and an FTDI USB-to-serial cableAdafruit
Buy Now
Kill-A-Watt P4400 power meter Power meter which the XBee transmitter taps intoP3 International
Buy Now
Adafruit Pi Box Enclosure Protects Pi and has 'convertible' mode to accommodate the LCD Pi PlateAdafruit
Buy Now
Adafruit RGB LCD Pi Plate Displays current power usage; Buttons can be used to create simple UIAdafruit
Buy Now
Adafruit Stacking Header Replaces the header that comes with the Pi Plate, and allows the Pi Cobbler to be usedAdafruit
Buy Now
Adafruit Pi Cobbler Allows for easy connection to the Pi's GPIO pinsAdafruit
Buy Now
Full-Size Breadboard Allows for easy construction of additional sensor circuitsTwin Industries
Buy Now

 

*Products and resources are listed to help members build their own Pi Projects. For substitutions of any parts, please login to post a question to the original author.

  • Sign in to reply

Top Comments

  • Former Member
    Former Member over 12 years ago in reply to Former Member +1
    FYI, I found out the hard way that you DO need the adafruit xBee shield for programing.
  • Former Member
    Former Member over 12 years ago in reply to fustini +1
    Me too. I was trying to avoid buying more than I needed, as I already had several SparkFun XBee Explorers. My guess is the FTDI vs USB cable. Have you or anyone else set up the COSM code for more than…
  • felixemman
    felixemman over 12 years ago +1
    Hye guys in my case the XBEE didn't work because it was drawing too much power from the KillAWatt and causing the screen to flicker and turn off. I created my own version of the Tweet A Watt using a Moteino…
  • Former Member
    Former Member over 12 years ago in reply to fustini

    Sorry for not responding, Drew. Things have been rather hectic over the last week and I haven't had time to tinker with this. I'll get into it again tomorrow and let you know how it goes. Thanks again for all the help.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • fustini
    fustini over 12 years ago in reply to Former Member

    Any luck so far?  Did my explanation make sense?  If you're interested, I could try to simulate another xbee transmitter and see if I can get the code to calculate the kWh & cost per sensor.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • fustini
    fustini over 12 years ago in reply to Former Member

    The dot operator accesses data or methods that are stored in a object.  Take a look at https://github.com/misterbonnie/Tweet-a-Watt/blob/master/sensorhistory.py.  This defines on line 15:

     

    class SensorHistories:

        # array of sensor data

        sensorhistories = []

     

    in https://github.com/misterbonnie/Tweet-a-Watt/blob/master/wattcher_cosm.py on line 6:

     

    import sensorhistory

     

    That is importing the SensorHistories module into our program, wattcher_cosm.py. On line 160:

     

    sensorhistories = sensorhistory.SensorHistories(logfile)

     

    This creates a SensorHistories object from the sensorhistory module and can be referenced as sensorhistories in our program now.  So this line 295:

     

            for history in sensorhistories.sensorhistories:

                wattsused += history.avgwattover5min()

                whused += history.dayswatthr

     

    This will iterate through each itme in the array called sensorhistories inside the sensorhistories object.  Each iteration of the for loop will place the next item from the sensorhistories array into history.  Since history is a reference to a SensorHistory object, it has methods avgwattover5min which is on line 123 of sensorhistory.py:

     

      def avgwattover5min(self):

          return self.cumulative5mwatthr * (60.0*60.0 / (time.time() - self.fiveminutetimer))

     

    So I think what is happening is that wattsused and whused is cumulative to all the sensors.  Thus the cost we calculate will also be cumulative for all the sensor.

     



    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 12 years ago in reply to fustini

    It does, and I've been fiddling with that part of the file. I'm pretty new to python though, so tell me if I'm wrong, but is the dot syntax in python unlike that in other languages like C? When did history become a file or class that contains the methods avgwattover5min() and dayswatthr? I should also say I'm not the most experienced developer beyond python as well. image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • fustini
    fustini over 12 years ago in reply to Former Member

    Hi - I'm looking at the original code https://github.com/adafruit/Tweet-a-Watt/blob/master/wattcher.py and also the design document http://www.ladyada.net/make/tweetawatt/database.html.  Unfortunately, I don't have the equipment right now to test it myself.

     

    I think the trouble is that it is using the sensor histories for all sensors.  From your gist, line 269:

            # Taking avgwattover5min from ALL or only one sensor => erronious KWh

            for history in sensorhistories.sensorhistories:

                wattsused += history.avgwattover5min()

                whused += history.dayswatthr

    I think this would need to be filtered based on the sensornum.  Does that make sense?  I should be able to get the equipment later this week to test it out myself.

     

    Thanks,

    Drew

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
<>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube