Society of Robots - Robot Forum

Software => Software => Topic started by: benji on April 13, 2008, 02:20:29 PM

Title: hyper terminal hexa
Post by: benji on April 13, 2008, 02:20:29 PM
i did connect my sharp ir to my pc serial port
what im doing is that ,my atmega is reading adc value ,store it in a variable, send this variable through uart

i can see my data on the hyper terminal screen but its coded,, its a font(ascii),,how do i turn it back to hexa or decimal?
Title: Re: hyper terminal hexa
Post by: izua on April 13, 2008, 02:49:08 PM
hyperterminal bad, bray's terminal (http://braypp.googlepages.com/terminal) good  :D
Title: Re: hyper terminal hexa
Post by: frank26080115 on April 13, 2008, 04:20:27 PM
something even more awesome, if you use linux, KontrollerLab is a fully featured IDE and it has this terminal built in, it doesn't interfere with any other program reading the same port, and it has different graphing functions too like a o'scope or a histogram
Title: Re: hyper terminal hexa
Post by: dunk on April 13, 2008, 04:28:34 PM
Quote
i can see my data on the hyper terminal screen but its coded,, its a font(ascii),,how do i turn it back to hexa or decimal?
that's not really what a terminal emulator like HyperTerminal is designed to do.

why not just transmit the 3 ASCII characters that make up the number?
something like this:
Code: [Select]
void transmit_ascii_num(int i)
{
   char h = (i / 100) + '0' ;                     // h = hundreds
   char t = ((i % 100) / 10) + '0' ;           // t = tens
   char o = (i % 10)  + '0' ;                    // o = ones

   tx(h);                                                 // where "tx(char)" is your UART transmit function.
   tx(t);
   tx(o);

   return;
}

dunk.
Title: Re: hyper terminal hexa
Post by: paulstreats on April 13, 2008, 05:25:42 PM
theres also a standard function itoa() that does this. It converts the int value into an array of characters which have the related ascii symbols of the number. So giving it the number 12 will return 2 characters 1 is 0x31 and the other is 0x32. When sent sent to hyperterminal these show the ascii characters of 1 and 2 ie.12

to use it you must send it an int and also give it a char array to return its characters to, and also state the base radix that you would like returned.

Code: [Select]
unsigned char[5] outstring;                     //the char array that will store the converted number
int mynum = 12;                     //the number to convert

itoa(mynum,outstring,10);        //send the int and char to itoa and tell it we want to use a base radix of 10.

uartputS(outstring);                // finally send the converted number to hyperterminal


once the number 12 gets sent to itoa() the array outstring contains the following:-

outstring[0] = 0x31               //this is the ascii code for the number 1
outstring[1] = 0x32               //this is the ascii code for the number 2
outstring[2] = undefined       // not used
outstring[3] = undefined
outstring[4] = undefined

If you just send the number 12 to hyperterminal the screen will become blank because 12 (or 0x0C) is the ascii code for starting a new page, so the itoa function converts the decimal value into hex characters that display as the decimal value but have no relation to the actual number 12.

If you cant find the itoa() function in any of your built in libraries, let me know and ill post it for you
Title: Re: hyper terminal hexa
Post by: benji on April 14, 2008, 03:46:40 AM
thanks paul this is awsome,, and yea i have the function,i just have a question about it

should the outstring contain 5 elements? cuz my input isnt an int ,its 8 bits variables
so actually 3 elements would do

if one of the outstring elements is undefined,would it send it via uart?what does this show on hyperterminal?

thanks
Title: Re: hyper terminal hexa
Post by: paulstreats on April 14, 2008, 04:57:12 AM
The outstring can be any size, I usually just use 5 because an int has the possibility of a 5 digit value (32000). It can be reduced if you know that it isnt going to overflow.

The undefined values in the outstring simply wont be printed.

Im not sure if it works properly by sending just an 8 bit char, it might only accept an int but you could do the following:


Code: [Select]
char mychar = 0x08;

unsigned char[3] outstring;

itoa((int)mychar,*outstring,10)


So you send a character but write (int) in brackets before the char name to convert its value for this purpose only to an int.
Also you will notice that there is a * before outstring, you need to do this because you are just sending a pointer to the array (i forgot to put it in the original post)
Title: Re: hyper terminal hexa
Post by: superchiku on April 14, 2008, 07:10:56 AM
as  i told u bfore in my earlier post use this code, it is tested and debugged

Code: [Select]
# include<stdio.h>
# include<avr/io.h>

# include<util/delay.h>
# include<avr/interrupt.h>
# include<stdlib.h>
# include<string.h>
# include<avr/pgmspace.h>



#define USART_BAUDRATE 38400
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL)))- 1)


 char u[11]="adcvalue\r\n";
 char *d;
 char b[10];
 char *p;
 
 unsigned int a;

void adcinitialize();
void uartinitialize();
void adcgetvalue();
void transferusart();
void printvalue(char *);

 int main(void)
  {
   adcinitialize();
   uartinitialize();
   while(1)
    {
adcgetvalue();
     
p=itoa(a,b,10);

strcat_P(b,PSTR("\r\n"));

d=&u[0];

transferusart();

     
     }       
   

   return(0);
   }
 
 
 
 void adcinitialize()
  {
   
  ADCSRA|=_BV(7)|_BV(ADPS2)|_BV(ADPS1);
  ADMUX=0x60;
  ADCSRA|=(1<<ADSC);
  while(!(ADCSRA & (1<<ADIF)));
  ADCSRA|=(1<<ADIF);
  TCCR1B|=(1<<CS12);
 
  }
 
  void uartinitialize()
   {
    UCSRB= (1<<RXEN) | (1<<TXEN);
    UCSRC= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1);
    UBRRL=BAUD_PRESCALE;
UBRRH=(BAUD_PRESCALE>>8);
   }
void adcgetvalue()
 {
 
   ADMUX=0x61;
   ADCSRA|=(1<<ADSC);
  while(!(ADCSRA & (1<<ADIF)));
  ADCSRA|=(1<<ADIF);
  a=ADCH;
 }
 
void transferusart()
 {
   
   while (*d != '\0')
    {

     while ((UCSRA & (1 << UDRE)) == 0) {}; // Do nothing until UDR is ready for more data to be written to it
      UDR =*d ; // Echo back the received byte back to the computer
      d++;
}
TCNT1=0;
while(TCNT1<=60000){};
TCNT1=0;
 printvalue(p);
 }
 
 void printvalue(char *l)
  {
   
   while (*l != 0x00)
    {
 

  while ((UCSRA & (1 << UDRE)) == 0) {}; // Do nothing until UDR is ready for more data to be written to it
      UDR =*l ; // Echo back the received byte back to the computer
     
     
     l++;
    }
TCNT1=0;
while(TCNT1<=60000){};
TCNT1=0;
  }
 

   
Title: Re: hyper terminal hexa
Post by: benji on April 14, 2008, 09:35:12 AM
thanks paul,, and sorry superchiku i should have seen it,thanks anyways
Title: Re: hyper terminal hexa
Post by: superchiku on April 14, 2008, 10:21:29 AM
no problem , do post the sensor digital o/p and graph when you use the code
Title: Re: hyper terminal hexa
Post by: benji on April 17, 2008, 04:28:52 PM
Quote
hyperterminal bad, bray's terminal good 

maan this is one great piece of art, thanks
Title: Re: hyper terminal hexa
Post by: superchiku on April 18, 2008, 01:29:45 AM
whats bray's terminal?
Title: Re: hyper terminal hexa
Post by: izua on April 18, 2008, 07:10:08 AM
check the link.
two dudes decided hyperterminal sucked. one of them was bray and finished his terminal with a whole bunch of options for debugging. the other one, izua, found bray's terminal and never finished his own terminal software :P
Title: Re: hyper terminal hexa
Post by: superchiku on April 18, 2008, 11:23:26 AM
hm.. u use which software to make the terminal?
Title: Re: hyper terminal hexa
Post by: izua on April 18, 2008, 01:07:46 PM
c++ mostly.
Title: Re: hyper terminal hexa
Post by: superchiku on April 24, 2008, 02:08:07 AM
is it advanced C or embedded
Title: Re: hyper terminal hexa
Post by: izua on April 24, 2008, 01:07:56 PM
it was a terminal software for the pc. if you consider the intel cpu as embedded, then yes, it was embedded.
i use the term software for PC software, and firmware for embedded software (like avr, pic, etc..)

offtopic: this is way offtopic.
Title: Re: hyper terminal hexa
Post by: superchiku on April 24, 2008, 11:18:26 PM
this isnt offtopic its realted to programming and may be this can be used in robots also
Title: Re: hyper terminal hexa
Post by: Admin on April 26, 2008, 06:05:55 PM
everyone bashes hyperterminal . . . I like it tho . . .

Anyway, benji, can you show us the output you have in the terminal? Are you sure its just not an improper baud config?

To convert from ascii, do this:
your_variable = your_variable & 0x0F;
Title: Re: hyper terminal hexa
Post by: benji on April 27, 2008, 03:10:24 AM
no ,, the baud rate is right,, hyper terminal worked good, but i wanted to see my real numbers,,not coded stuff
try bray's terminal,, its just more robotic,, ;D
Title: Re: hyper terminal hexa
Post by: superchiku on April 27, 2008, 07:26:44 AM
you can see have you tried to use itoa function which convers to char and ascii, have you used strcat and attached /r/n at the end of your coverted string?

and have you tried using the progrem function if your using avr
Title: Re: hyper terminal hexa
Post by: benji on April 27, 2008, 09:08:00 AM
there is no point to add stuff to my code just to use hyperterminal,,bray's terminal is perfect
Title: Re: hyper terminal hexa
Post by: superchiku on April 27, 2008, 10:20:36 AM
hmm.. if pre made codes make your life easy then that doesnt mean you cant learn anything , if you try to make your own code , you will be able to learn a lot more..
Title: Re: hyper terminal hexa
Post by: izua on April 27, 2008, 11:21:39 AM
maybe he uses assembler, and an itoa function or ftoa is pretty evil to write.
Title: Re: hyper terminal hexa
Post by: superchiku on April 27, 2008, 11:37:55 AM
he uses C too..
Title: Re: hyper terminal hexa
Post by: benji on April 28, 2008, 10:40:26 AM
its not that i dont want to learn,, its that i would save my time to learn somthin that helps me with my project ,,to improve it,, not learn stuff that i can do the easy way,,thats just my point of view
if you have 2 solutions , get the easier one and save time for another problems,, ;)
Title: Re: hyper terminal hexa
Post by: superchiku on April 29, 2008, 04:48:54 AM
REMEMBER ALWAYS "THE EASIEST WAY IS NOT THE BEST WAY ALWAYS"
Title: Re: hyper terminal hexa
Post by: benji on April 29, 2008, 09:13:58 AM
yea but in this case i think it is,, cause i would be happy if the code gets smaller,, i have tons of things to program other than this little sensor,,
Title: Re: hyper terminal hexa
Post by: superchiku on May 01, 2008, 12:23:55 AM
your wish
Title: Re: hyper terminal hexa
Post by: Steel_monkey on May 02, 2008, 04:38:05 PM
Are there any programs for COM ports which are able to graph data properly? Terminal can, but in poor quality. Also it saves data in hex or ASCI , no decimal option for saving available. So, if I want to graph data, for example, in Maple, I need to do a lot of things ( cut prologue and epilogue for every string, convert it to decimal and graph). Do anybody knows easier way? 
Title: Re: hyper terminal hexa
Post by: superchiku on May 02, 2008, 10:23:32 PM
no decimal option for saving data??? i saved my data in digital numerical form not is hexa or ascii
Title: Re: hyper terminal hexa
Post by: Steel_monkey on May 03, 2008, 03:18:06 AM
What program are you talking about? In Br@y++ terminal there are no options for decimal saving, only for decimal listing. In hyperterminal too.
Title: Re: hyper terminal hexa
Post by: superchiku on May 03, 2008, 04:28:31 AM
no hyperterminal ill giive u my readings if u want
Title: Re: hyper terminal hexa
Post by: Steel_monkey on May 03, 2008, 09:13:30 AM
Can you tell what settings did you use saving data in decimal? Did you use atoi? I am looking for simple solution without atoi to plot graph from my data from UART on PC screen. I tried a lot of programs, only Bray terminal can plot, but relatively poor.

P.S. I have just done Excel program to plot graphs. In my ancient Ex. 2000, there are no hex to dec, but it was not very hard to implement. However, it takes time to save hex file in ComPort Toolkit and graph it.
Title: Re: hyper terminal hexa
Post by: superchiku on May 03, 2008, 11:24:18 AM
yes man i used itoa , a relative son could come if i created some kinda software for u ppl but i dont know how to create a software out of the code i have written so thats the problem