GP8403 driver now working :)

This commit is contained in:
DeltaLima 2025-03-17 00:50:04 +01:00
parent 966cf5f117
commit a7f33aab68
2 changed files with 13 additions and 29 deletions
Arduino/CanGrow/include/Output

View file

@ -19,8 +19,6 @@ const byte Output_I2C_01_MCP4725_Ports = 1;
void Output_I2C_01_MCP4725_Update(const byte AddrId, const byte PortId, const byte Value) {
/* Update Output Port of I2C Module */
const static char LogLoc[] PROGMEM = "[Output:I2C:01_MCP4725:Update]";
//const short MaxRawValue = 4095;
//byte RawValue = map(); // (MaxRawValue * Value)/100;
/* 'Value' , which comes from outputState[], is byte, so 0-255. So we need to map this to the MCPs 0-4095 */
MCP4725[AddrId].setVoltage(map(Value, 0, 255, 0, 4095), false);

View file

@ -12,28 +12,19 @@
const byte Output_I2C_02_GP8403_Addr[] = { 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F };
//DFRobot_GP8403 GP8403[sizeof(Output_I2C_02_GP8403_Addr)];
//for(byte i = 0; i < sizeof(Output_I2C_02_GP8403_Addr); i++) {
//GP8403[i] = DFRobot_GP8403(Output_I2C_02_GP8403_Addr[i]);
//}
DFRobot_GP8403 GP8403(0x58);
DFRobot_GP8403 GP8403[sizeof(Output_I2C_02_GP8403_Addr)];
const byte Output_I2C_02_GP8403_Ports = 2;
void Output_I2C_02_GP8403_Update(const byte AddrId, const byte PortId, const byte Value) {
/* Update Output Port of I2C Module */
const static char LogLoc[] PROGMEM = "[Output:I2C:02_GP8403:Update]";
//const short MaxRawValue = 4095;
//byte RawValue = map(); // (MaxRawValue * Value)/100;
/* 'Value' , which comes from outputState[], is byte, so 0-255. So we need to map this to the MCPs 0-4095 */
//MCP4725[AddrId].setVoltage(map(Value, 0, 255, 0, 4095), false);
//GP8403[AddrId].setDACOutVoltage(map(Value, 0, 255, 0, 4095), PortId);
GP8403.setDACOutVoltage(map(Value, 0, 255, 0, 4095), PortId);
#ifndef DEBUG
/* 'Value' , which comes from outputState[], is byte, so 0-255. So we need to map this to the GP8403 0-4095 */
GP8403[AddrId].setDACOutVoltage(map(Value, 0, 255, 0, 4095), PortId);
#ifdef DEBUG
Log.verbose(F("%s 0x%x Port %d, Value %d, GP8403_Value %d" CR), LogLoc, Output_I2C_02_GP8403_Addr[AddrId], PortId, Value, map(Value, 0, 255, 0, 4095));
#endif
@ -44,17 +35,12 @@ bool Output_I2C_02_GP8403_Init(const byte AddrId, const byte PortId) {
const static char LogLoc[] PROGMEM = "[Output:I2C:02_GP8403:Init]";
bool returnCode;
/* GP8403.begin() does not return a valid result, if connection worked or not, so we check it ourselfs beforehand */
//Wire.beginTransmission(Output_I2C_02_GP8403_Addr[AddrId]);
//short i2cError = Wire.endTransmission();
//GP8403[AddrId] = DFRobot_GP8403(Output_I2C_02_GP8403_Addr[AddrId]);
//if(i2cError == 0) {
//if(GP8403[AddrId].begin() == 0) {
if(GP8403.begin() != 0) {
//GP8403[AddrId].begin();
//GP8403[AddrId].setDACOutRange(GP8403[AddrId].eOutputRange10V);
GP8403.setDACOutRange(GP8403.eOutputRange10V);
/* Overwrite the default address of the library 0x58 with configured one */
GP8403[AddrId] = DFRobot_GP8403(Output_I2C_02_GP8403_Addr[AddrId]);
if(GP8403[AddrId].begin() == 0) {
/* Set output to 0-10V - this is what most grow devices are using as control standard */
GP8403[AddrId].setDACOutRange(GP8403[AddrId].eOutputRange10V);
Log.notice(F("%s found at addr 0x%x" CR), LogLoc, Output_I2C_02_GP8403_Addr[AddrId]);
Output_I2C_02_GP8403_Update(AddrId, PortId, 0);
returnCode = true;