electronicramblings.com

Archive for February, 2013

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...

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...