noelia1210
Posts: 2
Joined: Tue Jan 27, 2015 9:56 pm

communication between raspberry and arduino using pyserial

Tue Jul 19, 2016 5:27 am

hi,

I'm new to pyserial and python, i'm working with a project in which i have to move a motor (stepper) every 5 min.
i'm using a raspberry pi to control the data measurement and an arduino to control the motor. I used pyserial and got them to talk but only to send or receive data, i need them to do both in the same code.
First i'm sending a message to the arduino for it to move the motor, and i want that, when the motor stops, the arduino sends an "ok" to the raspberry so I have reports of the motor movements.
The raspberry sends data, the arduino receives the data but when i tried to send the "ok" back to my rpi nothing happens. Can you help me please!! i've read a lot of information but i wasn't able to find an answer!!

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: communication between raspberry and arduino using pyseri

Tue Jul 19, 2016 7:23 am

noelia1210 wrote: The raspberry sends data, the arduino receives the data but when i tried to send the "ok" back to my rpi nothing happens. Can you help me please!! i've read a lot of information but i wasn't able to find an answer!!
Serial links are manual... by that I mean that you must control what happens at each end of the communication (send - receive) in each direction. Nothing is going to happen automatically.

(I may not understand what you mean, of course)

The serial link is full duplex... each end may send (buffered) and each end may recieve from the buffer. Coordinating the send-receive is up to you as programmer. You will need to develop some sort of 'protocol' for your system. Each end should 'expect' a certain communication , and each end needs to understand the 'protocol' for proper response for each transaction (whatever that is, its your system after all).

Do some debugging and make sure your serial connection is solid. Perhaps one Tx-Rx line is not connected ? .. loose wiring ? unplugged pin ? I'm just guessing here...

If the comm port works on both ends (check with debug jumper) and if each of the twisted paris Tx-Rx connection is good, then the rest of it is controlled by your software protocol (and you control that).

marcus
marcus
:ugeek:

dgordon42
Posts: 760
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: communication between raspberry and arduino using pyseri

Tue Jul 19, 2016 12:16 pm

Which Arduino model are you using?
Most Arduinos operate at 5Volts, whereas the Pi's GPIO pins operate at 3.3Volts. If you connect their serial ports together without a level shifter or potential divider, you will permanently damage the Pi's Serial Rx pin (physical pin 10), and probably the whole Pi.

It would also help to know which model Pi you have, and it's Operating System revision number, report the output of: "uname -a".

Dave.

lerner
Posts: 502
Joined: Sun Mar 29, 2015 12:12 am

Re: communication between raspberry and arduino using pyseri

Wed Jul 20, 2016 4:11 am

Ok, I'll jump in and ask a dumb question:

I don't know HOW the PYSERIAL works, but if it uses a USB port, what does the pi running on 3 volts have to do with things?

I am only jumping in here becuase soon I shall need to know/learn how to connect an Arduino to a PI too.

On the PC it is via the USB port and it does all the "magic" creating a fake serial port to the Arduino.

But I don't know if the PI does the same thing or not.

dgordon42
Posts: 760
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: communication between raspberry and arduino using pyseri

Wed Jul 20, 2016 9:47 am

@lerner,
The OP did not say how he connected his Arduino to his Pi.
If he connected the serial pins of a 5V Arduino directly to the serial pins on the Pi, he will damage the Pi's Rx pin, and find that he can send, but not receive, serial data, which is what he reports:
noelia1210 wrote:The raspberry sends data, the arduino receives the data but when i tried to send the "ok" back to my rpi nothing happens.
If he uses the USB ports to transfer the serial data, then the 3.3V issue is irrelevant as you suggest, and he has an error in the code running on the Pi and/or the Arduino.

We won't know until he replies.

Hope this helps,
Dave.

lerner
Posts: 502
Joined: Sun Mar 29, 2015 12:12 am

Re: communication between raspberry and arduino using pyseri

Wed Jul 20, 2016 9:45 pm

Dave,

No prob's.

I am hoping that they reply to clarify that too. That way I shall learn what not to do.

Return to “Beginners”