Astenoth
Posts: 19
Joined: Thu Jan 30, 2014 12:25 pm

Raspberry Arduino serial comunication problem

Sun Mar 23, 2014 10:22 am

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... :?

Astenoth
Posts: 19
Joined: Thu Jan 30, 2014 12:25 pm

Re: Raspberry Arduino serial comunication problem

Mon Mar 24, 2014 9:39 am

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

User avatar
DougieLawson
Posts: 39304
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Raspberry Arduino serial comunication problem

Mon Mar 24, 2014 9:51 am

Have you disabled the serial console on /dev/ttyACM0?

Look in /boot/cmdline and /etc/inittab remove any references to /dev/ttyACM0 and reboot.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Astenoth
Posts: 19
Joined: Thu Jan 30, 2014 12:25 pm

Re: Raspberry Arduino serial comunication problem

Tue Mar 25, 2014 9:36 am

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

User avatar
DougieLawson
Posts: 39304
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Raspberry Arduino serial comunication problem

Tue Mar 25, 2014 11:43 am

When you connect your Arduino what device appears?

Unplug it.
Plug it back in.
Look at the kernel messages with a dmesg command.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Astenoth
Posts: 19
Joined: Thu Jan 30, 2014 12:25 pm

Re: Raspberry Arduino serial comunication problem

Tue Mar 25, 2014 1:15 pm

When I connect the new device in the list is:
/dev/ttyACM0

Regards
Raul

User avatar
DougieLawson
Posts: 39304
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Raspberry Arduino serial comunication problem

Tue Mar 25, 2014 1:21 pm

Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Astenoth
Posts: 19
Joined: Thu Jan 30, 2014 12:25 pm

Re: Raspberry Arduino serial comunication problem

Tue Mar 25, 2014 6:57 pm

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

Return to “Python”