opamp convert

who know the opamps
masters
I need your help

I had different trials
I couldn't perform the voltage process

I tried optocoupler and plain transistors
0.7v and 0.8v for transmission
not enough
I'm trying to compile a study that will feel exactly 0 ... v 5v mv

ardunio dac output with opamps
From 0-5v
5- I want to convert 0v
can work with different power supply

+5v -5 and +10v gnd 0v

To start with, the AD620 needs a resistor across pins 1 and 8. This resistor controls the gain of that stage. Look at the datasheet for information on how to calculate this resistor.

Do you mean invert rather than convert? i.e. reflect the voltage about mid-rail?

What is the source impedance? If low then a simple unity gain inverting stage with 2.5V at the + input
would work. You'd need a genuine rail-to-rail opamp.

hi

yes I mean a full inverted

I shared a sample application picture

ardunio and mcp4725 dac output 0 to 5v

I want opamp output 5v to 0v

opamp will drop from high voltage to 0 volts

voltage changing process

thanks

High voltage? Opamps can't handle high voltages in general.

Can you be more specific about input / output voltages and source-resistance please.

ardunio and mcp4725 dac output 0 to 5v
I want opamp output 5v to 0v

Inverting the direction of voltage doesn’t require an opamp, it just involves subtraction. If you’re sending 12 bits to the mcp4725, (4095 - count) will flip 0->5 to 5->0.

 #include<Wire.h>                   //Include Wire library for using I2C functions 

#define MCP4725 0x61              //MCP4725 address as 0x61 Change yours accordingly

unsigned int adc;
byte buffer[3];                   

void setup() 
{
  Wire.begin();                    //Begins the I2C communication
 

}

void loop() 

{
  buffer[0] = 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;  //Finding voltage formula (A0)
  buffer[1] = adc >> 4;              //Puts the most significant bit values
  buffer[2] = adc << 4;              //Puts the Least significant bit values
  
 
  unsigned int analogread = analogRead(A1)*4 ; //Reads analog voltage from A1
  
  float opvolt = (5.0/4096.0)* analogread; //Finding Voltage Formula (A1)
  
  Wire.beginTransmission(MCP4725);         //Joins I2C bus with MCP4725 with 0x61 address
  
  Wire.write(buffer[0]);            //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(500);
 
}

hi

I'm trying with these codes
unfortunately 0 to 5v

about codes
I did not succeed
change you can suggest
Do you have a code

5 to 0v changing

thanks

for a long time
I'm dealing with codes somehow
I couldn't adapt the extraction to the program

mcp4725 anolog using voltage opamp
I want to change 5 to 0v

I have to explain with a picture what to do with this inverted voltage

screen displey 000
when
diode voltage becomes 5v
screen displey 999
when
diode voltage zero
should be

MarkT:
High voltage? Opamps can't handle high voltages in general.

Can you be more specific about input / output voltages and source-resistance please.

https://ibb.co/c1DWnbQ

upload pictures
problem

download link

Not sure what you're trying to do with that opamp and it's output,
but I'm sure you don't need it to invert 0-5volt to 5-0volt.
Do it in code (see post#5).
Example sketch attached.
Leo..

int adc; // holds A/D readings
float ipvolt; // whatever that is

void setup() {
}

void loop() {
  adc = 0; // reset with every loop
  for (int i = 0; i < 4; i++) adc += analogRead(A0); // add four 10-bit readings | adc is now 0-4095

  // convert to volt, assuming VCC is 5.0volt (which it rarely is)
  ipvolt = (5.0 / 4096.0) * adc; // 0-5volt

  // or... invert and convert to volt
  ipvolt = (5.0 / 4096.0) * (4095 - adc); // 5-0volt
}

Wawa:
Not sure what you're trying to do with that opamp and it's output,
but I'm sure you don't need it to invert 0-5volt to 5-0volt.
Do it in code (see post#5).
Example sketch attached.
Leo..

int adc; // holds A/D readings

float ipvolt; // whatever that is

void setup() {
}

void loop() {
  adc = 0; // reset with every loop
  for (int i = 0; i < 4; i++) adc += analogRead(A0); // add four 10-bit readings | adc is now 0-4095

// convert to volt, assuming VCC is 5.0volt (which it rarely is)
  ipvolt = (5.0 / 4096.0) * adc; // 0-5volt

// or... invert and convert to volt
  ipvolt = (5.0 / 4096.0) * (4095 - adc); // 5-0volt
}

for (int i = 0; i <4; i ++) adc + = analogRead (A0);

these codes are counted automatically and become 4095
I tried this code

analogread (A0); works independently of the input 4095 counter

// or ... turn it over and convert it to volts
ipvolt = (5.0 / 4096.0) * (4095 - adc); // 5-0volt

I will try the code and I hope it works and thank you very much for your help.
god bless you and all of you from dangers

thanks the

Maybe the "map" function its what you need:

adc = analogRead(A0); 
adcT4 = map(adc, 1023, 0, 0, 4095);

Im not sure about the 4095 instead of 4096, but I think thats how it works in 12bit, you know, 0 to 4095 are 4096 different values.

Subtract the MCP4725 values from 5V.

edpsycho:
Maybe the "map" function its what you need:

adc = analogRead(A0); 

adcT4 = map(adc, 1023, 0, 0, 4095);




Im not sure about the 4095 instead of 4096, but I think thats how it works in 12bit, you know, 0 to 4095 are 4096 different values.

edpsycho:
Maybe the "map" function its what you need:

adc = analogRead(A0); 

adcT4 = map(adc, 1023, 0, 0, 4095);




Im not sure about the 4095 instead of 4096, but I think thats how it works in 12bit, you know, 0 to 4095 are 4096 different values.

this map command
it worked

there is only one problem
when the analog input voltage is zero
why dac output becomes zero volts

sample

A (0) 0V = dac out = 0v
A (0) 5mv = 4.95v
A (0) 500mv = 4.50v
all working backwards

I want
A (0) 0v = dac out = 4.99
it should have been

deniçem codes are available

adc = 0; // volt reset
adc = 5; //

but overall it's nice to work
I am grateful to all of you

Post your code, I guess you have this line:

float ipvolt = (5.0/4096.0)* adc;

And maybe its 4095 instead of 4096.

there is only one problem
when the analog input voltage is zero
why dac output becomes zero volts

sample

A (0) 0V = dac out = 0v
A (0) 5mv = 4.95v
A (0) 500mv = 4.50v
all working backwards

BEFORE subtracting DAC output from 5V,

DAC output = 0,

5V - 0 = 5V
AFTER subtracting DAC output from 0,
Result = 5V

#include<Wire.h> //Include Wire :
#define MCP4725 0x60 //MCP4725 0x6 :
unsigned long adc;
unsigned long buffer[3];

void setup()
{

Wire.begin(); //Begins the:
}
void loop() {
adc = analogRead(A0); // read :
adc = map(adc,0,1023,4096,0); // map :

buffer[0] = 0b01000000; //Sets the buffer0 with:
buffer[1] = adc >> 4; //Puts the most :
buffer[2] = adc << 4; //Puts the Least:
Wire.beginTransmission(MCP4725); //Joins I2C bus:
Wire.write(buffer[0]); //Sends the:
Wire.write(buffer[1]); //Sends the MSB to I2C :
Wire.write(buffer[2]); //Sends the LSB to I2C:
Wire.endTransmission(); //Ends :
delay(1);

}}

hi

these codes are working
map code worked

can you check the codes

raschemmel:
BEFORE subtracting DAC output from 5V,

DAC output = 0,

5V - 0 = 5V
AFTER subtracting DAC output from 0,
Result = 5V

can you share a short sample code

I tried the subtraction code you gave above but the result has not changed

thanks

What I sent was pseudo code.
Before we even go there you need disclose what the status of your project is,
You have too much going on.
You need to eliminate all of the code in your sketch and simply do nothing but
command the dac to 5 different values and read back that you receive those
values. Nothing more.

There is nothing in the following code that is related to the problem you describe
except for the MCP4725 I2C code. You need to test the DAC BY ITSELF WITH NO OTHER
DEVICES FIRST.
IF AND ONLY IF , you can repeated command the DAC to 5 different voltages and read those
back with the arduino analog pin, then we can proceed. Otherwise, you're just spinning
your wheels.
There is one other thing that needs to be verified and that's the I2C addresses. Have you
run the I2C SCANNER yet ? If not , the code is attached and I will paste it in the post
window as well. Once you have verified the DAC works, AND verified there are no conflicting
addresses, then we can talk about your problem:
For starters, if you're using an MCP4725, why aren't you including an MCP4725 Library ?

#include<Wire.h>                   //Include Wire library for using I2C functions

#define MCP4725 0x61              //MCP4725 address as 0x61 Change yours accordingly

unsigned int adc;
byte buffer[3];                   

void setup()
{
  Wire.begin();                    //Begins the I2C communication
 

}

void loop()

{
  buffer[0] = 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;  //Finding voltage formula (A0)
  buffer[1] = adc >> 4;              //Puts the most significant bit values
  buffer[2] = adc << 4;              //Puts the Least significant bit values
 
 
  unsigned int analogread = analogRead(A1)*4 ; //Reads analog voltage from A1
 
  float opvolt = (5.0/4096.0)* analogread; //Finding Voltage Formula (A1)
 
  Wire.beginTransmission(MCP4725);         //Joins I2C bus with MCP4725 with 0x61 address
 
  Wire.write(buffer[0]);            //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(500);
 
}

I2C SCANNER CODE

   // --------------------------------------
    // i2c_scanner
    //
    // Version 1
    //    This program (or code that looks like it)
    //    can be found in many places.
    //    For example on the Arduino.cc forum.
    //    The original author is not know.
    // Version 2, Juni 2012, Using Arduino 1.0.1
    //     Adapted to be as simple as possible by Arduino.cc user Krodal
    // Version 3, Feb 26  2013
    //    V3 by louarnold
    // Version 4, March 3, 2013, Using Arduino 1.0.3
    //    by Arduino.cc user Krodal.
    //    Changes by louarnold removed.
    //    Scanning addresses changed from 0...127 to 1...119,
    //    according to the i2c scanner by Nick Gammon
    //    https://www.gammon.com.au/forum/?id=10896
    // Version 5, March 28, 2013
    //    As version 4, but address scans now to 127.
    //    A sensor seems to use address 120.
    // Version 6, November 27, 2015.
    //    Added waiting for the Leonardo serial communication.
    //
    //
    // This sketch tests the standard 7-bit addresses
    // Devices with higher bit address might not be seen properly.
    //
     
    #include <Wire.h>
     
     
    void setup()
    {
      Wire.begin();
     
      Serial.begin(9600);
      while (!Serial);             // Leonardo: wait for serial monitor
      Serial.println("\nI2C Scanner");
    }
     
     
    void loop()
    {
      byte error, address;
      int nDevices;
     
      Serial.println("Scanning...");
     
      nDevices = 0;
      for(address = 1; address < 127; address++ )
      {
        // The i2c_scanner uses the return value of
        // the Write.endTransmisstion to see if
        // a device did acknowledge to the address.
        Wire.beginTransmission(address);
        error = Wire.endTransmission();
     
        if (error == 0)
        {
          Serial.print("I2C device found at address 0x");
          if (address<16)
            Serial.print("0");
          Serial.print(address,HEX);
          Serial.println("  !");
     
          nDevices++;
        }
        else if (error==4)
        {
          Serial.print("Unknown error at address 0x");
          if (address<16)
            Serial.print("0");
          Serial.println(address,HEX);
        }    
      }
      if (nDevices == 0)
        Serial.println("No I2C devices found\n");
      else
        Serial.println("done\n");
     
      delay(5000);           // wait 5 seconds for next scan
    }

I i2c_scanner.pde (1.99 KB)

I i2c_scanner.pde (1.99 KB)

readme.txt (518 Bytes)