|
|
View previous topic :: View next topic |
Author |
Message |
andys
Joined: 23 Oct 2006 Posts: 175
|
Driver For SHT75 Temperature & Humidity Sensor |
Posted: Tue Jul 10, 2012 6:33 am |
|
|
Where can i find driver for the sensor SHT25????
Can i use the driver of SHT75 for the SHT25 sensor????? |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Tue Jul 10, 2012 2:12 pm |
|
|
does not look that hard to write one.
is this classwork or a job offer ?
got 3.3V ??? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9216 Location: Greensville,Ontario
|
|
Posted: Tue Jul 10, 2012 5:19 pm |
|
|
SHT25, standard I2C interface,datasheet explains all modes,examples online....
...cutting a driver from 'scratch' for the device might take 1-2 hours...add a coffee brake or two... 4 hours tops and it's all done...
..cut and paste applicable routines or functions from similar drivers will cut the time in half.
no..I will not do the work for you since I do not have that device here to test my code and I don't send any code or drivers without testing them on real hardware here in my real shop.That's the only way I _know_ the code works. |
|
|
andys
Joined: 23 Oct 2006 Posts: 175
|
Where can I find driver for the sensor SHT25 ? |
Posted: Tue Jul 10, 2012 5:26 pm |
|
|
ok, can you help me , explain to me how to do it?
This is the first time that i try to do something like this. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Tue Jul 10, 2012 5:30 pm |
|
|
ok - i suggest you adapt some example i2c code to the specs of the part.
then show what effort you expended and what you have written yourself that does not work.
if you have no clue of where to start, perhaps you have chosen the wrong career. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9216 Location: Greensville,Ontario
|
|
Posted: Tue Jul 10, 2012 7:24 pm |
|
|
The mfr. gives complete code in their download section, so I'd print that out for a start...
'Googling' the part number and CCS C code might get a few hits....
Also you appear to have a driver for a similar product , so simply read both datasheets (print them out..) look side by side, compare command codes, data format, etc. to see what's the same...what's not...take notes !
Usually mfrs. will make devices similar so that code will be similar. This allows everyone to take advantage of past code, common drivers, easy upgrading, etc.
I prefer to use hardcopy, allows me to easily compare information, highlight bitmaps, function tables, etc. Same hold true for breadboarding a schematic. You can highlight connections to confirm proper signal paths, grounds, etc.
It's the details like finding out you've 'crisscrossed' I2C data and I2C clock lines that show why it is important to read the datasheets, confirm pinouts, and recheck the wiring.
Also do not try to make a complete, 'sophisticated' program, just the basics, in this case say just read the data and display it....
On this forum(or the code library), PCM programmer has an I2C test program. It would be a great start....as it will confirm you've got the device attached to the I2C bus correctly. Be sure to use the correct pullup resistors (3k3 or 4k7 may be ok for the 3 volt supply you must use).
Start small and simple, make BACKUP copies of ALL programs,building on small changes or additions. Yes, you may end up with 30-40-50 versions of the program, who cares, computers have terabytes nowadays. When you get it 'up and running', then delete all but say the last 5 versions. That way you'll have a chance to go back. If you only have 1 version and keep editing it, you have very little chance to get success as you will get confused on what works, what doesn't , or any combination !!
Drivers are not that difficult, providing you take them in steps. Get the basics working, then progress to more 'options'. If, for instance, a device allows 8 bit or 12 bit data, choose the 8 bit setup, as it's easier to code and debug to confirm that it is working. Then, code a new version to setup the 12 bit mode of data. Depending on the device the command or data need to be left or right justified or even a bit mask applied to get the right data but by having the 8 bit mode working, any errors will now come from your '12 bit code'.
hth
jay |
|
|
andys
Joined: 23 Oct 2006 Posts: 175
|
Where can I find driver for the sensor SHT25 ? |
Posted: Tue Jul 10, 2012 9:25 pm |
|
|
I have already start to study the driver.
a first question:
There are two define of the pins at the beginning
#define sht_data_pin PIN_D3
#define sht_clk_pin PIN_C4
These pins, are the pins of the microcontroller which will connect the sensor ???? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9216 Location: Greensville,Ontario
|
|
Posted: Wed Jul 11, 2012 5:17 am |
|
|
yes.
Depending on the PIC you choose and whatever other functions you want the PIC to do, you can use that code to 'define' which pins you want the I2C device to be attached to.
Most PICs nowadays have a builtin I2C 'module' or 'peripheral' and most programmers will choose it but the CCS compiler will allow you to use any two bidirectional I/O pins for software I2C.Actually one pin, I2C_clock can be an output only,the other I2C_data needs to be bidirectional.
hth
jay |
|
|
andys
Joined: 23 Oct 2006 Posts: 175
|
Where can I find driver for the sensor SHT25 ? |
Posted: Wed Jul 11, 2012 4:24 pm |
|
|
I did some changes to the driver file of SHT75 to use it for the SHT25 sensor. Because this is the first time that I did something like that I would like, someone to to check it, please.
For every change that I did I put a note ( with symbol //-----------------> at which is write the section which I read information about it). Also I put a note for each function for which I did not put a note.
Code: |
SHT25 (Under test):
///////////////////////////////////////////////////////////////////////////////
// //
// Driver file for SHT75 Temperature & Humidity Sensor //
// //
// ***** To initialise SHT75 sensor upon power up ***** //
// //
// Function : sht_init() //
// Return : none //
// //
// //
// ***** To measure and caluculate SHT75 temp & real RH ***** //
// //
// Function : sht_rd (temp, truehumid) //
// Return : temperature & true humidity in float values //
// //
///////////////////////////////////////////////////////////////////////////////
#define sht_data_pin PIN_D3
#define sht_clk_pin PIN_C4
//***** Function to alert SHT75 *****
void comstart (void) //-------------------------->No change
{
output_float(sht_data_pin); //data high
output_bit(sht_clk_pin, 0); //clk low
delay_us(1);
output_bit(sht_clk_pin, 1); //clk high
delay_us(1);
output_bit(sht_data_pin, 0); //data low
delay_us(1);
output_bit(sht_clk_pin, 0); //clk low
delay_us(2);
output_bit(sht_clk_pin, 1); //clk high
delay_us(1);
output_float(sht_data_pin); //data high
delay_us(1);
output_bit(sht_clk_pin, 0); //clk low
}
//***** Function to write data to SHT75 *****
int1 comwrite (int8 iobyte)
{
int8 i, mask = 0x80; // --------------------------> Why use this?the mask equal to 0X80, Changed or not ?
int1 ack;
//Shift out command
delay_us(4);
for(i=0; i<8; i++)
{
output_bit(sht_clk_pin, 0); //clk low
if((iobyte & mask) > 0) output_float(sht_data_pin); //data high if MSB high
else output_bit(sht_data_pin, 0); //data low if MSB low
delay_us(1);
output_bit(sht_clk_pin, 1); //clk high
delay_us(1);
mask = mask >> 1; //shift to next bit
}
//Shift in ack
output_bit(sht_clk_pin, 0); //clk low
delay_us(1);
ack = input(sht_data_pin); //get ack bit
output_bit(sht_clk_pin, 1); //clk high
delay_us(1);
output_bit(sht_clk_pin, 0); //clk low
return(ack);
}
//***** Function to read data from SHT75 *****
int16 comread (void)
{
int8 i;
int16 iobyte = 0;
const int16 mask0 = 0x0000; //-------------------------->Why use this Changed or not ?
const int16 mask1 = 0x0001; //-------------------------->Why use this Changed or not ?
//shift in MSB data
for(i=0; i<8; i++)
{
iobyte = iobyte << 1;
output_bit(sht_clk_pin, 1); //clk high
delay_us(1);
if (input(sht_data_pin)) iobyte |= mask1; //shift in data bit //-------------------------->Why use this Changed or not ??
else iobyte |= mask0;
output_bit(sht_clk_pin, 0); //clk low
delay_us(1);
}
//send ack 0 bit
output_bit(sht_data_pin, 0); //data low
delay_us(1);
output_bit(sht_clk_pin, 1); //clk high
delay_us(2);
output_bit(sht_clk_pin, 0); //clk low
delay_us(1);
output_float(sht_data_pin); //data high
//shift in LSB data
for(i=0; i<8; i++)
{
iobyte = iobyte << 1;
output_bit(sht_clk_pin, 1); //clk high
delay_us(1);
if (input(sht_data_pin)) iobyte |= mask1; //shift in data bit
else iobyte |= mask0;
output_bit(sht_clk_pin, 0); //clk low
delay_us(1);
}
//send ack 1 bit
output_float(sht_data_pin); //data high
delay_us(1);
output_bit(sht_clk_pin, 1); //clk high
delay_us(2);
output_bit(sht_clk_pin, 0); //clk low
return(iobyte);
}
//***** Function to wait for SHT75 reading *****
void comwait (void)
{
int16 sht_delay;
output_float(sht_data_pin); //data high
output_bit(sht_clk_pin, 0); //clk low
delay_us(1);
for(sht_delay=0; sht_delay<30000; sht_delay++) // wait for max 300ms //--------------------------> Why needs this Changed or not ?
{
if (!input(sht_data_pin)) break; //if sht_data_pin low, SHT75 ready
delay_us(10);
}
}
//***** Function to reset SHT75 communication *****
void comreset (void) //-------------------------->check
{
int8 i;
output_float(sht_data_pin); //data high
output_bit(sht_clk_pin, 0); //clk low
delay_us(2);
for(i=0; i<9; i++)
{
output_bit(sht_clk_pin, 1); //toggle clk 9 times //-------------------------->The 9 times appear at sht75 section 3.4 is ano appear at sht25.
delay_us(2);
output_bit(sht_clk_pin, 0);
delay_us(2);
}
comstart();
}
//***** Function to soft reset SHT75 *****
void sht_soft_reset (void) //-------------------------->Changed the comwrite(0x1e) to comwrite(0xFe) table 4 in Sht75 datasheet and table 6 in sht25 datasheet
{
comreset(); //SHT75 communication reset
//comwrite(0x1e); //send SHT75 reset command
comwrite(0xFe); //send SHT75 reset command
delay_ms(15); //pause 15 ms //--------------------------> I don not know if this is needed.
}
//***** Function to measure SHT75 temperature *****
int16 measuretemp (void) //-------------------------->No change
{
int1 ack;
int16 iobyte;
comstart(); //alert SHT75
ack = comwrite(0x03); //send measure temp command and read ack status
if(ack == 1) return;
comwait(); //wait for SHT75 measurement to complete
iobyte = comread(); //read SHT75 temp data
return(iobyte);
}
//***** Function to measure SHT75 RH *****
int16 measurehumid (void) //-------------------------->No change
{
int1 ack;
int16 iobyte;
comstart(); //alert SHT75
ack = comwrite(0x05); //send measure RH command and read ack status
if(ack == 1) return;
comwait(); //wait for SHT75 measurement to complete
iobyte = comread(); //read SHT75 temp data
return(iobyte);
}
//***** Function to calculate SHT75 temp & RH *****
//void calculate_data (int16 temp, int16 humid, float & tc, float & rhlin, float & rhtrue)
void calculate_data (int16 temp, int16 humid, float & tc, float & RH, float & RHi)
{
float truehumid1, rh;
//calculate temperature reading
//tc = ((float) temp * 0.01) - 40.0; //-------------------------->section4.2 Sht75
tc =175.72*((float) temp/(pow(2,16)))-46.85; //-------------------------->section6.2 Sht25 is this ok?
//calculate Real RH reading
rh = (float) humid;
//rhlin = (rh * 0.0405) - (rh * rh * 0.0000028) - 4.0; //-------------------------->section4.2 Sht75
RH=125*(rh/(pow(2,16))) -6; //-------------------------->section6.1 Sht25 is this ok?
//calculate True RH reading
//rhtrue= ((tc - 25.0) * (0.01 + (0.00008 * rh))) + rhlin; //-------------------------->section4.2 Sht75
RHi=RH((tc*17.62)/(243.12+tc))/((tc*22.46)/(272.62+tc)); //-------------------------->section6.1 Sht25 is this ok?
}
//***** Function to measure & calculate SHT75 temp & RH *****
void sht_rd (float & temp, float & truehumid)//-------------------------->No change
{
int16 restemp, reshumid;
float realhumid;
restemp = 0; truehumid = 0;
restemp = measuretemp(); //measure temp
reshumid = measurehumid(); //measure RH
calculate_data (restemp, reshumid, temp, realhumid, truehumid); //calculate temp & RH
}
//***** Function to initialise SHT75 on power-up *****
void sht_init (void)
{
comreset(); //reset SHT75
delay_ms(20); //delay for power-up //------------------->section 3.3 at sht75
} |
The 2 datasheets
SHT75:
http://elcodis.com/parts/2271661/SHT75.html#datasheet
SHT25:
http://elcodis.com/parts/5618489/SHT25.html#datasheet |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Thu Jul 12, 2012 7:39 am |
|
|
so , how is that working for you ?? |
|
|
andys
Joined: 23 Oct 2006 Posts: 175
|
Where can I find driver for the sensor SHT25 ? |
Posted: Thu Jul 12, 2012 7:44 am |
|
|
I don't have test it with hardware?
Before test it with hardware, is it look like ok?
There is any way to test it without hardware? |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Thu Jul 12, 2012 8:58 am |
|
|
hardware testing is the ONLY way that matters in the end.
the procedure:
do{
1- (re) design circuit
2- (re) write program
3- build || alter hardware
4- test
} while (!working); |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Fri Jul 13, 2012 2:19 pm |
|
|
Quote: | hardware testing is the ONLY way that matters in the end.
|
Yes. Support that 100%.
Mike |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|