LiquidCrystal & Shift Register

Ah nice! I’ll definitely love to get the 595 then :smile:

It’s like $12 vs $2 on element 14 which i thought was just too drastic!

EDIT: Ah…the search function is the problem…they aren’t that pricey :smiley:

Thinking of making a simple LCD shield but doubles up as a prototyping shield for people who are new to try out LCD either through a 595 or just individual wires to the core.

It’s more for a learning tool for new beginners really.

Hope to hear everyone’s inputs/suggestion!

Dang... on Digikey I was seeing $1.05 for the 595, and $0.47 for the 164. I was wondering why you splitting hairs over that price difference :wink: $10.00 more is definitely a problem! :slight_smile:

initially i was puzzled as well… But i wonder why those 595 i saw costs 12 bucks! :stuck_out_tongue:

@BDub sorry for my late reply, i know I was the TS, but traveling just took way more time than expected before i could test again.

anyway, the software library is working like a charm!
yay!

question :

is there any way to port this into the new system that has the tabs? so the seperate .cpp and .h files?

trying to cleanup my code :smile:

Yep, it’s very easy. I’m removing wallpaper glue from walls right now, but I added a note to my backlog of things to do. Should be a quick fix. Ping me again if you don’t hear anything on this thread before the end of tomorrow.

@BDub
excellent :slight_smile:

am i understand that theoretically any program for arduino should work now as long as i copy the .h contents into a seperate tab and name it correctly?

I'm afraid not. Even if the arduino library doesn't use any low level AVR hardware or special things, then it at least needs to have some of the #defines and #includes commented out. It's not too bad, but until you do a few of them you won't think it's super duper easy. After then though, piece of :cake:

@BDub

so how would one go about know which to uncomment?

@BDub

reminder for the seperation;)

1 Like

@BDub

so i gave it a go to do the seperation myself, but it seems there is more to it… would it be possible for you to explain really quickly how you seperated it?

Hmm… well I just separated the files… and it was a little trickier than I thought because I pulled in some changes that I had made to the other LiquidCrystal library. Also there was a slight issue with the way the constructor was being initialized, that would fail when things were in separate files. I basically started with my LiquidCrystal library, that was already separated… made a copy of those files in my SPI library directory, renamed the files to have SPI on the end and started by copy/pasting the contents of each section of the old single file into separate files… paying close attention to the include guards. Then getting all of the includes straight. Then fixing the issue I mentioned. And finally adding changes to the file. Hopefully someday I can do a better job of explaining HOW to do this…

Please let me know if this works! It compiles online for me, but I don’t have the time now to test it.

@korneel just checking if you saw my above post and got this working?

works like a charm :slight_smile: thanks!

3 Likes

It won’t compile now, I guess it’s since Spark Core turned to Photon? Anyway, including the library and compiling gives shoals of errors.

Best rgds
Alan T

1 Like

@AlanSparkMan, what errors are you getting?

I think it’s mainly the BSRR not declared errors

inline void LiquidCrystal::writeFast(uint8_t value) {
  PIN_MAP[_latchPin].gpio_peripheral->BRR = PIN_MAP[_latchPin].gpio_pin; // Latch Low
  for (uint8_t i = 0; i < 8; i++)  {
    if (value & (1 << (7-i))) { // walks down mask from bit 7 to bit 0
      PIN_MAP[_sdatPin].gpio_peripheral->BSRR = PIN_MAP[_sdatPin].gpio_pin; // Data High
    } 
    else {
      PIN_MAP[_sdatPin].gpio_peripheral->BRR = PIN_MAP[_sdatPin].gpio_pin; // Data Low
    }
    asm volatile("mov r0, r0" "\n\t" "nop" "\n\t" "nop" "\n\t" "nop" "\n\t" ::: "r0", "cc", "memory");
    PIN_MAP[_sclkPin].gpio_peripheral->BSRR = PIN_MAP[_sclkPin].gpio_pin; // Clock High (Data Shifted In)
    asm volatile("mov r0, r0" "\n\t" "nop" "\n\t" "nop" "\n\t" "nop" "\n\t" ::: "r0", "cc", "memory");
    PIN_MAP[_sclkPin].gpio_peripheral->BRR = PIN_MAP[_sclkPin].gpio_pin; // Clock Low
  }
  asm volatile("mov r0, r0" "\n\t" "nop" "\n\t" "nop" "\n\t" "nop" "\n\t" ::: "r0", "cc", "memory");
  PIN_MAP[_latchPin].gpio_peripheral->BSRR = PIN_MAP[_latchPin].gpio_pin; // Latch High (Data Latched)
}
1 Like

Yes, exactly - BSRR not declared.

@AlanSparkMan, you can replace the function with the code below which uses the new low level GPIO instructions:

inline void LiquidCrystal::writeFast(uint8_t value) {
  pinResetFast(_latchPin);
  for (uint8_t i = 0; i < 8; i++)  {
    if (value & (1 << (7-i))) { // walks down mask from bit 7 to bit 0
      pinSetFast(_sdatPin);   // Data High
    else {
      pinResetFast(_sdatPin);   // Data Low
    }
    asm volatile("mov r0, r0" "\n\t" "nop" "\n\t" "nop" "\n\t" "nop" "\n\t" ::: "r0", "cc", "memory");
    pinSetFast(_sclkPin);  // Clock High (Data Shifted In)
    asm volatile("mov r0, r0" "\n\t" "nop" "\n\t" "nop" "\n\t" "nop" "\n\t" ::: "r0", "cc", "memory");
    pinResetFast(_sclkPin);  // Clock Low
  }
  asm volatile("mov r0, r0" "\n\t" "nop" "\n\t" "nop" "\n\t" "nop" "\n\t" ::: "r0", "cc", "memory");
  pinSetFast(_latchPin);  // Latch High (Data Latched)
}

You will need to copy the library files to tabs in the web IDE to do the edits. Ideally, a pull-request should be done on the original repo (which I will investigate). :smile:

1 Like

@peekay123 That’s great - many thanks for the fix.