...
for the ADC he used mcp3426 i used ADS1115 which is really similar
and for the RTC he used mcp79410 i used ds1307 also pretty close to his
...
but my problem is in his code because i don't understand coding or any other similar thing.
So i did put the libraries for the parts i used but all i get is pages of errors.
...
You're going to need to do more than just download new libraries for the parts.
First you must see how the code uses the original parts.
I've pulled the following code that deals with the MCP3426 here:
#include <MCP342x.h> //Steve Marple library avaiable from [url]https://github.com/stevemarple/MCP342x[/url]
...
uint8_t address = 0x68; //0x68 is the default address for the MCP3426 device
MCP342x adc = MCP342x(address);
...
//---------------------------------------------Read Voltage and Current--------------------------------------------------------------
void readVoltageCurrent (void) {
MCP342x::Config status;
// Initiate a conversion; convertAndRead() will wait until it can be read
adc.convertAndRead(MCP342x::channel1, MCP342x::oneShot,
MCP342x::resolution16, MCP342x::gain1, //"gain1" means we have select the input amp of the ADC to x1
1000000, voltage, status);
// Initiate a conversion; convertAndRead() will wait until it can be read
adc.convertAndRead(MCP342x::channel2, MCP342x::oneShot,
MCP342x::resolution16, MCP342x::gain4, //"gain4" means we have select the input amp of the ADC to x4
1000000, current, status);
}
Apart from changing the device address, changes appear localized to just providing a drop-in replacement for the adc.convertAndRead() call.
That is, one-shot read from the correct channel, a 16bit value (into long vars
voltage or
current), and if necessary time-out after a second.
The gain in the old library is relative to an internal 2.048V reference, so keep that in mind for the equivalent in the new library.
Luckily, the
status variable is just ignored.
Scullcom Load project files (incl. schematic):
http://www.scullcom.com/DC_Load_9_2_files.zipMCP3426 library:
https://github.com/stevemarple/MCP342xMCP3426 datasheet:
https://ww1.microchip.com/downloads/en/DeviceDoc/22226a.pdfADS1115 tutorial:
https://how2electronics.com/how-to-use-ads1115-16-bit-adc-module-with-arduino/ADS1X15 library:
https://github.com/RobTillaart/ADS1X15ADS1115 datasheet:
https://www.ti.com/lit/ds/symlink/ads1115.pdfNew library equivalent is probably something like this:
#include "ADS1X15.h"
...
ADS1115 ADS(0x48);
...
void setup() {
...
ADS.begin();
...
}
...
void readVoltageCurrent (void) {
ADS.setGain(2); // for 2.048V max.
voltage = ADS.readADC(0); // read channel 1 raw value
ADS.setGain(8); // for 0.512V max. x4 the x1 equivalent
current = ADS.readADC(1); // read channel 2 raw value
}
Substituting a DS1307 for the MCP79410 is more involved since the code doesn't appear to use it as a wall-clock.
That is, it keeps resetting the time to zero, and start/stopping like a stop watch.
I've pulled the following code that deals with the MCP79410 here:
#include <MCP79410_Timer.h> //Scullcom Hobby Electronics library http://www.scullcom.com/MCP79410Timer-master.zip
...
const byte MCP79410_ADDRESS = 0x6f; //0x6f is the default address for the MCP79410 Real Time Clock IC
MCP79410_Timer timer = MCP79410_Timer(MCP79410_ADDRESS);
...
various calls to: timer.reset(), timer.getTime(), timer.getTotalSeconds(), timer.status(), timer.start(), timer.stop()
You could make the equivalent local functions by just using Arduino millis()
without any new hardware at all!
MCP79410 library:
http://www.scullcom.com/MCP79410Timer-master.zipMCP79410 datasheet:
http://ww1.microchip.com/downloads/en/devicedoc/20002266h.pdfDS1307 library:
https://github.com/adafruit/RTClibDS1307 datasheet:
https://www.analog.com/media/en/technical-documentation/data-sheets/DS1307.pdfI cant attach the code bellow because it doesn't support the files...
For .ino files, just rename your file to add the suffix .txt and it will upload, or zip it first.
...but my problem is in his code because i don't understand coding or any other similar thing.
Good luck.