Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
cod3gen committed Jan 31, 2024
1 parent 08dfbcc commit 60d4c97
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
30 changes: 30 additions & 0 deletions examples/ACS712_ESP32_external_ADC_Raw_Async/.arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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
libraries:
- ADS1x15

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// FILE: ACS712_ESP32_external_ADC_Raw_Async.ino
// AUTHOR: Stian Blåsberg
// PURPOSE: demo to measure mA DC with external ADC using raw values - asynchronous
// URL: https://github.com/RobTillaart/ACS712

#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

uint16_t rawAdsValue;


// explicit parameters for demo
ADS1015 ads1015(ADS1015_ADDRESS, &Wire); // ADS1015 == 12 bit


// SENSOR_ACS712_ADSPIN sets pin 1 of the ADS1015, 3.3 volt, 4095 = 12 bit, 100 = mVperAmpere
ACS712 ACS(SENSOR_ACS712_ADSPIN, 3.3, 4095, 100);

///////////////////////////////////////////////////////////////

void setup()
{
Serial.begin(115200);
while (!Serial);
Serial.println(__FILE__);
Serial.print("ACS712_LIB_VERSION: ");
Serial.println(ACS712_LIB_VERSION);
Serial.print("ADS1X15_LIB_VERSION: ");
Serial.println(ADS1X15_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.setADCRaw(rawAdsValue, 3.3, 4095);
ads1015.requestADC(0);
}


void loop()
{
if (ads1015.isBusy() == false)
{
int16_t val_0 = ads1015.getValue();
// request a new one
ads1015.requestADC(0);
int mA = ACS.mA_DC();
Serial.println(mA);
}
// simulate other tasks...
delay(1000);
}


// -- END OF FILE --

0 comments on commit 60d4c97

Please sign in to comment.