-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b73115
commit d1b711a
Showing
10 changed files
with
192 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
platforms: | ||
rpipico: | ||
board: rp2040:rp2040:rpipico | ||
package: rp2040:rp2040 | ||
gcc: | ||
features: | ||
defines: | ||
- ARDUINO_ARCH_RP2040 | ||
warnings: | ||
flags: | ||
|
||
packages: | ||
rp2040:rp2040: | ||
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json | ||
|
||
compile: | ||
# Choosing to run compilation tests on 2 different Arduino platforms | ||
platforms: | ||
# - uno | ||
# - due | ||
# - zero | ||
# - leonardo | ||
# - m4 | ||
- esp32 | ||
# - esp8266 | ||
# - mega2560 | ||
# - rpipico | ||
|
77 changes: 77 additions & 0 deletions
77
examples/ACS712_ESP32_external_ADC/ACS712_ESP32_external_ADC.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// FILE: ACS712_ESP32_external_ADC.ino | ||
// AUTHOR: Rob Tillaart | ||
// PURPOSE: demo to measure mA DC with external ADC | ||
// URL: https://github.com/RobTillaart/ACS712 | ||
|
||
// see also ACS712_20_DC_external_ADC.ino | ||
|
||
#include <Arduino.h> | ||
#include <ACS712.h> | ||
#include <ADS1X15.h> | ||
|
||
|
||
// I2C config | ||
#define ADS1015_ADDRESS 0x48 | ||
#define ADS1015_SCL 22 // default SCL ESP32 | ||
#define ADS1015_SDA 21 // default SDA ESP32 | ||
|
||
// ADS1x15 config | ||
#define SENSOR_ACS712_ADSPIN 1 | ||
|
||
|
||
// explicit params for demo | ||
ADS1015 ads1015(ADS1015_ADDRESS, &Wire); // ADS1015 == 12 bit | ||
|
||
|
||
// SENSOR_ACS712_ADSPIN sets pin 1 of the ADS1015, 5.0 volt, 4095 = 12 bit, 100 = mVperAmpere | ||
ACS712 ACS(SENSOR_ACS712_ADSPIN, 5.0, 4095, 100); | ||
|
||
|
||
// ACS712 ADC WRAPPER FOR ADS1015 Note: uses only one direction. | ||
uint16_t readADS1015(uint8_t pin) | ||
{ | ||
uint16_t ADS_raw = ads1015.readADC(pin); | ||
Serial.print("ADS_raw: "); | ||
Serial.println(ADS_raw); | ||
return ADS_raw; | ||
} | ||
|
||
|
||
/////////////////////////////////////////////////////////////// | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
while (!Serial); | ||
Serial.println(__FILE__); | ||
Serial.print("ACS712_LIB_VERSION: "); | ||
Serial.println(ACS712_LIB_VERSION); | ||
Serial.println(); | ||
|
||
|
||
// ESP32 set wire pins explicitly | ||
Wire.begin(ADS1015_SDA, ADS1015_SCL); | ||
Wire.setClock(400000); | ||
|
||
|
||
// initialize ADS1015, if fail => report | ||
if (ads1015.begin() == false) | ||
{ | ||
Serial.println("ADS1x15 not found. Check wires and pins. Reboot."); | ||
while(1); | ||
} | ||
|
||
// set up the external ADC for the ACS712 | ||
ACS.setADC(readADS1015, 5.0, 4095); | ||
} | ||
|
||
|
||
void loop() | ||
{ | ||
int mA = ACS.mA_DC(); | ||
Serial.println(mA); | ||
delay(1000); | ||
} | ||
|
||
|
||
// -- END OF FILE -- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name=ACS712 | ||
version=0.3.8 | ||
version=0.3.9 | ||
author=Rob Tillaart <[email protected]>, Pete Thompson <[email protected]> | ||
maintainer=Rob Tillaart <[email protected]> | ||
sentence=ACS712 library for Arduino. | ||
|