Then and Now Volt Meter

Could not help myself…Just had to bring home the Rider VoltOhmyst.  Plugged her in and measured some voltage on some DC batteries as well as some ohms across some resistors. resistors. Dead on…Well after some adjustments and warming up.  Will put on the shelf now.

Dates around 1939.  

Weather Station Code

Current code (needs some clean up but working) for the weather station that post to both Xively and ThingSpeak.

ThingSpeak Weather Channel
Xively Weather Station

[pre lang=”C” wrapline=”false”]
// Includes
#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp.h>
#include <ThingSpeak.h>
#include <Xively.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_TSL2561_U.h>
#include <Adafruit_BMP085_U.h>

// Setup TSL2561 and BMP085 Sensors

Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);

// MAC address for your Ethernet shield
byte mac[] = { 0xDE, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };

//Uploading Data to two different services for comparisons

// Your Xively key to let you upload data
char xivelyKey[] = "YOURKEYHERE";

// ThingSpeak
unsigned long myChannelNumber = 000000;
const char * myWriteAPIKey = "YOURKEYHERE";

// Define the strings for our datastream IDs for Xively
char tempID[] = "Temp";
char lightID[] = "Light";
char bpID[] = "Barometric_Pressure";
char wsID[] = "Wind_Speed";

//Setting up Windspeed
//Thanks Allison Lassiter – hackerscapes.com for help with anemometer code
int sensorPin = A0;
int sensorValue = 0;
float voltageConversionConstant = .0048828125;
float windSpeed = 0;
float sensorVoltage = 0;

float voltageMin = .4; // Mininum output voltage from anemometer in V.
float windSpeedMin = 0; // Wind speed in meters/sec corresponding to minimum voltage

float voltageMax = 2.0; // Maximum output voltage from anemometer in V.
float windSpeedMax = 32; // Wind speed in meters/sec corresponding to maximum voltage

//Data structure for Xively data upload
//Basically one for each sensor
XivelyDatastream datastreams[] = {
XivelyDatastream(tempID, strlen(tempID), DATASTREAM_FLOAT),
XivelyDatastream(lightID, strlen(lightID), DATASTREAM_FLOAT),
XivelyDatastream(bpID, strlen(bpID), DATASTREAM_FLOAT),
XivelyDatastream(wsID, strlen(wsID), DATASTREAM_FLOAT)
};
// Finally, wrap the datastreams into a feed
XivelyFeed feed(00000000, datastreams, 4 /* number of datastreams */);

//Setup Ethernet Client
EthernetClient client;

//Setup Xively client
XivelyClient xivelyclient(client);

/**************************************************************************/
/*
Displays some basic information on this sensor from the unified
sensor API sensor_t type (see Adafruit_Sensor for more information)
*/
/**************************************************************************/
void displaySensorDetails(void)
{
sensor_t sensor;
tsl.getSensor(&sensor);
Serial.println("————————————");
Serial.print ("Sensor: "); Serial.println(sensor.name);
Serial.print ("Driver Ver: "); Serial.println(sensor.version);
Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id);
Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" lux");
Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" lux");
Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" lux");
Serial.println("————————————");
Serial.println("");
delay(500);

}

void displayBMPSensorDetails(void)
{
sensor_t sensor;
bmp.getSensor(&sensor);
Serial.println("————————————");
Serial.print ("Sensor: "); Serial.println(sensor.name);
Serial.print ("Driver Ver: "); Serial.println(sensor.version);
Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id);
Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" hPa");
Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" hPa");
Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" hPa");
Serial.println("————————————");
Serial.println("");
delay(500);
}

/**************************************************************************/
/*
Configures the gain and integration time for the TSL2561
*/
/**************************************************************************/
void configureSensor(void)
{
/* You can also manually set the gain or enable auto-gain support */
// tsl.setGain(TSL2561_GAIN_1X); /* No gain … use in bright light to avoid sensor saturation */
// tsl.setGain(TSL2561_GAIN_16X); /* 16x gain … use in low light to boost sensitivity */
tsl.enableAutoRange(true); /* Auto-gain … switches automatically between 1x and 16x */

/* Changing the integration time gives you better sensor resolution (402ms = 16-bit data) */
tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS); /* fast but low resolution */
// tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_101MS); /* medium resolution and speed */
// tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_402MS); /* 16-bit data but slowest conversions */

/* Update these values depending on what you’ve set above! */
Serial.println("————————————");
Serial.print ("Gain: "); Serial.println("Auto");
Serial.print ("Timing: "); Serial.println("13 ms");
Serial.println("————————————");
}

/**************************************************************************/
/*
Arduino setup function (automatically called at startup)
*/
/**************************************************************************/
void setup(void)
{
Serial.begin(9600);
Serial.println("Light Sensor Test"); Serial.println("");
// Setup Ethernet

while (Ethernet.begin(mac) != 1)
{
Serial.println("Error getting IP address via DHCP, trying again…");
delay(5000);
}
// print your local IP address:
Serial.print("My IP address: ");

for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}

/* Initialise the BMP sensor */
if(!bmp.begin())
{
/* There was a problem detecting the BMP085 … check your connections */
Serial.print("Ooops, no BMP085 detected … Check your wiring or I2C ADDR!");
while(1);
}

/* Display some basic information on this sensor */
Serial.println("Found BMP");
displayBMPSensorDetails();

/* Initialise the TSL sensor */
if(!tsl.begin())
{
/* There was a problem detecting the ADXL345 … check your connections */
Serial.print("Ooops, no TSL2561 detected … Check your wiring or I2C ADDR!");
while(1);
}

/* Display some basic information on this sensor */

displaySensorDetails();

/* Setup the sensor gain and integration time */
//configureSensor();

//Setup Thingspeak client
ThingSpeak.begin(client);

/* We’re ready to go! */
Serial.println("");
}

/**************************************************************************/
/*
Arduino loop function, called once ‘setup’ is complete (your own code
should go here)
*/
/**************************************************************************/
void loop(void)
{
/* Get a new sensor event */
sensors_event_t event;
sensors_event_t tslevent;
tsl.getEvent(&tslevent);

bmp.getEvent(&event);

/* Display the results (light is measured in lux) */
if (tslevent.light)
{
Serial.print(tslevent.light); Serial.println(" lux");
//Add Light reading to Xively datastream and ThingSpeak
datastreams[1].setFloat(tslevent.light);
ThingSpeak.setField(3,tslevent.light);
}
else
{
/* If event.light = 0 lux the sensor is probably saturated
and no reliable data could be generated! */
Serial.println("Sensor overload");
}

/* Display the results (barometric pressure is measure in hPa) */

if (event.pressure)
{
/* Display atmospheric pressue in hPa */
Serial.print("Pressure: ");
Serial.print(event.pressure);
Serial.println(" hPa");

/Add Event Pressure to Xively datastream and ThingSpeak

datastreams[2].setFloat(event.pressure);
ThingSpeak.setField(1,event.pressure);
/* Calculating altitude with reasonable accuracy requires pressure *
* sea level pressure for your position at the moment the data is *
* converted, as well as the ambient temperature in degress *
* celcius. If you don’t have these values, a ‘generic’ value of *
* 1013.25 hPa can be used (defined as SENSORS_PRESSURE_SEALEVELHPA *
* in sensors.h), but this isn’t ideal and will give variable *
* results from one day to the next. *
* *
* You can usually find the current SLP value by looking at weather *
* websites or from environmental information centers near any major *
* airport. *
* *
* For example, for Paris, France you can check the current mean *
* pressure and sea level at: http://bit.ly/16Au8ol */

/* First we get the current temperature from the BMP085 */
float temperature;
bmp.getTemperature(&temperature);

datastreams[0].setFloat(temperature);
ThingSpeak.setField(2,temperature);

Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" C");

/* Then convert the atmospheric pressure, SLP and temp to altitude */
/* Update this next line with the current SLP for better results */
float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA;
Serial.print("Altitude: ");
Serial.print(bmp.pressureToAltitude(seaLevelPressure,
event.pressure,
temperature));
Serial.println(" m");
Serial.println("");
}
else
{
Serial.println("Sensor error");
}

//Read anemometer
sensorValue = analogRead(sensorPin);
sensorVoltage = sensorValue * voltageConversionConstant; //Convert sensor value to actual voltage
Serial.print("Sensor Value: ");
Serial.println(sensorValue);

//Convert voltage value to wind speed using range of max and min voltages and wind speed for the anemometer
if (sensorVoltage <= voltageMin){
windSpeed = 0; //Check if voltage is below minimum value. If so, set wind speed to zero.
//Write to Xively and ThingSpeak
datastreams[3].setFloat(windSpeed);
ThingSpeak.setField(4,windSpeed);
}else {
//Write to Xively and ThingSpeak
windSpeed = (sensorVoltage – voltageMin)*windSpeedMax/(voltageMax – voltageMin); //For voltages above minimum value, use the linear relationship to calculate wind speed.
datastreams[3].setFloat(windSpeed);
ThingSpeak.setField(4,windSpeed);
}

//Add all streams to Xively
Serial.println("Uploading it to Xively");

Serial.println(xivelyKey);
Serial.println(feed);
int ret = xivelyclient.put(feed, xivelyKey);

Serial.print("xivelyclient.put returned ");
Serial.println(ret);

// Update Thingspeak
// Write the fields that you’ve set all at once.
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);

//Print voltage and windspeed to serial
Serial.print("Voltage: ");
Serial.print(sensorVoltage);
Serial.print("\t");
Serial.print("Wind speed: ");
Serial.println(windSpeed);
delay(3000);
}

[/pre]

Weather Station with Anemometer

I have been chipping away at building an Arduino based Weather Station.  Upgraded to a Arduino Mega as I was running out of memory on the Uno with all the libraries and sensors I was using.

Have code reading the Anemometer/BMP180/TSL2561 at this point. (more code sharing in upcoming post).

Using basic Ethernet Shield at the moment for proof of concept.  Will eventually go wireless.

Also have code writing to an Xively feed at: Weather Station

Will more than likely play with other sites like Thingspeak and or more Plot.ly.

image

image

image

Plotly via Python API

Spent some time working with the Plotly Python API.  Able to read my data logger files and upload to a plot with ease. Will need to comment code better I know…just started playing with it and wanted to share. Upload all environmental data and if the additional “Annotation” field exist add that to the plot as well.

More Info at: Plotly Python API

import plotly.plotly as py
from plotly.graph_objs import *
 
myname = 'plotlyid'
mykey = "plotlykey"
 
py.sign_in(myname,mykey)
 
x1 =[]
y1 =[]
y2 =[]
y3 =[]
MyAnnotation = []
 
f = open("LOGGER26.CSV",'r')
#f = open("smallset.csv",'r')
 
for lines in f:
	data = lines.split(',')
	x1.append(data[0])
	y1.append(data[1])
	y2.append(data[2])
	y3.append(data[3].strip())
 
	if len(data)==5:
		print data[4]
		Annotation = {'x':data[0],'y':data[1],'text':data[4] + data[0],'xref':'x','yref':'y','showarrow':True,'arrowhead':7,'bgcolor':'red'}
		MyAnnotation.append(Annotation)
 
# (2) Make dictionary linking x and y coordinate lists to 'x' and 'y' keys
#     (mandatory in plotly v.1.0.8 and up)
layout = Layout(
	title="MyEnvi",
 
	annotations=MyAnnotation,
 
    legend=Legend(
        x=100,
        y=1
    ),
    xaxis=XAxis(
    	domain=[0, 0.8],
        autorange=True,
        showgrid=False,
        zeroline=False,
        showline=True,
        autotick=True,
        ticks='',
        showticklabels=True
    ),
    yaxis=YAxis(
    	title="Light",
    	autorange=True,
        showgrid=False,
        zeroline=False,
        showline=True,
        autotick=True,
        ticks='',
        showticklabels=True
    ),
 
    yaxis2=YAxis(
        title='Barometric',
        showgrid=False,
        titlefont=Font(
            color='#ff7f0e'
        ),
        tickfont=Font(
            color='#ff7f0e'
        ),
        anchor='x',
        overlaying='y',
        side='right'
 
    ),
 
 	yaxis3=YAxis(
 		showgrid=False,
        title='Temp',
        titlefont=Font(
            color='#087804'
        ),
        tickfont=Font(
            color='#087804'
        ),
        anchor='free',
        overlaying='y',
        side='right',
        position = .9
    ),
 
)
trace1 = dict(x=x1,y=y1, name='Light')
trace2 = dict(x=x1,y=y2, name= 'Barometric',yaxis='y2')
trace3 = dict(x=x1,y=y3, name='Temp',yaxis='y3')
# (3) Make list of 1 trace, to be sent to Plotly
#     (mandatory in 1.0.8 and up)
data = [trace1,trace2,trace3]
 
fig = Figure(data=data,layout=layout)
 
plot_url = py.plot(fig, filename='MyEnvi')
f.close()

Short data file snippet:

2014-6-10 19:19:48,508,996.00,24.94
2014-6-10 19:19:49,508,995.95,24.94
2014-6-10 19:19:50,508,995.99,24.94
2014-6-10 19:19:51,508,995.95,24.92
2014-6-10 19:19:53,507,995.93,24.92,Migraine Severe
2014-6-10 19:19:54,507,995.99,24.94
2014-6-10 19:19:55,507,995.96,24.94
2014-6-10 19:19:56,507,996.00,24.92
2014-6-10 19:19:57,507,995.98,24.94
2014-6-10 19:19:58,507,995.97,24.92
2014-6-10 19:19:59,507,995.92,24.92
2014-6-10 19:20:0,507,995.92,24.92

Next steps: Create a way to add the annotation to the data file on the Arduino.

TSL 2591 on the Breadboard

image

image

Wanted to add a more comprehensive light monitor to my project.  Tha TSL 2591 does the trick.  Started running into memory issues with my Arduino Uno.  Will will add that discovery and resolution in an upcoming post.

Battery Powered Arduino

image

Adafruit to the rescue as I am pushing my project to be portable.

One lithium ion polymer battery and an Adafruit PowerBoost 500 Charger later I was able to get the project untethered from a power source.

Will figure out battery life and such in the near future.

Couple of interesting notes:  I already went the alkaline battery route – it worked to a point but the are too bulky for my applications and they had about a 4 hour life span.  The combination of Adafruits PowerBoost 500 Charger and the LiPo seems to be (so far) ideal.

The PowerBoost 500 does not work for this application (probably no application) if you connect it via the 2.1mm Power Jack.  The Power Jack needs at least 6V to operate properly.  I have not yet evaluated using the USB power input.  My initial finding showed that it did not work but I am a bit skeptical about my USB connection.  Does not really matter much as I know have the PowerBoost 500 connected right to GND and VIN which works great!

Further reading on the subject it appears the only way to power the Arduino from the PowerBoost 500 is the way I ended up doing it — straight to GND and VIN.  Makes sense as the USB optional output appears to be for charging other units, not powering a device.

Moved proto type off the breadboard

image

Used the Adafruit Data Logger prototype area.  A little sloppy but working.  Need to move the BMP180 next time as I realized the pins interfer with the Uno ATmega chip.

Next steps: figure out power and a simple enclosure.

Updated the Fritzing diagram to mostly match the project.  There does not appear to be an Adafruit Data Logging part for Fritzing yet and the Barometric sensor has not been updated to the BMP180 (but 85 close enough).

LightMeter_bb2

Fritzing! Document your Arduino Sketches

I just used Fritzing for the first time and was quite impressed.  Will help me a lot as I dissect what I built already and as I design new projects moving forward.  I have only scratched the surface using Fritzing application but it is great.

 

LightMeter_bb
My first Fritzing image!

Using Plot.ly with Adafruit Data Logging Shield

I have played with a few IOT type services for showing off data collected and or sent from Arduino (and other micro controller devices) and have settled on Plot.ly for now.

I have used ThingSpeak and Xively as well but found Plotly worked better for importing from the data logger disk than the others. Xively appear to be more “live update” oriented and not as well geared for file upload of large data sets.

 

Plot.ly Graph from Arduino Barometric and Light Project