Solved: Help with Serial Communication on UDOO Quad

Discussion in 'Troubleshooting' started by itfarmer, Feb 11, 2014.

  1. itfarmer

    itfarmer New Member

    Joined:
    Feb 11, 2014
    Messages:
    4
    Likes Received:
    0
    I've been trying like crazy to get my UDOO Quad running Ubunto 12.04 LTS to communicate from the onboard Arduino to a perl script. I've been troubleshooting the issue quite a bit, and have paired down my code to the smallest script possible:

    void setup(){
    Serial.begin(115200);
    pinMode(A0, INPUT);
    pinMode(A1, INPUT);
    }

    void loop(){

    int a0 = analogRead(AO);
    Serial.print("AO:");
    Serial.print(a0);

    int a1 = analogRead(A1);
    Serial.print("A1:");
    Serial.print(a1);

    }

    When I upload this program via the Arduino IDE on the UDOO board itself, There is a brief message about "Warning undefined reference to '_sbrk', but the program finishes compiling, and uploads.

    I'm not very familiar with C, but I believe I would get a compile error if there was a code issue.

    When I try to use the Serial Monitor pointing at Serial Port '/dev/ttymxc3' from the Arduino IDE running on the UDOO, it doesn't show any serial traffic. Nothing. The way I understand the Arduino script above, it should check the states of two analog ports, and shovel that information to the serial port continuously.

    Can anyone help me find out why there is no serial traffic from the Serial Monitor ? There has to be a jumper set wrong, or maybe I'm using the wrong serial port. Any help would be greatly appreciated. Thanks in advance.
     
  2. itfarmer

    itfarmer New Member

    Joined:
    Feb 11, 2014
    Messages:
    4
    Likes Received:
    0
    Re: Help with Serial Communication on UDOO Quad

    I've made some progress with my project, and wanted to share it with any others who might be frustrated.

    By using this tutorial:

    http://www.elinux.org/UDOO_programming_ ... controller

    I was able to use this part of the tutorial to upload my Arduino code:

    ++++++++++++++++++++++

    "Using Arduino IDE without UDOO patch
    A different way for programming the Arduino side without applying patches consists in stopping the board at U-boot stage before the Kernel is loaded
    To do so you’ll have to:
    1. Download and install a serial monitor program (Teraterm for Windows, Minicom for Linux, serial tools for OS X). Please check the appendix for the configuration and the parameters of these software tools.
    2. Connect the external Host PC through the microUSB port CN6, taking care that jumper J18 is plugged. Then insert the power plug and start the system. On the serial monitor it will appear something similar:
    U-Boot 2009.08 (Sep 27 2013 - 12:30:44)
    CPU: Freescale i.MX6 family TO1.2 at 792 MHz
    Thermal sensor with ratio = 181
    Temperature: 50 C, calibration data 0x5774fa69
    mx6q pll1: 792MHz
    mx6q pll2: 528MHz
    mx6q pll3: 480MHz
    mx6q pll8: 50MHz
    ipg clock : 66000000Hz
    ipg per clock : 66000000Hz
    uart clock : 80000000Hz
    cspi clock : 60000000Hz
    ahb clock : 132000000Hz
    axi clock : 264000000Hz
    emi_slow clock: 132000000Hz
    ddr clock : 528000000Hz
    usdhc1 clock : 198000000Hz
    usdhc2 clock : 198000000Hz
    usdhc3 clock : 198000000Hz
    usdhc4 clock : 198000000Hz
    nfc clock : 24000000Hz
    Board: i.MX6Q-UDOO: unknown-board Board: 0x63012 [WDOG]
    Boot Device: NOR
    I2C: ready
    DRAM: 1 GB
    MMC: FSL_USDHC: 0,FSL_USDHC: 1,FSL_USDHC: 2,FSL_USDHC: 3
    In: serial
    Out: serial
    Err: serial
    Net: got MAC address from IIM: 00:00:00:00:00:00
    FEC0 [PRIME]
    Hit any key to stop autoboot: 3
    Hit any key to stop autoboot: 2
    Hit any key to stop autoboot: 1
    3. Before the counter reaches 0, press any key on the external PC’s serial console.
    i.Mx6Q_UDOO_BOOT> _
    4. Close the serial monitor and unplug J18 jumper. This will allow the communication with the programming port of SAM3X;
    5. Plug the jumper J22 for 1 second, then remove it (to erase the old sketch programmed in SAM3X);
    6. Plug the jumper J16 for 1 second, thend remove it (to reset the SAM3X);
    7. Select from the IDE: Tools –> Board –> Arduino DUE programming port and select the correct serial COM from the IDE;
    8. Send the sketch using the IDE upload button.
    9. Press the reset button to restart i.MX6 and use Ubuntu or Android again."

    ++++++++++++++++++++


    The instructions sound very complicated, but I happened to notice that after step 7 was completed, all I need to do to upload sketches is press Command+U or (File->Upload). So long as the usb cable was connected, and Jumper 18 is unplugged, the code uploads well, with no errors, and without all the jumper movements.

    From this point, I can see the arduino sketch working by opening up Serial Tools on the Mac (https://itunes.apple.com/us/app/serialt ... 1963?mt=12).

    Here's the sketch that I have uploaded:
    void setup() {
    Serial.begin(115200);
    }

    void loop() {
    if (Serial.available() > 0){
    char inChar = Serial.read();
    Serial.print(inChar);
    }
    }

    If I press any key on the serial monitor, it send the key-press to the arduino sketch, which simply echo's it back.

    At this point I'm still left with some pretty significant problems:

    I cannot duplicate the serial monitoring capability from the UDOO board itself, using the Ardunio IDE's Serial Monitor.
    I cannot echo text to perl, or back to the Arduino.
    I believe my issue is centered around the Serial port involved, or the serial ports configuration on Ubuntu.

    I've decided to continue to post to this forum even if I receive no replies. I have found these forums to be exceptionally helpful in the past, and maybe I can help someone, if only with my one-sided ramblings....
     
  3. gokumars

    gokumars New Member

    Joined:
    Feb 22, 2014
    Messages:
    5
    Likes Received:
    0
    Re: Help with Serial Communication on UDOO Quad

    I can successfully get the arduino to transmit code and show it on a serial terminal both in windows externally and on the serial terminal I added to ubuntu 12.04, however, the communication is entirely 1 way! Arduino out. I can get nothing to send to the Arduino.

    A nice link to the Arduino out
    http://imusic1.ucsd.edu/~dmedine/udoo_g ... t/S2.xhtml


    However, I cannot get the arduino to accept any incoming traffic from here or through the usb connection to another computer. If you want the code as below;

    sorry for some of the fluff, it's from another project where the arduino actually DID echo code properly back through the usb connector.

    IF ANYONE can advise if there is something missing that allows the sam3x to receive serial as well as send, that would be much appreciated.

    //setup for blinking led with command serial
    volatile int count = 30;
    volatile boolean toggle = false;
    volatile boolean running = false;
    volatile int laser_duty = 900;
    volatile int laser_period_us = 1000;
    String inputString = ""; // a string to hold incoming data
    String inputDigit = ""; // a string to hold incoming numberical data
    boolean stringComplete = false; // whether the string is complete


    int led = 13;//pin led is on
    //boolean flag
    //String inputString = ""; // a string to hold incoming data
    //boolean stringComplete = false; // whether the string is complete

    void setup()
    {
    // initialize serial:
    Serial.begin(9600);
    delay(200);
    inputString.reserve(200);
    inputDigit.reserve(200);
    Serial.println("\n[pulse_demo]");

    // reserve 200 bytes for the inputString:
    pinMode(led,OUTPUT);
    digitalWrite(led,LOW);
    Serial.println("ready to start");
    }

    void loop()
    {
    //Serial.println("ready to start");
    // print the string when a newline arrives:
    if (stringComplete)
    {
    Serial.println("you entered "+inputString);
    if(inputString.indexOf("run")!=-1)
    {
    digitalWrite(led,HIGH);
    }
    if(inputString.indexOf("stop")!=-1)
    {
    digitalWrite(led,LOW);
    }

    if(inputString.indexOf("period")!=-1)
    {

    laser_period_us = inputDigit.toInt();
    Serial.print("Laser PWM Period = ");
    Serial.print(laser_period_us);
    Serial.println(" microseconds");
    }

    if(inputString.indexOf("duty")!=-1)
    {
    laser_duty = inputDigit.toInt();
    Serial.print("Laser Duty cycle = ");
    double fraction = (double)(laser_duty)*laser_period_us/1023;
    Serial.print(fraction);
    Serial.println(" microseconds");
    }


    // clear the string:
    inputString = "";
    inputDigit = "";
    stringComplete = false;
    }
    }

    /*
    SerialEvent occurs whenever a new data comes in the
    hardware serial RX. This routine is run between each
    time loop() runs, so using delay inside loop can delay
    response. Multiple bytes of data may be available.
    */
    void serialEvent()
    {
    while (Serial.available())
    {
    // get the new byte:
    int inDig = Serial.read();
    char inChar = (char)inDig;
    // add it to the inputString:
    inputString += inChar;
    if(isDigit(inDig))
    {
    inputDigit += (char)inDig;
    }
    // if the incoming character is a newline, set a flag
    // so the main loop can do something about it:
    //if (inChar == 0xA || inChar == 0xD)
    //{
    stringComplete = true;
    // Serial.print(inputDigit.toInt());
    //}
    }
    }
     
  4. itfarmer

    itfarmer New Member

    Joined:
    Feb 11, 2014
    Messages:
    4
    Likes Received:
    0
    Re: Help with Serial Communication on UDOO Quad

    Gokumars;

    I shelved this project while I attended to others, but I just had some limited success. I can send data from a perl script (running on the Ubuntu udoo dist), and the arduino can receive the data. The weird part is that the arduino will not send data back to the perl script, but I can see the returned information on the Arduino Serial Monitor..... very odd.

    Here's my Arduino Program:

    void setup(){

    Serial.begin(115200);

    }

    void loop(){

    if (Serial.available() > 0){

    char inChar = Serial.read();
    Serial.print("Read Character:");
    Serial.print(inChar);
    Serial.print("\n");


    }

    }

    My perl script is pretty simple too. You can do a "gedit serialcom.pl" from terminal to create the file, then the code is:

    use Device::SerialPort;
    my $port = Device::SerialPort->new("/devttymxc3");
    $port->baudrate(115200);
    $port->databits(8);
    $port->parity("none");
    $port->stopbits(1);

    print "Enter character to send to Arduino:\n";


    while ($i == 1){

    my $char = $port->read();
    if ($char){
    print $char;
    } else {
    $in = <STDIN>;
    $port->write($in);
    print ".";
    }
    }

    }

    Then to execute the script browse to the directory it's saved in and type "perl serialcom.pl" to run the script.
     
  5. itfarmer

    itfarmer New Member

    Joined:
    Feb 11, 2014
    Messages:
    4
    Likes Received:
    0
    Re: Help with Serial Communication on UDOO Quad

    The two scripts will exchange serial communication, but in order for the data to go from the Arduino to the perl script, you will need to close the Arduino IDE, and any other Serial Monitor programs. It seems when you have a serial monitor, it reads the data, and deletes it from the buffer. This prevents the linux program from receiving anything.

    * Note, I've added the following to my Perl script, line 2, just above "use Device::SerialPort;"

    system(" stty -F /dev/ttymxc3 cs8 115200 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts ");
     

Share This Page