Advice needed for connecting multiple arduinos as slave to raspberry pi - arduino

I have a project in hand where I need to connect 5 or more arduinos as slaves to Raspberry Pi. Load Cells, Reed Switch, Solenoid lock will be connected to each of the arduino. The arduinos need to send the weight readings when a communication is started by the raspberry pi(master). Only a single arduino will be activated at a time. The arduinos will be placed at a maximum of 6ft distance from the raspberry pi. I need advice regarding how to make this connection. I read that I2C cannot be used for long distances so I am unsure if 6 ft is a long distance for I2C. Next, I am trying to see if a USB would work for my case but the issue is the Pi has only 4 USB slots. So can I use a external USB hub with an external power supply and connected each of the arduinos to the USB hub and provide individual power supply to the arduinos? Will this arrangement work or should I be looking at any other protocol apart from I2C and USB?? Any advice on this will be much appreciated. Thanks a lot for your time.

Arduino (Nano, Uno, Mega etc.) can communicate via SPI, I2C or UART.
Long story short, SPI is not suitable for your application. It is used for fast data transfer over short distances (usually milimeters or centimeters), so mainly for communication between chips mounted on the same PCB or PCBs close together (e.g. display shields).
Using I2C is perfectly fine (let's say up to 10 meters) and in your case it is a way to go. The maximum possible length depends on baud rate, for 10 meters a 9600 baud rate would be OK. The big advantage is that you need only 2 wires to connect all Arduinos, the disadvantage is that only one device can transfer data at the time – in your case, that does not matter.
UART is used for communication with many external modules (GSM, GPS, HMI, ...) and also in combination with USB-TTL chip for communication via USB (virtual COM port). In your case, you can use UART e.g. in combination with external UART-RS485 converter module, but there is no need since you can use I2C.

Related

Communication between 2 arduinos

I am working with Arduino yun, and I would like to know how can I access sensor values from one arduino using another arduino. Which ways of comunication they are between arduinos? Can I access data from another arduino through wireless? Do I need additional hardware to accomplish this, or its possible with just two arduinos and one computer?
It is possible. Arduinos, depending on the model, can usually communicate via SPI, I2C, etc. Both Arduinos can send and receive data via SPI, for example, so you can hook them up to each other.
It also depends on the type of sensor data you have as well as how many open pins you have: if you really wanted to, you could set 8 bits of data to 8 different pins, and simply connect those pins to 8 pins on the receiving Arduino. That's a rather barbaric way to do it considering you have SPI at your disposal, though.
There are a couple of ways, without any external hardware you have :
SPI
I2C
Serial communication/UART
Serial is the easiest to use among these 3.
And for any other kind of communication you will require external hardware, so if you want to go wireless, then you have cheap RF modules, XBee, etc..
That said that's more appropriate question for Arduino SE site ;)
Check this page. https://www.arduino.cc/en/Tutorial/MasterWriter
I used the I2C to trigger sound from on one arduino and play it on the other. There was no noticeable delay. If you want to stream a lot of data then SPI should be used.

Is it possible to use both external power jack and USB port with Arduino?

I have the Arduino UNO board and I want to know if it is possible to use both the USB connection (for exchanging data) and the external jack to power supply it.
I will use the following cable: http://ecx.images-amazon.com/images/I/41OMXaj5cPL.SY355.jpg with a AC-DC 5V adaptor in order to power supply the Arduino. However, I want to use also the USB connection in order to send some data from the computer.
Both will be connected at the same time.
In short, I want the Arduino to be able to run even if the computer is OFF and whenever I open the computer to send data to Arduino from USB connection.
Is this possible? Will the Arduino Uno board support it?
Yes. From the official Arduino website:
Power
The Arduino Uno can be powered via the USB connection or with an external power supply. The power source is selected automatically.
External DC power will override USB power if the Arduino detects it. [Source]
as other said, it is absolutely possible to have both usb and power jack plugged in.
but be aware that if you shut down your computer and turn it on after, when reading the usb port you'll restart the Arduino and might loose important data.
yeah both of them can be used. If you want to upload the code in arduino then simply use the usb cable otherwise keep it on adapter. it wont harm the device.
What I personally do is, I keep on plugging the adapter and remove the usb once I am done with uploading and then test it as normally the usb cable is quite small and I normally work on robots so I need long wires.
if you want just plugs it in, it's ok but Arduino board will chose one and usb has priority to other power source.
********* Very important :*****
if you are controlling other circuits, that are connected to an external power supply, with your Arduino and connecting it to your PC's usb, Arduino will have potential difference and it will cause current flow that will damage your PC and Arduino board. if you want to do such thing, you have to shield your Arduino board from your other circuits that you want to control and they have external power source. this could happen with optocouplers for digital ports, non signal analog ports with shield relays, and complex analog circuits for analog signals

PWM read with Arduino MEGA and Ethernet Shield

I'm on a project in which I must read the DC (1ms-2ms) of 16 PWM signals with 4 Arduino MEGA 2560, 4 PWM for each one. After have read it, I should send the 16 values to a computer. The initial idea was to use 4 Arduino Ethernet Shield connected to a router and then get on the computer. The other option is to connect the 4 Arduino directly by USB to the computer and perform it with each Serial.print. Which of the two options could give me better results? I have to emphasize that time is important, less than 20ms to receive the 16 PWM values would be optimal.
A greeting and thanks.
20ms is not really an issue here. Assuming you connect the Arduino over USB, using Serial, at 115,000bps, you can send the 4 bytes (Assuming a byte per Duty Cycle reading) to the control computer in .35ms.
Using TCP/IP, and a direct Ethernet connection, it will be orders of magnitude faster than that.
So, I would say, what are you more comfortable with in coding terms? The serial approach will be easy on the Arduino, but you might have to work a bit harder on the control computer. (For instance, will you use C++, and a Serial library like Boost::ASIO ?
Or, are you comfortable with TCP/IP socket programming? And if so, you will have a more robust solution, which will scale better for you.

Bridge shield between Arduino and Raspberry Pi (to wirelessly upload the measurements of analog sensors to a webpage)?

I like to build a project to make my gardening work smarter! My goal is to measure soil temperature, soil water content, light intensity and also taking a picture, and then wirelessly upload these datasets to a webpage. I can also control the irrigation system (turn on/off the pump switch) via the webpage.
These sensors are anagogic! However, the Raspberry Pi Face (PiFace) Digital Interface is only able to take care of digital signals. The PiFace comes with the relaies, which is pretty handy for a startup project. I just like to get some premade boards and ensemble them easily without too work.
Can I layer up a Raspberry Pi board, an Arduino bridge shield, an Arduino board and a PiFace (or a relay board) without wiring?
I really need a recommended "shopping list" to start with. What should I choose?
I suggest you try following the steps outlined in Arduino and the Raspberry Pi.
I agree that you should involve an Arduino as your conduit to the outside world. Then do a simple serial connection between the two. If you get any Arduino except for the new Due, you have got to get from 5 V (Arduino) to 3.3 V (Raspberry Pi). I'd suggest Sparkfun's Logic Level converter.
Sparkfun also has a good light sensor, TEMT6000 Breakout Board.
While you're there, you can grab a couple of thermistors to measure temperature, Thermistor 10K.
Also, Make did an article on almost exactly what you intend on doing (from the Arduino side), Microcontroller-assisted gardening.
On the Raspberry Pi side, Pygame will give you a huge head-start on connecting to the Arduino and taking webcam shots. A Halloween Sound Trigger with Raspberry Pi and Arduino should get you started.
According to what you describe, you may achieve this with only an Arduino UNO, an Ethernet Shield, sensors (at least temperature and light) and a cheap CMOS camera.
If you want to take advantage of the two worlds (Raspberry with Arduino I/O capabilities), you may also consider the Raspberry Pi to Arduino shields connection bridge from Cooking-Hacks: they provide both library and tutorial to start with.

Gathering/reading data from sensors on two different baud rates with Arduino

I want to use an Arduino to gather data from two sensors. This seems easy when the required baud rate for two sensors is the same. However, I'm stumped as how to go about doing this when two different rates are required.
For example, suppose I want to use a barometer and a GPS sensor at the same time. I imagine I'd have to modify something lower-level for one of the sensors (possibly in the libraries or supporting functions), but where do I begin?
Having a look at the provided material, I can see that your hardware use serial communications. The barometer uses an I²C port and the GPS a serial port.
The "communication speed" (or baud rate) does not have to be exactly the same for all devices. Indeed, your sensors may have different sample rate or different needs, and thus does not need to communicate with the central unit with the same frequency.
I would suggest to go step by step. Try first with the GPS sensor. I think serial ports are easier to start with. Try first (a) to communicate directly with the GPS through your computer (you can use your Arduino to set up a USB-serial connection), and later (b) try to write some code which communicates in the same way with the GPS but now from Arduino.
Simple method for Doing this. You have two Serial Port
SoftwareSerial
hardwareserial
In software Serial is one You communicate Directly . in hardware serial you configured for particular pin as Tx and Rx pin. SO barometer you can use SoftwareSerial and for GPS you can use Hardware Serial.
[1]: http://arduino.cc/en/Reference/SoftwareSerial
[2]: http://forum.arduino.cc/index.php?topic=49645.0

Resources