Feltros
Posts: 2
Joined: Sat Apr 20, 2013 11:03 am

Communication between ATMega to Pi

Sat Apr 20, 2013 11:15 am

Hi All,

I am attempting a prototype robotics project (A moving arm with grippers to begin with).
I have to say a big thank you to Gert as his manual for the gertboard has allowed me to easily write code on to the ATMega which will handle servo control, along with analog inputs.

I am however a little confused as to how communication in general occurs between the RPi and the ATMega chip - as I would like eventually for a Java 'control' program to tell the ATMega which hardware operations to carry out.
I have considered using 5 of the digital inputs to the ATMega and treating them as a 5bit input to an ATMega program which would constantly loop and detect a change in their result. This seems like it could easily go wrong however, as the RPi could not be guaranteed to write the individual bits quick enough to prevent a mis-read. It also leaves me with only 32 options to carry out, and few spare pins to deal with sending readings from analog sensors (Such as a temperature sensor) back to the pi.

Am I missing an obvious bi-directional communication mechanism between these two?

If there is such a mechanism please bear in mind my electronics knowledge is relatively basic, so if anyone knows of a blog/tutorial where someone had use this mechanism and I could read about it in a step by step fashion that would be fantastic.

btidey
Posts: 1633
Joined: Sun Feb 17, 2013 6:51 pm

Re: Communication between ATMega to Pi

Sat Apr 20, 2013 1:08 pm

You can just connect the serial uart on the ATMega and the serial uart on the GPIO. These are on different pins than the SPI used for downloading making it easier to debug. Arduino libraries have Serial support making it easy to send and receive data. You can use a console program like minicom on the Raspberry to manually send stuff and display whatever the AT Mega sends. Then add the serial support on the Raspberry for program control.

Main restriction will be the speed. 9600 baud will give about 1000 characters / sec. 115000 baud will give about 12000 characters per second.

Feltros
Posts: 2
Joined: Sat Apr 20, 2013 11:03 am

Re: Communication between ATMega to Pi

Sat Apr 20, 2013 1:26 pm

Thanks btidey. I have got the ATMega sending analog inputs over the serial connector to Minicom which works rather nicely.

If I am dealing with bi-directional communication, (IE the ATMega sending lots of sensor readings to the Pi and the Pi sending new commands to the ATMega) do I need to worry about them clashing over the serial port, or does it naturally handle blocking one side from writing whilst the other side sends?

btidey
Posts: 1633
Joined: Sun Feb 17, 2013 6:51 pm

Re: Communication between ATMega to Pi

Sat Apr 20, 2013 10:32 pm

There is no problem with sending and receiving over the two paths simultaneously. They are effectively independent links. However, you really should use one central routine at each end to send data to make sure messages are sent in an orderly fashion and avoid separate send messages getting interleaved.

Return to “HATs and other add-ons”