Success! Thanks to 4DSysFan at
http://4d.websitetoolbox.com/post/Converting-from-SGC-to-GFX-5858304, I now have an integer variable on the uVGA-II (result) that contains the same data as the integer variable on the Arduino (num). The print statements to the serial port had to be modified again, as the uVGA-II is looking for a $ as a start of packet, and a CR as the end of the packet:
Serial3.print("$");
Serial3.println(num, DEC);
Arduino sketch:
int req = 5; //mic REQ line goes to pin 5 through q1 (arduino high pulls request line low)
int dat = 2; //mic Data line goes to pin 2
int clk = 3; //mic Clock line goes to pin 3
int i = 0; int j = 0; int k = 0;
byte mydata[14];
int num;
void setup(){
Serial3.begin(9600);
Serial.begin(9600);
pinMode(req, OUTPUT);
pinMode(clk, INPUT);
pinMode(dat, INPUT);
digitalWrite(clk, HIGH); // enable internal pull ups
digitalWrite(dat, HIGH); // enable internal pull ups
digitalWrite(req,LOW); // set request at LOW
}
void loop(){
// get data from mic
digitalWrite(req, HIGH); // generate set request
for( i = 0; i < 13; i++ ) {
k = 0;
for (j = 0; j < 4; j++) {
while( digitalRead(clk) == LOW) { } // hold until clock is high
while( digitalRead(clk) == HIGH) { } // hold until clock is low
bitWrite(k, j, (digitalRead(dat) & 0x1)); // read data bits, and reverse order )
}
// extract data
mydata[i] = k;
// sign = mydata[4];
// decimal = mydata[11];
// units = mydata[12];
}
// assemble measurement from bytes
char buf[7];
for(int lp=0;lp<6;lp++)
buf[lp]=mydata[lp+5]+'0';
buf[6]=0;
num=atol(buf); //assembled measurement, no decimal place added
Serial3.print("$");
Serial3.println(num, DEC);
digitalWrite(req,LOW);
// delay(25);
}
uVGA-II 4DGL Code:
#platform "uVGA-II_GFX2"
// Micrometer GFX
#inherit "4DGL_16bitColours.fnc"
func main()
var comvar;
var result;
gfx_Cls();
txt_Set(FONT_SIZE, FONT2);
gfx_Rectangle(75,75,150,120,WHITE);
//print("Com test");
//com_SetBaud(COM0,960);
//to(COM0); print("serial input test:\n");
repeat
comvar := serin1();
if(comvar == '$')
//gfx_Cls();
//print("$");
result :=0;
endif
if(lookup8(comvar,"0123456789"))
result:=(result*10)+(comvar-'0');
//print("\n Char:",comvar);
endif
if(comvar ==13)
txt_MoveCursor(12,10);
print(result," ");
endif
forever
endfunc