Page 1 of 1

Raspberry Arduino serial comunication problem

Posted: Sun Mar 23, 2014 10:22 am
by Astenoth
Hi,
I have a simple python script to test the communications between the Raspberry and the Arduino Uno.
In the Raspberry:

Code: Select all

#!/usr/bin/env python

import serial

arduino = serial.Serial('/dev/ttyACM0', 9600)
arduino.open()
arduino.write('D')
arduino.close()
In the Arduino:

Code: Select all

int dia = 9;
int dPWD;

void setup(){
  Serial.begin(9600);
  pinMode(dia,OUTPUT);
}

void loop (){
  if (Serial.available()){
    char c = Serial.read();
    if (c=='D'){
      //dPWD=Serial.parseInt();
      analogWrite(dia,255);
      Serial.flush();
    } else if (c=='E'){
      analogWrite(dia,0);
      Serial.flush();
    }
  }
}
When I run the python script the Arduino don't work.
I instaled the Arduino program in the Raspberry and I test the code in Arduino with the serial monitor and it go fine. I think that it is not comunication problem.
Could somebody help me?. I tried it solve a week... :?

Re: Raspberry Arduino serial comunication problem

Posted: Mon Mar 24, 2014 9:39 am
by Astenoth
Hi
I solved the problem... I founnd the below in Arduino web page...
It is worth noting that the example above will not work on a windows machine; the arduino serial device takes some time to load, and when a serial connection is established it resets the arduino.
I don't understand why... my python script is running in the raspberry and no in windows machine.... but it is solved with:

Code: Select all

time.sleep(2)
After the python opened the serial comunication.

Regards
Raul

Re: Raspberry Arduino serial comunication problem

Posted: Mon Mar 24, 2014 9:51 am
by DougieLawson
Have you disabled the serial console on /dev/ttyACM0?

Look in /boot/cmdline and /etc/inittab remove any references to /dev/ttyACM0 and reboot.

Re: Raspberry Arduino serial comunication problem

Posted: Tue Mar 25, 2014 9:36 am
by Astenoth
First thanks.
DougieLawson wrote:Look in /boot/cmdline and /etc/inittab remove any references to /dev/ttyACM0 and reboot.
I reviewed the two files and there are not about ttyACM0.

Regards
Raul

Re: Raspberry Arduino serial comunication problem

Posted: Tue Mar 25, 2014 11:43 am
by DougieLawson
When you connect your Arduino what device appears?

Unplug it.
Plug it back in.
Look at the kernel messages with a dmesg command.

Re: Raspberry Arduino serial comunication problem

Posted: Tue Mar 25, 2014 1:15 pm
by Astenoth
When I connect the new device in the list is:
/dev/ttyACM0

Regards
Raul

Re: Raspberry Arduino serial comunication problem

Posted: Tue Mar 25, 2014 1:21 pm
by DougieLawson

Re: Raspberry Arduino serial comunication problem

Posted: Tue Mar 25, 2014 6:57 pm
by Astenoth
Hi,

I reviewed all them, and all are ok and I updated the raspberry firmware too. But the USB communication go fine with the time.sleep only.

Thanks.
Raul