Excuse me guys.
I am currently working on my final project now. Basically i use some sensors and upload it with gsm module. I attach an LCD 16x2 in order to view the data from outside.
so this is the problem.
The gsm module was not working each time i use the function lcd.xxxxx
So this is my code
#include <GPRSClient.h>
#include <Xively.h>
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
#define PIN_TX 2
#define PIN_RX 3
#define GSM_ON 9
#define GSM_RESET 10
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// Your Xively key to let you upload data
char xivelyKey[] = "1111111111111111111111111111111111111111111111111111";
// Define the string for our datastream ID
char sensorId_0[] = "firstreed";
char sensorId_1[] = "secondistancesensor";
XivelyDatastream datastreams[] = {
XivelyDatastream(sensorId_0, strlen(sensorId_0), DATASTREAM_FLOAT),
XivelyDatastream(sensorId_1, strlen(sensorId_1), DATASTREAM_FLOAT),
};
// Finally, wrap the datastreams into a feed
XivelyFeed feed(11111111, datastreams, 2 /* number of datastreams */);
char apn[] = "internet";
char user[] = "";
char pass[] = "";
GPRSClient gprs(PIN_TX, PIN_RX, 2400, apn, user, pass);
XivelyClient xivelyclient(gprs);
int nilailama, dapetinnilai, nilaibaru;
void setup() {
// put your setup code here, to run once:
nyalainModulGSM();
//delay(10000);
Serial.begin(9600);
Serial.println("mulai");
gprs.init();
while (false == gprs.join()) {
Serial.println("gagal");
delay(2000);
}
// successful DHCP
Serial.print("IP =");
Serial.println(gprs.getIPAddress());
}
void loop() {
lcd.clear();
//reed
const int switchPin = 5;
//dibawah ini ultrasonik
const int trigPin = 6;
const int echoPin = 7;
long duration, inches, cm;
//inisiasi ultrasonik
pinMode(trigPin, OUTPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(1000);
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
//konversi waktu ke jarak
//inches = microsecondsToInches(duration);
//cm = duration/29/2;
int ultrasonicValue = duration/29/2;
//Rumus Reed . Ngitung banyaknya PERUBAHAN STATUS dari 0 sampai 1 , dikalikan 0.2 . Selama 280detik
int sensorValue0 = digitalRead(switchPin);
datastreams[0].setFloat(sensorValue0);
Serial.print("Sensor reed ");//menjumlahkan apa yang dibaca reed disini
Serial.println(datastreams[0].getFloat());//disini kan dikirim
Serial.println("Unggah data reed ke server");
//lcd.clear();
int ret0 = xivelyclient.put(feed, xivelyKey);
if(true == ret0){
Serial.println("update success!");
//lcd.print(sensorValue0);
//lcd.print(" done");
}else{
Serial.println("update failed!");
//lcd.print("gagal");
}
Serial.println();
delay(2000);
//lcd.clear();
//Rumus Ultrasonik
int sensorValue1 = ultrasonicValue;
delay(1000);
nilaibaru = sensorValue1;
if(nilaibaru != nilailama){
datastreams[1].setFloat(nilaibaru);
delay(1000);
Serial.print("Sensor jarak ");
Serial.println(datastreams[1].getFloat());
//disini kan dikirim
Serial.println("Unggah data jarak ke server");
int ret1 = xivelyclient.put(feed, xivelyKey);
if(true == ret1){
Serial.println("update success!");
//lcd.print(nilaibaru);
//lcd.print(" done");
}else{
Serial.println("update failed!");
//lcd.print("gagal");
}
Serial.println();
delay(1000);
//lcd.print(nilaibaru);
//lcd.print(" done");
delay(1000);
}
nilailama = nilaibaru;
delay(1000);
}
void nyalainModulGSM()
{
//pinMode(9, OUTPUT);
pinMode(9, OUTPUT);
digitalWrite(9,LOW);
delay(20000);
digitalWrite(9,HIGH);
delay(10000);
digitalWrite(9,LOW);
delay(5000);
}
Right after i upload the code, i always open the serial monitor.
So as you can see i put the lcd.clear() right on the first row of loop();
And yes as i have told you the data can’t be uploaded successfully.
The same thing happened if i add some lcd.clear() after serial.begin(9600).
It ended up with no IP and no GPRS connection.
it kind of like the connection were lost right after it read some lcd.xxxxx .
it happened with every lcd.xxxxxxx syntax. So do lcd.begin , or anything.
Below i attach a picture with lcd.clear() right before
}
void nyalainModulGSM()
and as you can see the third data wasn’t succeeded.
I consider using i2c thing but it costs me extra money to buy.
Basically i just want this lcd to show the data without cut the connection off.
So could you guys please help me with this?
Thank you, am sorry for my bad english.