Control Arduino side with c code in gedit

Discussion in 'General Programming Discussion' started by msener, Dec 3, 2014.

  1. msener

    msener New Member

    Joined:
    Dec 1, 2014
    Messages:
    6
    Likes Received:
    0
    Hi,

    I want to control Arduino side of Udoo with c code.
    On arduino side, I have a code like turn on LED when I press 1.
    When I wrote to terminal

    stty -F/dev/ttymxc3 cs8 115200
    echo message> /dev/ttymxc3 1

    it is working.

    But I wrote a simple c code at gedit.

    #include <stdio.h>
    int main(void)
    {
    int a;
    printf("character\n");
    scanf("%d", &a);
    printf("echo message > /dev/ttymxc3 %d \n", a);

    return 0;
    }

    I execute program at terminal
    ./LED
    I input character
    and output is " echo message> /dev/ttymxc3 1 ".
    But it doesn't effect the Arduino side.
    I think, I must add some c code for serial but how I don't know.
    Can you help?
    Thank you.
     
  2. gionji

    gionji Member

    Joined:
    Jun 28, 2013
    Messages:
    38
    Likes Received:
    0
    Hi,

    printf("echo message > /dev/ttymxc3 %d \n", a);

    prints a string on stdio, you need a syscall to write this string on a "console".

    #include <stdio.h>
    #include <string.h>

    int main ()
    {
    char command[50];

    strcpy( command, "echo message > /dev/ttymxc3 1" );
    system(command);

    return(0);
    }

    In next few days we'll release a guide to communicate on serial :D

    Regards
     

Share This Page