User Tools

Site Tools


raspberry_pi_led_clock_and_ntp_server

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
raspberry_pi_led_clock_and_ntp_server [2017/01/22 16:26] – [Some Simple Testing] walkeradminraspberry_pi_led_clock_and_ntp_server [2023/03/09 22:35] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== Raspberry Pi LED Clock and NTP Server ====== ====== Raspberry Pi LED Clock and NTP Server ======
-<color #db5f0b>Jan 2017</color>+<color #db5f0b>Jan 2017 (Updated Mar 2017)</color>
 \\  \\ 
 \\  \\ 
-{{:7segprototype.jpg?400|}}+{{:7segledfocus.jpg?400|}}
 \\  \\ 
 \\  \\ 
Line 10: Line 10:
 ==== Does this work? ==== ==== Does this work? ====
 \\  \\ 
-Yes it does, so read on. At the time of writing I have finished the hardware (not got a PCB made yet, so am still using my prototype) and the Clock software is working. I have not yet started the NTP part, but will do so once the hardware is fully ready (I.E I have a PCB)+Yes it does, so read on. At the time of writing I have finished the hardware (not got a PCB made yet, so am still using my prototype) and the Clock software is working. The NTP part is also workingThe only parts left to do are to actually have some PCBs made, and some enclosures 3D Printed.
 \\  \\ 
 \\  \\ 
Line 49: Line 49:
  
 ---- ----
- +==== Main Project Elements ==== 
-==== Hardware First ==== +  * [[The Hardware Build and Test]]\\  
-\\  +  * [[The Software Build and Test]]\\  
-I am going to assume that you have a Raspberry Pi, and have the following: +  * [[Inverted LED Display]]\\  
-\\  +  * [[The NTP Functions]]\\  
-  - A working OS +  * [[Circuit and PCB layouts]]\\  
-  - An Installation of WiringPi +  * [[Printed Circuit Photos]]\\  
-  - Working Python installation +  * [[How to save money on your PCBs]]\\ 
-  - Network Connectivity +
-\\  +
-Only when you meet the above requirements can you start this project (okay so the fourth one isn't actually required, you can just plug a keyboard and monitor in to the Pi) +
-\\  +
-\\  +
-I have decided to get the 7 Segment LED working first, then to tackle the NTP part second. This mainly because I just want to play with the 7 Segment LED, because it seems an interesting thing to do. +
-\\  +
-\\  +
- +
----- +
- +
-==== The Circuit ==== +
-\\  +
-Let's take a look at the circuit for this project. +
-\\  +
-\\  +
-{{:7_segment_led.jpg?900|}} +
-\\  +
-\\  +
-There are two Opto-Isolators to control the four digit lines. These are required because the Pi can't supply enough current (a whole 7 Segment digit using all segments requires around 40-50 mA, a GPIO pin should only sink or source around 16 mA). +
-\\  +
-\\  +
-There are 8 GPIO Pins connected to the 7 Segment LED via 330R resistors. +
-\\  +
-\\  +
-So in total there are only 12 connections to the Raspberry Pi. +
-\\  +
-\\  +
- +
----- +
-==== Opto Isolators ==== +
-\\  +
-So what do these do exactly? +
-\\  +
-{{:7_segment_led_opto_isolatorjpg.jpg?600|}} +
-\\  +
-\\  +
-You can think of these as an electrical switch, operated by light. On the left hand side of the device, you supply a small current via a resistor (that is connected to a GPIO pin) and this turns on the LED in the package, this allows a current to flow on the right hand side, this current can be much greater than the input current. This stops too much current being pulled from the Raspberry Pi. +
-\\  +
-\\  +
- +
----- +
-==== 7 Segment LED ==== +
-\\  +
-The 7 Segment LED I am using is a four digit version, with time indicator (the : in the middle) and there are many versions of these displays. Some have more pins than others, some are common Anode and some are Common Cathode. You can use Single Digit ones if you have them lying around, but you will have to common the pins together yourself. +
-\\  +
-\\  +
-{{:7segfront.jpg?300|}}{{:7segrear.jpg?300|}} +
-\\  +
-\\  +
-Common Anode vs Common Cathode - All LEDs have a positive (Anode) and negative (Cathode) connection. On a common Anode display, all the Anodes (positives) are joined together, so you can only control the negative side of the LED segments. This means you switch each segment on by connecting or disconnecting the negative pins. +
-\\  +
-\\  +
-For Common Cathode, its is the opposite. All the negatives are ganged and connected to ground. All the positives are individually controlled. +
-\\  +
-\\  +
-So what? - Well if you use Common Cathode (which I have not) life is a little easier. You see with common Anode, you can only control the negative part of the LED, so to turn an LED on, you need to make the GPIO pin go to ground (or go low, or off whatever you prefer) This means an operation to turn an LED on (on in binary is generally accepted to be a 1) requires you make the pin go low (in binary that would be a 0). +
-\\  +
-\\  +
-So with common anode all of your logic is reversed. To make an '8' you would turn on all the segments, so 1111111, but because you have to make your pins go to ground on Common Anode, you actually have to set 0000000. +
-\\  +
-\\  +
-This project is using <color red>Common Anode</color> if you want to use Common Cathode, that is fine, but you will have to change the wiring and the software. +
-\\  +
-\\  +
-{{:7segments.jpg?220|}}{{:commonanode.jpg?600|}} +
-\\  +
-Above is the connections for my 7 Segment LED Display. Mine has 12 pins. Four pins for the selection of the Digit (which number is on) and 8 pins for the individual segments. There are 8 pins because this display has a full stop after each digit. +
-\\  +
-\\  +
- +
----- +
-==== Connecting things up ==== +
-\\  +
-For this project I have used some jumper wires I purchased from eBay a while ago when doing another project. There are three main types, Male to Male, Male to Female and Female to Female, as displayed here: +
-\\  +
-\\  +
-{{ :rpijumpers.jpg?500 |}} +
-\\  +
-\\  +
-To test that everything will work as I think it will, I have used some breadboard to build my circuit on, these are really cheap from eBay (£2). +
-\\  +
-\\  +
-{{ :breadboard.jpg?300 |}} +
-\\  +
-\\  +
-Below is my connected prototype build. +
-\\  +
-\\  +
-{{ :7segprototype2.jpg?800 |}} +
-\\  +
-\\  +
-Once everything is connected we can do some basic testing. +
-\\  +
-\\  +
- +
----- +
-==== How the Hardware Works ==== +
-\\  +
-There are four digits on my display, and these can be enabled or disabled using the Pins 12(digit1), 9(digit2), 8(digit3) and 6(digit4). +
-\\  +
-\\  +
-The rest of the pins control which LED segment(s) are on. +
-\\  +
-\\  +
-Because the same pins control the segments on all the digits, we have to turn the digits on and off (or the same thing will display on all digits) So we enable digit one, set the segments we require to on (so a number is displayed) then we turn that digit off (and yes it goes off), then we repeat this process for digit2, digit3 and digit4. +
-\\  +
-\\  +
-To get the illusion that all four digits are always on, we do this process at a very high speed (100Hz) so that we can't see the segments going on and off. +
-\\  +
-\\  +
- +
----- +
- +
-==== Some Simple Testing ==== +
-\\  +
-Before trying to get the Python Script working, it would be best to verify that everything is connected correctly and working as expected. We can do this from the command line using a utility called GPIO. GPIO comes part of some software called WiringPi. +
-\\  +
-\\  +
-First check to see if Wiring Pi is installed, use the following command. +
-\\  +
-\\  +
-    gpio -v +
-\\  +
-If you get an error, you may have to install Wiring Pi: +
-\\  +
-\\  +
-    sudo apt-get install wiringpi +
-\\  +
-Once installed try gpio -v again. +
-\\  +
-\\  +
-Now try using gpio readall: +
-\\  +
-\\  +
-<file> +
- +
-gpio readall +
- +
- +
- +-----+-----+---------+------+---+-Pi Zero--+---+------+---------+-----+-----+ +
- | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM | +
- +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+ +
-            3.3v |      |    1 || 2  |        | 5v      |         | +
-   2 |   8 |   SDA.1 |   IN | 1 |  3 || 4  |        | 5V      |         | +
-   3 |   9 |   SCL.1 |   IN | 1 |  5 || 6  |        | 0v      |         | +
-   4 |   7 | GPIO. 7 |  OUT | 0 |  7 || 8  | 1 | ALT0 | TxD     | 15  | 14  | +
-              0v |      |    9 || 10 | 1 | ALT0 | RxD     | 16  | 15  | +
-  17 |   0 | GPIO. 0 |   IN | 0 | 11 || 12 | 1 | OUT  | GPIO. 1 | 1   | 18  | +
-  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |        | 0v      |         | +
-  22 |   3 | GPIO. 3 |   IN | 0 | 15 || 16 | 0 | OUT  | GPIO. 4 | 4   | 23  | +
-            3.3v |      |   | 17 || 18 | 0 | OUT  | GPIO. 5 | 5   | 24  | +
-  10 |  12 |    MOSI |   IN | 0 | 19 || 20 |        | 0v      |         | +
-   9 |  13 |    MISO |   IN | 0 | 21 || 22 | 0 | OUT  | GPIO. 6 | 6   | 25  | +
-  11 |  14 |    SCLK |   IN | 0 | 23 || 24 | 1 | IN   | CE0     | 10  | 8   | +
-              0v |      |   | 25 || 26 | 1 | IN   | CE1     | 11  | 7   | +
-   0 |  30 |   SDA.0 |   IN | 1 | 27 || 28 | 1 | IN   | SCL.0   | 31  | 1   | +
-   5 |  21 | GPIO.21 |  OUT | 0 | 29 || 30 |        | 0v      |         | +
-   6 |  22 | GPIO.22 |  OUT | 0 | 31 || 32 | 0 | IN   | GPIO.26 | 26  | 12  | +
-  13 |  23 | GPIO.23 |  OUT | 1 | 33 || 34 |        | 0v      |         | +
-  19 |  24 | GPIO.24 |  OUT | 0 | 35 || 36 | 0 | OUT  | GPIO.27 | 27  | 16  | +
-  26 |  25 | GPIO.25 |  OUT | 0 | 37 || 38 | 0 | OUT  | GPIO.28 | 28  | 20  | +
-              0v |      |   | 39 || 40 | 1 | OUT  | GPIO.29 | 29  | 21  | +
- +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+ +
- | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM | +
- +-----+-----+---------+------+---+-Pi Zero--+---+------+---------+-----+-----+ +
-</file> +
-\\  +
-\\  +
-Now we can test the GPIO functionality. For this we will again use the GPIO command. +
-\\  +
-\\  +
-<color red>Warning</color> The GPIO pins can be addressed using their <color red>GPIO</color> number (so GPIO18 for example) or by their actual <color red>physical</color> pin number (GPIO18 is on physical pin 12. +
-\\  +
-\\  +
-I always use what is reffered to as <color red>BCM</color> numbers, which is the GPIO Number, not the physical pin number. +
-\\  +
-\\  +
-In the circuit diagram we can see that four GPIO lines control the Digits. These are: +
-\\  +
-<file> +
-GPIO18 - Digit1 - Connected to pin12 +
-GPIO23 - Digit2 - Connected to pin16 +
-GPIO24 - Digit3 - Connected to pin18 +
-GPIO25 - Digit4 - Connected to pin22 +
-</file> +
-\\  +
-We also have 8 GPIO lines to control each Segment. These are: +
-\\  +
-<file> +
-GPIO5  - Segment a - Connected to pin29 +
-GPIO6  - Segment b - Connected to pin31 +
-GPIO13 - Segment c - Connected to pin33 +
-GPIO19 - Segment d - Connected to pin35 +
-GPIO26 - Segment e - Connected to pin37 +
-GPIO21 - Segment f - Connected to pin40 +
-GPIO16 - Segment g - Connected to pin38 +
-GPIO20 - Segment h - Connected to pin36 +
-</file> +
-\\  +
-So first of all we will set the mode of the pins we are using to 'OUTPUT' +
-\\  +
-\\  +
-From the command line, enter the following: (the -g means we are using BCM GPIO numbers, if you leave off the -g you are using 'physical pin' numbers). +
-\\  +
-\\  +
-<file> +
-gpio -g mode 18 out +
-gpio -g mode 23 out +
-gpio -g mode 24 out +
-gpio -g mode 25 out +
-</file> +
-\\  +
-This sets the digit control pins to 'Output' mode. <color red>You probably won't see anything happen to your LEDs yet</color>+
-\\  +
-\\  +
-Now we can do the same for the GPIO Segment connections. +
-\\  +
-<file> +
-gpio -g mode  5 out +
-gpio -g mode  6 out +
-gpio -g mode 13 out +
-gpio -g mode 19 out +
-gpio -g mode 26 out +
-gpio -g mode 21 out +
-gpio -g mode 20 out +
-gpio -g mode 16 out +
-</file> +
-\\  +
-Next we will turn on all of the digits (by making the pins go 'high' binary '1') <color red>All we are doing setting the digits to active, nothing will happen until the next step when we start to turn on the LED Segments</color> +
-\\  +
-\\  +
-<file> +
-gpio -g write 18 1 +
-gpio -g write 23 1 +
-gpio -g write 24 1 +
-gpio -g write 25 1 +
-</file> +
-\\  +
-Now we can start to to turn on the segments, I would do this one at a time by turning a segment on, then off and moving on to the next segment. This way you can tell if you are only turning on a single segment at a time. +
-\\  +
-\\  +
-Enter this line: +
-\\  +
-\\  +
-    gpio -g write 5 1 +
-\\  +
-\\  +
  
  
raspberry_pi_led_clock_and_ntp_server.1485102401.txt.gz · Last modified: 2023/03/09 22:35 (external edit)