Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LCD: I2C device/controller profiles #486

Closed
2 tasks
rwaldron opened this issue Nov 8, 2014 · 39 comments
Closed
2 tasks

LCD: I2C device/controller profiles #486

rwaldron opened this issue Nov 8, 2014 · 39 comments

Comments

@rwaldron
Copy link
Owner

rwaldron commented Nov 8, 2014

  • Refactor LCD implementation into a device/controller profile based design
  • Implement support for at least one I2C LCD device

Examples of device/controller profile designs:

Notes:

  • Existing LCD tests must pass for refactor and new implementation
  • Existing LCD code must still function without changes

Example Usage:

// Initialize an RGB LCD
var lcd = new five.LCD({
  controller: "JHD1313M1" // the model number
});

// Initialize an OLED LCD
var lcd = new five.LCD({
  controller: "SSD1308" // the model number
});

Suggested devices:

cc @deathbearbrown

@dtex
Copy link
Collaborator

dtex commented Nov 18, 2014

@dtex I need to ask you about LCD refactoring
ie. device, controller, etc.
Let me prime that:
LCD's come in 4 major flavors: Parallel (we support this), Serial (can't do this until SoftwareSerial), I2C and SPI
In your vision, these are the major "Devices" correct?
And say there are 2 different I2C protocols, those 2 would be different "Controllers" correct?

Not exactly. I know this is TMI, but it helps me to talk through it...

I see the whole ecosystem as having five layers:

  1. Foundation classes - Fundamental building blocks that can be used on their own or in other classes. Sensor and ShiftRegister are the only two examples I can think of. I kinda think there should be one for I2C, but that's irrelevant for now.
  2. Classes - Classes correspond to different types of hardware (servo, motor, LCD etc). If you make a new class that has the exact same surface API as an existing class, that's a sign that it should not be its own class.
  3. Devices - Classes that have more than one interaction model will need "Devices". Devices can be thought of as different physical interfaces for a class (i.e. Motor 2-pin, Motor 3-pin). Devices can also be enhanced versions of the standard device (i.e. backlit LCD's or motors with current sensing).
  4. Controllers - When we address the pins or pass data in a way other than simply setting/reading pins on the micro-controller we use a "Controller" (i.e. Motor ShiftRegister, Servo PCA9685). In other words, controllers live beyond the micro-controller or board that is being communicated with via Board.IO.
  5. Configs - Configs are just pre-defined options to pass when instantiating a new class. They can be grouped under a parent object to describe shields.

Examples

Multiple Devices, one Controller - In motor (prior to I2C and ShiftRegister support) we had motors that required 1, 2 or 3 pins, and we had motors with current sensing pins and brake pins. These were all different devices. The physical interface, and therefore the code to control those devices was very different, but they all just used pins on the Arduino.

One device, multiple Controllers - In servo we still use one PWM pin to control the servo regardless of wether it is addressed as a pin on the micro controller, or a pin on another controller (PCA9685). One device, multiple controllers.

Multiple Devices, multiple Controllers - Some 2-pin motors are controlled using pins on the micro controller, others using pins that are attached to a PWM controller that we communicate with via I2C. These are different controllers.

So for LCD, the differences in I2C would actually be different controllers. These all look like controllers to me, but I haven't done a deep dive on any of them If any of these LCD's have different capabilities that Add to the standard device (i.e. a backlight), those might be different devices that decorate the default. Also, if any of the LCD's share a controller, but use a different number/type of pins they would also be different devices.

Ugh, this still seems convoluted.

@Resseguie
Copy link
Collaborator

@dtex thanks, that helps me better understand the stuff you've been doing recently.

@deathbearbrown
Copy link
Collaborator

@dtex re:TMI - that was really helpful to me!

@dtex
Copy link
Collaborator

dtex commented Nov 18, 2014

I should qualify one thing: I just made up that Foundation Class label. It's not an official thing... It just helps me organize.

@nofear87
Copy link

Have somebody implemented the 1602?

@rwaldron
Copy link
Owner Author

1602

This stands for the number of columns and rows: 16 columns and 2 rows. There are many 1602 devices that are already accounted for, including parallel and i2c variants. Do you have a product link for the device/ That will help us figure out which you're using.

@nofear87
Copy link

Thank you for fast answering. My display uses the LCM1602 IIC V1 controller.

http://arduino-info.wikispaces.com/file/view/YwRobotLCD-CU-450.jpg/341645320/YwRobotLCD-CU-450.jpg

This one.

@rwaldron
Copy link
Owner Author

@nofear87 ok, I've got one of those here but I'm having strange issues with mine. I will post back when I know more. Thanks for your patience.

@nofear87
Copy link

@rwaldron That would be very nice! Thank you very much!

@rwaldron
Copy link
Owner Author

@nofear87 ok, looks like mine is different, so I ordered this: http://www.amazon.com/Arrela%C2%AE-Display-Yellow-green-Backlight-Character/dp/B00KKQVHME/ref=sr_1_7?ie=UTF8&qid=1419018582&sr=8-7&keywords=i2c+lcd should be here on Sunday. I will post more when I know more :)

@nofear87
Copy link

good job! I am very pleased to hear that.

@dtex dtex mentioned this issue Dec 23, 2014
@nofear87
Copy link

@rwaldron you get it working?

@rwaldron
Copy link
Owner Author

@nofear87 yes, but I haven't landed the patch yet. Unfortunately I just left my house to drive to Boston—I won't be able to get back to this until tomorrow

@nofear87
Copy link

@rwaldron are there some updates for me :-)

@rwaldron
Copy link
Owner Author

@nofear87 yes: I've pushed all the work to this branch: https://github.com/rwaldron/johnny-five/tree/PCF8574

@nofear87
Copy link

Thank you very much! I will test it today!

@nofear87
Copy link

@rwaldron
eg/lcd-all.js
eg/lcd-i2c-PCF8574.js
lib/lcd-chars.js
lib/lcd.js
test/lcd.js

I only have to overwrite these files, right? How can I find the pin setup I have to realize?

@rwaldron
Copy link
Owner Author

The only pins are V, G, SDA, SCL. The chip on the LCD backpack will say PCF8574 or PCF8574A, then follow the example in the commit

@rwaldron
Copy link
Owner Author

Overwrite? Just make a new branch in your local repo and pull PCF8574 branch onto it

@nofear87
Copy link

@rwaldron I have pulled the repo.

var lcd = new LCD({
controller: "LCM1602",
board: this.board
});

I get the following error:

/home/robert/workspace/arduino/server.js:46
var lcd = new LCD({
^
ReferenceError: LCD is not defined

I connected it to Arduino Mega Pin 21 SCL und 20 SDA

@rwaldron
Copy link
Owner Author

Try changing this:

var lcd = new LCD({
  controller: "LCM1602",
  board: this.board
});

To this:

var lcd = new five.LCD({
  controller: "LCM1602"
});

The LCD class located at five.LCD (assuming you have var five = require("johnny-five");) and board: this.board is unnecessary.

@nofear87
Copy link

@rwaldron works like a charm...thank you very very much!

@rwaldron
Copy link
Owner Author

That's awesome. I will land the branch this week and it will be available via npm (we have some other stuff to address first :)

@gabrielpapke
Copy link

Hi @rwaldron, firstly, congratulations to Johnny-five project, is exciting.
I'm beginner yet, and i have some difficulties to use my LCD display with johnny-five framework, the model is i2c PCF8574T, and i tried to use your example for tests, but doesn't work.
Is there some reason to not work?
Thanks.

@rwaldron
Copy link
Owner Author

rwaldron commented Mar 3, 2015

@gabrielpapke can you share your code?

To initialize that device:

var lcd = new five.LCD({
  controller: "PCF8574"
});

I will add an alias for PCF8574T

@rwaldron
Copy link
Owner Author

rwaldron commented Mar 3, 2015

Added.

var lcd = new five.LCD({
  controller: "PCF8574T"
});

@gabrielpapke
Copy link

When i initialize the device the display show only box like this image
And this is my component.

This is my code:

var five = require("johnny-five/lib/johnny-five.js");

var board = new five.Board();

board.on("ready", function() {
  var l = new five.LCD({
    controller: "PCF8574"
  });

  l.useChar("heart");
  l.cursor(0, 0).print("hello : heart:");
  l.blink();
  l.cursor(1, 0).print("Blinking? ");
});

Thanks for attention.

@rwaldron
Copy link
Owner Author

rwaldron commented Mar 3, 2015

var five = require("johnny-five/lib/johnny-five.js");

Are you running this code from the repo or from an npm install?


And this is my component.

The good news is that I have that exact same LCD, so I was able to identify the actual chip model. Unfortunately, the example you've provided isn't using the correct controller, and my last fix overlooked the alternate default I2C slave address. I've just updated Johnny-Five's LCD class and confirmed on 4 separate LCD components.

This code works correctly when using the LCD in the image above:

// From the repo eg/ dir: 
// var five = require("../");
// From an npm install: 
var five = require("johnny-five");
var board = new five.Board();

board.on("ready", function() {

  var lcd = new five.LCD({
    controller: "PCF8574AT"
  });

  lcd.useChar("heart");
  lcd.cursor(0, 0).print("hello :heart:");
  lcd.blink();
  lcd.cursor(1, 0).print("Blinking? ");
});

Note that the controller is PCF8574AT, that's the chip model as printed on the chip itself. This is very important, as it determines which default address to use.

Here's a video of the above code with the same LCD: https://www.youtube.com/watch?v=thFte7gjoNI

@gabrielpapke
Copy link

I'm using the code from repo, i have updated the repo but still not working :(
I tried with controllers: PCF8574T, PCF8574AT, PCF8574 again.
The same problem: when I initialize the device the display show only boxes.
Is it because the chip model is different from yours? PCF8574T without the "A" letter.

Thanks for attention.

@rwaldron
Copy link
Owner Author

rwaldron commented Mar 4, 2015

I tried with controllers: PCF8574T, PCF8574AT, PCF8574 again.
The same problem: when I initialize the device the display show only boxes.
Is it because the chip model is different from yours? PCF8574T without the "A" letter.

Whatever the chip number on your chip, use that.

Can you share a picture of your own wiring?

@gabrielpapke
Copy link

img_4309
This is my wiring, is there something wrong?
(The reflex is a bit disturbing, sorry)

@rwaldron
Copy link
Owner Author

rwaldron commented Mar 4, 2015

Sorry if this is a dumb question, but you've made sure that StandardFirmata is on the board, correct?

Can you take a picture of the back of the LCD, as close as possible but without blurring the writing on the chip and the pcb? I really appreciate your patience :)

Also, this picture is really great :) I think I might've noticed something, but I can't be sure—can you take a look at these solder points:

(This may be nothing at all, but I know I'd look closer at them if I could)

@gabrielpapke
Copy link

Thanks for your patience too!
No problem, the StandardFirmata is on board, i'm using others components and they are working :)

I don't have so much experience with solder, the solder can not touch each other?
Sorry if this is a dumb question haha

Sorry about my english, I from Brazil and i speak portuguese.

Take a look at the pictures:
img_4317
img_4313

Thanks!

@rwaldron
Copy link
Owner Author

rwaldron commented Mar 5, 2015

I don't have so much experience with solder, the solder can not touch each other?

Correct—each solder joint must be "isolated" such that it only affects the circuit nodes that it's connecting. If any of those are touching on the LCD, then it could (at least) not work correctly or (at worst) permanently damage the LCD.

Do you have access to a multimeter? If you do, set it to "continuity" mode, look for this icon:

Then touch and hold the two probes together, you will hear a beep when they are touching—this is just a self check. Now touch and hold the probes to any two solder joints at a time—there should be no "long beep" (some multimeters have a short tone for low ohm continuity and a continuous tone for continuity).

Sorry if this is a dumb question haha

Don't be sorry—this is how we learn together :)

@gabrielpapke
Copy link

A don't have access to a multimeter now, but I already test the LCD with C++ code directly with Arduino, and it works.
The problem can be still in the LCD? If the problem can be on the LCD, I will provide a multimeter.

Thanks for the tips. :)

@rwaldron
Copy link
Owner Author

rwaldron commented Mar 9, 2015

If it works with the C code, then it's not the LCD. That also means that I don't know what's wrong and I'm completely out of ideas :( I have about 10 LCDs here, 3 of which are variations of yours, 1 that is identical and all of them work for me, so I'm at a loss.

@asit569
Copy link

asit569 commented May 11, 2016

@gabrielpapke adjust the potentiometer backside the lcd in controller

@pomek
Copy link

pomek commented Jun 7, 2016

Hey,

@rwaldron, I have the same issue like @rwaldron… And also, I've tested with C++ code - everything works fine. Unfortunately, with Johny-Five it does not work correctly.

But, what I have noticed… I think, the program (code below) was not loaded to Arduino, because my previous program (some operations with expander PCF8574 still working - LED are lighting). Perhaps it is some tip for you.

var five = require("johnny-five");
var board = new five.Board();

board.on("ready", function() {
  var random = Math.random().toString(36).replace(/[^a-z]+/g, "").substr(0, 4).toUpperCase();

  var l = new five.LCD({
    controller: "PCF8574T"
  });

  l.useChar("heart");
  l.cursor(0, 0).print("hello :heart:");
  l.blink();
  l.cursor(1, 0).print("Blinking? ");
  l.cursor(0, 10).print(random);
});

@aimerib
Copy link

aimerib commented Oct 4, 2017

@rwaldron Just wanted to say that thanks to your help troubleshooting gabrielpapke's problem I decided to take a closer look at my own lcd and noticed two leads slightly touching making my ic2 code never work, yet I could bypass the ic2 chip altogether and connect the lcd to the arduino directly and it would work! This saved me from hours of frustration, so thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants