Hi,
I am new in the world of Arduino, and still learning.
I am building a Humidity Temperature reading device, where the hum/temp is displayed on an LCD + a RGB Led that changes depending on temperature intervals, and finally a live stream via twitter, where it shows the data real time.
I used some authorized codes I found here and there online, and compiled it to make it work on my system.
Issue I have: First I made sure the LCD/RGB led worked. Then I went on the twitter thing to make it work.
When each thing was working, I decided to put everything together.
However, the LCD won't work.
Tests I have done:
-
I moved the LCD setup before the twitter setup. The LCD boots up and shows the preliminary informations. Twitter starts and post its preliminary post. Then the LCD stays with the same preliminary informations, without backlight. The twitter loops works as it posts the information i want, and the RGB Led reacts (changes colors).
-
I put the twitter setup before the LCD setup. The LCD won't boot up. Everything else works (twitter + RGB Led).
-
Therefore I understand the twitter setup loop is doing something bad. I did a line by line debug. It appears the issue comes up when i have the line " Ethernet.begin ".
Any comment ? I am really stuck on this one.
Thanks for your help!!
Here is the code :
(also, if someone manages to repair this issue. I will have another problem (I believe) with the loop. Since the twitter loop is expected to post a temperature every 600 seconds, I don't want the LCD to update every 600 seconds, but 5 seconds.... uhh)..
// Connections:
// LCD pin 1 to Arduino GND
// LCD pin 2 to Arduino 5v
// LCD pin 3 (Contrast) to GND
// rs (LCD pin 4) to Arduino pin 12
// rw (LCD pin 5) to Arduino pin 11
// enable (LCD pin 6) to Arduino pin 10
// LCD pin 15 to Arduino pin 13
// LCD pin 16 to Arduino GND
// LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 2
//Sensor
//pin SDA to Arduino Analog pin 4
//pin SCL to Arduino Analog pin 5
//pin GND to Arduino GND
//pin VCC to Arduino 3v
//RGB LED
//Red Cathode to Arduino pin 9
//Blue Cathode to Arduino pin 8
//Green Cathode to Arduino pin 7
//Anode to 270 ohm resistor to 5V
#define RATE 600
#include <LiquidCrystal.h>
#include <Wire.h>
#include <LibHumidity.h>
#include <Ethernet.h>
#include <EthernetDHCP.h>
#include <EthernetDNS.h>
#include <Twitter.h>
#include <math.h>
#include <PString.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 5 };
//byte gateway[] = { 192, 168, 1, 1 };
//byte subnet[] = { 255, 255, 255, 0 };
Twitter twitter("44621871-WJOjmyDh1RgrshGiMLomhuNqJtJ2DJgTdg543Gd4");
Server server(80);
LibHumidity humidity = LibHumidity(0);
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
int backLight = 13; // pin 13 will control the backlight
int RedLEDPin = 9;
int BlueLEDPin = 8;
int GreenLEDPin = 7;
int marker = 0;
long int counter = 0;
//Buffer used for tweets, tweets can't be more than 140 characters
char buffer[140] = {0};
//Setup the PString function
PString mystring(buffer, sizeof(buffer));
void setup()
{
pinMode(backLight, OUTPUT);
digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
lcd.begin(20, 4);
lcd.setCursor(0,0);
delay(1000);
lcd.print("Remote Climate");
lcd.setCursor(0,1);
lcd.print("Monitor v. 1.0");
delay(1000);
lcd.setCursor(0,2);
lcd.print("SeniorDesign Project");
delay(1000);
//I2C
pinMode(16, OUTPUT);
digitalWrite(16, LOW); //GND pin
pinMode(17, OUTPUT);
digitalWrite(17, HIGH); //VCC pin
//Furnace / AC Indicator
pinMode(RedLEDPin, OUTPUT); // sets the digital pin as output
pinMode(BlueLEDPin, OUTPUT); // sets the digital pin as output
pinMode(GreenLEDPin, OUTPUT); // sets the digital pin as output
//Begin internet connection
counter = RATE;
Ethernet.begin(mac, ip); // THIS CRASHES THE LCD
Serial.begin(9600); // opens serial port for status/monitoring
delay(5000); // give it time to do its thing
//Short test tweet
mystring.print("Remote Climate Monitor booting up... Temperature is ");
mystring.print(humidity.GetTemperatureF());
mystring.print("F (");
mystring.print(humidity.GetTemperatureC());
mystring.print(" C), with a Relative Humidity of ");
mystring.print(humidity.GetHumidity());
mystring.print("%. All systems online.");
Serial.println("Connecting to Twitter...");
if (twitter.post(buffer)) {
int status = twitter.wait();
if (status == 200) {
Serial.println("OK.");
}
else {
Serial.print("Connection failed: code ");
Serial.println(status);
}
} else {
Serial.println("Connection failed.");
}
delay(5000);
}
void loop()
{
// LCD Loop starts
lcd.begin(20,4);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Humidity: ");
lcd.print(humidity.GetHumidity());
lcd.setCursor(0,1); // set cursor to column 0, row 1
lcd.print("Temperature (C): ");
lcd.print(humidity.GetTemperatureC());
lcd.setCursor(0,2); // set cursor to column 0, row 2
lcd.print("Temperature (F): ");
lcd.print(humidity.GetTemperatureF());
// LCD loop done
if (humidity.GetTemperatureF() < 60)
{
digitalWrite(RedLEDPin, LOW); // sets the Red LED on
digitalWrite(BlueLEDPin, HIGH); // sets the Blue LED off
digitalWrite(GreenLEDPin, LOW); // sets the Green LED off
}
else if (humidity.GetTemperatureF() >= 78)
{
digitalWrite(BlueLEDPin, LOW); // sets the Blue LED on
digitalWrite(RedLEDPin, HIGH); // sets the Red LED off
digitalWrite(GreenLEDPin, HIGH); // sets the Green LED off
}
else
{
digitalWrite(GreenLEDPin, LOW); // sets the Green LED on
digitalWrite(BlueLEDPin, HIGH); // sets the Blue LED off
digitalWrite(RedLEDPin, HIGH); // sets the Red LED off
}
}
delay (20000);
//begin loop for twitter
if (counter == 1) {
//Reset counter
counter = RATE;
PString mystring(buffer, sizeof(buffer));
//Generates a random number
marker = random(1,100);
mystring.print(" Real time temperature is ");
mystring.println(humidity.GetTemperatureC());
mystring.print(" C.");
Serial.println("Connecting to Twitter...");
if (twitter.post(buffer)) {
int status = twitter.wait();
if (status == 200) {
Serial.println("OK.");
}
if (status == 0) {
Serial.println("No response from Twitter...");
}
else {
Serial.print("Transmission failed HTTP code: ");
Serial.println(status);
}
} else {
Serial.println("connection failed.");
}
}
delay(1);
//Decrement counter
--counter;
Serial.println(counter);
delay(1000);
}