Pulling my hair out Trying to read the DAC1 value using any ADC pin. Cannot get it to work

Msousa
Posts: 1
Joined: Thu Aug 31, 2023 2:21 am

Pulling my hair out Trying to read the DAC1 value using any ADC pin. Cannot get it to work

Postby Msousa » Thu Aug 31, 2023 3:26 am

/*
Maybe someone can help me out. I'm using a ESP32 TTGO ver1 display 240x135

I am trying to display the DAC1 voltage on the tft display. I thought this would be trivial but I was wrong.

I can setup any ADC on the TTGO and have it read some external voltage 0 to 3.3v works great.
I can also setup the DAC1 or DAC2 and change the output voltage using the built in Buttons, that works great
I can connect my meter or a scope to the DAC1 pin and view the changing voltage. All good so far.

Here is the problem I want to display the DAC value on the TFT display. So I connect the DAC1 pin to any
ADC (that was working above) and I get garbage. the value is completely wrong. I'm lost.

Any Help would be awesome
Mike

*/





#include <TFT_eSPI.h> // Hardware-specific library
#include <SPI.h>

TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
#define TFT_WIDTH 240 // ST7789 240 x 240 and 240 x 320
#define TFT_HEIGHT 135
#define TFT_GREY 0x5AEB

// define the ADC Name, ADC Pin#
#define ADC12 2 // 9p"D" pin1 Brown Wire Internal Peltier 2.7v
#define ADC13 15 // 9p"D" pin7 Violet Wire External Peltier 2.4v
#define ADC14 13 // 9p"D" pin4 Yellow Wire Power +15v
#define ADC15 12 // Not working properly. When tide to 3v ESP32 hangs
//#define ADC0 36
#define ADC3 39 // 9p"D" pin3 Orange Wire Power -15v
#define ADC4 32 // 9p"D" pin2 Red Wire Detector 140v
#define ADC5 33 // Reads DAC1 value on pin 25 !! not working
#define ADC17 27
#define ADC19 26
#define DAC1 25 // 9p"D" pin5 Green Wire Temp Sensor

//Buttons
int Button_Left = 0;
int Button_Right = 35;
bool buttonStateL;
bool buttonStateR;

int x = 0;
float data = 0.0;

void setup() {
// put your setup code here, to run once:
tft.init();
tft.setRotation(1);
tft.setTextSize(2);
Serial.begin(57600); // For debug
tft.fillScreen(TFT_BLACK);
analogReadResolution(12);

pinMode(Button_Left, INPUT_PULLUP);
pinMode(Button_Right, INPUT_PULLUP);
pinMode(ADC12,INPUT_PULLUP);
pinMode(ADC13,INPUT);
pinMode(ADC14,INPUT);
pinMode(ADC3, INPUT);
pinMode(ADC4, INPUT);
pinMode(ADC5, INPUT);
pinMode(ADC17, INPUT);
pinMode(ADC19,INPUT_PULLDOWN);
pinMode(DAC1, OUTPUT);

analogWrite(DAC1, x);

}

void loop() {
// put your main code here, to run repeatedly:
ButtonTest();
delay(200);
}

void ButtonTest() {

buttonStateL = digitalRead(Button_Left);
buttonStateR = digitalRead(Button_Right);
if(buttonStateL == false) {
tft.fillRect(0,120,240,15,TFT_BLACK);
if(x > 0){
x=x-10;
}
//Update19 = true;
// tft.setCursor(10,120);
// tft.print(x);
// tft.print(" ");
// tft.print(dacValues[x]);
}

if(buttonStateR == false) {
tft.fillRect(0,120,240,15,TFT_BLACK);
if(x < 255) {
x=x+10;
}
//Update19 = true;
// tft.setCursor(10,120);
// tft.print(x);
// tft.print(", ");
// tft.print(dacValues[x]);
}
tft.setCursor(10,120);
tft.print(x);
analogWrite(DAC1, x);
delay(100);
data = analogReadMilliVolts(ADC12);
//data = analogRead(ADC12);
tft.setCursor( 80,120);
tft.print(data*.001);

}

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 76 guests