Example 1: No Optimizations

This example demonstrates the basic WiFi datalogging hardware. The hardware reads the value of a photocell every minute and sends it to a server listening on TCP port 8000. Later examples will investigate how to reduce power consumption and increase battery life of this simple example.

You will need the following parts to build this example:
  • Arduino Uno or Nano
  • CC3000 breakout or shield
  • Photocell
  • 10 kilo-ohm, 1/4 watt resistor
  • 6x AA or AAA battery holder as a power source
  • Batteries, preferably rechargeable. Look for a name brand battery with a datasheet that provides the battery capacity.
Above you can see the hardware and schematic for the project. Hook up the CC3000 to the Arduino through the standard pins:
  • CC3000 VIN to power supply positive.
  • CC3000 ground to power supply ground.
  • CC3000 CLK to Arduino digital pin 13.
  • CC3000 MISO to Arduino digital pin 12.
  • CC3000 MOSI to Arduino digital pin 11.
  • CC3000 CS to Arduino digital pin 10.
  • CC3000 VBEN to Arduino digital pin 5.
  • CC3000 IRQ to digital pin 3.
Finally hook up the photocell:
  • One photocell lead to Arduino 5V power.
  • The other photocell lead through the 10 kilo-ohm resistor to ground.
  • From the junction of the photocell and resistor, connect a wire back to an Arduino analog input such as analog pin 4.
Once the hardware is assembled, load in Arduino the Example_1_No_Optimizations sketch from the software download. There are a few configuration values you can change in the #define values at the top of the sketch:
  • ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, and ADAFRUIT_CC3000_CS should be set to the appropriate pins which connect the CC3000 to the Arduino.
  • WLAN_SSID, WLAN_PASS, and WLAN_SECURITY should be set to the appropriate values for your wireless network.
  • SENSOR_PIN should be set to the analog input which is connected to the photocell and resistor.
  • SERVER_IP and SERVER_PORT should be set to the IP address and port of the computer which will receive photo sensor readings. The IP address should be written with commas instead of periods, for example if your computer has an IP address of 192.168.1.100 you would use a value of '192, 168, 1, 100' without quotes.
Once the configuration is updated, compile the sketch and load it on the hardware.

Listening Server

To receive measurements on your computer, you can either run a python script (good for Windows, Mac, or Linux with python installed) or use the netcat command (good for Mac or Linux out of the box, or Windows if installed separately).

To run the python listener, in a terminal window navigate to the Scripts subdirectory of the software download and execute this command:

python listener.py

Alternatively, to use the netcat tool in a terminal window execute:

nc -lk 8000

Either server will listen for connections on port 8000 and print out data received to the standard output. The python script will also append the time that each measurement occured, whereas the netcat command won't add anything. You can stop either server by pressing Ctrl-C in the terminal.

Once the server and hardware are running, wait a few minutes to confirm the server receives a measurement from the hardware about once a minute. If you don't see anything on the server after a few minutes, make sure the hardware is configured with the right server IP and there aren't any firewall or routing issues that might block the network traffic.

Current Usage

Looking at the code for this example you'll see it's a fairly simple sketch. The setup() function connects to the WiFi network, and the loop() function waits a minute before sending a new reading to the server using the CC3000 board.

The current consumption of this hardware should be fairly high because both the Arduino and CC3000 constantly run at full power, even when sitting idle between measurements. To confirm this assumption I connected my hardware (an Arduino Nano and CC3000 breakout) to the INA219 current datalogger and measured the current consumption for 5 minutes.
Above you can see the current consumption I measured for this example hardware. The current usage is quite steady at a value of about 135 milliamps. This measurement confirms that there's no difference between waiting to send and sending a measurement, in both states the Arduino & CC3000 are drawing a steady amount of current.

Expected Battery Life

With a measure of the average current consumption, I can estimate and test how long the hardware will run on batteries.
For this test I'm using eneloop AAA Ni-MH rechargeable batteries. Above is a picture of the battery's rated milliamp-hour capacity at different discharge currents (taken from this datasheet).

The 160mA discharge current curve is pretty close to the current consumption of this example, 135mA, so the battery capacity should be 750 mAh.

If the hardware's average current consumption was much higher, for example around 800mA or more, I would want to use a lower milliamp-hour rating in battery life calculations. Remember, pulling more current from a battery results in a lower battery capacity.

Dividing the milliamp hour capacity of the batteries by the average current consumption will yield the number of hours I can expect the hardware to run.

Expected battery life:

750 mAh / 135 mA = 5.6 hours

Actual Battery Life

To measure the actual battery life I ran the hardware on batteries and used the INA219 datalogger to measure battery pack voltage over time.
Above is a graph of the battery cell voltage over time. The cell voltage was computed by dividing the total battery pack voltage by the number of batteries in series, in this case 6.

At a full charge the battery cell voltage starts around 1.35 volts. Over time the voltage drops following a curve that's similar to what's seen in the battery datasheet.

Once the battery cell voltage drops below 1 volt the batteries are exhausted and the hardware will quickly stop running. Be careful not to run rechargeable batteries too far below 1 volt or else they might be damaged.

The actual battery life of the hardware was quite close to the expected battery life. Factors such as age of the batteries, ambient temperature, and number of charge/discharge cycles can all affect capacity and might explain some of the difference in expected vs. actual capacity.

Actual Battery Life:

5.3 hours
    This guide was first published on Feb 13, 2014. It was last updated on Feb 13, 2014. This page (Example 1: No Optimizations) was last updated on Jun 15, 2019.