ShiftOut with a 64-bit register?(Well, 2x32)

As most may know by now, I have in my possession a Knight-rider type bar which runs on Sanyo LC7935's

They're basically 32 bit shift registers but I have 2 daisy chained.

The problem I'm having is interfacing it with the Arduino, I've tried ShiftOut, but it's designed for 8 Bits, the sample code includes alot of counting but not enough documentation to state what each count is for.

When running any of the 3 sample code sets, the LED's just light up in sets of 8 until the whole bar is lit, then it just stops. Pulling power and applying it back just repeats the process.

Someone suggested to "daisychain" a bunch of Shiftout code together.

But with all the counters I have no idea where to start.

Ideally, I would modify the library itself to facilitate 65-bit, then send that, BUT the sample code seems to run into an actual library and I can;t find anything relating in the Arduino "Install" directory.

It should work to simply call shiftout 8 times with your 64 bits of date. One call right after another. If that's not working, how sure are you about how the light bar is wired?

Ohhh, duhhhh. :-/

I kept on reading the tutorial for the 8-bit shift register LED thing, and I JUST noticed the Factsheet on it.

Hold for resuslts.

P.S. WOULD it be possible to modify it to run 32 bits?

I fail at coding :confused:

I've tried and tried, but can't seem to get them lit up in proper sequence, it either gives out random lights, or 8 light sets that have nothing to do with what I'm specifying.

Could someone please write some code that'll accept a single hex number, then convert it to the required array.

If you tell me more about the required array I can give it a shot...

  • Ben

2 Sanyo LC7935's wired in series over the "Continue" pin, with 32 LED's connected to each.

The LED's are in just a Row, no matrix.

I posted pics of the board somewhere else on the board, but can't seem to find them :frowning:

OH yey, I got it working(Sorta)

Kay, well I woke up this morning and the proper idea of what I'm supposed to be doing popped into my head.

First: The code:

//pins
int latchPin = 13;
int clockPin = 12;
int dataPin = 11;
//Decimal value to output
int d = 170;

void setup() {
//Start serial to debug/send values
Serial.begin(9600);
//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop() {
//If there's something new
if (Serial.available() > 0) {
// read the incoming byte:
d = Serial.read();
}
//ground latchPin and hold low for as long as you are transmitting
digitalWrite(latchPin, LOW);
//Repeat the 8 bit pattern 8 times
shiftOut(dataPin, clockPin, MSBFIRST, d);
shiftOut(dataPin, clockPin, MSBFIRST, d);
shiftOut(dataPin, clockPin, MSBFIRST, d);
shiftOut(dataPin, clockPin, MSBFIRST, d);
shiftOut(dataPin, clockPin, MSBFIRST, d);
shiftOut(dataPin, clockPin, MSBFIRST, d);
shiftOut(dataPin, clockPin, MSBFIRST, d);
shiftOut(dataPin, clockPin, MSBFIRST, d);
//latch up
digitalWrite(latchPin, HIGH);
//Send that it's done.
Serial.print("DONE!");
Serial.println();
//Print last byte
Serial.print(d);
Serial.println();
Serial.println();
}

Kay, so the way I have it now, I use a Binary converter to convert a pattern of 1's and 0's to a decimal number, I then define it as "d"

With the current code, when I run it, it outputs the proper pattern, sends the number back through serial, and all works swell.

BUT

When I try to send it any number through serial(8 bit or otherwise) the feedback seems to bounce some(as do the lights) then it pretty much always fixiates on "51"

EDIT: IT seems to not fixiate on 51, if I type in jibberish, it gives me 100, and if I type in 11, it gives me 49, so it seems to be converting something, any way to make it stop/counter act it?

I'm assuming that it's having a problem with the serial not being "Timed" properly, but I tried sending it a bunch of times in a row(To hope that I hit the right timing point) but nothing

BTW.
For the uninformed, colorful code comes from the Tools > Copy For Forum menu in the Arduino IDE

So I've fiddled with the code, and am still getting the problem of Serial receiving totally different numbers,

I send a 128, it lights up the LED's in a random fashion, then pings back 42.

There seems to be SOME pattern here, but I can't decipher it.

Are you actually typing numbers into Hyperterminal? That would output several bytes of ASCII instead of a raw decimal number like your code appears to expect.

I'm using the Arduino serial monitor,

And I'm submitting valid 8-bit numbers in decimal.

Even 170(the default defined one, which works fine) doesn't work when sent from the Serial Monitor.

I send it a 170, it spits back a 52

Might help. I've not done any changes for your setup.

http://www.datasheetcatalog.org/datasheet/sanyo/ds_pdf_e/LC7935AN.pdf

The toggle bits in write16 function are needed to dump the data then latch and display it. It's much cleaner as a function.

I suppose with careful coding I could have read two bytes and gotten the two digit code I wanted but had to suffer converting the incoming serial byte using the switch statement.

This is a breadboarded knight rider display with sixteen LEDs. The only hardware limit to this is how long updates take and the max load on the data lines. The arduino would at some point run out of ram I think though I could grab the data out of an SD card or SPI flash.

/* Serially controlling bits
mrmeval 2008
This comes from the ShiftOut tutorial so is under a creative commons license.

Originally:
Name    : shiftOutCode, Hello World
Author  : Carlyn Maw,Tom Igoe                     
Date    : 25 Oct, 2006  

Rest of my comments insane, deleted

*/

int data = 11;
int strob = 8;
int clock = 12;
int oe = 11;
int count = 0;
int dato = 0;
int ack = 13;
int incomingByte;


void setup()
{
  pinMode(data, OUTPUT);
  pinMode(clock, OUTPUT);
  pinMode(strob, OUTPUT);
  pinMode(oe, OUTPUT);
  pinMode(ack, OUTPUT);
  digitalWrite(oe, LOW);
  Serial.begin(9600);
}

void write16(int x) {
  shiftOut(data, clock, MSBFIRST, x>>8);
  shiftOut(data, clock, MSBFIRST, x);
  digitalWrite(oe, LOW); 
  digitalWrite(strob, HIGH);
  digitalWrite(oe, HIGH); 
  digitalWrite(strob, LOW);
}

void loop()
{
  digitalWrite(ack, HIGH);

  if (Serial.available() > 0) {
    incomingByte = Serial.read();
    Serial.println(incomingByte);
    switch (incomingByte) {
      case 49:
      write16 (1);
      break;
      
      case 50: 
      write16 (2);
      break;
      
      case 52:
      write16 (4);
      break;
      
      case 56:
      write16 (8);
      break;
      
      case 97:
      write16 (16);
      break;

      case 98:
      write16 (32);
      break;
      
      case 99:
      write16 (64);
      break;
      
      case 100:
      write16 (128);
      break;
      
      case 101:
      write16 (256);
      break;
      
      case 102:
      write16 (512);
      break;    
      
      case 103:
      write16 (1024);
      break;
      
      case 104:
      write16 (2048);
      break;
      
      case 105:
      write16 (4096);
      break;
      
      case 106:
      write16 (8192);
      break;
     
      case 107:
      write16 (16384);
      break;
      
      case 108:
      write16 (32768);
      break;
      
      case 48:
      write16 (0);
      break;
      
      case 126:
      write16 (65535);
      break;
      
      default:
      write16 (0);
      break;
    }
      delay(50);
  }
} 


/*Since I can't seem to read two bytes in a row, I encode thuse
a=16 b=32 c=64 d=128 e=256 f=512 g=1024 h=2048 i=4096 j=8192 k=16384 l=32768
zero sets them all to 0, tilda sets them all on.
ascii codes     
97       a
98       b
99       c
100      d
101      e
102      f
103      g
104      h
105      i
106      j
107      k
108      l
*/

In your code d is declared int. Serial read returns a byte. You might want to change that. As you might note in my program you can't send decimal values via the serial console. I think it can be done with the processing language but as you can see I didn't bother. :wink:

The decimal value for 1 is 49.
The decimal value for 7 is 55
The decimal value for 0 is 48

Cough thought it;d be obvious, but I'm sending from the Arduino Serial Monitor.

I'm pretty busy for the next couple days, so I'll see what I can do when I can.

And I've read the Datasheet, but the timings mean jibberish, in one of my other threads, one of the mods said that it's a standard shift register, so that's what I refer to it as now.