{"id":14042,"date":"2016-05-19T11:00:15","date_gmt":"2016-05-19T18:00:15","guid":{"rendered":"https:\/\/blog.digilentinc.com\/?p=14042"},"modified":"2021-06-16T14:13:11","modified_gmt":"2021-06-16T21:13:11","slug":"how-to-use-the-pmodoledrgb-display-with-chipkit-microcontroller-boards","status":"publish","type":"post","link":"https:\/\/digilent.com\/blog\/how-to-use-the-pmodoledrgb-display-with-chipkit-microcontroller-boards\/","title":{"rendered":"How to Use the PmodOLEDrgb Display with chipKIT Microcontroller Boards"},"content":{"rendered":"<figure id=\"attachment_14158\" aria-describedby=\"caption-attachment-14158\" style=\"width: 339px\" class=\"wp-caption alignright\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-14158 size-full\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/05\/chiKIT-pro-mx7-snip-for-blog.png\" alt=\"chiKIT pro mx7 snip for blog\" width=\"339\" height=\"407\" data-wp-pid=\"14158\" \/><figcaption id=\"caption-attachment-14158\" class=\"wp-caption-text\">chipKIT board with PmodOLEDrgb.<\/figcaption><\/figure>\n<p>Although this blog post will specifically detail how to use the <a href=\"https:\/\/digilent.com\/shop\/pmodoledrgb-96-x-64-rgb-oled-display-with-16-bit-color-resolution\/\">PmodOLEDrgb<\/a>\u00a0with the <a href=\"https:\/\/digilent.com\/shop\/chipkit-mx3-microcontroller-board-with-pmod-headers\/\">chipKIT MX3<\/a>, it will also be very useful for getting the PmodOLEDrgb up and running and communicating via SPI on most of our chipKIT boards. The example provided here will cover how to get set up with the necessary software, how to properly connect the hardware, and how to use some simple library functions to draw shapes on the display.<\/p>\n<hr \/>\n<p>And it happens to be a great time to try this out during our <a href=\"https:\/\/digilent.com\/shop\/pmod-peripheral-modules\/\">Pmod Summer Sale!<\/a><\/p>\n<hr \/>\n<p>The PmodOLEDrgb is a 19.99$ RGB organic LED display that plugs nicely into any Pmod host port. Pmod host ports can be found on three different chipKIT boards. They are the chipKIT MX3, <a href=\"https:\/\/digilent.com\/shop\/chipkit-pro-mx4-embedded-systems-trainer-board\/\">chipKIT Pro MX4<\/a>\u00a0and <a href=\"https:\/\/digilent.com\/shop\/chipkit-pro-mx7-advanced-peripherals-embedded-systems-trainer-board\/\">chipKIT Pro MX7<\/a>. Additionally, the <a href=\"https:\/\/digilent.com\/shop\/chipkit-pmod-shield-adapter-board-for-uno-r3-standard-to-pmod\/\">chipKIT Pmod Shield<\/a>\u00a0can be used with the <a href=\"https:\/\/digilent.com\/shop\/chipkit-uc32-basic-microcontroller-board-with-uno-r3-headers\/\">chipKIT uC32<\/a>\u00a0and <a href=\"https:\/\/digilent.com\/shop\/chipkit-wf32-wifi-enabled-microntroller-board-with-uno-r3-headers\/\">chipKIT WF32<\/a>\u00a0to conveniently add Pmod host ports. If your board is either the <a href=\"https:\/\/digilent.com\/shop\/chipkit-max32-microcontroller-board-with-mega-r3-headers\/\">chipKIT Max32<\/a>\u00a0or the <a href=\"https:\/\/digilent.com\/shop\/chipkit-wi-fire-wifi-enabled-mz-microcontroller-board\/\">chipKIT Wi-FIRE<\/a>\u00a0then some extra wires will be needed. All chipKIT boards feature a 32-bit PIC32 microcontroller from the Microchip PIC32MX or PIC32MZ microcontroller families.<\/p>\n<p><strong>Software and Libraries<\/strong><\/p>\n<p>You will need MPIDE downloaded in order to follow this example; you can get that\u00a0<a href=\"http:\/\/chipkit.net\/started\/install-chipkit-software\/\">here<\/a>. We also have an Instructable (<a href=\"http:\/\/www.instructables.com\/id\/Uploading-Code-with-MPIDE\/?ALLSTEPS\">Uploading Code with MPIDE<\/a>)\u00a0that goes step by step through how to download the software and get up and running with any chipKIT board. I extracted the MPIDE ZIP file to my Documents folder.<\/p>\n<p><strong>Steps:<\/strong><\/p>\n<p>Install the PmodOLEDrgb libraries <a href=\"https:\/\/digilent.com\/reference\/_media\/pmod:pmod:oledrgb:pmodoledrgb_lib_mpide.zip\">here<\/a>.<\/p>\n<p>Extract\u00a0<strong>pmodoledrgb_lib_mpide.zip<\/strong><\/p>\n<p>Copy the &#8220;OLEDrgb&#8221; folder into your\u00a0<strong>Documents&gt;mpide&gt;libraries<\/strong>\u00a0folder. If this folder doesn&#8217;t exist, open up MPIDE to automatically generate the folders.<\/p>\n<p>Once it is copied, restart MPIDE and click the\u00a0<strong>Open<\/strong>\u00a0button. You should see\u00a0<strong>OLEDrgb<\/strong><strong>\u00a0<\/strong>in the drop down menu as depicted below.<\/p>\n<figure id=\"attachment_14043\" aria-describedby=\"caption-attachment-14043\" style=\"width: 595px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-14043 size-full\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/05\/MPIDE-Open-dropdown.jpg\" alt=\"MPIDE Open dropdown\" width=\"595\" height=\"402\" data-wp-pid=\"14043\" \/><figcaption id=\"caption-attachment-14043\" class=\"wp-caption-text\">After following the above steps you should see PmodOLEDrgb in the Open button drop down menu.<\/figcaption><\/figure>\n<p>This PmodOLEDrgb library contains several useful functions that make interfacing with the PmodOLEDrgb much simpler. It takes care of all of the timing and individual SPI transmissions that happen between your board and the Pmod.<\/p>\n<p><strong>Connecting the Hardware<\/strong><\/p>\n<p>This is what tripped me up at first. What\u2019s important to know is that the PmodOLEDrgb library uses the DSPI0 object class, which is not part of the standard SPI library, but rather part of the Digilent SPI library (DSPI). What this functionally means is that when using the PmodOLEDrgb library, the PmodOLEDrgb must be plugged into an SPI port that is accessed by DSPI0. On the chipKIT Pro MX3, this is found on Pmod port JE, as seen in the image below. If you are using a different chipKIT board, please refer to table 1 for a useful breakdown of which SPI ports are accessible by DSPI0 on each board. Note that there are two for which the PmodOLEDrgb library will not work without further tweaking of the code.<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"133\"><strong>chipKIT board<\/strong><\/td>\n<td width=\"128\"><strong>DSPI0<\/strong><\/td>\n<td width=\"118\"><strong>SPI port <\/strong><\/td>\n<td width=\"134\"><strong>RM section<\/strong><\/td>\n<td width=\"109\"><strong>Has Pmod Ports<\/strong><\/td>\n<td width=\"98\"><strong>\u00a0Pmod Shield Compatible<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"133\">Max 32<\/td>\n<td width=\"128\">SPI2A<\/td>\n<td width=\"118\">J13<\/td>\n<td width=\"134\">3.5 Peripheral I\/O Functions<\/td>\n<td width=\"109\">No<\/td>\n<td width=\"98\">No<\/td>\n<\/tr>\n<tr>\n<td width=\"133\">Uc32<\/td>\n<td width=\"128\">Not supported<\/td>\n<td width=\"118\">n\/a<\/td>\n<td width=\"134\">3.5 Peripheral I\/O Functions<\/td>\n<td width=\"109\">No<\/td>\n<td width=\"98\">Yes<\/td>\n<\/tr>\n<tr>\n<td width=\"133\">MX3<\/td>\n<td width=\"128\">Not supported<\/td>\n<td width=\"118\">n\/a<\/td>\n<td width=\"134\">7 Serial Peripheral Interface (SPI)<\/td>\n<td width=\"109\">Yes<\/td>\n<td width=\"98\">No<\/td>\n<\/tr>\n<tr>\n<td width=\"133\">Pro MX4<\/td>\n<td width=\"128\">SPI2<\/td>\n<td width=\"118\">JB<\/td>\n<td width=\"134\">10 Serial Peripheral Interface (SPI)<\/td>\n<td width=\"109\">Yes<\/td>\n<td width=\"98\">No<\/td>\n<\/tr>\n<tr>\n<td width=\"133\">WiFire<\/td>\n<td width=\"128\">SPI2<\/td>\n<td width=\"118\">J7<\/td>\n<td width=\"134\">10.3 SPI<\/td>\n<td width=\"109\">No<\/td>\n<td width=\"98\">No<\/td>\n<\/tr>\n<tr>\n<td width=\"133\">WF32<\/td>\n<td width=\"128\">SPI2<\/td>\n<td width=\"118\">J10<\/td>\n<td width=\"134\">10.2 SPI<\/td>\n<td width=\"109\">No<\/td>\n<td width=\"98\">Yes<\/td>\n<\/tr>\n<tr>\n<td width=\"133\">Pro MX7<\/td>\n<td width=\"128\">SPI1<\/td>\n<td width=\"118\">JD<\/td>\n<td width=\"134\">10 Serial Peripheral Interface (SPI)<\/td>\n<td width=\"109\">Yes<\/td>\n<td width=\"98\">No<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Table 1 showing which ports on which chipKIT boards will function smoothly with the PmodOLEDrgb library as well as a breakdown of which boards have Pmod host ports and which will work with the chipKIT Pmod shield.<\/p>\n<p><strong>Drawing Shapes on the Display<\/strong><\/p>\n<p>Open MPIDE (if it isn\u2019t already) and create a new sketch by clicking\u00a0<strong>Open,<\/strong><strong>\u00a0<\/strong>scrolling down to\u00a0<strong>1.Basics<\/strong>, and opening the\u00a0<strong>BareMinimum<\/strong>\u00a0project.<\/p>\n<p>Go to\u00a0<strong>File<\/strong>\u00a0and click\u00a0<strong>Save As.<\/strong><strong>\u00a0<\/strong>Name and save it. Next we need to include the necessary libraries. Add the following lines to the beginning of your program:<\/p>\n<p>#include &lt;DSPI.h&gt;<br \/>\n#include &lt;OLEDrgb.h&gt;<\/p>\n<p>Oledrgb OLEDrgb;<\/p>\n<p>This will include the SPI and the OLEDrgb libraries, and will instantiate an Oledrgb object named OLEDrgb. Inside the setup() function, add the following line:<\/p>\n<p>OLEDrgb.begin();<\/p>\n<p>This function goes through the powering on sequence and configuration that the PmodOLEDrgb must go through to operate correctly. It should look like the image below .<\/p>\n<figure id=\"attachment_14044\" aria-describedby=\"caption-attachment-14044\" style=\"width: 629px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-14044 size-full\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/05\/new-MPIDE-sketch-with-OLEDrgb-libraries-included.jpg\" alt=\"new MPIDE sketch with OLEDrgb libraries included\" width=\"629\" height=\"707\" data-wp-pid=\"14044\" srcset=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/05\/new-MPIDE-sketch-with-OLEDrgb-libraries-included.jpg 629w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/05\/new-MPIDE-sketch-with-OLEDrgb-libraries-included-534x600.jpg 534w\" sizes=\"auto, (max-width: 629px) 100vw, 629px\" \/><figcaption id=\"caption-attachment-14044\" class=\"wp-caption-text\">Example MPIDE code showing powering on sequence and inclusion of necessary libraries.<\/figcaption><\/figure>\n<p>You can find several functions within the OLEDrgb.c file included in the library. These functions include DrawPixel, DrawLine, DrawRectangle, and DrawBitmap. There is also a helper function called BuildRGB (red,green,blue), this formats the RGB color into 2 bytes that can be read by the PmodOLEDrgb.<\/p>\n<p>Calling OLEDrgb.DrawPixel(50, 15, OLEDrgb.BuildRGB(255, 0, 0)) will draw a pixel at coordinate\u00a0<strong>(50,15)<\/strong>\u00a0colored\u00a0<strong>red<\/strong>.<\/p>\n<p>Calling OLEDrgb.DrawLine(10, 20, 45, 5, OLEDrgb.BuildRGB(0, 255, 0)) will draw a line from\u00a0<strong>(10,20)<\/strong><strong>\u00a0<\/strong>to\u00a0<strong>(45, 5)<\/strong><strong>\u00a0<\/strong>colored\u00a0<strong>green<\/strong>.<\/p>\n<p>Calling OLEDrgb.DrawRectangle(10, 20, 80, 60, OLEDrgb.BuildRGB(0, 255, 0), true, OLEDrgb.BuildRGB(0,0,255)) will draw a\u00a0<strong>green<\/strong>\u00a0rectangle from\u00a0<strong>(10,20)<\/strong>\u00a0to\u00a0<strong>(80,60)<\/strong>.\u00a0<strong>True<\/strong><strong>\u00a0<\/strong>signifies that it will be filled in, and the last parameter sets that the fill will be\u00a0<strong>blue.<\/strong><\/p>\n<figure id=\"attachment_14045\" aria-describedby=\"caption-attachment-14045\" style=\"width: 630px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-14045 size-full\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/05\/MPIDE-simple-draw-functions-for-OLEDrgb.jpg\" alt=\"MPIDE simple draw functions for OLEDrgb\" width=\"630\" height=\"710\" data-wp-pid=\"14045\" srcset=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/05\/MPIDE-simple-draw-functions-for-OLEDrgb.jpg 630w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/05\/MPIDE-simple-draw-functions-for-OLEDrgb-532x600.jpg 532w\" sizes=\"auto, (max-width: 630px) 100vw, 630px\" \/><figcaption id=\"caption-attachment-14045\" class=\"wp-caption-text\">Example code to draw a dot, line and rectangle on the display simultaneously.<\/figcaption><\/figure>\n<p>Plug your chipKIT board into your computer via USB and select it in MPIDE by clicking\u00a0<strong>Tools&gt;Board&gt;chipKIT&gt;chipKIT MX3 <\/strong><strong>(or other chipKIT board)<\/strong>. Select the serial port that your board is plugged into by clicking\u00a0<strong>Tools&gt;Serial Port&gt;COM_\u00ad\u00ad__<\/strong>. In order to know which serial port to select, check the device manager on your PC for which port is dedicated to the USB interface. Once you are all set up, click the\u00a0<strong>Upload<\/strong>\u00a0button to upload it to your board! You should see some combination of the image below depending on whether or not you included all three example functions.<\/p>\n<figure id=\"attachment_14046\" aria-describedby=\"caption-attachment-14046\" style=\"width: 640px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-14046 size-full\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/05\/oledrgb-with-square-line-dot.jpg\" alt=\"oledrgb with square, line, dot\" width=\"640\" height=\"480\" data-wp-pid=\"14046\" srcset=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/05\/oledrgb-with-square-line-dot.jpg 640w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/05\/oledrgb-with-square-line-dot-600x450.jpg 600w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><figcaption id=\"caption-attachment-14046\" class=\"wp-caption-text\">Final product of above code.<\/figcaption><\/figure>\n<p>Hopefully this was useful in getting started with the PmodOLEDrgb and chipKIT PIC32 products. For more information, as well as instructions on how to display a bitmap, see our <a href=\"http:\/\/www.instructables.com\/id\/Programming-the-PmodOLEDrgb-on-the-ChipKIT-Pro-MX7\/\">Instructable<\/a> on Programming the PmodOLEDrgb on the <a href=\"https:\/\/digilent.com\/shop\/chipkit-pro-mx7-advanced-peripherals-embedded-systems-trainer-board\/\">ChipKIT Pro MX7<\/a>. For more information on any of the products used here, please visit our <a href=\"http:\/\/reference.blog.digilentinc.com\">Wiki<\/a>.<\/p>\n<p>And don&#8217;t forget to check out our <a href=\"https:\/\/digilent.com\/shop\/pmod-peripheral-modules\/\">Pmod Summer Sale<\/a> for a great price on the PmodOLEDrgb!<\/p>\n<div class='watch-action'><div class='watch-position align-left'><div class='action-like'><a class='lbg-style6 like-14042 jlk' data-task='like' data-post_id='14042' data-nonce='05046dc8ab' rel='nofollow'><img src='https:\/\/digilent.com\/blog\/wp-content\/plugins\/wti-like-post-pro\/images\/pixel.gif' title='Like' \/><span class='lc-14042 lc'>0<\/span><\/a><\/div><div class='action-unlike'><a class='unlbg-style6 unlike-14042 jlk' data-task='unlike' data-post_id='14042' data-nonce='05046dc8ab' rel='nofollow'><img src='https:\/\/digilent.com\/blog\/wp-content\/plugins\/wti-like-post-pro\/images\/pixel.gif' title='Unlike' \/><span class='unlc-14042 unlc'>0<\/span><\/a><\/div><\/div> <div class='status-14042 status align-left'>Be the 1st to vote.<\/div><\/div><div class='wti-clear'><\/div>","protected":false},"excerpt":{"rendered":"<p>Talesa takes you through how to get the  PmodOLEDrgb up and running with our chipKIT boards.<\/p>\n","protected":false},"author":26,"featured_media":14046,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[38,1563],"tags":[],"ppma_author":[4491],"class_list":["post-14042","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-expansion-modules","category-guide"],"jetpack_featured_media_url":"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2016\/05\/oledrgb-with-square-line-dot.jpg","authors":[{"term_id":4491,"user_id":26,"is_guest":0,"slug":"talesab","display_name":"Talesa Bleything","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/4ebebd593afbf3d758e9127934708634ab09aeaa7fcfcf6151f4e9ceb9cf6d0e?s=96&d=mm&r=g","1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":"","9":"","10":""}],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts\/14042","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/users\/26"}],"replies":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/comments?post=14042"}],"version-history":[{"count":0,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts\/14042\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/media\/14046"}],"wp:attachment":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/media?parent=14042"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/categories?post=14042"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/tags?post=14042"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=14042"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}