I have a project that I prefer split on two arduinos, that is my idea:
1° Arduino: Controller GPRS with reading SD card
2° Arduino: Monitor Temperature , controller 2 servos and 1 camera JPEG, also writing SD card
There are two ways ( I guess ) to communicate between two arduinos, I2C or Serial, I'd like to know what is the better way.
What I have to build is that 1° Arduino is starting a socket connection and exchange information with the 2° Arduino, like: move servo left, move servo down, take a picture, etc..., when the second Arduino has taken a picture, it should send signal to the first and then read the picture from the SD card.
Another problem is that I don't know if I can connect the same SD card to two Arduinos.
So what I'd like to ask is:
What is the best method to communicate between each other
Is possible to use that same SD card with 2 Arduinos, obviously I have to wait that one of them has stopped to use it.
SPI is probably the "best" method, will certainly be the fastest. If data is to go back & forth, you will have to develop a protocol that lets the master control the Slave Select line and some buffering so either device can control the SCK line.
Both can use the SD card, which is controlled by the SPI bus. So you will have to develop a protocol to decide who has access, for how long, etc. and come up with similar buffering for the SCK, MOSI, MISO, and CS lines to share who is controlling them. One board or the other will provide 3.3V power, and both boards will have their GNDs connected.
I would be cautious about having two processors controlling the same SD card, because one may "cache" data (like the disk directory) and then be surprised if the other one changes the disk contents. It could be done if you totally closed the card before accessing from the other processor (but then you would have to negotiate which processor "owns" the SD card at one time). To have them both accessing the card willy-nilly is almost certainly going to lead to grief.
You might find I2C simpler to communicate between processors if you are already tying up SPI with the SD card. You could use SPI for both, but again you would need to decide, at a given moment, if the SD card is going to be active or the other processor.
So you will have to develop a protocol to decide who has access, for how long, etc. and come up with similar buffering for the SCK, MOSI, MISO, and CS lines to share who is controlling them.
CrossRoads is right, and that part will be the tricky bit.
Well, the Arduino that takes care about "take a picture" must close the file and then send a signal to the other Arduino, like that I am sure that I don't have any conflict.
That decision only because I have tried to work only with one Arduino but sometimes I have too much code and I can't run it.
Seems like an invitation for trouble to allow two Arduinos to become 'masters' on the SPI bus. I would suggest using a master-slave configuration as intended by the folk who brought you SPI. Another option to consider is communicating between the Arduinos using I2C and EasyTransfer by Bill Porter. Easy, straight-forward, and very reliable in my experience.
Have you tried using a 'larger' Mega for your project? Might be the simplest solution of all. Or, if you really want to get fancy, the Teensy 3.0, Maple, or Digilent lines of very powerful processors programmable with a Arduino-like IDE?
I checked maple, it's a great board and it's powerful.
I'd like to check if I can run all my code without any problem, I have a library for Camera, DHT22 and SD, can I use the same library on Maple?
**** UPDATE ***
I have tried the MAPLE IDE, but it looks like crap, I can't load my Camera library because it couldn't find software serial... I can't really use it
** UPDATE 2 ***
If I want to use a teensy++ 2.0 , is that working as normal without any problem , like libraries etc.. or I have to make it works ?
Teensy = AtMega with a few small differences, such as an on-chip USB solution. Contact Paul Stoffregen, the maker @ prjc.com, he'll be able to help you answer whatever questions you may have. However, I'd expect the Teensy 2.0 to work for you w/o the need for 2 chips. Plenty of SRAM (8kb!), oodles of Flash (128kb!), lots of I/O and a great IDE to program in. What's not to like?
One advantage to the rather basic method of using serial comms is that you can easily test each Arduino separately by routing the serial to pins 0/1 and talking directly to the serial monitor on your computer....
Then you switch to NewSoftSerial on the correct pins to get each talking to the other (although the "slave" processor is easiest left on pins 0/1 and hardware Serial)
Once that's working its relatively painless to transition to another method should you desire to.
If just starting out stick with Serial, 115,200 baud rate is possible especially if you use handshake, and so much easier to add a pc comm port to monitor the traffic for debugging
Also when you do use comms between micros think about using simple command bytes no need for a full string like "Move:left" can be simply enumerated as follows
use a value to mean a function or direction etc.
0 = stop
1 = right
2 = up
3 = down
4 = left
5 = go
6 = step
in your code use something like this so its nice for you to read
(cut and paste from a web example as i felt lazy lol)
enum MyEnumType { ALPHA, BETA, GAMMA };
Then the following lines are legal:
int i = BETA; // give i a value of 1
int j = 3 + GAMMA; // give j a value of 5
machines are simple, keep it simple makes life easier and quicker