Isn't raspberry pi powerfull enough to perform all the opertations ? When do i need a microcontroller in my project? Example ?
please solve my dilemma .
W. H. Heydt wrote:The Pi doesn't have any analog inputs or outputs. They can be faked...somewhat, but for real analog I/O you need a device that has that. That means you have to use either ADC/DAC converters, or some device that has analog I/O....such as a microcontroller. MCUs are also useful for driving external devices that need more current than the Pi can deliver on the GPIO pins. Again. there are ways around that, but an MCU can do it as well, to some extent.
The short way to express that is: Pi for brains, Arduino for muscle.
rurwin wrote:Microcontrollers have two advantages: They have a lot of I/O pins with various hardware built into them (for example serial ports and I2C) that will source or sink a reasonably large current. They are also programmed directly without an operating system, so the application has full control over how it uses its time.
The Raspberry Pi also has advantages: It has an operating system, so it can run complex programs of the same sort that you can run on a desktop computer (and often exactly those same programs.) It has a screen and Ethernet interface so it can communicate richly with the user and with the rest of the world.
The Raspberry Pi has a few I/O and also a little hardware support for PWM, I2C, SPI and serial, but not as much as a microcontroller and with less protection against electrical mishaps. You can use a microcontroller directly for many jobs that you would be best advised to only use a Raspberry Pi for if you added a few components to protect it's interfaces against voltage spikes and EMI.
You can get hardware modules to add Ethernet and a screen to a microcontroller, but you would then have to pay for them and integrate various third-party software in order to get them to do anything useful. The Raspberry Pi has all that built-in.
Because the Raspberry Pi has an operating system, your program does not get full control of the computer all the time. Sometimes it will be redrawing the screen, transferring data to and from the SD card or handling Ethernet traffic, etc. It can be difficult to get it to do such things as count (or generate) fast pulses or to implement a high-speed interface to some other hardware. But because it has an operating system it can give you multiple threads of execution, a rich filesystem on the SD card and a powerful user interface, all of which would take a lot of work to implement on a microcontroller even if you found third-party libraries for each individual capability.
Those devices you suggested are good examples of things that the Raspberry Pi might find difficult to interface to. The ultrasonic sensor is in fact supported because there is an I2C interface on the Pi. The flow meter on the other hand outputs a stream of fast pulses and the computer has to count them. Depending on the maximum frequency you needed to count, that could be difficult on the Pi.
rurwin wrote:You need to know the maximum flow rate of the water and how many pulses per second that is on the Raspberry Pi's input.
If the answer is ten pulses per second then you have no problem. If it is a hundred then you might miss a few now and again. If it is a thousand then you need complex software to handle it. (Device drivers and/or realtime-priority threads.) Any faster than that and it would be a challenging project for an expert.
An Arduino could keep going up to around a hundred thousand pulses per second or more, but I doubt you will be getting anywhere near that.
well , this is what i found about the device i may use.rurwin wrote:You need to know the maximum flow rate of the water and how many pulses per second .
Then again, what are the characteristics of the electronic signal? There is a high probability that you will need some electronics to convert the output of the hall-effect sensor to the up to 3.3V (maybe a volt or two lower but definitely never any higher) signal that the Pi needs.
You can power it from the Raspberry Pi's 5V supply, but you may need a couple of resistors to reduce its output down to 3.3V.josh_B wrote: Working Voltage: 5 to 18V DC (min tested working voltage 4.5V)
Max current draw: 15mA @ 5V
Output Type: 5V TTL
So you will only be able to measure how much water is in the tank to within 10%.Accuracy: ±10%
So the maximum frequency is 7.5 x 30 = 225Hz.Working Flow Rate: 1 to 30 Liters/Minute
Flow rate pulse characteristics: Frequency (Hz) = 7.5 * Flow rate (L/min)