electronicramblings.com

Arduino ATmega328

Arduino TVout DS18S20 DS18B20 with Graphing!!!

by on Mar.04, 2013, under Arduino, Arduino ATmega328, Electronic Projects

Another Great Visual Arduino Adventure.

Again this is a more of a reminder for me of the sketch and a working sketch for others to start from.

Now I searched Google for TVout graphing….and found this site: TVout with video overlay.

From this site was able to modify the sketch to be able to graph my DS18x20 sensor. Now that may not seem like a big thing, but I was impressed by being able to do this with a simple 8 bit processor.

The graph up dates about every second and shows the graphed data point in the top left corner. Picture not so good.(Iphone3 just can’t handle the flash that happens on my monitor)

March 03 2013 008

To x,y axis show up on the second rotation of the graph, have not figured out why at this time, but will repost once I do.

Till next time, thanks for your time.

Sketch:
/*
************
Video out with DS18x20 Sensors Graphing
************
electroinicramblings.com
***********
//http://nootropicdesign.com/projectlab/2011/03/20/text-and-graphics-overlay/
Above is where I got the graphing code.
//
Video Out with Maxim/Dallas DS18x20 temperature sensors displayed.
Pin 3 is for 1-wire
Video setup as discribed in Arduino.cc
This simple sketch is to show 1 temperatures on a tv or video monitor
Updates graph aprox. every 1 seconds.
Graph on TV!!!!
March 03, 2013

Important:
any delays you require should be TV.delay(), if not you will loose video.

*/
#include <TVout.h>
#include <font4x6.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into port 10 on the Arduino
#define ONE_WIRE_BUS 3
#define TEMPERATURE_PRECISION 12

TVout TV;

unsigned char x,y;
unsigned char originx = 5;
unsigned char originy = 80;
unsigned char plotx = originx;
unsigned char ploty = 40;
unsigned int n = 0;
int index = 0;

 

//Varibles for temperature Video Out
float T1;

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

//Device is a DS18S20 : 10-EC-A7-48-00-08-00-47
DeviceAddress tempa={0X10, 0XEC, 0XA7, 0X48, 0X00, 0X08, 0X00, 0X47}; //DS18S20 temperature senor MAC address

void gtemp()
{
sensors.requestTemperatures(); //Get temperature of all sensors
TV.delay(750);
T1=(sensors.getTempC(tempa));
}

void setup(void)
{
TV.fill(0);
drawGraph();
// randomSeed(analogRead(0));
sensors.begin();
// set the resolution to 12 bit
sensors.setResolution(tempa, TEMPERATURE_PRECISION); //Setup Dallas sensor resolution and address

//Video out setup
TV.begin(NTSC,136,96);
TV.select_font(font4x6);
}

void loop(void)
{
gtemp();

for(int x=6;x>=0;x–) {
if (x<6) {
TV.delay_frame(1);
}

for(byte y=87;y<96;y++) {
TV.draw_line(0, y, 5, y, 0);
TV.draw_line(128, y, 134, y, 0);
}
}

index++;
if (index > 45) {
index = 0;
}

 

TV.print(0,0,” C ARDUINO TEMPERATURE GRAPH”);
TV.print(0,0,T1);

if (plotx++ > 120) {
TV.fill(0);
drawGraph();
plotx = originx + 1;
return;
}
byte newploty = (1/T1)*1000;
newploty = constrain(newploty, 15, originy);

TV.draw_line(plotx-1, ploty, plotx, newploty, 1);
ploty = newploty;
}

void drawGraph()
{
TV.draw_line(originx, 15, originx, originy, 1);
TV.draw_line(originx, originy, 120, originy, 1);
for(byte y=originy;y>15;y -= 4) {
TV.set_pixel(originx-1, y, 1);
TV.set_pixel(originx-2, y, 1);
}
for(byte x=originx;x<120;x += 4) {
TV.set_pixel(x, originy+1, 1);
TV.set_pixel(x, originy+2, 1);
}
}

 

Leave a Comment more...

Arduino TVout with DS18S20 or DS18B20 Video

by on Mar.04, 2013, under Arduino, Arduino ATmega328, Electronic Projects

Arduino and using the TVout Library.

Dam this is a simple project, but good visual results. (Video attached)

Again this is a more of a reminder for me of the sketch and a working sketch for others to start from.

This is a short post just to show how simple it is t work with the TVout library and the Dallas 1-wire library.  The TVout is very well documented at Arduino.cc, and google will take you to even more places showing this feather. And if you are a youtuber….look there.

This is a video of the display showing four temperatures that update approx 5 seconds.

March 03 2013 004 (16megs in size)

Enjoy and hope it shows you more of what you can do with the Arduino system.

Till next time, thanks for your time.

Sketch:

/*
************
TVout with DS18x20 Sensors
************
electroinicramblings.com
***********
Video Out with Maxim/Dallas DS18x20 temperature sensors displayed.
Pin 3 is for 1-wire comms
Video setup as discribed in Arduino.cc
This simple sketch is to show 4 temperatures on a tv or video monitor
Updates aprox. every 7 seconds.
March 03, 2013

Important:
any delays you require should be TV.delay(), if not you will loose video.

*/
#include <TVout.h>
//#include <video_gen.h>
#include <font4x6.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into port 10 on the Arduino
#define ONE_WIRE_BUS 3
#define TEMPERATURE_PRECISION 12

TVout TV;

//Varibles for temperature Video Out
float T1;
float T2;
float T3;
float T4;

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

//Device is a DS18S20 : 10-EC-A7-48-00-08-00-47
DeviceAddress tempa={0X10, 0XEC, 0XA7, 0X48, 0X00, 0X08, 0X00, 0X47}; //DS18S20 temperature senor MAC address
//Device is a DS18S20 : 10-22-E1-48-00-08-00-BE
DeviceAddress tempb={0X10, 0X22, 0XE1, 0X48, 0X00, 0X08, 0X00, 0XBE}; //DS18S20 temperature senor MAC address
//Device is a DS18S20 : 10-21-D8-48-00-08-00-90
DeviceAddress tempc={0X10, 0X21, 0XD8, 0X48, 0X00, 0X08, 0X00, 0X90}; //DS18S20 temperature senor MAC address
//Device is a DS18S20 : 10-7F-E2-48-00-08-00-94
DeviceAddress tempd={0X10, 0X7F, 0XE2, 0X48, 0X00, 0X08, 0X00, 0X94}; //DS18S20 temperature senor MAC address

void gtemp()
{
sensors.requestTemperatures(); //Get temperature of all sensors
TV.delay(2000);
T1=(sensors.getTempC(tempa));
T2=(sensors.getTempC(tempb));
T3=(sensors.getTempC(tempc));
T4=(sensors.getTempC(tempd));
}

void setup(void)
{

sensors.begin();
// set the resolution to 12 bit
sensors.setResolution(tempa, TEMPERATURE_PRECISION); //Setup Dallas sensor resolution and address
sensors.setResolution(tempb, TEMPERATURE_PRECISION); //Setup Dallas sensor resolution and address
sensors.setResolution(tempc, TEMPERATURE_PRECISION); //Setup Dallas sensor resolution and address
sensors.setResolution(tempd, TEMPERATURE_PRECISION); //Setup Dallas sensor resolution and address
//Video out setup
TV.begin(NTSC,120,96);
TV.select_font(font4x6);
//Video start screen
TV.println(“”);
TV.println(“”);
TV.println(“”);
TV.println(“Arduino DS18x20 and Video Out”);
TV.println(“”);
TV.println(” DS18x20 and Video Out Demo”);
TV.println(“”);
TV.println(” March 2013″);
TV.delay(5000);
}

void loop(void)
{
gtemp();
TV.clear_screen();
TV.println(“Arduino Temperatures”);
TV.println(” DS18x20 Sensors”);
TV.println(“”);
TV.print(“Temp Deg C: “);
TV.println(T1);
TV.println(“”);
TV.print(“Temp Deg C: “);
TV.println(T2);
TV.println(“”);
TV.print(“Temp Deg C: “);
TV.println(T3);
TV.println(“”);
TV.print(“Temp Deg C: “);
TV.println(T4);
TV.println(“”);
TV.delay(5000);
}

 

Leave a Comment more...

Arduino: A Sad Day….I could NOT figure out how to make my Dallas Weather Station V1.0 work!!!

by on Feb.17, 2013, under Arduino, Arduino ATmega328, Electronic Projects

Morning All (below is in someway or another( code, circuits) from someone else hard work!!! I just built on it for my needs)

Again this is a more of a reminder for me of the sketch and a working sketch for others to start from.

I have been working with more 1-wire devices. I had built a humidity,  barometer,and rain gauge with temperature module about 11 years ago that used 1-wire interface.  Also have a couple Dallas 1-Wire Ver 1.0 Weather Stations.  I got the home made board I built to work, then was able to talk to the wind speed part of Dallas 1-Wire Weather Station to work.  But, alas I could not get the wind direction working properly.

A little Dallas Weather Station history:

The Dallas 1-Wire Weather Station is a demo unit that is functional.  Dallas Semiconductor made to show case there 1-Wire devices. (Dallas is no more, were bought out by Maxim) This unit would allow you to get temperature (DS18S20), Windspeed (DS2423), and Wind Direction (DS2407 and 8 x DS2401). (Here is a great explanation of the 1 Wire Weather Station Version 1.0.)

WSDV10

 

Above is a diagram of the the weather station’s electronics.

DS2407 is a to ground switch. (Can be used to run a relay or other circuits that need to turn on/off like a LED.)

-in this case allow the wind direction circuit to be turned on/off as needed.(Save power and confusion when talking to the other 1-wire chips.)

DS2401 are serial number chip, do nothing but have a serial number. (Can be used as a PCB identification serial number.)

-in this case it would be active if these conditions are met: DS2407 switch is turned on, the magnet is over its reed switch. The chip then would respond to a request. But wait, you could have two of the DS2401 active at one time. The magnet is powerful enough to activate two of the reed switch. Which is a good thing, as it would allow for a total of 16 wind direction instead of just 8.   With the PC software this all worked fine.

DS2423 is a 2 x counter. (Can be used to count things…..)

-has one reed switch that as the wind blows spins two magnets over it to create pulse it can store for you to read. Some simple math and you get wind speed.

DS1820 is a temperature sensor. (Man more information about this sensor then you can ever read when it comes to the Arduino system. Go search google and be educated)

-Well, you read it and get a temperature…again so much on the net about it, not going into it.

Now if you were to purchase a 1-Wire weather station you would go to AAG.   The version they sell now does not use the DS2407 and DS2401 combination to get wind direction. But use a Atmega8 to do the work and give the readings back in 1-wire format. Not to much on how it works on there site. Hope it comes with good documentation.

There is also Version 2.0  and 3.0 out there, that also does not use the DS2407 and DS2401 combination. it used a DS2450 Quad A/D chip. Pretty good idea and easier to get a direction still using reed switches(Ver 2.0) or Hall-effect sensors(Ver 3.0). Code for one of these can be found here: Paul East

So here is what I need to do and fail at:( Hear my plea: If any one has got this to work, please share!!! Thanks in advance.)

Close the switch on the DS2407 so it would allow the DS2401’s to be active.  Read the DS2401’s that are active. Then by knowing which one or two are active give a wind direction.

I got the DS2407 part to work, but have not been able to come up with a way to know which of the DS2401’s are active with out doing a whole buss search. Which in a real world conditions, takes way to long to work properly.

I know the address of the DS2401’s and would just like to be able to do a direct read/verify if there are there. But have had no luck doing so.  So for now the Dallas weather station will go back into storage……or modify the one of the boards I have to use the DS2450 method of wind directions. If I do this I will go a post of it.

The Home Made board for the Rain, RH%, Temperature and Barometric reading.

The interesting things I found out as I started working with old board is some of the chips have built in temperature sensors(DS2438). This would be used for temperature compensation of the voltage readings.(With the Arduino Uno, not enough room in memory code to start doing things like that.)

The Barometric circuit is like the one found on this pages: David Bray

The RH% circuit looks like this:

RH

 

The Rain circuit is very simple, used a DS2423 with a rain gauge bucket that has a reed switch on it to close a switch every time it tips. Also added in a DS18S20 temperature sensor. With all this on one board it was easy to wire up and talk to it.

Built this 11 years ago, so no schematic or PCB layout at this time. Might rebuild the board to fit in a known case size. right now the board is huge and not easily cased.

Below is the sketch and a view of the serial output.  I hope you find something useful here and can build from what you see. For now my Weather station will be on hold. But should be able to get the Baro and RH% with Rain gauge out on Cosm.com very soon.

Till next time, thanks for your time.

The Libraries:

Here is where I found the Arduino library for the DS2423, DS2438. Library

I modified the Libraries to work with Arduino Beta 1.0.3 and added in my baro stuff, they can be found here: Library Modified

 

 

Example what what you would see when running:

___________________________________________
26.24.61.33.00.00.00.17.Barometer: 23.56C 1.37v 97.45 kPa
26.B7.44.33.00.00.00.D5.Humidity: 22.75C 1.87v 34.29 %RH

DS1820 Temperature(HMB): 23.81
DS1820 Temperature(WS): 19.54
WindSpeed(kmh): 3
Counter A: 235
Counter B: 241

Time between counter readings: 3551
Wind Direction:
___________________________________________
___________________________________________
26.24.61.33.00.00.00.17.Barometer: 23.53C 1.37v 97.45 kPa
26.B7.44.33.00.00.00.D5.Humidity: 22.78C 1.89v 34.61 %RH

DS1820 Temperature(HMB): 23.81
DS1820 Temperature(WS): 19.54
WindSpeed(kmh): 6
Counter A: 241
Counter B: 251

Time between counter readings: 3552
Wind Direction:
___________________________________________
___________________________________________
26.24.61.33.00.00.00.17.Barometer: 23.66C 1.37v 97.45 kPa
26.B7.44.33.00.00.00.D5.Humidity: 22.87C 1.88v 34.29 %RH

DS1820 Temperature(HMB): 23.81
DS1820 Temperature(WS): 19.56
WindSpeed(kmh): 21
Counter A: 252
Counter B: 29

Time between counter readings: 3550
Wind Direction:
___________________________________________

 

Arduino Uno type board used: 

The Sketch:(9,558 of 30,720)(A lot of fluff  in the sketch below from when I was trying different ideas for wind direction)

/*
Read my 1-wire board (Baro,RH%,Rain,Temperature)and read Dallas weather Station V1.0
Feb 10, 2013

Not very clean but get the job done.
electronicramblings.com
*/
#include <OneWire.h>
#include <DS2438.h>
#include <DS2423.h>
#include <DallasTemperature.h>
#define TEMPERATURE_PRECISION 12

//Varibles
float baro;
float temp1;
float rh;
float temp2;
int rain;
int windsp;
int windP;
int windD;
int windR;
int WDR;
int rainV;

//Variables for wind speed
long time;
int timeDifference;
int WindCount = 0;
int WindCounter1 = 0;
int WindCounter2 = 0;
int WindDelayMilliSeconds = 0;
int RevsPerSecx100 = 0;
//int windMILES_PER_HOUR = 0;
//int windMETER_PER_SECOND = 0;
int windKMS_PER_HOUR = 0;
int windRaw =0;
//int windKNOTS = 0;
//#define METER_PER_SECOND 1.096;
#define KMS_PER_HOUR 3.9477;
//#define MILES_PER_HOUR 2.453;
//#define KNOTS 2.130;

//Wind Direction
int DS01A=0;
int DS02A=0;
int DS03A=0;
int DS04A=0;
int DS05A=0;
int DS06A=0;
int DS07A=0;
int DS08A=0;

 

//Variables for reading and data storage
byte i;
byte present = 1;
byte data[12];
byte addr[8];

OneWire oneWire(3);
//Home made Board(Baro, RH%,Rain,Temperature)
//DS18S20 10 51 EF 48 0 8 0 DD Temperature
//DS2438 26 24 61 33 0 0 0 17 PSI
//DS2438 26 B7 44 33 0 0 0 D5 RH%
//DS2423 1D 50 B5 0 0 0 0 70 RAIN
/*
Weather Station:
DS18S/B20 10 55 9 26 0 0 0 B4 Temperature
DS2423 1D 96 C8 0 0 0 0 DC Wind speed (Will need math)
DS2407 12 69 C0 A 0 0 0 ED Switch with EEprom
DS2401(Serial number chips):
DS2401 01 CC D1 60 3 0 0 38
DS2401 01 BD D1 60 3 0 0 97
DS2401 01 B4 D1 60 3 0 0 1
DS2401 01 B7 D1 60 3 0 0 58
DS2401 01 C9 D1 60 3 0 0 D3
DS2401 01 C3 D1 60 3 0 0 1C
DS2401 01 C0 D1 60 3 0 0 45
DS2401 01 BA D1 60 3 0 0 12
*/
DeviceAddress hum1_addy ={ 0x26, 0x24, 0x61, 0x33, 0x00, 0x00, 0x00, 0x17 }; //PSI
DeviceAddress hum1_addya={ 0x26, 0xB7, 0x44, 0x33, 0x00, 0x00, 0x00, 0xD5 };//RH%
DeviceAddress counter = { 0x1D, 0x50, 0xB5, 0x00, 0x00, 0x00, 0x00, 0x70 };//RAIN
DeviceAddress windCounter = { 0x1D, 0x96, 0xC8, 0x00, 0x00, 0x00, 0x00, 0xDC };//Wind
DeviceAddress tempa={0X10, 0X55, 0X09, 0X26, 0X00, 0X00, 0X00, 0XB4}; //DS18S20 temperature senor MAC address
DeviceAddress tempb={0X10, 0X51, 0XEF, 0X48, 0X00, 0X08, 0X00, 0XDD}; //DS18S20 temperature senor MAC address

DeviceAddress Dswitch= { 0x12, 0x69, 0xC0, 0x0A, 0x00, 0x00, 0x00, 0xED };//Switch to control read of DS2401
DeviceAddress DS01 = { 0x01, 0xCC, 0xD1, 0x60, 0x03, 0x00, 0x00, 0x38 };// DS2401 01
DeviceAddress DS02 = { 0x01, 0xBD, 0xD1, 0x60, 0x03, 0x00, 0x00, 0x97 };// DS2401 02
DeviceAddress DS03 = { 0x01, 0xB4, 0xD1, 0x60, 0x03, 0x00, 0x00, 0x01 };// DS2401 03
DeviceAddress DS04 = { 0x01, 0xB7, 0xD1, 0x60, 0x03, 0x00, 0x00, 0x58 };// DS2401 04
DeviceAddress DS05 = { 0x01, 0xC9, 0xD1, 0x60, 0x03, 0x00, 0x00, 0xD3 };// DS2401 05
DeviceAddress DS06 = { 0x01, 0xC3, 0xD1, 0x60, 0x03, 0x00, 0x00, 0x1C };// DS2401 06
DeviceAddress DS07 = { 0x01, 0xC0, 0xD1, 0x60, 0x03, 0x00, 0x00, 0x45 };// DS2401 07
DeviceAddress DS08 = { 0x01, 0xBA, 0xD1, 0x60, 0x03, 0x00, 0x00, 0x12 };// DS2401 08

ds2438 hum1(&oneWire, hum1_addy); //barometric reading setup
ds2438 hum1a(&oneWire, hum1_addya); //humidity reading setup
ds2423 cntRain(&oneWire, counter); //rain reading setup
ds2423 wind(&oneWire, windCounter); //wind reading setup

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
//_______________________________________________________
void PIOON()//DS2407 turn on the switch
{
oneWire.reset(); //reset bus
oneWire.select(Dswitch); //select device previously discovered
oneWire.write(0x55); //write status command
oneWire.write(0x07); //select location 00:07 (2nd byte)
oneWire.write(0); //select location 00:07 (1st byte)
oneWire.write(0x1F); //write status data byte (turn PIO-A ON)
Serial.print (“VALUE=”); //read CRC16 of command, address and data and print it; we don’t care
for ( i = 0; i < 6; i++) {
data[i] = oneWire.read();
Serial.print(data[i], HEX);
Serial.print(” “);
}
oneWire.write(0xFF,1); //dummy byte FFh to transfer data from scratchpad to status memory, leave the bus HIGH
delay(2000); //leave the things as they are for 2 seconds

}
//_______________________________________________________

void PIOOFF()//DS2407 trun off the switch
{
oneWire.reset(); //reset bus
oneWire.select(Dswitch); //select device previously discovered
oneWire.write(0x55); //write status command
oneWire.write(0x07); //select location 00:07 (2nd byte)
oneWire.write(0); //select location 00:07 (1st byte)
oneWire.write(0x3F); //write status data byte (turn PIO-A OFF)
Serial.print (“VALUE=”); //read CRC16 of command, address and data and print it; we don’t care
for ( i = 0; i < 6; i++) {
data[i] = oneWire.read();
Serial.print(data[i], HEX);
Serial.print(” “);
}
oneWire.write(0xFF,1); //dummy byte FFh to transfer data from scratchpad to status memory, leave the bus HIGH
delay(2000); //leave the things as they are for 2 seconds

}
//_______________________________________________________
void rainR(){

rainV=((cntRain.readCounter(1))*.5);//my rain cups are .5mm per switch count
Serial.println();
Serial.print(“Rain total(mm)”);
Serial.print(rainV);
Serial.println();
}
//_______________________________________________________
void wSpeed()
{
WindCounter2 = (wind.readCounter(1)); //Get the current counter value
timeDifference = millis() – time; //Work out the time since the last count
time = millis(); //Reset the time count
RevsPerSecx100 = CalcRevolutionsPerSecondx100(WindCounter1, WindCounter2, timeDifference);
// windMILES_PER_HOUR = (RevsPerSecx100) * MILES_PER_HOUR;
// windMETER_PER_SECOND = (RevsPerSecx100) * METER_PER_SECOND;
windRaw = (RevsPerSecx100) * KMS_PER_HOUR;
windKMS_PER_HOUR =windRaw/100;
// windKNOTS = (RevsPerSecx100) * KNOTS;
Serial.print(“WindSpeed(kmh): “);
Serial.print(windKMS_PER_HOUR);
Serial.println();
Serial.print(“Counter A: “);
Serial.println(WindCounter1);
Serial.print(“Counter B: “);
Serial.println(WindCounter2);
Serial.println();
Serial.print(“Time between counter readings: “);
Serial.print(timeDifference);
Serial.println();
WindCounter1 = (wind.readCounter(1)); //Take the counter to compare next time
}
/////////////////////////////////////////////////////////////////////////////////////////////
//Returns the revolutions per second x 100 to allow for decimal places to be worked out
/////////////////////////////////////////////////////////////////////////////////////////////
int CalcRevolutionsPerSecondx100(int WindCounter1, int WindCounter2, int timeDifference)
{
if(WindCounter2 < WindCounter1) //If the counter has gone past 0…
{
WindCounter2 = WindCounter2 + 255; // Add 255 for this comparision (it’ll sort itself out for next time)
}
//We must /2 in the next formula as there are 2 counts per revolution.
//Multiplying by 100 so I can pass back an int and then work the decimal places out in the loop.
RevsPerSecx100 = (((WindCounter2 – WindCounter1) * 100) / 2) / (timeDifference / 1000);
// RevsPerSecx100 = ((WindCounter2 – WindCounter1) / 2) / (timeDifference / 1000);
return(RevsPerSecx100);
}

//_______________________________________________________
void wdirection()
{
//*********************
//HELP!!!!!
//**********************
}
//_______________________________________________________
//_______________________________________________________
void setup(void)
{
Serial.begin(9600);
//Wind speed stuff
WindCounter1 = (wind.readCounter(1)); //Set the wind counter variables…
WindCounter2 = WindCounter1; // to the same amount and…
time = millis(); // store the current millis.
//Homemade 1-wire board stuff
printAddress(hum1_addy);
printAddress(hum1_addya);
printAddress(counter);
Serial.println();
Serial.print(“Initial config: “);
Serial.println(hum1.readSetup(), BIN);
Serial.println(hum1a.readSetup(), BIN);
// Serial.println(cntRain.readSetup(),BIN);
hum1.writeSetup(0x00);
Serial.print(“New config: “);
Serial.println(hum1.readSetup(), BIN);
Serial.println(hum1a.readSetup(), BIN);
// Serial.println(cntRain.readSetup(),BIN);
delay(1000);
}
//_______________________________________________________
void loop(void)
{
sensors.requestTemperatures(); //Get temperature of all sensors
delay(700);
printAddress(hum1_addy);
Serial.print(“Barometer: “);
Serial.print(hum1.readTempC());
Serial.print(“C “);
Serial.print(hum1.readVolt());
Serial.print(“v “);
Serial.print(hum1.readKpa());
Serial.println(” kPa”);
printAddress(hum1_addya);
Serial.print(“Humidity: “);
Serial.print(hum1a.readTempC());
Serial.print(“C “);
Serial.print(hum1a.readVolt());
Serial.print(“v “);
Serial.print(hum1a.readHum());
Serial.println(” %RH”);
Serial.println();
Serial.print(“DS1820 Temperature(HMB): “);
Serial.print(sensors.getTempC(tempb));
Serial.println();
Serial.print(“DS1820 Temperature(WS): “);
Serial.print(sensors.getTempC(tempa));
Serial.println();

wSpeed();

Serial.print(“Wind Direction:”);
wdirection();
Serial.println();

Serial.print(“___________________________________________”);
Serial.println();
Serial.print(“___________________________________________”);
Serial.println();
}

// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
for (uint8_t i = 0; i < 8; i++)
{
if (deviceAddress[i] < 16) Serial.print(“0”);
Serial.print(deviceAddress[i], HEX);
Serial.print(“.”);
}
delay(1000);
}

 

2 Comments more...

Arduino WiShield WiServer Cosm Pachube DS18S20 Sketch

by on Jan.30, 2013, under Arduino, Arduino ATmega328, Electronic Projects, WiShield

This sketch took couple of days to get to where I was happy with the data being pushed to the Cosm site.

In this sketch I have succeeded on having the unit push temperature data to the Cosm.com site. 

There is some interesting information on doing this all over the web, but the best place I found for how to get float data to be pushed was from a free chapter of this book: Building Internet of things with the Arduino.

http://www.buildinginternetofthings.com/

Have a look, they have done a great job on this book, one I would recommend you buy if you want to get your Arduino on the web.

Have a look at the Sketch and see if there anything that will help on your next project.

Again this is a more of a reminder for me of the sketch and a working sketch for others to start from.

A picture of the data looks like on the COSM site….

cosm

Hardwared use:

Arduino 328 version

AysncLabs V1.0 Wishield

Dallas/Maxium DS18S20 1-wire temperature sensors.

Software:

Arduino Beta 1.1

Latest Dallas  and Wiserver Libraries.

Till next time, thanks for your time.

Sketch:

WiServer_Cosm_DS18S20_Jan_2013_Ver1_3

 

 

/*
* electronicramblings.com
*
* A sketch that uses WiServer to PUT (via POST) to Cosm
* Works with my WiShield ver 1.0 and Arduino 328.
* Very happy on its ability to push data.
* Cosm is setup for 4 variables.
* Have setup two DS18S20 sensors
* Did this to show a four graphs on Cosm.
* Good start to seeing how Cosm works.
* Sends out data every 30 seconds
* Jan 30, 2013
*/

#include <WiServer.h>
#include <string.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
#define ONE_WIRE_BUS 7
#define TEMPERATURE_PRECISION 12

//non WiShield defines
char buf1[16];
char buf2[16];
char buf3[16];
char buf4[16];
char buf5[32];
//Variables
float aB;
float cD;
float eF;
float gH;
//My four DS18S20 sensors address:
//Device is a DS18S20 : 10-EC-A7-48-00-08-00-47
DeviceAddress tempa={0X10, 0XEC, 0XA7, 0X48, 0X00, 0X08, 0X00, 0X47}; //DS18S20 temperature senor MAC address
//Device is a DS18S20 : 10-22-E1-48-00-08-00-BE
DeviceAddress tempb={0X10, 0X22, 0XE1, 0X48, 0X00, 0X08, 0X00, 0XBE}; //DS18S20 temperature senor MAC address
//Device is a DS18S20 : 10-21-D8-48-00-08-00-90
DeviceAddress tempc={0X10, 0X21, 0XD8, 0X48, 0X00, 0X08, 0X00, 0X90}; //DS18S20 temperature senor MAC address
//Device is a DS18S20 : 10-7F-E2-48-00-08-00-94
DeviceAddress tempd={0X10, 0X7F, 0XE2, 0X48, 0X00, 0X08, 0X00, 0X94}; //DS18S20 temperature senor MAC address

OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.
//________________________________________________________________________
// Wireless configuration parameters —————————————-
unsigned char local_ip[] = {192,168,0,151}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,0,2}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {“dlink”}; // max 32 bytes

unsigned char security_type = 3; // 0 – open; 1 – WEP; 2 – WPA; 3 – WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {“1234567890″}; // max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
};

// setup the wireless mode
// infrastructure – connect to AP
// adhoc – connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len;
unsigned char security_passphrase_len;
//_________________________________________________________________
// End of wireless configuration parameters —————————————-

//body data function, provides data for the POST command in comma separated values (CSV)
//currently POSTs one value but more can be added by separating with commas (no spaces)
//Your program will not want to use the hardcoded values below, rather it would read the
//sensor(s) and build the data string shown below.
void feedData()
{
ftoa(buf1, aB, 2);
ftoa(buf2, cD, 2);
ftoa(buf3, eF, 2);
ftoa(buf4, gH, 2);
sprintf(buf5,”%s,%s,%s,%s”,buf1,buf2,buf3,buf4);
WiServer.print(buf5);
}
//__________________________________________________________________
void tempRead()
{
sensors.requestTemperatures(); //Get temperature of all sensors
delay(700);
aB=(sensors.getTempC(tempa));
cD=(sensors.getTempC(tempb));
eF=(sensors.getTempC(tempc));
gH=(sensors.getTempC(tempd));
}
//__________________________________________________________________
// IP Address for Pachube.com
uint8 ip[] = {64,94,18,122};
char hostName[] = “www.cosm.com\nX-PachubeApiKey: gWtWaEag5ytGWwKFsW7KxPyOp6qSAKwweGZhS1lCeUVSWT0g\nConnection: close”;
char url[] = “/api/feeds/100816.csv?_method=put”;

// A request that POSTS data to Pachube
POSTrequest postPachube(ip, 80, hostName, url, feedData);
void setup(void)
{
aB=0.0f;
cD=0.0f;
eF=0.0f;
gH=0.0f;
// Initialize WiServer (we’ll pass NULL for the page serving function since we don’t need to serve web pages)
WiServer.init(NULL);
postPachube.submit();
WiServer.server_task();
}
// Time (in millis) when the data should be retrieved
long updateTime = 0;
//________________________________________________________________________
void loop()
{
// Check if it’s time to get an update
if (millis() >= updateTime)
{
postPachube.submit();
// Get/Push another update 30 seconds from now
updateTime += 30000;
// cycle();
tempRead();
}
// Run WiServer
WiServer.server_task();
delay(10);
}
//________________________________________________________________________
//Convert double to char (due to currently sprintf in Arduino fails to do so)
char *ftoa(char *a, double f, int precision)
{
long p[] =
{0,10,100,1000,10000,100000,1000000,10000000,100000000};
char *ret = a;
long heiltal = (long)f;
itoa(heiltal, a, 10);
while (*a != ‘\0’) a++;
*a++ = ‘.’;
long desimal = abs((long)((f – heiltal) * p[precision]));
itoa(desimal, a, 10);
return ret;
}
//________________________________________________________________________

Leave a Comment more...

Arduino WiShield WiServer Cosm upload (Put, Push) Sketch

by on Jan.28, 2013, under Arduino, Arduino ATmega328, Electronic Projects, WiShield

Arduino 328 with WiShield V1.0 to Cosm (Pachube)

In this sketch I have succeeded on having the unit push data to the Cosm.com site. Which is pretty cool if you want to see your data without building a web page on your WiServer.

Again this is a more of a reminder for me of the sketch and a working sketch for others to start from.

After much reading many posts and blogs I was able to get this little gem of code working. I wanted to see numbers changing on the site so I setup the unit with four variables that will change at different rates to show activity on the graph that comes up in the Cosm.com site.

Hope this helps one to move forward on using the Arduino and WiShield.

WiServer_Cosm_Basic_Skectch

The Sketch:

/*electronicramblings.com
* A sketch that uses WiServer to PUT (via POST) to Cosm
* Works with my WiShield ver 1.0 and Arduino 328.
* Very happy on its ability to push data.
* Cosm is setup for 4 variables.
* Have setup four variables that will increase or decrease depending on the math
* Did this to show a fast four graphs on Cosm.
* Good start to seeing how Cosm works.
* Sends out data every 30 seconds
* Jan 28, 2013
*/

#include <WiServer.h>

#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2

//Variables
int aB;
int cD;
int eF;
int gH;

// Wireless configuration parameters
unsigned char local_ip[] = {192,168,0,151}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,0,2}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {“dlink”}; // max 32 bytes

unsigned char security_type = 3; // 0 – open; 1 – WEP; 2 – WPA; 3 – WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {“1234567890”}; // max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
};

// setup the wireless mode
// infrastructure – connect to AP
// adhoc – connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len;
unsigned char security_passphrase_len;
//_________________________________________________________________
// End of wireless configuration parameters

// Function that prints data from the server
void printData(char* data, int len) {

// Print the data returned by the server
// Note that the data is not null-terminated, may be broken up into smaller packets, and
// includes the HTTP header.
while (len– > 0) {
Serial.print(*(data++));
}
}

//body data function, provides data for the POST command in comma separated values (CSV)
//currently POSTs one value but more can be added by separating with commas (no spaces)
//Your program will not want to use the hardcoded values below, rather it would read the
//sensor(s) and build the data string shown below.
void feedData()
{
//e.g. a single value
//WiServer.print(“21”);
//e.g. two values
//WiServer.print(“10,20,30,40″);
char buf[16];
sprintf(buf,”%d,%d,%d,%d”, aB, cD, eF, gH);
WiServer.print(buf);
}

void cycle()
{
aB=(aB+8);
cD=(cD+5);
eF=(eF++);
gH=(gH-5);
if (aB>=200)
{
aB=1;
}
if (cD>=200)
{
cD=1;}
if (eF>=200)
{
eF=1;
}
if (gH<=5)
{
gH=200;
}
Serial.print(“”);
Serial.print(“AB: “);
Serial.println(aB);
Serial.print(“CD: “);
Serial.println(cD);
Serial.print(“EF: “);
Serial.println(eF);
Serial.print(“GH: “);
Serial.println(gH);
}

// IP Address for Pachube.com
uint8 ip[] = {64,94,18,122};
char hostName[] = “www.cosm.com\nX-PachubeApiKey: }YOURAPICODE]\nConnection: close”;
char url[] = “/api/feeds/9999.csv?_method=put”;

// A request that POSTS data to Pachube
POSTrequest postPachube(ip, 80, hostName, url, feedData);
void setup() {
aB=1;
cD=15;
eF=25;
gH=150;
// Initialize WiServer (we’ll pass NULL for the page serving function since we don’t need to serve web pages)
WiServer.init(NULL);

// Enable Serial output and ask WiServer to generate log messages (optional)
Serial.begin(9600);
WiServer.enableVerboseMode(true);

// Have the printData function called when data is returned by the server
postPachube.setReturnFunc(printData);
}
// Time (in millis) when the data should be retrieved
long updateTime = 0;

void loop(){

// Check if it’s time to get an update
if (millis() >= updateTime)
{
postPachube.submit();
// Get another update 30 seconds from now
updateTime += 30000;
Serial.print(millis());
cycle();
}

// Run WiServer
WiServer.server_task();
delay(10);
}

1 Comment more...

Arduino WiShield WiServer DS18S20 Alarm Control Back Ground Routine

by on Jan.27, 2013, under Arduino, Arduino ATmega328, Electronic Projects, WiShield

 

Well here we go again:
Arduino with a Async Labs WiServer 1.0 WiShield and two DS18S20 Dallas Temperature Senors and control …. count them…. 5 LEDs.

Again this is a more of a reminder for me of the sketch and a working sketch for others to start from.

Good Stuff  to report!!!!

Now the system can server a simple web page, read temperature from two 1-wire sensors (Dallas one wire DS18x20 Sensors), control three LEDs, and best part is it will control two LEDs (outputs) off the temperature in a background routine.

Now the sketch is ready to something useful. Don’t know what, but something.

 

Pic of the Web Page:

 

Jan 27 2013 003

 

Jan 27 2013 004

 

Till next time, thanks for your time.

 

 

The Sketch:(21,288 or 30,720 bytes)

Wiserver_Multi_LED_Jan2013_WAP_V3Alarm

/*

*** WiServer using WiShield***
elelctronicramblings.com
I work with the sketch that kim messed with for the Web page LED control.
Added in my DS18x20 code and added in Alarms for temperature.
Add in Routine to do alarm without a web page call.
Jan 27,2013
***
Was compiled on Beta 1.0.1
Latest AysncLab WiServer Library for Jan 2013
Latest Dallas one-wire Library for Jan 2013
***
Pins used
1,3 for alarm LEDS
4,5,6 for control LEDS
7 for Onewire(DS18S20)
13(SCK),12(SD0),11(SDI),10(SS_N),9(LED WIFI),8(INTX),2(who knows) for WiShield
***
It works as a 3 LED control and Read Temperture from 2 DS18S20 senosors.
Alarms with LED control for the alarm for both temperatures.
Set able Alarm levels for each alarm from the web page.
Was well as give the up time of the Arduino system.
*************************
IMPORTANT
It can get temperature with a web page refresh or embedded link in the page has been used.
Temperature updates for alarms every xx seconds.
Alarms activate/deactivate when the temperature has been read.
*************************
All fits just on a iphone 3S screen.
***
Router needs to have this setup:
WAP needs to be TPIK and PSK
WAP2 needs to be AES and PSK
***
*/
#include <WiServer.h>
#include <string.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2

#define alarmPin2 1 //not a good one to use(specially if you put a relay there to control something)…but ran out of pins
#define alarmPin3 3
#define ledPin1 4
#define ledPin2 5
#define ledPin3 6
#define ONE_WIRE_BUS 7
#define TEMPERATURE_PRECISION 12

int tempAlarm =25;
int tempAlarma =25;
long previousMillis = 0; // will store last time Temperature and Alarm routine was updated
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 5000; // interval at which to get temperature and run Alarm routine(milliseconds)

//Device is a DS18S20 : 10-EC-A7-48-00-08-00-47
DeviceAddress tempa={0X10, 0XEC, 0XA7, 0X48, 0X00, 0X08, 0X00, 0X47}; //DS18S20 temperature senor MAC address
//Device is a DS18S20 : 10-22-E1-48-00-08-00-BE
DeviceAddress tempb={0X10, 0X22, 0XE1, 0X48, 0X00, 0X08, 0X00, 0XBE}; //DS18S20 temperature senor MAC address

OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.
//________________________________________________________________________
// Wireless configuration parameters —————————————-
unsigned char local_ip[] = {192,168,0,151}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,0,1}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {“dlink”}; // max 32 bytes

unsigned char security_type = 2; // 0 – open; 1 – WEP; 2 – WPA; 3 – WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {“1234567890”}; // max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
};

// setup the wireless mode
// infrastructure – connect to AP
// adhoc – connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len;
unsigned char security_passphrase_len;
//_________________________________________________________________
// End of wireless configuration parameters —————————————-

boolean states[3]; //holds led states
char stateCounter; //used as a temporary variable
char tmpStrCat[64]; //used in processing the web page
char stateBuff[4]; //used in text processing around boolToString()
char numAsCharBuff[2];
char ledChange;
//__________________________________________________________________
void tempRead()
{
sensors.requestTemperatures(); //Get temperature of all sensors
}
//__________________________________________________________________
void alarmLoop()
{
if ((sensors.getTempC(tempa))>=(tempAlarm)) // easily changed to a less then value, say for turning on a heater
{
digitalWrite(alarmPin2, HIGH);
}
else
{
digitalWrite(alarmPin2, LOW);
}

if ((sensors.getTempC(tempb))>=(tempAlarma))
{
digitalWrite(alarmPin3, HIGH);
}
else
{
digitalWrite(alarmPin3, LOW);
}
}
//__________________________________________________________________
void boolToString (boolean test, char returnBuffer[4])
{
returnBuffer[0] = ‘\0’;
if (test)
{
strcat(returnBuffer, “On”);
}
else
{
strcat(returnBuffer, “Off”);
}
}
//__________________________________________________________________
void writeStates()
{
//set led states
digitalWrite(ledPin1, states[0]);
digitalWrite(ledPin2, states[1]);
digitalWrite(ledPin3, states[2]);
}
//__________________________________________________________________
// This is our page serving function that generates web pages
boolean sendPage(char* URL) {
writeStates();
//check whether we need to change the led state
if (URL[1] == ‘?’ && URL[2] == ‘L’ && URL[3] == ‘E’ && URL[4] == ‘D’) //url has a leading /
{
ledChange = (int)(URL[5] – 48); //get the led to change.

for (stateCounter = 0 ; stateCounter < 3; stateCounter++)
{
if (ledChange == stateCounter)
{
states[stateCounter] = !states[stateCounter];

}
}

//after having change state, return the user to the index page.
WiServer.print(“<HTML><HEAD><meta http-equiv=’REFRESH’ content=’0;url=/’></HEAD></HTML>”);
return true;
}

;
//Alarm set point 0
if (URL[1] == ‘A’) //add 1 to the alarm set point
{
tempAlarm = tempAlarm++;
//after having change state, return the user to the index page.
WiServer.print(“<HTML><HEAD><meta http-equiv=’REFRESH’ content=’0;url=/’></HEAD></HTML>”);
return true;
}

if (URL[1] == ‘B’) //minus 1 to the alarm set point
{ tempAlarm = tempAlarm–;
//after having change state, return the user to the index page.
WiServer.print(“<HTML><HEAD><meta http-equiv=’REFRESH’ content=’0;url=/’></HEAD></HTML>”);
return true;
}
//Alarm setpoint 1
if (URL[1] == ‘C’) //add 1 to the alarm set point
{
tempAlarma = tempAlarma++;
//after having change state, return the user to the index page.
WiServer.print(“<HTML><HEAD><meta http-equiv=’REFRESH’ content=’0;url=/’></HEAD></HTML>”);
return true;
}

if (URL[1] == ‘D’) //minus 1 to the alarm set point
{ tempAlarma = tempAlarma–;
//after having change state, return the user to the index page.
WiServer.print(“<HTML><HEAD><meta http-equiv=’REFRESH’ content=’0;url=/’></HEAD></HTML>”);
return true;
}

if (strcmp(URL, “/”) == false) //why is this not true, just refresh the page
{
WiServer.print(“<html><body><meta name=\”viewport\” content=\”width=device-width, user-scalable=no\” />”);
WiServer.print(“<b><center>Arduino WiShield Web Server</center></b><hr/>”);
WiServer.print(“<b><center>LED Control<center>\n<center></b>”);
for (stateCounter = 0; stateCounter < 3; stateCounter++) //for each led
{
numAsCharBuff[0] = (char)(stateCounter + 49); //as this is displayed use 1 – 3 rather than 0 – 2
numAsCharBuff[1] = ‘\0’; //strcat expects a string (array of chars) rather than a single character.
//This string is a character plus string terminator.

tmpStrCat[0] = ‘\0’; //initialise string
strcat(tmpStrCat, “<a href=?LED”); //start the string
tmpStrCat[12] = (char)(stateCounter + 48); //add the led number
tmpStrCat[13] = ‘\0’; //terminate the string properly for later.

strcat(tmpStrCat, “>Led “);
strcat(tmpStrCat, numAsCharBuff);
strcat(tmpStrCat, “: “);

boolToString(states[stateCounter], stateBuff);
strcat(tmpStrCat, stateBuff);
strcat(tmpStrCat, “</a>”); //we now have something in the range of <a href=?LED0>Led 0: Off</a>
WiServer.print(” “);
WiServer.print(tmpStrCat);
}
sensors.requestTemperatures(); //Get temperature of all sensors
WiServer.print(“<BR><hr/>”);
WiServer.print(“Arduino has been running: “);
WiServer.printTime(millis()); //prints millis timer in hours:minutes:seconds format
WiServer.print(“<hr/>”);
WiServer.print(“<b>Temperature</b>”);
WiServer.print(“<BR>”);
WiServer.print(“Sensor 0 (Deg C): “);
WiServer.print(sensors.getTempC(tempa)); //print temperature from DS18x20 sensor
WiServer.print(“<BR>”);
WiServer.print(“Alarm Set Point: “);
WiServer.print(tempAlarm);
WiServer.print(“<button><a href=\”/A\”> UP </a></button>”);
WiServer.print(“<button><a href=\”/B\”>DOWN</a></button>”);
WiServer.print(“<BR>”);
WiServer.print(“Sensor 1 (Deg C): “);
WiServer.print(sensors.getTempC(tempb));//print temperature from DS18x20 sensor
WiServer.print(“<BR>”);
WiServer.print(“Alarm Set Point: “);
WiServer.print(tempAlarma);
WiServer.print(“<button><a href=\”/C\”> UP </a></button>”);
WiServer.print(“<button><a href=\”/D\”>DOWN</a></button>”);
WiServer.print(“<BR><hr/>”);
WiServer.print(“<b>Alarms</b>”);
WiServer.print(“<BR>”);
if ((sensors.getTempC(tempa))>=(tempAlarm)) // easily changed to a less then value, say for turning on a heater
{
WiServer.print(“****Sensor 0 HIGH TEMPERATURE****”);
digitalWrite(alarmPin2, HIGH);
}
else
{
digitalWrite(alarmPin2, LOW);
WiServer.print(“Sensor 0 None”);
}

if ((sensors.getTempC(tempb))>=(tempAlarma))
{
WiServer.print(“<BR>”);
WiServer.print(“****Sensor 1 HIGH TEMPERATURE****”);
digitalWrite(alarmPin3, HIGH);
}
else
{
digitalWrite(alarmPin3, LOW);
WiServer.print(“<BR>”);
WiServer.print(“Sensor 1 None”);
}

WiServer.print(“<hr/>”);
WiServer.print(“</body></html>”);
return true;
}
}
//__________________________________________________________________
void setup() {
// Initialize WiServer and have it use the sendMyPage function to serve pages
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(alarmPin2, OUTPUT);
pinMode(alarmPin3, OUTPUT);

WiServer.init(sendPage);
states[0] = false;
states[1] = false;
states[2] = false;
sensors.setResolution(tempa, TEMPERATURE_PRECISION); //Setup Dallas sensor resolution and address
sensors.setResolution(tempb, TEMPERATURE_PRECISION); //Setup Dallas sensor resolution and address
}
//__________________________________________________________________
void loop()
{
// Run WiServer
WiServer.server_task();
// here is where you’d put code that needs to be running all the time.
// check to see if it’s time to get temperature and run alarm routine; that is, if the
// difference between the current time and last time you got temperature and run the alarm routine
// is bigger than the interval at which you want to
// get temperature and alarm routine.
unsigned long currentMillis = millis();
if(currentMillis – previousMillis > interval)
{
// save the last time you got the temperature and alarm routine.
previousMillis = currentMillis;
tempRead();
alarmLoop();
}
}
//__________________________________________________________________
//That all Folks!!!!

 

Leave a Comment more...

Arduino WiShield WiServer DS18S20 Temperature Alarms with LED control.

by on Jan.26, 2013, under Arduino, Arduino ATmega328, Electronic Projects, WiShield

Well here we go again:

Arduino with a Async Labs WiServer 1.0 Shield and two DS18S20 Dallas Temperature Senors and count them….Control 5 LEDS.

Again this is a more of a reminder for me of the sketch and a working sketch for others to start from.

To start off this is a not a sketch to run your BBQ or home AC, but one to start with to get a idea of what can be done.

****Important****

This sketch does not run the alarm or temperature capture in the main loop, but only when a web page is refreshed or a embedded link is used. That will come in the next adventure!!!!

This is a short description of what this sketch does:

Severs up a web page that has three LED control links, Time the Arduino has been running, Temperature read from two DS18S20 Temperature sensors, Alarm setpoints(That are can be changed through control Links), and show if the set points have been reached.

Pretty simple, but took me sometime to get all of it working together.

Here is a picture of the web pages on a iphone 3s.

Jan 26 2013 004

A picture of my setup:

Jan 26 2013 003

Till next time, thanks for your time.

 

Below is the sketch: Wiserver_Multi_LED_Jan2013_WAP_V2Alarm

/*
elelctronicramblings.com
*** A simple sketch that uses WiServer to serve a web page !! that kim messed with.***
I work with the sketch that kim messed with and added in my DS18x20 code and added in Alarms for temperature.
Jan 26,2013
***
Was compiled on Beta 1.0.1
Latest AysncLab WiServer Library
Latest Dallas one-wire Library
***
Pins used
1,3 for alarm LEDS
4,5,6 for control LEDS
7 for Onewire(DS18S20)
13(SCK),12(SD0),11(SDI),10(SS_N),9(LED WIFI),8(INTX),2(who knows) for WiShield
***
It works as a 3 LED control and Read Temperture from 2 DS18S20 senosors.
Alarms with LED control for the alarm for both temperatures.
Set able Alarm levels for each alarm from the web page.
Was well as give the up time of the Arduino system.
*************************
IMPORTANT
Nothing happens without a web page refresh or embedded link in the page has been used.
Temperature only updates when the above condition is met.
Alarms will only activate/deactivate when the above condition is met.
*************************
All fits just on a iphone 3S screen.
***
Router needs to have this setup:
WAP needs to be TPIK and PSK
WAP2 needs to be AES and PSK
***
*/
#include <WiServer.h>
#include <string.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2

#define alarmPin2 1 //not a good one to use(specially if you put a relay there to control something)…but ran out of pins
#define alarmPin3 3
#define ledPin1 4
#define ledPin2 5
#define ledPin3 6
#define ONE_WIRE_BUS 7
#define TEMPERATURE_PRECISION 12

int tempAlarm =25;
int tempAlarma =25;

 

//Device is a DS18S20 : 10-EC-A7-48-00-08-00-47
DeviceAddress tempa={0X10, 0XEC, 0XA7, 0X48, 0X00, 0X08, 0X00, 0X47}; //DS18S20 temperature senor MAC address
//Device is a DS18S20 : 10-22-E1-48-00-08-00-BE
DeviceAddress tempb={0X10, 0X22, 0XE1, 0X48, 0X00, 0X08, 0X00, 0XBE}; //DS18S20 temperature senor MAC address

OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.
//________________________________________________________________________

// Wireless configuration parameters —————————————-
unsigned char local_ip[] = {192,168,0,151}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,0,1}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {“dlink”}; // max 32 bytes

unsigned char security_type = 2; // 0 – open; 1 – WEP; 2 – WPA; 3 – WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {“1234567890”}; // max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM =

{ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
};

// setup the wireless mode
// infrastructure – connect to AP
// adhoc – connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len;
unsigned char security_passphrase_len;
// End of wireless configuration parameters —————————————-

boolean states[3]; //holds led states
char stateCounter; //used as a temporary variable
char tmpStrCat[64]; //used in processing the web page
char stateBuff[4]; //used in text processing around boolToString()
char numAsCharBuff[2];
char ledChange;

void boolToString (boolean test, char returnBuffer[4])
{
returnBuffer[0] = ‘\0’;
if (test)
{
strcat(returnBuffer, “On”);
}
else
{
strcat(returnBuffer, “Off”);
}
}

void writeStates()
{
//set led states
digitalWrite(ledPin1, states[0]);
digitalWrite(ledPin2, states[1]);
digitalWrite(ledPin3, states[2]);
}

// This is our page serving function that generates web pages
boolean sendPage(char* URL) {

writeStates();

//check whether we need to change the led state
if (URL[1] == ‘?’ && URL[2] == ‘L’ && URL[3] == ‘E’ && URL[4] == ‘D’) //url has a leading /
{
ledChange = (int)(URL[5] – 48); //get the led to change.

for (stateCounter = 0 ; stateCounter < 3; stateCounter++)
{
if (ledChange == stateCounter)
{
states[stateCounter] = !states[stateCounter];

}
}

//after having change state, return the user to the index page.
WiServer.print(“<HTML><HEAD><meta http-equiv=’REFRESH’ content=’0;url=/’></HEAD></HTML>”);
return true;
}

;
//Alarm set point 0
if (URL[1] == ‘A’) //add 1 to the alarm set point
{
tempAlarm = tempAlarm++;
//after having change state, return the user to the index page.
WiServer.print(“<HTML><HEAD><meta http-equiv=’REFRESH’ content=’0;url=/’></HEAD></HTML>”);
return true;
}

if (URL[1] == ‘B’) //minus 1 to the alarm set point
{ tempAlarm = tempAlarm–;
//after having change state, return the user to the index page.
WiServer.print(“<HTML><HEAD><meta http-equiv=’REFRESH’ content=’0;url=/’></HEAD></HTML>”);
return true;
}
//Alarm setpoint 1
if (URL[1] == ‘C’) //add 1 to the alarm set point
{
tempAlarma = tempAlarma++;
//after having change state, return the user to the index page.
WiServer.print(“<HTML><HEAD><meta http-equiv=’REFRESH’ content=’0;url=/’></HEAD></HTML>”);
return true;
}

if (URL[1] == ‘D’) //minus 1 to the alarm set point
{ tempAlarma = tempAlarma–;
//after having change state, return the user to the index page.
WiServer.print(“<HTML><HEAD><meta http-equiv=’REFRESH’ content=’0;url=/’></HEAD></HTML>”);
return true;
}

if (strcmp(URL, “/”) == false) //why is this not true, just refresh the page
{
WiServer.print(“<html><body><meta name=\”viewport\” content=\”width=device-width, user-scalable=no\” />”);
WiServer.print(“<b><center>Arduino WiShield Web Server</center></b><hr/>”);
WiServer.print(“<b><center>LED Control<center>\n<center></b>”);
for (stateCounter = 0; stateCounter < 3; stateCounter++) //for each led
{
numAsCharBuff[0] = (char)(stateCounter + 49); //as this is displayed use 1 – 3 rather than 0 – 2
numAsCharBuff[1] = ‘\0’; //strcat expects a string (array of chars) rather than a single character.
//This string is a character plus string terminator.

tmpStrCat[0] = ‘\0’; //initialise string
strcat(tmpStrCat, “<a href=?LED”); //start the string
tmpStrCat[12] = (char)(stateCounter + 48); //add the led number
tmpStrCat[13] = ‘\0’; //terminate the string properly for later.

strcat(tmpStrCat, “>Led “);
strcat(tmpStrCat, numAsCharBuff);
strcat(tmpStrCat, “: “);

boolToString(states[stateCounter], stateBuff);
strcat(tmpStrCat, stateBuff);
strcat(tmpStrCat, “</a>”); //we now have something in the range of <a href=?LED0>Led 0: Off</a>
WiServer.print(” “);
WiServer.print(tmpStrCat);
}
sensors.requestTemperatures(); //Get temperature of all sensors
WiServer.print(“<BR><hr/>”);
WiServer.print(“Arduino has been running: “);
WiServer.printTime(millis()); //prints millis timer in hours:minutes:seconds format
WiServer.print(“<hr/>”);
WiServer.print(“<b>Temperature</b>”);
WiServer.print(“<BR>”);
WiServer.print(“Sensor 0 (Deg C): “);
WiServer.print(sensors.getTempC(tempa)); //print temperature from DS18x20 sensor
WiServer.print(“<BR>”);
WiServer.print(“Alarm Set Point: “);
WiServer.print(tempAlarm);
WiServer.print(“<button><a href=\”/A\”>+++</a></button>”);
WiServer.print(“<button><a href=\”/B\”>—</a></button>”);
WiServer.print(“<BR>”);
WiServer.print(“Sensor 1 (Deg C): “);
WiServer.print(sensors.getTempC(tempb));//print temperature from DS18x20 sensor
WiServer.print(“<BR>”);
WiServer.print(“Alarm Set Point: “);
WiServer.print(tempAlarma);
WiServer.print(“<button><a href=\”/C\”>+++</a></button>”);
WiServer.print(“<button><a href=\”/D\”>—</a></button>”);
WiServer.print(“<BR><hr/>”);
WiServer.print(“<b>Alarms</b>”);
WiServer.print(“<BR>”);
if ((sensors.getTempC(tempa))>=(tempAlarm)) // easily changed to a less then value, say for turning on a heater
{
WiServer.print(“****Sensor 0 HIGH TEMPERATURE****”);
digitalWrite(alarmPin2, HIGH);
}
else
{
digitalWrite(alarmPin2, LOW);
// WiServer.print(“<BR>”);
WiServer.print(“Sensor 0 None”);
}

if ((sensors.getTempC(tempb))>=(tempAlarma))
{
WiServer.print(“<BR>”);
WiServer.print(“****Sensor 1 HIGH TEMPERATURE****”);
digitalWrite(alarmPin3, HIGH);
}
else
{
digitalWrite(alarmPin3, LOW);
WiServer.print(“<BR>”);
WiServer.print(“Sensor 1 None”);
}

WiServer.print(“<hr/>”);
WiServer.print(“</body></html>”);
return true;
}
}

void setup() {
// Initialize WiServer and have it use the sendMyPage function to serve pages
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(alarmPin2, OUTPUT);
pinMode(alarmPin3, OUTPUT);

WiServer.init(sendPage);
states[0] = false;
states[1] = false;
states[2] = false;
sensors.setResolution(tempa, TEMPERATURE_PRECISION); //Setup Dallas sensor resolution and address
sensors.setResolution(tempb, TEMPERATURE_PRECISION); //Setup Dallas sensor resolution and address
}

void loop(){
// Run WiServer
WiServer.server_task();

delay(10);
}

Leave a Comment more...

Arduino WiServer with Multiple DS18S20 Temperature Sensors

by on Jan.07, 2013, under Arduino, Arduino ATmega328, Electronic Projects, WiShield

Arduino with a Async Labs WiServer 1.0 Shield and four DS18S20 Dallas Temperature Senors.

Again this is a more of a reminder for me of the sketch and a working sketch for others to start from.

As I played with this idea, did some searching and found a sketch “that kim messed with”.  It had for me the ultimate LED control, it worked very good. Then added in my DS18S20 temperature sensor sketch and BAM…. all worked and works dam good.

Found the sketch very stable. In fact it ran for almost a week (518,654 seconds) before I got back to it and start working on the SD card logging and file server ideas.

This is what the web page looks like on a iphone/ipod:

Jan 06 2013

This sketch will poll the DS18S20 every time you request a web page, either by refreshing the page or changing one of the LED states.

The running time is good way of know how long the Arduino has been running.  I have not had a bad responses from the DS18S20 so far, which is pretty good for a one-wire devices.

It takes about 4 seconds for the web page to refresh, this is  do to the time it takes to read all four of the DS18S20 sensors.

Till next time, thanks for your time.

 

Sketch:

/*
elelctronicramblings.com
*** A simple sketch that uses WiServer to serve a web page !! that kim messed with.***
I work with the sketch that kim messed with and added in my DS18x20 code. Dam it works good.
Jan 2013
***
The code is stable.
Was compiled on Beta 1.0.1
Latest AysncLab WiServer Library
Latest Dallas one-wire Library
***
It works as a 3 LED control and Read Temperture from 4 DS18S20 senosors.
Was well as give the up time of the Arduino system.
***
All fits just on a iphone/ipod screen.
***

*/
#include <WiServer.h>
#include <string.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2

#define ledPin1 5
#define ledPin2 6
#define ledPin3 3
#define ONE_WIRE_BUS 7
#define TEMPERATURE_PRECISION 12

//Device is a DS18S20 : 10-EC-A7-48-00-08-00-47
DeviceAddress tempa={0X10, 0XEC, 0XA7, 0X48, 0X00, 0X08, 0X00, 0X47}; //DS18S20 temperature senor MAC address
//Device is a DS18S20 : 10-22-E1-48-00-08-00-BE
DeviceAddress tempb={0X10, 0X22, 0XE1, 0X48, 0X00, 0X08, 0X00, 0XBE}; //DS18S20 temperature senor MAC address
//Device is a DS18S20 : 10-21-D8-48-00-08-00-90
DeviceAddress tempc={0X10, 0X21, 0XD8, 0X48, 0X00, 0X08, 0X00, 0X90}; //DS18S20 temperature senor MAC address
//Device is a DS18S20 : 10-7F-E2-48-00-08-00-94
DeviceAddress tempd={0X10, 0X7F, 0XE2, 0X48, 0X00, 0X08, 0X00, 0X94}; //DS18S20 temperature senor MAC address

OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.
//________________________________________________________________________

// Wireless configuration parameters —————————————-
unsigned char local_ip[] = {192,168,0,151}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,0,1}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {“dlink”}; // max 32 bytes

unsigned char security_type = 1; // 0 – open; 1 – WEP; 2 – WPA; 3 – WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {“123456780”}; // max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
};

// setup the wireless mode
// infrastructure – connect to AP
// adhoc – connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len;
unsigned char security_passphrase_len;
// End of wireless configuration parameters —————————————-

boolean states[3]; //holds led states
char stateCounter; //used as a temporary variable
char tmpStrCat[64]; //used in processing the web page
char stateBuff[4]; //used in text processing around boolToString()
char numAsCharBuff[2];
char ledChange;

void boolToString (boolean test, char returnBuffer[4])
{
returnBuffer[0] = ‘\0’;
if (test)
{
strcat(returnBuffer, “On”);
}
else
{
strcat(returnBuffer, “Off”);
}
}
/*
void printStates()
{
for (stateCounter = 0 ; stateCounter < 3; stateCounter++)
{
boolToString(states[stateCounter], stateBuff);

Serial.print(“State of “);
Serial.print(stateCounter);
Serial.print(“: “);
Serial.println(stateBuff);
}
}
*/
void writeStates()
{
//set led states
digitalWrite(ledPin1, states[0]);
digitalWrite(ledPin2, states[1]);
digitalWrite(ledPin3, states[2]);
}

// This is our page serving function that generates web pages
boolean sendPage(char* URL) {

// Serial.println(“Page printing begun”);

// printStates();
writeStates();

//check whether we need to change the led state
if (URL[1] == ‘?’ && URL[2] == ‘L’ && URL[3] == ‘E’ && URL[4] == ‘D’) //url has a leading /
{
ledChange = (int)(URL[5] – 48); //get the led to change.

for (stateCounter = 0 ; stateCounter < 3; stateCounter++)
{
if (ledChange == stateCounter)
{
states[stateCounter] = !states[stateCounter];
// Serial.print(“Have changed “);
//Serial.println(ledChange);
}
}

//after having change state, return the user to the index page.
WiServer.print(“<HTML><HEAD><meta http-equiv=’REFRESH’ content=’0;url=/’></HEAD></HTML>”);
return true;
}

if (strcmp(URL, “/”) == false) //why is this not true?
{

WiServer.print(“<html><body><meta name=\”viewport\” content=\”width=device-width, user-scalable=no\” />”);
WiServer.print(“<b><center>Arduino Web Server<center>\n<center><hr/></b>”);
WiServer.print(“<b><center>Please select the led state:<center>\n<center></b>”);
for (stateCounter = 0; stateCounter < 3; stateCounter++) //for each led
{
numAsCharBuff[0] = (char)(stateCounter + 49); //as this is displayed use 1 – 3 rather than 0 – 2
numAsCharBuff[1] = ‘\0’; //strcat expects a string (array of chars) rather than a single character.
//This string is a character plus string terminator.

tmpStrCat[0] = ‘\0’; //initialise string
strcat(tmpStrCat, “<a href=?LED”); //start the string
tmpStrCat[12] = (char)(stateCounter + 48); //add the led number
tmpStrCat[13] = ‘\0’; //terminate the string properly for later.

strcat(tmpStrCat, “>Led “);
strcat(tmpStrCat, numAsCharBuff);
strcat(tmpStrCat, “: “);

boolToString(states[stateCounter], stateBuff);
strcat(tmpStrCat, stateBuff);
strcat(tmpStrCat, “</a>”); //we now have something in the range of <a href=?LED0>Led 0: Off</a>
WiServer.print(“<hr/>”);
WiServer.print(tmpStrCat);
sensors.requestTemperatures(); //Get temperature of all sensors
}
WiServer.print(“<BR><hr/>”);
WiServer.print(“Arduino has been running: “);
WiServer.print((millis()/1000));
WiServer.print(” seconds<br>”);
WiServer.print(“<hr/>”);
WiServer.print(“Sensors”);
WiServer.print(“<BR>”);
WiServer.print(“0(Deg C): “);
WiServer.print(sensors.getTempC(tempa));
WiServer.print(“<BR>”);
WiServer.print(“1(Deg C): “);
WiServer.print(sensors.getTempC(tempb));
WiServer.print(“<BR>”);
WiServer.print(“2(Deg C): “);
WiServer.print(sensors.getTempC(tempc));
WiServer.print(“<BR>”);
WiServer.print(“3(Deg C): “);
WiServer.print(sensors.getTempC(tempd));
WiServer.print(“<BR><hr/>”);
WiServer.print(“</body></html>”);
return true;
}
}

void setup() {
// Initialize WiServer and have it use the sendMyPage function to serve pages
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);

//Serial.begin(9600);
WiServer.init(sendPage);
states[0] = false;
states[1] = false;
states[2] = false;
sensors.setResolution(tempa, TEMPERATURE_PRECISION); //Setup Dallas sensor resolution and address
sensors.setResolution(tempb, TEMPERATURE_PRECISION); //Setup Dallas sensor resolution and address
sensors.setResolution(tempc, TEMPERATURE_PRECISION); //Setup Dallas sensor resolution and address
sensors.setResolution(tempd, TEMPERATURE_PRECISION); //Setup Dallas sensor resolution and address
}

void loop(){
// Run WiServer
WiServer.server_task();

delay(10);
}

Leave a Comment more...

Arduino + DS18S20 + WiServer

by on Jan.03, 2013, under Arduino, Arduino ATmega328, Electronic Projects, WiShield

Arduino WiServer and DS18S20 Temperature Sensor adventure.
(This post is not meant to be a tell all on how to use the DS18S20 or Microchip Wifi module, but to reminder for me and maybe help others with a working sketch.)
This is my adventure of the the Microchip Wifi MRF24WB0A module and DS18S20 Temperature semiconductor.
I did not want to pay 85 dollars for a fancy Arduino shield. So I bought a Microchip MRF2424WB0A  from ebay for $9 and looked around for a way to hook up. I started with this web page: http://theiopage.blogspot.ca/2011/10/connecting-mrf24wb0ma-to-arduino.html
But decided l wanted a shield to work with. So found on the Aysnclab Wiki site the Eagle Cad files for the WiServer Shield V1.0.
http://asynclabs.com/wiki/index.php?title=WiShield_1.0
I checked out the schematic and Board PCB found on the above pages and sent them to OSH Park prototype batch PCB operation. http://oshpark.com/
For the size of the shield it cost me under $25 with shipping for three boards.(Just over $8 per board, dam good price in my world)
These boards came with silkscreen and solder mask for this price.

(yes they arrived with purple solder mask!)

It took just over two weeks for the boards to show up.

Went with the through hole design as I already had the parts in my archives to build up the shields and not have to buy or order anything to assemble shields.
So at this point it was going to cost me about $20 to make my first Wifi shield.

Now the fun part, programming the unit to work.
I started by upgrading the Arduino Interface to Beta….bad choice. Everything I originally found was written for sketches were written for the Arduino Alpha interface….but with much reading of forums and blogs I got it working!!!!!
Places I found my help with this simple projects programming:
http://asynclabs.com/forums/
http://arduino.cc/  (the site that if you search hard enough you will find the answer…
So many good responses to the questions asked about the arduino system. Thanks!!!!)
If all else fails search using google and Yahoo. Amazing how different sites come up between the two search engines.

So to use the sketch below, you will need:
Arduino Beta interface
Wiserver Library(https://github.com/asynclabs/WiShield), with some changes
Dallas 1-Wire Library(http://playground.arduino.cc/Learning/OneWire).
LED and a 330 ohm resistor on pin 5
DS18S20 attached using pin 7
These should be all you need to run the sketch below.

Added Note:
The changes needed in the WiServer Library are in the apps-conf file to hav this work:
What needs to change:
//Here we include the header file for the application(s) we use in our project.
comment out–>#define APP_WEBSERVER
//#define APP_WEBCLIENT
//#define APP_SOCKAPP
//#define APP_UDPAPP
uncomment–>//#define APP_WISERVER

Should end up with this:
//Here we include the header file for the application(s) we use in our project.
//#define APP_WEBSERVER
//#define APP_WEBCLIENT
//#define APP_SOCKAPP
//#define APP_UDPAPP
#define APP_WISERVER

Load the sketch below into the Arduino Interface and modify the wifi network information for your network.
I am not going to go into much detail as the Asynclab site has already done it.

Here as promised, the Sketch:

//******************************************************************************************
/*
electronicramblings.com
Written Jan 2013.
A simple sketch that will read a DS18S20 temperature sensor, serve up a web page that
will count each time the page is served, and also turn on/off a LED on pin 5
*/

#include <WiServer.h>

#define WIRELESS_MODE_INFRA    1
#define WIRELESS_MODE_ADHOC    2
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 7
#define TEMPERATURE_PRECISION 12

DeviceAddress tempa={0X10, 0X7F, 0XE2, 0X48, 0X00, 0X08, 0X00, 0X94}; //DS18S20 temperature senor MAC address
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.

int ledPin5 =  5;    // LED connected to digital pin 5
int Count = 1; //Setup of page counter

//________________________________________________________________________________
//For the temperature time delay loop
long previousMillis = 0;        // will store last time TEMP was updated
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 10000;           // interval at which to blink (milliseconds)
//________________________________________________________________________________
// Wireless configuration parameters —————————————-
unsigned char local_ip[] = {192,168,0,151}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,0,1}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {“dlink”}; // max 32 bytes

unsigned char security_type = 1; // 0 – open; 1 – WEP; 2 – WPA; 3 – WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {“123456780”}; // max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
};

// setup the wireless mode
// infrastructure – connect to AP
// adhoc – connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len;
unsigned char security_passphrase_len;
// End of wireless configuration parameters —————————————-

// This is our page serving function that generates web pages
boolean sendMyPage(char* URL) {

// Check if the requested URL match es “/”
if (strcmp(URL, “/on”) == 0) {
digitalWrite(ledPin5, HIGH);   // set the LED on
// Use WiServer’s print and println functions to write out the page content
WiServer.print(“<html><body><meta name=\”viewport\” content=\”width=device-width, user-scalable=no\” />”);
WiServer.print(“<b>Simple webserver<BR></b>”);
WiServer.print(“<hr /><BR>”);
WiServer.print(“<button><a href=\”off\”>LED OFF  </a></button><BR>”);
WiServer.print(“<BR>”);
WiServer.print(“Web Page Served:  “);
WiServer.print(Count);
WiServer.print(”  Times<BR>”);
WiServer.print(“<hr /><BR>”);
Count=Count++; // Counter +1
WiServer.print(“Temperature(Deg C): “);
WiServer.print(sensors.getTempC(tempa));
WiServer.print(“</table></body></html>”);
// URL was recognized
return true;
}
if (strcmp(URL, “/off”) == 0) {
digitalWrite(ledPin5, LOW);   // set the LED off
// Use WiServer’s print and println functions to write out the page content
WiServer.print(“<html><body><meta name=\”viewport\” content=\”width=device-width, user-scalable=no\” />”);
WiServer.print(“<b>Simple webserver<BR></b>”);
WiServer.print(“<hr /><BR>”);
WiServer.print(“<button><a href=\”on\”>LED ON</a></button><BR>”);
WiServer.print(“<BR>”);
WiServer.print(“Web Page Served:  “);
WiServer.print(Count);
WiServer.print(”  Times<BR>”);
WiServer.print(“<hr /><BR>”);
Count=Count++; // Counter +1
WiServer.print(“Temperature(Deg C): “);
WiServer.print(sensors.getTempC(tempa));
WiServer.print(“</table></body></html>”);
// URL was recognized
return true;
}}

void setup() {

pinMode(ledPin5, OUTPUT); // Make pin a output
WiServer.init(sendMyPage);   // Initialize WiServer and have it use the sendMyPage function to serve pages
sensors.setResolution(tempa, TEMPERATURE_PRECISION); //Setup Dallas sensor resolution and address
}

void loop(){
//___________________________________________________________________________
// Here is where you’d put code that needs to be running all the time.
// Check to see if it’s time to get temperature; that is, if the
// Difference between the current time and last time you get the temperature
unsigned long currentMillis = millis(); // From Blink without delay statment

if(currentMillis – previousMillis > interval) {
WiServer.server_task();
// save the last time you get temperature
previousMillis = currentMillis;
//____________________________________________________________________________
sensors.requestTemperatures();    //Get temperature:
}
WiServer.server_task(); //Run wiserver and wait for a connection
}

//******************************************************************************************

What the web page looks like on a iphone:

The I am off to see now to make the unit read and display multiple DS18x20 sensors.
Also the next time I build one of these shields I will find the design with the SD card as well and modify it to have the RTC on it as well.(to make a fancy data logger)

Till Next time, thanks for your time.

4 Comments more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...