andrsimo
andrsimo

Reputation: 21

Raspberry pi serial port data wrong

I connected an Arduino Board to Raspberry through an USB port. With a Processing code i want to read 70 bytes sended by arduino. If i use this program on my PC windows it works, but with Raspberry the data that i get from Processing are different from the data sended by arduino. This is the Processing code to read the serial port:

import processing.serial.*;
Serial uart;
byte[] codice= new byte[70];

void setup() {
  uart= new Serial(this, Serial.list()[1], 9600);
}

void draw() {
  if (uart.available()>0) {
    codice=uart.readBytes();
    println(codice);
  }
}

In my case the serial port is "dev/ttyUSB0". I tried also with python in this way:

>>> import serial
>>> ser = serial.Serial('/dev/ttyUSB0', 9600)
>>> while True:
 ...     print ser.readline()

Also in python there is the same error. I also tried to change the baud rate (115200) with the same result.

Upvotes: 1

Views: 1358

Answers (1)

codeflag
codeflag

Reputation: 191

Unplug your Arduino, search with ls /dev/tty* and plug it in.
If you now search again with ls /dev/tty* you will see a new device, for example /dev/ttyACM0. Additionally you need the arduino drivers to emulate the COM-Port sudo apt-get update && sudo apt-get install arduino.

Arduino Code

void setup(){
  Serial.begin(9600);
}

void loop(){
  Serial.println(“Hello Raspi”);
  delay(3000);
}

Raspberry Pi Code-Snippet

import serial
ser = serial.Serial('/dev/ttyACM0', 9600)

Try the python example on this page: How to attach an Arduino?

Upvotes: 0

Related Questions