SparkFun Forums 

Where electronics enthusiasts find answers.

General project discussion / help
Did you make a robotic coffee pot which implements HTCPCP and decafs unauthorized users? Show it off here!
#168302
I'd like to connect two RingCoder breakout boards (https://www.sparkfun.com/products/11040) to a single ATMega328, but I'm a little bit confused about how to connect them both together.

I'm new to shift registers in general, but it seems that the RingCoder is not set up to allow for daisy chaining multiple modules on the same SPI bus. Or am I wrong about that?

I could use some pointers about which pins are common between the boards, and which must be separate. For example, I'm thinking that I need to connect both boards' GND, DAT, CLR, CLK, LATCH and VCC pins together (don't care about colors or switch right now), then bring the EN lines to two different pins of my ATMega328 so I can switch between the two boards. Is this correct?
#168304
Look at the BoB's schematic. Notice the two shift register chips and how they are daisy chained (pin 9 to pin 14).
You could do this to the second BoB by soldering a wire onto IC2's pin 9 then connecting this wire to the DAT (IC1's pin 14 on the second BoB. The other pins on IC1 & IC2 all connect together on both BoBs.
Your code would then need to shift out 32 bits instead of 16 bits.
And you will need separate sets of inputs for the two encoders.
By Mee_n_Mac
#168390
H4T wrote:That handles the daisy chaining, but what about the wiring? Did I get it right about which lines to make common, and which to keep separate?
In a word, nope (if you don't daisychain the 2 BoBs ala waltr). I believe the enable pin controls the output drivers on each SR. If you want separate data to be displayed you have 2 choices; share all pins except for separate latch signals or share all pins except for separate CLK signals. I believe the SRs used function like 595's do. You clock data into the SR using it's SER and SRCK pins (DAT and CLK on the BoB). Once the data has been clocked in, it's transferred to the "output registers" by pulsing the RCK pin (LATCH on the BoB). Then when the output enable is low, whatever is in the output registers goes on the output pins. This way you can shift in new data w/o the output changing (until it's R clocked/latched). So the 1'st choice is explained. The only issue is that each of your BoBs will clock in it's data and then the others data (but it's never latched into the output registers). So you can't shift the data, 1 clock at a time, like you might want to do w/a single SR chain. You have to reload all 16 bits each time you want the BoB to change. Perhaps you're going to do this anyway.

The other choice means each BoB clocks in only it's own data and then re-latches it 2x. The re-latch is a don't care as the data has not changed. This means a different argument for the Shiftout() function, depending on the BoB being used.

You choice.
http://www.ti.com/lit/ds/symlink/sn74ls595.pdf
#168391
I am completely new to shift registers, and not super excited about getting too far into them. I'm really just interested in getting using the LEDs as a dial gauge, and using the rotary encoders as potentiometers. Just a visual feedback mechanism for the position of the pot (filled to the current level).

Since this daisy chaining thing is turning out to be more complicated than I need it to be, I may just end up putting in two ATMega328s and having them pass data over I2C. Just really wish these boards were a little more friendly for non-EEs.
By Mee_n_Mac
#168396
H4T wrote:Since this daisy chaining thing is turning out to be more complicated than I need it to be, I may just end up putting in two ATMega328s and having them pass data over I2C. Just really wish these boards were a little more friendly for non-EEs.
No need to daisychain the 2 Bobs, just wire them in parallel except for the LATCH signals. Let each have it's own pin. Now send out the data as you would have to either Bob but use the proper pin for the LATCH signal. That's it. About as easy as doing just 1 ring.

Here's a snippet from the example code.
Code: Select all
  // Now we just need to write to the shift registers. We have to
  // control latch manually, but shiftOut16 will take care of
  // everything else.
  digitalWrite(latchPin, LOW);  // first send latch low
  shiftOut16(ledOutput);  // send the ledOutput value to shiftOut16
  digitalWrite(latchPin, HIGH);  // send latch high to indicate data is done sending 
Assuming you use 2 different variables to hold the LED states for each ring, the above portion might then look like ...
Code: Select all
  // Now we just need to write to the shift registers. We have to
  // control latch manually, but shiftOut16 will take care of
  // everything else.
  digitalWrite(latchPin1, LOW);   // first send latch low for ring1
  shiftOut16(ledOutput1);         // send the ledOutput value to shiftOut16
  digitalWrite(latchPin1, HIGH);  // send latch high to indicate data is done sending 
  // Now repeat for ring2.
  digitalWrite(latchPin2, LOW);   // send latch low for ring2
  shiftOut16(ledOutput2);         // send the ledOutput value to shiftOut16
  digitalWrite(latchPin2, HIGH);  // send latch high to indicate data is done sending 
Of course you'll have to declare and initialize 2 latch pins now but the shifting routine used above remains unchanged.
Code: Select all
// This function'll call shiftOut (a pre-defined Arduino function)
// twice to shift 16 bits out. Latch is not controlled here, so you
// must do it before this function is called.
//   data is sent 8 bits at a time, MSB first.
void shiftOut16(uint16_t data)
{
  byte datamsb;
  byte datalsb;
  
  // Isolate the MSB and LSB
  datamsb = (data&0xFF00)>>8;    // mask out the MSB and shift it right 8 bits
  datalsb = data & 0xFF;         // Mask out the LSB
  
  // First shift out the MSB, MSB first.
  shiftOut(datPin, clkPin, MSBFIRST, datamsb);
  // Then shift out the LSB
  shiftOut(datPin, clkPin, MSBFIRST, datalsb);
}