Wire.h conflict with VirtualWire, SoftwareSerial and RH_ASK.h
first of all, thank time reading this.
it realy appreciated!
i measure ph aquarium follwing board , arduino nano:
http://rezaalihussain.blogspot.nl/2014/04/measuring-ph-using-dormant-labs-ph.html
the sketch provided reza works fine on own 1 of libraries mentioned in titel used ph output goes "inf"
main code provided reza:
in past tried include softwareserial (for reason can't remember) skipped since sketch above stopped working.
this time trying use virtualwire library (rf 433) on same arduino again same issue had before.
tried radiohead library (ask) alternative same issue:
http://www.airspayce.com/mikem/arduino/radiohead/index.html
serial output stand alone:
serial output when using once of libraries:
i tried , tried skill alre lacking solve one.
reza did not reply try luck here.
thank in advance.
it realy appreciated!
i measure ph aquarium follwing board , arduino nano:
http://rezaalihussain.blogspot.nl/2014/04/measuring-ph-using-dormant-labs-ph.html
the sketch provided reza works fine on own 1 of libraries mentioned in titel used ph output goes "inf"
main code provided reza:
code: [select]
#include <wire.h>
#define phaddress 0x4d
int roomtempi2caddress = b1001011;
float volt4 = 0.95;
float volt7 = 0.67;
float calibrationtempc = 20;
void setup()
{
}
void loop()
{
wire.begin(); //connects i2c
serial.begin(9600);
serial.print("avgmeasuredph-");
setroomtemperataureresolutionbits(12);//12 bits room temp resolution in celcius
int samplesize = 500;
double avgmeasuredph = 0;
double avgroomtempc = 0;
double avgphvolts = 0;
double avgroomtemperaturecompensatedmeasuredph = 0;
double tempadjusted4;
int x;
for(x=0;x< samplesize;x++)
{
double phvolt = getphvolts();
tempadjusted4 = adjustphbasedontemp(4,calibrationtempc);
double voltsperph = (abs(volt7-volt4)) / (7-tempadjusted4);
double realphvolt = (volt7 - phvolt);
double phunits = realphvolt / voltsperph;
double measuredph = 7 + phunits;
double roomtempc = getroomtemperaturec();
double roomtempcompensatedmeasuredph = adjustphbasedontemp(measuredph,roomtempc);
avgmeasuredph+=measuredph;
avgroomtemperaturecompensatedmeasuredph+=roomtempcompensatedmeasuredph;
avgroomtempc+=roomtempc;
avgphvolts += phvolt;
}
avgmeasuredph/=samplesize;
avgroomtemperaturecompensatedmeasuredph/=samplesize;
avgroomtempc/=samplesize;
avgphvolts/=samplesize;
serial.print("avgmeasuredph-");
serial.print(avgmeasuredph,4);
serial.print(" roomtempcompensatedph-");
serial.print(avgroomtemperaturecompensatedmeasuredph,4);
serial.print(" avgroomttempc-");
serial.print(avgroomtempc,4);
serial.print(" avgphvolts-");
serial.print(avgphvolts,4);
serial.print(" 7calvolts-");
serial.print(volt7,4);
serial.print(" 4calvolts-");
serial.print(volt4,4);
serial.print(" 4caltempadjusted-");
serial.println(tempadjusted4,4);
delay(1000);
}
float adjustphbasedontemp(float ph, float temp)
{
// http://www.omega.com/green/pdf/phbasics_ref.pdf
// when temperature other 25degc , ph other 7
// temperature error 0.03ph error/ph unit/10degc
// means error = 0.03*(ph away 7)*(tempdiffc/10)
float phdifference = abs(ph-7);
float tempdifferencec = abs(temp-25);
float phadjust = (0.03*phdifference)*(tempdifferencec/10);
if(ph>7 && temp<25)
phadjust=phadjust;
if(ph>7 && temp>25)
phadjust=phadjust*-1;
if(ph<7 && temp>25)
phadjust=phadjust;
if(ph<7 && temp<25)
phadjust=phadjust*-1;
float tempadjustedph = ph + phadjust;
return tempadjustedph;
}
double getphvolts()
{
byte ad_high;
byte ad_low;
wire.requestfrom(phaddress, 2); //requests 2 bytes
while(wire.available() < 2); //while 2 bytes receive
ad_high = wire.read();
ad_low = wire.read();
double units = (ad_high * 256) + ad_low;
double volts = (units /4096)*3;
return volts;
}
double getroomtemperaturec()
{
wire.requestfrom(roomtempi2caddress,2);
byte msb = wire.read();
byte lsb = wire.read();
int temperaturesum = ((msb << 8) | lsb) >> 4;
double celsius = temperaturesum*0.0625;
return celsius;
}
void setroomtemperataureresolutionbits(int resolutionbits)
{
if (resolutionbits < 9 || resolutionbits > 12) exit;
wire.begintransmission(roomtempi2caddress);
wire.write(b00000001); //addresses configuration register
wire.write((resolutionbits-9) << 5); //writes resolution bits
wire.endtransmission();
wire.begintransmission(roomtempi2caddress); //resets reading temperature
wire.write((byte)0x00);
wire.endtransmission();
}
in past tried include softwareserial (for reason can't remember) skipped since sketch above stopped working.
this time trying use virtualwire library (rf 433) on same arduino again same issue had before.
tried radiohead library (ask) alternative same issue:
http://www.airspayce.com/mikem/arduino/radiohead/index.html
serial output stand alone:
code: [select]
avgmeasuredph-avgmeasuredph-6.9461 roomtempcompensatedph-6.9465 avgroomttempc-27.7500 avgphvolts-0.6750 7calvolts-0.6700 4calvolts-0.9500 4caltempadjusted-3.9550
serial output when using once of libraries:
code: [select]
avgmeasuredph-avgmeasuredph-inf roomtempcompensatedph-inf avgroomttempc-27.8981 avgphvolts-0.6755 7calvolts-0.6700 4calvolts-0.9500 4caltempadjusted-3.9550
i tried , tried skill alre lacking solve one.
reza did not reply try luck here.
thank in advance.
quote
as 1 of libraries mentioned in titel usedused what?
the wire library should not conflict of other packages.
Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > Wire.h conflict with VirtualWire, SoftwareSerial and RH_ASK.h
arduino
Comments
Post a Comment