i2c with adafruit LCD display (for PI)

I’m trying to connect a LCD via i2c to the Particle Core (and tried it on Photon) but am unable to make it work.

I’ve tried 3 screens (though there might be something faulty), but testing it on a PI and it works. I trying all sorts of stuff, including a different power supply (for the 5v).
I don’t know what else to do. I’m down to the library not working correctly.

My code is pretty straight forward:

/*********************

Example code for the Adafruit RGB Character LCD Shield and Library

This code displays text on the shield, and also reads the buttons on the keypad.
When a button is pressed, the backlight changes color.

**********************/

// include the library code:
//#include <Wire.h>
#include "Adafruit_RGBLCDShield/Adafruit_MCP23017.h"
#include "Adafruit_RGBLCDShield/Adafruit_RGBLCDShield.h"

// The shield uses the I2C SCL and SDA pins. On classic Arduinos
// this is Analog 4 and 5 so you can't use those for analogRead() anymore
// However, you can connect other I2C sensors to the I2C bus and share
// the I2C bus.
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();

// These #defines make it easy to set the backlight color
#define RED 0x1
#define YELLOW 0x3
#define GREEN 0x2
#define TEAL 0x6
#define BLUE 0x4
#define VIOLET 0x5
#define WHITE 0x7

void setup() {
  // Debugging output
  Serial.begin(9600);
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  lcd.clear();

  Spark.publish("loaded", "true");

  int time = millis();
  lcd.print("Hello, world!");
  time = millis() - time;
  Spark.publish("process/time", String(time) );
  Serial.print("Took "); Serial.print(time); Serial.println(" ms");
  lcd.setBacklight(WHITE);
}

void loop() {
  lcd.print(millis()/1000);
  Serial.println(millis()/1000);
  delay(1000);
}

Can anyone else see an issue?

How are you wiring the shield to the Photon?

great question!
D0 and D1 go to PI’s i2c ports:

Power (5v) and ground are also like seen on the Pi photo (1st and 3rd pin on top).

Ok i thought you were referring to the P1 but you were actually looking at the Raspberry Pi.

I mean how did you connect the power line etc etc to the Photon?

I am still looking for a way to get that basic 16x2 LCD to work on a Photon with I2C. Something about the firmware version not being up-to-date with the IDE because the HAL something.

I’ve tried powering it with many different things but mostly powering it off the MacBook Pro USB port.
I’ve also tried to power it from a YwRobot stright to the Vin pin.
As well as I tired using a Spark Core to run the same code but it still didn’t work :frowning:

Forgot to add, they’re sharing ground (as I thought that might cause an issue if they weren’t).

Hi,

Here is a potentially dumb question, but it caused a similar problem for me. Have you updated your Photon to 0.3.4 yet? Prior to that, I found that neither D0 nor D1 worked and I was having similar issues. The easy test is to throw an LED (and a resistor) on D0 and D1 and turn them on and off and see what happens.

Prior to the update, D0 and D1 would never go high and so my display never worked. Once I upgraded, the two pins behaved normally as did my OLED display.

I’m not sure how to check what version I’m using and I wasn’t able to find great docs on how to update it. However I’ve tried it with a Spark Core and I’ve updated it yesterday.

Is there a great place to read on how to upgrade the Photon?

@anlek, I believe @JL_678 mean Photon system firmware version 0.4.3rc2 which you can find here. It address some of the I2C issues though Particle is testing a new fix.

Ok, I’ve updated it but still no go :frowning:
Could there be something different in the PI vs the Photon (or Core)?
Could the library for the LCD/Board be messing something up? I mean display Pi plate is using the correct chipset.

I think the next step is to grab an Arduino and try to make the screen work with it. If it works, then I will have to assume the library code for the screen is messed up.
I’ll report back once I have some time to play with it.

If anyone else has any ideas, please let me know.

So I had some time to play with an Arduino and I have it fully running with the following code:

#include <Wire.h>
#include <Adafruit_RGBLCDShield.h>

#define OFF 0x0
#define RED 0x1
#define YELLOW 0x3
#define GREEN 0x2
#define TEAL 0x6
#define BLUE 0x4
#define VIOLET 0x5
#define WHITE 0x7 

Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();

void setup() {
  Serial.begin(9600);
  // put your setup code here, to run once:
  lcd.begin(16, 2);
  lcd.clear();

  int time = millis();
  lcd.print("Hello, world!");
  lcd.setBacklight(RED);
  time = millis() - time;
  Serial.print("Took "); Serial.print(time); Serial.println(" ms");
}

void loop() {
  lcd.clear();
  lcd.print(millis()/1000);
  Serial.println(millis()/1000);
  delay(1000);
}

I’ve pasted the code into build.particle.io and tweak the require statement to say #include "Adafruit_RGBLCDShield/Adafruit_RGBLCDShield.h" and everything compiled fine, however nothing works :frowning:

I’ve also just updated to firmware 0.4.4-rc.2 and still nothing.

Does anyone have any more ideas I can try?

My understanding is that the firmware 0.4.4-rc.2 does NOT have the I2C fixes in it but that 0.4.4-4c.3 will. That should be available in a day or so according to a post by BDub.

Thank you @wmjenk, that’s good to know!

##I solved the issue!
It seems that the I2C (D0 and D1) require a pull up resistor.

I’ll attach more information in the next few hours, once I figure out exactly what happened.
Thank you for everyone’s feedback!

I should say that outside the pullup resistor, I did get corrupted communications from the photon after a few seconds (to a few minutes). Upgrading to firmware 0.4.4-rc3 seems to have fixed the issue completely! :slight_smile:

2 Likes

If you want to learn more about the pullup resistor, checkout: