{"id":139,"date":"2013-11-28T18:04:41","date_gmt":"2013-11-28T16:04:41","guid":{"rendered":"https:\/\/justaddelectrons.com\/blogi\/?p=139"},"modified":"2013-11-28T18:55:14","modified_gmt":"2013-11-28T16:55:14","slug":"pcb-exposure-timer-with-picaxe-microcontroller-and-lcd-display","status":"publish","type":"post","link":"https:\/\/justaddelectrons.com\/blogi\/pcb-exposure-timer-with-picaxe-microcontroller-and-lcd-display\/","title":{"rendered":"PCB exposure timer with Picaxe microcontroller and LCD display"},"content":{"rendered":"<p><a href=\"https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/exposure_timer.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-330 alignnone\" title=\"PCB exposure timer\" alt=\"exposure_timer\" src=\"https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/exposure_timer.jpg\" width=\"997\" height=\"516\" srcset=\"https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/exposure_timer.jpg 997w, https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/exposure_timer-150x77.jpg 150w, https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/exposure_timer-300x155.jpg 300w\" sizes=\"auto, (max-width: 997px) 100vw, 997px\" \/><\/a>Quite appropriately, the first board that I exposed with my <a title=\"UV led pcb exposure box\" href=\"https:\/\/justaddelectrons.com\/blogi\/uv-led-pcb-exposure-box\/\" target=\"_blank\">UV exposure box<\/a> was a timer to control the exposure. The heart of the timer is a <a href=\"http:\/\/www.picaxe.com\/Hardware\/PICAXE-Chips\/PICAXE-08M2-microcontroller\" target=\"_blank\">Picaxe 08M2<\/a> microcontroller. The timer has also an inexpensive 16&#215;2 characters LCD display (based on a HD44780 controller protocol) and a rotary encoder to set the time. The rotary includes a push button that starts and stops the timer and the exposure. An I2C I\/O expander chip <a href=\"http:\/\/www.nxp.com\/documents\/data_sheet\/PCF8574.pdf\" target=\"_blank\">PCF8574<\/a> interfaces the PICAXE to the display module to save i\/o pins on the microcontroller. This way even a small 8-pin microcontroller can be used. <!--more-->The PICAXE uses a power MOSFET transistor to switch power on and off for the UV leds.<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/exposure_timer_assembled.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-331\" title=\"PCB exposure timer assembled\" alt=\"exposure_timer_assembled\" src=\"https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/exposure_timer_assembled-1024x528.jpg\" width=\"604\" height=\"311\" srcset=\"https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/exposure_timer_assembled-1024x528.jpg 1024w, https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/exposure_timer_assembled-150x77.jpg 150w, https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/exposure_timer_assembled-300x154.jpg 300w\" sizes=\"auto, (max-width: 604px) 100vw, 604px\" \/><\/a><\/p>\n<p>The schematic is below (click to view full size).<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/exposure_timer_schematic1.jpg\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-353\" title=\"UV led pcb exposure box timer schematic part 1\" alt=\"exposure_timer_schematic1\" src=\"https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/exposure_timer_schematic1.jpg\" width=\"503\" height=\"455\" \/><\/a>\u00a0<a href=\"https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/exposure_timer_schematic2.jpg\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-311\" title=\"UV led pcb exposure box timer schematic part 2\" alt=\"exposure_timer_schematic2\" src=\"https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/exposure_timer_schematic2.jpg\" width=\"1253\" height=\"808\" srcset=\"https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/exposure_timer_schematic2.jpg 1253w, https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/exposure_timer_schematic2-150x96.jpg 150w, https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/exposure_timer_schematic2-300x193.jpg 300w, https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/exposure_timer_schematic2-1024x660.jpg 1024w\" sizes=\"auto, (max-width: 1253px) 100vw, 1253px\" \/><\/a><\/p>\n<p style=\"text-align: left;\">At the top there is the power part of the circuit. Power input is the 12 volts for the exposure box. A 78L05 regulator gives a 5V supply for the rest of the circuit. Two capacitors, 0.33uF and 0.1 uF are used to help to stabilize that supply. The IRFZ44N MOSFET acts as a switch for the UV leds. Its gate has a 1K pulldown to ground to keep the switch in off postion unless told otherwise. IRFZ44N has a low resistance when it is on and it helps keeping it cool. A heat sink is still needed. I first tried using an IRF640 MOSFET but it got really hot.<\/p>\n<p style=\"text-align: left;\">Next there is the PICAXE and its connections. The standard programming interface is at left and those pins are shared with power switch and button functionality. The PCB uses\u00a0 jumpers to disconnect the power switch and the button input when programming. 08M2 has built-in I2C bus support (the SCL and SDA pins) and it is used to communicate with the I\/O expander chip that interfaces to the LCD module. The SCL and SDA lines both need to have pull up resistors as per the bus specification. I used 4.7k ohm for those. The values do not need to be exact, and they actually depend on things like the distance between the devices on the bus and the bus speed that is being used. Google &#8220;i2c pull up values&#8221; for 800000 hits. For my case this 4.7k worked well.<\/p>\n<p style=\"text-align: left;\">The 8574 I\/O expander is being used as sort of extra input and output pins for the picaxe. The picaxe can either set or read the values of the I\/O expander&#8217;s 8 pins via the serial I2C bus (that consumes only two of the picaxe&#8217;s pins) by sending it an 8 bit byte or reading a byte value from it. In this case I&#8217;m only sending data to the LCD. An I2C bus can have several devices on it and each device needs to have a specific address associated with\u00a0 it. For 8574 this address is set by pulling a combination of pins 1, 2 and 3 either high or low. Here I have connected those all to ground.<\/p>\n<p style=\"text-align: left;\">The protocol used by Hitachi HD44780 LCD driver is a de facto standard and you can find plenty of inexpensive LCD modules that are based on it. I got mine on eBay from China for 1.75 euros. It is a two line display with 16 characters per line (16&#215;2 LCD display module). The LCD module actually has a parallel interface with 8 data pins and 3 pins for control purposes (plus pins for power, contrast and led backlight). It can also be configured to use only 4 data pins plus the three control pins. As the 8 bit I\/O expander chip has 8 output lines it is adequate for the communication. In simplified terms the communication with the LCD controller happens in two phases so that whenever a byte needs to be sent the high 4 bits are sent first on the data lines and then the low 4 bits after that. The control pins are used to indicate whether it is data or a command that is being sent as well as indicating when the data is ready to be processed.<\/p>\n<p style=\"text-align: left;\">Whenever picaxe needs to send a byte to the lcd controller there are several bytes that it needs to send to the I\/O expander. The control pins need to be toggled and each toggle requires for one byte to be sent. The low and high part of the byte both need one whole byte from picaxe to the I\/O expander. That&#8217;s shown in the attached code.<\/p>\n<p style=\"text-align: left;\">The schematic does not show the pin names for the LCD module, but they are visible in the photos below. The schematic has two trimmer pots, one for lcd contrast and the other for setting the background led brightness. Since there is one &#8220;unused&#8221; I\/O expander output it can be used to switch the background led on or off with the PN2222A transistor. That functionality is not actually being used for anything, it got there just because I copied the design from an earlier project.<\/p>\n<p style=\"text-align: left;\">The rotary encoder is a 20 position with push button, 2 bit gray code, 61 euro cent one from eBay. The rotary part has three terminals, one of which is common. The common is connected to positive supply\u00a0 with a 330 ohm resistor. The other terminals are pulled to ground with 4.7k resistors. When turning the knob each position or &#8220;click&#8221; results in both pins going first up and then down with slightly different timing.\u00a0 The direction that it is being turned to can be detected in software based on which pin goes high first. The push button part of it has a 10k pull down and a 1k limiting resistor as suggested by picaxe manuals for any switch.<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/lcd_front.jpg\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-320\" title=\"LCD module front\" alt=\"lcd_front\" src=\"https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/lcd_front-1024x601.jpg\" width=\"604\" height=\"354\" srcset=\"https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/lcd_front-1024x601.jpg 1024w, https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/lcd_front-150x88.jpg 150w, https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/lcd_front-300x176.jpg 300w\" sizes=\"auto, (max-width: 604px) 100vw, 604px\" \/><\/a><a href=\"https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/lcd_back.jpg\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-321\" title=\"LCD module back\" alt=\"lcd_back\" src=\"https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/lcd_back-1024x482.jpg\" width=\"604\" height=\"284\" srcset=\"https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/lcd_back-1024x482.jpg 1024w, https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/lcd_back-150x70.jpg 150w, https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/lcd_back-300x141.jpg 300w\" sizes=\"auto, (max-width: 604px) 100vw, 604px\" \/><\/a><a href=\"https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/rotary_encoder.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-325\" title=\"Rotary encoder\" alt=\"rotary_encoder\" src=\"https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/rotary_encoder-300x229.jpg\" width=\"300\" height=\"229\" srcset=\"https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/rotary_encoder-300x229.jpg 300w, https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/rotary_encoder-150x114.jpg 150w, https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/rotary_encoder-1024x784.jpg 1024w, https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/rotary_encoder.jpg 1940w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p style=\"text-align: left;\"><strong>The PCB<\/strong><\/p>\n<p style=\"text-align: left;\"><a href=\"https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/exposure_timer_pcb.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-309 alignnone\" title=\"UV led exposure box timer pcb\" alt=\"exposure_timer_pcb\" src=\"https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/exposure_timer_pcb-1024x745.jpg\" width=\"604\" height=\"439\" srcset=\"https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/exposure_timer_pcb-1024x745.jpg 1024w, https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/exposure_timer_pcb-150x109.jpg 150w, https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/exposure_timer_pcb-300x218.jpg 300w, https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/exposure_timer_pcb.jpg 1252w\" sizes=\"auto, (max-width: 604px) 100vw, 604px\" \/><\/a><\/p>\n<p style=\"text-align: left;\">As you can see from the photo of the assembled timer, the pcb is designed so that the LCD piggybacks on the main pcb. The data pins on the LCD align with corresponding pads on the pcb and there are matching holes for screws. A soldered 16-pin sil header (with long pins) connects the pcb to the LCD board.<\/p>\n<p style=\"text-align: left;\">The rotary encoder is on a separate small pcb to make the placement to the box easier. Getting all the needed holes to align was hard enough already.<\/p>\n<p style=\"text-align: left;\"><strong>The software<\/strong><\/p>\n<p style=\"text-align: left;\">The full code is in a zip here <a href=\"https:\/\/justaddelectrons.com\/blogi\/wp-content\/uploads\/2013\/11\/pcb_exposure_timer.zip\" target=\"_blank\">pcb_exposure_timer<\/a>.<\/p>\n<p style=\"text-align: left;\">The <a href=\"http:\/\/www.picaxeforum.co.uk\/forum.php\" target=\"_blank\">picaxe forums<\/a> are a great source of information and examples. I used the forums a lot when searching for solutions to various design problems.<\/p>\n<p style=\"text-align: left;\">At power up the LCD is initialized and a couple of screens of information gets displayed. The picaxe is set to run at 16MHz as writing text to the LCD was a little slow at slower speeds.<\/p>\n<p style=\"text-align: left;\">The software has two main loops where most of the time is spent. The first one is for waiting for user actions before the exposure has started. The user can either change the exposure time setting or start the exposure. The second loop is the exposure timer when the seconds count down on display. At that point the user can abort the exposure by a button press. The exposure time setting that was used is saved to EEPROM and used as a default the next time.<\/p>\n<p style=\"text-align: left;\">Turning of the rotary encoder gets detected in a hardware interrupt subroutine. It increments or decrements a global counter value that then gets detected and processed in the first main loop.<\/p>\n<p>The program makes use of some layers of subroutines. I have tried to make the routine names as descriptive as possible to help in understanding how the code works.<\/p>\n<p><strong>Parts list<\/strong><\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>Part<\/strong><\/td>\n<td><strong>Origin<\/strong><\/td>\n<td><strong>Cost in eur<\/strong><\/td>\n<\/tr>\n<tr>\n<td>picaxe 08M2<\/td>\n<td>picaxe.com<\/td>\n<td>1.80<\/td>\n<\/tr>\n<tr>\n<td>LCD module<\/td>\n<td>eBay<\/td>\n<td>1.75<\/td>\n<\/tr>\n<tr>\n<td>PCF8574 I\/O expander<\/td>\n<td>eBay<\/td>\n<td>0.47<\/td>\n<\/tr>\n<tr>\n<td>IRFZ44N mosfet<\/td>\n<td>eBay<\/td>\n<td>0.61<\/td>\n<\/tr>\n<tr>\n<td>78L05 regulator<\/td>\n<td>eBay<\/td>\n<td>0.20<\/td>\n<\/tr>\n<tr>\n<td>PN2222A transistor<\/td>\n<td>eBay<\/td>\n<td>0.09<\/td>\n<\/tr>\n<tr>\n<td>\u00a0Capacitors, 0.1uF and 0.33uF<\/td>\n<td>eBay<\/td>\n<td>0.05<\/td>\n<\/tr>\n<tr>\n<td>\u00a0Resistors<\/td>\n<td>eBay<\/td>\n<td>0.10<\/td>\n<\/tr>\n<tr>\n<td>\u00a0trimmer pots, 1k and 10k<\/td>\n<td>eBay<\/td>\n<td>0.36<\/td>\n<\/tr>\n<tr>\n<td>\u00a0rotary encoder<\/td>\n<td>eBay<\/td>\n<td>0.61<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td style=\"text-align: right;\">Total:<\/td>\n<td>6.04<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>Quite appropriately, the first board that I exposed with my UV exposure box was a timer to control the exposure. The heart of the timer is a Picaxe 08M2 microcontroller. The timer has also an inexpensive 16&#215;2 characters LCD display (based on a HD44780 controller protocol) and a rotary encoder to set the time. The &hellip; <a href=\"https:\/\/justaddelectrons.com\/blogi\/pcb-exposure-timer-with-picaxe-microcontroller-and-lcd-display\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">PCB exposure timer with Picaxe microcontroller and LCD display<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[11,10],"class_list":["post-139","post","type-post","status-publish","format-standard","hentry","category-tools-2","tag-diy-pcb","tag-picaxe"],"_links":{"self":[{"href":"https:\/\/justaddelectrons.com\/blogi\/wp-json\/wp\/v2\/posts\/139","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/justaddelectrons.com\/blogi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/justaddelectrons.com\/blogi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/justaddelectrons.com\/blogi\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/justaddelectrons.com\/blogi\/wp-json\/wp\/v2\/comments?post=139"}],"version-history":[{"count":40,"href":"https:\/\/justaddelectrons.com\/blogi\/wp-json\/wp\/v2\/posts\/139\/revisions"}],"predecessor-version":[{"id":355,"href":"https:\/\/justaddelectrons.com\/blogi\/wp-json\/wp\/v2\/posts\/139\/revisions\/355"}],"wp:attachment":[{"href":"https:\/\/justaddelectrons.com\/blogi\/wp-json\/wp\/v2\/media?parent=139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/justaddelectrons.com\/blogi\/wp-json\/wp\/v2\/categories?post=139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/justaddelectrons.com\/blogi\/wp-json\/wp\/v2\/tags?post=139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}