LiquidCrystal & Shift Register

HI Guys;

yes, me again.

so i have gotten my liquidcrystal working, and have the shift register working.
now i’m trying to combine the both.
i have used this tutotial : http://playground.arduino.cc/Main/LiquidCrystal#ExtraPins to wire the setup up, nut now i’m stuck at translating this into a new firmware sketch…

i need to replace the digital ports currently defined in my liquidcrystal sketch, by the ports from the shiftregister. i have no freaking clue how to do this… any suggestions?

Support for multiple files in the IDE will be added soon. In the meantime, you can selectively copy and paste the content from the LiquidCrystal.h and LiquidCrystal.cpp files into the IDE in addition to your code, and simply change the pin numbers as necessary.

If you run into any issues as you attempt this, post them here and your combined code so far and we can help you work through it.

I’ve created a port of the LIQUIDCRYSTAL SPI 74HC595 LIBRARY FOR SPARK CORE
https://gist.github.com/technobly/ba306404a1a90554eb59/raw/

Please let me know if it works!

Steps to create:

  1. Combine LiquidCrystal.h, LiquidCrystal.cpp and HelloWorld_SPI.pde in one file.
  2. Remove all include headers and references to arduino stuff
  3. Find missing helper functions and replace (from Arduino.h)
  4. Change SPI_CLOCK_DIV to be as close to 8MHz as possible. You might be able to speed this up!
  5. Document pinout for Spark Core SPI and 74HC595

so BDub,

first of all, you rock!
i’ve copied the code, but for the love of me, i can’t find where to define my shift register pins? nor can i find where to define to which shift register pin i’ve connected my display… am i that stupid?

Check out line 564 of the code for wiring info. Here’s a pic as well:
http://docs.spark.io/#/firmware/communication-spi

Line 551 is the start of the user application, everything above that is the library.
https://gist.github.com/technobly/ba306404a1a90554eb59#file-sparkliquidcrystalspi-cpp-L551

Make sure you copy the raw view of the code:
https://gist.github.com/technobly/ba306404a1a90554eb59/raw/

You shouldn’t have to define any pins as long as you hook up your 74HC595 to A2, A3, A5 as pictured. A4 is not used.

You also have to make sure you hook up the pins from the '595 to the LCD like this:

Good luck!

1 Like

Hi;

thanks for your reply!
yes, i’ve wired the LCD like that, but i actually wired the shift register differently, i connected the DS to Digital 4, Clock Pin to Digital 5 and Storage to Digital 6…
so the difference is that in your diagram it is 13, 11, 10, in my setup it’s 4,5,6…

can we change that easily?

Yup! This is how you want to hook your 74HC595’s three lines to your Spark Core:

SPARK CORE SPI PINOUTS
  Spark Core    74HC595
  A5 (MOSI)     14 - The data bits (74HC595 pin 14 "DS").
  A4 (MISO)     NOT USED
  A3 (SCK)      11 - The shift clock for the data bits (74HC595 pin 11 "SHCP").
  A2 (SS)       12 - The strobe that copies the databits into the latch (74HC595 pin 12 "STCP").

Hi bdub,

im sorry, i think You misunderstood,
i tested the shift register with led’s on port d4,d5,d6, and that worden. SO then i hard wired everything To those 3 ports.

the question is, can we change the code do that islt uses those 3 digital ports instead of the 3 spi ports that You are refering To…

The default connections for SPI on the Spark Core are A2, A3, A4, A5 and they are hooked up to a hardware SPI peripheral inside the STM32 (at least I’m pretty sure it’s hardware). There is no way to redefine those pins from your application at the moment. The only other way you could do it is if you used the slow shiftOut() function.

But the library I converted takes advantage of the high speed SPI that the Core has, so if there is no strong reason to use D4, D5, D6… I would suggest using A2, A3, A5. :wink: Otherwise we can work on crippling the library to use shiftOut() which is supported by the Spark Core already, but I don’t think you’ll like how slow your LCD updates.

Hmm i Guess that Will mean rewiring… SO how does This work with multiple shift registers?

You can define multiple SS pins that act as the Latch for SPI devices. The default is A2, but you can define a second latch pin on any other digital output. The MOSI (data A5) and SCK (clock A3) for your second device can be paralleled together with the first device, but only the latch pin that is low will respond to the data and clock.

If using this library you could theoretically define a new instance like LiquidCrystal lcd2(D0); and set the SS pin to whatever you want, in this case D0.

so, progress… i guess.
rewired everything, reconnected the spark core, and now only the little blue LED (n ot the big one) is on. nothing else. c an’t even reset… nice.

@korneel could you please share a picture of your wiring?

Also do you know how to factory reset?

Try a factory reset. Hold down both buttons, then release the RST button, while holding down the MODE button. The LED should begin flashing yellow. Continue holding down the MODE button until you see the Core change from flashing yellow to flashing white. Then release the button. The Core should begin flashing blue after the factory reset is complete.

@korneel - I am having the same symptom from this code. Any time I flash / run it I need to factory reset.

sory for thelate reply, i’m traveling for work for another week.

as far as my issues;
so i have to reset the spark core whenever i load this code.

even worse, after the factory reset, i am unable to use the USB and Windows method to reconnect to the spark cloud.
it happily blinks blue, i connect using serial, give it my wireless network name and wireless key, and it accepts it. reboots and hello, the blue blinky led is back and i still have to put in my wireless ssid and password…

will try more when i get back home.

Just to comment on this chain…

I have re-jumpered my LCD board to I2C - SPI is just not working for me.

Ken

ok, i’m back.

now, my core is acting interestingly.

i connected it back to the spark cloud, reflashed the firmware, and now the core is in a couple-white flash, couple green flash - blue led D7, no LED loop.
i think someone from the Spark friends should step up here and look at this with us,…

Spark friends reporting in!

-- Which code / wiring diagram are we working with here, is it this one?

@Dave yep that’s the one… now I’m starting to think the pinMode() and digitalWrite() 's might be an issue in the Constructor for this one as well :wink:

https://gist.github.com/technobly/ba306404a1a90554eb59#file-sparkliquidcrystalspi-cpp-L177-L278

And probably doesn’t help that begin defaults to begin(16,1) from init when we are calling it in code as begin(16,2)…

1 Like

first of all, thanks @Dave for reporting in :slight_smile:
let me be specific about the fact that @BDub is the resident genius here, without the library import i am essentially lost, but he has been making great progress!

@BDub, do you still need me to share the wiring?
i don’t think the problem is in the wiring, if i just upload the code to the core, even without any connection, the core just completely flips out…

let me know how i can help…

1 Like