@@ -101,25 +101,27 @@ Let's get started with the FoBE Quill ESP32S3 Mesh using the MFP interface.
101101#include < Wire.h>
102102
103103#define GP8403_ADDR 0x58
104- #define GP8403_MODE_005V 0x00
105- #define GP8403_MODE_005_010V 0x01
106- #define GP8403_MODE_010_005V 0x10
107- #define GP8403_MODE_010V 0x11
108- #define GP8403_MODE_ADDRESS 0x01
104+ #define GP8403_MODE_005V 0x00 // 0-5V output
105+ #define GP8403_MODE_005_010V 0x10 // 0-5V and 0-10V output
106+ #define GP8403_MODE_010_005V 0x01 // 0-10V and 0-5V output
107+ #define GP8403_MODE_010V 0x11 // 0-10V output
109108
109+ #define GP8403_MODE_ADDRESS 0x01
110110#define GP8403_CHANNEL0_ADDRESS 0x02 // Channel 0 data register
111111#define GP8403_CHANNEL1_ADDRESS 0x04 // Channel 1 data register
112112
113113#define IIC_SDA_PIN PIN_MFP3
114114#define IIC_SCL_PIN PIN_MFP4
115115
116- void setDACVoltage (uint16_t voltage, uint8_t channel) {
117- voltage &= 0x0FFF ; // Ensure 12-bit data
118- Wire .beginTransmission (GP8403_ADDR );
119- Wire .write (channel == 0 ? GP8403_CHANNEL0_ADDRESS : GP8403_CHANNEL1_ADDRESS );
120- Wire .write (voltage & 0xFF ); // Low 8 bits
121- Wire .write ((voltage >> 8 ) & 0xFF ); // High 8 bits
122- Wire .endTransmission ();
116+ bool setDACVoltage (uint8_t address, uint16_t vol_levl, uint8_t channel_reg) {
117+ uint8_t hibyte = ((vol_levl << 4 ) & 0xff00 ) >> 8 ;
118+ uint8_t lobyte = ((vol_levl << 4 ) & 0xff );
119+ vol_levl = lobyte << 8 | hibyte ;
120+ Wire .beginTransmission (address );
121+ Wire .write ((uint8_t )channel_reg );
122+ Wire .write ((uint8_t )(vol_levl >> 8 ));
123+ Wire .write ((uint8_t )(vol_levl & 0xFF ));
124+ return (Wire .endTransmission () == 0 );
123125}
124126
125127void setup() {
@@ -131,25 +133,28 @@ void setup() {
131133 Wire .begin (IIC_SDA_PIN , IIC_SCL_PIN );
132134
133135 Wire .beginTransmission (GP8403_ADDR );
134- Wire .write (GP8403_MODE_ADDRESS );
135- Wire .write (GP8403_MODE_010V ); // Set 0-10V range for both channels
136- Wire .endTransmission ();
137-
138- // Set channel 0 to output 3V (in 0-10V range)
139- uint16_t dacValue0 = (3 * 4095 ) / 10 ; // 3V in 0-10V range
140- setDACVoltage (dacValue0 , 0 );
141-
142- // Set channel 1 to output 8V (in 0-10V range)
143- uint16_t dacValue1 = (8 * 4095 ) / 10 ; // 8V in 0-10V range
144- setDACVoltage (dacValue1 , 1 );
145-
146- Serial .println (" DAC configuration completed:" );
147- Serial .print (" Channel 0: 3V (DAC value: " );
148- Serial .print (dacValue0 );
149- Serial .println (" )" );
150- Serial .print (" Channel 1: 8V (DAC value: " );
151- Serial .print (dacValue1 );
152- Serial .println (" )" );
136+ if (Wire .endTransmission () == 0 ) {
137+ Serial.println(" GP8403 DAC found." );
138+ } else {
139+ Serial.println(" GP8403 DAC not found. Check connections." );
140+ while (1) delay(1000);
141+ }
142+
143+ Wire.beginTransmission(GP8403_ADDR);
144+ Wire.write((uint8_t)GP8403_MODE_ADDRESS);
145+ Wire.write((uint8_t)GP8403_MODE_005_010V);
146+ if(Wire.endTransmission() == 0){
147+ Serial.println(" GP8403 mode set to 0-5V and 0-10V output." );
148+ } else {
149+ Serial.println(" Failed to set GP8403 mode." );
150+ while (1) delay(1000);
151+ }
152+
153+ setDACVoltage(GP8403_ADDR, 2047, GP8403_CHANNEL0_ADDRESS);
154+ Serial.println(" Channel 0 set to approximately 2.5V." );
155+
156+ setDACVoltage(GP8403_ADDR, 2047, GP8403_CHANNEL1_ADDRESS);
157+ Serial.println(" Channel 1 set to approximately 5V." );
153158}
154159
155160void loop() {
@@ -174,9 +179,10 @@ monitor_raw = true
1741794. Build and upload the project. You should measure 3V on channel 0 and 8V on channel 1 using a multimeter.
175180
176181` ` ` bash
177- DAC configuration completed:
178- Channel 0: 3V (DAC value: 1228)
179- Channel 1: 8V (DAC value: 3276)
182+ GP8403 DAC found .
183+ GP8403 mode set to 0 - 5V and 0 - 10V output .
184+ Channel 0 set to approximately 2.5V .
185+ Channel 1 set to approximately 5V .
180186` ` `
181187
182188:::note
0 commit comments