Like Tree2Likes
  • 2 Post By Salem

help in c communication with arduino

This is a discussion on help in c communication with arduino within the C Programming forums, part of the General Programming Boards category; hello, iam begginer in c.. and i need some help. Iam trying to send 0x20 from arduino and get the ...

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    4

    help in c communication with arduino

    hello,
    iam begginer in c.. and i need some help. Iam trying to send 0x20 from arduino and get the hex in c program on the pc iam using
    RS-232 for Linux and Windows lirary for rs232 communication and when i send 0x20 i get 28ef30 i dont know why.. but i want to get 20 integer type value in c program

    the code that i use in c is
    Code:
    n = PollComport(cport_nr, buf, 4095);
    
        if(n > 0)
        {
          buf[n] = 0;   /* always put a "null" at the end of a string! */
    
    
          for(i=0; i < n; i++)
          {
            if(buf[i] < 32)  /* replace unreadable control-codes by dots */
            {
              buf[i] = '.';
            }
          }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    And how did you print it?

    Additionally, what is the code you used to do the sending?

    Because getting something like 28ef30 looks a lot like you sent an address, rather than some data.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    4
    i found out that you can print it but i want to do somthing like if buf == 20 do that.. this was printed i think using %x

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    Well that really helps to clear things up for us.

    > when i send 0x20 i get 28ef30 i dont know why.. but i want to get 20 integer type value in c program
    OK, do you send
    - A single space character, which as a single char is decimal 32, or hexadecimal 0x20
    - A string of 4 characters "0x20" which you then parse.

    What does "20 integer type" mean?

    How To Ask Questions The Smart Way
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,344
    I'm guessing that you are using the sample program from the website, so I doubt if there is anything wrong with that code. I don't know if this is still a problem with the Arduino, but when serial communication is established, the program on the Arduino used to reset.

    What are you doing with the Arduino code?

    [edit]
    Try running this code from the Arduino
    http://arduino.cc/en/Tutorial/ArduinoSoftwareRS232

    Have you set up any hardware (MAX232) for the comms? Are you using some sort of breakout board?
    [/edit]
    Last edited by Click_here; 02-05-2013 at 05:50 PM.
    Fact - Beethoven wrote his first symphony in C

  6. #6
    Registered User
    Join Date
    Feb 2013
    Posts
    4
    on arduino there is just 1 line of code Serial.println(0x20, HEX); and it is connected to my usb port..
    and yes iam using default code from the page.
    the only thing i want to do is to send int and get the int from arduino to c..
    thanks alot for replys
    Last edited by kapustelis; 02-06-2013 at 12:54 AM.

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    > on arduino there is just 1 line of code Serial.println(0x20, HEX); and it is connected to my usb port..
    So it has this specification then -> Arduino - Println
    So it seems on the face of it that you're expecting "0x20\r\n" down the wire.


    You still haven't shown us what you do with 'buf' (see post #1) to print it.


    Arduino - Serial
    You can use the Arduino environment's built-in serial monitor to communicate with an Arduino board. Click the serial monitor button in the toolbar and select the same baud rate used in the call to begin().
    Have you done this?
    Does it work?
    If it does, the problem is entirely in your 'C' code running on the host.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    Registered User
    Join Date
    Feb 2013
    Posts
    4
    when i use &x to print it i get 28ef30, when i use some other i think &s i get 20.. cant rly say because now i dont have the arduino right now and cant tell you 100%. And iam sure that arduino code is okei because i did alot of arduino projects.. and the code in arduino is just for testing c and thats why its just 1 line

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    > when i use &x to print it i get 28ef30, when i use some other i think &s i get 20..
    Why does it seem like you're printing the ADDRESS of a variable?
    You seem to be spraying & though your printf calls (you're mistaking them for scanf calls) like there is no tomorrow - and it's just plain wrong.

    Code:
    int x = 20;
    int y = 0x20;
    printf("X: Dec=%d, hex=%x, address=%p\n", x, x, &x );
    printf("Y: Dec=%d, hex=%x, address=%p\n", y, y, &y );
    Next time, SHOW YOUR CODE FFS.
    Click_here and AndiPersti like this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. arduino
    By Annonymous in forum Tech Board
    Replies: 7
    Last Post: 05-29-2012, 11:13 PM
  2. Arduino LED Clock
    By qtip2293 in forum C++ Programming
    Replies: 1
    Last Post: 10-11-2011, 02:05 PM
  3. Arduino project programming question
    By qtip2293 in forum C++ Programming
    Replies: 10
    Last Post: 10-10-2011, 03:57 PM
  4. moving multiple servos through Arduino board
    By cross-side in forum C Programming
    Replies: 26
    Last Post: 02-17-2011, 10:08 PM
  5. Arduino programming
    By Terese in forum C++ Programming
    Replies: 5
    Last Post: 12-11-2010, 12:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21