Hi Guys, I have a HMC5883L Compass connected to an arduino UNO. When I open the serial monitor I get the heading in degrees which is what I want. I no want to send the heading to an lcd display.
I have also connected the Lcd to the UNO and displayed the word HELLO WORLD as stock which prints onto the screen so i know the Lcd is hooked up correctly.
THE PROBLEM
I have tried to merge the 2 codes together, which i have pasted below. I cant seem to get the Lcd to display the heading. Has anyone got any pointers.
If your HELLO WORLD has the command lcd.write, I'm wrong, but I think the real problem might be that you are sayng "lcd.write" where you should be saying "lcd.print". If you change all the writes to print, it might work.
You need to access the data to send to the lcd the same way you get it for the serial.I believe Serial.read is for reading data/characters from the computer, not the arduino. Maybe
robtillaart:
lcd.write will only send one byte to the lcd, it is the basic mechanism
Actually, this is incorrect.
the write() function is overloaded.
There are 3 versions of write()
write(unsigned char) outputs a single byte.
write(const char * str) which is assumed to be a pointer to a C string
so the function will output all the characters in the in the C string pointed to by the pointer.
write(const uint8_t *buffer, size_t size) which outputs the specified number of bytes
starting at the buffer pointer.
The standard LiquidCrystal library (which appears to be what is being used) supports
printing floats.
It isn't clear what the intent of this code is and it
looks like it may not do what is probably expected:
void Output(float headingDegrees)
{
Serial.print(headingDegrees);
Serial.println(" Degrees \t");
delay(900);
lcd.write(Serial.read());
}
It prints some information on the serial port then
after waiting 900ms (just less than 1 second), it will then call Serial.read() to read a single character
from serial port buffer.
The read() function returns either 1 single character from the UART/Serial buffer or -1 if no characters are in the buffer.
Serial.read() is not blocking i.e. it will not wait for input. It will immediately return with either a single character from
the RX buffer or a -1 if none are available.
If no character is available the -1 or 0xffff will be passed to lcd.write(), lcd.write() is only looking
at the lower 8 bits so it will end up sending a 0xff to the LCD. A 0xff on many hd44780 displays
will be full block of pixels.
So this Output() function seems very strange to me.
It outputs some information to the serial port, then it tries to read a single character from the serial port.
If there is a character in the serial RX buffer, the character is pushed to the lcd, if there is no character
in the serial RX buffer, a 0xff is send to the lcd which on most lcds will be a full block of pixels.
I'm assuming this is not the desired behavior.