Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

36
#include "etherShield.h" // Stokerfyrs Arduino 131009 med ethershield fra nuelectronics.com // Pellet boiler datalogger v1 //------------------------------------------------------------------------ // Maaler kedel temperatur og temperatur ude og // Traepille niveau med ultralyd. // // V1: language Danish, sorry , v2 will be in english // // Licens type:GNU GPL http://www.gnu.org/licenses/quick-guide-gplv3.html// // Author: michael pedersen http://mynerdstuff.blogspot.com/2011/10/arduino-pellet-boiler-data-logger-and.html // ------------------------------------------------------------------------ // // 051209: isdigit check af ultralyds m ler // // please modify the following lines. mac and ip have to be unique // in your local area network. You can not have the same numbers in // two devices: static uint8_t mymac[6] = {0x54,0x55,0x58,0x22,0x22,0x22}; static uint8_t myip[4] = {192,168,2,22}; //arduino ethershield ip adresse static uint16_t my_port = 1200; // client port // client_ip - modify it when you have multiple client on the network // for server to distinguish each ethershield client static char client_ip[] = "192.168.2.22"; // arduino ethernet ip adresse // server settings - modify the service ip to your own server static uint8_t dest_ip[4]={192,168,2,100};//websever ip adresse, husk der skal noget php / asp kode til for at fange data. Data placed here on webserver, in a file called save.php, read more on nuelectronic homepage about this: /temperatur_log/save.php static uint8_t dest_mac[6]; enum CLIENT_STATE { IDLE, ARP_SENT, ARP_REPLY, SYNC_SENT

Transcript of Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

Page 1: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

#include "etherShield.h"// Stokerfyrs Arduino 131009 med ethershield fra nuelectronics.com// Pellet boiler datalogger v1//------------------------------------------------------------------------// Maaler kedel temperatur og temperatur ude og// Traepille niveau med ultralyd.//// V1: language Danish, sorry , v2 will be in english//// Licens type:GNU GPL http://www.gnu.org/licenses/quick-guide-gplv3.html// // Author: michael pedersen http://mynerdstuff.blogspot.com/2011/10/arduino-pellet-boiler-data-logger-and.html// ------------------------------------------------------------------------//// 051209: isdigit check af ultralyds m ler�//// please modify the following lines. mac and ip have to be unique// in your local area network. You can not have the same numbers in// two devices:static uint8_t mymac[6] = {0x54,0x55,0x58,0x22,0x22,0x22}; static uint8_t myip[4] = {192,168,2,22}; //arduino ethershield ip adressestatic uint16_t my_port = 1200; // client port

// client_ip - modify it when you have multiple client on the network// for server to distinguish each ethershield clientstatic char client_ip[] = "192.168.2.22"; // arduino ethernet ip adresse

// server settings - modify the service ip to your own serverstatic uint8_t dest_ip[4]={192,168,2,100};//websever ip adresse, husk der skal noget php / asp kode til for at fange data. Data placed here on webserver, in a file called save.php, read more on nuelectronic homepage about this: /temperatur_log/save.phpstatic uint8_t dest_mac[6];

enum CLIENT_STATE{ IDLE, ARP_SENT, ARP_REPLY, SYNC_SENT

Page 2: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

}; static CLIENT_STATE client_state;

static uint8_t client_data_ready;

static uint8_t syn_ack_timeout = 0;

#define isdigit(X) (((X) >= '0') && ((X) <= '9'))#define BUFFER_SIZE 500static uint8_t buf[BUFFER_SIZE+1];

char sensorData[10];

EtherShield es=EtherShield();

// prepare the webpage by writing the data to the tcp send bufferuint16_t print_webpage(uint8_t *buf);int8_t analyse_cmd(char *str);// get current temperature#define TEMP_PIN 5// peltier heat source temperatur#define TEMP_PIN_PS 6 #define TEMP_PIN1 8int sensor = 0; void getCurrentTemp( char *temperature);void getCurrentTemp1( char *temperature);void client_process(void);void getcurrent0(char *current); // stdvoid getcurrent1(char *current); // stdvoid getcurrent2(char *current); // stdvoid getcurrent3(char *current); // stdvoid getcurrent4(char *current); // stdvoid getcurrent5(char *current); // std

Page 3: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

void getcurrent6(char *current); // stdvoid getCurrentTempPs(char *temp); // temperatur peltier heat sourcevoid getdummy2(char *temp); // dummyvoid getdummy3(char *temp); // dummyvoid getdummy4(char *temp); // dummyvoid getdummy5(char *temp); // dummy

//---- ultrasonic -- Variabler -- start/* Ultrasound Sensor*------------------* URM V3.2 ultrasonic sensor TTL connection with Arduino* Reads values (0-300) from an ultrasound sensor (3m sensor)* and writes the values to the serialport.* Pin4 (Arduino)-> Pin 1 VCC (URM V3.2)* GND (Arduino) -> Pin 2 GND (URM V3.2)* Pin3 (Arduino) -> Pin 7 (URM V3.2)* Pin 0 (Arduino) -> Pin 9 (URM V3.2)* Pin 1 (Arduino) -> Pin 8 (URM V3.2)* www.yerobot.com* Last modified 20/04/2009*/

int UREnable = 3; // 11 Ultrasound enable pinint URPower = 4; // 12 Ultrasound power pinint val = 0;//int USValue = 0;int timecount = 0; // Echo counter//int ledPin = 13; // LED connected to digital pin 13boolean flag=true;uint8_t DMcmd[4] = { 0x22, 0x00, 0x00, 0x22}; //distance measure command//---- ultrasonic -- Variabler -- slutint errorcounter =0;

Page 4: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

void setup(){ // Ultrasonic -- initialize -- start Serial.begin(9600); // Sets the baud rate to 9600// pinMode(ledPin, OUTPUT); // Sets the digital pin as output pinMode(UREnable, OUTPUT); digitalWrite(UREnable, HIGH); // Set to High pinMode(URPower, OUTPUT); digitalWrite(URPower, HIGH); // Set to Highdelay(200); //Give sensor some time to start up --Added By crystal from Singapo, Thanks Crystal. // Ultreasonic -- initialize -- slut

/*initialize enc28j60*/

es.ES_enc28j60Init(mymac); es.ES_enc28j60clkout(2); // change clkout from 6.25MHz to 12.5MHz delay(10);

/* Magjack leds configuration, see enc28j60 datasheet, page 11 */// LEDA=greed LEDB=yellow//// 0x880 is PHLCON LEDB=on, LEDA=on// enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00);es.ES_enc28j60PhyWrite(PHLCON,0x880);delay(500);//// 0x990 is PHLCON LEDB=off, LEDA=off// enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00);es.ES_enc28j60PhyWrite(PHLCON,0x990);delay(500);//// 0x880 is PHLCON LEDB=on, LEDA=on// enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00);es.ES_enc28j60PhyWrite(PHLCON,0x880);

Page 5: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

delay(500);//// 0x990 is PHLCON LEDB=off, LEDA=off// enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00);es.ES_enc28j60PhyWrite(PHLCON,0x990);delay(500);//

// 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit // enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10); es.ES_enc28j60PhyWrite(PHLCON,0x476);

delay(100); //init the ethernet/ip layer: es.ES_init_ip_arp_udp_tcp(mymac,myip,80); // intialize varible; syn_ack_timeout =0; client_data_ready = 0; client_state = IDLE; // initialize DS18B20 datapin digitalWrite(TEMP_PIN, LOW); pinMode(TEMP_PIN, INPUT); // sets the digital pin as input (logic 1), temperatur sensor stoker digitalWrite(TEMP_PIN1, LOW); pinMode(TEMP_PIN1, INPUT); // sets the digital pin as input (logic 1), temperatur sensor ude

}

void loop(){

if(client_data_ready==0){

Page 6: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

sensor = sensor + 1; if (sensor > 13) //8 oprindeligt, updateres naar der tilfoejes en sensor { sensor =0; delay(60000); delay(60000); } getCurrentTemp(sensorData); // 01 Temperatur stoker kedel

switch (sensor) { case 0: getCurrentTemp(sensorData); // 01 Temperatur stoker kedel /* if isdigit(sensorData[7]) { } else { while (errorcounter <= 3) { getCurrentTemp(sensorData); if isdigit(sensorData[7]) { errorcounter=4; } } } */ break; case 1: getCurrentTemp1(sensorData); // 02 Temperatur ude

Page 7: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

break; case 2: getcurrent0(sensorData); // 03 break; case 3: getcurrent1(sensorData); // 04 break; case 4: getcurrent2(sensorData); // 05 break; case 5: getcurrent3(sensorData); // 06 break; case 6: getcurrent4(sensorData); // 07 break; case 7: getcurrent5(sensorData); // 08 break; case 8: getCurrentTempPs(sensorData); // 09 peltier heat source break; case 9: getdummy2(sensorData); // 10 dummy break; case 10: getdummy3(sensorData); // 11 dummy break; case 11: getdummy4(sensorData); // 12 dummy break; case 12: getCurrentLevel(sensorData); // 13 traepille niveau

Page 8: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

break; case 13: getdummy5(sensorData); // 14 dummy break; } client_data_ready = 1; }

client_process();//delay(60000UL); // delay 60s }

uint16_t gen_client_request(uint8_t *buf ){

uint16_t plen;byte i;

plen= es.ES_fill_tcp_data_p(buf,0, PSTR ( "GET /temperatur_log/save.php?pwd=secret&client=" ) );

for(i=0; client_ip[i]!='\0'; i++){ buf[TCP_DATA_P+plen]=client_ip[i]; plen++; }switch (sensor) { case 0: plen= es.ES_fill_tcp_data_p(buf,plen, PSTR ( "&status=temperatur-stoker" ) ); break;

case 1: plen= es.ES_fill_tcp_data_p(buf,plen, PSTR ( "&status=temperatur----ude" ) );

Page 9: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

break; case 2: plen= es.ES_fill_tcp_data_p(buf,plen, PSTR ( "&status=current---------1" ) ); break; case 3: plen= es.ES_fill_tcp_data_p(buf,plen, PSTR ( "&status=current---------2" ) ); break; case 4: plen= es.ES_fill_tcp_data_p(buf,plen, PSTR ( "&status=current---------3" ) ); break; case 5: plen= es.ES_fill_tcp_data_p(buf,plen, PSTR ( "&status=current---------4" ) ); break; case 6: plen= es.ES_fill_tcp_data_p(buf,plen, PSTR ( "&status=current---------5" ) ); break; case 7: plen= es.ES_fill_tcp_data_p(buf,plen, PSTR ( "&status=current---------6" ) ); break; case 8: plen= es.ES_fill_tcp_data_p(buf,plen, PSTR ( "&status=peltierheatsource" ) ); break; case 9: plen= es.ES_fill_tcp_data_p(buf,plen, PSTR ( "&status=current-----dummy" ) ); break; case 10: plen= es.ES_fill_tcp_data_p(buf,plen, PSTR ( "&status=current-----dummy" ) ); break; case 11: plen= es.ES_fill_tcp_data_p(buf,plen, PSTR ( "&status=current-----dummy" ) ); break; case 12: plen= es.ES_fill_tcp_data_p(buf,plen, PSTR ( "&status=pille------niveau" ) ); break;

Page 10: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

case 13: plen= es.ES_fill_tcp_data_p(buf,plen, PSTR ( "&status=current-----dummy" ) ); break; }

// plen= es.ES_fill_tcp_data_p(buf,plen, PSTR ( "&status=temperature-" ) );

for(i=0; sensorData[i]!='\0'; i++){ buf[TCP_DATA_P+plen]=sensorData[i]; plen++; }

plen= es.ES_fill_tcp_data_p(buf, plen, PSTR ( " HTTP/1.0\r\n" ));plen= es.ES_fill_tcp_data_p(buf, plen, PSTR ( "Host: 192.168.1.4\r\n" ));plen= es.ES_fill_tcp_data_p(buf, plen, PSTR ( "User-Agent: AVR ethernet\r\n" ));

plen= es.ES_fill_tcp_data_p(buf, plen, PSTR ( "Accept: text/html\r\n" ));plen= es.ES_fill_tcp_data_p(buf, plen, PSTR ( "Keep-Alive: 300\r\n" ));plen= es.ES_fill_tcp_data_p(buf, plen, PSTR ( "Connection: keep-alive\r\n\r\n" ));

return plen;}

//*****************************************************************************************//// Function : client_process// Description : send temparature to web server, this option is disabled by default.// YOU MUST install webserver and server script before enable this option,

Page 11: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

// I recommented Apache webserver and PHP script.// More detail about Apache and PHP installation please visit http://www.avrportal.com/////*****************************************************************************************void client_process ( void ){ uint16_t plen;

uint8_t i;

if (client_data_ready == 0) return; // nothing to send

if(client_state == IDLE){ // initialize ARP es.ES_make_arp_request(buf, dest_ip);

client_state = ARP_SENT; return;}

if(client_state == ARP_SENT){ plen = es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf);

// destination ip address was found on network if ( plen!=0 ) { if ( es.ES_arp_packet_is_myreply_arp ( buf ) ){ client_state = ARP_REPLY;

syn_ack_timeout=0;return;

}

} delay(10);

Page 12: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

syn_ack_timeout++;

if(syn_ack_timeout== 100) { //timeout, server ip not foundclient_state = IDLE;client_data_ready =0;syn_ack_timeout=0;return;

} }

// send SYN packet to initial connectionif(client_state == ARP_REPLY){

// save dest macfor(i=0; i<6; i++){

dest_mac[i] = buf[ETH_SRC_MAC+i];}

es.ES_tcp_client_send_packet ( buf, 80, 1200, TCP_FLAG_SYN_V, // flag 1, // (bool)maximum segment size 1, // (bool)clear sequence ack number 0, // 0=use old seq, seqack : 1=new seq,seqack no data : new seq,seqack with data 0, // tcp data length

dest_mac, dest_ip

);

client_state = SYNC_SENT;

Page 13: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

} // get new packet if(client_state == SYNC_SENT){ plen = es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf);

// no new packet incoming if ( plen == 0 ) { return; }

// check ip packet send to avr or not? // accept ip packet only if ( es.ES_eth_type_is_ip_and_my_ip(buf,plen)==0){

return; }

// check SYNACK flag, after AVR send SYN server response by send SYNACK to AVR if ( buf [ TCP_FLAGS_P ] == ( TCP_FLAG_SYN_V | TCP_FLAG_ACK_V ) ) {

// send ACK to answer SYNACK

es.ES_tcp_client_send_packet ( buf, 80, 1200, TCP_FLAG_ACK_V, // flag 0, // (bool)maximum segment size 0, // (bool)clear sequence ack number 1, // 0=use old seq, seqack : 1=new seq,seqack no data : new seq,seqack with data 0, // tcp data length

dest_mac,dest_ip

Page 14: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

); // setup http request to server plen = gen_client_request( buf ); // send http request packet // send packet with PSHACK es.ES_tcp_client_send_packet ( buf, 80, // destination port 1200, // source port TCP_FLAG_ACK_V | TCP_FLAG_PUSH_V, // flag 0, // (bool)maximum segment size 0, // (bool)clear sequence ack number 0, // 0=use old seq, seqack : 1=new seq,seqack no data : >1 new seq,seqack with data plen, // tcp data length dest_mac,

dest_ip );

return; } // after AVR send http request to server, server response by send data with PSHACK to AVR // AVR answer by send ACK and FINACK to server if ( buf [ TCP_FLAGS_P ] == (TCP_FLAG_ACK_V|TCP_FLAG_PUSH_V) ) { plen = es.ES_tcp_get_dlength( (uint8_t*)&buf );

// send ACK to answer PSHACK from server es.ES_tcp_client_send_packet ( buf, 80, // destination port 1200, // source port TCP_FLAG_ACK_V, // flag 0, // (bool)maximum segment size 0, // (bool)clear sequence ack number plen, // 0=use old seq, seqack : 1=new seq,seqack no data : >1 new seq,seqack with data

Page 15: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

0, // tcp data length dest_mac, dest_ip

);; // send finack to disconnect from web server

es.ES_tcp_client_send_packet ( buf, 80, // destination port 1200, // source port TCP_FLAG_FIN_V|TCP_FLAG_ACK_V, // flag 0, // (bool)maximum segment size 0, // (bool)clear sequence ack number 0, // 0=use old seq, seqack : 1=new seq,seqack no data : >1 new seq,seqack with data 0,

dest_mac,dest_ip

);

return; } // answer FINACK from web server by send ACK to web server if ( buf [ TCP_FLAGS_P ] == (TCP_FLAG_ACK_V|TCP_FLAG_FIN_V) ) { // send ACK with seqack = 1 es.ES_tcp_client_send_packet(

buf, 80, // destination port 1200, // source port TCP_FLAG_ACK_V, // flag 0, // (bool)maximum segment size 0, // (bool)clear sequence ack number

Page 16: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

1, // 0=use old seq, seqack : 1=new seq,seqack no data : >1 new seq,seqack with data 0,

dest_mac, dest_ip

);client_state = IDLE; // return to IDLE stateclient_data_ready =0; // client data sent

} } }

void OneWireReset(int Pin) // reset. Should improve to act as a presence pulse{ digitalWrite(Pin, LOW); pinMode(Pin, OUTPUT); // bring low for 500 us delayMicroseconds(500); pinMode(Pin, INPUT); delayMicroseconds(500);}

void OneWireOutByte(int Pin, byte d) // output byte d (least sig bit first).{ byte n;

for(n=8; n!=0; n--) { if ((d & 0x01) == 1) // test least sig bit { digitalWrite(Pin, LOW); pinMode(Pin, OUTPUT); delayMicroseconds(5); pinMode(Pin, INPUT); delayMicroseconds(60); }

Page 17: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

else { digitalWrite(Pin, LOW); pinMode(Pin, OUTPUT); delayMicroseconds(60); pinMode(Pin, INPUT); }

d=d>>1; // now the next bit is in the least sig bit position. } }

byte OneWireInByte(int Pin) // read byte, least sig byte first{ byte d, n, b;

for (n=0; n<8; n++) { digitalWrite(Pin, LOW); pinMode(Pin, OUTPUT); delayMicroseconds(5); pinMode(Pin, INPUT); delayMicroseconds(5); b = digitalRead(Pin); delayMicroseconds(50); d = (d >> 1) | (b<<7); // shift d to right and insert b in most sig bit position } return(d);}// dummy routine, void getdummy1(char *temp){ //database felt nummer 09 - > nu gettemperaturPS

Page 18: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

temp[0] = '0'; temp[1] = '9';//dummy data temp[2]= '0' ;

temp[3]= '0' ;temp[4]= '0';

temp[5]='0';temp[6]='0';temp[7]='0';

delay(1000UL); // delay 30 sec}// dummy routinevoid getdummy2(char *temp){ //database felt nummer 10 temp[0] = '1'; temp[1] = '0';//dummy data temp[2]= '0' ;

temp[3]= '0' ;temp[4]= '0';

temp[5]='0';temp[6]='0';temp[7]='0';

delay(1000UL); // delay 30 sec}// dummy routinevoid getdummy3(char *temp){ //database felt nummer 11 temp[0] = '1'; temp[1] = '1';

Page 19: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

//dummy data temp[2]= '0' ;

temp[3]= '0' ;temp[4]= '0';

temp[5]='0';temp[6]='0';temp[7]='0';

delay(1000UL); // delay 30 sec}// dummy routinevoid getdummy4(char *temp){ //database felt nummer 12 temp[0] = '1'; temp[1] = '2';//dummy data temp[2]= '0' ;

temp[3]= '0' ;temp[4]= '0';

temp[5]='0';temp[6]='0';temp[7]='0';

delay(1000UL); // delay 30 sec} // dummy routinevoid getdummy5(char *temp){ //database felt nummer 14 temp[0] = '1'; temp[1] = '4';//dummy data temp[2]= '0' ;

temp[3]= '0' ;

Page 20: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

temp[4]= '0';

temp[5]='0';temp[6]='0';temp[7]='0';

delay(1000UL); // delay 30 sec}

//stoker kedel temperaturvoid getCurrentTemp(char *temp){ int HighByte, LowByte, TReading, Tc_100, sign, whole, fract;

OneWireReset(TEMP_PIN); OneWireOutByte(TEMP_PIN, 0xcc); OneWireOutByte(TEMP_PIN, 0x44); // perform temperature conversion, strong pullup for one sec

OneWireReset(TEMP_PIN); OneWireOutByte(TEMP_PIN, 0xcc); OneWireOutByte(TEMP_PIN, 0xbe);

LowByte = OneWireInByte(TEMP_PIN); HighByte = OneWireInByte(TEMP_PIN); TReading = (HighByte << 8) + LowByte; sign = TReading & 0x8000; // test most sig bit if (sign) // negative { TReading = (TReading ^ 0xffff) + 1; // 2's comp } Tc_100 = (6 * TReading) + TReading / 4; // multiply by (100 * 0.0625) or 6.25

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

Page 21: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

if(sign) temp[2]='-';else temp[2]='+';

//database felt nummer 01 temp[0] = '0'; temp[1] = '1';//temperaturen

temp[3]= (whole-(whole/100)*100)/10 +'0' ;temp[4]= whole-(whole/10)*10 +'0';

temp[5]='.';temp[6]=fract/10 +'0';temp[7]=fract-(fract/10)*10 +'0';

}

// temperatur udevoid getCurrentTemp1(char *temp){ int HighByte, LowByte, TReading, Tc_100, sign, whole, fract;

OneWireReset(TEMP_PIN1); OneWireOutByte(TEMP_PIN1, 0xcc); OneWireOutByte(TEMP_PIN1, 0x44); // perform temperature conversion, strong pullup for one sec

OneWireReset(TEMP_PIN1); OneWireOutByte(TEMP_PIN1, 0xcc); OneWireOutByte(TEMP_PIN1, 0xbe);

LowByte = OneWireInByte(TEMP_PIN1); HighByte = OneWireInByte(TEMP_PIN1); TReading = (HighByte << 8) + LowByte;

Page 22: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

sign = TReading & 0x8000; // test most sig bit if (sign) // negative { TReading = (TReading ^ 0xffff) + 1; // 2's comp } Tc_100 = (6 * TReading) + TReading / 4; // multiply by (100 * 0.0625) or 6.25

whole = Tc_100 / 100; // separate off the whole and fractional portions fract = Tc_100 % 100; if(sign) temp[2]='-';

else temp[2]='+';

//database felt nummer 02 temp[0] = '0'; temp[1] = '2';//temperaturen

temp[3]= (whole-(whole/100)*100)/10 +'0' ;temp[4]= whole-(whole/10)*10 +'0';

temp[5]='.';temp[6]=fract/10 +'0';temp[7]=fract-(fract/10)*10 +'0';

/*if(sign) temp[0]='-';else temp[0]='+';

temp[1]= (whole-(whole/100)*100)/10 +'0' ;temp[2]= whole-(whole/10)*10 +'0';

temp[3]='.';temp[4]=fract/10 +'0';

Page 23: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

temp[5]=fract-(fract/10)*10 +'0';

temp[6] = '\0';*/}

// temperatur peltier heat sourcevoid getCurrentTempPs(char *temp){ int HighByte, LowByte, TReading, Tc_100, sign, whole, fract;

OneWireReset(TEMP_PIN_PS); OneWireOutByte(TEMP_PIN_PS, 0xcc); OneWireOutByte(TEMP_PIN_PS, 0x44); // perform temperature conversion, strong pullup for one sec

OneWireReset(TEMP_PIN_PS); OneWireOutByte(TEMP_PIN_PS, 0xcc); OneWireOutByte(TEMP_PIN_PS, 0xbe);

LowByte = OneWireInByte(TEMP_PIN_PS); HighByte = OneWireInByte(TEMP_PIN_PS); TReading = (HighByte << 8) + LowByte; sign = TReading & 0x8000; // test most sig bit if (sign) // negative { TReading = (TReading ^ 0xffff) + 1; // 2's comp } Tc_100 = (6 * TReading) + TReading / 4; // multiply by (100 * 0.0625) or 6.25

whole = Tc_100 / 100; // separate off the whole and fractional portions fract = Tc_100 % 100; if(sign) temp[2]='-';

else temp[2]='+';

Page 24: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

//database felt nummer 02 temp[0] = '0'; temp[1] = '9';//temperaturen

temp[3]= (whole-(whole/100)*100)/10 +'0' ;temp[4]= whole-(whole/10)*10 +'0';

temp[5]='.';temp[6]=fract/10 +'0';temp[7]=fract-(fract/10)*10 +'0';

/*if(sign) temp[0]='-';else temp[0]='+';

temp[1]= (whole-(whole/100)*100)/10 +'0' ;temp[2]= whole-(whole/10)*10 +'0';

temp[3]='.';temp[4]=fract/10 +'0';temp[5]=fract-(fract/10)*10 +'0';

temp[6] = '\0';*/}

// Ultralyds m ler�void getCurrentLevel(char *temp){ // digitalWrite(URPower, HIGH); // T nd ultralyds sensor�

Page 25: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

int HighByte, LowByte, TReading, Tc_100, sign, whole, fract, USValue, retrycounter; retrycounter=0; flag=true; //delay(175); //delay for 75 ms //digitalWrite(UREnable, HIGH); // enable u. sensor

//Sending distance measure command : 0x22, 0x00, 0x00, 0x22 ;

for(int i=0;i<4;i++) { Serial.print(DMcmd[i],BYTE); } delay(175); //delay for 75 ms while(flag){ if(Serial.available()>0) { int header=Serial.read(); //0x22 int highbyte=Serial.read(); int lowbyte=Serial.read(); int sum=Serial.read();//sum if(highbyte==255) { USValue=65525; //if highbyte =255 , the reading is invalid. } else { USValue = highbyte*255+lowbyte; } //Serial.print("Distance=");

Page 26: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

//Serial.print(USValue); flag=false; }} //delay(50);

whole = USValue; // separate off the whole and fractional portions fract = USValue % 100;

// db felt nummer 13 temp[0]='1'; temp[1]='3';// data temp[2]= '0'; temp[3]= '0'; temp[4]= '0'; temp[5]= whole/100+'0'; // er m ling ok?� if isdigit(temp[5]) {

temp[6]= (whole-(whole/100)*100)/10 +'0' ; temp[7]= whole-(whole/10)*10 +'0';

// slut m ling og retuner til void loop�

} // hvis IKKE ok, lav fire m linger, sluk/t nd sensor� � else { retrycounter = 0; digitalWrite(UREnable, LOW); // enable u. sensor

digitalWrite(URPower, LOW); // SLUK ultralyds sensor

Page 27: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

delay(175); //delay for 75 ms digitalWrite(URPower, HIGH); // TAEND ultralyds sensor delay(75); //delay for 75 ms digitalWrite(UREnable, HIGH); // enable u. sensor delay(75); //delay for 75 ms while(retrycounter <= 4) { flag=true; //Sending distance measure command : 0x22, 0x00, 0x00, 0x22 ;

for(int i=0;i<4;i++) { Serial.print(DMcmd[i],BYTE); } delay(175); //delay for 75 ms while(flag) { if(Serial.available()>0) { int header=Serial.read(); //0x22 int highbyte=Serial.read(); int lowbyte=Serial.read(); int sum=Serial.read();//sum if(highbyte==255) { USValue=65525; //if highbyte =255 , the reading is invalid. } else { USValue = highbyte*255+lowbyte; }

Page 28: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

//Serial.print("Distance="); //Serial.print(USValue); flag=false; } } whole = USValue; // separate off the whole and fractional portions fract = USValue % 100; // db felt nummer 13 temp[0]='1'; temp[1]='3'; // data temp[2]= '0'; temp[3]= '0'; temp[4]= '0'; temp[5]= whole/100+'0'; // er m ling ok?� if isdigit(temp[10]) {

temp[6]= (whole-(whole/100)*100)/10 +'0' ; temp[7]= whole-(whole/10)*10 +'0';

// slut m ling og retuner til void loop hurtigst muligt� retrycounter= 5;

} // hvis IKKE ok, send fejl kode else { retrycounter = retrycounter+1; /* if (retrycounter = 2 ) { digitalWrite(UREnable, LOW); // enable u. sensor digitalWrite(URPower, LOW); // SLUK ultralyds sensor

Page 29: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

delay(100); digitalWrite(URPower, HIGH); // SLUK ultralyds sensor digitalWrite(UREnable, HIGH); // enable u. sensor }*/ // db felt nummer 13 temp[0]='1'; temp[1]='3'; // data temp[2]= 'F'; temp[3]= 'E'; temp[4]= 'J'; temp[5]= 'L'; temp[6]= '0'; temp[7]= '0'; } } // slut while loekke }// slut else

}

// ********************************************************************************************************************************// ***** Opsamler Stroem med acs714 og putter data i en string (den varialen som bruges til at kalde routinen med) *****// ***** acs714 maaler maks 5 ampere, har en offset spaending paa 2,5 volt, og giver 187mv pr. ampere ( x5,34) ***** // ********************************************************************************************************************************

Page 30: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

void getcurrent0(char *current){ int sign, whole; // digitalWrite(digital_io_pin7,LOW); // alive led turns offsign=false; // kommer fra gettemperatur routinen

if(sign) current[2]='-';else current[2]='+';

// analog read//sensor = 3;whole = 0;whole = analogRead(0);whole = whole; if (whole < 513) whole = 513; if (whole > 715) whole = 513;

int mappedValue = map( whole, 513, 700, 0, 5000 ); // 513 svarer til 2,5 volt og 715 svarer til 25, volt + 5x187mvolt, 5000 er 5 ampere ** 700 calibreretr 230809

// db felt 03 current[0] = '0'; current[1] = '3';// felt data current[3]= (mappedValue % 10000)/1000 +'0' ;

current[4]= (mappedValue % 1000)/100 +'0';current[5]='.';

current[6]= (mappedValue % 100)/10 +'0'; //whole=whole;+24; //calibrering af maaling

current[7]= (mappedValue % 10)+'0'; delay(1000UL); // delay 30 sec}

Page 31: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

// ********************************************************************************************************************************// ***** Opsamler Stroem med acs714 og putter data i en string (den varialen som bruges til at kalde routinen med) *****// ***** acs714 maaler maks 5 ampere, har en offset spaending paa2,5 volt, og giver 187mv pr. ampere ( x5,34) ***** // ********************************************************************************************************************************

void getcurrent1(char *current){ int sign, whole; // digitalWrite(digital_io_pin7,LOW); // alive led turns offsign=false; // kommer fra gettemperatur routinen

if(sign) current[2]='-';else current[2]='+';

// analog read//sensor = 3;whole = 0;whole = analogRead(1);whole = whole; if (whole < 513) whole = 513; if (whole > 715) whole = 513;

int mappedValue = map( whole, 513, 700, 0, 5000 ); // 513 svarer til 2,5 volt og 715 svarer til 25, volt + 5x187mvolt, 5000 er 5 ampere ** 700 calibreretr 230809// db felt 04 current[0] = '0'; current[1] = '4';// felt data; current[3]= (mappedValue % 10000)/1000 +'0' ;

current[4]= (mappedValue % 1000)/100 +'0';current[5]='.';

current[6]= (mappedValue % 100)/10 +'0';

Page 32: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

//whole=whole;+24; //calibrering af maalingcurrent[7]= (mappedValue % 10)+'0';

delay(1000UL); // delay 30 sec}// ********************************************************************************************************************************// ***** Opsamler Stroem med acs714 og putter data i en string (den varialen som bruges til at kalde routinen med) *****// ***** acs714 maaler maks 5 ampere, har en offset spaending paa 2,5 volt, og giver 187mv pr. ampere ( x5,34) ***** // ********************************************************************************************************************************

void getcurrent2(char *current){ int sign, whole;// digitalWrite(digital_io_pin7,LOW); // alive led turns offsign=false; // kommer fra gettemperatur routinen

if(sign) current[2]='-';else current[2]='+';

// analog read//sensor = 3;whole = 0;whole = analogRead(2);whole = whole; if (whole < 513) whole = 513; if (whole > 715) whole = 513;

int mappedValue = map( whole, 513, 700, 0, 5000 ); // 513 svarer til 2,5 volt og 715 svarer til 25, volt + 5x187mvolt, 5000 er 5 ampere ** 700 calibreretr 230809

// db felt 05 current[0] = '0';

Page 33: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

current[1] = '5';// felt data current[2] = '0'; current[3]= (mappedValue % 10000)/1000 +'0' ;

current[4]= (mappedValue % 1000)/100 +'0';current[5]='.';

current[6]= (mappedValue % 100)/10 +'0'; //whole=whole;+24; //calibrering af maaling

current[7]= (mappedValue % 10)+'0'; delay(1000UL); // delay 30 sec}// ********************************************************************************************************************************// ***** Opsamler Stroem med acs714 og putter data i en string (den varialen som bruges til at kalde routinen med) *****// ***** acs714 maaler maks 5 ampere, har en offset spaending paa 2,5 volt, og giver 187mv pr. ampere ( x5,34) ***** // ********************************************************************************************************************************

void getcurrent3(char *current){ int sign, whole;// digitalWrite(digital_io_pin7,LOW); // alive led turns offsign=false; // kommer fra gettemperatur routinen

if(sign) current[2]='-';else current[2]='+';

// analog read//sensor = 3;whole = 0;whole = analogRead(3);whole = whole; if (whole < 513) whole = 513;

Page 34: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

if (whole > 715) whole = 513;

int mappedValue = map( whole, 513, 700, 0, 5000 ); // 513 svarer til 2,5 volt og 715 svarer til 25, volt + 5x187mvolt, 5000 er 5 ampere ** 700 calibreretr 230809// db felt 06 current[0] = '0'; current[1] = '6';// felt data current[3]= (mappedValue % 10000)/1000 +'0' ;

current[4]= (mappedValue % 1000)/100 +'0';current[5]='.';

current[6]= (mappedValue % 100)/10 +'0'; //whole=whole;+24; //calibrering af maaling

current[7]= (mappedValue % 10)+'0';

delay(1000UL); // delay 30 sec}// ********************************************************************************************************************************// ***** Opsamler Stroem med acs714 og putter data i en string (den varialen som bruges til at kalde routinen med) *****// ***** acs714 maaler maks 5 ampere, har en offset spaending paa 2,5 volt, og giver 187mv pr. ampere ( x5,34) ***** // ********************************************************************************************************************************

void getcurrent4(char *current){ int sign, whole; // digitalWrite(digital_io_pin7,LOW); // alive led turns offsign=false; // kommer fra gettemperatur routinen

if(sign) current[2]='-';else current[2]='+';

// analog read

Page 35: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

//sensor = 3;whole = 0;whole = analogRead(4);whole = whole; if (whole < 513) whole = 513; if (whole > 715) whole = 513;

int mappedValue = map( whole, 513, 700, 0, 5000 ); // 513 svarer til 2,5 volt og 715 svarer til 25, volt + 5x187mvolt, 5000 er 5 ampere ** 700 calibreretr 230809// db felt 07 current[0] = '0'; current[1] = '7';// felt data current[3]= (mappedValue % 10000)/1000 +'0' ;

current[4]= (mappedValue % 1000)/100 +'0';current[5]='.';

current[6]= (mappedValue % 100)/10 +'0'; //whole=whole;+24; //calibrering af maaling

current[7]= (mappedValue % 10)+'0'; delay(1000UL); // delay 30 sec}// ********************************************************************************************************************************// ***** Opsamler Stroem med acs714 og putter data i en string (den varialen som bruges til at kalde routinen med) *****// ***** acs714 maaler maks 5 ampere, har en offset spaending paa 2,5 volt, og giver 187mv pr. ampere ( x5,34) ***** // ********************************************************************************************************************************

void getcurrent5(char *current){ int sign, whole; // digitalWrite(digital_io_pin7,LOW); // alive led turns off

Page 36: Arduino Pellet Boiler Data Logger v1 My Nerd Stuff

sign=false; // kommer fra gettemperatur routinenif(sign) current[2]='-';else current[2]='+';

// analog read//sensor = 3;whole = 0;whole = analogRead(5);whole = whole; if (whole < 513) whole = 513; if (whole > 715) whole = 513;

int mappedValue = map( whole, 513, 700, 0, 5000 ); // 513 svarer til 2,5 volt og 715 svarer til 25, volt + 5x187mvolt, 5000 er 5 ampere ** 700 calibreretr 230809

// db felt 08 current[0] = '0'; current[1] = '8';// felt data current[3]= (mappedValue % 10000)/1000 +'0' ;

current[4]= (mappedValue % 1000)/100 +'0';current[5]='.';

current[6]= (mappedValue % 100)/10 +'0'; //whole=whole;+24; //calibrering af maaling

current[7]= (mappedValue % 10)+'0'; delay(1000UL); // delay 30 sec}