electronicramblings.com

Arduino

Truck Temperature Gauge ATtiny85 DS18S20 DS18B20 LCD

by on Apr.13, 2013, under Arduino, ATtiny, Electronic Projects

Well, finally built something useful with the ATtiny85.

Again this is more for reference then a how to.  So please use with a grain of salt.

I used the Halogen M16 Light housing as a template for the PCB boards.  Bought these from Ebay a few years ago to attempt to build a simple LED tachometer for my Cruiser(2006 Kawasaki Vulcan Nomad), but instead found a cheap 2″ gauge to do the job, so the lights were just sitting in my archives till I decided to build a temperature sensor for my Ford Ranger.  Will be mounting this gauge on the windshield column using the OH Shit!!! handle. When I get the bracket built will have pictures of the actual install.  Below this is the Lamps housing.  Can’t find it on ebay any more.  So if anyone know where to find them, let me know…I have a few ideas of what to put in them next. 🙂

April 13 iphone4 2013 141-800

The interesting thing I found is the M16 Lamp has a glass lens over the actual bulb.  Not like the other M16 bulbs I have in my home that have the bulb open to the air. (M16 EXN 12VDC 50 Watt is the lamp with a glass shield over the bulb)

So to protect my display on the LCD I decided to get a glass shop to cut me couple of circles of glass that I would silicon into the face of the housing.  This will make the unit able to be used on my Cruiser as well as my truck.

This is more of a picture post, hope is give you ideas of doing your own gauge.  If you do one, let me know as I do like seeing how other have done there projects.

Housing parts:

April 13 iphone4 2013 147-800

 

Electronics assembled reading for hiding way into the housing.

 

April 13 iphone4 2013 157-800

 

Back View, So you can see how the electronics are held into the housing.

 

April 13 iphone4 2013 160-800

 

 

 

 

April 13 iphone4 2013 163-800

 

Finished display. Now the hard part, figuring out how to mount without harming the original molding in the Truck.

April 13 iphone4 2013 167-800

 

 

Thoughts on other setups for this configuration: 

Oil Temperature
Oil Pressure
OBDII Readings(this one will take a lot of work, will have to go a at least a ATmega328 chip for this one)
Any other gauge one can think of!

Other configuration ideas:
No CPU in the gauge housing, but just a SPI LCD display and a electronics box under the dash to do all the gathering of information and controlling of the displays.

Boards:
Eagle Cad Boards:  ATtinyx5 LCD 8×2 V3

Note on board build:
Did not install the reset circuit, or the resonator. Not needed for this project. The Main board was setup for just project.(One Wire DS18S20 or DS18B20 temperature sensors)
If you use these boards, add in extra set of headers for external wiring, I got lucky and was able to solder my external wires to the pins on the header.
The boards were setup with through hole parts for two reasons, I was home etching the boards, and I have a lot of parts I wanted to use up. If I were to manufacturer these boards I would go to surface mount.

Sketch Notes:
Used the Arduino Digispark interface 1.03, BUT did not load into the ATtiny85 the boot loader!
The interface has most of the libraries need to do this project.  The rest of the libraries are in previous post. Please look back to find them. (Post)

Till next time, thanks for your time.

Sketch:

/*
April 12, 2013
Digispark Arduino interface 1.03 used to compile
Digispark(Tiny Core)
ATtiny85 Clock PLL-16Mhz
LCD control PCF8475A ([A]extended address chip) wired to use the DFRRobot Library
Eagle board “ATtinyx5 ***** V3”
(Actually uses a header for 8×2 LCD)

I2C LCD connects to SDA, SCL +5v, Gnd
Uses a 8×2 I2C LCD Backlight Display

DS18x20 x2 Temperature chip on pin P4
4k7 pullup between pin P4 and +5v.
Hard code addresses of sensor to make code smaller and easier.

Pin connections of ATtiny85
P0 = SDA Pin 5
P1 = Pin 6
P2 = SCL Pin 7
P3 = Pin 2
P4 = DS18B20 Pin 3
P5 = Pin 1

*/

#include <OneWire.h>
#define ONE_WIRE_BUS 4 // DS18B20 is on P4
#include <TinyWireM.h> // I2C Master lib for ATTinys which use USI – comment this out to use with standard arduinos
#include <LiquidCrystal_I2C.h> // for LCD w/ GPIO MODIFIED for the ATtiny85
#define GPIO_ADDR 0x38 //LCD address, PCF8475A extended address

OneWire ds(ONE_WIRE_BUS);
LiquidCrystal_I2C lcd(GPIO_ADDR,16,2); // set address & 16 chars / 2 lines

//DS18S20 temperature senor MAC address
byte addr[8]={0x10, 0x22, 0xE1, 0x48, 0x00, 0x08, 0x00, 0xBE};//long sensor cable [outside]
//DS18S20 temperature senor MAC address
byte addr1[8]={0x10, 0xEC, 0xA7, 0x48, 0x00, 0x08, 0x00, 0x47};//Short sensor cable [inside]

//
int HighByte, LowByte, TReading, SignBit, Tc_100, Whole, Fract;
char buf[20];

int HighBytea, LowBytea, TReadinga, SignBita, Tc_100a, Wholea, Fracta;
char bufa[20];

//________________________________________________________________________________
void setup(void) {
// set up the LCD’s number of rows and columns:

TinyWireM.begin(); // initialize I2C lib

lcd.init(); // initialize the lcd
lcd.clear();
lcd.noCursor();
lcd.backlight(); // Turn on the backlight

// Print a message to the LCD.
lcd.setCursor(0,0); // First position (0) and first line (0)
lcd.print (“Arduino “);
lcd.setCursor(0,1); // First position (0) and second line (1)
lcd.print (“Dual”);
delay(3000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print (“Temp”);
lcd.setCursor(0,1);
lcd.print (“Gauge”);
delay(4000);
lcd.clear();

}
//________________________________________________________________________________

void loop(void) {

sensorRead();
delay(4000);
sensor2Read();
delay(4000);

}

//________________________________________________________________________________

void sensorRead()
{
byte i;
byte present = 0;
byte data[12];

ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end

delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.

present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad

for ( i = 0; i < 9; i++)
{ // we need 9 bytes
data[i] = ds.read();
}

LowByte = data[0];
HighByte = data[1];
TReading = (HighByte << 8) + LowByte;
SignBit = TReading & 0x8000; // test most sig bit
if (SignBit) // negative
{
TReading = (TReading ^ 0xffff) + 1; // 2’s comp
}
Tc_100 = (TReading*100/2);

Whole = Tc_100 / 100; // separate off the whole and fractional portions
Fract = Tc_100 % 100;

sprintf(buf, “%c%d.%d\337C “,SignBit ? ‘-‘ : ‘+’, Whole, Fract < 10 ? 0 : Fract);
lcd.clear();
lcd.setCursor(0,1);
lcd.print(buf);
lcd.setCursor(0,0);
lcd.print(“Outside”);
}
//________________________________________________________________________________
void sensor2Read()
{
byte j;
byte presenta = 0;
byte dataa[12];

ds.reset();
ds.select(addr1);
ds.write(0x44,1); // start conversion, with parasite power on at the end

delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.

presenta = ds.reset();
ds.select(addr1);
ds.write(0xBE); // Read Scratchpad

for ( j = 0; j < 9; j++)
{ // we need 9 bytes
dataa[j] = ds.read();
}

LowBytea = dataa[0];
HighBytea = dataa[1];
TReadinga = (HighBytea << 8) + LowBytea;
SignBita = TReadinga & 0x8000; // test most sig bit
if (SignBita) // negative
{
TReadinga = (TReadinga ^ 0xffff) + 1; // 2’s comp
}
Tc_100a = (TReadinga*100/2);

Wholea = Tc_100a / 100; // separate off the whole and fractional portions
Fracta = Tc_100a % 100;

sprintf(bufa, “%c%d.%d\337C “,SignBita ? ‘-‘ : ‘+’, Wholea, Fracta < 10 ? 0 : Fracta);
lcd.clear();
lcd.setCursor(0,1);
lcd.print(bufa);
lcd.setCursor(0,0);
lcd.print(“Inside”);

}

Leave a Comment more...

Digispark ATtiny85 LCD I2C DS18S20 DS18B20 Temperature Monitor

by on Apr.01, 2013, under Arduino, ATtiny, Electronic Projects

Well this has been a great adventure!!!

I wanted to build a simple interior and exterior temperature sensor for my truck. This was a bigger adventure than I expected.  I started off by doing research of a the three main components that I wanted to use ( ATtiny85, DS18x20,LCD,).  I stumbled upon the Digispark project on Kickstarter and what they have done.  Searching more I found a article published in a magazine called the “The Shed” that used the Digispark to accomplish the reading of the DS18x20 temperature chip, but could not do negative number very well.  (The project in The Shed magazine/DigiStump forum also had a max/min and relay control).  So will look at that code later for running my smoker.

As I was still searching for code snippets that would work for me, I decided to build up the circuit that matched the DigiSpark on my trusty bread board minus the relay control.  The reason I am going with the DigiSpark circuit is that I am going to use the Arduino 1.03 Digispark inteface. It already has a lot of the libraries need for this small processor.  I WILL NOT be loading on the boot loader, so in fact you get 2k more space if you need it. Just have to modify the Arduino interface files to reflect that.

April 01 2013 049

I have a lot of older DS18x20 chips around so that is why I am using them up in projects.  (I have a vast archive of semiconductors and components from when I ran a repair and design company, oh so long ago….)  In the picture you may notice two arduino boards, and one with a shield with a mess of wirewrap on it, that is my dedicated Arduino as a ISP with my hand built ATtiny85/84 programmer shield.

When starting with the ATTiny and wanting to use the Arduino interface, this is the place.  They did a lot of great work there.

Now this is where the adventure truly started…..  Bricking the ATtiny 85 on the first try.

I followed the direction given by the MIT people, but then thinking I am smarter than the average bear I decided to program the fuses myself using one of the many AVR programmers I have with the AVR Studio software.  That is where I went wrong….word of warning….never set the reset fuse!!! I did and could not program the ATtiny flash or the fuses.  So this is where I learned of the High Voltage Programming circuit and software to fix the fuses. You can find a good write up this here.  So seeing that this must be a problem out here I made a Arduino shield up for this to.

Zip of the Attiny LV and HV Programmer shield I put together.

ATTINY Fuse Fix

 

After getting my Attiny85 unbricked, I still had to program the Clock fuse to what I needed. I could have figured out what was needed using this web page as a reference. Fuse Calculator And then used the HV circuit to set the fuses.  But, still a wanting to do it my way!  I went back to my trusty AVR programmer, and finished programming my ATtiny85 to have a clock speed of 16mHz (PLL).

Now we are cooking with fire….  This is where I was at, a ATtiny85, LCD 16×2 with a I2C backpack, and handful of DS18x20 chips.  I decided not to write any code at this time, but modify The Shed’s code to match my components to see if my wiring was working.  I always like to start from a known point and then really screw it up after that!  Well, some god’s of electronic adventures was good to me and we had a temperature show up on the LCD. And better yet it changed.  The bad part is it had a problem reading negative temperatures, so had to start working out a method that would give me a negative value. (It gets dam cold around here in the winter. Alberta, Canada) And the sketch below is the code that will do the job.  You will also see that I have hard coded in the DS18x20 addresses.  Did this so the correct reading matches up with the text on the LCD.

I then layed out a board fast, etched, drilled and stuff in a couple of hours to test out my new code.

A wack of Pics showing a semi completed project:

April 01 2013 046 April 01 2013 045 April 01 2013 044 April 01 2013 041

 

April 01 2013 047

I am including my eagle cad drawing for the project as well as the library folder from the Arduino 1.03 Digispark interface.   The PCB is pretty dam poor designing, I am not good at doing 2 sided boards at home yet.  Something like 12 jumpers one has to solder in on this one, however, it only took me 30 minutes to do the schematic and PCB layout.

Zip of my files:

Digispark_DS18x20_LCD_2_sensors_march_2013_v4_

The next one will use the 8×2 display and be more modular. Thinking of going with a power supply board, ATTiny board and LCD interface board that match the 8×2 8 pin dual row header.

 

Till next time, thanks for your time.

 

 

Sketch:

/*
April 01, 2013

electronicramblings.com
Digispark Arduino interface 1.03 used to compile code
Digispark(Tiny Core)
ATtiny85 Clock PLL-16Mhz
LCD control PCF8475A ([A]extended address chip) wired to use the DFRRobot Library
Eagle board “LCD 8×2 dual DS18x20 Ver2.brd”
(actually uses a header for 16×2 LCD) Was going to use a 8×2 but it was damaged.

I2C LCD connects to SDA, SCL +5v, Gnd (Don’t forget the 4k7ohm pull up resistors for the SDA SCL pins)
Uses a 16×2 I2C LCD Backlight Display

DS18B20 x2 Temperature chip on pin P4
4k7 pullup between pin P4 and +5v.
Hard code addresses of sensor to make code smaller and easier.

Pin connections of ATtiny85
P0 = SDA Pin 5
P1 = Pin 6
P2 = SCL Pin 7
P3 = Pin 2
P4 = DS18B20 Pin 3
P5 = Pin 1

*/

#include <OneWire.h>
#define ONE_WIRE_BUS 4 // DS18B20 is on P4
#include <TinyWireM.h> // I2C Master lib for ATTinys which use USI – comment this out to use with standard arduinos
#include <LiquidCrystal_I2C.h> // for LCD w/ GPIO MODIFIED for the ATtiny85
#define GPIO_ADDR 0x38 //LCD address, PCF8475A extended address

OneWire ds(ONE_WIRE_BUS);
LiquidCrystal_I2C lcd(GPIO_ADDR,16,2); // set address & 16 chars / 2 lines

//DS18S20 temperature senor MAC address
byte addr[8]={0x10, 0x22, 0xE1, 0x48, 0x00, 0x08, 0x00, 0xBE};//long sensor cable [outside]
//DS18S20 temperature senor MAC address
byte addr1[8]={0x10, 0xEC, 0xA7, 0x48, 0x00, 0x08, 0x00, 0x47};//Short sensor cable [inside]

//
int HighByte, LowByte, TReading, SignBit, Tc_100, Whole, Fract;
char buf[20];

int HighBytea, LowBytea, TReadinga, SignBita, Tc_100a, Wholea, Fracta;
char bufa[20];

//________________________________________________________________________________
void setup(void) {
// set up the LCD’s number of rows and columns:

TinyWireM.begin(); // initialize I2C lib

lcd.init(); // initialize the lcd
lcd.clear();
lcd.noCursor();
lcd.backlight(); // Turn on the backlight

// Print a message to the LCD.
lcd.setCursor(0,0); // First position (0) and first line (0)
lcd.print (“Arduino “);
lcd.setCursor(2,1); // First position (0) and second line (1)
lcd.print (“Temp Sensors”);
delay(4000);
lcd.clear();

}
//________________________________________________________________________________

void loop(void) {
sensorRead();
sensor2Read();
delay(3000);

}

//________________________________________________________________________________

void sensorRead()
{
byte i;
byte present = 0;
byte data[12];

ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end

delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.

present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad

for ( i = 0; i < 9; i++)
{ // we need 9 bytes
data[i] = ds.read();
}

LowByte = data[0];
HighByte = data[1];
TReading = (HighByte << 8) + LowByte;
SignBit = TReading & 0x8000; // test most sig bit
if (SignBit) // negative
{
TReading = (TReading ^ 0xffff) + 1; // 2’s comp
}
Tc_100 = (TReading*100/2);

Whole = Tc_100 / 100; // separate off the whole and fractional portions
Fract = Tc_100 % 100;

sprintf(buf, “%c%d.%d\337C “,SignBit ? ‘-‘ : ‘+’, Whole, Fract < 10 ? 0 : Fract);
lcd.setCursor(0,0);
lcd.print(buf);
lcd.setCursor(9,0);
lcd.print(“Outside”);
}
//________________________________________________________________________________
void sensor2Read()
{
byte j;
byte presenta = 0;
byte dataa[12];

ds.reset();
ds.select(addr1);
ds.write(0x44,1); // start conversion, with parasite power on at the end

delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.

presenta = ds.reset();
ds.select(addr1);
ds.write(0xBE); // Read Scratchpad

for ( j = 0; j < 9; j++)
{ // we need 9 bytes
dataa[j] = ds.read();
}

LowBytea = dataa[0];
HighBytea = dataa[1];
TReadinga = (HighBytea << 8) + LowBytea;
SignBita = TReadinga & 0x8000; // test most sig bit
if (SignBita) // negative
{
TReadinga = (TReadinga ^ 0xffff) + 1; // 2’s comp
}
Tc_100a = (TReadinga*100/2);

Wholea = Tc_100a / 100; // separate off the whole and fractional portions
Fracta = Tc_100a % 100;

sprintf(bufa, “%c%d.%d\337C “,SignBita ? ‘-‘ : ‘+’, Wholea, Fracta < 10 ? 0 : Fracta);
lcd.setCursor(0,1);
lcd.print(bufa);
lcd.setCursor(9,1);
lcd.print(“Inside”);

}

 

_________________________________________________________________

Keywords: Dallas Maxim Temperature ATtiny ATMEL AVR Studio I2C IIc

 

 

2 Comments more...

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

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