Bluz DK with Serial LCD


#1

Hey Everyone,

Has anyone gotten an LCD to work with Bluz? I’m using a Newhaven 0220D3Z which is 5v and i’m thinking it could be that the logic level from the RX (serial1) is 3.3v? Would a logic level converter fix that?

I’m not getting much of any displaying to work. It seems to send erroneous characters sometimes.


#2

Is the display working at all? Or do you get nothing on the screen?

How are you powering the screen? Are the GND lines of the display and bluz hooked together?

A level shifter would be the best way, but it may work without it. It depends if the display registers 3V3 as HIGH, which it could do. How do you have the two wired together?


#3

It’s able to write text, but functions like clearscreen are not working. All the lines are correct, and the RX is connected to the TX pin.

This test code is basically printing “Line 1!” one after the other and wrapping the text, instead of clearing the screen each time.

//newhaven NHD-0220D3Z-NSW-BBW-V3 commands
byte program = 0xFE;
byte displayOn = 0x41;
byte displayOff = 0x42;
byte cursorPos = 0x45; //1 Byte Set
byte cursorHome = 0x46;
byte underlineOn = 0x47;
byte underlineOff= 0x48;
byte cursorLeft = 0x49;
byte cursorRight = 0x4A;
byte blinkingOn = 0x4B;
byte blinkingOff = 0x4C;
byte backspace = 0xFE;
byte clearScreen = 0x51;
byte setContrast = 0x52;//1 byte set
byte setBrightness = 0x53; //1 byte set
byte custom = 0x54;
byte displayLeft = 0x55;
byte displayRight = 0x56;
byte firmware = 0x70;
/*
0xFE 0x61 1 Byte Change RS‐232 BAUDrate 3mS
0xFE 0x62 1 Byte Change I2C address 3mS
0xFE 0x70 None Display firmware version number 4mS
0xFE 0x71 None Display RS‐232 BAUDrate 10mS
0xFE 0x72 None Display I2C address 4mS
*/



void setup() {
    Serial1.begin(9600);  
    delay(1000);
    lcdCommand(program,clearScreen);
    delay(500);
    blinkCursor(true);
    lcdCommand(program, cursorPos);
    Serial1.write(0x4C);
} //end void setup

void loop() {
    lcdCommand(program,clearScreen);
    delay(500);
    String line1 = "Line 1!";
    display(line1,1);
    delay(500);

}
int lcdCommand(byte address, int value){
    Serial1.write(address);//CORRECT syntax for lcd commands
    Serial1.write(value);
    delay(10);
}

void display(String text, int line) {
    if (line == 1) {
    	lcdCommand(program, cursorPos);
        Serial1.write(0x00);
        Serial1.print(text.substring(0,20));
    } else if (line == 2) {
        lcdCommand(program, cursorPos);
        Serial1.write(0x40);
        Serial1.print(text.substring(0,20));
    }
}

#4

Still having some trouble with this lcd. I’m using that exact code on both the Bluz and a Photon, and only the Print seems to work on the Bluz. It never clears. I measured the voltage out at TX on both, and they were both 3.3v. I tried to make a simple level shifter to 5v with a mosfet, but that didn’t work. Gave me gibberish from both.

Any ideas on why the lcdCommand seems not to work on just the Bluz dk?


#5

Sorry for the delay.

If it works on a Photon and not bluz, then it could be a timing issue or possibly something to do with the physical pins. The UART peripheral on bluz works in a FIFO fashion, so calling the write function doesn’t mean it instantly gets sent, there is a delay. I don’t know how sensitive the device is to timing, but you could try and add a delay in between the two write commands in the lcdCommand function. Or you could try putting the two values into a two byte array and writing that all at once. If it is something to do with timing of the commands being sent, then it will require some research or some tinkering (or maybe both)

It could also be that the display doesn’t see bluz as a valid UART device. That sounds less likely since you said it can pass data to write lines on the screen.

You are clearing the screen in the setup function, does that work? So if the screen is filled and you reboot bluz while keeping the display powered on, does the display clear?


#6

I just added some more delays and tried sending them as a two byte array and neither seemed to do anything. Looks like only the print functioon works. It doesn’t even clear the display after a reset, just keeps on printing “Line 1!”


#7

I don’t have the display to try, unfortunately, but it sounds like there must be some difference to what the Photon is doing. Is the clear command the only one that isn’t working? Short of looking at the signals with a logiz analyzer, it is hard to say what could be causing the issue


#8

Thanks for the reply Eric. I definitely appreciate the customer service.

It’s not just clear screen. It seems any actiion that uses the seperate function doesn’t work, while only .print works.

It says on the 2nd page of the data sheet (http://www.newhavendisplay.com/specs/NHD-0220D3Z-NSW-BBW-V3.pdf) under Function and Features “1/6 duty, 1/5 bias” Does this have anything to do with the problem? I’m not exactly sure what it means, but it seems like the datasheet doesn’t mention anything else remotely related to helping the problem.

Could I try a software serial library? Anything you know of that is different from the Photon that might give me a lead on how to figure this out?

I don’t have an oscilloscope (at least not handy) to look at the signals. My multimeter is showing 3.3v from both the Bluz and Photon. If it’s sending out the .print text, it wouldn’t seem like a level problem though?


#9

I will try and do a little research into this. I can measure the UART of bluz and the Photon. I have not seen any issues with other devices, so my guess is that for some reason it has to do with the voltage, but that is just a guess.

I also ordered one of these displays, so I can try it out when it comes in.


#10

That sounds great. Thanks for doing that! I’m going to keep messing with it, so I’ll let you know as well if anything comes of it!


#11

If you’ve gotten around to it yet, any luck getting yours to work?


#12

Mine just arrived this weekend, wasn’t around to try it yet but will get to it soon. Sorry for the delay


#13

Ok, I got a chance to try out the screen and could indeed reproduce the issue. I am not sure exactly what is going on yet, but by watching the UART output from bluz in CoolTerm I can see the bytes are coming out in the wrong order. This clearly seems to be a bug with the UART driver, I think it has to do with the multiple Serial1.write calls.

The good news is, I was able to fix it in the user app. So by consolidating multiple Serial1.write calls into one that writes a buffer, I can get the desired behavior. This is my modified code that works:

//newhaven NHD-0220D3Z-NSW-BBW-V3 commands
byte program = 0xFE;
byte displayOn = 0x41;
byte displayOff = 0x42;
byte cursorPos = 0x45; //1 Byte Set
byte cursorHome = 0x46;
byte underlineOn = 0x47;
byte underlineOff= 0x48;
byte cursorLeft = 0x49;
byte cursorRight = 0x4A;
byte blinkingOn = 0x4B;
byte blinkingOff = 0x4C;
byte backspace = 0xFE;
byte clearScreen = 0x51;
byte setContrast = 0x52;//1 byte set
byte setBrightness = 0x53; //1 byte set
byte custom = 0x54;
byte displayLeft = 0x55;
byte displayRight = 0x56;
byte firmware = 0x70;
/*
0xFE 0x61 1 Byte Change RS‐232 BAUDrate 3mS
0xFE 0x62 1 Byte Change I2C address 3mS
0xFE 0x70 None Display firmware version number 4mS
0xFE 0x71 None Display RS‐232 BAUDrate 10mS
0xFE 0x72 None Display I2C address 4mS
*/

void setup() {
    Serial1.begin(9600);  
    delay(1000);
    lcdCommand(program,clearScreen);
    delay(500);
    lcdCommand(program, cursorPos);
    Serial1.write(0x4C);
} //end void setup

void loop() {
    lcdCommand(program,clearScreen);
    delay(500);
    String line1 = "Line 1!";
    display(line1,1);
    delay(500);

}

void display(String text, int line) {
    if (line == 1) {
    	lcdCommand(program, cursorPos, 0x00);
        delay(50);
        Serial1.print(text.substring(0,text.length()));
    } else if (line == 2) {
        lcdCommand(program, cursorPos, 0x40);
        Serial1.print(text.substring(0,text.length()));
    }
}

int lcdCommand(byte address, byte value){
    uint8_t arr[2] = {address, value};
    Serial1.write(arr, 2);//CORRECT syntax for lcd commands
    delay(10);
}

int lcdCommand(byte address, byte value, byte arg){
    uint8_t arr[3] = {address, value, arg};
    Serial1.write(arr, 3);//CORRECT syntax for lcd commands
    delay(10);
}

I am opening an issue on this and will investigate it further for the next release. In the meantime, consolidating many Serial1.write commands into one command that writes a buffer seems to fix the issue, if anyone else runs across a similar problem.


#14

This is great. Thank you very much Eric! I was able to get the full code I had written for the Photon to work.

That’s interesting why it won’t woork on the Bluz though. Keep me updated if the issue get’s solved. Thanks!


#15

Did you happen to try the code I posted above? Would be great to verify it fully works for you, it should work on the Photon and bluz.


#16

Yep that code seems to work. However, the setup function needs to have the cursorPos consolidated. (when it writes 0x4C)