LDR with 7 seg display and PWM output

cjcj: I also did buy the DS3231 AT24C32 clock... I did however write code in a sketch to run my clock - and I was so proud of doing it. Is it better I use this module? Isn't that sort of cheating and relying on pre made components!

Why get a dog and bark yourself? The RTC module has several important advantages over using the Arduino as a clock. It will be much more accurate over long term, Arduino will probably loose/gain several mintues per day, vs several minutes per year with ds3231. RTC has battery back-up, so doesn't need re-setting every time Arduino is powered up/reset.

cjcj: I'll order the shift registers, mock up 15 small led displays with it, then write the code to learn how to do it.

Make sure to buy common-anode individual/single-digit 7-seg displays for your mock-up. You won't be able to use multi-digit displays without multiplexing them, and that wouldn't be an accurate mock-up of your final curcuit.

cjcj: Below for instance is an example of the code I've written for a MM:SS timer. You'll look at it and think it's quite long winded. But self taught, so far it's the best I can do.

Its good that you are practising your coding skills, but little of that code will be suitable for your project. You won't be multiplexing, you will be using shift registers and an RTC connected to the i2c bus. For now, better to spend your time getting the code for that RTC module working. Just send the output to serial monitor for now.

You are right. I already noticed I had to fiddle with microseconds in order to get the time accurate'sh. At least I learnt something with my code. As for the battery backup - yes, I didn't think of that.

I've already got small 7 segment common anode digits (10 at this stage, so I'll order another 1/2 dozen).

I do realize the multiplexing is out the window now. Again - good practice and I'm learning heaps.

CrossRoads: $2.30 per part - you guys down under get hosed on prices. Same for me is $1.74

Bob, could you check this LINK for shift registers on ebay. Do you think I should trust them?

Up to you. I don't trust anything on e-bay. I only by electronics from actual distributors. If this is just for personal use, that's different. I deliver a lot of what I buy, so I buy from known good suppliers. I also can't live with 3-4 week delivery time.

As for the code: have an array of elements that you will shift out.

dataArray[] = {
leftScoreTens,
leftScoreOnes,
rightScoreTens,
rightScoreOnes,
minutesTens,
minutesOnes,
secondsTens,
secondsOnes,
tenths,
//etc
};

Then send the data to the shift registers

digitalWrite (ssPin, LOW); // connects to RCLK
for (x=0; x<15; x=x+1){
SPI.transfer (fontArray[dataArray[x]]); // look up font mapping and send it out for data at location x in dataArray
}
digitalWrite (ssPin, HIGH); // connects to RCLK, outputs update on this rising edge.

CrossRoads: Up to you. I don't trust anything on e-bay....If this is just for personal use, that's different... I buy from known good suppliers...I also can't live with 3-4 week delivery time.

The 3 to 4 weeks is a pain, but in my it will take me a while to do this project. In my previous large project I did use ebay components alot of the time, except for anything high powered like the TPIC6B595s. Yes, this is not for "personal" use, so I might just order 15 of from a local suppler (rs components) and some "spares only" from ebay. This way I can start breadboarding earlier.

Thanks for all the snipits of code. They will come in handy when I get my PICs and start coding.

PaulRB: For now, better to spend your time getting the code for that RTC module working. Just send the output to serial monitor for now.

I did try my RTC, the only problem was that it was labelled on the ebay website as "DS3231", however I was sent a "DS1307" (no temperature on it). The $2 lost on this module is not the problem - only the 3-4 week waiting again! I connected it and tried some code anyway - time works well (but I've read the earlier DS1307 looses too much time as it is heat affected). New module on order.

Time for me to read some posts on shift registers and do some more practice...

cjcj: it was labelled on the ebay website as "DS3231", however I was sent a "DS1307"

On eBay? I hope you opened a dispute!

PaulRB: On eBay? I hope you opened a dispute!

I did write back to the seller saying "what tha". Interested to see what he does. If I have to return the unit, it'll probably cost me between $5 to $10. Some seller are just dishonest!

I expect they will send you a replacement, rather than risk a dispute case or poor feedback. Question is do they understand difference between ds1307 and ds3231, if they are one of those bazar-type vendors that sell false nails and clothes that no self respecting woman would be seen wearing in public except on a hen night!

Yes, your right. Not sure if they understand the difference either. I just had a reply from "Alice" and I had no idea what her reply ways so I wrote back in simpler english - "You send me wrong part. Please send me right part = DS3231 NOT". It makes me laugh. But at the same time I ordered another unit for about $2 from someone else - "Plan B".

You mean alice1101983? They run the TxHang shop. I was recommended them by another forum member and have used them a couple of times without a problem.

Now sorry if this question sounds a bit naive, but I'm trying to get my head how a TPIC6B595N shift register works and then daisy chaining 15 of them. I have setup 2 x 74HC595 with an exercise noted in a book called "Beginning Arduino" to try and understand registers. Is this what happens:

  • The Arduino generates binary code - 8 bits / 1 byte (i.e. 00010000) to depict a 7 segment digit number
  • This info is sent in serial (via a single line) to the shift register - pin 3 (SER IN)?
  • Each bit is sent/received 1 at a time and shoves the next spot in the register until all 8 are filled up (received)
  • To snapshot this, via the Arduino, "latch" is changed from Low to High - this is pin 12 (RCL) or the register
  • This flip causes the bits to be copied to each of register output pins (drain0 to drain7)
  • This then repeats replacing the bits in the shift register

Now, to cascade, is this correct? - All the 15 drain0's are connected together, and all 15 drain1's, are connected together etc, etc - All 15 latch pins are connected together - pin 12? - All 15 clock pins are connected together - pin 13? - To "shunt?" the 8 bits down from the first register to the next and next, pin 18 (SER OUT) is connected to pin 3 (SER IN) of the next register, and so on - Common anodes (in my case) are connected directly to 24V - The arduino PWM signal is connected to all the output enable pins (G) - pin 9 of each register - The arduino sends out 15 bytes at a time which fill each of the 15 shift registers

Is this the basic idea? So does this mean that 15 bytes of info are sent by the arduino ever microsecond or so, hence any change in 8-bit is displayed immediately in the 7 segment displays so 100 duty cycle? And does it also mean that the dimming all the displays is controlled by a PWM signal from the Arduino to pin 9 of every shift register which essentially essentially creates a sort of duty cycle/pulse width?

Maybe a question for Bob - other than the 15 shift registers, 20 pin IC sockets and 0.1uF caps for each register, is there any other basic components that I need to get started for this test?

cjcj:

  • The Arduino generates binary code - 8 bits / 1 byte (i.e. 00010000) to depict a 7 segment digit number
  • This info is sent in serial (via a single line) to the shift register - pin 3 (SER IN)?
  • Each bit is sent/received 1 at a time and shoves the next spot in the register until all 8 are filled up (received)
  • To snapshot this, via the Arduino, “latch” is changed from Low to High - this is pin 12 (RCL) or the register
  • This flip causes the bits to be copied to each of register output pins (drain0 to drain7)
  • This then repeats replacing the bits in the shift register

Now, to cascade, is this correct?

  • All the 15 drain0’s are connected together, and all 15 drain1’s, are connected together etc, etc
  • All 15 latch pins are connected together - pin 12?
  • All 15 clock pins are connected together - pin 13?
  • To “shunt?” the 8 bits down from the first register to the next and next, pin 18 (SER OUT) is connected to pin 3 (SER IN) of the next register, and so on
  • Common anodes (in my case) are connected directly to 24V
  • The arduino PWM signal is connected to all the output enable pins (G) - pin 9 of each register
  • The arduino sends out 15 bytes at a time which fill each of the 15 shift registers

That all looks correct.

cjcj:
So does this mean that 15 bytes of info are sent by the arduino ever microsecond or so, hence any change in 8-bit is displayed immediately in the 7 segment displays so 100 duty cycle?

No, your sketch only sends the data when you want to change something. So for example if you were displaying the time as hh:mm you would only need to update once per minute.

cjcj:
And does it also mean that the dimming all the displays is controlled by a PWM signal from the Arduino to pin 9 of every shift register which essentially essentially creates a sort of duty cycle/pulse width?

Yes, your sketch can set the level with analogWrite(), again, only when it needs to change.

cjcj:
Maybe a question for Bob - other than the 15 shift registers, 20 pin IC sockets and 0.1uF caps for each register, is there any other basic components that I need to get started for this test?

For your small 7-seg displays, probably be ok, maybe add a 10uF for each display. For your large displays, some much larger caps, maybe 1000uF per digit.

All devices receive clock and latch in parallel. 1st device gets Serial data from processor, it's Serial Out goes to Serial In on next chip. Example: http://www.crossroadsfencing.com/BobuinoRev17/ |500x252

All the 15 drain0's are connected together, and all 15 drain1's, are connected together etc, etc

Oh, that's wrong. Each drain is connected to a separate segment cathode.

PaulRB: You mean alice1101983? They run the TxHang shop.

Yes. What a coincidence. It was exactly the same person / company.

PaulRB: No, your sketch only sends the data when you want to change something. So for example if you were displaying the time as hh:mm you would only need to update once per minute

Yes, of course. That makes sense.

PaulRB: For your small 7-seg displays, probably be ok, maybe add a 10uF for each display. For your large displays, some much larger caps, maybe 1000uF per digit.

Is that right? I "thought" that each IC needs a 0.1uF capacitor as close to the Vcc as possible and ground in order to stop any resilient "noise".

CrossRoads: All devices receive clock and latch in parallel. 1st device gets Serial data from processor, it's Serial Out goes to Serial In on next chip. Example...

Yes, now that's starting to make sense. Your link to the sketch now also is making sense. So am I now understanding this correctly. Your post #30 that shows a circuit board, is essentially exactly what I need (expect I need an extra 3 shift registers, plus having to connect my PWM signal?

I "thought" that each IC needs a 0.1uF capacitor as close to the Vcc as possible and ground in order to stop any resilient "noise".

Correct, you need those too. The larger caps are to smooth the sudden demand spikes when large currents are switched, such as your led segments. You might get away with minimal or no caps for your small prototype, depending how good your power supply is and how far away the chips are from it. But with your large displays and the long power lines you will probably have in the final build of the project, lots of large caps spread around would be a very good idea.

I suppose then these are to replace the 0.1uF. So do I put them next to each shift register (15 in total), and maybe 35V, 1000uF?

I mean you need (or might need) both. Definitely a 0.1uF decoupling cap for each chip (accross 5V & ground), plus (maybe) a larger cap to smooth the high-current switching (accross 24V & ground - check cap's voltage rating is adequate). With your small displays, maybe not needed at all. For the large displays, maybe 1000uF per display is overkill. I'm not sure how to estimate that, maybe Bob has some advice.

CrossRoads: All devices receive clock and latch in parallel. 1st device gets Serial data from processor, it's Serial Out goes to Serial In on next chip.

Bob, So am I now understanding this correctly. Your post #30 that shows a circuit board, is essentially exactly what I need (expect I need an extra 3 shift registers, plus having to connect my PWM signal? And yes, any ideas on the number and placement of caps as suggested above?