Serial communication between UDOO NEO and external Arduino

Discussion in 'UDOO NEO' started by Amit Pasquini, Jun 12, 2017.

  1. Amit Pasquini

    Amit Pasquini New Member

    Joined:
    Jan 9, 2016
    Messages:
    5
    Likes Received:
    1
    Hi all!
    I'm trying to make a project which involves using UDOO NEO as a webserver with an HTML page I made.
    The webserver is made following the tutorial:
    https://www.udoo.org/control-udoo-neos-arduino-web-page/
    And despite some troubles (I had to install python-dev using synaptic) I managed to set it up.
    Now the server sends data to the internal /dev/ttyMCC serial port and using a proper Arduino code I can also read it using the terminal.
    With this data I then wanted to control an addressable LED strip (ws2812b aka NeoPixels) but the neoPixel library can't be used on UDOO because of interrupts.
    So i decided to use an external Arduino thinking that I could have used serial communication between them, but I can't.
    I connected pin 1 and 0 of the Arduino to 44 and 45 respectively and this is what I uploaded: [UDOO side]
    Code:
    void setup() {
    Serial.begin(115200);
    Serial0.begin(115200);
    pinMode(13,OUTPUT);
    }
    
    void loop() {
      while(Serial.available()>0){
        int inByte = Serial.read();
        Serial.write(inByte);
        digitalWrite(13,HIGH);
        //delay(500);
        //Serial0.write(inByte);
      }
     
      digitalWrite(13,LOW);
     
    }
    as you can see from the comment I also tried to use the Serial0 (UART5 aka 1 and 0 pins) but it seems that those aren't activated:
    Code:
    udooer@udooneo:~$ ls -l /dev/ttymxc*
    crw-rw---- 1 root tty  207, 16 Jan  1 00:00 /dev/ttymxc0
    crw------- 1 root root 207, 18 Jan  1  1970 /dev/ttymxc2
    udooer@udooneo:~$
    
    
    In Arduino side instead:
    Code:
    void setup() {
      Serial.begin(115200);
      pinMode(13,OUTPUT);
    }
    
    void loop() {
      while(Serial.available()>0){
        Serial.write(Serial.read());
        //Serial.println(Serial.read());
        digitalWrite(13,HIGH);
        }
      digitalWrite(13,LOW);
    }
    My problem is that the strings that I write on the serial monitor appear only on the side I'm writing in.
    What can I do? Any help will be appreciated
     
  2. Gorgo

    Gorgo UDOOer

    Joined:
    Nov 9, 2016
    Messages:
    159
    Likes Received:
    17
  3. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    If you connect 2 Arduino's you have to use Serial0() (pin 0/1) from Arduino Neo sketch to communicate with the other Arduino (with Serial(), pin 0/1). Serial0 of the Arduino Neo is preinstalled so no changes needed, it is not accessible from linux.
    Be aware that the Arduino Neo is 3.3V and for example a Arduino UNO is 5V so you need a logical level shifter (although it depends on who you ask).

    UART2 (pin44/45) can be used for debugging the M4 Linux side but cannot be used for communication.
     
  4. Amit Pasquini

    Amit Pasquini New Member

    Joined:
    Jan 9, 2016
    Messages:
    5
    Likes Received:
    1
    So I also tried as you Waltervl said also in another thread, connecting Arduino 0/1 pins to Udoo Neo 0/1 pins, but also this does not work
    Code:
    void setup() {
    Serial.begin(115200);
    delay(100);
    Serial0.begin(115200);
    delay(100);
    pinMode(13,OUTPUT);
    }
    
    void loop() {
      if(Serial.available()){
        int inByte = Serial.read();
        Serial0.write(inByte);
        digitalWrite(13,HIGH);//used as visualization feedback
      }
    else digitalWrite(13,LOW);
    }
     
  5. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    What does not work? Is the Led 13 not switching on?
    Serial0 on Arduino Neo is definitely working, but perhaps not on 115200 baudrate.
    Also you use write() instead of print() which also is a known issue on Arduino Neo.

    You know you have to crosswire? So Neo TX connect to Arduino RX and Neo RX to Arduino TX.
     
  6. Amit Pasquini

    Amit Pasquini New Member

    Joined:
    Jan 9, 2016
    Messages:
    5
    Likes Received:
    1
    Yes yes, I've done the crosswire.
    Sorry if I wasn't clear enough.
    What I'm trying to do is to communicate between the two devices.
    From the Udoo's serial port I want to write a string (writing from the serial monitor), then from the Arduino's serial monitor I want to see what I've written. Maybe using the vpn connection can be a problem (?).
    The LED flashes only when writing from udoo's serial monitor
    Anyway I want to thank you for your help.
    the schematic is as follows:
    Arduino 0 - Udoo 1
    Arduino 1 - Udoo 0
    I've also grounded them toghether
     
  7. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    I do not understand your scheme. What kind of Arduino are you using?
    Serial() on the Arduino Neo is the communication with Neo Linux (or remote serial monitor). Your sketch is only listening to Serial() so the flashing is correct.
    On a normal Arduino Uno this sketch is not working because it has no Serial0()

    If you connect on a normal Arduino Uno the Tx/Rx pins and listen to the serial monitor connected to the USB of this Arduino Uno you are reading and sending on the same port and I do not know if that is working.
     
  8. Amit Pasquini

    Amit Pasquini New Member

    Joined:
    Jan 9, 2016
    Messages:
    5
    Likes Received:
    1
    My Arduino is a Leonardo.
    My goal, in the end, is to have Arduino to do something when a certain string comes from the serial. This string is sent from the Udoo once it receives it from the other serial. I have a webserver set up and managed to send this string to the internal serial and I can also visualize it on the terminal. So my trouble here is to make Udoo and Arduino communicate toghether, and thought that I could have used the Serial0 to do the job.
    So the logic is: Udoo receives data from internal Serial (done) then sends this data to another serial (Serial0) at which Arduino is connected. Arduino then decides what to do.
     
  9. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    In the sketch of the Leonardo you have to use Serial1() to receive the data from Udoo Arduino (sent by Serial0()).
     
    Gorgo likes this.
  10. Amit Pasquini

    Amit Pasquini New Member

    Joined:
    Jan 9, 2016
    Messages:
    5
    Likes Received:
    1
    That worked!!
    Thank you so much!
     
    waltervl likes this.

Share This Page