mcp4725 voltage

Hi
my god
damn the virus let's pray

i just joined the ardunio family thanks

my question
I made dac with mcp 4725 my codes

#include<Wire.h> //Include Wire library for using I2C functions
#define MCP4725 0x60 //MCP4725 address as 0x60 Change yours accordingly
unsigned int adc;
byte buffer[3];
void setup()
{
Serial.begin(9600);
Wire.begin(); //Begins the I2C communication
}
void loop()
{
buffer
= 0b01000000; //Sets the buffer0 with control byte (010-Sets in Write mode

adc = analogRead(A0) * 4; //Read Analog value from pin A0 and convert into digital (0-1023) multiply with 4 gives (0-4096)
float ipvolt = (5.0 / 4096.0) * adc;
buffer[1] = adc >> 4;
buffer[2] = adc << 4;
unsigned int analogread = analogRead(A0)4 ;
float opvolt = (5.0/4096.0)
analogread;
Wire.beginTransmission(MCP4725);
Wire.write(buffer
); //Sends the control byte to I2C

Wire.write(buffer [1] ); //Sends the MSB to I2C
Wire.write(buffer [2]); //Sends the LSB to I2C
Wire.endTransmission(); //Ends the transmission
delay(1000);

input voltage will go to voltage (0 ... 5)
output voltage
Must be (5 ... 0) v

I want it to be
anologread A0 input voltage (0 .... 5v)
I want from the output (5 ..... 0v)

can this be achieved by changing the address
or lice ~~ or !! I tried to use it, did not

I could not do the inverting process in the output example I would like your help, maybe a simple operation

from your code it looks like you want to send the 10-bit adc value read from A0 to the I2C device

don't understand the 4-bit shifts left and right.

in order to break the 10-bit value in the a least significant and most significant byte, you need to shift and/or mask

    byte lsb = adc & 0xFF;
    byte msb = (adc >> 8) & 0xFF;

on the other hand, you say the input is 0-5 but you want the output 5-0.

one approach is to simply subtract the 10-bit input value from 210, 1024.

--

actually the above program code is running
I programmed with ardunio uno
normal entry

voltage 0..5v
the exit

0..5v
i want the opposite
Max when A0 input is 5v

I want the output to be 0v

then I want the output to be 5v when A0 input is 0v

help thanks

gcjr:
from your code it looks like you want to send the 10-bit adc value read from A0 to the I2C device

don't understand the 4-bit shifts left and right.

in order to break the 10-bit value in the a least significant and most significant byte, you need to shift and/or mask

    byte lsb = adc & 0xFF;

byte msb = (adc >> 8) & 0xFF;





on the other hand, you say the input is 0-5 but you want the output 5-0.

one approach is to simply subtract the 10-bit input value from 2<sup>10</sup>, 1024. 

--

gcjr:
from your code it looks like you want to send the 10-bit adc value read from A0 to the I2C device

don't understand the 4-bit shifts left and right.

in order to break the 10-bit value in the a least significant and most significant byte, you need to shift and/or mask

    byte lsb = adc & 0xFF;

byte msb = (adc >> 8) & 0xFF;





on the other hand, you say the input is 0-5 but you want the output 5-0.

one approach is to simply subtract the 10-bit input value from 2<sup>10</sup>, 1024. 

--

thank the

as far as I understand this is not done with a different code

I will try to apply the code you specified above, I'm new to ardunio please I need your help very much

if you have different comments please I want you to write
I am grateful to this forum

byte lsb = adc & 0xFF;
byte msb = (adc >> 8) & 0xFF;

#include<Wire.h> //Include Wire library for using I2C functions
#define MCP4725 0x60 //MCP4725 address as 0x60 Change yours accordingly
unsigned int adc;
byte buffer[3];
void setup()
{

Wire.begin(); //Begins the I2C communication
}
void loop()
{
buffer [0] = 0b01000000;
adc = analogRead(A0) * 4;
float ipvolt = (5.0 / 4096.0) * adc; )
buffer[1] = adc >> 4;
buffer[2] = adc << 4;
unsigned int analogread = analogRead(A0)4 ; A1
float opvolt = (5.0/4096.0)
analogread;
Wire.beginTransmission(MCP4725);
Wire.write(buffer [0]);
byte lsb = adc & 0xFF; (where I wrote the codes)
byte msb = (adc >> 8) & 0xFF;
Wire.endTransmission();
delay(1000);

}

I added the code you gave to the loop section, I could not see a change, I added the code of the place lsb and msb

I may have applied in the wrong place

you need to understand the code i posted

you added code to calculate lsb and msb, but you're still sending buffer [1] and buffer [2]. lsb/msb are the values for buffer 1/2

gcjr:
you need to understand the code i posted

you added code to calculate lsb and msb, but you're still sending buffer [1] and buffer [2]. lsb/msb are the values for buffer 1/2

As you said in writing the codes yes, I am not very good, I am learning slowly.
In which cycle will I use this code?
It is not enough to know the codes one by one, it is very important to interpret the codes as a whole
I'm new, thank you, thankful

Configuration bytes:
// 12-bit device values from 0-4095
// page 18-19 spec sheet
buffer[0] = 0b01000000; // control byte
// bits 7-5; 010 write DAC; 011 write DAC and EEPROM
// bits 4-3 unused
// bits 2-1 PD1, PD, PWR down P19 00 normal.
// bit 0 unused

buffer[1] = 0b00000000; //HIGH data
// bits 7-0 D11-D4

buffer[2] = 0b00000000; // LOW data
// bits 7-4 D3-D0
// bits 3-0 unused
*/

the code I posted shows how to break the 10-bit value from the ADC into two separate 8-bit values for transmission.

presumably you know how to transmit the data, bufer [1] and buffer [2]. your shifting by 4 bits wasn't corrrect

You continue to post code without using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons. The "Code: [Select]" feature allows someone to select the entire sketch so it can be easily copied and pasted into the IDE for testing.
If you have already posted without using code tags, open your message and select "modify" from the pull down menu labelled, "More", at the lower right corner of the message. Highlight your code by selecting it (it turns blue), and then click on the "</>" icon at the upper left hand corner. Click on the "Save" button. Code tags can also be inserted manually in the forum text using the code and /code metatags.

// Test program for DAC MCP4725
// Code for Arduino
// Author Retian
// Version 2.2

#include <Wire.h> //wire library
#include <Adafruit_MCP4725.h> // MCP4725 library from adafruit

MyMCP4725 DAC (0x60); // I2C address = 0x62

#define potiPin A0

int16_t potiVert;
long long int startTime, endTime;
bool dacStatus = false;

void setup () {
Serial.begin (115200);

}

void loop () {
if (dacStatus)
{
// Read in the potentiometer
potiWert = analogRead (potiPin);
potiValue = map (potiValue, 0, 1023, 0, 4095);
Serial.print ("\ nPotiwert:");
Serial.println (potiWert);
startTime = micros ();

// Output of the potentiometer value in normal mode
DAC.setVoltage (potiWert);
endTime = micros ();
Serial.print ("Time:");
Serial.print (endTime - startTime);
Serial.println ("us");

// Read back the DAC register
Serial.print ("DAC:");
Serial.println (DAC.readRegister ());

// Read back the EEPROM
Serial.print ("EEPROM:");
Serial.println (DAC.readEEPROM ());

delay (1000);
}
}

(( STRAY '/302' in program ))

I got the program error. What could be the reason?

https://arduino-projekte.webnode.at/meine-libraries/dac-mcp4725/

Do copy and paste cause program errors?

can you share

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom... :slight_smile:

Hi,
The error STRAY means that there is a hidden character in your sketch that is not recognizable.
This a reason using code tags are so important.

Also the structure of the code for the Adafruit library that you have posted looks nothing like that.
Have a look at the Examples in the IDE for that library.

Can you post the ENTIRE code you had working in post#1 please, using code tags.

Tom.. :slight_smile:

    // Test program for DAC MCP4725
// Code for Arduino
// Author Retian
// Version 2.2


#include <Wire.h>           //wire library
#include <Adafruit_MCP4725.h> // MCP4725 library from adafruit

MyMCP4725 DAC (0x60); // I2C address = 0x62



#define potiPin 0

int16_t potiVert;
long long int startTime, endTime;
bool dacStatus = false;



void setup () {
  Serial.begin (115200);


}



void loop () {
  if (dacStatus)
  {
    // Read in the potentiometer
    potiWert = analogRead (potiPin);
    potiValue = map (potiValue, 0, 1023, 0, 4095);
    Serial.print ("\ nPotiwert:");
    Serial.println (potiWert);
    startTime = micros ();



    // Output of the potentiometer value in normal mode
    DAC.setVoltage (potiWert);
    endTime = micros ();
    Serial.print ("Time:");
    Serial.print (endTime - startTime);
    Serial.println ("us");



    // Read back the DAC register
    Serial.print ("DAC:");
    Serial.println (DAC.readRegister ());



    // Read back the EEPROM
    Serial.print ("EEPROM:");
    Serial.println (DAC.readEEPROM ());



    delay (1000);
  }
}

from the originally written site

 // Test program for DAC MCP4725
// Code for Arduino
// Author Retian
// Version 2.2



#include <MyMCP4725.h>
MyMCP4725 DAC (0x62); // I2C address = 0x62



#define potiPin 0

int16_t potiVert;
unsigned long startTime, endTime;
bool dacStatus = false;



void setup () {
  Serial.begin (115200);


  if (DAC.isReady ())
  {
    Serial.println ("\ nDAC ok!");
    dacStatus = true;
  }
  else Serial.println ("DAC error!");


  // Start output value of the DAC at 0 V (basic setting = VDD / 2)
  //DAC.setVoltage(0, MCP4725_WRITE_EEPROM); // EEPROM is written !!

}



void loop () {
  if (dacStatus)
  {
    // Read in the potentiometer
    potiWert = analogRead (potiPin);
    potiValue = map (potiValue, 0, 1023, 0, 4095);
    Serial.print ("\ nPotiwert:");
    Serial.println (potiWert);
    startTime = micros ();



    // Output of the potentiometer value in normal mode
    DAC.setVoltage (potiWert);
    endTime = micros ();
    Serial.print ("Time:");
    Serial.print (endTime - startTime);
    Serial.println ("us");



    // Read back the DAC register
    Serial.print ("DAC:");
    Serial.println (DAC.readRegister ());



    // Read back the EEPROM
    Serial.print ("EEPROM:");
    Serial.println (DAC.readEEPROM ());



    delay (1000);
  }
}

for mcp 4725

adofruit model
and there is a normal clone

their distinct pcb colors are blue adofrites
red clone

In most articles, adofrit is written with a special program as if there is a different code application.
it has air

adofrit 0x62----0x63

clone 0x60--0x61

What is your comment?

I am gradually learning that I am new to the

mcp4725 eeprom intervention codes available

Hi,
Try this edit of your code, I have used the map() function to reverse the response.
Also the code was outputting the analog input and not the scaled output.

// Test program for DAC MCP4725
// Code for Arduino
// Author Retian
// Version 2.2

#include <MyMCP4725.h>
MyMCP4725 DAC (0x62); // I2C address = 0x62
#define potiPin 0

int16_t potiVert;
unsigned long startTime, endTime;
bool dacStatus = false;

void setup ()
{
  Serial.begin (115200);

  if (DAC.isReady ())
  {
    Serial.println ("\ nDAC ok!");
    dacStatus = true;
  }
  else Serial.println ("DAC error!");
  // Start output value of the DAC at 0 V (basic setting = VDD / 2)
  //DAC.setVoltage(0, MCP4725_WRITE_EEPROM); // EEPROM is written !!
}

void loop ()
{
  if (dacStatus)
  {
    // Read in the potentiometer
    potiWert = analogRead (potiPin);
    potiValue = map (potiValue, 0, 1023, 4095, 0); // use map function to reverse the output response
    Serial.print (" Potiwert: ");
    Serial.print (potiWert);
    Serial.print ("  Potiwert: ");
    Serial.println (potiValue);
    startTime = micros ();

    // Output of the potentiometer value in normal mode
    DAC.setVoltage (potiValue);
    endTime = micros ();
    Serial.print ("Time:");
    Serial.print (endTime - startTime);
    Serial.println ("us");

    // Read back the DAC register
    Serial.print ("DAC:");
    Serial.println (DAC.readRegister ());

    // Read back the EEPROM
    Serial.print ("EEPROM:");
    Serial.println (DAC.readEEPROM ());
    delay (1000);
  }
}

Tom... :slight_smile:

I don't understand why the program goes wrong
everything must be normal

kkkkkkkk.jpg

hello tom

thanks for your answers

4096, to 0;
I realized that you did your code, I thought so

nzmxp:
I don't understand why the program goes wrong
everything must be normal

The error report tells you it cannot find that library, you will have to find it and load it into the IDE.
Did my code work?
Tom.. :slight_smile:

TomGeorge:
The error report tells you it cannot find that library, you will have to find it and load it into the IDE.
Did my code work?
Tom.. :slight_smile:

I couldn't compile the code I last installed

available in my library
adofrites and normal
there is mcp4725

there may be extra libraries belonging to it.

a little more
I have to work

thanks tom