I want to preface this by saying I don't want to be the lazy guy that posts his code and lets others solve its issues without doing some research. That said, I've read most of the threads where people are trying to do what I'm doing.
What am I trying to do: Take a sensor measurement on an arduino, send it to a goldelox display module (using a Visi setup), and display the data on a round gauge.
So, I used and adapted code from these posts:
http://forum.4dsystems.com.au/forum/...cd-70-dt/page2
and http://old.4dsystems.com.au/code/ind...?node=10&id=28
and especially this one: http://forum.4dsystems.com.au/forum/...l-uoled-160-g2
All the bit shifting and Hex using reminds me of CS classes I took a long time ago, but it makes sense for the most part.
With the code below I can plug the arduino into the computer, send it the "ACK" of '!' or '21' in HEX from the terminal and get back a random number in the format I want (Bhexhex). It works repeatedly, etc. I can also plug in the display module to the computer and in the terminal and send it the same sequence and get back an ack and have a measurement show up on the gauge. However, with the display module plugged in to the arduino I get nothing.
So, what's that one small silly thing that I'm missing.
Arduino code:
4DGL code
What am I trying to do: Take a sensor measurement on an arduino, send it to a goldelox display module (using a Visi setup), and display the data on a round gauge.
So, I used and adapted code from these posts:
http://forum.4dsystems.com.au/forum/...cd-70-dt/page2
and http://old.4dsystems.com.au/code/ind...?node=10&id=28
and especially this one: http://forum.4dsystems.com.au/forum/...l-uoled-160-g2
All the bit shifting and Hex using reminds me of CS classes I took a long time ago, but it makes sense for the most part.
With the code below I can plug the arduino into the computer, send it the "ACK" of '!' or '21' in HEX from the terminal and get back a random number in the format I want (Bhexhex). It works repeatedly, etc. I can also plug in the display module to the computer and in the terminal and send it the same sequence and get back an ack and have a measurement show up on the gauge. However, with the display module plugged in to the arduino I get nothing.
So, what's that one small silly thing that I'm missing.
Arduino code:
Code:
#define DisplaySerial Serial void setup() { DisplaySerial.begin(9600); //delay(10000); } void loop() { //DisplaySerial.flush(); while(!DisplaySerial.available()) ; if (DisplaySerial.read() == '!'){ int iBoost = getBoost(); DisplaySerial.print('B', HEX); DisplaySerial.print(0,HEX); DisplaySerial.print(0,HEX); if (iBoost < 16){ DisplaySerial.print(0,HEX);} DisplaySerial.print(iBoost, HEX); DisplaySerial.flush(); } } int getBoost(){ return random(0,17); }
Code:
#platform "GOLDELOX" // Program Skeleton 1.0 generated 1/28/2016 9:13:29 PM #inherit "4DGL_16bitColours.fnc" #inherit "VisualConst.inc" #inherit "gaugepagesConst.inc" var buf[4]; func main() var numx; var page; setbaud(BAUD_9600); com_Init(buf,8,0); print("Starting\n") ; //check for SD card...repeat forever while(!media_Init()) putstr("Missing SD Card!"); pause(200); gfx_Cls(); pause(200); wend //sweep the gauge media_SetAdd(iAngularmeter1H, iAngularmeter1L); var i; repeat i := i + 2; media_VideoFrame(0,0,i); until (i >= 45); repeat i := i - 2; media_VideoFrame(0,0,i); until (i <= 0); media_VideoFrame(0,0,0); var cmd; serout('!'); repeat if (com_Count() >= 3) print([STR]buf); //debug print of a string of the buffer (should print 'B' and nothing else) print("\n"); serout('!'); //ACK to the arduino saying it can take more data cmd := serin(); if (cmd == 'B') numx := serin() << 8 | serin(); //if you input 420015 (which is hex for Bnullnull21) you get an output of 21) pause (5000); com_Init(buf,8,0); //reset the buffer endif endif //instead sit and wait for serial input from the arduino //numx := ABS (RAND() % 1000); //then the next 4 bytes are the float //scale the float to the dial positions // Angularmeter1 1.0 generated 1/29/2016 9:40:30 PM media_SetAdd(iAngularmeter1H, iAngularmeter1L) ; // point to the Angularmeter1 image media_VideoFrame(0, 0, numx) ; // where numx is 0 to 45 (for a displayed -15 to 30) forever endfunc
Comment