Products > Test Equipment
Arduino C Code for Measurements from UT61E
(1/1)
JenniferG:
If you are just measuring ohms you can get the measurement in as little as 25 to 50 lines of code.  Super easy.  Not complicated at all :)  (This uses the RS-232 DB9 cable that comes with the UT61E.)

The following is my code and it works well, at least so far (just wrote it).  Btw, I'll will modify the code later to check for LF at end of packet to make sure it's framed properly, which only adds a few lines of code.


--- Code: ---#define PIN_DTR 32

struct Packet {
  byte range;
  byte digit1;
  byte digit2;
  byte digit3;
  byte digit4;
  byte digit5;
  byte mode;
  byte info_flags;
  byte relative_mode_flags;
  byte limit_flags;
  byte voltage_and_autorange_flags;
  byte hold;
  byte cr;
  byte lf;
};

struct Packet packet;
float ohms = 0.0;

void setup() {
  Serial.begin(115200); // coms from arduino to mac/pc
  Serial2.begin(19200, SERIAL_7O1);        // seven bit word length, odd parity, one stop bit.
  pinMode(PIN_DTR, OUTPUT); // DTR needs to be high to power adapter
  digitalWrite(PIN_DTR, HIGH); // RTS needs to be grounded as well for powering adapter
  // RX line needs to be inverted (e.g. 74HC14N) before the arduino
}

void loop() {
  if (Serial2.available() > 0) {
    // read in the packet
    Serial2.readBytes((char *)&packet, 14);

    // strip out the junk
    packet.range  = packet.range  & B00000111; // bits 7 through 3 are always 00110
    packet.digit1 = packet.digit1 & B00001111; // bits 7 through 4 are always  0011
    packet.digit2 = packet.digit2 & B00001111; // bits 7 through 4 are always  0011
    packet.digit3 = packet.digit3 & B00001111; // bits 7 through 4 are always  0011
    packet.digit4 = packet.digit4 & B00001111; // bits 7 through 4 are always  0011
    packet.digit5 = packet.digit5 & B00001111; // bits 7 through 4 are always  0011
    packet.mode   = packet.mode   & B00001111; // bits 7 through 4 are always  0011

    // do the maths
    ohms = (100.0 * packet.digit1) + (10.0 * packet.digit2) + (1.0 * packet.digit3)
              + (0.1 * packet.digit4) + (0.01 * packet.digit5);
    if (packet.range > 0) {
      ohms = ohms * (pow(10.0, packet.range));
    }
 
    // display the result
    Serial.print("Ohms: " );
    if (ohms > 220000000) {
      Serial.println("OL.");
    } else {
      Serial.println(ohms);
    }
  }
}


--- End code ---

Measuring other stuff will come later.  I just got this meter yesterday :)  But I am primarily interested in measuring Ohms of an LDR in a DIY Vactrol for all 255 PWM values the Arduino writes to the LED in the same DIY Vactrol.

I am using the following web site to help me understand the packets; couldn't of done it without the following:

https://github.com/4x1md/ut61e_py


This could easily be adapted to STM32 and/or ESP32 etc.
JenniferG:
I started on the UT61E C++ class for this.  I created a github for this project.  Right now it can just read resistance, but will quickly evolve into a full functioning class to read anything possible on the meter.

https://github.com/JenniferGDev/ArduinoUT61E
JenniferG:
Wrote this little program for measuring the resistance of LDR in my DIY vactrol, based on variable PWM sent to the LED in the vactrol -- this is just a little example. Works great, and I achieved my goals and got all 256 resistance values for all 256 PWM signals sent to the LED.

The PWM adjusts the brightness on an LED in the DIY Vactrol.  Using the Tayda Water Green A-057 LED, 5549 photoresistor (LDR) and 10K current limiting resistor for this example.


--- Code: ---
#include "UT61E.h"
#define PIN_VACTROL_LED 46
#define PIN_DTR 32
UT61E ut61e = UT61E(&Serial2, PIN_DTR);

void setup() {
  Serial.begin(115200);                   // coms from arduino to mac
  pinMode(PIN_VACTROL_LED, OUTPUT);
}

void loop() {
  for (int i = 0; i < 256; i++) {
    analogWrite(PIN_VACTROL_LED, i);
    delay(3000);
    int error = ut61e.measureResistance();

    if (error != UT61E_SUCCESS) {
      switch (error) {
        case UT61E_ERROR_TIMEOUT:
          Serial.println("TIMEOUT");
          return;
        case UT61E_ERROR_READING_PACKET:
          Serial.println("ERROR READING PACKET");
          return;
        case UT61E_ERROR_INVALID_MODE:
          Serial.println("INVALID METER MODE");
          return;
      }
    }
    float ohms = ut61e.getResistance();
    Serial.print(i);
    Serial.print(" ");
    Serial.println(ohms);
  }
}


--- End code ---

Output:

--- Code: ---0 225800000.00
1 6162000.00
2 2620000.00
3 1630700.00
4 1169000.00
5 906400.00
6 737600.00
7 619500.00
8 533300.00
9 467100.00
10 414900.00
11 372500.00
12 338900.00
13 308400.00
14 283900.00
15 262500.00
16 244200.00
17 228100.00
18 213800.00
19 201460.00
20 190160.00
21 180040.00
22 170830.00
23 162450.00
24 154840.00
25 148370.00
26 141300.00
27 135430.00
28 129970.00
29 125360.00
30 120520.00
31 115850.00
32 111820.00
33 108050.00
34 104440.00
35 101460.00
36 97940.00
37 95010.00
38 92180.00
39 90170.00
40 87630.00
41 85220.00
42 82910.00
43 80740.00
44 78640.00
45 76710.00
46 74840.00
47 73000.00
48 71310.00
49 69690.00
50 68090.00
51 66320.00
52 64680.00
53 63310.00
54 62040.00
55 60700.00
56 59520.00
57 58280.00
58 57170.00
59 55990.00
60 55020.00
61 53960.00
62 53010.00
63 52020.00
64 51140.00
65 50220.00
66 49390.00
67 48530.00
68 47720.00
69 46960.00
70 46160.00
71 45400.00
72 44690.00
73 44010.00
74 43310.00
75 42660.00
76 42030.00
77 41410.00
78 40820.00
79 40210.00
80 39650.00
81 39100.00
82 38640.00
83 38000.00
84 37510.00
85 37000.00
86 36510.00
87 36010.00
88 35570.00
89 35080.00
90 34650.00
91 34200.00
92 33790.00
93 33330.00
94 32960.00
95 32540.00
96 32160.00
97 31760.00
98 31410.00
99 31010.00
100 30670.00
101 30300.00
102 29950.00
103 29610.00
104 29280.00
105 28950.00
106 28640.00
107 28330.00
108 28020.00
109 27730.00
110 27430.00
111 27150.00
112 26860.00
113 26580.00
114 26310.00
115 26040.00
116 25780.00
117 25510.00
118 25260.00
119 25010.00
120 24760.00
121 24510.00
122 24280.00
123 24030.00
124 23820.00
125 23570.00
126 23380.00
127 23130.00
128 22940.00
129 22710.00
130 22520.00
131 22300.00
132 22110.00
133 21900.00
134 21710.00
135 21500.00
136 21330.00
137 21120.00
138 20950.00
139 20750.00
140 20590.00
141 20400.00
142 20240.00
143 20070.00
144 19910.00
145 19726.00
146 19560.00
147 19397.00
148 19240.00
149 19082.00
150 18920.00
151 18777.00
152 18642.00
153 18488.00
154 18342.00
155 18207.00
156 18051.00
157 17920.00
158 17771.00
159 17642.00
160 17503.00
161 17378.00
162 17243.00
163 17122.00
164 16992.00
165 16867.00
166 16744.00
167 16624.00
168 16500.00
169 16377.00
170 16270.00
171 16153.00
172 16041.00
173 15922.00
174 15813.00
175 15700.00
176 15591.00
177 15482.00
178 15381.00
179 15274.00
180 15171.00
181 15069.00
182 14964.00
183 14869.00
184 14771.00
185 14675.00
186 14573.00
187 14484.00
188 14391.00
189 14296.00
190 14202.00
191 14114.00
192 14020.00
193 13933.00
194 13842.00
195 13753.00
196 13666.00
197 13579.00
198 13494.00
199 13414.00
200 13335.00
201 13255.00
202 13170.00
203 13098.00
204 13020.00
205 12941.00
206 12863.00
207 12787.00
208 12713.00
209 12637.00
210 12563.00
211 12492.00
212 12420.00
213 12341.00
214 12270.00
215 12201.00
216 12133.00
217 12061.00
218 11990.00
219 11928.00
220 11855.00
221 11796.00
222 11726.00
223 11666.00
224 11600.00
225 11537.00
226 11470.00
227 11413.00
228 11350.00
229 11292.00
230 11232.00
231 11174.00
232 11113.00
233 11059.00
234 10995.00
235 10940.00
236 10883.00
237 10831.00
238 10773.00
239 10723.00
240 10671.00
241 10622.00
242 10571.00
243 10520.00
244 10472.00
245 10423.00
246 10371.00
247 10331.00
248 10290.00
249 10248.00
250 10200.00
251 10187.00
252 10114.00
253 10079.00
254 10042.00
255 10002.00

--- End code ---

I then copy and paste the data from a terminal program to my spreadsheet.  Going to be running this tests over and over for various configurations: current limiting resistor, type of LED used as well as type of LDR used.
JenniferG:
Added methods for measuring amperage and voltage to my Arduino UT61E library, in addition to the resistance.

https://github.com/JenniferGDev/ArduinoUT61E
Navigation
Message Index
There was an error while thanking
Thanking...

Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod