Liquid Crystal Library

Anyone has luck porting over the LiquidCrystal library?

Arduino library documentation:
http://arduino.cc/en/Tutorial/LiquidCrystal

Arduino library source:
https://code.google.com/p/arduino/source/browse/trunk/libraries/LiquidCrystal/?r=1037

2 Likes

Glued .h, .cpp, Hello-World example and the known fixes all together but I still get some errors. Maybe one of the experts can help?

Source to be found at http://pastebin.com/B4Ea6uHz

Compiler errors:

the_user_app.cpp:104:16: error: conflicting return type specified for 'virtual void LiquidCrystal::write(uint8_t)'
In file included from ../inc/spark_wiring_stream.h:38:0,
from ../inc/spark_wiring.h:32,
from ../inc/application.h:29,

the_user_app.cpp:7:
../inc/spark_wiring_print.h:57:20: error: overriding 'virtual size_t Print::write(uint8_t)'

LIBRARY RELEASED: https://github.com/technobly/SparkCore-LiquidCrystal


@Frido @BlaBlackSheep give this a try:
http://pastebin.com/raw.php?i=SpasTyuP (EDIT: SEE NEWER VERSION BELOW)

I changed:

virtual void write(uint8_t); 

inline void LiquidCrystal::write(uint8_t value) {
  send(value, HIGH);
}

to:

virtual size_t write(uint8_t);

inline size_t LiquidCrystal::write(uint8_t value) {
  send(value, HIGH);
  return 1;
}

void to size_t was a change from 0.xx to 1.xx ArduinoIDE

I added the return 1; to appease the compiler because it was complaining that the method returned nothing. In the future it won’t error in this case, just issue a warning (that can hopefully be suppressed).

Perfect!

You can even remove lines 16-23 and it compiles!

\o/

1 Like

Have you actually gotten it to work on a Spark Core ?
Line 486 in the pastebin (the instantiation of the LiquidCrystal object) has pin numbers from a regular arduino board, and not a spark core one (there are only 7 digital pins in spark core).

When I changed those to relevant spark core pins and connected them, I get (what looks to be like a) crash - the core has no light at all in the RGB LED, and nothing happens. I have to do a factory reset.

My changes from the arduino tutorial sketch is that instead of pins 2-5 in the arduino, I’m using 0-3 in the core, and instead of 11-12 in the arduino, I’m using 5-6 in the core.

Try to allocate the LCD object dynamically instead of statically, otherwise the Core can hang during boot. I ran into a similar issue with the Adafruit OLED library. Like so:

LiquidCrystal *lcd;

void setup() {
  lcd = new LiquidCrystal(D0, D1, D2, D3, D4, D5); //Make sure to update these to match how you've wired your pins
  // set up the LCD's number of columns and rows: 
  lcd->begin(16, 2);
  // Print a message to the LCD.
  lcd->print("Hello, Sparky!");
}
2 Likes

LIBRARY RELEASED: https://github.com/technobly/SparkCore-LiquidCrystal


Added @c99koder’s @Frido’s suggestions here:
http://pastebin.com/raw.php?i=w6AE8CxV (should work!)

It now works!
Thanks @BDub, @c99koder and @Frido !

1 Like

Just curious…remember this from the Kickstarter page?

How was that done? Was a library written already?

(Is that an i2c backpack on the LCD? That may have meant no library needed).

Paul

1 Like

@PaulRB, Mohit said the other day that they had used a serial backpack LCD :wink:

@BDub Verified! Thanks!

pardon the wire-mess.

1 Like

Oh, and just to be clear, you don’t need a shield to do this. Simply power the LCD via the VIN terminal.

2 Likes

ok, so maybe i’m just missing it;

so if i wire my LCD like the way mohit has done this, what would be the code send to my Spark?

would it be simply:
LiquidCrystal *lcd;

void setup() {
lcd = new LiquidCrystal(D0, D1, D2, D3, D4, D5); //Make sure to update these to match how you’ve wired your pins
// set up the LCD’s number of columns and rows:
lcd->begin(16, 2);
// Print a message to the LCD.
lcd->print(“Hello, Sparky!”);
}
?

or, i’m simply an idiot, and had to copy everything from the example.

so new question, is there a way to improve on this experience? i mean, the code is getting very messy this way… if there would be some server-side scripts that would ease the include mess?

Here http://www.mpja.com/download/QC1602a.pdf is the data sheet of my 16/2-LCD

I mapped the pins this way

VSS -> GND
VDD -> +5V (via VIN)
V0 -> to the variable resistor's middle PIN, left to GND, right to +5V/VIN 
RS -> D0
RW -> GND
E -> D1
D3-D6 -> D2-D5 
A -> 3V3 (or +5V/VIN for a brighter background light)
K -> GND

@korneel the :spark: Spark Team is working on adding external library support to the web IDE (aka Sparkulator)… so yeah, the code will be less messy real soon and we’ll all have to break up our library ports into separate files again!

2 Likes

Folks, forgive the total newbie question, but I am having a difficult time with compiling this as it keeps asking me for “WProgram.h”, a header file that was included in the .cpp file above. Not having an Arduino (or Spark) background, I have no idea what this is or how to supply it. Any help would be much appreciated.

Hi @mattygregg,

Just wanted to check and see if you got this working. To double-check I copied and pasted BDub’s code from this post: https://community.spark.io/t/liquid-crystal-library/1048/7?u=dave into the build IDE, and it seemed to compile fine. I think the #include "WProgram.h" is commented out, maybe double-check that you grabbed the latest copy?

Thanks!
David

SparkCore-LiquidCrystal LIBRARY RELEASED: https://github.com/technobly/SparkCore-LiquidCrystal

also if you want to hook up less pins on your Spark Core and have a SPI backpack or 74HC595 IC, try this library: https://github.com/technobly/SparkCore-LiquidCrystalSPI

I also de-swizzled the issue that was preventing us from using the library like normal… aka “needing to allocate the LCD object dynamically instead of statically” … now you can just allocated statically and the hardware initialization happens in the lcd.begin() routine.

http://imgur.com/5rizsos

1 Like

I also just updated the SparkCore-LiquidCrystal: https://github.com/technobly/SparkCore-LiquidCrystal library to support Adafruit’s V2 OLED display and Sparkfun’s OLED display without users having to change any code. If you have a V1 OLED from Adafruit, there are two lines (109 and 110) in the begin() routine you need to comment out in the LiquidCrystal.cpp file.

http://imgur.com/qUXdosd

Enjoy! :wink: Please let me know if it works, or doesn’t work for you!

2 Likes