making diy electronic dc load (problem with the arduino code) - Page 1
Forum section: electronics / projects

author: Dzoro
author_rank: Contributor
timestamp: April 03, 2023, 11:43:06 pm
content: Hello guys i have started to build my own electronic dc load which i found on Scullcom Hobby Electronics youtube channel, but some of the components that he used in his design i couldn't get them so i found the closest ones that i can getso for the DAC i used the same as he did the mcp4725for the ADC he used mcp3426 i used ADS1115 which is really similarand for the RTC he used mcp79410 i used ds1307 also pretty close to hisalso i build my own circuit board so my components can fit on itbut 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. I cant attach the code bellow because it doesn't support the files but here is a link Scullcom Hobby Electronics link to see the latest version of the code and if anyone can fix it and make it work for my components i would be really gratefulthanks dzoroThe link for the codehttp://www.scullcom.com/Electronic_Load_software_V35.ino

author: dobsonr741
author_rank: Frequent Contributor
timestamp: April 04, 2023, 01:22:58 am
content: Error messages please. Put it in a pdf or paste in the message with the # button.

author: Dzoro
author_rank: Contributor
timestamp: April 04, 2023, 01:46:36 am
content: the error messages i think are because of mebecause i replaced the include libraries with my partsand i tought it will work just like thati have just tried things but i don't know what am i doing so i need someone to change the code for me because i will never be able to change and fix it myself

author: schmitt trigger
author_rank: Super Contributor
timestamp: April 04, 2023, 02:30:49 am
content: For the DACs, ADCs and RTCs which communication protocol are you using? SPI? I2C? Other?I know that the DS1307 is I2C, but it only supports low speed. If you are driving the bus at high speed because the other I2C components support it, your DS1307 may hang the bus.Also, saying that two components are “really similar” is not a good enough description. They may have very similar functionality, but the internal registers may have different addresses, there could be different control registers that may require a setup, and many other subtle technical details which may render them incompatible.Speaking of I2C addressing: the substitute IC may very likely have a completely different device address than what the library is calling. The device will then proceed to ignore all requests.

author: Dzoro
author_rank: Contributor
timestamp: April 04, 2023, 12:48:37 pm
content: The whole circuit uses I2CFor the similarity of the parts i am not entirely sure about the DS1307 but at what i found i think it should workBut for the ADS1115 is very close with MCP3426 they both are 16bit ADC and work with I2C the only thing different is the pinout and number of pins other than that everithing is the same on the board

author: pqass
author_rank: Super Contributor
timestamp: April 04, 2023, 03:25:22 pm
content: Quote from: Dzoro on April 03, 2023, 11:43:06 pmYou'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:Code:#include <MCP342x.h> //Steve Marple library avaiable from https://github.com/stevemarple/MCP342x...uint8_t address = 0x68; //0x68 is the default address for the MCP3426 deviceMCP342x adc = MCP342x(address);...//---------------------------------------------Read Voltage and Current--------------------------------------------------------------void readVoltageCurrent (void) {MCP342x::Config status;// Initiate a conversion; convertAndRead() will wait until it can be readadc.convertAndRead(MCP342x::channel1, MCP342x::oneShot,MCP342x::resolution16, MCP342x::gain1, //"gain1" means we have select the input amp of the ADC to x11000000, voltage, status);// Initiate a conversion; convertAndRead() will wait until it can be readadc.convertAndRead(MCP342x::channel2, MCP342x::oneShot,MCP342x::resolution16, MCP342x::gain4, //"gain4" means we have select the input amp of the ADC to x41000000, 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 varsvoltageorcurrent), 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, thestatusvariable 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:Code:#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 valueADS.setGain(8); // for 0.512V max. x4 the x1 equivalentcurrent = 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:Code:#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 ICMCP79410_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.pdfQuoteFor .ino files, just rename your file to add the suffix .txt and it will upload, or zip it first.QuoteGood luck.

author: Dzoro
author_rank: Contributor
timestamp: April 04, 2023, 07:57:21 pm
content: I will try all of the above tthanks alotI didnt uderstan the thing for the RTC but first i want to mak it work with the ADCThanks a lot

author: dobsonr741
author_rank: Frequent Contributor
timestamp: April 04, 2023, 09:39:37 pm
content: Do you understand/can you code in C? If not this is the first to tackle, so you can fix up code and make it syntactically correct.Then I would suggest to bring up just the ADC, with the bare minimum code.

author: Dzoro
author_rank: Contributor
timestamp: April 04, 2023, 09:46:28 pm
content: I dont know how to code but i really want to make this project work because i have put so much time and effort in the pcb and the enclosure design, i almost went too far with the design but the only thing that is stopping this project is the arduino codeSo i will tackle with it search on the internet and try different things

author: Dzoro
author_rank: Contributor
timestamp: April 04, 2023, 09:49:13 pm
content: Also one more thing i noticed is that when i put the original code without any changes and try to upload it on the arduino it gives a big error message something to do with the lcdAnd when i delete that line it just goes on and on and gives errors on every line that has lcd in itWhat could be the problem of that?

author: dobsonr741
author_rank: Frequent Contributor
timestamp: April 05, 2023, 01:40:06 am
content: You have two choices IMO:1. Learn to code. Might worth the investment of your time.2. Ask someone to do the coding for you.

author: Dzoro
author_rank: Contributor
timestamp: April 05, 2023, 01:43:34 am
content: I have already tried to learn the code last night i stayed all night long and i only learned some basic stuff about the lcd and the void loop and setup but i didn't understand the things i need to understand to fix itAll in all i have never been a fan of coding so i need to find someone to code it for meIf you can or someone else