josh_B
Posts: 17
Joined: Tue Jan 12, 2016 1:57 pm

When Do I need Microcontroller ?

Tue Jan 12, 2016 2:02 pm

I am from computer science field , i am new to Raspberry pi and i was going through various projects and i found that many projects used Combination of raspberry pi and ardiuno . Why is that ? (I am bad at basic electronics).

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 . :(
Last edited by josh_B on Tue Jan 12, 2016 6:14 pm, edited 1 time in total.

W. H. Heydt
Posts: 12785
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: When Do I need Microcontroller ?

Tue Jan 12, 2016 5:55 pm

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.

josh_B
Posts: 17
Joined: Tue Jan 12, 2016 1:57 pm

Re: When Do I need Microcontroller ?

Tue Jan 12, 2016 6:08 pm

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.


So , if have a water flow sensor like this one : http://www.amazon.in/Generic-Transparen ... 91a372300f

And a ultrasonic sensor like this one : http://www.amazon.in/gp/aw/d/B00NYATRNO ... nic+sensor

Is it possible to connect it to raspberry pi ? Or i'll need libraries to connect it to raspberry pi. ? And what exactly are these libraries?

Sorry for stupid question but iam new to all this.

Thanks in advance.

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: When Do I need Microcontroller ?

Tue Jan 12, 2016 6:35 pm

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.

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: When Do I need Microcontroller ?

Tue Jan 12, 2016 6:42 pm

For these reasons it is often useful to use both a microcontroller and a Raspberry Pi in a project.

Even if a microcontroller is not required for its computational abilities, it is often more cost effective to fit a single $2 microcontroller than it is to fit a $2 ADC chip and a handful of support components to a Raspberry Pi. It's cheaper, easier to build and more flexible.

And for the same reasons, for a personal hobby project it is easier to use an off-the-shelf Arduino than to design and build unique electronics.

josh_B
Posts: 17
Joined: Tue Jan 12, 2016 1:57 pm

Re: When Do I need Microcontroller ?

Tue Jan 12, 2016 6:50 pm

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.

thank you sir the answer .

Actually i want to make a 3rd year project on raspberry pi which is similar to this : https://learn.adafruit.com/adafruit-keg-bot/overview . In this project they have used a adafruit water flow sensor which i cannot afford so i had to look up for a cheaper version found on amazon.in . I wanted to measure the amount of water in the watertank and pass the information from the raspberry pi to the server for further processing . Therefore i dont know where to start from.

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: When Do I need Microcontroller ?

Tue Jan 12, 2016 9:20 pm

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.

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.

josh_B
Posts: 17
Joined: Tue Jan 12, 2016 1:57 pm

Re: When Do I need Microcontroller ?

Wed Jan 13, 2016 7:16 am

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.

nicely explained sir, thank you. U cleared my questions.

josh_B
Posts: 17
Joined: Tue Jan 12, 2016 1:57 pm

Re: When Do I need Microcontroller ?

Wed Jan 13, 2016 7:21 am

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.
well , this is what i found about the device i may use.

Model: YF-S201
Working Voltage: 5 to 18V DC (min tested working voltage 4.5V)
Max current draw: 15mA @ 5V
Output Type: 5V TTL
Working Flow Rate: 1 to 30 Liters/Minute
Working Temperature range: -25 to +80?
Working Humidity Range: 35%-80% RH
Accuracy: ±10%
Maximum water pressure: 2.0 MPa
Output duty cycle: 50% +-10%
Output rise time: 0.04us
Output fall time: 0.18us
Flow rate pulse characteristics: Frequency (Hz) = 7.5 * Flow rate (L/min)
Pulses per Liter: 450
Durability: minimum 300,000 cycles
Cable length: 15cm
1/2" nominal pipe connections, 0.78" outer diameter, 1/2" of thread
Size: 2.5" x 1.4" x 1.4"

User avatar
rpdom
Posts: 17275
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: When Do I need Microcontroller ?

Wed Jan 13, 2016 7:52 am

Ok, from that we can work out the maximum pulse rate

30 Litres per minute and 450 pulses per Litre gives a maximum of 13500 pulses per minute.

That's 225 pulses per second at most, usually much less, which shouldn't be a problem to detect with very few missed pulses. The device only claims +/-10% accuracy anyway.

You'll need to drop the output to 3.3V, but that'll be easy with a couple of resistors.

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: When Do I need Microcontroller ?

Wed Jan 13, 2016 8:05 am

josh_B wrote: Working Voltage: 5 to 18V DC (min tested working voltage 4.5V)
Max current draw: 15mA @ 5V
Output Type: 5V TTL
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.
Accuracy: ±10%
So you will only be able to measure how much water is in the tank to within 10%.
Working Flow Rate: 1 to 30 Liters/Minute
Flow rate pulse characteristics: Frequency (Hz) = 7.5 * Flow rate (L/min)
So the maximum frequency is 7.5 x 30 = 225Hz.
30 litres per minute is a litre every two seconds, or about a pint a second.
You should be able to handle that on the Pi, but I would choose to write at least that bit in C rather than use a slower language like Python, and I would use a GPIO library that was good with fast edge-triggered interrupts such as pigpio.

Massi
Posts: 1691
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: When Do I need Microcontroller ?

Wed Jan 13, 2016 9:10 am

i think i tried one of these.
5V from raspberry were not enough to get it to life
and i was quite sure that the output was an open collector output, not 5V ttl..

to read the signal, i quote the use of pigpio, but in my opinion you can use also the python module.

if you do not need the flow measure "always" but only "periodically", you can set a watchdog on the gpio for a period of time, in the callback log only the ticks of one edge and than proportionally get the flow measure.
All interrupts are timestamped down to 5us precision (with default pigpiod settings), so you are not going to loose any pulse
It should be quite easy.

Return to “Beginners”