1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Lcd 16x2 and Usb.Init ()

Discussion in 'AVR' started by mauros, Jun 18, 2017 at 8:17 AM.

  1. mauros

    mauros New Member

    Joined:
    Apr 25, 2017
    Messages:
    24
    Likes:
    0
    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 !!
     
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    8,857
    Likes:
    862
    Location:
    Rochdale UK
    ONLINE
    Whoops.... If USB == -1 then a forever loop... This is just the USB failing... Nothing wrong with the LCD code..

    Try this
    Code (c):

    if (Usb.Init() == -1)
       lcd .print ("USB not found!!");
    else
         lcd .print ("USB up and running!!");
    {while(1);}

     
     
  3. mauros

    mauros New Member

    Joined:
    Apr 25, 2017
    Messages:
    24
    Likes:
    0
    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: Jun 18, 2017 at 1:39 PM
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    8,857
    Likes:
    862
    Location:
    Rochdale UK
    ONLINE

    Because after the USB init you go into a while(1) loop.. Nothing else can happen..

    Post the code!
     
  6. mauros

    mauros New Member

    Joined:
    Apr 25, 2017
    Messages:
    24
    Likes:
    0
    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
     
  7. mauros

    mauros New Member

    Joined:
    Apr 25, 2017
    Messages:
    24
    Likes:
    0
    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
     
  8. mauros

    mauros New Member

    Joined:
    Apr 25, 2017
    Messages:
    24
    Likes:
    0
    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
     
  9. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    8,857
    Likes:
    862
    Location:
    Rochdale UK
    ONLINE
    Okay!! Your USB shield will need pin 10 as does you LCD.. You'll need to use another pin on the LCD.
     
  10. mauros

    mauros New Member

    Joined:
    Apr 25, 2017
    Messages:
    24
    Likes:
    0
    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
     
  11. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    8,857
    Likes:
    862
    Location:
    Rochdale UK
    ONLINE
     
  12. mauros

    mauros New Member

    Joined:
    Apr 25, 2017
    Messages:
    24
    Likes:
    0
    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: Jun 19, 2017 at 5:38 AM
  13. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    8,857
    Likes:
    862
    Location:
    Rochdale UK
    ONLINE
    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.
     
  14. mauros

    mauros New Member

    Joined:
    Apr 25, 2017
    Messages:
    24
    Likes:
    0
    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
     
  15. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    8,857
    Likes:
    862
    Location:
    Rochdale UK
    ONLINE
    Have you a datasheet for this shield?? Is the LCD officially mounted to the USB shield or did you mount it??
     
  16. mauros

    mauros New Member

    Joined:
    Apr 25, 2017
    Messages:
    24
    Likes:
    0
    Last edited: Jun 19, 2017 at 7:42 AM
  17. mauros

    mauros New Member

    Joined:
    Apr 25, 2017
    Messages:
    24
    Likes:
    0
    I bought this
    http://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
     
  18. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    8,857
    Likes:
    862
    Location:
    Rochdale UK
    ONLINE
    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
     
  19. mauros

    mauros New Member

    Joined:
    Apr 25, 2017
    Messages:
    24
    Likes:
    0

Share This Page