If I generate a sine signal with the DAC ESP32 feature, can I feed it to one analog pin of an Arduino UNO?
Certainly; however it would be more interesting if we knew what you are trying to achieve?
They will need to have a common ground.
Nothing special. I am doing some testing.
Yes, the ESP32 and the Arduino (ActuaIly I am using an Adafruit Itsy-Bitsy M4) share the ground, but I only I receive in the Itsy-Bitsy M4 a fixed value of: 2016, not what the ESP32 is generating.
The ESP32 code is: (I downloaded it from 06 Wave form ( Sine wave, Square, Triangular and sawtooth wave form) generate with ESP32 DAC - YouTube)
#include <driver/dac.h>
#define Num_Samples 112 // number of dample of signal
#define MaxWaveTypes 4 // types of wave (signal)
int i = 0;
static byte WaveFormTable[MaxWaveTypes][Num_Samples] = {
// Sin wave
{
0x80, 0x83, 0x87, 0x8A, 0x8E, 0x91, 0x95, 0x98, 0x9B, 0x9E, 0xA2, 0xA5, 0xA7, 0xAA, 0xAD, 0xAF,
0xB2, 0xB4, 0xB6, 0xB8, 0xB9, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, 0xBF, 0xBF, 0xC0, 0xBF, 0xBF, 0xBF,
0xBE, 0xBD, 0xBC, 0xBB, 0xB9, 0xB8, 0xB6, 0xB4, 0xB2, 0xAF, 0xAD, 0xAA, 0xA7, 0xA5, 0xA2, 0x9E,
0x9B, 0x98, 0x95, 0x91, 0x8E, 0x8A, 0x87, 0x83, 0x80, 0x7C, 0x78, 0x75, 0x71, 0x6E, 0x6A, 0x67,
0x64, 0x61, 0x5D, 0x5A, 0x58, 0x55, 0x52, 0x50, 0x4D, 0x4B, 0x49, 0x47, 0x46, 0x44, 0x43, 0x42,
0x41, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x41, 0x42, 0x43, 0x44, 0x46, 0x47, 0x49, 0x4B,
0x4D, 0x50, 0x52, 0x55, 0x58, 0x5A, 0x5D, 0x61, 0x64, 0x67, 0x6A, 0x6E, 0x71, 0x75, 0x78, 0x7C
},
// Triangular wave table
{
0x80, 0x84, 0x89, 0x8D, 0x92, 0x96, 0x9B, 0x9F, 0xA4, 0xA8, 0xAD, 0xB2, 0xB6, 0xBB, 0xBF, 0xC4,
0xC8, 0xCD, 0xD1, 0xD6, 0xDB, 0xDF, 0xE4, 0xE8, 0xED, 0xF1, 0xF6, 0xFA, 0xFF, 0xFA, 0xF6, 0xF1,
0xED, 0xE8, 0xE4, 0xDF, 0xDB, 0xD6, 0xD1, 0xCD, 0xC8, 0xC4, 0xBF, 0xBB, 0xB6, 0xB2, 0xAD, 0xA8,
0xA4, 0x9F, 0x9B, 0x96, 0x92, 0x8D, 0x89, 0x84, 0x7F, 0x7B, 0x76, 0x72, 0x6D, 0x69, 0x64, 0x60,
0x5B, 0x57, 0x52, 0x4D, 0x49, 0x44, 0x40, 0x3B, 0x37, 0x32, 0x2E, 0x29, 0x24, 0x20, 0x1B, 0x17,
0x12, 0x0E, 0x09, 0x05, 0x00, 0x05, 0x09, 0x0E, 0x12, 0x17, 0x1B, 0x20, 0x24, 0x29, 0x2E, 0x32,
0x37, 0x3B, 0x40, 0x44, 0x49, 0x4D, 0x52, 0x57, 0x5B, 0x60, 0x64, 0x69, 0x6D, 0x72, 0x76, 0x7B
},
// Sawtooth wave table
{
0x00, 0x02, 0x04, 0x06, 0x09, 0x0B, 0x0D, 0x10, 0x12, 0x14, 0x16, 0x19, 0x1B, 0x1D, 0x20, 0x22,
0x24, 0x27, 0x29, 0x2B, 0x2D, 0x30, 0x32, 0x34, 0x37, 0x39, 0x3B, 0x3E, 0x40, 0x42, 0x44, 0x47,
0x49, 0x4B, 0x4E, 0x50, 0x52, 0x54, 0x57, 0x59, 0x5B, 0x5E, 0x60, 0x62, 0x65, 0x67, 0x69, 0x6B,
0x6E, 0x70, 0x72, 0x75, 0x77, 0x79, 0x7C, 0x7E, 0x80, 0x82, 0x85, 0x87, 0x89, 0x8C, 0x8E, 0x90,
0x93, 0x95, 0x97, 0x99, 0x9C, 0x9E, 0xA0, 0xA3, 0xA5, 0xA7, 0xA9, 0xAC, 0xAE, 0xB0, 0xB3, 0xB5,
0xB7, 0xBA, 0xBC, 0xBE, 0xC0, 0xC3, 0xC5, 0xC7, 0xCA, 0xCC, 0xCE, 0xD1, 0xD3, 0xD5, 0xD7, 0xDA,
0xDC, 0xDE, 0xE1, 0xE3, 0xE5, 0xE8, 0xEA, 0xEC, 0xEE, 0xF1, 0xF3, 0xF5, 0xF8, 0xFA, 0xFC, 0xFE
},
// Square wave table
{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
}
};
void setup() {
Serial.begin(115200); // serial monitor at 115200 bps
}
void loop() {
byte wave_type = 0; // Sine
// byte wave_type = 1; // Triangle
//byte wave_type = 2; // Sawtooth
//byte wave_type = 3; // Square command
dacWrite(DAC_CHANNEL_1, WaveFormTable[wave_type][i]); // output wave form
i++;
if (i >= Num_Samples)
{
i = 0;
}
}
What is he code on the M4?
What happens if you slow down the output from the ESP32?
Here is the Itsy Bitsy M4 code
#include <SPI.h>
#include <Wire.h>
#define SAMPLES_TO_READ 2000L
char getGoing = 'N';
unsigned long timeStartReading,timeEndReading;
int sampleValue[SAMPLES_TO_READ];
void ADC_Init(void)
{
//////////////////////////////////////////////////////////////////////////
///ADC Clock Config
//////////////////////////////////////////////////////////////////////////
MCLK->APBDMASK.bit.ADC0_ = 1;
//Use GCLK1, channel it for ADC0, select DFLL(48MHz) as source and make sure no divider is selected
GCLK->PCHCTRL[ADC0_GCLK_ID].reg = GCLK_PCHCTRL_GEN_GCLK1_Val | (1 << GCLK_PCHCTRL_CHEN_Pos); // enable gen clock 1 as source for ADC channel
GCLK->GENCTRL[0].reg = GCLK_GENCTRL_SRC_DFLL | GCLK_GENCTRL_GENEN | GCLK_GENCTRL_DIV(1);
GCLK->GENCTRL[0].bit.DIVSEL = 0;
GCLK->GENCTRL[0].bit.DIV = 0;
//Divide 8MHz clock by 4 to obtain 2MHz clock to adc
ADC0->CTRLA.bit.PRESCALER = ADC_CTRLA_PRESCALER_DIV4_Val;
//Choose 12-bit resolution
ADC0->CTRLB.bit.RESSEL = ADC_CTRLB_RESSEL_12BIT_Val;
//Ensuring freerun is activated
ADC0->CTRLB.bit.FREERUN = 1;
//waiting for synchronisation
while(ADC0->SYNCBUSY.reg & ADC_SYNCBUSY_CTRLB);
//Sampletime set to 0
ADC0->SAMPCTRL.reg = 0;
//Waiting for synchronisation
while(ADC0->SYNCBUSY.reg & ADC_SYNCBUSY_SAMPCTRL);
ADC0->INPUTCTRL.reg = ADC_INPUTCTRL_MUXNEG_GND; // No Negative input (Internal Ground)
while( ADC0->SYNCBUSY.reg & ADC_SYNCBUSY_INPUTCTRL ); //wait for sync
// Averaging (see datasheet table in AVGCTRL register description)
ADC0->AVGCTRL.reg = ADC_AVGCTRL_SAMPLENUM_1 | // 1 sample only (no oversampling nor averaging)
ADC_AVGCTRL_ADJRES(0x0ul); // Adjusting result by 0
//Wait for synchronisation
while(ADC0->SYNCBUSY.reg & ADC_SYNCBUSY_AVGCTRL)
//Select VDDANA (3.3V chip supply voltage as reference)
ADC0->REFCTRL.reg = ADC_REFCTRL_REFSEL_INTVCC1;
//Enable ADC
ADC0->SWTRIG.bit.START = 1;
ADC0->CTRLA.bit.ENABLE = 1;
//wait for ADC to be ready
while(ADC0->SYNCBUSY.bit.ENABLE);
}
void setup()
{
ADC_Init();
Serial.begin(115200);
while(!Serial);
Serial.println("Begin ...");
}
void loop()
{
if (Serial.available() > 0 )
{
getGoing = Serial.read();
if (getGoing=='x') {
readNOAnalogRead(SAMPLES_TO_READ);
Serial.write('K');
}
if(getGoing=='z')
{
//Serial.println("BUFFER CONTENTS:");
for(int i=0;i<SAMPLES_TO_READ;i++)
{
Serial.print(sampleValue[i]);
if(i<SAMPLES_TO_READ-1)
Serial.print(",");
}
}
while(Serial.available()> 0)
Serial.read();
}
}
void readNOAnalogRead(int numberSamples)
{
timeStartReading = micros();
for(int i=0;i<numberSamples;i++)
{
// Reading ADC
ADC0->SWTRIG.bit.START = 1;
while(!ADC0->INTFLAG.bit.RESRDY);
sampleValue[i] = ADC0->RESULT.reg;
}
timeEndReading = micros();
Serial.print("Time per read (analogRead): "); Serial.print((float((timeEndReading-timeStartReading))/SAMPLES_TO_READ),2); Serial.print(" us (");
Serial.print(SAMPLES_TO_READ); Serial.println(" samples)");
}
The output I am getting is
46,40,43,12,73,71,67,41,57,58,60,67,59,0,75,78,74,67,67,56,69,52,35,54,59,55,36,0,0,0,0,0,0,0,0,0,47,75,84,94,74,28,67,65,64,57,65,66,71,75,3,239,0,41,55,451,226,320,405,340,184,27,0,0,0,81,131,110,121,3,19,25,47,60,72,83,67,75,59,32,64,65,65,65,68,59,57,66,49,51,66,82,67,58,58,55,96,72,37,58,64,56,59,59,57,59,67,45,36,69,83,73,75,69,67,61,83,3,40,58,64,58,57,55,61,70,69,41,174,91,75,71,315,375,329,144,0,0,0,10,104,186,140,69,33,11,11,39,66,77,71,0,0,0,0,0,0,0,0,0,20,70,56,57,75,0,53,79,78,64,56,62,67,76,66,47,73,72,79,72,66,58,57,65,27,51,64,66,59,56,67,57,69,58,53,59,68,75,66,64,50,52,163,34,64,59,293,362,321,114,0,0,0,9,107,172,133,70,41,10,1,1,43,78,85,79,60,47,43,64,72,45,72,75,60,50,58,46,53,66,52,55,61,61,57,55,59,44,71,65,46,72,73,76,73,70,59,59,75,32,46,57,59,59,60,65,65,79,64,51,67,72,42,0,0,0,0,0,65,226,0,0,79,251,154,0,0,0,0,94,186,170,109,65,14,14,27,11,64,82,66,47,56,59,58,78,0,76,82,76,62,45,32,43,72,73,30,58,64,67,64,60,67,56,201,9,33,69,72,67,56,36,44,66,69,42,50,65,65,67,69,66,65,78,57,42,71,78,73,66,55,54,207,0,0,66,400,417,388,271,52,0,0,0,16,128,148,116,78,34,1,56,64,30,77,75,64,46,45,58,67,85,65,45,69,69,59,56,53,53,52,64,26,59,58,61,35,0,0,0,0,33,21,0,50,163,107,33,10,58,168,149,0,0,159,219,0,0,95,200,41,0,0,185,174,24,0,48,288,0,0,0,448,448,418,371,277,78,0,0,0,11,154,168,105,59,30,25,98,138,0,64,142,82,35,24,64,66,142,23,0,81,110,73,33,54,83,99,153,0,0,72,105,67,58,81,94,121,154,0,14,85,101,53,45,66,75,136,128,0,46,109,53,40,68,90,115,162,0,24,76,91,150,0,50,73,0,0,0,0,89,234,234,186,83,0,60,0,0,105,146,82,18,15,24,48,131,15,0,0,202,184,2,0,55,142,178,0,0,34,226,183,0,0,74,176,174,0,0,91,270,130,0,0,106,186,153,0,0,128,202,98,0,8,79,169,122,0,11,129,129,83,26,52,64,136,74,0,36,121,115,54,40,67,73,147,20,0,53,120,88,42,41,73,75,139,106,0,83,96,165,26,32,128,0,0,0,32,278,296,160,26,0,0,42,137,67,10,90,101,36,2,34,98,128,142,32,0,73,98,57,29,59,96,89,154,27,0,73,96,65,25,35,65,72,140,15,0,49,106,82,21,32,56,67,130,132,0,0,118,257,66,0,9,90,162,138,0,0,57,235,155,0,99,73,106,203,0,0,0,123,307,215,122,111,78,64,44,0,3,217,265,46,0,1,79,143,129,0,0,116,175,96,9,26,80,90,148,0,0,83,139,58,1,13,72,91,128,106,0,46,122,129,14,19,42,65,104,147,0,15,81,105,67,40,61,78,99,145,32,0,54,90,60,32,40,71,74,129,19,0,72,129,56,28,39,53,59,116,143,30,97,139,184,0,0,19,258,334,313,0,0,0,46,34,72,129,100,128,99,0,0,98,128,50,51,75,81,68,129,0,0,24,226,161,0,1,66,128,146,2,0,0,236,234,32,0,35,115,174,106,0,0,134,238,120,0,0,117,187,137,0,0,64,226,152,0,0,84,137,129,13,0,155,256,98,18,0,3,0,0,0,0,5,323,259,138,22,8,11,73,134,34,0,96,114,46,14,34,74,72,130,114,0,28,110,104,64,41,64,74,107,137,0,0,97,91,51,45,75,91,73,133,9,0,46,107,89,43,28,58,71,103,143,0,3,73,93,55,53,77,95,70,137,27,0,66,104,73,14,30,73,113,149,0,21,79,97,61,52,85,81,87,148,0,0,25,179,185,0,0,0,153,341,221,3,0,123,129,0,0,64,170,188,114,0,0,110,263,112,0,19,89,160,143,0,0,42,214,155,0,0,91,169,159,0,0,15,149,108,43,1,41,72,138,116,0,4,64,95,67,41,46,79,119,168,0,0,81,90,46,24,52,80,81,147,31,0,308,0,29,1,443,264,321,408,363,82,0,0,0,0,74,150,118,288,120,0,0,84,108,75,52,66,82,85,147,0,0,72,120,83,33,25,59,83,149,121,0,49,113,110,52,32,59,67,104,161,0,0,72,95,57,9,65,84,75,133,129,0,0,136,198,53,0,27,97,156,121,0,0,43,206,163,0,0,68,142,140,115,0,0,136,229,98,0,0,129,111,149,20,0,155,224,162,249,0,0,233,384,344,73,0,0,64,19,0,68,153,123,153,0,0,29,140,99,41,0,33,67,129,128,0,0,101,129,36,14,30,73,73,153,35,0,65,133,65,26,18,52,75,116,164,0,18,74,78,50,32,59,77,109,171,0,0,78,120,88,33,33,50,67,133,123,0,53,82,280,0,0,91,412,440,430,351,270,104,0,0,0,16,113,171,184,74,0,48,84,71,0,92,92,67,123,153,0,0,114,257,51,0,8,90,165,139,0,0,85,250,154,0,0,90,142,156,0,0,0,234,248,47,0,29,113,179,117,0,0,99,251,133,0,0,121,197,145,0,0,47,178,121,16,121,300,82,129,0,2,9,0,0,0,0,145,192,187,164,2,0,14,92,89,59,55,65,65,102,138,0,19,87,96,53,36,0,56,35,123,42,0,68,119,93,52,48,65,0,60,148,19,0,92,104,48,21,47,52,54,90,164,0,0,79,83,43,40,64,67,57,116,171,0,18,87,90,54,23,54,57,42,129,130,0,42,99,72,41,37,56,41,35,139,101,0,0,184,0,0,0,0,0,78,251,174,0,0,171,139,0,0,37,157,140,132,34,0,0,207,211,15,0,18,149,120,151,58,0,0,220,192,0,0,52,155,112,119,98,0,36,117,100,14,14,80,129,57,114,6,0,43,84,53,40,64,90,82,66,106,145,0,39,78,56,59,80,111,70,53,221,128,0,110,0,0,0,228,321,234,120,41,27,0,0,114,140,73,75,59,42,26,37,98,142,0,48,109,109,78,58,34,40,36,42,116,136,0,98,133,163,7,25,51,40,27,93,172,0,15,101,115,75,39,65,55,42,64,170,85,0,78,107,51,7,34,77,64,66,171,203,0,0,270,170,56,0,0,9,0,0,118,0,0,128,323,233,0,0,47,202,392,410,61,0,0,88,360,194,0,73,425,456,459,185,0,0,0,419,370,204,180,407,436,448,185,0,0,106,427,371,301,331,421,443,448,56,0,0,258,411,355,335,406,411,440,433,0,0,0,379,411,352,394,402,403,425,48,152,0,44,293,264,192,226,385,427,458,324,0,0,152,420,384,333,366,408,403,436,163,0,0,256,430,403,338,352,393,411,441,169,0,0,317,441,393,314,321,361,410,438,210,0,0,309,440,402,337,274,273,289,430,281,0,0,219,451,410,372,312,194,152,244,448,153,0,0,347,457,423,308,50,0,82,410,448,0,0,0,481,339,356,0,0,0,19,460,450,0,0,0,449,424,161,0,0,130,373,440,442,15,0,0,428,400,146,0,22,308,398,411,450,243,0,0,131,413,307,147,169,328,377,391,443,399,0,0,32,385,330,180,165,321,392,384,417,427,0,0,85,426,341,169,121,288,371,298,335,441,4,0,66,419,368,251,197,435,299,221,307,424,0,0,148,338,291,203,225,224,172,224,430,243,0,0,227,347,210,66,97,169,193,417,218,0,0,136,338,249,88,35,56,107,416,202,0,0,162,346,229,58,0,52,201,433,224,0,0,232,282,0,83,180,138,267,421,25,0,0,266,374,194,0,0,184,443,270,0,0,0,435,395,148,0,0,313,434,0,0,0,270,429,267,0,0,152,440,129,0,0,128,411,310,13,0,142,431,299,0,0,35,394,276,13,0,193,431,412,0,0,2,286,211,1,40,205,416,443,0,0,9,281,142,0,61,200,369,433,5,0,0,219,169,10,58,175,298,431,175,0,0,183,227,81,21,2,129,442,329,0,0,232,277,51,0,0,71,399,193,0,0,139,322,225,82,18,45,280,428,5,0,25,297,259,128,83,128,171,411,187,0,0,267,233,47,203,185,66,360,291,0,0,75,412,282,11,0,0,168,407,111,0,0,315,430,314,0,0,0,147,406,0,0,0,394,426,134,357,19,79,65,261,0,0,0,416,443,251,0,0,0,156,402,56,0,0,344,419,243,0,0,0,35,345,387,0,0,278,354,216,11,0,0,35,114,426,137,0,53,386,331,105,0,0,0,23,280,430,0,0,177,392,168,0,0,4,26,73,361,449,0,0
Is your sending and receiving sample rate identical, or very close?
There is not a sinusoidal sequence.
Too, I slow down the samples generation (1 ms)
I obtain:
2528,2410,2296,2208,2066,1936,1838,1740,1672,1588,1514,1480,1432,1368,1336,1288,1220,1204,1124,1161,1107,1103,1083,1057,1013,1041,993,1009,1025,955,965,961,961,937,931,923,906,882,914,881,907,891,921,899,875,911,875,921,881,919,875,909,885,924,896,864,928,640,858,923,589,647,727,859,999,1069,1007,869,841,815,802,810,812,845,851,885,964,942,930,917,901,889,915,865,907,867,897,866,896,864,888,914,888,910,872,916,888,928,902,879,911,883,913,889,904,878,924,905,877,907,875,905,875,905,879,897,864,904,876,905,865,896,864,884,898,878,874,923,905,889,921,897,865,896,864,882,920,856,905,882,916,883,911,891,922,896,872,905,841,879,1000,938,908,885,919,884,963,623,937,944,738,940,884,840,836,896,938,992,1032,972,936,880,915,897,883,936,920,896,856,875,899,859,875,921,897,865,887,915,883,910,882,910,888,898,884,927,910,882,906,875,905,881,913,897,857,885,918,874,904,769,691,733,762,821,815,790,820,928,938,867,833,853,913,888,898,886,938,824,850,942,937,867,873,978,930,899,872,936,864,851,916,906,858,861,899,889,929,888,950,998,0,930,1059,1195,1121,1116,1104,1037,889,868,900,836,868,993,1002,976,960,949,939,914,906,922,916,802,847,882,897,844,880,911,880,905,897,896,804,796,841,850,840,853,883,910,869,882,954,887,879,971,978,955,931,914,904,878,905,905,901,792,811,851,868,873,897,872,898,856,897,885,853,846,914,890,906,868,898,881,915,877,937,931,825,882,938,906,856,874,896,872,896,885,941,843,876,942,922,883,901,897,872,896,874,931,833,833,897,875,880,864,904,896,872,898,900,888,816,814,982,108,910,908,1136,1145,1137,1116,1056,866,795,825,929,929,881,923,931,915,851,889,875,851,878,1024,971,904,832,878,946,930,911,907,803,793,845,915,851,827,841,882,904,857,917,869,824,883,939,898,840,866,907,883,905,889,941,833,874,938,915,874,904,878,915,881,923,924,832,846,904,878,897,859,899,872,896,875,921,847,962,4,858,960,1156,968,1032,1035,971,930,804,696,782,832,861,884,908,886,904,852,899,837,809,877,936,896,843,856,884,919,883,948,883,867,936,953,931,880,912,896,873,904,908,897,779,837,875,866,861,891,931,907,889,943,867,874,948,936,905,859,861,946,904,899,896,783,747,872,973,921,827,833,884,928,914,820,772,808,920,922,821,775,794,833,861,875,815,770,841,938,16,784,859,1123,1115,1097,1049,860,836,865,883,877,908,939,970,961,938,847,824,906,930,896,833,841,880,910,889,936,824,864,933,922,876,888,932,914,885,946,931,822,880,955,928,879,897,877,920,904,901,833,802,859,901,848,843,856,896,859,887,943,848,865,928,916,872,897,872,911,873,923,917,809,842,897,865,870,878,910,883,908,917,840,822,875,942,913,848,869,905,882,931,929,853,834,904,896,847,842,856,897,865,897,888,854,864,929,909,869,879,922,904,872,928,920,821,793,873,968,904,856,746,920,1032,760,804,811,952,1066,1008,901,763,826,896,896,908,866,804,833,931,897,793,769,802,841,853,866,822,770,825,912,856,809,801,843,874,904,858,789,819,896,873,847,833,856,896,886,865,841,915,910,856,848,874,920,896,896,881,827,857,914,888,896,850,880,906,884,954,888,878,961,961,931,889,930,928,914,914,900,796,835,877,885,899,865,901,867,880,946,914,827,942,288,850,915,1057,1049,988,948,850,727,779,843,913,906,888,914,864,859,931,970,840,910,904,842,840,856,882,906,906,899,780,820,848,861,864,878,917,880,920,931,845,797,859,985,939,841,852,917,919,906,872,793,817,937,937,841,795,812,872,911,879,813,785,864,961,905,803,804,859,888,944,861,803,851,970,960,857,846,904,915,906,875,803,832,906,909,840,813,833,854,914,880,842,817,879,937,883,881,910,907,897,896,873,809,856,913,873,878,896,867,896,872,936,833,849,910,889,901,865,905,881,923,929,855,833,888,949,905,857,886,922,898,899,887,1005,698,867,971,1147,867,923,1025,1068,1033,873,818,832,842,852,898,898,882,904,873,911,794,847,905,865,864,875,905,873,906,912,835,827,881,921,867,874,920,897,857,919,904,770,771,867,920,812,770,787,816,844,857,777,720,856,949,888,840,844,904,903,898,819,730,826,946,917,801,771,808,857,896,835,737,797,906,919,816,761,832,876,933,900,768,762,898,906,841,802,812,847,878,922,825,792,850,888,897,833,851,883,908,909,825,808,873,921,869,877,897,877,911,907,896,776,826,860,873,872,883,917,885,943,941,834,879,945,923,889,923,908,888,940,935,872,925,640,873,922,613,681,738,841,1007,1056,1009,1073,996,946,908,904,889,952,978,974,880,960,963,939,923,915,897,867,913,905,792,842,881,884,873,939,916,875,925,936,824,800,897,955,869,833,849,916,914,883,789,762,919,975,925,815,833,896,908,868,786,756,901,961,904,800,803,852,905,873,783,730,865,971,936,824,832,897,899,874,782,751,890,971,921,848,875,938,940,1001,13,787,954,1144,914,930,1037,1026,961,881,756,815,879,937,920,915,897,864,904,868,804,850,905,858,857,882,907,875,945,883,866,936,929,879,911,896,864,915,923,832,839,882,898,850,877,910,891,942,944,851,900,896,848,870,897,856,873,937,856,859,928,908,861,896,860,885,929,935,867,896,897,856,865,880,909,877,951,954,833,837,947,1001,907,804,836,925,936,815,752,884,1032,890,847,872,968,1001,929,812,907,1007,996,898,835,905,954,932,769,754,947,1004,939,815,835,904,933,851,745,873,1002,1001,928,875,938,969,969,844,876,962,973,1000,192,943,1025,1172,1133,1050,1059,978,882,834,840,881,955,992,952,896,905,865,867,904,899,883,936,932,808,833,880,889,906,898,883,910,922,908,776,832,872,859,865,897,864,896,920,861,812,876,909,847,873,913,874,933,953,849,854,928,898,840,866,896,856,921,937,805,836,904,857,808,841,861,878,946,904,784,803,917,907,763,784,834,912,920,792,689,817,946,977,797,658,762,917,1010,800,628,905,1072,1026,850,675,673,952,964,661,609,995,1083,1028,841,693,781,1000,834,557,713,1096,1080,1026,859,768,917,916,584,541,864,1049,985,964,928,952,987,922,555,628,978,1042,989,988,984,1025,897,605,472,801,1039,962,924,960,1009,1034,874,521,450,838,1039,933,873,974,1056,932,813,495,665,952,1010,904,851,1035,1037,973,739,599,842,1044,942,810,820,1024,986,888,706,808,1024,954,840,736,835,1025,941,722,712,1000,1033,957,843,737,889,1051,837,675,873,1065,1001,900,682,714,1008,942,652,610,1036,1052,1007,937,755,865,1057,779,543,745,1080,962,1000,941,915,1005,913,589,545,888,1098,1058,983,907,1013,1043,777,442,586,978,1052,964,922,989,1033,937,608,436,718,1024,970,880,931,1049,1008,858,602,717,1011,1081,914,828,1002,1098,1000,776,705,1001,1083,938,814,833,1056,992,768,682,954,1008,944,780,715,901,1007,820,656,876,1052,996,921,763,843,1026,879,673,809,985,1033,946,922,898,930,932,604,643,849,942,878,866,942,977,987,864,603,745,1010,1004,984,1027,1007,1077,1066,786,471,686,1004,993,856,874,1039,1115,1025,681,472,786,1012,1024,846,864,1038,1089,937,629,691,975,1069,899,776,808,1033,948,724,588,845,1059,955,785,736,898,1034,879,625,693,1051,1056,910,689,689,907,1010,754,672,914,1043,960,844,770,800,948,896,635,800,938,923,872,906,884,932,964,757,752,951,971,904,889,979,1001,1066,949,683,781,921,881,856,907,947,962,1025,842,617,787,897,835,826,876,923,969,1010,821,657,820,905,815,801,843,878,1026,931,718,723,896,872,817,812,873,925,1025,889,751,873,994,953,856,928,939,985,1050,826,603,905,1033,852,695,842,931,1035,481,498,933,1120,1041,783,696,889,1098,869,604,814,1108,1121,1032,822,769,954,962,739,602,888,1133,1103,979,928,968,1108,971,680,620,963,1129,1057,913,909,997,1077,873,609,746,1064,1068,922,864,968,1071,1059,783,568,804,971,819,809,835,907,1003,1026,706,610,863,967,889,864,920,936,1058,986,761,756,968,1001,943,907,914,922,1032,900,706,800,908,864,818,833,883,922,1001,885,761,922,994,954,860,904,929,961,1037,817,699,867,994,938,835,851,883,974,1058,848,736,913,979,948,874,946,919,883,1045,878,608,691,980,1076,938,822,848,945,1058,932,569,578,888,1098,1028,850,814,868,1081,1049,655,512,797,1025,946,819,777,813,961,975,688,491,795,995,1011,904,844,922,1010,1057,801,529,681,973,1024,851,803,872,1003,1043,858,597,696,968,1024,855,820,888,1000,1091,995,730,759,1025,1025,869,843,913,941,1002,1065,810,652,841,1001,954,834,952,815,955,1025,800,565,623,929,955,832,795,856,915,1013,950,717,650,882,1066,960,794,794,877,1025,1006,755,606,867,1112,1088,907,757,867,1044,1089,866,611,811,1043,1082,930,771,777,900,1002,858,571,719,968,1066,952,889,886,980,1097,964,650,672,971,1054,873,784,842,952,1058,887,604,770,962,1083,961,789,777,859,1056,896,553,716,904,1025,896,707,722,847,1027,866,568,662,886,1057,941,768,738,889,1075,923,585,687,922,1040,924,763,803,896,1024,845,536,672,897,984,901,744,808,937,1013,824,538,746
Have you graphed the values? Looks a bit like a sine to me.
For troubleshooting, wouldn't it be easier to use the triangle wave?
aarg: No, I do not sending sample rate. I am only reading the voltage ESP32 put in its pin 25 and reading it using the pin A0 of the M4.
Sample rate is not something you "send". It is a characteristic measure of the rate at which samples are taken or reproduced.
Seems like you're off to the races without a horse. What is this "testing" you're doing?
Do you have a DMM? Have you tried sending various voltages with a small test program and monitoring with the DMM to verify the DAC ouput pin?
Here is a simple code to send values to DAC1 (pin 25).
#define DAC1 25
void setup()
{
Serial.begin(115200);
}
void loop() // Generate a Sine wave
{
int Value = 64; //255= 3.3V 128=1.65V
dacWrite(DAC1, Value);
delay(1000);
}
I get 0.83 Vdc for 64.
If that works, have you tested the output of the DAC with the DMM while running the ESP code in the OP?
While running the sine waveform I see a bit over 0.5Vac. Frequency of 1.6 ish KHz.
I have changed to the square wave. The ESP32 generates 0 and 255 values as expected. I guess they are equivalent to 0V and 3.3V (I do not have a DMM)
In the M4, I must read the values 0 (0 V) and 4096 (3.3V) However I read;
842,864,1052,906,664,828,930,664,732,922,978,976,922,840,760,832,886,946,936,919,889,911,877,911,905,841,897,879,905,865,885,909,885,931,907,897,832,870,908,881,897,867,897,865,889,919,901,833,873,911,881,899,881,906,874,900,884,930,888,923,913,897,859,887,909,879,917,897,877,905,864,906,914,641,841,875,620,712,786,907,993,1049,1005,967,905,857,889,938,942,946,948,914,864,910,884,918,898,704,644,843,1007,995,889,803,912,960,980,901,825,867,937,913,885,927,825,801,874,976,928,837,853,920,908,900,874,810,796,889,979,919,825,845,913,898,878,904,776,814,877,906,834,897,219,865,936,1102,1090,1033,931,813,736,786,820,885,961,952,937,843,865,900,866,906,882,916,890,922,886,938,912,886,928,904,873,905,877,914,896,872,904,847,881,907,877,907,877,921,897,875,909,882,890,938,916,896,864,897,872,904,872,913,877,883,931,901,877,911,882,902,896,871,907,873,882,929,939,36,872,1000,1208,983,1081,1123,1093,984,928,856,874,932,954,974,971,955,937,904,864,905,900,880,904,675,600,878,1060,979,867,781,825,974,984,906,826,876,955,937,911,896,794,771,835,916,866,818,818,861,896,858,886,825,805,890,988,944,864,884,963,962,949,940,842,889,968,961,933,916,906,896,855,904,896,795,837,864,865,932,552,849,911,911,962,905,777,716,760,864,953,979,979,952,909,879,856,921,921,912,884,914,883,913,891,936,916,866,914,888,914,875,923,905,883,911,897,866,868,912,878,914,886,928,896,875,901,885,904,864,910,877,915,889,928,898,868,905,883,907,869,909,886,920,890,928,898,878,910,896,834,872,904,906,642,836,882,643,669,748,906,968,1045,975,929,857,777,549,705,1025,1025,885,753,777,896,962,889,840,866,952,952,910,897,801,777,841,931,879,841,845,897,886,916,897,793,751,886,991,955,872,904,920,915,885,929,849,865,929,900,860,897,872,904,872,905,891,883,908,912,884,914,886,925,905,877,908,886,915,875,929,904,880,906,882,914,886,920,905,877,888,944,972,202,932,1001,1184,1140,1128,1072,938,837,827,869,947,960,980,973,942,912,883,931,906,891,955,936,911,883,912,858,896,883,920,872,923,889,929,907,884,923,897,869,897,873,865,915,898,872,896,861,883,905,884,932,905,884,897,897,866,897,865,889,915,882,910,916,880,890,938,922,898,873,855,676,707,851,973,1011,914,787,920,680,936,867,513,635,769,793,908,1008,989,971,1003,1032,905,826,869,960,971,960,946,858,864,947,961,928,882,937,930,900,868,939,874,882,952,928,896,885,914,897,874,908,897,840,861,905,875,896,860,897,859,890,933,911,876,897,880,904,881,919,897,868,897,862,886,922,867,912,897,867,889,923,897,882,917,897,872,884,902,897,870,899,866,896,859,884,913,898,865,865,906,879,911,917,716,888,960,713,750,864,1025,1057,1041,960,884,888,915,907,917,919,910,872,874,906,874,911,857,905,896,866,886,912,896,858,882,922,897,872,896,860,883,911,882,922,896,850,904,872,903,873,841,739,791,776,779,899,900,762,800,897,906,820,777,781,821,840,846,864,809,795,866,929,857,827,844,886,906,867,929,865,866,936,910,870,948,526,866,939,937,1011,970,858,822,820,880,980,1026,978,962,922,897,873,885,949,940,924,898,866,896,870,905,879,921,887,915,901,875,896,866,914,873,898,872,908,879,883,937,910,884,920,897,887,913,897,872,904,848,882,915,889,920,896,874,896,874,906,888,910,868,916,897,868,898,870,897,864,896,873,888,904,897,867,897,897,555,851,897,626,835,795,724,792,873,995,1043,995,979,941,908,884,939,897,921,911,884,913,881,911,884,923,902,882,907,873,921,896,872,903,820,780,789,776,777,757,790,800,795,814,847,851,866,878,898,880,907,849,905,873,899,866,899,857,880,907,885,914,861,915,896,864,897,858,882,906,873,925,896,847,897,865,887,909,883,913,885,929,916,897,883,611,922,936,548,727,777,769,832,945,1025,953,961,921,871,882,911,905,896,874,906,880,896,854,898,870,899,867,896,857,875,897,882,915,867,915,882,910,889,921,897,873,905,876,920,885,913,897,874,900,867,891,920,896,872,909,882,896,883,917,884,914,899,864,898,874,906,883,906,859,900,866,896,867,897,865,888,917,896,877,897,857,898,867,888,917,888,922,907,882,930,898,842,884,919,882,920,897,852,880,907,872,910,872,883,937,921,897,882,915,889,924,905,887,921,867,915,919,643,853,912,612,686,754,889,1058,1071,1033,967,921,865,884,943,939,939,925,909,878,878,928,911,896,873,906,873,912,875,899,884,899,867,920,897,859,880,904,874,904,965,912,904,808,842,878,905,857,883,921,897,867,941,953,856,840,911,914,873,875,904,897,887,914,916,844,815,873,951,929,861,876,928,931,909,906,905,787,801,867,905,832,860,744,912,946,739,801,800,952,1059,1006,937,827,825,868,923,923,940,868,844,909,919,876,896,865,918,913,873,928,887,840,906,937,913,849,860,906,898,864,915,832,789,841,914,887,875,879,914,919,897,888,932,816,858,938,937,882,891,936,937,915,911,897,782,810,879,923,859,858,888,939,911,904,897,784,810,878,917,854,857,882,928,897,888,932,810,860,943,930,883,897,882,929,900,904,827,794,840,917,897,825,817,842,873,882,937,888,849,923,955,928,869,887,939,937,923,928,856,845,922,945,906,846,920,730,889,978,768,679,761,1028,1089,1043,922,856,859,869,930,936,851,916,951,928,855,857,899,896,881,933,843,821,888,965,940,883,916,919,909,900,884,840,865,942,952,907,865,900,889,918,925,856,832,896,928,905,835,834,864,900,905,881,827,824,897,907,856,848,868,913,882,939,918,792,843,922,906,836,824,850,882,913,905,823,792,854,918,873,898,538,837,899,607,817,738,747,867,979,1034,1024,984,988,952,942,876,877,971,1043,992,950,911,906,921,915,900,816,792,850,917,873,855,865,914,896,876,928,816,827,899,906,855,837,856,898,873,918,896,770,803,882,920,842,833,857,896,864,909,835,797,855,936,907,833,827,854,896,859,905,812,782,842,911,866,843,840,882,925,906,897,819,788,848,912,857,836,845,866,938,900,897,824,784,835,897,849,818,817,851,876,888,942,897,800,864,941,904,832,835,881,929,896,896,840,797,841,917,880,866,864,909,905,881,929,917,809,876,836,940,1024,684,740,930,1024,988,978,842,778,826,896,865,879,923,912,878,888,945,899,819,883,969,937,873,901,907,905,873,916,910,792,810,888,922,850,846,882,939,917,897,899,793,779,843,905,836,814,828,865,889,921,909,845,809,864,932,898,833,851,897,875,889,936,878,846,938,950,916,865,907,901,874,904,904,832,806,866,921,875,874,908,904,883,921,909,824,808,866,922,882,882,913,911,897,876,924,841,818,880,944,906,850,880,932,914,897,889,873,850,930,952,922,866,899,889,939,880,953,897,817,897,915,872,860,882,936,928,896,897,873,802,856,938,904,833,885,746,925,949,750,754,786,975,1137,1123,1024,888,921,914,906,931,946,850,887,977,975,921,872,928,936,920,900,906,810,803,875,939,879,861,883,947,932,912,921,844,832,904,935,889,873,899,900,888,908,917,873,833,887,982,960,899,867,931,924,896,896,880,825,840,936,920,846,842,882,939,914,896,907,808,786,850,908,844,827,840,881,907,864,921,861,731,896,931,901,833,841,933,778,835,969,768,693,856,1033,993,937,817,786,802,819,843,898,897,771,746,867,897,827,817,842,876,889,904,897,902,784,793,876,931,841,821,841,883,907,864,907,912,804,809,897,880,866,849,879,931,904,867,900,923,833,805,888,961,904,839,865,916,897,852,875,946,890,846,911,952,920,865,888,954,947,916,888,961,975,865,906,960,948,897,854,912,913,883,897,873,947,851,841,929,937,884,896,874,920,888,928,883,965,923,826,900,929,885,889,923,925,915,876,832,930,947,833,865,954,942,874,888,942,947,920,898,905,915,795,796,936,648,778,794,576,640,668,768,923,937,864,909,897,801,760,840,900,900,864,907,821,771,791,865,885,864,866,921,915,885,944,880,846,914,953,921,856,864,930,931,911,915,824,794,857,922,864,856,888,944,929,930,864,825,882,974,954,896,852,920,922,929,905,769,808,877,907,828,811,843,879,933,913,770,803,865,897,825,816,832,858,908,889,811,833,921,913,840,841,869,906,913,897,754,851,936,908,834,833,858,904,916,843,779,834,915,867,841,841,887,943,957,870,835,920,960,921,853,878,940,946,961,843,837,942,969,929,865,897,896,905,898,747,737,908,971,906,800,786,812,936,916,697,643,812,899,794,699,732,818,949,1053,731,704,841,942,843,779,769,778,888,1039,699,680,840,896,811,755,814,852,938,1057,798,690,833,908,832,800,799,834,843,992,938,714,810,911,858,808,824,875,911,921,1035,801,690,842,909,818,782,811,826,809,874,1057,805,760,930,872,832,867,921,904,874,969,1089,825,777,913,896,792,794,833,843,846,850,997,944,728,837,936,883,872,896,901,873,896,858,1038
Neither 0s nor 4096s.
Approximately the ESP32 is generating a value every millisecond. The M4 is reading the values every microsecond.
Please le me know if I have a conceptual error.
Hi, @LMario28
Have you got the gnd connections of BOTH controllers connected together?
Can you please post an image(s) of your project?
Can you please post a copy of your circuit diagram?
Thanks.. Tom...
May I suggest you START by checking each end is working as you expect?
ie (#12 @groundFungus ) if you send 64 to the ESP32 DAC do you get ABOUT 0.8V?
and - more importantly - if you connect a single cell battery - eg a fresh AAA alkaline to the Itsy Bitsy M4 analog input - you get a reading that corresponds to ABOUT 1.5 volts?
The sketches run well now. The problem was the variable DAC_CHANNEL_1. Arduino IDE define it like 2 not as 25 as should it be.
Thanks to all for your help.
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.