Skip to content

Commit

Permalink
2021-01-29
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart committed Jan 29, 2021
1 parent 7286182 commit 7661eee
Show file tree
Hide file tree
Showing 1,414 changed files with 61,325 additions and 4,631 deletions.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# MIT License

Copyright (c) 2010-2020 Rob Tillaart
Copyright (c) 2010-2021 Rob Tillaart

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
41 changes: 27 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,52 @@
# Arduino libraries

**NOTE** these libraries will all get their own repo, so this repository
does not have the latest version of all libs anymore. That said I will update
this bulk repo on request or if time permit.
**NOTE** these libraries all have their own repo under https://github.com/RobTillaart?tab=repositories

So this repository does not have the latest version of all libs anymore.
That said I will update this bulk repo on request or if time permit.


### Introduction

This repository contains several Arduino libraries I have written to be used in applications.
Most of them include example code how the libraries can be used.
Furthermore this repository contains a few stand alone applications.


### Questions

For questions about the usage of the libraries, please post a question on the Arduino
forum at http://forum.arduino.cc/


### Bugs and issues

**Please check if the library has its own repo first and fill an issue there**

For bugs in the libraries, please fill in an issue in Github as that makes it
far easier to track them. If possible provide a minimal code snippet that exposes
the bug. Also proposals for solutions are welcome.
For bugs in the libraries, please fill in an issue in Github as that makes it far easier to track them.
If possible provide a minimal code snippet that exposes the bug.
Add information about platform used and version etc.
Also proposals for solutions are welcome.

Other issues are not directly bugs but still problematic.
E.g. if a library is too slow for your application that is an serious issue, not a bug.
Please fill in an issue and provide as much details about your requirements.
Maybe I can help to fix it.

Issues are not bugs but still possible problematic. E.g. if a library is too slow
for your application that is an issue, not a bug. Please fill in an issue and provide
as much details about your requirements.

### Improvements and changes
For improvements and changes, please provide a pull request. I will try to follow up on them
asap but it can take quite some time. Please try to be generic in your improvements and try to
see "over the needs of your own application".

For improvements and changes, please provide a pull request.
I will try to follow up on them asap but it can take quite some time.
Please try to be generic in your improvements and try to see "over the needs of your own application".

There is no guarantee that pull requests will be honored.
In such case feel free to start your own modified library from a fork.


### License and Warranty
I appreciate if you give credits when appropriate, and if you want to donate, please
donate to charity like "doctors without borders".

I appreciate if you give credits when appropriate.

Please check the file LICENSE.md for the details.

Expand Down
7 changes: 7 additions & 0 deletions libraries/ACS712/.arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
- leonardo
- due
- zero
13 changes: 13 additions & 0 deletions libraries/ACS712/.github/workflows/arduino_test_runner.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
name: Arduino CI

on: [push, pull_request]

jobs:
arduino_ci:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: Arduino-CI/action@master
# Arduino-CI/[email protected]
82 changes: 42 additions & 40 deletions libraries/ACS712/ACS712.cpp
Original file line number Diff line number Diff line change
@@ -1,66 +1,68 @@
//
// FILE: ACS712.cpp
// AUTHOR: Rob Tillaart, Pete Thompson
// VERSION: 0.2.0
// VERSION: 0.2.1
// DATE: 2020-08-02
// PURPOSE: ACS712 library - current measurement
//
// HISTORY:
// 0.1.0 2020-03-17 initial version
// 0.1.1 2020-03-18 first release version
// 0.1.2 2020-03-21 automatic formfactor test
// 0.1.2 2020-03-21 automatic formfactor test
// 0.1.3 2020-05-27 fix library.json
// 0.1.4 2020-08-02 Allow for faster processors
// 0.2.0 2020-08-02 Add autoMidPoint
// 0.2.1 2020-12-06 Add arduino-CI + readme + unittest + refactor

#include "ACS712.h"

ACS712::ACS712(uint8_t analogPin, float volts, uint16_t maxADC, uint8_t mVperA)
{
_pin = analogPin;
// 1x 1000 for V -> mV
_mVpstep = 1000.0 * volts / maxADC;
_mVperAmpere = mVperA;
_formFactor = 0.70710678119; // 0.5 * sqrt(2); TODO: should be smaller in practice 0.5 ?
_midPoint = maxADC / 2;
_noisemV = 21; // Noise is 21mV according to datasheet
_pin = analogPin;
_mVpstep = 1000.0 * volts / maxADC; // 1x 1000 for V -> mV
_mVperAmpere = mVperA;
_formFactor = 0.70710678119; // 0.5 * sqrt(2); TODO: should be smaller in practice 0.5 ?
_midPoint = maxADC / 2;
_noisemV = 21; // Noise is 21mV according to datasheet
}

int ACS712::mA_AC(uint8_t freq)
{
uint32_t start = micros();
uint16_t period = ((freq == 60) ? 16670 : 20000);
uint16_t samples = 0;
uint16_t zeros = 0;
int _min, _max;
_min = _max = analogRead(_pin);
while (micros() - start < period) // UNO ~180 samples...
{
samples++;
int val = analogRead(_pin);
if (val < _min) _min = val;
if (val > _max) _max = val;
if (abs(val - _midPoint) <= (_noisemV/_mVpstep)) zeros++;
}
int p2p = (_max - _min);
uint32_t start = micros();
uint16_t period = ((freq == 60) ? 16670 : 20000);
uint16_t samples = 0;
uint16_t zeros = 0;

int _min, _max;
_min = _max = analogRead(_pin);

while (micros() - start < period) // UNO ~180 samples...
{
samples++;
int val = analogRead(_pin);
if (val < _min) _min = val;
if (val > _max) _max = val;
if (abs(val - _midPoint) <= (_noisemV/_mVpstep)) zeros++;
}
int point2point = (_max - _min);

// automatic determine _formFactor / crest factor
float D = 0;
float FF = 0;
if (zeros > samples * 0.025)
{
D = 1.0 - (1.0 * zeros) / samples; // % SAMPLES NONE ZERO
FF = sqrt(D) * 0.5 * sqrt(2); // ASSUME NON ZERO PART ~ SINUS
}
else // # zeros is small => D --> 1 --> sqrt(D) --> 1
{
FF = 0.5 * sqrt(2);
}
_formFactor = FF;
// automatic determine _formFactor / crest factor
float D = 0;
float FF = 0;
if (zeros > samples * 0.025)
{
D = 1.0 - (1.0 * zeros) / samples; // % SAMPLES NONE ZERO
FF = sqrt(D) * 0.5 * sqrt(2); // ASSUME NON ZERO PART ~ SINUS
}
else // # zeros is small => D --> 1 --> sqrt(D) --> 1
{
FF = 0.5 * sqrt(2);
}
_formFactor = FF;

// math could be partially precalculated: C = 1000.0 * 0.5 * _mVpstep / _mVperAmpere;
// rounding?
return 1000.0 * 0.5 * p2p * _mVpstep * _formFactor / _mVperAmpere;
// math could be partially precalculated: C = 1000.0 * 0.5 * _mVpstep / _mVperAmpere;
// rounding?
return 1000.0 * 0.5 * point2point * _mVpstep * _formFactor / _mVperAmpere;
}

int ACS712::mA_DC()
Expand Down
10 changes: 5 additions & 5 deletions libraries/ACS712/ACS712.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// FILE: ACS712.h
// AUTHOR: Rob Tillaart
// VERSION: 0.2.0
// VERSION: 0.2.1
// DATE: 2020-08-02
// PURPOSE: ACS712 library - current measurement
//
Expand All @@ -11,7 +11,7 @@

#include "Arduino.h"

#define ACS712_LIB_VERSION "0.1.3"
#define ACS712_LIB_VERSION "0.2.1"


class ACS712
Expand All @@ -37,7 +37,7 @@ class ACS712
int mA_DC();

// midpoint ADC for DC only
inline void setMidPoint(uint16_t mp) { _midPoint = mp; };
inline void setMidPoint(uint16_t mp) { _midPoint = mp; };
inline uint16_t getMidPoint() { return _midPoint; };
inline void incMidPoint() { _midPoint++; };
inline void decMidPoint() { _midPoint--; };
Expand All @@ -58,8 +58,8 @@ class ACS712

private:
uint8_t _pin;
float _mVpstep; // millivolt per step
float _formFactor; // P2P -> RMS
float _mVpstep; // millivolt per step
float _formFactor; // point2point -> RMS
uint8_t _mVperAmpere;
uint16_t _midPoint;
uint8_t _noisemV;
Expand Down
2 changes: 1 addition & 1 deletion libraries/ACS712/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Rob Tillaart
Copyright (c) 2020-2021 Rob Tillaart

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
23 changes: 23 additions & 0 deletions libraries/ACS712/keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Syntax Coloring Map For ACS712

# Datatypes (KEYWORD1)
ACS712 KEYWORD1

# Methods and Functions (KEYWORD2)
mA_AC KEYWORD2
mA_DC KEYWORD2
setMidPoint KEYWORD2
getMidPoint KEYWORD2
incMidPoint KEYWORD2
decMidPoint KEYWORD2
setFormFactor KEYWORD2
getFormFactor KEYWORD2
setNoisemV KEYWORD2
getNoisemV KEYWORD2
setmVperAmp KEYWORD2
getmVperAmp KEYWORD2


# Constants (LITERAL1)
ACS712_LIB_VERSION LITERAL1

2 changes: 1 addition & 1 deletion libraries/ACS712/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/ACS712"
},
"version":"0.2.0",
"version":"0.2.1",
"frameworks": "arduino",
"platforms": "*"
}
2 changes: 1 addition & 1 deletion libraries/ACS712/library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ACS712
version=0.2.0
version=0.2.1
author=Rob Tillaart <[email protected]>, Pete Thompson <[email protected]>
maintainer=Rob Tillaart <[email protected]>
sentence=ACS712 library for Arduino.
Expand Down
58 changes: 55 additions & 3 deletions libraries/ACS712/readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@

[![Arduino CI](https://github.com/RobTillaart/ACS712/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/ACS712/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/ACS712.svg?maxAge=3600)](https://github.com/RobTillaart/ACS712/releases)

# ACS712

Current Sensor - 5A, 20A, 30A
Library for the ACS712 Current Sensor - 5A, 20A, 30A


## Description

Expand All @@ -9,8 +15,8 @@ analog output that provides a voltage that is lineair with the current.
The ACS712 library supports only a built in ADC by means of analogRead().
There are 2 core functions:

* **int mA_DC()**
* **int mA_AC()**
- **int mA_DC()**
- **int mA_AC()**

To measure DC current a single analogRead() with some conversion math is sufficient to get
a value. To stabilize the signal analogRead() is called twice.
Expand All @@ -20,10 +26,50 @@ peak to peak value which is converted to the RMS value. To convert the peak2peak
value to RMS one need the so called crest or form factor. This factor depends heavily
on the signal form. For a perfect sinus the value is sqrt(2)/2.


## Interface

#### Base

- **ACS712(analogPin, volts = 5.0, maxADC = 1023, mVperA = 100)** constructor
- **mA_AC(freq = 50)** blocks ~21 ms to sample a whole 50 or 60 Hz period.
- **mA_DC()**

#### Midpoint

- **setMidPoint(mp)** sets midpoint ADC for DC only
- **autoMidPoint(uint8_t freq = 50)** Auto midPoint, assuming zero DC current or any AC current
- **getMidPoint()** read back setting
- **incMidPoint()** manual increase midpoint (manually)
- **decMidPoint()** manual decrease midpoint (manually)


#### Formfactor

Also known as crest factor; affects AC only.
Default = 0.5 \* sqrt(2) = ~0.70710678...

- **setFormFactor(ff)** manually sets formfactor 0.0 .. 1.0
- **getFormFactor()** returns current formFactor

#### Noise

Default = 21 mV.
- **setNoisemV(noisemV)** set noise level
- **getNoisemV()** returns set value

#### mV per Ampere

Both for AC and DC
- **setmVperAmp(mva)** sets the milliVolt per Ampere measured.
- **getmVperAmp()** returns set value.


## Test

The library is tested with the RobotDyn ACS712 20A breakout and an Arduino UNO.


## Operation

With the constructor the parameters **volts** and **maxADC (steps)** of the ADC are set
Expand All @@ -41,3 +87,9 @@ To callibrate the noise level (used for AC measurements), 2 functions are availa
get and set the noise in mV.

The examples show the basic working of the functions.

## Future

- mA_AC blocks 20 ms so might affect taskscheduling on a ESP32.
This needs to be investigated.
- int point2point(uint8_t freq) function for AC. Is part of mA_AC() allready.
Loading

0 comments on commit 7661eee

Please sign in to comment.