Arduino C Code for Measurements from UT61E - Page 1
Forum section: electronics / testgear

author: JenniferG
author_rank: Frequent Contributor
timestamp: November 22, 2022, 08:00:09 am
content: 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 32struct 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/pcSerial2.begin(19200, SERIAL_7O1);// seven bit word length, odd parity, one stop bit.pinMode(PIN_DTR, OUTPUT);// DTR needs to be high to power adapterdigitalWrite(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 packetSerial2.readBytes((char *)&packet, 14);// strip out the junkpacket.range = packet.range & B00000111;// bits 7 through 3 are always 00110packet.digit1 = packet.digit1 & B00001111;// bits 7 through 4 are always 0011packet.digit2 = packet.digit2 & B00001111;// bits 7 through 4 are always 0011packet.digit3 = packet.digit3 & B00001111;// bits 7 through 4 are always 0011packet.digit4 = packet.digit4 & B00001111;// bits 7 through 4 are always 0011packet.digit5 = packet.digit5 & B00001111;// bits 7 through 4 are always 0011packet.mode = packet.mode & B00001111;// bits 7 through 4 are always 0011// do the mathsohms = (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 resultSerial.print("Ohms: " );if (ohms > 220000000) {Serial.println("OL.");} else {Serial.println(ohms);}}}Measuring other stuff will come later. I just got this meter yesterdayBut 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_pyThis could easily be adapted to STM32 and/or ESP32 etc.

author: JenniferG
author_rank: Frequent Contributor
timestamp: November 22, 2022, 07:32:31 pm
content: 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

author: JenniferG
author_rank: Frequent Contributor
timestamp: November 23, 2022, 11:21:15 am
content: 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 32UT61E ut61e = UT61E(&Serial2, PIN_DTR);void setup() {Serial.begin(115200); // coms from arduino to macpinMode(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);}}Output:Code:0 225800000.001 6162000.002 2620000.003 1630700.004 1169000.005 906400.006 737600.007 619500.008 533300.009 467100.0010 414900.0011 372500.0012 338900.0013 308400.0014 283900.0015 262500.0016 244200.0017 228100.0018 213800.0019 201460.0020 190160.0021 180040.0022 170830.0023 162450.0024 154840.0025 148370.0026 141300.0027 135430.0028 129970.0029 125360.0030 120520.0031 115850.0032 111820.0033 108050.0034 104440.0035 101460.0036 97940.0037 95010.0038 92180.0039 90170.0040 87630.0041 85220.0042 82910.0043 80740.0044 78640.0045 76710.0046 74840.0047 73000.0048 71310.0049 69690.0050 68090.0051 66320.0052 64680.0053 63310.0054 62040.0055 60700.0056 59520.0057 58280.0058 57170.0059 55990.0060 55020.0061 53960.0062 53010.0063 52020.0064 51140.0065 50220.0066 49390.0067 48530.0068 47720.0069 46960.0070 46160.0071 45400.0072 44690.0073 44010.0074 43310.0075 42660.0076 42030.0077 41410.0078 40820.0079 40210.0080 39650.0081 39100.0082 38640.0083 38000.0084 37510.0085 37000.0086 36510.0087 36010.0088 35570.0089 35080.0090 34650.0091 34200.0092 33790.0093 33330.0094 32960.0095 32540.0096 32160.0097 31760.0098 31410.0099 31010.00100 30670.00101 30300.00102 29950.00103 29610.00104 29280.00105 28950.00106 28640.00107 28330.00108 28020.00109 27730.00110 27430.00111 27150.00112 26860.00113 26580.00114 26310.00115 26040.00116 25780.00117 25510.00118 25260.00119 25010.00120 24760.00121 24510.00122 24280.00123 24030.00124 23820.00125 23570.00126 23380.00127 23130.00128 22940.00129 22710.00130 22520.00131 22300.00132 22110.00133 21900.00134 21710.00135 21500.00136 21330.00137 21120.00138 20950.00139 20750.00140 20590.00141 20400.00142 20240.00143 20070.00144 19910.00145 19726.00146 19560.00147 19397.00148 19240.00149 19082.00150 18920.00151 18777.00152 18642.00153 18488.00154 18342.00155 18207.00156 18051.00157 17920.00158 17771.00159 17642.00160 17503.00161 17378.00162 17243.00163 17122.00164 16992.00165 16867.00166 16744.00167 16624.00168 16500.00169 16377.00170 16270.00171 16153.00172 16041.00173 15922.00174 15813.00175 15700.00176 15591.00177 15482.00178 15381.00179 15274.00180 15171.00181 15069.00182 14964.00183 14869.00184 14771.00185 14675.00186 14573.00187 14484.00188 14391.00189 14296.00190 14202.00191 14114.00192 14020.00193 13933.00194 13842.00195 13753.00196 13666.00197 13579.00198 13494.00199 13414.00200 13335.00201 13255.00202 13170.00203 13098.00204 13020.00205 12941.00206 12863.00207 12787.00208 12713.00209 12637.00210 12563.00211 12492.00212 12420.00213 12341.00214 12270.00215 12201.00216 12133.00217 12061.00218 11990.00219 11928.00220 11855.00221 11796.00222 11726.00223 11666.00224 11600.00225 11537.00226 11470.00227 11413.00228 11350.00229 11292.00230 11232.00231 11174.00232 11113.00233 11059.00234 10995.00235 10940.00236 10883.00237 10831.00238 10773.00239 10723.00240 10671.00241 10622.00242 10571.00243 10520.00244 10472.00245 10423.00246 10371.00247 10331.00248 10290.00249 10248.00250 10200.00251 10187.00252 10114.00253 10079.00254 10042.00255 10002.00I 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.

author: JenniferG
author_rank: Frequent Contributor
timestamp: November 27, 2022, 09:18:50 pm
content: Added methods for measuring amperage and voltage to my Arduino UT61E library, in addition to the resistance.https://github.com/JenniferGDev/ArduinoUT61E