I'm new to the Arduino and I am having problems passing an array to a function to print to a 4D uLCD-320PMD2 screen using a Picaso graphics controller.
This code prints an array of characters successfully:
void setup() {
Serial.begin(9600); //open serial port at 9600 bps
Serial.print(0x55,BYTE); //initialize LCD
char str[]="abctest";
int i = 0;
Serial.print(0x53,BYTE); //print string cmd
Serial.print(0x05,BYTE); //x coord
Serial.print(0x00,BYTE); //y1 coord
Serial.print(0x05,BYTE); //y2 coord
Serial.print(0x00,BYTE); //font
Serial.print(0x0f,BYTE); //color
Serial.print(0xff,BYTE); //color
Serial.print(0x02,BYTE); //width
Serial.print(0x02,BYTE); //height
while(str[i]!='\0')
{
Serial.print(str[i],BYTE); //print each array element until '\0'
i++;
}
Serial.print(0x00,BYTE); //Terminator
}
What "void printstring(char* str)" does is declare the function as having an argument thru which you are passing a pointer. Basically, a pointer is nothing more than an address which "points" to the memory where the array begins.
That's the basics; I won't go into pointer math, etc - when pointers are involved, things get complicated quickly if you aren't careful (even if you know what you are doing!)...
I feel like it isn't keeping the actual character elements in the new array.
What new array?
The serial monitor output shows that the pointer to the array is being passed to the function, and that the function has access to the pointed-to memory locations.
Well it looks like it prints the correct data to the serial console but this text is not showing up on the LCD as it does for the code without the function.
I don't see any code for the LCD, so you must be just unplugging the computer and plugging in the LCD on TX/RX?
I can't see a difference timing wise... and if the console displays the same characters with the printstring() function or without, and at the same baud rate, it should work with your LCD.
If you have an oscilloscope available, check the delays between all of the bytes sent, and zoom in on each byte and see if they are identical.
Since that's a lot of work, can you post the complete code listing for both versions... and can you retest the non-function version to make sure it still works?
I figured it out! Thanks for the help. The issue was that I was not allowing a long enough delay after a command to change the background so the LCD was never receiving the bytes telling it to print the array!