Hi guys,
So I am very new to Arduino and a beginner programmer at best. That said, I am having a similar problem nend in the original post.
My setup:
-Arduino Mega 2560
-LCD 4884
-I/O Expansion shield, for Serial-RS485 communication
-Displacement Laser, communicates of RS485
-SD Card Logger Shield
What I am trying to do:
-Send a command over RS485 to the Displacement Laser asking for a measurement, this is working already. Nine (9) characters and a carriage return.
Should (and does) look like this: %01#RMD**\r
-Receive the measurement (a character string) from the Displacement Laser, again over RS485, I am not sure if this is working yet. Seventeen (17) characters and a carriage return.
Should look something like this: %01$RMD-0142901**
-Display the measurement optimally as just a number and not the character string (I am willing to take baby steps) onto the LCD 4884.
On the screen it should look something like: -14.2901 mm or %01$RMD-0142901** would be acceptable
So far all the screen displays is: ~'
I know how to display text and a regular variable, but apparently its not the same as a serially read variable
-Write/append each new measurement value to a file on the SD card/Logger Shield. Have not yet gotten this far.
My Code (partly self written, partly from examples far-and-wide on the Internet, partly from this forum post (nend and olikraus), I am ignoring the SD card for the meantime:
int EN = 20; //RS485 TX/RX enable pin
int x = 0;
char string[10];
char inputStr = 0;
//Included files for LCD4884
#include "LCD4884.h"
void setup()
{
pinMode(EN, OUTPUT);
Serial1.begin(9600);
lcd.LCD_init(); // creates instance of LCD
lcd.LCD_clear(); // blanks the display
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
}
void loop()
{
// Enable Data Transfer
digitalWrite(EN, HIGH);
delay(16);
// Ask for Displacement over RS485 (Serial1)
Serial1.print("%01#RMD**\r");
delay(12);
// Enable Data Recieve
digitalWrite(EN, LOW);
delay(16);
// Recieve Value over RS485 (Serial)
inputStr = Serial1.read();
// Convert Serial1 Value
string[0] = inputStr;
string[1] = '\0';
delay(16);
// Display Serial1 Value on LCD4884
lcd.LCD_write_string(0,1,string,MENU_NORMAL);
delay(16);
}
Help is much appreciated!
-Glenn