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!")
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)
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
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
Arduino communicates with the MAX3421E using the SPI bus (through the ICSP header). This is on digital pins 10, 11, 12, and 13 on the Uno and pins 10, 50, 51, and 52 on the Mega. On both boards, pin 10 is used to select the MAX3421E. Pins 7, 8 and 9 are used for GPX, INT and RES 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
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
I bought this https://www.ebay.it/itm/322167092482
Which would be the same as my display with the addition of the i2C module. So I should be able to use it with only 4 pins.
Hoping to solve 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:
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.
}