Help me for the coding

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

Help me for the coding

Postby Hidayah » Wed Nov 20, 2013 11:28 pm

hye there... i really need your help, please help me.. i need to display the ph sensor value to the LCD 16x2.

i try to write it but the value output at LCD is "pEhsk"

the code for the ph sensor is

CODE: SELECT_ALL_CODE
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>                                                    //add the soft serial libray
#define rxpin 2                                                                //set the RX pin to pin 2
#define txpin 3                                                                //set the TX pin to pin 3

SoftwareSerial myserial(rxpin, txpin);                                         //enable the soft serial port

String inputstring = "";                                                       //a string to hold incoming data from the PC
String sensorstring = "";                                                      //a string to hold the data from the Atlas Scientific product
boolean input_stringcomplete = false;                                          //have we received all the data from the PC
boolean sensor_stringcomplete = false;                                         //have we received all the data from the Atlas Scientific product

LiquidCrystal lcd(7,8,9,10,11,12);
void setup()
{                                                                //set up the hardware
     Serial.begin(38400);                                                      //set baud rate for the hardware serial port to 38400
     myserial.begin(38400);                                                    //set baud rate for software serial port to 38400
     inputstring.reserve(5);                                                   //set aside some bytes for receiving data from the PC
     sensorstring.reserve(30);          //set aside some bytes for receiving data from Atlas Scientific product
     lcd.begin(16, 2);
     lcd.print("Ph : ");
     
}

void serialEvent()
{                                                         //if the hardware serial port receives a char
     char inchar = (char)Serial.read();                               //get the char we just received
     inputstring += inchar;                                           //add it to the inputString
     if(inchar == '\r') {input_stringcomplete = true;}                //if the incoming character is a <CR>, set the flag


void loop()
{             //here we go....
   
    if (input_stringcomplete)
    {                                                   //if a string from the PC has been recived in its entierty
      myserial.print(inputstring);                                             //send that string to the Atlas Scientific product
      inputstring = "";                                                        //clear the string:
      input_stringcomplete = false;                                            //reset the flage used to tell if we have recived a completed string from the PC
    }
    while (myserial.available())
    {                                               //while a char is holding in the serial buffer
      char inchar = (char)myserial.read();                                  //get the new char
      sensorstring += inchar;                                               //add it to the sensorString
      if (inchar == '\r') {sensor_stringcomplete = true;}                   //if the incoming character is a <CR>, set the flag
    }


   if (sensor_stringcomplete)
   {                                                 //if a string from the Atlas Scientific product has been received in its entirety
       Serial.print(sensorstring);                                             //use the hardware serial port to send that data to the PC
       sensorstring = "";                                                      //clear the string:
       sensor_stringcomplete = false;     //reset the flag used to tell if we have received a completed string from the Atlas
   }
     
     lcd.setCursor(0, 1);
     lcd.println(sensorstring);
     lcd.setCursor(1,1);
     delay(3000);

}



thanks...
Hidayah
Novice
 
Posts: 30
Joined: Thu Jun 06, 2013 12:12 am

Re: Help me for the coding

Postby yonghui » Thu Nov 21, 2013 10:50 am

Which part convert data byte to string format?
thanks&regards,
yh
yonghui
Moderator
 
Posts: 732
Joined: Mon Sep 28, 2009 3:27 pm

Re: Help me for the coding

Postby robosang » Thu Nov 21, 2013 4:12 pm

Who will read your code oh?
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm


Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 28 guests