0

$USD

$USD
PROJECTS

X-Board V2 and Pachube data on LCD

DFRobot Jan 22 2012 1065

This project reads feed data on Pachube and shows the data on an LCD. The project is quite simple. The following hardware was used:

-DFRobot X-Board v2 (DFR0162)
-DFRobot FTDI Basic Breakout (DFR0065) for uploading the sketch code to X-Board
-LCD2004 display
- DFRobot USB Power adapter (FIT0197)
-USB cable for power
-Ethernet cable to connect it to router/internet


To connect the LCD to the X-board please take a look at the LCD Wiki: here

So we have the hardware, now it is time for software. To compile your code you need:
- Arduino IDE, the latest version is V1.0
- Pachube library ERxPachube available: here (note: please download and install library version compatible with your IDE, i.e. for IDE 1 is the latest version ERxPachube-I-3.1.zip)
 

The sketch code:

/* 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); } }

I recover all 5 values from Pachube: Outer and inner temperature, atmospheric pressure and trend of its changes, and LiPO accumulator voltage. You can see a Pachube sample feed at 25574.

The sketch is very simple. The ways how to display the values on LCD is endless so take this layout as an idea only.   

This project was created and contributed by DFRobot forum user: Synekvl

If you have any questions about this tutorial feel free to contact him or post your questions at the bottom of this post, and we will try to answer it.
You can also follow @Synekvl on Twitter