DFRobot's library and examples will compile when the target for the sketch is an Arduino UNO, but not when the target is a GIGA.
Does anyone have any thoughts about how I might be able to get the DFRobot library to work with GIGA?
I have posted below a short example sketch and the compilation output when the target is GIGA.
The library is fairly simple, so maybe I can just modify something? Looking at the compilation errors, it seems that maybe some constants or variable names have changed for the GIGA?
Any help appreciated! Thank you in advance.
Brian
Example sketch:
/*!
* @file outputData.ino
* @brief A use example for DAC, execute it to output different values from different channels.
* @copyright Copyright (c) 2021 DFRobot Co.Ltd (http://www.dfrobot.com)
* @license The MIT License (MIT)
* @author [TangJie](jie.tang@dfrobot.com)
* @version V1.0
* @date 2022-03-07
* @url https://github.com/DFRobot/DFRobot_GP8403
*/
#include "DFRobot_GP8403.h"
DFRobot_GP8403 dac(&Wire,0x58);
void setup() {
Serial.begin(115200);
while(dac.begin()!=0){
Serial.println("init error");
delay(1000);
}
Serial.println("init succeed");
//Set DAC output range
dac.setDACOutRange(dac.eOutputRange5V);
//Set the output value for DAC channel 0, range 0-5000
dac.setDACOutVoltage(2500, 0);
delay(1000);
//Store data in the chip
dac.store();
}
void loop(){
}
Compilation output:
In file included from D:\Dropbox\arduino\libraries\DFRobot_GP8403\examples\outputData\outputData.ino:12:0:
d:\Dropbox\arduino\libraries\DFRobot_GP8403/DFRobot_GP8403.h:114:13: error: 'SCL' was not declared in this scope
int _scl= SCL;
^~~
d:\Dropbox\arduino\libraries\DFRobot_GP8403/DFRobot_GP8403.h:114:13: note: suggested alternative: 'SCK'
int _scl= SCL;
^~~
SCK
d:\Dropbox\arduino\libraries\DFRobot_GP8403/DFRobot_GP8403.h:115:14: error: 'SDA' was not declared in this scope
int _sda = SDA;
^~~
Thanks. Adding the additional include produces the exact same output errors. As I mentioned in the original post, the sketch compiles fine when the target is UNO. It fails when the target is GIGA.
I don't know what pins are SCL and SDA, it may compile and work if you added two lines before the incude that look like SDA=35; similary for SCL. put real pins in for 35.
OOPS, that doesn't work, something about scope.
Thank you... I updated the issue on github with more info. And your troubleshooting is kind of what I'm looking for. Maybe if I modify my local copy of the library? But I've not done that before so I'm climbing a learning curve.
I don't recommend that. The 'correct' way is to use github (I am not trained in it) to fix the error and at some point somebody in charge of maintaining that code will see that you fixed it and will verify the fix and make it official.
private:
/**
* @fn writeReg
* @brief Write register value through IIC bus
* @param reg Register address 8bits
* @param pBuf Storage cache to write data in
* @param size The length of data to be written
*/
void writeReg(uint8_t reg, void *pBuf, size_t size);
TwoWire *_pWire;
uint8_t _addr;
uint16_t voltage = 0;
int _scl = SCL;
int _sda = SDA;
void sendData(uint16_t data, uint8_t channel);
};
Hi @bfnj Do you have a Wire library in your arduino/libraries folder? The mbed-core for the Giga comes with its own lib in ...Arduino15\packages\arduino\hardware\mbed_giga\4.2.1\libraries (which uses I2C_SDA etc
I modified my local copy of the DFrobot_GP8403.h library file at the offending location as follows, but now I'm getting new compile errors.
I changed lines 114 and 115 in the file, which is where the errors are thrown. I replaced the references to SCL and SDA with literals for the pin numbers on the board (21 and 20).
private:
/**
* @fn writeReg
* @brief Write register value through IIC bus
* @param reg Register address 8bits
* @param pBuf Storage cache to write data in
* @param size The length of data to be written
*/
void writeReg(uint8_t reg, void *pBuf, size_t size);
TwoWire *_pWire;
uint8_t _addr;
uint16_t voltage = 0;
int _scl = 21; // int _scl= SCL;
int _sda = 20; // int _sda = SDA;
void sendData(uint16_t data, uint8_t channel);
New compile messages:
C:\Users\brian\AppData\Local\Temp\arduino\sketches\8EDAAF6CECE8ABFF9A3BEA60DF76FB6C/....\cores\arduino_mbed_giga_giga_split_100_0,target_core_cm7_9514d4b8080517b96b7e72096c2bf248\core.a(wiring_analog.cpp.o):C:\Users\brian\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.2.1\cores\arduino/wiring_analog.cpp:32: multiple definition of `dac'
C:\Users\brian\AppData\Local\Temp\arduino\sketches\8EDAAF6CECE8ABFF9A3BEA60DF76FB6C\sketch\outputData.ino.cpp.o:D:\Dropbox\arduino\libraries\DFRobot_GP8403\examples\outputData/outputData.ino:13: first defined here
collect2.exe: error: ld returned 1 exit status
Thank you! I did change the dac variable name to avoid the collision and had it compiling with the literal pin values. I just removed the literals to instead use the I2C_SCL and I2C_SDA names you proposed, and that also compiles.
I uploaded the sketch and, unfortunately, the DAC board is not initializing.