simon884
Posts: 5
Joined: Thu Dec 20, 2018 8:09 am

ACS712 + MCP3008 with Raspberry vs Arduino

Thu Dec 20, 2018 8:24 am

Hi all,

I'am trying to use one ACS712 with MCP3008 and Raspberry, but I'm having problems.
If I use my ACS712 with Arduino everything works well, I get good measurement current .

But now I want to use this with my Raspberry. I use a MPC3008,ACS712 output is analog value. But when I try to read current with my raspberry I don't have same value with my Arduino.
I use same formula, my MCP works, I have tried to read battery voltage and I read the good value.

I use voltage divider (R1 => 1.2k and R2 => 1.8k) in MCP DOUT because Vcc and Vref are 5V.
The zero current value seems to be good I get 512 (1024/2) from MCP3008. But If i plug a charge on ACS712 value doesn't change...

for read MCP channel (On my Arduino I don't use this function, I use AnalogRead function)

Code: Select all

def ReadChannel(channel):
  adc = spi.xfer2([1,(8+channel)<<4,0])
  data = ((adc[1]&3) << 8) + adc[2]
  return data
For read current (I use the same function on Arduino)

Code: Select all

def getVPP():  
  result = 0.0  
  readValue = 0         
  maxValue = 0      
  minValue = 1024
  
  for i in range(0,100):
    readValue = ReadChannel(current_1_channel) //On Arduino this line is ReadValue = AnalogRead(A0);
       
    if (readValue > maxValue):         
      maxValue = readValue
       
    if (readValue < minValue):
      minValue = readValue    
       
  result = ((maxValue - minValue) * 5)/float(1024)
   
  return result;

So, I get the same result with or without charge in my ACS712, I am a little lost because the same code works on arduino... Why? MCP is not accurate enough ?

Thanks

User avatar
DougieLawson
Posts: 39296
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: ACS712 + MCP3008 with Raspberry vs Arduino

Thu Dec 20, 2018 3:16 pm

Have you grounded any unused analog pins on the MCP3008? What the voltage between the Vref (pin#15) and AGND (pin#14)?
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

simon884
Posts: 5
Joined: Thu Dec 20, 2018 8:09 am

Re: ACS712 + MCP3008 with Raspberry vs Arduino

Fri Dec 21, 2018 8:14 am

DougieLawson wrote:
Thu Dec 20, 2018 3:16 pm
Have you grounded any unused analog pins on the MCP3008? What the voltage between the Vref (pin#15) and AGND (pin#14)?
Thanks for your reply,

Yes all unused analog pins are connected to the ground, and between Vref and AGND I have 5.06V.

I really don't understand why analog output from ACS712 are the same with or without charge. I have tested ACS712 he works with Arduino, I have tested MCP3008 it also works

User avatar
DougieLawson
Posts: 39296
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: ACS712 + MCP3008 with Raspberry vs Arduino

Fri Dec 21, 2018 8:35 am

Image

You need the 5V connected to Vref, GND connected to AGND and OUTPUT connected to CH0. This code should get a reading for you.

Code: Select all

#!/usr/bin/python3
from gpiozero import MCP3008
from time import sleep
volts = MCP3008(channel=0, device=0)

while True:
    adcValue = (volts.value * 5.06) * 100
    print('{:.1f}'.format(adcValue), 10 * ' ')
    sleep(0.1)
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

simon884
Posts: 5
Joined: Thu Dec 20, 2018 8:09 am

Re: ACS712 + MCP3008 with Raspberry vs Arduino

Fri Dec 21, 2018 8:51 am

I have just tried your code and I get the same result, with or without the voltage is the same.
I tried to redo a voltage measurement with the mcp3008 on channel 0 and it works. I'am sure that my ACS712 works and MCP3008 too

User avatar
DougieLawson
Posts: 39296
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: ACS712 + MCP3008 with Raspberry vs Arduino

Fri Dec 21, 2018 9:01 am

Test it on your Arduino again.

Test the MCP3008 with a potentiometer wired between Vref & AGND with the wiper connected to CH0 (pin#1).
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

simon884
Posts: 5
Joined: Thu Dec 20, 2018 8:09 am

Re: ACS712 + MCP3008 with Raspberry vs Arduino

Fri Dec 21, 2018 9:43 am

DougieLawson wrote:
Fri Dec 21, 2018 9:01 am
Test it on your Arduino again.
It works, if I plug a charge, I get good current on my Serial print (50mA)
DougieLawson wrote:
Fri Dec 21, 2018 9:01 am
Test the MCP3008 with a potentiometer wired between Vref & AGND with the wiper connected to CH0 (pin#1).
It also works, I test with multimeter, I have the same voltage display in my terminal

I really don't understand what's going on, my ACS712 always out 2.52V (this voltage is good datasheet say : for zero current analog output is VCC/2)

User avatar
DougieLawson
Posts: 39296
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: ACS712 + MCP3008 with Raspberry vs Arduino

Fri Dec 21, 2018 9:48 am

I don't think I can help much more. I've got MCP3008s but I don't have an ACS712 hall-effect sensor (and it would be 2019 before I can get one).
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

simon884
Posts: 5
Joined: Thu Dec 20, 2018 8:09 am

Re: ACS712 + MCP3008 with Raspberry vs Arduino

Fri Dec 21, 2018 9:51 am

DougieLawson wrote:
Fri Dec 21, 2018 9:48 am
I don't think I can help much more. I've got MCP3008s but I don't have an ACS712 hall-effect sensor (and it would be 2019 before I can get one).
Thank you for your help :)
I continue my research and if I find I will say the solution here (and I really hope to find the solution :D :D )

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

Re: ACS712 + MCP3008 with Raspberry vs Arduino

Fri Dec 21, 2018 11:22 am

I didn't read everything.

But what for type of ACS712 are your using. Because there are three types. And not all are suitable for measuring a low current.
And I would advice you to take a look at this topic. Because it is almost the same question. And it is explained in detail with schematic and code.

Return to “Advanced users”