Raymondo02
Posts: 8
Joined: Thu Apr 18, 2019 11:48 pm

problem with connection Raspberry pi to Arduino

Fri Apr 19, 2019 12:07 am

Hello everyone,
I have a problem with sending a message from Raspberry pi to Arduino. I use on my raspberry pi Python IDLE to send message to my arduino uno. When I run my program, I got a problem message :

Code: Select all

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 265, in open
    self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
FileNotFoundError: [Errno 2] No such file or directory: '/dev/ttyACM0'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/Arduino Et Raspi/arduino&raspi1.py", line 4, in <module>
    ser = serial.Serial('/dev/ttyACM0', 9600)
  File "/usr/lib/python3/dist-packages/serial/serialutil.py", line 236, in __init__
    self.open()
  File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 268, in open
    raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
serial.serialutil.SerialException: [Errno 2] could not open port /dev/ttyACM0: [Errno 2] No such file or directory: '/dev/ttyACM0'
>>> 
The arduino program runs perfectly. I can sand a message to my raspi with my arduino, but not the opposite.
My program on my arduino for my test is :

Code: Select all

#define LED1 2
#define LED2 3
#define LED3 4

int message = 0;


void setup()
{
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  
  Serial.begin(9600);
}

void loop()
{
  if (Serial.available())  {
    message = Serial.read()-'0';  // on soustrait le caractère 0, qui vaut 48 en ASCII
    
    switch (message) {
    case 1:
      digitalWrite(LED1, HIGH);
      break;
    case 2:
      digitalWrite(LED2, HIGH);
      break;
    case 3:
      digitalWrite(LED3, HIGH);
      break;
    case 4:
      digitalWrite(LED1, LOW);
      break;
    case 5:
      digitalWrite(LED2, LOW);
      break;
    case 6:
      digitalWrite(LED3, LOW);
      break;
    }
  }
}
and on my raspi is :

Code: Select all

import serial  # bibliothèque permettant la communication série
import time    # pour le délai d'attente entre les messages

ser = serial.Serial('/dev/ttyACM0', 9600)
time.sleep(2)
compteur = 0
while True:     # boucle répétée jusqu'à l'interruption du programme
    if compteur < 6:
	    compteur = compteur + 1
    else:
	    compteur = 0
    ser.write(str(compteur))
    time.sleep(1)               # on attend pendant 2 secondes
I googled for several hours without finding an answer to my problem.
So help me please.

Andyroo

Re: problem with connection Raspberry pi to Arduino

Fri Apr 19, 2019 12:35 am

Are they connected via a USB to serial adapter?

If so, you could try /dev/ttyUSB0

Can you also post the output of

Code: Select all

lsusb

Raymondo02
Posts: 8
Joined: Thu Apr 18, 2019 11:48 pm

Re: problem with connection Raspberry pi to Arduino

Sat Apr 20, 2019 12:45 pm

They are connected via a USB to serial adapter. I try /dev/ttyUSB0 and it doesn't work.
This is the output of lsusb:

Code: Select all

Bus 001 Device 007: ID 2341:0043 Arduino SA Uno R3 (CDC ACM)
Bus 001 Device 005: ID 0424:7800 Standard Microsystems Corp. 
Bus 001 Device 003: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub
Bus 001 Device 002: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Return to “General discussion”