G+_Steve C Posted December 29, 2015 Share Posted December 29, 2015 +Fr. Robert Ballecer In Coding 101 #96 you show how to make an ultrasonic measuring device from an Arduino with an LED light bar as the display. I built that circuit but don't have a light bar and it's rather inconvenient carrying around a computer terminal to use for the readings so I was thinking of using an I2C 1602 LCD display to show the distance since I got one in a kit of parts with the Arduino. Problem is I can't find any information anywhere about how to get I2C LCD display to work. There are a lot of YouTube videos claiming to show how to make a project with an I2C display but they either start out talking about it then go to the finished project without showing how they did it or their script won't compile or else the whole video is nonsense that doesn't show how to do anything that will work. Can you recommend someplace that shows how to get an I2C LCD display to work that actually works? Link to comment Share on other sites More sharing options...
G+_Walter L. McCormick Posted December 29, 2015 Share Posted December 29, 2015 This is the tutorial I followed to get my lcd working. Hope this helps. https://learn.adafruit.com/adafruit-arduino-lesson-11-lcd-displays-1?view=all Link to comment Share on other sites More sharing options...
G+_Scott W Posted December 29, 2015 Share Posted December 29, 2015 I use this Library for my 1602/1604 LCD's. There are example sketches to try. https://github.com/mysensors/Arduino/tree/development/libraries/LiquidCrystal Link to comment Share on other sites More sharing options...
G+_Steve C Posted December 30, 2015 Author Share Posted December 30, 2015 Walter L. McCormick The problem with that is it's for a parallel display, not I2C. Actually most of the examples different companies have posted are still using old fashioned parallel displays from several years ago and haven't been updated to anything newer. Link to comment Share on other sites More sharing options...
G+_Steve C Posted December 30, 2015 Author Share Posted December 30, 2015 Scott Weeks Thanks but I'm not sure what to make of all those sketches on Github. Is there something that explains what all of them do? Link to comment Share on other sites More sharing options...
G+_Scott W Posted December 30, 2015 Share Posted December 30, 2015 Load this sketch to your Arduino to test your display. /* * Wire up for Aruduino Uno and I2C LCD * * Arduino I2C LCD * GND GND * +5v VCC * A4 SDA * A5 SCL * */ // include library code #include #include // initialize the library with the numbers of the interface pins LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); void setup() { // set up the LCDs number of columns and rows: lcd.begin(16, 2); // Print to the LCD. lcd.print("1602 LCD Test!"); } void loop() { // set the cursor to column 0, line 1 lcd.setCursor(0, 1); // print the number of seconds since reset: lcd.print(millis()/1000); } Link to comment Share on other sites More sharing options...
G+_Steve C Posted December 30, 2015 Author Share Posted December 30, 2015 OK I got it to work using a sketch for a 4 line display and modifying it for 2 lines. Link to comment Share on other sites More sharing options...
G+_Steve C Posted December 30, 2015 Author Share Posted December 30, 2015 This works: #include #include #include #include #define I2C_ADDR 0x27 // <<- Add your address here. #define Rs_pin 0 #define Rw_pin 1 #define En_pin 2 #define BACKLIGHT_PIN 3 #define D4_pin 4 #define D5_pin 5 #define D6_pin 6 #define D7_pin 7 #define ECHO_PIN 11 // Arduino pin tied to echo pin #define TRIGGER_PIN 12 // Arduino pin tied to trigger pin #define MAX_DISTANCE 500 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm. NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance. LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin); void setup() // LCD pin SDA to A4, SCL to A5 { lcd.begin (16,2); // <<-- our LCD is a 20x4, change for your LCD if needed // LCD Backlight ON lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE); lcd.setBacklight(HIGH); lcd.home (); // go home on LCD lcd.print("Range Finder"); } void loop() { unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS). unsigned int cm = sonar.convert_cm(uS); // Convert into centimeters lcd.setCursor (0,0); // go to start of 1st line lcd.setCursor (0,1); // go to start of 2nd line lcd.print("Distance: "); lcd.print(cm); lcd.print(" cm "); delay(500); } Link to comment Share on other sites More sharing options...
G+_Steve C Posted December 30, 2015 Author Share Posted December 30, 2015 The second line, #include turned out not to be necessary. Link to comment Share on other sites More sharing options...
Recommended Posts