-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMCP4725_4-20mA_Tx.ino
41 lines (38 loc) · 996 Bytes
/
MCP4725_4-20mA_Tx.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <Wire.h>
byte address = 0x60;
void setup()
{
Serial.begin (9600);
Wire.begin();
}
int set_volt ( int raw_value)
{
Wire.beginTransmission(address );
Wire.write(64);
Wire.write(raw_value >> 4); // 8 MSB
Wire.write((raw_value & 15) << 4); //4 LSB
Wire.endTransmission();
Serial.print (raw_value, DEC);
Serial.print("\n");
}
void loop()
{
/// at DAC vlaue 290 the current output will be around 4mA and
///at DAC vlaue 1500 the current output will be around 20mA
/// you can change these values to tune the 4-20mA output
//for (int i=0; i <= 4096; i++) ///////to use this code with 0-10V Hardware
for (int i=290; i <= 1500; i++) ///////to use this code with 4-20mA Hardware
{
Wire.beginTransmission(address );
Wire.write(64);
// Wire.write(64);
Wire.write(i >> 4); // 8 MSB
Wire.write((i & 15) << 4); //4 LSB
delay(1000);
Serial.print (i, DEC);
Serial.print("\n");
Wire.endTransmission();
i = i + 100;
}
//set_volt(4095);
}