Pessoal boa tarde, estou tentando ligar um sensor de umidade HIH-4004 e um fotodiodo no ds2438, ja peguei um exemplo da net mas não funciona de jeito algum, se alguém que ja tenha mexido neste sensor pode me dar uma luz por favor!!

estou usando o ARDUINO R3 para ler a rede on wire, 

estou usando esta biblioteca:

DS2438.CPP

#include "DS2438.h"

ds2438::ds2438(OneWire* _oneWire, uint8_t* deviceAddress)
{
_wire = _oneWire;
_deviceAddress = deviceAddress;
}

bool ds2438::writeSetup(uint8_t config)
{
//write config to scratchpad
_wire->reset();
_wire->select(_deviceAddress);
_wire->write(WRITESCRATCH, 0);
_wire->write(0x00, 0); //write to first block
_wire->write(config, 0);

//confirm good write
_wire->reset();
_wire->select(_deviceAddress);
_wire->write(READSCRATCH, 0);
_wire->write(0x00, 0);

uint8_t compare = _wire->read();

if ( compare != config) return 0;

_wire->reset();
_wire->select(_deviceAddress);
_wire->write(COPYSCRATCH, 0);
_wire->write(0x00, 0);
delay(20);

return 1;
}

uint8_t ds2438::readSetup()
{
ScratchPad _scratchPad;
_readMem(_scratchPad);

return _scratchPad[0];
}

float ds2438::readHum()
{
// humidity can be calculated via two methods with the HIH-4010
//VOUT=(VSUPPLY)(0.0062(sensor RH) + 0.16), typical at 25 ºC
//((vout / vsupply) - 0.16)/0.0062 = RH @ 25 ºC
//or temp compensated:
//True RH = (Sensor RH)/(1.0546 – 0.00216T), T in ºC

float nowTemp = readTempC();

writeSetup(0x0F); // read source voltage for formula
float sourceVolt = readVolt();

writeSetup(0x00); // back to humidity voltage
float sensorVolt = readVolt();

float stdHum = ((sensorVolt / sourceVolt) - 0.16) / 0.0062;
float trueHum = stdHum / (1.0546 - (0.00216 * nowTemp));

return trueHum;
}

float ds2438::readTempC()
{
//override for now, plsfixkthx
_parasite = 1;

//request temp conversion
_wire->reset();
_wire->select(_deviceAddress);
_wire->write(CONVERTT, _parasite);
delay(20);

//copy data from eeprom to scratchpad & read scratchpad
ScratchPad _scratchPad;
_readMem(_scratchPad);

//return tempC (ignore 3 lsb as they are always 0);
int16_t rawTemp = ( ((int16_t)_scratchPad[TEMP_MSB]) 5) | (_scratchPad[TEMP_LSB] >> 3);

return (float)rawTemp * 0.03125;
}

float ds2438::readTempF()
{
return (readTempC() * 1.8) + 32;
}

float ds2438::readVolt()
{
//override for now, plsfixkthx
_parasite = 1;

//request temp conversion
_wire->reset();
_wire->select(_deviceAddress);
_wire->write(CONVERTV, _parasite);
delay(10);

//copy data from eeprom to scratchpad & read scratchpad
ScratchPad _scratchPad;
_readMem(_scratchPad);

//return tempC (ignore 3 lsb as they are always 0);
int16_t rawVolt = ( ((int16_t)_scratchPad[VOLT_MSB]) 8) | _scratchPad[VOLT_LSB];

return (float)rawVolt * 0.01;
}


void ds2438::_readMem(uint8_t* _scratchPad)
{
_wire->reset();
_wire->select(_deviceAddress);
_wire->write(RECALLSCRATCH);
_wire->write(0x00); // starting at address 0x00

_wire->reset();
_wire->select(_deviceAddress);
_wire->write(READSCRATCH);
_wire->write(0x00); // starting at address 0x00

_scratchPad[STATUS] = _wire->read();
_scratchPad[TEMP_LSB] = _wire->read();
_scratchPad[TEMP_MSB] = _wire->read();
_scratchPad[VOLT_LSB] = _wire->read();
_scratchPad[VOLT_MSB] = _wire->read();
_scratchPad[CURR_LSB] = _wire->read();
_scratchPad[CURR_MSB] = _wire->read();
_scratchPad[THRESH] = _wire->read();
}

DS2438.h

#ifndef DS2438_h
#define DS2438_h

/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see a href="http://www.gnu.org/licenses/>">http://www.gnu.org/licenses/>;.

Copyright 2010 Guilherme Barros
*/


#include <OneWire.h>

#define DS2438MODEL 0x26

#define WRITESCRATCH 0x4E
#define COPYSCRATCH 0x48
#define READSCRATCH 0xBE
#define RECALLSCRATCH 0xB8
#define CONVERTT 0x44
#define CONVERTV 0xB4

// Scratchpad locations
#define STATUS 0
#define TEMP_LSB 1
#define TEMP_MSB 2
#define VOLT_LSB 3
#define VOLT_MSB 4
#define CURR_LSB 5
#define CURR_MSB 6
#define THRESH 7


typedef uint8_t DeviceAddress[8];

class ds2438
{
public:
ds2438(OneWire*, uint8_t*);
float readTempF();
float readTempC();
float readVolt();
uint8_t readSetup();
bool writeSetup(uint8_t);
float readHum();

private:
OneWire* _wire;
uint8_t* _deviceAddress;
typedef uint8_t ScratchPad[9];
bool _parasite;
void _readMem(uint8_t*);
};
#endif

O programa ficou assim:

#include <OneWire.h>
#include <DS2438.h>

OneWire oneWire(7);

DeviceAddress hum1_addy = { 0x26, 0xC3, 0xD8, 0x0B, 0x01, 0x00, 0x00, 0xF8 };

ds2438 hum1(&oneWire, hum1_addy);

void setup(void)
{
Serial.begin(9600);

printAddress(hum1_addy);
Serial.println();
Serial.print("Initial config: ");
Serial.println(hum1.readSetup(), BIN);
hum1.writeSetup(0x00);
Serial.print("New config: ");
Serial.println(hum1.readSetup(), BIN);

delay(1000);
}

void loop(void)
{
printAddress(hum1_addy);
Serial.print(" ");
Serial.print(hum1.readTempF());
Serial.print("F ");
Serial.print(hum1.readVolt());
Serial.print("v ");
Serial.print(hum1.readHum());
Serial.println("% RH");


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(".");
}
}

Mas não le nada!!!

Se alguém poder me ajudar eu agradeço!!

Exibições: 315

Responder esta

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço