1
\$\begingroup\$

I'm working on a project where a raspberry pi zero will be the main controller. The pi has to receive information from a GPS module (gy-gps6mv2) over UART. The same pi will be controlling (receive and transmit) a bare Atmega328 (let's call it an Arduino).

I'd like to stay away from USB. The project has to be compact. This means that I've only got one serial port on GPIO of the pi. I have considered softwareserial on the Arduino, passing the information to the pi, but the Arduino is already doing a lot of work and softwareserial is by no means reliable enough. Bitbanging GPIO pins on the pi to establish serial also doesn't seem like an amazing option.This means that I'll have to come up with another way to communicate with the Arduino.

I know both the pi and the Arduino have I2C and SPI, but there seems to be surprisingly little information out these about pi-arduino communication over any of these 2 protocols. The Arduino is already configured as a I2C master, communication to a barometric sensor (slave) so I assume (?) SPI is the only option left.

What would be the best way to establish this communication? Are there other ways to accomplish this? Does anyone have any experience with this?

EDIT

As some have pointed out, I should've provided more information.

The communication from the gps to the pi happens at baudrate 9600. The pi does not send anything back to the gps. The 2 way pi-Arduino communication has to be at least 9600 as well. There is a constant data stream between the pi and the Arduino, making MUX infeasible. As far as I understand, this also means that making the pi an I2C slave of the Arduino isn't really an option because I2C is needed for the barometer-Arduino communication (I2C is however new to me, my assumptions might not be right). I haven't tried bitbanging/softwareserial, but according to what I'm reading online, this takes a lot of processing power and the losses get up to 10%.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ How much data? What is the data rate? Which device should control the communication? Why isn't software serial "reliable enough" for you? What does "an amazing option" mean to you? You haven't provided nearly enough information to give you a good answer. \$\endgroup\$ Commented Aug 12, 2019 at 18:16

2 Answers 2

1
\$\begingroup\$

What is the data rate at which Pi (needs to) speaks to Arduino?

what is the data size?

what is the data interval?

Can Pi be interrupted by GPIO and act like a Slave?

Or Signal Arduino to switch to I2C slave mode..

Solution 1:

you can also use 2:1 Mux(analog switches) to multiplex UART lines between two devices for example..
when Pi is using UART for GPS module, the two UART lines of Pi gets connected to GPS module. When there is no data to be received The same UART lines can be connected to Arduino. One extra IC and one GPIO from Pi is needed for this.

Solution 2:
Arduino can control both Pi and the sensor. Pi can be configured to act like slave. Pi can interrupt Arduino via GPIO whenever Pi has something to communicate.

\$\endgroup\$
-1
\$\begingroup\$

Your question lacks lots of useful information.

Anyway, an easy answer to this problem would be just using the SoftwareSerial library on the ATmega. Connect one serial port (either the hardware or the software one) to the sensor and the other to the Pi.

\$\endgroup\$
2
  • 3
    \$\begingroup\$ The OP said that they have considered, and discarded, software serial. \$\endgroup\$ Commented Aug 12, 2019 at 19:47
  • \$\begingroup\$ @ElliotAlderson you're right. Sorry \$\endgroup\$
    – Iaka Noe
    Commented Aug 12, 2019 at 20:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.