I have this CLCD display module from COMFILE Technology which uses I2C for communication. The basic idea is for my Arduino Pro Mini to send some Data to the LCD display. Some example codes are already available in the Arduino programming environment but it is not compatible with the module. COMFILE provide little information about the module but I managed to come up with this code and be able to send some data successfully. I now can send characters to the LCD module as well as number. My challenge was to turn numerical values into text. Sending numerical values such as int or float would result in incomprehensible gibberish. Thanks to the function itoa() I now can send those numbers as text and can read a text such as "My Text is" and "567" and it works quite well.
The end goal is to be able to utilize my LCD module to read some variable length numbers such as 1 or 76 or 876538. The problem I have is I can’t figure out how to pass a numerical value to a function().
So far I tried to implement the String() function with no success. C++ is a bit of a learning curve for me. I have more experience with Visual Basic.
The following code is working
itoa ( x , TheNumber , 10 ) ; // x is a float() number
Wire.beginTransmission(ADrss ) ; // Start transmit to LCD screen
Wire.write ( "Line of Text" ) ; // send message
Wire.write ( TheNumber ) ; // send the x number as a text
Wire.endTransmission ( ) ; // stop transmitting
This code is Not working:
void LCDtext( String(TheText) ) {
Wire.beginTransmission(ADrss) ;
Wire.write ( TheText ) ;
Wire.endTransmission ( ) ; }
I am unable to come up with a working Function() to do the job.
I am trying to implement a “Function( MyText)” that will send the text to the LCD.
Same for numbers. When passing those values to the LCDtext() function or LCDnumber()
the compiler choke: error
“ (Send_I2C:39:31: error: no matching function for call to 'TwoWire::write(String&)' Wire.write ( TheText ) ”
My suspicion is that the I2C Arduino routine does not accept a String() as input.
I need to pass a char() type text but the length has to be dynamic.
Not sure how to implement that.
The complete code is here:
#include <Wire.h>
#include <string.h>
void setup() {
pinMode(LED_BUILTIN, OUTPUT) ;
Wire.begin() ; } // join i2c bus
bool BrdLED = 0 ;
float x = 0 ;
int ADrss = 0x00 ;
char TheNumber[9] ;
String MyText = String("0123456789ABCDEF");
void loop() {
x++;
itoa ( x , TheNumber , 10 ) ;
if (x/2 == int(x/2) ) {
LCDrow1234(1) ; }
else {
LCDrow1234(2) ; }
String MyText = String( "Text: ") ;
LCDtext(MyText); // this function call not working
LCDnumber(x); // this function call not working
Wire.beginTransmission(ADrss ) ; // Start transmit to LCD screen
Wire.write ( "Line of Text" ) ; // send message
Wire.write ( TheNumber ) ; // send one byte
Wire.endTransmission ( ) ; // stop transmitting
delay(200) ;
FlashLED() ;
}
void LCDtext( String(TheText) ) {
Wire.write ( TheText ) ;
Wire.endTransmission ( ) ; } // stop transmitting
void LCDnumber( char n[9] ) {
char TheString [ 9 ] ;
itoa ( n , TheString , 10 ) ;
Wire.beginTransmission ( ADrss ) ;
Wire.write ( TheString ) ;
Wire.endTransmission ( ) ; }
void LCDclear() {
delay(100);
Wire.beginTransmission(ADrss);
Wire.write(" ClearLCD ");
Wire.write(0x1B);
Wire.write(0x43);
Wire.endTransmission( );
delay(20);
}
void LCDcursor ( bool ONOFF ) {
Wire.beginTransmission( ADrss ) ;
Wire.write ( 0x1B ) ;
if ( ONOFF == true ) {
Wire.write( 0x53 ) ; }
else {
Wire.write( 0x73 ) ; }
Wire.endTransmission ( ) ;
delay(20);
}
void LCDbacklight ( bool ONOFF ) {
Wire.beginTransmission( ADrss ) ;
Wire.write ( 0x1B ) ;
if ( ONOFF == true ) {
Wire.write( 0x42 ) ; }
else {
Wire.write( 0x62 ) ; }
Wire.endTransmission ( ) ;
delay(20);
}
void LCDhome ( void ) {
Wire.beginTransmission( ADrss ) ;
Wire.write ( 0x1B ) ;
Wire.write( 0x48 ) ; // Bring Cursor Home
Wire.endTransmission ( ) ;
delay(20);
}
void LCDlocate ( byte XX , byte YY ) {
Wire.beginTransmission( ADrss ) ;
Wire.write ( 0x1B ) ;
Wire.write ( 0x4C ) ;
Wire.write ( XX ) ; // X coordinate
Wire.write ( YY ) ; // Y coordinate
Wire.endTransmission ( ) ;
delay(120);
}
void LCDuser ( char B8[7] ) {
Wire.beginTransmission( ADrss ) ;
Wire.write ( 0x1B ) ;
Wire.write ( 0x44 ) ;
Wire.write ( B8 ) ; // This is 8bytes string containing the custom character
Wire.endTransmission ( ) ;
delay(20);
}
void LCDrow1234 ( byte row ) { // row 0x01 to go to Row 1
Wire.beginTransmission( ADrss ) ; // row 0x02 to go to Row 2
Wire.write ( row ) ; // row 0x03 to go to Row 3
Wire.endTransmission ( ) ; // row 0x04 to go to Row 4
delay(20); } // NO row 5 available
void LCDzero() {
delay(100);
Wire.beginTransmission(ADrss);
Wire.write(" LCDzero ");
Wire.write(0x1B);
Wire.write(0x48);
Wire.endTransmission(); // stop transmitting
delay(20);
}
void FlashLED( ) {
BrdLED = !BrdLED; // This funciton will flash the OnBoard LED
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on
delay(200);
digitalWrite(LED_BUILTIN, LOW); // turn the LED off
delay(1000); }