Nine Hills vista, Alamaden Quicksilver Bike Trail

July 6, 2009 by Shahram Javey

Arduino development with command-line tools

July 2, 2009 by Shahram Javey

You may find that after your Arduino program grows to be over 1000 lines of C code that the Arduino IDE becomes increasing more annoying to use. Well, you can use TextMate, but first you need to set yourself up for command line programming. There are some instructions on the Arduino site for this, but it is a bit out of date. Specifically, the Makefile that they recommend simply does not work. Read the rest of this entry »

How to sync real-time clock with network-time on Telit modules

June 30, 2009 by Shahram Javey

You can configure the Telit GM cellular modem to set its internal real-time clock to the network time and have this value automatically updated each time the module is powered on. Here are the AT commands that you need to issue (I’ve omitted the AT response codes):


AT#SELINT=2
AT#NITZ=7,0 // sync network time to internal clock
AT&P0 // profile to be loaded on startup
AT&W0 // store the complete profile
AT#SHDN // this will turn off the modem
// now power on the modem
AT+CCLK? // get current time
// time response is +CCLK: "09/06/29,15:25:32-28"
// time format is yy/MM/dd,hh:mm:ss±zz

The command AT#NITZ=7,0 on your specific modem may not work, check the range of valid inputs for this command using AT#NITZ=?. If you’ve an old module from sparkfun.com then AT#NITZ=? may return #NITZ:(0-1),(0-7). More recent firmwares return #NITZ:(0-7)(0,1). If you’ve an older firmware, then you should set the AT#NITZ=1,0. The difference is that with newer firmware, you will also get the time-zone zz, not so with the older firmware. If you set AT#NITZ=7,1, then when the module gets the network time it is supposed to be echoed as an unsolicited message on the serial port. This didn’t work in my tests. Just as well. In this case, I rather not deal with unsolicited messages for network time, since I can use the real-time clock to get the time when I want to (getting unsolicited messages for AT+CREG is valuable, however).

What do I mean by older firmware? The GM862 module that I bought from sparkfun.com has this firmware:


AT+CGMR
PS:5.02.203/AL:6.04.204-GM862 QUAD

The module that I purchased from SemiConductorStore has this firmware:


AT+CGMR
07.03.600

Water & Energy

June 25, 2009 by Shahram Javey

Did you know that about 20% of energy in California is used to pump or treat water as compared to the 4% nationwide? That is a huge portion of the state’s total energy use. The reason for this is in California we have to move large quantities  of water from a source to the final point of use. Water from the Bay delta is moved 400 miles to San Diego. It has be pumped over two mountains ranges along the way.

The term water energy intensity captures the amount of energy that is used to make/deliver water. For instance, in East Bay MUD water energy intensity is 1.25 MWH per Million Gallons of water (based on 2006 numbers). EBMUD needs to pump water up the Oakland and Berkeley hills and that accounts for a significant portion of the energy use in their water.

The relationship between water and energy has been known and studied for a while (e.g., see the pioneering work of Professor Wilkinson’s on the energy intensity of water), but this information still appears to be largely ignored. There are few if any real bridges between the water and energy industry or professional silos. To better manage energy, you need to understand how the biggest customer, water agencies, are using the energy.

There are four main energy uses in a typical water system:

  • Pumps to extract ground water and to deliver water from source to a final point of use.
  • Water treatment and distribution with in a service area.
  • On-site water pumping, treatment and thermal inputs (heating and cooling).
  • Waste water collection and treatment.

EPA offers a top 10 list of ways to manage water. The best way to manage water is to Meter, Measure, and Monitor the water use for each building or facility. This information can help detect leaks and the knowledge of water usage will lead to greater water efficiency.

In commercial buildings, the main user of water & energy are cooling towers. Some use as much as 30K gallons of water per day. Metering the quantity of water put into and discharged from the cooling tower provides information that helps better manage the efficiency of the cooling tower.

Irrigation often accounts for 50% of a facility’s total water use. So minimizing the water used for irrigation will have a significant impact to the overall amount of water used.

According to the Energy Independence and Security Act of 2007, all Federal buildings are required to measure and verify energy and water usage and savings. The list of Best Management Practices is well worth reading.

Per Capita Use of Water in California

June 24, 2009 by Shahram Javey

Gallons Per Capita Daily water use in all California counties

Gallons Per Capita Daily water use in all California counties

Per capita water use is calculated by dividing the total amount of water withdrawn from all water suppliers by the population. Water used for irrigation and agriculture is not included. See this excellent summary report on per capita use in Florida.

The Water Resource division of the U.S. Geological Survey (USGS) publishes the Estimated Use of Water in the United States every five years. This report has detailed per capita water usage on a state by state and county by county level.

In California, Kern county has the highest per capita use of water at 274 Gallons per Day, & Mariposa has the lowest at 67 GPD. Santa Clara is 171 GPD and San Diego county is 156 GPD. Sacramento & Fresno don’t have a lot of meters and consequently they use more water at 265 GPD and 246 GPD, respectively.

Combine PDFs with Python on Mac

June 21, 2009 by Shahram Javey

I was looking for a way to combine PDFs (without using Acrobat) and came across this note.


$ python '/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py' -o '/path/to/output.pdf' '/path/to/input1.pdf' '/path/to/input2.pdf'

This command will generate the PDF and it will echo the following warning (date and name of your computer will vary, of course) which apparently you can safely ignore.


Sun Jun 21 14:58:34 sj.local Python [16000] : The function `CGPDFDocumentGetMediaBox' is obsolete and will be removed in an upcoming update. Unfortunately, this application, or a library it uses, is using this obsolete function, and is thereby contributing to an overall degradation of system performance. Please use `CGPDFPageGetBoxRect' instead.

Better yet, use the Mac Automator. You can use the Automator to combine multiple image files, or PDFs into a single PDF. You can then use the Previewer to re-arrange the pages and delete some of the pages if needed.

avr on mac

June 6, 2009 by Shahram Javey
  1. install mac ports
  2. sudo port install avr-binutils Read the rest of this entry »

How to dismiss the keyboard in iPhone

May 27, 2009 by Shahram Javey
  • In the Interface Builder add the text field to the view and use the inspector to change the Text Input Traits so that the Return Key is set to Done (see thumbnail).Text Input Traits
  • In the .h file for your view controller, define an IBAction method to dismiss the keyboard, e.g.
    - (IBAction)dismissKeyboard:(id)sender;
    
  • In the .m file define the method:
    
    - (IBAction)dismissKeyboard:(id)sender {
    	[sender resignFirstResponder];
    }
    
  • In the Interface Builder, control click on the text field object, and connect the “Did End On Exit” event to the view controller’s File’s Owner object.

You can use the same method to dismiss the keyboard for all of the text fields in the view.

Another bike route to top of St. Joseph Hill

May 26, 2009 by Shahram Javey

At 6:30 AM this morning, our bike club tried yet another route to the summit of St. Joseph Hill in Los Gatos. The 6.44 miles ride took one hour and 10 minutes.

Water laws and water use in USA

May 25, 2009 by Shahram Javey

Interesting lecture on the laws of water use in USA by Prof. Glennon given at the UC Berkeley California Colloquium on Water. Some of the facts cited in this talk:

  • Groundwater use for domestic purposes alone 8 BGD (Billion Gallons per Day) in 1965 to 19.7 BGD in 2000.
  • Farmers use 2/3 of all groundwater pumped.
  • Total groundwater use in 2000: 30 trillion gallons
  • Groundwater makes up 25% of the nation’s water supply
  • 1/2 population relies on groundwater for drinking water

But these numbers are quite out of date. During the past decade people have turned to groundwater to supplement the short supply of water caused by draughts. This means that much more water must have been pumped from new and existing groundwater sources than in 2000 (the last year for which there is data from the US Geological survey).

Surface water law. If you own property on a lake or river, then you’ve water rights. This is called the Riparian Water Rights (which has its origin in English common law). It is a shared water rights (all land owners that are on the river or lake share the water rights). In the western USA, a different law is in place: Prior Appropriation. In this system, water rights are unconnected to land ownership. The first person to use a quantity of water for a beneficial use (agricultural, industrial or household use), has the right to use that quantity of water for that purpose. Each water right has a yearly quantity and an appropriation date.

Groundwater law: Rights of Capture & Reasonable Use. The problem with the groundwater law capture and reasonable use is that it allows for over-drafting or mining the resource to the extend of exhausting the supply. Basically anything you can with groundwater is considered reasonable.

San Joaquin Valley subsidence

San Joaquin Valley subsidence

These are the basic laws for water. One set of rules for surface water and one set for groundwater. Think of a ground water as a glass of water and each groundwater user having a straw. The groundwater laws allows for unlimited supply of straws. This leads to exploitation of groundwater aquifers.

Water is measured in acre-foot. That is how much water it takes to cover an acre of land to the depth of one foot with water. An acre water is 325,000 gallons, and weights 1358 tons. So water is really heavy and it takes a lot of energy to pump it out of the aquifers. Pumping water out of a 500 feet well will require many kilo watts of energy (multi $K per month).

Problems with over-drafting:

  • The water quality is lower the deeper the well.
  • Salt-water intrusion.
  • Subsidence. The land collapse when groundwater is pumped too quickly without giving the aquifers times to naturally replenish (rate of 2 inches per year).

Groundwater moves laterally and it actually provides water to the rivers.