Go Down

Topic: UT60E meter receiving data to arduino (Read 111 times) previous topic - next topic

Steveiboy

Aug 17, 2016, 09:04 pm Last Edit: Aug 23, 2016, 07:16 am by Steveiboy
I have a working project which was done in PDS and would like now to convert it over to Arduino instead as this is all I use now and been a long time since I used basic.
But there is some bit's that I'm struggling with and tried many ways to convert it over.
Example Dim TEMP0 = 0  in basic and would be byte TEMP0 = 0; and this would be Dim DMM_ARRAY[14] As Byte in basic changed to byte DMM_ARRAY[14];
Not sure how I can achieve this from basic to Arduino
Code: [Select]
SerIn PORTC.7 , T2400 , [Str DMM_ARRAY\14]  'get the 14 bytes

Basic Str is a string arrary
Would this work Arduino code serial part only to start
Code: [Select]
byte buffer1[14]; ' store the data
int cnt = 0 ;

//void process_sample(void);
void setup() {
Serial.begin(2400);
Serial.println("START");
}

void loop() {
if ((cnt <14) && Serial.available()) buffer1[cnt++] = Serial.read(); ' get the serial data
}

 
This is another part I'm struggling with if I can convert this part I think the rest will be the same for LOOP2,3,4 as I'm not sure how to create a look downtable in Arduino
Code: [Select]
'BYTES 1&2 FOR THE FIRST DIGIT AND PRINTS THE NEGATIVE SIGN
        For LOOP1 = 1 To 7 Step 2
        TEMP1 = (DMM_ARRAY[1] <<4) | (DMM_ARRAY[2] &$0F)
        If TEMP1.7 = 1 Then
        Print At 2,1,"-"
        'Print $FE, $C0, "-" 'PRINT THE DECIMAL POINT
        Clear TEMP1.7 ' CLEAR THE MSB.
        Else Print At 2,1," "'Print $FE, $C0, " " 'PRINT BLANK SAPCE IF CORRECT
        EndIf
        TEMP1 = LookDown TEMP1,[$7D,$05,$5B,$1F,$27,$3E,$7E,$15,$7F,$3F,$00,$68]' change to []={ 0x7D, 0x05, 0x5B, 0x1F, 0x27, 0x3E, 0x7E, 0x15, 0x7F, 0x3F, 0 }; for Arduino
        Next LOOP1

The case select and printing to the LCD I should be able to work out, Here is the full basic code
Code: [Select]

Device = 16F883

'Config1 FOSC_xt, WDTE_OFF, PWRTE_OFF, MCLRE_ON, BOREN_OFF, BORV_20, DEBUG_OFF, CCP2MX_RC1, CP_OFF
'Config2 FCMEN_OFF, IESO_OFF, BORSEN_OFF

Config1 FOSC_HS, WDTE_OFF, PWRTE_OFF, MCLRE_ON, CP_OFF, CPD_OFF, BOREN_OFF, IESO_ON, FCMEN_OFF, LVP_OFF, DEBUG_OFF
Config2 BOR4V_BOR40V, WRT_OFF
;**** End of Fuse Configurator Settings ****
;-------------------------------------------------------------------------------
    Declare LCD_DTPin = PORTC.0
    Declare LCD_RSPin = PORTC.4
    Declare LCD_ENPin = PORTC.5
    Declare LCD_Interface = 4
    Declare LCD_Lines = 2
    Declare LCD_Type = 0
    Declare LCD_CommandUs = 2000
    Declare LCD_DataUs = 50                     ' CURRENT CHOSEN DEVICE  
    All_Digital = true
   Xtal = 4
  
        
    Dim TEMP0 As Byte=0
    Dim TEMP1 As Byte = 0
    Dim TEMP2 As Byte = 0
    Dim TEMP3 As Byte = 0
    Dim TEMP4 As Byte = 0
    Dim TEMP5 As Byte = 0
    Dim TEMP6 As Byte = 0
    Dim TEMP9 As Byte =0
    Dim TEMP10 As Byte =0
    Dim TEMP11 As Byte =0
    Dim TEMP12 As Byte =0
    Dim TEMP14 As Byte =0
    Dim LOOP1 As Byte = 0
    Dim LOOP2 As Byte = 0
    Dim LOOP3 As Byte = 0
    Dim LOOP4 As Byte = 0
    Dim LOOP5 As Byte = 0
    Dim LOOP As Byte = 0
    Dim PRINT_SIGN As Byte =0
    Dim PRINT_SIGN1 As Byte =0
    Dim TEMP_STORED As Byte = 0
    Dim STORED1 As Bit = 0
    Dim STORED2 As Bit =0
    Dim STORED3 As Bit =0
    Dim STORED4 As Bit =0
    Dim F_SELECT As Byte  =0  
    Dim DMM_ARRAY[14] As Byte
     Cls
     DelayMS 100
  MAIN:
        
        SerIn PORTC.7 , T2400 , [Str DMM_ARRAY\14]  'get the 14 bytes
       'BYTES 1&2 FOR THE FIRST DIGIT AND PRINTS THE NEGATIVE SIGN
        For LOOP1 = 1 To 7 Step 2
        TEMP1 = (DMM_ARRAY[1] <<4) | (DMM_ARRAY[2] &$0F)
        If TEMP1.7 = 1 Then
        Print At 2,1,"-"
        'Print $FE, $C0, "-" 'PRINT THE DECIMAL POINT
        Clear TEMP1.7 ' CLEAR THE MSB.
        Else Print At 2,1," "'Print $FE, $C0, " " 'PRINT BLANK SAPCE IF CORRECT
        EndIf
        TEMP1 = LookDown TEMP1,[$7D,$05,$5B,$1F,$27,$3E,$7E,$15,$7F,$3F,$00,$68]
        Next LOOP1
       'BYTES 3&4 FOR THE SECOND DIGIT
        For LOOP2 = 1 To 7 Step 2
        TEMP2 = (DMM_ARRAY[3] <<4) | (DMM_ARRAY[4] &$0F)
        STORED1 = TEMP2.7  
        Clear TEMP2.7 ' CLEAR THE MSB.
        TEMP2 = LookDown TEMP2,[$7D,$05,$5B,$1F,$27,$3E,$7E,$15,$7F,$3F,$00,$68]
        Next LOOP2
       'BYTES 5&6 FOR THE THIRD DIGIT
        For LOOP3 = 1 To 7 Step 2
        TEMP3 = (DMM_ARRAY[5] <<4) | (DMM_ARRAY[6] &$0F)
        STORED2 = TEMP3.7  
        Clear TEMP3.7 ' CLEAR THE MSB.
        TEMP3 = LookDown TEMP3,[$7D,$05,$5B,$1F,$27,$3E,$7E,$15,$7F,$3F,$00,$68]
        Next LOOP3
       'BYTES 7&8 FOR THE FORTH DIGIT
        For LOOP4 = 1 To 7 Step 2
        TEMP4 = (DMM_ARRAY[7] <<4) | (DMM_ARRAY[8] &$0F)
        STORED3 = TEMP4.7  
        Clear TEMP4.7 ' CLEAR THE MSB.
        TEMP4 = LookDown TEMP4,[$7D,$05,$5B,$1F,$27,$3E,$7E,$15,$7F,$3F,$00,$68]
        Next LOOP4
        
       'SELECT THE SCREEN FOR PRINTING    
       If STORED1 = 1 And STORED2 = 0 And STORED3 = 0 And STORED4 = 0 Then F_SELECT = 1
       If STORED1 = 0 And STORED2 = 1 And STORED3 = 0 And STORED4 = 0 Then F_SELECT = 2
       If STORED1 = 0 And STORED2 = 0 And STORED3 = 1 And STORED4 = 0  Then F_SELECT = 3
       If STORED1 = 0 And STORED2 =  0 And STORED3 = 0 And STORED4 = 0  Then F_SELECT = 4
       If  TEMP1 = 10 Then F_SELECT = 5  
       Select F_SELECT
       Case 1
      Print At 2,2,Dec1 TEMP1,".",Dec1 TEMP2,Dec1 TEMP3,Dec TEMP4,"  "
       Case 2
       Print At 2,2,Dec1 TEMP1,Dec1 TEMP2,".",Dec1 TEMP3,Dec TEMP4,"  "
      Case 3
       Print At 2,2,Dec1 TEMP1,Dec1 TEMP2,Dec1 TEMP3,".",Dec TEMP4,"  "
       Case 4
         Print At 2,2,Dec1 TEMP1,Dec1 TEMP2,Dec1 TEMP3,Dec TEMP4,"  "
         Case 5
         Print At 2,2," O.L "
       End Select
       If TEMP0.3 = 1 Then
       Print At 1,7,"AC "
       Else  Print At 1,7,"DC "
       EndIf
        TEMP0 = DMM_ARRAY[0] & $0F
        TEMP9 = DMM_ARRAY[9] & $0F
        TEMP10 = DMM_ARRAY[10] & $0F
        TEMP11 = DMM_ARRAY[11] & $0F
        TEMP12 = DMM_ARRAY[12] & $0F
        TEMP14 = DMM_ARRAY[13] & $0F
        Print At 1,9,#TEMP14.3,#TEMP14.2,#TEMP14.2,#TEMP14.0
         DelayMS 20    
       If TEMP10.3 = 1 And TEMP12.2 = 1  Then PRINT_SIGN = 0  'PRINT THE mV SIGN
       If TEMP10.3 =0 And TEMP12.2 = 1  Then  PRINT_SIGN = 1   'PRINT THE V SIGN
       If TEMP11.2 =1 And TEMP11.1 =0 Then  PRINT_SIGN = 2   'PRINT R SING FOR OHMS
       If TEMP9.1 = 1 And TEMP11.2=1 Then   PRINT_SIGN = 3    'PRINT K SING FOR OHMS
       If TEMP10.1 =1 And TEMP11.2 = 1 Then PRINT_SIGN = 4  'PRINT THE M MEG OHMS
       If TEMP9.0 = 1 And TEMP12.2= 1 Then PRINT_SIGN = 5   'DIODE
       If TEMP10.0 =1 And TEMP11.2 = 1 Then PRINT_SIGN = 6   'BLLEP
       If TEMP9.2 =1 And TEMP11.3= 1 Then PRINT_SIGN = 7     'nF CAP
       If TEMP9.3 =1 And TEMP11.3=1  Then PRINT_SIGN = 8     'uF CAP
       If TEMP9.1 = 0 And TEMP12.1 = 1  Then PRINT_SIGN = 9    ' HZ
       If TEMP9.1 = 1 And TEMP12.1 = 1 Then  PRINT_SIGN = 10    'k HZ
       If TEMP10.1 = 1 And TEMP12.1 = 1  Then  PRINT_SIGN = 11    ' mHZ
       If TEMP10.2 = 1 And TEMP10.1 = 0 Then  PRINT_SIGN = 12       'DUTY %
       If TEMP9.3=0 And TEMP10.3 = 0 And TEMP11.3=0 And TEMP14.0 = 1 Then  PRINT_SIGN = 13      'TEMP
       If TEMP9.3 =1 And TEMP10.3 = 0 And TEMP11.3 =0 And TEMP12.3 = 1 Then PRINT_SIGN = 14     'u AMPS
       If TEMP9.3=0 And TEMP10.3 = 1 And TEMP11.3=0 And TEMP12.3 = 1 Then PRINT_SIGN = 15      'm AMPS
       If TEMP9.3=0 And TEMP10.3 = 0 And TEMP11.2=0 And TEMP12.3=1 Then PRINT_SIGN = 16     'A AMPS
            
       Select PRINT_SIGN
      Case  0
       Print At 1,1,"VOLTS"
       Print At 2,7,"mV"
       Case 1
       Print At 1,1,"VOLTS"
       Print At 2,7," V"
       Case 2
       Print At 1,1," OHMS  "
      Print At 2,7," R"
       Case 3
       Print At 1,1," OHMS  "
       Print At 2,7," K"
        Case 4
       Print At 1,1," OHMS  "
       Print At 2,7," M"
       Case 5
       Print At 1,1," DIODE "
        Print At 2,7," V"
       Case 6
       Print At 1,1," BLEEP "
        Print At 2,7,"CM"
       Case 7
       Print At 1,1,"   CAP   "
       Print At 2,7,"nF"
       Case 8
       Print At 1,1,"   CAP   "
       Print At 2,7,"uF"
        Case 9
      Print At 1,1," FREQ   "
      Print At 2,7,"HZ"
       Case 10
      Print At 1,1," FREQ   "
      Print At 2,7," k"
       Case 11
       Print At 1,1," FREQ   "
       Print 2,7," M"
       Case 12
       Print At 1,1," DUTY  "
       Print At 2,7," %"
       Case 13
       Print At 1,1," TEMP   "
       Print At 2,7," C"
       Case 14
     Print At 1,1," AMPS "
      Print At 2,7,"uA"
       Case 15
      Print At 1,1," AMPS "
       Print At 2,7,"mA"
       Case 16
     Print At 1,1," AMPS "
       Print At 2,7," A"
       End Select  
      GoTo MAIN


any guidance would be grateful
Thanks
Steve





johnwasser

I don't recognize some of those constructs but the regular flow-control statements (if, for, else)  are fairly easy to translate:
Code: [Select]
//'BYTES 1&2 FOR THE FIRST DIGIT AND PRINTS THE NEGATIVE SIGN
//        For LOOP1 = 1 To 7 Step 2
    for (int LOOP1 = 1; LOOP1 <= 7; LOOP1 += 2) {
//        TEMP1 = (DMM_ARRAY[1] <<4) | (DMM_ARRAY[2] &$0F) 
        byte TEMP1 = (buffer1[0] <<4) | buffer1[1] & 0x0F;
//        If TEMP1.7 = 1 Then
        if (TEMP1 & 0x80) {
//          Print At 2,1,"-"
            Serial.write('-');
//        'Print $FE, $C0, "-" 'PRINT THE DECIMAL POINT
            Serial.write(0xFE);
            Serial.write(0xC0);
            Serial.write('-');
//        Clear TEMP1.7 ' CLEAR THE MSB.
            TEMP1 &= 0x7F;
        Else Print At 2,1," "'Print $FE, $C0, " " 'PRINT BLANK SAPCE IF CORRECT
        else {
            Serial.write(0xFE);
            Serial.write(0xC0);
            Serial.write(' ');
//        EndIf
        }
//        TEMP1 = LookDown TEMP1,[$7D,$05,$5B,$1F,$27,$3E,$7E,$15,$7F,$3F,$00,$68]' change to []={ 0x7D, 0x05, 0x5B, 0x1F, 0x27, 0x3E, 0x7E, 0x15, 0x7F, 0x3F, 0 }; for Arduino
    for (int i=0; i<sizeof LOOKDOWN; i++) {
        if (LOOKDOWN[i] == TEMP1) {
            TEMP1 = i;
            break;
        }
     }
//        Next LOOP1
    }


I'm assuming 'LookDown' return the index of the array that matches the value.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

Steveiboy

Thanks John
I will try that, Yes the look down returns the value the meter sends out 14 byte hexadecimal string and need to convert this into more human figure, This is where I got the data from when I used PDS
http://perfec.to/ut60e/

I have the byte sequence..... 20,35,47,5d,69,75,85,9b

The first digit of each byte (high nibble) is the sequence number so for the purposes of the calculation, it can be discarded. We the combine the second digits from two consecutive numbers (the lower nibbles) to form a byte. So we now have...
05, 7D, 97, 5B

Using the look-up table from the link I posted we get...
05...1
7D...0
97...7 (Note that the msb of this byte is cleared so we look up 17 not 97 The fact that the msb is set indicates the decimal point.)
5B...2

So the voltage is 10.72 volts and so on, The PDS codes displays the mode and readings from the meter

Thanks
Steve



Steveiboy

I have been working on this project again and made a bit of progress, If I have the Get_data part set correctly to receive the 14 bytes and  I now have it displaying the - sign is I reverse the meter and + sign is correct way round, But the bit I don't understand is how to create the look up or down table to extract and print the first digit, the second,third and 4th I will need to add but it should be just a repeat of the first loop. At the moment I have an input voltage of 3.816 volts,
How do I extract the 3 out of first bytes 1&2 for the first digit ?
I know that the four digits begin at offsets 1, 3, 5 and 7 (sequences 0x2, 0x4, 0x6 and 0x8) within the frame.

The negative sign is encoded in the high bit of the first digit, and the decimal points are encoded in the high bits of the other three digits.

Here if the latest code
Code: [Select]
byte DMM_ARRAY[14];   // Where to store the Bytes read
int ledPin = 13;  // Set the pin to digital I/O
int index = 0;
byte c;
byte TEMP1;
byte LOOKDOWN[7];
char  temp2;
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x03f, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

void setup()
{
  lcd.begin (20, 4); // for 16 x 2 LCD module
  lcd.setBacklight(HIGH);
  pinMode(ledPin, OUTPUT);
  Serial.begin(2400);

}
void loop() {
  Get_data();
  //print the hex bytes to the display
  lcd.setCursor(0, 0);
  lcd.print(DMM_ARRAY[0], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[1], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[2], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[3], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[4], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[5], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[6], HEX);
  lcd.print(",");
  lcd.setCursor(0, 1);
  lcd.print(DMM_ARRAY[7], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[8], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[9], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[10], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[11], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[12], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[13], HEX);

  //'BYTES 1&2 FOR THE FIRST DIGIT AND PRINTS THE NEGATIVE SIGN
  //        For LOOP1 = 1 To 7 Step 2
  for (int LOOP1 = 1; LOOP1 <= 7; LOOP1 += 2) {
    TEMP1 = (DMM_ARRAY[1] << 4) | DMM_ARRAY[2] & 0x0F;
    //        If TEMP1.7 = 1 Then
    if (TEMP1 & 0x80) {
      lcd.setCursor(3, 3);
      lcd.print("-"); //print - just to show it working
      //        Clear TEMP1.7 ' CLEAR THE MSB.
      TEMP1 &= 0x80;
      //    Else Print At 2,1," "'Print $FE, $C0, " " 'PRINT BLANK SAPCE IF CORRECT
    } else {
      lcd.setCursor(3, 3);
      lcd.print("+"); //print + just to show it working
      //        EndIf
    }

    for (int i = 0; i < sizeof LOOKDOWN; i++) {
      if (LOOKDOWN[i] == TEMP1) {
        TEMP1 = i;
        //temp2[] ={ 0x7D, 0x05, 0x5B, 0x1F, 0x27, 0x3E, 0x7E, 0x15, 0x7F, 0x3F, 0 };
        break;
      }
    }
  }
}


void  Get_data() {
  while (Serial.available() < 14) {} // Wait 'till there are 14 Bytes waiting
  for (int n = 0; n < 14; n++)
    DMM_ARRAY[n] = Serial.read(); // Then: Get them.


}


with an input voltage of 3.816 volts the LCD displays
DMM_ARRARY 0,1,2,3,4,5,6,7 on the first line
15,29,3F,4F,5F,60,75
DMM_ARRARY 8,9,10,11,12,13,14 on the second line
83,9E,A0,B0,C0,D4,E8




johnwasser

Code: [Select]
const byte Segments[] = {0x7D, 0x05, 0x5B, 0x1F, 0x27, 0x3E, 0x7E, 0x15, 0x7F, 0x3F, 0x00, 0x68};
const char Digits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ' ', 'L'};

const char getDigit(const byte segments) {
   for (int i = 0; i < sizeof Segments / sizeof Segments[0]; i++) {
      if (Segments[i] == segments)
         return Digits[i];
    }
  return '?';
}
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

Steveiboy

Thanks for your time and help, I will try that and see how I get on. Looks good

Steve

Steveiboy

John How do I call the function to return the value so I could print it
If I use  DIGIT1 = getDigit(); I get too few arguments to function 'const char getDigit(byte)'
It's not like calling a function I guess but tried to read up on it but they are just all normal functions calls, This bit is new to me
Code attached
Code: [Select]
byte DMM_ARRAY[14];   // Where to store the Bytes read
int ledPin = 13;  // Set the pin to digital I/O
int index = 0;
byte c;
byte TEMP1;
byte TEMP2;
byte TEMP3;
byte TEMP4;
byte DIGIT1;
byte LOOKDOWN1[7];
byte LOOKDOWN2[7];
byte LOOKDOWN3[7];
byte LOOKDOWN4[7];
boolean STORED1 ;
boolean STORED2 = 1;
boolean STORED3 = 0;
boolean STORED4 = 0;
int F_SELECT ;
char  temp2;
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x03f, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
const byte Segments[] = {0x7D, 0x05, 0x5B, 0x1F, 0x27, 0x3E, 0x7E, 0x15, 0x7F, 0x3F, 0x00, 0x68};
const char Digits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ' ', 'L'};

void setup()
{
  lcd.begin (20, 4); // for 16 x 2 LCD module
  lcd.setBacklight(HIGH);
  pinMode(ledPin, OUTPUT);
  Serial.begin(2400);

}
void loop() {
  Get_data();
  //print the hex bytes to the display
  lcd.setCursor(0, 0);
  lcd.print(DMM_ARRAY[0], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[1], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[2], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[3], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[4], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[5], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[6], HEX);
  lcd.setCursor(0, 1);
  lcd.print(DMM_ARRAY[7], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[8], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[9], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[10], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[11], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[12], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[13], HEX);

  //'BYTES 1&2 FOR THE FIRST DIGIT AND PRINTS THE NEGATIVE SIGN
  for (int LOOP1 = 1; LOOP1 <= 7; LOOP1 += 2) {
    TEMP1 = (DMM_ARRAY[1] << 4) | DMM_ARRAY[2] & 0x0F;
    if (TEMP1 & 0x80) {
      lcd.setCursor(3, 3);
      lcd.print("-"); //print - just to show it working
      TEMP1 &= 0x7F;;
    } else {
      lcd.setCursor(3, 3);
      lcd.print("+"); //print + just to show it working
    }
    for (int i = 0; i < sizeof LOOKDOWN1; i++) {
      if (LOOKDOWN1[i] == TEMP1) {
        TEMP1 = i;
        //temp2[] ={ 0x7D, 0x05, 0x5B, 0x1F, 0x27, 0x3E, 0x7E, 0x15, 0x7F, 0x3F, 0 };
        break;
      }
    }
  }
  //'BYTES 3&4 FOR THE FIRST DIGIT AND PRINTS THE NEGATIVE SIGN
  for (int LOOP2 = 1; LOOP2 <= 7; LOOP2 += 2) {
    TEMP2 = (DMM_ARRAY[3] << 4) | DMM_ARRAY[4] & 0x0F;
    F_SELECT = 0;
    TEMP2 &= 0x7F;
    for (int l2 = 0; l2 < sizeof LOOKDOWN2; l2++) {
      if (LOOKDOWN2[l2] == TEMP2) {
        getDigit();
        //temp2[] ={ 0x7D, 0x05, 0x5B, 0x1F, 0x27, 0x3E, 0x7E, 0x15, 0x7F, 0x3F, 0 };
        break;
      }
    }

  }
  //'BYTES 5&6 FOR THE FIRST DIGIT AND PRINTS THE NEGATIVE SIGN
  for (int LOOP3 = 1; LOOP3 <= 7; LOOP3 += 2) {
    TEMP3 = (DMM_ARRAY[5] << 4) | DMM_ARRAY[6] & 0x0F;
    F_SELECT = 1;
    TEMP3 &= 0x7F;
    /*        for (int l3 = 0; l3 < sizeof LOOKDOWN3; l3++) {
         if (LOOKDOWN3[l3] == TEMP3) {

          //temp2[] ={ 0x7D, 0x05, 0x5B, 0x1F, 0x27, 0x3E, 0x7E, 0x15, 0x7F, 0x3F, 0 };
           break;
         }
      }
    */
  }
  //'BYTES 7&8 FOR THE FIRST DIGIT AND PRINTS THE NEGATIVE SIGN
  for (int LOOP4 = 1; LOOP4 <= 7; LOOP4 += 2) {
    TEMP4 = (DMM_ARRAY[7] << 4) | DMM_ARRAY[8] & 0x0F;
    F_SELECT = 2;
    TEMP4 &= 0x7F;
    /*    for (int l4 = 0; l4 < sizeof LOOKDOWN4; l4++) {
        if (LOOKDOWN4[l4] == TEMP4) {

         //temp2[] ={ 0x7D, 0x05, 0x5B, 0x1F, 0x27, 0x3E, 0x7E, 0x15, 0x7F, 0x3F, 0 };
          break;
        }
      }
    */
  }
  switch (F_SELECT) {
    case 0:
      lcd.setCursor(10, 3);
      lcd.print("CASE 1");
      break;
    case 1:
      lcd.setCursor(10, 3);
      lcd.print("CASE 2");
      break;
    case 2:
      lcd.setCursor(10, 3);
      lcd.print("CASE 3");
      break;
  }

  lcd.setCursor(0, 2);
  lcd.print(TEMP2);
  lcd.print(",");
  lcd.print(TEMP3);
  lcd.print(",");
  lcd.print("f");

}


void  Get_data() {
  while (Serial.available() < 14) {} // Wait 'till there are 14 Bytes waiting
  for (int n = 0; n < 14; n++)
    DMM_ARRAY[n] = Serial.read(); // Then: Get them.


}


const char getDigit(const byte segments) {
  for (int i = 0; i < sizeof Segments / sizeof Segments[0]; i++) {
    if (Segments[i] == segments)
      return Digits[i];
  }
  return '?';
}


Thanks
Steve

johnwasser

I think you want something like this:
Code: [Select]
#include <LiquidCrystal_I2C.h>
#include <Wire.h>

LiquidCrystal_I2C lcd(0x03f, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
//LiquidCrystal_I2C lcd(0x03f, 20, 4);  // Set the LCD address, columns, and rows

byte DMM_ARRAY[14];   // Where to store the Bytes read
const int ledPin = 13;  // Set the pin to digital I/O

const byte Segments[] = {0x7D, 0x05, 0x5B, 0x1F, 0x27, 0x3E, 0x7E, 0x15, 0x7F, 0x3F, 0x00, 0x68};
const char Digits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ' ', 'L'};

void setup() {
  lcd.begin (20, 4); // for 16 x 2 LCD module
  lcd.setBacklight(HIGH);
  pinMode(ledPin, OUTPUT);
  Serial.begin(2400);
}

void loop() {
  Get_data();
  //print the hex bytes to the display
  lcd.setCursor(0, 0);
  lcd.print(DMM_ARRAY[0], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[1], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[2], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[3], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[4], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[5], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[6], HEX);
  lcd.setCursor(0, 1);
  lcd.print(DMM_ARRAY[7], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[8], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[9], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[10], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[11], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[12], HEX);
  lcd.print(",");
  lcd.print(DMM_ARRAY[13], HEX);

  // Process two bytes for each of four digits, starting at offset 1
  lcd.setCursor(3, 3);
  for (int index = 0; index < 4; index += 2) {
    byte segments = (DMM_ARRAY[index*2+1] << 4) | DMM_ARRAY[index*2+2] & 0x0F;
    if (segments & 0x80) {  // Negative/Decimal flag set
      if (index == 0)
        lcd.print("-"); // Negative flag
      else
        lcd.print("+"); // Decimal flag
    }
    lcd.print(getDigit(segments & 0x7F));
  }
}


void  Get_data() {
  while (Serial.available() < 14) {} // Wait 'till there are 14 Bytes waiting
  for (int n = 0; n < 14; n++)
    DMM_ARRAY[n] = Serial.read(); // Then: Get them.
}


char getDigit(const byte segments) {
  for (byte i = 0; i < sizeof Segments / sizeof Segments[0]; i++) {
    if (Segments[i] == segments)
      return Digits[i];
  }
  return '?';
}
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

Steveiboy

Once again John thanks for the info and excellent piece of code. This has been a massive help and I've made great progress with it, I now have it displaying all digits correctly had to make some minor changes and added some code for debugging. I just need to sort out the part so that it displays the mode its in which I'm working my way through bit by bit.
One thing I noticed which I will look into when I first turn the meter I get ? On some of the digits but when I press the reset button on the Uno it all works perfect. I think it's something to do with while serial available loop when the meter is off nothing displays on the LCD I know this is because it is not receiving any data. I will read up and search how to exit the while loop when no data is been received

Thanks for your help
Steve

johnwasser

One problem is that you are grabbing 14 characters and assuming that is one complete message.  If the first character you read is not 0x1_  then the whole message will be wrong.  You should check the top half of each byte and throw away any bytes that don't fit the pattern.

Code: [Select]
void  Get_data() {
  int n = 0;
  while (n < 14) {
    if (Serial.available()) {
      byte c = Serial.read();
      if (c >> 4 == n + 1)
        DMM_ARRAY[n++] = c;  // Fits the pattern
      else
        n = 0; // Try again from the beginning
    }
  }
}
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

Steveiboy

Thank John that's cured the error I was getting when I first turn the meter on, now working my way through the rest now will update soon

Steve

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy