kpetrinak 0 Posted April 2, 2016 Share Posted April 2, 2016 I have a Spikenzie Labs LCD screen with an interface (screen utilizes the HD44780 chipset). I have it connected to an MSP-EXP432P401R (Rev 1.0). I have finally got code working that allows me to write to the LCD screen through the serial monitor, however I can only write to the screen for a short but varying amount of time. Sometimes I can print to the screen for 5 seconds, sometimes only for 1 second before communication cuts out. Here is the code I am using: #include <Wire.h> #include <LiquidCrystal.h> #define addr 0x40 >> 1 void setup() { Wire.begin(); Serial.begin(9600); } void loop() { Wire.beginTransmission(addr); Wire.write(Serial.read()); Wire.endTransmission(); } My connections are as follows: LCD screen -> MSP432 VCC -> 5V GND -> GND SDA -> pin 10 SCL -> pin 9 I have also tried using a level shifting circuit on the data lines with no effect. Does anyone know what's going on and what I can do to fix this? Thank you Quote Link to post Share on other sites
chicken 630 Posted April 3, 2016 Share Posted April 3, 2016 There might be a timeout at play. Did you try to read the character outside the Wire calls? I.e. Read character Start transmission Write character End transmission Quote Link to post Share on other sites
chicken 630 Posted April 3, 2016 Share Posted April 3, 2016 I just checked documentation on Energia.nu and it looks like Serial.read does return -1 if there's no input. With that, you also should add a if(character != -1) around the I2C commands. tripwire 1 Quote Link to post Share on other sites
energia 485 Posted April 3, 2016 Share Posted April 3, 2016 @@chicken is right, you should check if there is a character available otherwise it will write -1 to the LCD screen at a very fast pace and hence it might appear that things are not working. I would suggest the following: #include <Wire.h> #include <LiquidCrystal.h> #define addr 0x40 >> 1 void setup() { Wire.begin(); Serial.begin(9600); } void loop() { if(Serial.available()) { Wire.beginTransmission(addr); Wire.write(Serial.read()); Wire.endTransmission(); } } Quote Link to post Share on other sites
kpetrinak 0 Posted April 3, 2016 Author Share Posted April 3, 2016 Thanks for the replies! I used the code suggested by @@energia, it seems to work a little longer but still cuts out after a variable amount of time! Every time I upload the code it works for about 5 seconds. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.