Beginner’s Blog

I have been frequenting this fine forum for over a year now and recently I put together this information on different methods of driving 7 Seg displays and would appreciate any suggestions or criticisms from you, my teachers. Go easy on me I’m the sensitive type :roll_eyes: just kidding I can take it Pedro.

I suggest you find out how to do code tags on your blog. Having the code in "normal" font makes it hard to read.

Thanks for that Nick.

Yes not having any experience with what I assume is HTML I will look into how to make the code more legible. Thank you for your suggestion I appreciate it

Or even consider putting the code elsewhere, e.g. GitHub, Google Code, a link to the same site, etc. If there are particular features in the code to be discussed, then posting snippets (in the manner Nick suggest) will keep the overall post shorter, and focus on the discussion.

Since you're using wordpress have a look at,

http://www.viper007bond.com/wordpress-plugins/syntaxhighlighter/ and http://elabz.com/arduino-syntaxhighlighter/

I used these when I was messing about with wordpress here http://www.74hc.co.uk/lcd-and-button-sharing-io/ Really need to start adding articles on a regular basis, but theres always other things to do!

Thanks Jack,

but I was hoping to have all the code available on the blog as if there is only a snippet there, what else is to look at other than some amateurish circuit diagrams. Having the full code available, just like beige has on his blog is exactly the look I am after. Obviously I really don’t expect there to be a traffic jam on my site XD but hey a guy has to start somewhere and to me it must be aesthetically pleasing.

Beige,

thanks for the two links and coincidentally I did find both of those this afternoon but from what I can see, am I right in assuming that I have to have a paid up Wordpress.org account to use plugins. Would you be able to give me any advice as to how I can post my code looking as good as yours does on your site. If you experienced IT type Arduino guys thought that I was sketchy on Arduino coding, when it comes to HTML and websites I am a virtual snowy white virgin. Thank to you all for your suggestions they are appreciated

Pedro.

That's cool, too.

Pedro147: ... I was sketchy on Arduino coding ...

Pun intended? :D

You guys make all this seem so eeeeasy. I am envious 8)

Ah, I've only ever used wordpress on my own web host so not run into that.

Have a look at the pre tag, it's not as fancy but it'll make the code easier to read http://www.w3schools.com/tags/tag_pre.asp

My web design knowledge peaked with HTML4 when people still used tables for layout, these days it's all CSS with a bit of HTML to glue it together.

Thanks Nick,

I hope your info is good for my mojo 8)

What voltage / current draw are you basing your resistor calculations on?

The typical '595 can supply a maximum of 70mA, which at 20mA per segment is three (and a half!) simultaneously. To have all seven segments lit at the same time you don't want to be exceeding 10mA per segment...

A good point regarding the possible / highly likely excessive current draw in the first three examples that are not multiplexed. As pointed out by CR in an earlier different question I would be wise to change the shift register circuits to use common anode 7 Seg with a TPIC6B595 SR. As for the direct drive and DPM circuits I will have to consider all the different maximum ratings for –

  1. The whole board
  2. The different port groups
  3. And individual pins
    as outlined in Nicks information at - Gammon Forum : Electronics : Microprocessors : Arduino Uno Rev3 pinouts photo
    I did do some measurements previously and from the measurements shown in images Current draw 1 and 2 am I right in assuming that I am not exceeding any of the current rating limitations of the different components within my circuits?
    As for my circuit examples 4 and five, I believe that the code is multiplexing the displays and therefore should present no problem in regard to excessive current draw but I should actually check it rather than assume :smiley:
    But as always I defer to the recommendations of you guys in the know, as they say and eagerly await your thoughts on what I have outlined here.

Thanks Pedro.

As for my circuit examples 4 and five, I believe that the code is multiplexing the displays and therefore should present no problem in regard to excessive current draw but I should actually check it rather than assume

That isn't a multiplexing chip and as far as I can see you are not multiplexing in code.

The MAX7219 is a multiplexer.

To test, show an 8 and measure the current.

[quote author=Nick Gammon link=topic=192558.msg1423890#msg1423890 date=1381436871] To test, show an 8 and measure the current. [/quote]

If I use the code from circuit examples 4 or 5, which are inherently the same except that in one the counter is incremented and decremented by a pair of pushbuttons whereas the other by a pot position, this is what I measure. With the multimeter set at 20m, presumably 20 mA, and the test leads in series with the 5 volt header from the Arduino and the 5 volt rail of the breadboard the reading is 14.35 which I again assume is the total current that the circuit is drawing. When I place the multimeter in series with one segment of the 7 segment display again still set on the 20m range I get a reading of 0.37. This is all with the code set to display only the eight numeral. Does it seem that this code is multiplexing and do I have a problem with excessive current draw within this circuit? Also is my procedure for checking current draw sound.

Thanks Pedro

I honestly find all that left-justified code almost impossible to read.

Also, this part doesn't even compile:

if(potReading > 8)
potReading –;

Yes I realise that the formatting on that free website is not the best and at your suggestion I did investigate using some code tags to improve the readability. From what I have been able to find out I would need to pay for a site that allows the use of a plugin to do this and as this is basically being done as a learning exercise for me it isn’t happening. There are quite a few restrictions with these free sites as you can imagine, but that is why they are free. I had the same problem when I tried to copy the code from the blog and paste it into the IDE. it seems that it is only copying one of the minus signs in this part of the code. If anyone can show me how I can improve the code formatting I would be gratefull but I spent hours last night here on the forum and googling all to no avail.

if(potReading > 8)
potReading –;

The code does compile but admittedly I do have the original in front of me so it is easy for me to spot where it is incorrectly being copied. I have attached the code that I used to control the counter with the pot if you are interesed Nick. Thanks again Pedro.

  //  7-Segment LED counter, multiplexing using 74HC595 8-bit shift register, increment counter zero to nine to zero via push button switch
  // Code mangled together from these sources - thanks fellas
  //  http://www.sweeting.org/mark/blog/2011/11/27/arduino-74hc595-shift-register-and-a-7-segment-led-display
  //  http://thecustomgeek.com/2011/06/29/multiplexing-for-a-7-year-old/
  //  http://nootropicdesign.com/projectlab/2009/10/25/led-clock/
  
  const int latchPin = 5;  // Pin connected to Pin 12 of 74HC595 (Latch)
  const int dataPin  = 6;  // Pin connected to Pin 14 of 74HC595 (Data)
  const int clockPin = 7;  // Pin connected to Pin 11 of 74HC595 (Clock)
  
  int counter = 0;          // initialise counter as zero
  int potReading =0;
  
  
  const byte numbers[10] =  // Describe each digit in terms of display segments  0, 1, 2, 3, 4, 5, 6, 7, 8, 9
  
  {
    B11111100,
    B01100000,
    B11011010,
    B11110010,
    B01100110,
    B10110110,
    B10111110,
    B11100000,
    B11111110,
    B11100110,
  };
  

  void setup()
  {
  
  
  
    pinMode(latchPin, OUTPUT);   // set SR pins to output 
    pinMode(clockPin, OUTPUT);
    pinMode(dataPin, OUTPUT);
   
  }
  
  
  void loop()
  
  {
   potReading = analogRead (A0);
   potReading = map(potReading, 0, 1023, 0, 8);
    {
       if(potReading > 8)
         potReading --;
         show(numbers[potReading]);
        
    }
    
    {
       if(potReading < 0)
         potReading ++;
         show(numbers[potReading]);
        
    }
  }
    
  
  void show( byte number)
  {
    // Use a loop and a bitwise AND to move over each bit that makes up
    // the seven segment display (from left to right, A => G), and check
    // to see if it should be on or not
    for(int j = 0; j <= 7; j++)
    {
      byte toWrite = number & (B10000000 >> j); 
  
      if(!toWrite) { 
        continue; 
      }  // If all bits are 0 then no point writing it to the shift register,so break out and move on to next segment.
  
      shiftIt(toWrite); // Otherwise shift it into the register
    }
  }
  

  void shiftIt (byte data)
  {
    digitalWrite(latchPin, LOW); // Set latchPin LOW while clocking these 8 bits in to the register
  
    for (int k=0; k <= 7; k++)
    {
      digitalWrite(clockPin, LOW); // clockPin LOW prior to sending a bit 
  
      // Note that in our case, we need to set pinState to 0 (LOW) for
      // “On” as the 74HC595 is sinking current when using a common
      // anode display. If you want to use a common cathode display then
      // switch this around.
      if ( data & (1 << k) )
      {
        digitalWrite(dataPin, HIGH); // turn “On”
      }
      else
      {
        digitalWrite(dataPin, LOW); // turn “Off”
      }
      digitalWrite(clockPin, HIGH); // and clock the bit in
    }
    digitalWrite(clockPin, LOW);  //stop shifting out data
    digitalWrite(latchPin, HIGH); //set latchPin to high to lock and send data
  }

EDIT –
Just for interest potReading1 image is copied from the editing pane of the Wordpress blog and it has the correct two minus signs. However potReading2 image is copied from the blog page as it appears online and it only shows one minus sign. I assume it is those pesky HTML Gremlims at work again. Oh well, I found it interesting :smiley:

I finally decided to lash out and get some hosting for a [proper “big person’s” website ](http://www.pedroduino.com/7Seg LED circuits) XD and have used the SyntaxHighlighter Evolved plugin with the Arduino brush extension. I think that it does a fabulous job of highlighting the code in an easy to read and colourful format. I just thought that I would show it here in case anyone else is interested in using this plugin on their Wordpress.com site as I know that I had some difficulty in tracking down what I actually needed to do. If anyone has any queries I am only too willing to offer any humble assistance that I can, Pedro.

Edit-1 - Changed name of SyntaxHighlighter plugin to SyntaxHighlighter Evolved plugin

Edit-2 - Code highlighting now done by Javascript written by Jason Knight available at reply #11 http://www.webdeveloper.com/forum/showthread.php?298017-Javascript-to-format-Arduino-code&p=1347149&highlight=#post1347149

That syntax highlighter does a good job, does it only work with Wordpress or can I use it on my site?

BTW, what part of Canberra are you in?


Rob

As I am sure you are aware Rob I am very much on learner plates with all this website stuff, although I did manage to decimate a website tonight by improper use of a FTP program, but that’s another story. Wrecking stuff is a great way to learn. ]:slight_smile:
Have a look at this collection but they may only work on Wordpress, I’m not too sure.

Let me know how you go and if this is no good I’ll have a hunt through my browser history because I’m sure that there a bit more stuff I came across recently. I live in Narrabundah (not heights) but don’t hold that against me

Thanks I'll have a look.

I'm sure Narrabundah will be an "in" suburb one day, I think even the Causeway must be looking up what with all that foreshore development close by. At least you have a house, I don't even have that :)


Rob