/* Modified code for Arduino IDE ver. 1.0 The circuit: * 5V to Arduino 5V pin * GND to Arduino GND pin * CLK to Analog #5 * DAT to Analog #4 */ // include the library code: #include #include #include #include #include #if defined(ARDUINO) && ARDUINO >= 100 #define printByte(args) write(args); #else #define printByte(args) print(args,BYTE); #endif #define PACHUBE_API_KEY "................" // fill in your API key PACHUBE_API_KEY #define PACHUBE_FEED_ID ..... String data[5]; byte mac[] = { 0xCC, 0xAC, 0xBE, 0xEF, 0xFE, 0x91 }; // make sure this is unique on your network byte ip[] = { 192, 168, 2, 9 }; // no DHCP so we set our own IP address unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds const int postingInterval = 30000; // delay in [ms] between updates from Pachube.com ERxPachubeDataIn datain(PACHUBE_API_KEY, PACHUBE_FEED_ID); //void PrintDataStream(const ERxPachube& pachube); // Connect via i2c, default address #0 (A0-A2 not jumpered) LiquidCrystal lcd(0); void setup() { // set up the LCD's number of rows and columns: lcd.begin(20, 4); Ethernet.begin(mac, ip); delay(100); lastConnectionTime = postingInterval; } void loop() { if( millis()-lastConnectionTime > postingInterval ){ lastConnectionTime = millis(); int status = datain.syncPachube(); GetDataStream(datain); // set the cursor to column 0, line 1 // (note: line 1 is the second row, since counting begins with 0): lcd.clear(); if( status != 200 ){ lcd.setCursor( 20 - sizeof(status)+1, 0 ); lcd.print(status); } else { lcd.setCursor( 19, 0 ); lcd.print("."); } lcd.setCursor( 0, 0 ); lcd.print("Outer:"); lcd.setCursor( 12 - data[3].length(), 0 ); lcd.print( data[3] ); lcd.setCursor( 13, 0 );lcd.print(char(223));lcd.print("C"); lcd.setCursor( 0, 1 ); lcd.print("Inner:"); lcd.setCursor( 8, 1 ) ; lcd.print(data[0]); lcd.setCursor( 13, 1 );lcd.print(char(223));lcd.print("C"); lcd.setCursor( 0, 2 ); lcd.print("Press"); lcd.setCursor( 9, 2 ); lcd.print("Trend"); lcd.setCursor( 16, 2 ); lcd.print("Accu"); lcd.setCursor( 0, 3 ) ; lcd.print( data[1] ); lcd.setCursor( 11 - data[2].length()/2, 3 ) ; lcd.print( data[2] ); lcd.setCursor( 17, 3 ) ; lcd.print( data[4] ); } if( millis()-lastConnectionTime > postingInterval/2 ){ // THIRD row shows Units instead of values lcd.setCursor( 0, 2 ); lcd.print(" hPa Pa/Hr mV"); } char buf[ data[4].length()+1 ]; data[4].toCharArray( buf, data[4].length()+1 ); int volt = atoi( buf ); if( volt < 340 && millis()%2000 < 1000 ){ // voltage value blinks every 1sec when less than 340 lcd.setCursor( 17, 3 ); lcd.print( " " ); } else { lcd.setCursor( 17, 3 ); lcd.print(volt); } } void GetDataStream( const ERxPachube& pachube ){ unsigned int count = pachube.countDatastreams(); for(unsigned int i = 0; i < count; i++){ data[i] = pachube.getValueByIndex(i); } }