Shop OBEX P1 Docs P2 Docs Learn Events
Serial Output — Parallax Forums

Serial Output

RituRitu Posts: 39
edited 2006-07-26 18:16 in General Discussion
Hi,
I need to make a serial output with a 4800 bod, how do I do that? Where can I look to get help for that?
Thanks

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-07-26 13:40
    See the attachment.
    Change Uart.speed9600 into Uart.speed4800

    regards peter
  • RituRitu Posts: 39
    edited 2006-07-26 13:51
    would I need to change the char to an int if the information I am sending are numbers?
    thanks
  • RituRitu Posts: 39
    edited 2006-07-26 14:00
    If I want to use this stuff for the ADCDemo code given in the Javelin Manual, where do I put that into the code you have given me?
    thanks
  • RituRitu Posts: 39
    edited 2006-07-26 14:15
    Also for the ADCDemo I want numbers to continuously come out, no stopping, like a for loop that never stops. I tried to do this by haveing a while(true) loop but for some reason it only gives me 5 readings then stops. How can I fix this?
    thanks
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-07-26 14:24
    You can't just send numbers that are stored in an int.
    You can send the lowbyte, then the highbyte of an int:

    int value; //some value
    tx.sendByte(value); //send lowbyte of value
    tx.sendByte(value>>>8); //send highbyte of value

    On the receiving end these two bytes must be assembled into an int again.
    lowbyte = receive();
    highbyte = receive();
    value = (lowbyte&0xFF)|(highbyte<<8);

    For your other questions:
    Post your code so we can see what you (try to) do.
    And please post it as an attachement so we can load it
    into the JIDE and edit it.

    regards peter
  • RituRitu Posts: 39
    edited 2006-07-26 14:45
    Here is the code I have put together, I basically want the information in the Javelin to be sent to a radio, by way of a serial output.
    thanks
  • RituRitu Posts: 39
    edited 2006-07-26 15:12
    Is there anyway that I can send out the integer in ASCII, because the radio it is sent to cannot convert the high and low bytes?
    thanks
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-07-26 15:34
    You can use the Format class to convert a binary number to an asciiz string.
    You can specify the base (decimal,octal,binary,hexadecimal,unsigned) see
    pdf file for Format class.
    In the attachement I used decimal, eg. binary value 12 is converted to asciiz string "12"

    If your radio rquires a special start or stop character to identify the number,
    just insert a tx.sendByte() before or after the asciiz string is transmitted.

    You can download the Format class here:
    http://groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/util/text/

    regards peter
  • RituRitu Posts: 39
    edited 2006-07-26 15:53
    Is there a way for me to send out a $ before each thing I send to the radio?
    thanks
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-07-26 16:14
    You can insert a tx.sendByte('$') before sending the number.

    · public static void main() {
    ··· int value,i;
    ··· while(true) {
    ····· CPU.delay(1000);
    ····· value = adc.value(); //read adc
    ····· Format.sprintf(buf,"%d",value);· //convert binary number to asciiz string eg. binary 12 becomes "12"
    ····· i = 0;
    ····· tx.sendByte('$'); //identify start of number
    ····· while (buf[noparse][[/noparse]i] != 0) {
    ······· txUart.sendByte(buf[noparse][[/noparse]i++]); //send next char from asciiz string
    ····· }
    ··· }
    · }

    To identify the end of the ascii number, you can use
    tx.sendByte('!'); or whatever character you fancy (even binary 0).
    If you want your numbers to have equal length, you can use
    Format.sprintf(buf,"%5d",value);
    Each number is then rightjustified with space padding,
    eg. binary 12 becomes "·· 12"

    You can also do it all in one statement
    Format.sprintf(buf,"$%d ",value);
    binary 12 becomes "$12 "
    so the number starts after $ and stops before space.
    The buf array must then have length 9 instead of 7.

    regards peter
  • RituRitu Posts: 39
    edited 2006-07-26 16:46
    Sry this prob sounds stupid but what is a levelshifter and are all the pc pins you refer to pins that hook up to the radio transmitter?
  • RituRitu Posts: 39
    edited 2006-07-26 17:08
    Do I really need any of the pins besides the txpin? and ground? I have been told those are the only two that shoudl be necessary.
    Thanks
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-07-26 17:47
    A levelshifter like the MAX232 converts the javelin TTL levels (0V and 5V) into rs232
    levels (-12V and +12V). The pc expects rs232 levels.
    If your radio expects TTL levels than you don't need a levelshifter.

    If your radio only has a receive pin and never transmits anything,
    you only need the tx pin on the javelin (which connects to
    the radio receive pin, via levelshifter if necessary).

    regards peter
  • RituRitu Posts: 39
    edited 2006-07-26 18:13
    ack help its not transmitting to the radio, what do I do?
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-07-26 18:16
    Check your wiring and pin and power connections.
    Make sure the defined txPin is the pin connected to your radio.
    Also check wether you need rs232 or TTL levels.
    It could be the radio requires inverted signals.
    You can try
    · static Uart txUart = new Uart(Uart.dirTransmit,txPin,Uart.invert,Uart.speed4800,Uart.stop1);

    regards peter
Sign In or Register to comment.