Page 1 of 1

How to read 4-20mA signal input

Posted: Tue Jul 22, 2014 9:11 am
by jacquesknie
Hi,

I'm a total beginner when it comes to electronics. But I'm working on a project where I have to read a 4-20mA Signal with a Raspberry Pi. What's the best way to do that?

Thanks in advance and all the best,
Jacques

Re: How to read 4-20mA signal input

Posted: Tue Jul 22, 2014 10:13 am
by mahjongg
A question, what do you mean by a "4-20mA signal"? I happen to remember that the old serial protocol (comparable to RS232) used by old telex machines used 20mA current loop signaling. Is that what you are talking about, a binary signal encoded in the presence or absence of a 20mA DC current? Then I would run the current trough the LED-of an opto-isolator, and use the photo transistor with the emitter connected to GND, and the collector pulled up with a 10K resistor to 3V3, and connect the resulting binary coded voltage to the UART input of the PI. If the coding swaps the "marks" and "spaces" then simply swap the transistor and resistor so the collector is connected to 3V3, and the resistor becomes a pull-down resistor.


If you are talking about a (DC) current that varies (analogue) between 4 and 20mA, a different circuit is needed that convert the current to a voltage, and feeds it to a Analog to Digital converter, connected through either an I2C or an SPI bus to the PI.

Re: How to read 4-20mA signal input

Posted: Tue Jul 22, 2014 10:19 am
by PiGraham
It will probably be be an analog signal.
Some general info on 4-20mA here:
http://www.dataq.com/blog/faqs/4-20-ma- ... surements/

http://forums.adafruit.com/viewtopic.php?f=8&t=22860

You will need something to convert current to voltage, convert to digital and output in Pi comatible form (I2C or SPI are good bets).
You need to be careful about grounds.

This might help
http://microcontrollershop.com/product_ ... ts_id=5460

Re: How to read 4-20mA signal input

Posted: Sun Jul 27, 2014 6:48 am
by BMS Doug
Pi Graham ' s excellent link identifies the questions you need to answer before you can progress further with reading your input:

Is the 4-20mA source self-powered (if so what voltage?) or is it externally powered (if so what is the voltage range you need to supply it?)

Once those questions are answered then it will be possible to select a method of connecting the 4-20mA signal to the pi.

Re: How to read 4-20mA signal input

Posted: Sun Jul 27, 2014 8:05 am
by hampi
The current needs to be converted to voltage first. This is done with a resistor. If the common mode voltage coming from the cables is not important you could connect the resistor directly to an A/D-converter. Otherwise use a high common mode differential or instrumentation amplifier. There are also specific circuits called current receivers that can be used to get the best precision.

Re: How to read 4-20mA signal input

Posted: Sun Jul 27, 2014 11:50 pm
by yv1hx
hampi wrote:The current needs to be converted to voltage first. This is done with a resistor. If the common mode voltage coming from the cables is not important you could connect the resistor directly to an A/D-converter. Otherwise use a high common mode differential or instrumentation amplifier. There are also specific circuits called current receivers that can be used to get the best precision.
As hampi pinpoints there is two ways to connect a 4-20mA current loop signal to a A/D converter.

Particularly I should recommend the Resistor & Differential Op-Amp method since almost Op-Amp available in your draw box can offer good results in most cases and provide some isolation between the transmitter circuit and the converter.

If you need more precision, your should get an instrumentation amp or the more specifics IC's such as the current receivers.

BTW, until some years ago, the 4 - 20mA current loop, the 1 to 5Vdc Voltage sources and the 3 to 15 PSI were the most common (if not are the standard) way to send/receive a analog signal in the industrial arena, nowadays those standard are been migrated to industrial Ethernet and HART or Fieldbus devices.

Re: How to read 4-20mA signal input

Posted: Mon Jul 28, 2014 10:37 am
by BMS Doug
yv1hx wrote: BTW, until some years ago, the 4 - 20mA current loop, the 1 to 5Vdc Voltage sources and the 3 to 15 PSI were the most common (if not are the standard) way to send/receive a analog signal in the industrial arena, nowadays those standard are been migrated to industrial Ethernet and HART or Fieldbus devices.
0-10Vdc was a very common analogue signal source, much more common in my experience than 1-5V.

0-10V and 4-20mA and resistance based analogue signals are still very common in Building Services applications.

Re: How to read 4-20mA signal input

Posted: Thu Jul 31, 2014 3:06 pm
by jacquesknie
Thank you all so far!
I will have a look at all this and report back.

Best
Jacques

Re: How to read 4-20mA signal input

Posted: Sat Aug 01, 2015 8:36 pm
by HeiBau
Maybe this will help you to test the 4-20mA inputs: http://www.divize.com/current-loop.html
Simple 4-20 mA current loop testers which allow manual setting of the current in the loop.

Regards,

Heinrich.

Re: How to read 4-20mA signal input

Posted: Thu Feb 07, 2019 10:18 am
by robin48gx
I would really like a Pi Hat that has say four 4-20mA inputs and four 4-20mA inputs.

The 4-20mA signalling protocol is used commonly in industry.

I could lay one out in kicad as its very similar to a project I did with the pi last year ( see https://github.com/robin48gx/TH7 ).
I could re-use the ADC SPI stuff and add some DACS to control voltage to current conversion circuitry.
But its prob 3+ days solid work.

I'd rather buy one.

Anyone know if there is a multi channel pi 4-20mA hat out there already ?

Re: How to read 4-20mA signal input

Posted: Thu Feb 07, 2019 10:50 am
by scotty101

Re: How to read 4-20mA signal input

Posted: Thu Feb 07, 2019 10:55 am
by robin48gx
Those both seem to be input only devices.
I require outputs as well.

Re: How to read 4-20mA signal input

Posted: Thu Feb 07, 2019 11:09 am
by scotty101
robin48gx wrote:
Thu Feb 07, 2019 10:55 am
Those both seem to be input only devices.
I require outputs as well.
How about you cut out the middle man and do the googling your self ;)
https://www.google.com/search?q=raspber ... 0ma+output
https://ncd.io/raspberry-pi-analog-outp ... ansmitter/

Re: How to read 4-20mA signal input

Posted: Thu Jun 27, 2019 9:42 pm
by Avimesa
We have a 7-channel 4-20mA board that's plug and play with our cloud. Can use a Pi or a Systech (LTE or WiFi) as a gateway. They're running at one of the biggest brands in the world (insert name of crisp fruit here) so they're reliable. https://avimesa.com
robin48gx wrote:
Thu Feb 07, 2019 10:18 am
I would really like a Pi Hat that has say four 4-20mA inputs and four 4-20mA inputs.

The 4-20mA signalling protocol is used commonly in industry.

I could lay one out in kicad as its very similar to a project I did with the pi last year ( see https://github.com/robin48gx/TH7 ).
I could re-use the ADC SPI stuff and add some DACS to control voltage to current conversion circuitry.
But its prob 3+ days solid work.

I'd rather buy one.

Anyone know if there is a multi channel pi 4-20mA hat out there already ?

Re: How to read 4-20mA signal input

Posted: Mon Jul 01, 2019 1:58 am
by JohnsUPS
When you say "4-20ma" signal, that is usually referring to serial communication over a current loop, but as was pointed out, could also be an analog signal that is within that range.

If it is current loop communications that you are referring to, the below may be of help......

If you prefer to roll your own 4-20ma current loop transceiver board, these devices were typically used for that purpose where I used to work:
HCPL-4100 current loop transmitter
HCPL-4200 current loop receiver

Pretty straightforward to implement, but as I noticed when looking up the data sheets, they're not cheap.

Re: How to read 4-20mA signal input

Posted: Sat Aug 03, 2019 7:22 am
by stixoffire
I see many people are stating that the 4-20ma is usually referring to serial communication; Not in the Industrial world, usually a 4-20ma signal is a representation of a measurement; whether that measurement is PSI, Kp, Fahrenheit, Celsius, Meters, whatever. Typically a device will have a range min/max and that range will be represented by 4-20ma perhaps 0 PSI would be 4ma and 200 Psi would be 20ma. The unit of measure does not matter - only the scale must match the device. You will need to know if the loop is powered or not powered - there are devices built for pi that can read these signals.



JohnsUPS wrote:
Mon Jul 01, 2019 1:58 am
When you say "4-20ma" signal, that is usually referring to serial communication over a current loop, but as was pointed out, could also be an analog signal that is within that range.

If it is current loop communications that you are referring to, the below may be of help......

If you prefer to roll your own 4-20ma current loop transceiver board, these devices were typically used for that purpose where I used to work:
HCPL-4100 current loop transmitter
HCPL-4200 current loop receiver

Pretty straightforward to implement, but as I noticed when looking up the data sheets, they're not cheap.

Re: How to read 4-20mA signal input

Posted: Sat Aug 03, 2019 10:35 pm
by mahjongg
Unlike digital current loops, which often involves simple optical isolators, when talking about the Analog industrial control method, the theoretical solution would be to convert the current to a voltage in a range suitable for an ADC chip using a resistor, and adding an external (I2C or SPI (which could be optically isolated) ADC, see picture below) to the PI.

Image

These days often specialised microcontrollers are used that have built in 20mA receivers.

see: https://en.wikipedia.org/wiki/Current_loop

or use a HAT specifically designed for 4-20mA signalling.

note that the absence of current is/was often used to detect that there is a defect in the control mechanism (a broken wire in the current loop).

Also, prior to using electricity the same mechanism was used with other means, for example pneumatic pressure.

Re: How to read 4-20mA signal input

Posted: Tue Aug 06, 2019 11:03 am
by rin67630
For industrial 4..20mA you need galvanic insulation, since you may have got other instruments in the loop.
If you tie one pole to GND you might shortcut them.

If you really need a poorman's solution, then you may use a capacitor and two inverting reed relays.

Image

The resistor and 3 diodes are just to protect the input against surges.

To read a value, activate the 2relays (might have a common coil control), wait for ~ 100mS, read the value, release the relay.

Re: How to read 4-20mA signal input

Posted: Tue Aug 06, 2019 12:52 pm
by rin67630
robin48gx wrote:
Thu Feb 07, 2019 10:55 am
Those both seem to be input only devices.
I require outputs as well.
The outputs will be a bit tougher, since you need to provide rather high voltages --> 24V, depending on whether your actuator is powered or not.

Re: How to read 4-20mA signal input

Posted: Tue Aug 06, 2019 1:02 pm
by mahjongg
rin67630 wrote:
Tue Aug 06, 2019 11:03 am
For industrial 4..20mA you need galvanic insulation, since you may have got other instruments in the loop.
If you tie one pole to GND you might shortcut them.
Generally I agree that Optical isolation is most often useful, still some implementations will need it, others won't.
if there is just one 4-20mA source on the other end of the loop, which is powered by the loop, then you might not need optical isolation.

Also, the 4-20mA analog loop doesn't have to be where the isolation happens.
In my example the optical isolation is not on the 3-20mA side, but on the digital interface side, using a digital isolator ADuM5401 which also provide enough power over the isolation to power the ADC and analog logic.

But no, I'm not employed in this industry, I only have encountered a 4-20mA loop once in my career, working on a digital sunlight sensor.

For an analog isolator I would prefer to use an IL300 opto isolator that has a LED irradiating two photo transistors, one phototransistor used on the input side as a feedback for the LED current, with both transistors getting the same amount of light, so drawing an equal amount of current. This way you can control the current draw of the isolated phototransistor. Such an opto isolator doesn't cost much, and I think is cheaper than two dual pole reeds plus the vibrator logic etc.

Re: How to read 4-20mA signal input

Posted: Fri Aug 09, 2019 1:30 am
by JohnsUPS
What can also be used to keep the current loop isolated while still being able to precisely read the voltage across the scaling resistor used in the loop is a switched capacitor building block, like the LT6943:
https://www.analog.com/media/en/technic ... /6943f.pdf
The output can then be fed into an AD.

If better isolation is needed, there are optoisolators optimized for DC, such as the IL300 opto:
https://www.vishay.com/docs/83622/il300.pdf

I was involved with analog power transducers, meters and calibration standards. Most devices were used in electrical substations. The transducers typically had an analog current source output because of the electrically noisy environments. Meters usually had multiple outputs, either RS232 (back in the day) or a 20ma current loop - both for communication in addition to an analog output via current loop. Usually it was 0-1ma into a 0-10k ohm load, but 4-20ma was also common.