Fan174
Posts: 157
Joined: Tue Mar 20, 2018 6:10 am

Re: MCP3008 readings

Sun Sep 09, 2018 12:04 pm

davidcoton wrote:
Sun Sep 09, 2018 11:50 am
OK, that makes more sense. But where is the power going?
5V 0.2A is 1 Watt. 5V 2A is 10 Watts. Most potentiometers will not survive that.
okay if that's the case then I would test circuit with 10 omhs, 15 ohms and 20 ohm resistors

In first test I will connect 10 ohms resistor then I will calculate current throw resistor

in second test I will replace 10 omhs with 15 ohms and I will calculate current throw resistor

in third test I will replace 15 omhs with 20 ohms and I will calculate current throw resistor

Main goal is to measure the current at variable resistance that's reason I am testing with different size

danjperron
Posts: 3094
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: MCP3008 readings

Sun Sep 09, 2018 1:03 pm

I am trying to explain what I want to do right now. I have 5 V Dc adopter that can supply max 2A current. if load is connected then I want to measure current through load.

load may be 2.5 ohms to 25 ohms

This should have be put at the first post! What a waste of time and explanation!!!!

You should have choosen the acs712 5A.

The other method will be to cut a wire, gauge 22, around 18cm of length. This will give you a resistor of 0.01 ohm. Now you will need to amplify the signal using an OPAM, like a lm358 or lm324, with a gain of 100. 1K/100K resistor for the opam will be ok since you will need to calibrate it anyway to get the right scale value.

For the potentiometer it is quite simple with high power mosfet using D/A converter and heat sink to dissipate the heat lost.
Now you will have to create ,using D/A converter, a linearisation curve for the mosfet with feedback loop to compensate for error. This is more math!!
Last edited by danjperron on Sun Sep 09, 2018 1:08 pm, edited 1 time in total.

Brandon92
Posts: 531
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: MCP3008 readings

Sun Sep 09, 2018 1:07 pm

danjperron wrote:
Sun Sep 09, 2018 1:03 pm
I am trying to explain what I want to do right now. I have 5 V Dc adopter that can supply max 2A current. if load is connected then I want to measure current through load.

load may be 2.5 ohms to 25 ohms

This should have be put at the first post! What a waste of time and explanation!!!!

You should have choose the acs712 5A.
Well, I'm not that sure. He is al over the place :? :
Fan174 wrote:
Sun Sep 09, 2018 10:18 am
I am using 5v dc adopter just for testing. at present I don't have supply that can give 30 A maximum. in actual I have to measure current between 0.2 A - 30 A

I have read specification of acs712 it can be sense -30 A to 30 A that's the reason I purchased it

Does acs712 can't sense current between range 0-2 A to 2 A

danjperron
Posts: 3094
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: MCP3008 readings

Sun Sep 09, 2018 1:32 pm

I have read specification of acs712 it can be sense -30 A to 30 A that's the reason I purchased it
Yes your specification is 2 ohm at 5V max then 5V/2A = 2.5A.

You are using a device with 10% of its scale! This reduces the precision you could get from it.

If your were using the acs712 5A you will have triple the resolution of your system. It is not 6 times because the maximum of the scale is 3.5V (+/- 1V)

Then your resolution will have been for ACS7125A:
slope is 185mv/A => 0,185/(3.3V/1023) => 17.4ma per digital value

And now you have with your ACS71230A :
slope is 66mV/A => 0,66/(3.3V/1023) => 48.8ma per digital value.

At least with a load of 25 ohm will will get ~11 digital value( 5V/25 = 0.2A -> 2A/0.0488) instead of 4 digital value which is near the noise.

It is possible to increase resolution using an OPAM (operational amplifier) . This way you could shift the 2.5V to 0V and use the full span of the A/D converter.
Last edited by danjperron on Sun Sep 09, 2018 1:41 pm, edited 1 time in total.

User avatar
davidcoton
Posts: 3252
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: MCP3008 readings

Sun Sep 09, 2018 1:36 pm

Fan174 wrote: In first test I will connect 10 ohms resistor then I will calculate current throw resistor
Have you done the power calculation on that?

5V through 10R gives 0.5A. 5V at 05.A gives 2.5W. What is the power rating of your resistor? If you don't know, you have a problem.
Even if the resistor is adequate, it will get HOT.
"Thanks for saving my life." See https://www.raspberrypi.org/forums/viewtopic.php?p=1327656#p1327656
“Raspberry Pi is a trademark of the Raspberry Pi Foundation”

Brandon92
Posts: 531
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: MCP3008 readings

Sun Sep 09, 2018 1:40 pm

@danjperron
That is not complicity true, about the "specification" part. I advice him also to measure it in this way. But he is using the ACS712 to measure currents between the 0.2A - 30A in his final? project.

But he is not constant with this specifications...

danjperron
Posts: 3094
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: MCP3008 readings

Sun Sep 09, 2018 1:44 pm

But he is using the ACS712 to measure currents between the 0.2A - 30A in his final? project.
Then why his latest specification is 2 ohm max at 5V. this is 2.5A not 30A!


30A at 5 Volts need special wiring with 4 wires. 2 wires to feedback the voltage at the source to counteract the voltage drop of the wire itself! Or of course multiple wire or big gauge wire.
Last edited by danjperron on Sun Sep 09, 2018 1:50 pm, edited 1 time in total.

Brandon92
Posts: 531
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: MCP3008 readings

Sun Sep 09, 2018 1:48 pm

danjperron wrote:
Sun Sep 09, 2018 1:44 pm
But he is using the ACS712 to measure currents between the 0.2A - 30A in his final? project.
Then why his latest specification is 2 ohm max at 5V. this is 2.5A not 30A!
I don't know, this is part of the problem here.
That's why I wanted him to fill this in:

Brandon92 wrote: Would you be so kind to gives us the final requirements of your project / system. Because when I ask you about the load, it first was a little potentiometer. And now your writing down that you want to measure 0.2A -30A?

And you could write it for example like this:
  • Working voltage
  • lowest measured current
  • maximal measured current
  • resolution
  • ....

Fan174
Posts: 157
Joined: Tue Mar 20, 2018 6:10 am

Re: MCP3008 readings

Sun Sep 09, 2018 1:57 pm

davidcoton wrote:
Sun Sep 09, 2018 1:36 pm
Fan174 wrote: In first test I will connect 10 ohms resistor then I will calculate current throw resistor
Have you done the power calculation on that?

5V through 10R gives 0.5A. 5V at 05.A gives 2.5W. What is the power rating of your resistor? If you don't know, you have a problem.
Even if the resistor is adequate, it will get HOT.
I know the formula
Supply voltage = 5 Volts
Load = 20 Ohms
the current will be
I = 5/20 = 0.25A
P = (I*I)R
P = 1.25 W

User avatar
davidcoton
Posts: 3252
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: MCP3008 readings

Sun Sep 09, 2018 2:00 pm

@danjperron @brandon92

I think @Fan174 has realised that s/he is not ready to test anything at between 2 and 30A, and that the previous mA tests would not work. So now we have an achievable test at the bottom end of the range given by the ACS712 ad MCP3008 combination, which will prove the concept. Trouble is, I don't think s/he has considered the consequences of even these power levels -- on the good side, at least Ohm's Law is being used correctly.
Fan174 wrote: I know the formula
Supply voltage = 5 Volts
Load = 20 Ohms
the current will be
I = 5/20 = 0.25A
P = (I*I)R
P = 1.25 W
@Fan174
And what is the power rating of your resistor?
"Thanks for saving my life." See https://www.raspberrypi.org/forums/viewtopic.php?p=1327656#p1327656
“Raspberry Pi is a trademark of the Raspberry Pi Foundation”

Fan174
Posts: 157
Joined: Tue Mar 20, 2018 6:10 am

Re: MCP3008 readings

Sun Sep 09, 2018 2:09 pm

Brandon92 wrote:
Sun Sep 09, 2018 1:40 pm
@danjperron
That is not complicity true, about the "specification" part. I advice him also to measure it in this way. But he is using the ACS712 to measure currents between the 0.2A - 30A in his final? project.

But he is not constant with this specifications...
I have explained specification in page 2 second last post

I am trying to explain what I want to do right now. I have 5 V Dc adopter that can supply max 2A current. if load is connected then I want to measure current through load.

load may be 2.5 ohms to 25 ohms

Supply voltage = 5 Volts
Load = 20 Ohms

the current will be

I = 5/20 = 0.25A

At 0.2 A using 5 Volts the load resistance will be 5 Volts / 0.2 Amp = 25 Ohms.
At 2 A using 5 Volts the load resistance will be 5 Volts / 2 Amps = 2.5 Ohms

Fan174
Posts: 157
Joined: Tue Mar 20, 2018 6:10 am

Re: MCP3008 readings

Sun Sep 09, 2018 2:28 pm

davidcoton wrote:
Sun Sep 09, 2018 2:00 pm
@danjperron @brandon92

I think @Fan174 has realised that s/he is not ready to test anything at between 2 and 30A, and that the previous mA tests would not work. So now we have an achievable test at the bottom end of the range given by the ACS712 ad MCP3008 combination, which will prove the concept. Trouble is, I don't think s/he has considered the consequences of even these power levels -- on the good side, at least Ohm's Law is being used correctly.
I am not expert in electronics. I am on the way of learning. I tried to interface pi adc and acs712 in first test but it didn't work that's the reason I asked you to advice to purchase component.

when I will get the component I will make the circuit as you suggested. I asked Am I missing anything in component list ?

Please advice me component for last given specification

I used divider circuit in my first post but the problem is when I remove load it doesn't change the adc value it just show the previous value

Brandon92
Posts: 531
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: MCP3008 readings

Sun Sep 09, 2018 2:36 pm

Fan174 wrote:
Sun Sep 09, 2018 2:09 pm
Brandon92 wrote:
Sun Sep 09, 2018 1:40 pm
@danjperron
That is not complicity true, about the "specification" part. I advice him also to measure it in this way. But he is using the ACS712 to measure currents between the 0.2A - 30A in his final? project.

But he is not constant with this specifications...
I have explained specification in page 2 second last post
Okay, but you also told this to us:
Fan174 wrote:
Sun Sep 09, 2018 10:18 am
I am using 5v dc adopter just for testing. at present I don't have supply that can give 30 A maximum. in actual I have to measure current between 0.2 A - 30 A
And yes, I understand that you first want to test with a low current. And when you only talk about the low currents. We will give you some ideas to measure it with a beter methode and resolution. And like someone else told, to increase the measured you could connect the sensor without a voltage divider to you ADC. However, this is not possible any more, because of the other specification that you give to us.
Fan174 wrote: I am trying to explain what I want to do right now. I have 5 V Dc adopter that can supply max 2A current. if load is connected then I want to measure current through load.

load may be 2.5 ohms to 25 ohms
So, all in all you give us two specification, and this gives some confusing:
  • measure current between 0.2 A - 30 A
  • measure current between 0.2A - 2A (2.5 ohms to 25 ohms @5V)

Fan174
Posts: 157
Joined: Tue Mar 20, 2018 6:10 am

Re: MCP3008 readings

Sun Sep 09, 2018 3:19 pm

Brandon92 wrote:
Sun Sep 09, 2018 2:36 pm

So, all in all you give us two specification, and this gives some confusing:
  • measure current between 0.2A - 2A (2.5 ohms to 25 ohms @5V)
sorry i apologize for my mistake
first I want to test this specification
measure current between 0.2A - 2A (2.5 ohms to 25 ohms @5V)

@danjperron I am waiting of your response because you suggested me some component like LE33cz opm

Please suggest me the component (alternative of component) need for test. so I can purchase them for test

Brandon92
Posts: 531
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: MCP3008 readings

Sun Sep 09, 2018 3:43 pm

Okay, and I assume that you also want to keep the acs712 for measuring the current?

Fan174
Posts: 157
Joined: Tue Mar 20, 2018 6:10 am

Re: MCP3008 readings

Sun Sep 09, 2018 4:00 pm

Brandon92 wrote:
Sun Sep 09, 2018 3:43 pm
Okay, and I assume that you also want to keep the acs712 for measuring the current?
Yes because acs712 can measure current range up to 30 A

danjperron
Posts: 3094
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: MCP3008 readings

Sun Sep 09, 2018 4:12 pm

@danjperron I am waiting of your response because you suggested me some component like LE33cz opm
In reality you should change your MCP3008 for something better, with a Voltage reference already build in.

Something like a mcp3426/27/28. This is 16 bits resolutions and the Vref is build in. A lot less problem with voltage fluctuation.

Because it is 16 bits you will have better accuracy. It is I2C! I do have code in python posted on one of the forum.
https://www.raspberrypi.org/forums/view ... 53#p898853

The only drawback is the samples per second which is lower.

Fan174
Posts: 157
Joined: Tue Mar 20, 2018 6:10 am

Re: MCP3008 readings

Sun Sep 09, 2018 4:36 pm

danjperron wrote:
Sun Sep 09, 2018 4:12 pm
@danjperron I am waiting of your response because you suggested me some component like LE33cz opm
In reality you should change your MCP3008 for something better, with a Voltage reference already build in.

Something like a mcp3426/27/28. This is 16 bits resolutions and the Vref is build in. A lot less problem with voltage fluctuation.

Because it is 16 bits you will have better accuracy. It is I2C! I do have code in python posted on one of the forum.
https://www.raspberrypi.org/forums/view ... 53#p898853

The only drawback is the samples per second which is lower.
I have ads1115 16-bit adc.

Is it suitable ? if it suitable then I will use this one

This is program to print adc value

Code: Select all

# Simple demo of reading each analog input from the ADS1x15 and printing it to

import time

# Import the ADS1x15 module.
import Adafruit_ADS1x15

# Create an ADS1115 ADC (16-bit) instance.
adc = Adafruit_ADS1x15.ADS1115()

# Or create an ADS1015 ADC (12-bit) instance.
#adc = Adafruit_ADS1x15.ADS1015()

# Note you can change the I2C address from its default (0x48), and/or the I2C
# bus by passing in these optional parameters:
#adc = Adafruit_ADS1x15.ADS1015(address=0x49, busnum=1)

# Choose a gain of 1 for reading voltages from 0 to 4.09V.
# Or pick a different gain to change the range of voltages that are read:
#  - 2/3 = +/-6.144V
#  -   1 = +/-4.096V
#  -   2 = +/-2.048V
#  -   4 = +/-1.024V
#  -   8 = +/-0.512V
#  -  16 = +/-0.256V
# See table 3 in the ADS1015/ADS1115 datasheet for more info on gain.
GAIN = 1

print('Reading ADS1x15 values, press Ctrl-C to quit...')
# Print nice channel column headers.
print('| {0:>6} | {1:>6} | {2:>6} | {3:>6} |'.format(*range(4)))
print('-' * 37)
# Main loop.
while True:
    # Read all the ADC channel values in a list.
    values = [0]*4
    for i in range(4):
        # Read the specified ADC channel using the previously set gain value.
        values[i] = adc.read_adc(i, gain=GAIN)
        # Note you can also pass in an optional data_rate parameter that controls
        # the ADC conversion time (in samples/second). Each chip has a different
        # set of allowed data rate values, see datasheet Table 9 config register
        # DR bit values.
        #values[i] = adc.read_adc(i, gain=GAIN, data_rate=128)
        # Each value will be a 12 or 16 bit signed integer value depending on the
        # ADC (ADS1015 = 12-bit, ADS1115 = 16-bit).
    # Print the ADC values.
    print('| {0:>6} | {1:>6} | {2:>6} | {3:>6} |'.format(*values))
    # Pause for half a second.
    time.sleep(0.5)
Last edited by Fan174 on Sun Sep 09, 2018 4:53 pm, edited 2 times in total.

Brandon92
Posts: 531
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: MCP3008 readings

Sun Sep 09, 2018 4:51 pm

Yes, you can use that one.

Fan174
Posts: 157
Joined: Tue Mar 20, 2018 6:10 am

Re: MCP3008 readings

Sun Sep 09, 2018 5:08 pm

I don't have diode and other components at present it would take 1 or 2 days time to buy new components

I want to test ads1115 i want test with resistor divider and 1 k of series resistor.

https://learn.adafruit.com/raspberry-pi ... sh-ads1115

think I have to replace adc value 1024 with 32767
Two 10K resistors making a resistor divider

Ampere = (ADValue * 3.3/1024)-1.25) * 1000.0/33.0

simplify to

Ampere = (ADValue * 0,09766) - 37,879

Now with a single resistor in series

Ampere = (ADValue * 3.3V / 1024) - 2.5) * 1000.0/66
simplify to
Ampere = (ADValue * 0,04883) - 37,879
I think I have to add this function in program

Code: Select all

def     ConversionToAmp(ADValue):
   return ((ADValue * 3.3/32767)-1.25) * 1000.0/33.0
How to modify program to convert adc value into current

Code: Select all

import time

# Import the ADS1x15 module.
import Adafruit_ADS1x15

# Create an ADS1115 ADC (16-bit) instance.
adc = Adafruit_ADS1x15.ADS1115()

# Or create an ADS1015 ADC (12-bit) instance.
#adc = Adafruit_ADS1x15.ADS1015()

# Note you can change the I2C address from its default (0x48), and/or the I2C
# bus by passing in these optional parameters:
#adc = Adafruit_ADS1x15.ADS1015(address=0x49, busnum=1)

# Choose a gain of 1 for reading voltages from 0 to 4.09V.
# Or pick a different gain to change the range of voltages that are read:
#  - 2/3 = +/-6.144V
#  -   1 = +/-4.096V
#  -   2 = +/-2.048V
#  -   4 = +/-1.024V
#  -   8 = +/-0.512V
#  -  16 = +/-0.256V
# See table 3 in the ADS1015/ADS1115 datasheet for more info on gain.
GAIN = 1

print('Reading ADS1x15 values, press Ctrl-C to quit...')
# Print nice channel column headers.
print('| {0:>6} | {1:>6} | {2:>6} | {3:>6} |'.format(*range(4)))
print('-' * 37)
# Main loop.
while True:
    # Read all the ADC channel values in a list.
    values = [0]*4
    for i in range(4):
        # Read the specified ADC channel using the previously set gain value.
        values[i] = adc.read_adc(i, gain=GAIN)
        # Note you can also pass in an optional data_rate parameter that controls
        # the ADC conversion time (in samples/second). Each chip has a different
        # set of allowed data rate values, see datasheet Table 9 config register
        # DR bit values.
        #values[i] = adc.read_adc(i, gain=GAIN, data_rate=128)
        # Each value will be a 12 or 16 bit signed integer value depending on the
        # ADC (ADS1015 = 12-bit, ADS1115 = 16-bit).
    # Print the ADC values.
    print('| {0:>6} | {1:>6} | {2:>6} | {3:>6} |'.format(*values))
    # Pause for half a second.
    time.sleep(0.5)
Edit range of adc is -32768 to 32767
Last edited by Fan174 on Sun Sep 09, 2018 5:29 pm, edited 1 time in total.

Brandon92
Posts: 531
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: MCP3008 readings

Sun Sep 09, 2018 5:28 pm

I think it's maybe a better idea, to see if you can convert the code that is provided for the 10 bit adc.

So, how would you change this?

Code: Select all

Ampere = (ADValue * 3.3/1024)-1.25) * 1000.0/33.0 
Edit
And the best way to test it. Is to test if you program is working. And if not, change some things and test it again :geek:

danjperron
Posts: 3094
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: MCP3008 readings

Sun Sep 09, 2018 5:38 pm

Yes the ADS115 is perfect and it could run at 5V without any problem with the PI since it is I2C.

https://www.raspberrypi.org/forums/view ... 2#p1362352

Direct connection , using a resistor in series 1K + a capacitor to limit voltage transient spike. No need for diode protection.


And now the new conversion. ( You should figure it out right now)

Vref= 4.096V 16Bit signed resolution is (-32768 to 32767)


Now with a single resistor in series

Ampere = (ADValue * 4.096V / 32767) - 2.5) * 1000.0/66
simplify to
Ampere = (ADValue * 0,001894) - 37,879

Then 1 digital value give you 1.9ma of resolution. not bad at all.

Brandon92
Posts: 531
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: MCP3008 readings

Sun Sep 09, 2018 5:53 pm

danjperron wrote:
Sun Sep 09, 2018 5:38 pm
Yes the ADS115 is perfect and it could run at 5V without any problem with the PI since it is I2C.
I'm not sure about that. Because, the I2C line itself is 3.3V (with the pull-up) and the VIH of the ADS1115 is 0.7*VDD. This means that a logic one is at 3.5V. And that is lower that the 3.3V I2C line.

danjperron
Posts: 3094
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: MCP3008 readings

Sun Sep 09, 2018 6:23 pm

I'm not sure about that. Because, the I2C line itself is 3.3V (with the pull-up) and the VIH of the ADS1115 is 0.7*VDD. This means that a logic one is at 3.5V. And that is lower that the 3.3V I2C line.
Then a diode and a big cap to reduce the voltage to ~4.5V
https://www.raspberrypi.org/forums/view ... 6#p1173047


------

Or use 3.3V on the ADS1115 at voltage reference of 2.048V with a resistor divider from the acs715 to the input of the ADS1115.
With the resistor divider the conversion is still the same. A little bit noisier.


Vref= 2.048V (-32768 to 32768)

Ampere = (ADValue * 2.048V / 32767) - 1.25) * 1000.0/33 => Ampere = (ADValue * 0,001894) - 37,879

Fan174
Posts: 157
Joined: Tue Mar 20, 2018 6:10 am

Re: MCP3008 readings

Sun Sep 09, 2018 6:35 pm

danjperron wrote:
Sun Sep 09, 2018 5:38 pm
Yes the ADS115 is perfect and it could run at 5V without any problem with the PI since it is I2C.
But the information given in this link https://learn.adafruit.com/raspberry-pi ... sh-ads1115 mention

ADS1x15 VDD to Raspberry Pi 3.3V
ADS1x15 GND to Raspberry Pi GND
ADS1x15 SCL to Raspberry Pi SCL
ADS1x15 SDA to Raspberry Pi SDA

That means ads1115 will work with 3.3v DC
Last edited by Fan174 on Sun Sep 09, 2018 6:46 pm, edited 2 times in total.

Return to “General discussion”