Serial communication

Discussion in 'General Programming Discussion' started by Pablo, Oct 30, 2014.

  1. Pablo

    Pablo New Member

    Joined:
    Jan 21, 2014
    Messages:
    1
    Likes Received:
    0
    Hello there,

    I created a the link
    Code:
    sudo ln -sf /dev/ttymxc3 /dev/ttyS0
    Then, I wrote

    In Debian

    Code:
    #!/usr/bin/python
    
    import time
    import serial
    import commands
    arduino = serial.Serial('/dev/ttyS0', 9600)
    print("Hablando con Duino")
    while True:
       comando = 'H' #Input
       arduino.write(comando) #Mandar un comando hacia Arduino
       if comando == 'H':
          print('LED ENCENDIDO')
       elif comando == 'L':
          print('LED APAGADO')
       break
    arduino.close() #Finalizamos la comunicacion
    time.sleep(4)
    #output=commands.getoutput('sh /usr/bin/foto')
    

    In Arduino
    Code:
    int comedero = 3;
    int piloto = 13;
    
    void setup() {
    pinMode(comedero,OUTPUT);
    pinMode(piloto,OUTPUT);
    Serial.begin(9600);
    
    }
    void loop () {
    if (Serial.available()) {
    char c = Serial.read(); 
    if (c == 'H') { 
    
    digitalWrite(comedero, HIGH);
    delay(3000);
    digitalWrite(comedero, LOW);
    }
    
    if (c == 'W') { 
    digitalWrite(piloto, HIGH);
    }
    if (c == 'S') { 
    digitalWrite(piloto, LOW);
    }
    }
    digitalWrite(comedero, LOW);
    }

    But the LED i've put on the pin 3 of the UDOO doesn't go high, but it does when I upload the blink (changing pin 13 of the example to the 3 pin)
     
  2. mikelangeloz

    mikelangeloz Member

    Joined:
    Jul 9, 2013
    Messages:
    129
    Likes Received:
    1
    Why don't you use directly /dev/ttymxc3 in the python script? This could make the trick...
     
  3. xwalter

    xwalter Member

    Joined:
    Sep 8, 2014
    Messages:
    89
    Likes Received:
    4
    The communication channel between Arduino and ubuntu or else , in udoo, is the serial port /dev/ttymxc3
     
  4. xwalter

    xwalter Member

    Joined:
    Sep 8, 2014
    Messages:
    89
    Likes Received:
    4
    then in java or python you have to implement one or two threads to syncronized the communication and to close the port when you exit the application , otherwise you will have the serial port busy and not available for other application such as Arduino
     

Share This Page