Measure current ACS712 and ADS1115 are not working properly

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Dondolo
Normal user
Posts: 77
Joined: 03 Jul 2019, 06:56
Location: Germany

Measure current ACS712 and ADS1115 are not working properly

#1 Post by Dondolo » 20 Nov 2021, 20:15

Hi there,
I would like to use the ADS1115 to record the analog signal of the ACS712 current sensor a little more precisely.
With the rules I cannot offset the A0 port with the A1 port.
Only one value is ever assigned to a variable.
The offsetting by the ADS115 A1-A0 works, but I cannot calculate an average.
The transfer via task device to dummy is only possible with one port.

What am I doing wrong?

ESP_Easy_mega_20211005_test_B_beta_ESP8266_4M1M

ADS1115 # A0 // AIN0 - GND //FS6.144V
ADS1115 # A1 // AIN1 - GND //FS6.144V
ADS1115 # A0_A1 // AIN0 - AIN1 (differential)

Greetings Dondolo
Attachments
Rules.JPG
Rules.JPG (17.99 KiB) Viewed 6362 times
Log.JPG
Log.JPG (41.22 KiB) Viewed 6362 times
Device.JPG
Device.JPG (61.01 KiB) Viewed 6362 times
A0-A1.JPG
A0-A1.JPG (92.26 KiB) Viewed 6362 times
Device.JPG
Device.JPG (61.01 KiB) Viewed 6362 times

User avatar
Ath
Normal user
Posts: 3418
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Measure current ACS712 and ADS1115 are not working properly

#2 Post by Ath » 20 Nov 2021, 20:41

You should not try to name your Value "ADS1115#A0_A1", that's surely going to mess up somewhere unexpected.
And also, each task must have a unique name, they should not all be named ADS1115 !

And do you have different I2C addresses set for each task? That's also kind of required for the ADS1115 to work correctly, as when the all try to address the same module at nearly the same time, it will have a similar effect as running the unit at too high I2C clock speed.

Then your rule(s): When trying to access multiple values of a task in 1 event, you should better enable 'Single event with all values' and use %eventvalue1%, %eventvalue2% etc.
/Ton (PayPal.me)

Dondolo
Normal user
Posts: 77
Joined: 03 Jul 2019, 06:56
Location: Germany

Re: Measure current ACS712 and ADS1115 are not working properly

#3 Post by Dondolo » 20 Nov 2021, 21:22

Hello Ath, thanks for the quick reply.
The first part has already helped, thanks!

Now looks like this:

And do you have different I2C addresses set for each task? That's also kind of required for the ADS1115 to work correctly, as when the all try to address the same module at nearly the same time, it will have a similar effect as running the unit at too high I2C clock speed.
I didn't understand that, the ADS1115 sensor only has one IC2 address.

That was just for testing

Code: Select all

On ADS1115A0#A0 do
let,1,[ADS1115A0#A0]
let,2,[ADS1115A1#A1]
let,3,[VAR#1]-[VAR#2]
TaskValueSet,8,1,[VAR#2]
TaskValueSet,8,2,[VAR#1]-[VAR#2]
endon
Another question, how do I determine the correct current value in Amper with the formula?

Code: Select all

%value%/0.185
My formula doesn't work, a voltage divider is installed on A1 that halves the voltage.
Attachments
A1A0.JPG
A1A0.JPG (44.32 KiB) Viewed 6356 times

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Measure current ACS712 and ADS1115 are not working properly

#4 Post by TD-er » 20 Nov 2021, 22:18

The ADS1115 plugin is indeed a bit different from other plugins as it handles the complete measurement in a single call and thus you can have different tasks using the same chip only different ports.

Code: Select all

On ADS1115A0#A0 do
let,1,[ADS1115A0#A0]
let,2,[ADS1115A1#A1]
let,3,[VAR#1]-[VAR#2]
TaskValueSet,8,1,[VAR#2]
TaskValueSet,8,2,[VAR#1]-[VAR#2]
endon
That's probably not what you want as ADS1115A0#A0 gets updated, but you're also storing the last known value of ADS1115A1#A1 which is probably not yet updated when you call it here. (or it may be updated but not yet processed in the rules)

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Measure current ACS712 and ADS1115 are not working properly

#5 Post by TD-er » 20 Nov 2021, 22:21

About correcting the value, you can do it in the rules too.
Looks strange that the formula does not work, but when using the let command in the rules you can also perform calculations.

About the rules you posted...

Code: Select all

let,3,[VAR#1]-[VAR#2]
TaskValueSet,8,2,[VAR#1]-[VAR#2]
Why not use [var#3] in the TaskValueSet? Simple calculations should work there, but better to do the calculations in a "let" command and use the variable when actually using the computed value.

Dondolo
Normal user
Posts: 77
Joined: 03 Jul 2019, 06:56
Location: Germany

Re: Measure current ACS712 and ADS1115 are not working properly

#6 Post by Dondolo » 20 Nov 2021, 23:43

Hi TD-er,
I have rewritten the rules and worked, thanks for the feedback.
Can you also help me how I calculate the current now?
A voltage divider for half the reference voltage (2.5 V) was installed on the A1. What does the formula look like in the form field?

Code: Select all

on ADS1115A0#A0 do  
 TaskValueSet,8,1,[ADS1115A0#A0]
 let,1,[ADS1115A0#A0]
EndOn

on ADS1115A1#A1 do  
  TaskValueSet,8,2,[ADS1115A1#A1]
  let,2,[ADS1115A1#A1]
  Let,3,[VAR#1]-[VAR#2]
  TaskValueSet,8,3,[VAR#3]
EndOn

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Measure current ACS712 and ADS1115 are not working properly

#7 Post by TD-er » 21 Nov 2021, 00:06

Not sure how often voltage or current changes on your setup.
If it doesn't, then you don't need to tweak it, but if it does, you may want to make sure both tasks are executed as fast as possible after each other.
You could set a loop timer and call taskrun when handling the loop timer and then keep the rest of the rules as you have now, you can be sure both tasks are run at almost the same moment.
Just make sure the Interval set per task is set to a larger interval than your loop timer.

About the computation of a current.
Just to be clear, you are measuring the voltage over a shunt resistor?
If so, then the current is linear to the measured voltage: U = I x R => I = U / R

If it isn't as simple, please draw a schematic of how it is all setup.

Dondolo
Normal user
Posts: 77
Joined: 03 Jul 2019, 06:56
Location: Germany

Re: Measure current ACS712 and ADS1115 are not working properly

#8 Post by Dondolo » 21 Nov 2021, 10:49

Not sure how often voltage or current changes on your setup.
If it doesn't, then you don't need to tweak it, but if it does, you may want to make sure both tasks are executed as fast as possible after each other.
You could set a loop timer and call taskrun when handling the loop timer and then keep the rest of the rules as you have now, you can be sure both tasks are run at almost the same moment.
Just make sure the Interval set per task is set to a larger interval than your loop timer.
... thanks for the hint, currently only the supply voltage is required and it is quite constant. Later I want to monitor other consumers. Then I can use loop timer well.
About the computation of a current.
Just to be clear, you are measuring the voltage over a shunt resistor?
If so, then the current is linear to the measured voltage: U = I x R => I = U / R
I managed to measure the current, thanks. When it comes to averaging, I'm still thinking about how I can do it.
The transfer to the dummy task will be removed later, for control purposes only.

The rules now look like this, cumbersome but legible for me.

Code: Select all

on ADS1115A0#A0 do
TaskRun,10     // Spannungsteiler 0,5 x Busspannung  [Bit]
TaskRun,12    // Busspannung [Bit]
 let,1,[ADS1115A0#A0]       // ACS7112 Spannung Out [Bit]
 let,2,[ADS1115A1#A1]  
 let,3,[ADS1115A2#A2]
 let,4,[VAR#3]*0.1875/1000                  // Busspannung [Volt]
 let,5,([VAR#3]-[VAR#2])*0.1875/1000  // Differenz Busspannung - 0,5 x Busspannung   [Volt]
 let,6,([VAR#1]-[VAR#2])*0.1875/1000  // ACS7112 Spannung Out  [Volt]
 let,7,[VAR#6]/0.185                   // ACS7112 Curent Out   [Amper]

let,8,[VAR#1]*0.1875/1000

 

 TaskValueSet,8,1,[VAR#1]
 TaskValueSet,8,2,[VAR#2] 
 TaskValueSet,8,3,[VAR#8] // Sensor Spannung
 TaskValueSet,8,4,[VAR#4]

 TaskValueSet,7,1,[VAR#4]
 TaskValueSet,7,2,[VAR#5]
 TaskValueSet,7,3,[VAR#6]
 TaskValueSet,7,4,[VAR#7]


EndOn

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Measure current ACS712 and ADS1115 are not working properly

#9 Post by TD-er » 21 Nov 2021, 16:50

One example to perform filtering in rules: https://espeasy.readthedocs.io/en/lates ... ng-filters

Another really simple filter is to take the difference between old and new value and only apply a fraction of that difference to the old value.

In pseudo code:
diff = new - curval
curval = curval + (diff / 4)

This is an example of an IIR filter.
It will filter out spikes and changes will be more gradual.
However it will add an delay to the response (as does every filter).
So you may want to play around with the factor (1/4 in the example).
Making the factor lower (e.g. 1/8) will increase the delay and suppress fluke values even more.

Dondolo
Normal user
Posts: 77
Joined: 03 Jul 2019, 06:56
Location: Germany

Re: Measure current ACS712 and ADS1115 are not working properly

#10 Post by Dondolo » 21 Nov 2021, 18:18

One example to perform filtering in rules: https://espeasy.readthedocs.io/en/lates ... ng-filters
Hi TD-er,
I tried to calculate the mean of [VAR # 3] over 10 values.
But how, I tried it via an event, e.g. like this:

Code: Select all

on ADS1115A1#DiffA0A1ASC712 do
TaskRun,1
let,1,[ADS1115A0#SpannungsteilerA0]
let,2,[ADS1115A1#DiffA0A1ASC712]
let,3,([VAR#2]-[VAR#1])*0.1875/1000/0.1  // 0.1 für 20A Modul

event,Mittelwert=[VAR#3]

TaskValueSet,12,1,[VAR#1]
TaskValueSet,12,2,[VAR#2]
TaskValueSet,12,3,[VAR#3]
//TaskValueSet,12,4,[VAR#4]
EndOn

on Mittelwert do
 Let,10,[VAR#9]
 Let,9,[VAR#8]
 Let,8,[VAR#7]
 Let,7,[VAR#6]
 Let,6,[VAR#5]
 Let,5,[VAR#4]
 Let,4,[VAR#3]
 Let,3,[VAR#2]
 Let,2,[VAR#1]
 Let,1,[%eventvalue%]
 TaskValueSet,12,4,([VAR#1]+[VAR#2]+[VAR#3]+[VAR#4]+[VAR#5]+[VAR#6]+[VAR#7]+[VAR#8]+[VAR#9]+[VAR#10])/10  
  
EndOn

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Measure current ACS712 and ADS1115 are not working properly

#11 Post by TD-er » 21 Nov 2021, 19:54

You do set the same variables (1, 2 and 3) when receiving a value as you're using in the event Mittelwert.
So I guess you may want to use variables with a higher number in the Mittelwert event.

Code: Select all

on Mittelwert do
 Let,20,[VAR#19]
 Let,19,[VAR#18]
 Let,18,[VAR#17]
 Let,17,[VAR#16]
 Let,16,[VAR#15]
 Let,15,[VAR#14]
 Let,14,[VAR#13]
 Let,13,[VAR#12]
 Let,12,[VAR#11]
 Let,11,[%eventvalue%]
 TaskValueSet,12,4,([VAR#11]+[VAR#12]+[VAR#13]+[VAR#14]+[VAR#15]+[VAR#16]+[VAR#17]+[VAR#18]+[VAR#19]+[VAR#20])/10  
  
EndOn

Post Reply

Who is online

Users browsing this forum: No registered users and 31 guests