caramoan tour package

caramoan tour package

Author Topic: Achieving data from UART  (Read 1711 times)

Offline mr_carl

  • CR2032 Battery
  • **
  • Posts: 16
  • Pogi/Ganda Points: 0
Achieving data from UART
« on: September 16, 2010, 02:58:37 PM »
Pano po ang code pra makuha ko po ang data (in a form of string) from UART. Tapos gusto ko po ma.hiwalay ang data pra ma.display ko po separately ung data. For example: "InRange,-0250.6,0010.0,-0150.2,+0.6228,220.39,0.5
806," gusto ko mkuha yan from power analyzer tapos mahiwalay ang Watts = -0.250.6, VA=00.10.0, VAR = -0150.2 etc... I'm using ac power analyzer ng e-gizmo at servo sequencer. Please help po.

Philippine Electronics Forum

Achieving data from UART
« on: September 16, 2010, 02:58:37 PM »

Offline 0b00000111

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6129
  • Pogi/Ganda Points: 398
  • There is no delight in owning anything unshared.
Re: Achieving data from UART
« Reply #1 on: September 16, 2010, 03:06:41 PM »
use the comma as the delimiter then split them in parts .. or use C's strtok function http://www.cplusplus.com/reference/clibrary/cstring/strtok/
E-Gizmo Mechatronix Central: www.e-gizmo.com

Tel #: (63)(2) 536-3378
Globe +63915-973-7691
Smart +63921-779-0748

Location Map

YM: julie.egizmo  aka Born2BeWired  ;D

Philippine Electronics Forum

Re: Achieving data from UART
« Reply #1 on: September 16, 2010, 03:06:41 PM »

Offline mr_carl

  • CR2032 Battery
  • **
  • Posts: 16
  • Pogi/Ganda Points: 0
Re: Achieving data from UART
« Reply #2 on: September 16, 2010, 03:23:29 PM »
ah ok ic..hehe..thanks po..tapos po ung pgkuha ng data from uart pano po yun..getch() po ako or gets()..ng.try po kac ako ng getch() at nkuha ko po ung data pero problema d ko mahiwalay kac d ata array un..pwede po mkahingi ng sample code..salamat po..

Philippine Electronics Forum

Re: Achieving data from UART
« Reply #2 on: September 16, 2010, 03:23:29 PM »

Offline mr_carl

  • CR2032 Battery
  • **
  • Posts: 16
  • Pogi/Ganda Points: 0
Re: Achieving data from UART
« Reply #3 on: September 16, 2010, 06:27:48 PM »
help po..mga master pano po kunin ang data galing ac power analyzer..i'm using zdsII program..pls po..

Philippine Electronics Forum

Re: Achieving data from UART
« Reply #3 on: September 16, 2010, 06:27:48 PM »

Offline RiDdLeR???

  • Hydroelectric
  • ***
  • Posts: 3032
  • Pogi/Ganda Points: 208
Re: Achieving data from UART
« Reply #4 on: September 16, 2010, 08:36:31 PM »
Here is my crude but working code using mikroC and PIC16F877A.  Convert mo na lang to ZDS, hindi ako marunong nun.

Code: [Select]
/***********************************************
 LCD Display for E-Gizmo's AC Power Analyzer
 using PIC16F877A and 20x4 Character LCD

 This code was made using various codes that
 can be found from the internet.  Do with it
 whatever you wish at your own risk.

 By alyas, hunyangongelab@gmail.com
***********************************************/

// LCD module connections
sbit LCD_RS at RD2_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;

sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections

int uart_get_padata() {
  while (! Uart1_Data_Ready()) {}
  return  Uart1_Read();
  }

void main(){
  
  char i;
  char rxbyte;
  char pa_out[52];
  char * range;
  char * watts;
  char * va;
  char * var;
  char * pf;
  char * volts;
  char * amps;
  
  Uart1_Init(9600);
  Delay_Ms(100);
  Lcd_Init();                        // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  
  lcd_out(1,1,"PF         W");       // Format the LCDScreen
  lcd_out(2,1,"V         VA");       //
  lcd_out(3,1,"A         VR");       //
  
  

  while (1) {

    rxbyte = uart_get_padata();
      
    if (rxbyte = 73) {               // Store PA data when starting delimeter "I" is read
        
        pa_out[0] = rxbyte;
        
        for (i=1; i<53; i++) {
          rxbyte = uart_get_padata();
          pa_out[i] = rxbyte;
          }
        
        range = strtok(pa_out, ",");
        watts = strtok(0x00, ",");
        va = strtok(0x00, ",");
        var = strtok(0x00, ",");
        pf = strtok(0x00, ",");
        volts = strtok(0x00, ",");
        amps = strtok(0x00, ",");
    
        lcd_out(1,14,watts);
        lcd_out(2,15,va);
        lcd_out(3,14,var);
        lcd_out(1,4,pf);
        lcd_out(2,3,volts);
        lcd_out(3,3,amps);
        }
    rxbyte = "";
    *pa_out = "";
    }
  }

Philippine Electronics Forum

Re: Achieving data from UART
« Reply #4 on: September 16, 2010, 08:36:31 PM »

Offline mr_carl

  • CR2032 Battery
  • **
  • Posts: 16
  • Pogi/Ganda Points: 0
Re: Achieving data from UART
« Reply #5 on: September 17, 2010, 09:25:45 AM »
thank you po sa code..na.convert ko po sa zds..gumana po ung program..:)

Offline Oj0vO

  • Size C Battery
  • *****
  • Posts: 189
  • Pogi/Ganda Points: 11
  • Gender: Male
Re: Achieving data from UART
« Reply #6 on: December 14, 2010, 06:46:43 PM »
ano po ung zds?.. para sn po yan?..

Offline Oj0vO

  • Size C Battery
  • *****
  • Posts: 189
  • Pogi/Ganda Points: 11
  • Gender: Male
Re: Achieving data from UART
« Reply #7 on: December 22, 2010, 11:32:05 PM »
Code: [Select]
   if (rxbyte = 73) {               // Store PA data when starting delimeter "I" is read
sir bkit po 73?..

Offline 0b00000111

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6129
  • Pogi/Ganda Points: 398
  • There is no delight in owning anything unshared.
Re: Achieving data from UART
« Reply #8 on: December 22, 2010, 11:37:27 PM »
yung character equivalent ng 73 is I...   you can verify it sa dos prompt... hold Alt, press 73 sa numeric keypad...

you can either do it
if (rxbyte == 73)
or
if (rxbyte == 'I')  << mas better, for readability purpose...
E-Gizmo Mechatronix Central: www.e-gizmo.com

Tel #: (63)(2) 536-3378
Globe +63915-973-7691
Smart +63921-779-0748

Location Map

YM: julie.egizmo  aka Born2BeWired  ;D

Offline Oj0vO

  • Size C Battery
  • *****
  • Posts: 189
  • Pogi/Ganda Points: 11
  • Gender: Male
Re: Achieving data from UART
« Reply #9 on: December 25, 2010, 07:40:28 PM »
Here is my crude but working code using mikroC and PIC16F877A.  Convert mo na lang to ZDS, hindi ako marunong nun.

Code: [Select]
   
        for (i=1; i<53; i++) {
         

bakit po 53..?... tnx po

Offline RiDdLeR???

  • Hydroelectric
  • ***
  • Posts: 3032
  • Pogi/Ganda Points: 208
Re: Achieving data from UART
« Reply #10 on: December 26, 2010, 09:47:55 AM »
^ count mo kung ilang characters ang output data ng power analyzer

Offline Oj0vO

  • Size C Battery
  • *****
  • Posts: 189
  • Pogi/Ganda Points: 11
  • Gender: Male
Re: Achieving data from UART
« Reply #11 on: January 19, 2011, 06:25:56 PM »
ano po kaya mga possible problems bkit po ndi ko ma receive iyong mga data, ndi ma display sa LCD ang value dun sa binigay niyo po na program?.. tsaka mainit maxado ang 5w 100ohms na resistor, ok lang ba iyon?.. pull up resistor 4.7k galing sa output ng j1(optocoupler) ang gamit ko papunta sa Rx ng PIC16f877A, ano po ba kulang dun?.. nid help po lapit na po kasi final defense, tnx po

Offline Oj0vO

  • Size C Battery
  • *****
  • Posts: 189
  • Pogi/Ganda Points: 11
  • Gender: Male
Re: Achieving data from UART
« Reply #12 on: January 30, 2011, 04:41:33 PM »
bakit ndi ko po ma separate ang mga data,?.. pwd ba n power, volts, current lang ang edisplay ko sa LCD?.. garbage pag inalis ko ung powerfactor,in range, var.. anyone cand help?. salamat advance

Offline RiDdLeR???

  • Hydroelectric
  • ***
  • Posts: 3032
  • Pogi/Ganda Points: 208
Re: Achieving data from UART
« Reply #13 on: January 30, 2011, 05:55:31 PM »
I'm already at lost sa mga pm mo.  Better post the code you are using.  Sa lcd display routines lang yan.

Offline Oj0vO

  • Size C Battery
  • *****
  • Posts: 189
  • Pogi/Ganda Points: 11
  • Gender: Male
Re: Achieving data from UART
« Reply #14 on: January 30, 2011, 07:32:51 PM »
sir gusto ko po sana ang e display is power, volt, current, then peso.. paano po bha sir?.. sinubukan ko po kasi inalis ung Range,VA,VAR,PF kaso hindi pa rin maalis then meron na garbage,. by the way sir i'm using 4x16 LCD.

Code: [Select]
/***********************************************
 LCD Display for E-Gizmo's AC Power Analyzer
 using PIC16F877A and 16x4 Character LCD

 This code was made using various codes that
 can be found from the internet.  Do with it
 whatever you wish at your own risk.

 By alyas, hunyangongelab@gmail.com
***********************************************/

// LCD module connections
sbit LCD_RS at RD2_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;

sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections

int uart_get_padata() {
  while (! Uart1_Data_Ready()) {}
  return  Uart1_Read();
  }

void main(){

  char i;
  char rxbyte;
  char pa_out[52];
  char * range;
  char * watts;
  char * va;
  char * var;
  char * pf;
  char * volts;
  char * amps;

  Uart1_Init(9600);
  Delay_Ms(100);
  Lcd_Init();                        // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off

  lcd_out(1,1,"VA:");       // Format the LCDScreen
  lcd_out(2,1,"V:");       //
  lcd_out(3,-3,"A:");       //
   lcd_out(4,-3,"PESO:");


  while (1) {

    rxbyte = uart_get_padata();

    if (rxbyte = 73) {               // Store PA data when starting delimeter "I" is read

        pa_out[0] = rxbyte;

        for (i=1; i<53; i++) {      //53 characters being read
          rxbyte = uart_get_padata();
          pa_out[i] = rxbyte;
          }                              //end reading

      /*range = strpbrk(pa_out, ",");*/
       watts = strpbrk(pa_out, ",");
       /*va = strpbrk(pa_out, ",");
        var = strpbrk(pa_out, ",");
        pf = strpbrk(pa_out, ",");*/
        volts = strpbrk(pa_out, ",");
        amps = strpbrk(pa_out, ",");

       lcd_out(1,4,watts);
       /*lcd_out(2,15,va);
        lcd_out(3,14,var);
        lcd_out(1,4,pf);*/
        lcd_out(2,3,volts);
        lcd_out(3,3,amps);
        }
 /*rxbyte = "";
    *pa_out = "";*/
    }
  }

Offline Kaizer03

  • Nuclear Reactor
  • ****
  • Posts: 4847
  • Pogi/Ganda Points: 225
  • C#<-->Android<-->Java
    • PhilRobotics
Re: Achieving data from UART
« Reply #15 on: January 30, 2011, 07:45:29 PM »
just want to share this routine =)


Code: [Select]
#define COMMA ','

/*
cStorage[x]
0 - STAT
1 - Watts
2 - VA
3 - VAR
4 - PF
5 - VOLT
6 - AMP
*/

char cStorage[7][8];

void extract(char *data)
{
   int x = 0, y = 0;

   while(*data){
      //Transfer Buffer to Another Variable here
      cStorage[x][y++] = *data++;

      if(*data == COMMA){
         
         printf(cStorage[x]); //Send the Parameters through UART

         x++;
         y = 0;
         *data++;
      }
   }
}

void GetPowerData() //Get Power Analyzer Data
{
   unsigned char ucRcvBuffer[60];
   int iCommaCntr = 0, i = 0;
   
   if(((ucRcvBuffer[i] = getc()) == 'I')){ //Wait for 'I' to receive
   
      while((ucRcvBuffer[++i] = getc()));
   
      //Extract Here
      extract(ucRcvBuffer);
     
      memset(ucRcvBuffer,0,sizeof(ucRcvBuffer)); 
   }
 
}

last night ko lang nagawa yan for someone's project it works sa simulation sa Proteus.. though this code is intended for PIC, but i do believe that there will be no much difference between the code except for the initialization of the MCU, so it will work for zilog=)
Lend a hand for those who are in need!=)

Stop Hijacking!=) More Technical Posts!=)
 ;)

Kaizer Killer EX Pre-Alpha

Offline Oj0vO

  • Size C Battery
  • *****
  • Posts: 189
  • Pogi/Ganda Points: 11
  • Gender: Male
Re: Achieving data from UART
« Reply #16 on: January 30, 2011, 08:37:21 PM »
oo nga related, hirapan lng ako mag basa ng code, ndi kasi ako maxado magaling sa programming , cnxa na. jejeje, baka kaya mo edit yung code na gamit ko.. hehehe, salamat

Offline Oj0vO

  • Size C Battery
  • *****
  • Posts: 189
  • Pogi/Ganda Points: 11
  • Gender: Male
Re: Achieving data from UART
« Reply #17 on: January 31, 2011, 08:01:56 AM »
ganito po sana gusto ko mangyari sa ginawa ni sir zerowing http://www.electronicslab.ph/forum/index.php?topic=16596.0#quickreply
if (position == 34)  /* wait for the 34th character starting from 'I' */
paano ko kaya makuha ung data ng power, volts at current...
salamat po..



Code: [Select]
/*
          1         2         3   x
01234567890123456789012345678901234567890
InRange,-0250.6,0010.0,-0150.2,+0.6228,220.39,0.5
*/


void poll_input()
{
    unsigned char c;
static unsigned char position = 0;
unsigned char power_factor;

c = getc();

if (c == 'I') /* poll for 'I' in "InRange" */
{
position = 0;
}
else
{
    ++position;
if (position == 34)  /* wait for the 34th character starting from 'I' */
{
    power_factor = (c - '6') * 10;  /*10s digit of the power factor */
}
else if (position == 35)  /* wait for the 34th character starting from 'I'*/
{
    power_factor += (c - '6');  /*add the 1s digit of the power factor*/

/*power factor LED table*/
if (power_factor>=0 && power_factor<=9)
{
    LED = 0b0000;
}
else if (power_factor>=10 && power_factor<=19)
{
    LED = 0b0001;
}
else if .....
{
    .....
}
.....

}
else if (position > 35)
{
     position = 36;  /*prevent overflow rollover to 0*/
}
}
}

Offline RiDdLeR???

  • Hydroelectric
  • ***
  • Posts: 3032
  • Pogi/Ganda Points: 208
Re: Achieving data from UART
« Reply #18 on: January 31, 2011, 08:33:05 AM »
Yung method ni sir zero above is waiting for character by character so you must know the exact position of the data you want for you to parse it.  Also the data must be of known and fixed length. 

Hindi mo kasi pinag-aaralan yung mga code na posted.  Like what I said earlier, sa LCD display routine lang ang problem mo.  The data are  all there.  Its just a matter of which data you want to display.

Eto yung modified code, it will display only the value of the Power, Voltage and current.  Ikaw na bahala magformat nung LCD display so it wont display the units of VA, VAR and PF, it does'nt matter kung 16 or 20 characters wide yung lcd.  Just study the lcd display routines

Quote
/***********************************************
 LCD Display for E-Gizmo's AC Power Analyzer
 using PIC16F877A and 20x4 Character LCD

 This code was made using various codes that
 can be found from the internet.  Do with it
 whatever you wish at your own risk.

 By alyas, hunyangongelab@gmail.com
***********************************************/

// LCD module connections
sbit LCD_RS at RD2_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;

sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections

int uart_get_padata() {
  while (! Uart1_Data_Ready()) {}
  return  Uart1_Read();
  }

void main(){
 
  char i;
  char rxbyte;
  char pa_out[52];
  char * range;
  char * watts;
  char * va;
  char * var;
  char * pf;
  char * volts;
  char * amps;
 
  Uart1_Init(9600);
  Delay_Ms(100);
  Lcd_Init();                        // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
 
  lcd_out(1,1,"PF         W");       // Format the LCDScreen
  lcd_out(2,1,"V         VA");       //
  lcd_out(3,1,"A         VR");       //
 
 

  while (1) {

    rxbyte = uart_get_padata();
     
    if (rxbyte = 73) {               // Store PA data when starting delimeter "I" is read
       
        pa_out[0] = rxbyte;
       
        for (i=1; i<53; i++) {
          rxbyte = uart_get_padata();
          pa_out = rxbyte;
          }
         
        range = strtok(pa_out, ",");
        watts = strtok(0x00, ",");
        va = strtok(0x00, ",");
        var = strtok(0x00, ",");
        pf = strtok(0x00, ",");
        volts = strtok(0x00, ",");
        amps = strtok(0x00, ",");
   
        lcd_out(1,14,watts);
        //lcd_out(2,15,va);
        //lcd_out(3,14,var);
        //lcd_out(1,4,pf);
        lcd_out(2,3,volts);
        lcd_out(3,3,amps);
        }
    rxbyte = "";
    *pa_out = "";
    }
  }


Offline Oj0vO

  • Size C Battery
  • *****
  • Posts: 189
  • Pogi/Ganda Points: 11
  • Gender: Male
Re: Achieving data from UART
« Reply #19 on: January 31, 2011, 10:56:41 PM »
anong error po ito? Implicit conversion of int to ptr?

Philippine Electronics Forum

Re: Achieving data from UART
« Reply #19 on: January 31, 2011, 10:56:41 PM »

 

Privacy Policy

Contact Us: elabph@yahoo.com