Lcd 16x2 and Usb.Init ()

Status
Not open for further replies.

mauros

Member
The Usb.init () instruction creates problems with LCD display 16x2, depending on where I place it. When Usb.init is not present, the lcd shows anything but if Usb.init () is present, it happens that if for example i write before <lcd.print >

lcd.print ("Hello World!")
if (Usb.Init() == -1)
{while(1);}

"Hello World!" it is displayed on lcd

but if i put <lcd.print > after

if (Usb.Init() == -1)
{while(1);}
lcd .print ("Hello World!")

the lcd does not display anything.

Thanks !!
 
if (Usb.Init() == -1)
{while(1);}
Whoops.... If USB == -1 then a forever loop... This is just the USB failing... Nothing wrong with the LCD code..

Try this
C:
if (Usb.Init() == -1)
   lcd .print ("USB not found!!");
else
     lcd .print ("USB up and running!!");
{while(1);}
 
I get that USB up and running. Being sure the USB was found, I tried to remove those two instructions and then it happens that the lcd display works but no longer runs the serial.

Edit:

I practically did not understand what those two instructions do
( I am replicating an existing project but i would like to modify it by adding the lcd display)
 
Last edited:
Because after the USB init you go into a while(1) loop.. Nothing else can happen..

Post the code!
 
An android app created with MIT Inventor sends text to Arduino that must display it on the lcd display. I insert the most significant part of the code since there are more than 400 lines
#include <LiquidCrystal.h>
#include <Usb.h>
#include <usbh_midi.h>
LiquidCrystal lcd(10, 9, 8, 7, 6, 5);

USB Usb;
USBH_MIDI Midi(&Usb);

String name;



void setup()
{
Serial.begin(115200); //start serial
lcd.begin(16, 2);


if (Usb.Init() == -1)
{while(1);}
}


void loop() {

if( Serial.available()) { //check for serial
char ch = Serial.read(); //serial message

if (ch == '~') { //song name starts after this

name = ""; //empty the variable
lcd.clear();

for (int i=0; i<99; i++) { //counter to make sure you don't get stuck in an infinite loop
char ch2 = Serial.read(); //read the serial, and store to ch2
if (ch2 == '^') //last character of the transmission, so break
break;
else //otherwise, add the character to the song name
name = name + ch2;

}

Serial.println(name);
lcd.print(name);

}
}
}


Edit:
Sorry I tried to insert the code independently of the message but I did not succeed
 
Given that various data flow through the serial, to understand when the "name" passes, the protocol provides a start character and one end that says when "name" is finished
 
To get an idea of the project, I replied what you see in the following video and i would like to add a display to show the title of the song sent from the tablet
 
Last edited by a moderator:
Okay!! Your USB shield will need pin 10 as does you LCD.. You'll need to use another pin on the LCD.
 
I did not think that pin 10 was used by the Usb Shield, I knew 11 and 12. The free digital pins I have are numbers 5,6,7,8,9,10,11,12,13. I tried with pin 13 and then with analog pin A5 defined as output (19) but the problem remains
 
 
Very restrictive No possibility under these conditions ?
It seems that making a change to the library <UsbCore.h> i can use another pin (?)
 
Last edited:
Which boards are shields?? USB and LCD... If the LCD isn't on a shield you can use any pins... The LCDint allows you to specify alternate pins.
 
Unfortunately, the LCD is connected to the USB shield which in turn is connected to Arduino. It could not be otherwise, except I did not understand what you mean

Have you a datasheet for this shield?? Is the LCD officially mounted to the USB shield or did you mount it??
 
Why don't you post a link to the USB module then I can see what you can do with the existing LCD..
Otherwise you are going to need a library for I2C LCD
 
I received the I2C LCD, I replaced the <LiquidCrystal.h> library with <LiquidCrystal_I2C.h> but in a simple writing test nothing appears on the display.
The LiquidCrystal_I2C.h library may also be inappropriate, as it sometimes happened to other users with some 16x2 LCD libraries. Under the code:


**********************************************************************++
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

Char array1 [] = "SunFounder"; // the string to print on the LCD
Char array2 [] = "hello, world!"; // the string to print on the LCD
Int tim = 500; // the value of delay time
// initialize the library with the numbers of the interface pins
LiquidCrystal_I2C lcd (0x27.16.2); // set the LCD address to 0x27 for a 16 chars and 2 line display
/ ************************************************* ******** /
Void setup ()
{
lcd.init (); // initialize the lcd
lcd.backlight (); // open the backlight
}
/ ************************************************* ******** /
Void loop ()
{
lcd.setCursor (15.0); // set the cursor to column 15, line 0
For (int positionCounter1 = 0; positionCounter1 <26; positionCounter1 ++)
{
lcd.scrollDisplayLeft (); // Scrolls the contents of the display one space to the left.
lcd.print (array1 [positionCounter1]); // Print a message to the LCD.
delay (tim); // wait for 250 microseconds
}
lcd.clear (); // Clears the LCD screen and positions the cursor in the upper left corner.
lcd.setCursor (15,1); // set the cursor to column 15, line 1
For (int positionCounter = 0; positionCounter <26; positionCounter ++)
{
lcd.scrollDisplayLeft (); // Scrolls the contents of the display one space to the left.
lcd.print (array2 [positionCounter]); // Print a message to the LCD.
delay (tim); // wait for 250 microseconds
}
lcd.clear (); // Clears the LCD screen and positions the cursor in the upper left corner.
}

************************************************************
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…