<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Search Results for &#8220;u8g2&#8221; &#8211; IoT Expert</title>
	<atom:link href="https://iotexpert.com/search/u8g2/feed/rss2/" rel="self" type="application/rss+xml" />
	<link>https://iotexpert.com</link>
	<description>Engineering for the Internet of Things</description>
	<lastBuildDate>Sun, 17 Feb 2019 16:30:26 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.7</generator>

<image>
	<url>https://iotexpert.com/wp-content/uploads/2017/01/cropped-Avatar-32x32.jpg</url>
	<title>Search Results for &#8220;u8g2&#8221; &#8211; IoT Expert</title>
	<link>https://iotexpert.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>MBED OS &#038; PSoC 6 &#038; SSD1306</title>
		<link>https://iotexpert.com/mbed-os-psoc-6-ssd1306/</link>
					<comments>https://iotexpert.com/mbed-os-psoc-6-ssd1306/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Sun, 17 Feb 2019 16:29:44 +0000</pubDate>
				<category><![CDATA[4343W]]></category>
		<category><![CDATA[CY8CPROTO-062-4343W]]></category>
		<category><![CDATA[Embedded World 2019]]></category>
		<category><![CDATA[MBED OS]]></category>
		<category><![CDATA[PSoC 6]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=6600</guid>

					<description><![CDATA[Summary As I wrote about in the last article I have been working to get ready for Embedded World 2019 in a week and a bit.  For my demo, I will be handing out remote controls that have a 128&#215;64 monochrome OLED display that is driven by an I2C SSD1306.  This whole board is controlled [&#8230;]]]></description>
										<content:encoded><![CDATA[<h1>Summary</h1>
<p>As I wrote about in the <a href="https://iotexpert.com/2019/02/11/mbedos-ble/" target="_blank" rel="noopener">last article</a> I have been working to get ready for Embedded World 2019 in a week and a bit.  For my demo, I will be handing out remote controls that have a 128&#215;64 monochrome OLED display that is driven by an I2C SSD1306.  This whole board is controlled by a PSoC 6 &amp; a 4343W WiFi / Bluetooth Combo.</p>
<p><a href="https://iotexpert.com/2019/02/17/mbed-os-psoc-6-ssd1306/img_0227/" rel="attachment wp-att-6602"><img fetchpriority="high" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/02/IMG_0227-e1550413744346-493x1024.jpg" alt="" width="493" height="1024" class="alignnone size-large wp-image-6602" srcset="https://iotexpert.com/wp-content/uploads/2019/02/IMG_0227-e1550413744346-493x1024.jpg 493w, https://iotexpert.com/wp-content/uploads/2019/02/IMG_0227-e1550413744346-600x1246.jpg 600w, https://iotexpert.com/wp-content/uploads/2019/02/IMG_0227-e1550413744346-144x300.jpg 144w, https://iotexpert.com/wp-content/uploads/2019/02/IMG_0227-e1550413744346-768x1595.jpg 768w, https://iotexpert.com/wp-content/uploads/2019/02/IMG_0227-e1550413744346-scaled.jpg 1233w" sizes="(max-width: 493px) 100vw, 493px" /></a></p>
<p>This morning I started to port the <a href="https://iotexpert.com/?s=u8g2" target="_blank" rel="noopener">U8G2</a> library to MBEDOS&#8230; but ran into some problems, so I i decided to see what ports were already out there.  I immediately found a port of the <a href="https://os.mbed.com/users/nkhorman/code/Adafruit_GFX/" target="_blank" rel="noopener">Adafruit_GFX library</a>.  This article talks about using it on my CY8CPROTO_062_4343W board.  As part of this journey I also wanted to be able to draw the Cypress logo on the screen&#8230; so I had to figure out how to create a logo in a format that could be drawn on the screen.</p>
<p>I will follow these steps:</p>
<ol>
<li>Create a new project &amp; add the Adafruit_GFX_library</li>
<li>Create a main.cpp, configure the library and test</li>
<li>Make a Cypress logo using GIMP</li>
<li>Create a function to draw X11 bitmaps &amp; test</li>
</ol>
<h1>Create a new project &amp; add the Adafruit_GFX_library</h1>
<p>The first step to get everything going by running</p>
<ol>
<li>mbed new .</li>
<li>mbed add http://os.mbed.com/users/nkhorman/code/Adafruit_GFX/</li>
</ol>
<p><a href="https://iotexpert.com/2019/02/17/mbed-os-psoc-6-ssd1306/screen-shot-2019-02-17-at-9-41-48-am/" rel="attachment wp-att-6603"><img decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-9.41.48-AM.png" alt="" width="797" height="465" class="alignnone size-full wp-image-6603" srcset="https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-9.41.48-AM.png 797w, https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-9.41.48-AM-600x350.png 600w, https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-9.41.48-AM-300x175.png 300w, https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-9.41.48-AM-768x448.png 768w" sizes="(max-width: 797px) 100vw, 797px" /></a></p>
<p>The way to figure out how to add the library is by going to the library webpage on the mbedos website.  Then clicking the arrow on &#8220;Import into Compiler&#8221; where you will see two options, &#8220;Import into Compiler&#8221; and &#8220;Import with mbed CLI&#8221;</p>
<p><a href="https://iotexpert.com/2019/02/17/mbed-os-psoc-6-ssd1306/screen-shot-2019-02-17-at-9-41-03-am/" rel="attachment wp-att-6606"><img decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-9.41.03-AM-1024x278.png" alt="" width="1024" height="278" class="alignnone size-large wp-image-6606" srcset="https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-9.41.03-AM-1024x278.png 1024w, https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-9.41.03-AM-600x163.png 600w, https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-9.41.03-AM-300x81.png 300w, https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-9.41.03-AM-768x209.png 768w, https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-9.41.03-AM.png 1182w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>When you select that option you will get a window that tells you the exact command to run.</p>
<p><a href="https://iotexpert.com/2019/02/17/mbed-os-psoc-6-ssd1306/screen-shot-2019-02-17-at-9-41-15-am/" rel="attachment wp-att-6605"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-9.41.15-AM.png" alt="" width="402" height="161" class="alignnone size-large wp-image-6605" srcset="https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-9.41.15-AM.png 402w, https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-9.41.15-AM-300x120.png 300w" sizes="(max-width: 402px) 100vw, 402px" /></a></p>
<p>I have been using <a href="https://atom.io" target="_blank" rel="noopener">Atom</a> as an editor (and sort of IDE).  When you open the lcd-example directory using Atom you will see your project including</p>
<ol>
<li>The mbed-os directory with all of the mbed stuff in it.</li>
<li>The Adafruit_GFX library</li>
</ol>
<p><a href="https://iotexpert.com/2019/02/17/mbed-os-psoc-6-ssd1306/screen-shot-2019-02-17-at-9-46-14-am/" rel="attachment wp-att-6609"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-9.46.14-AM.png" alt="" width="815" height="662" class="alignnone size-full wp-image-6609" srcset="https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-9.46.14-AM.png 815w, https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-9.46.14-AM-600x487.png 600w, https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-9.46.14-AM-300x244.png 300w, https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-9.46.14-AM-768x624.png 768w" sizes="(max-width: 815px) 100vw, 815px" /></a></p>
<h1>Create a main.cpp, configure the library and test</h1>
<p>The next step is to create a main.cpp.</p>
<ol>
<li>Setup the I2C.  In order to use the graphics library you need to setup a communication vehicle.  In my case that is an I2C bus that is connected to P6[0] and P6[1] on my development board.  Lines 6-15 create the communication class of I2CPreInit, configure it to 400kbs and connect the I2C master to P6[0]/P6[1]</li>
<li>Line 16 actually setups up the graphics library and get it going.</li>
<li>The main simply prints out some information about the display on lines 22-23</li>
<li>Line 24 causes the current frame buffer to be displayed (more on this in a second)</li>
<li>The main loop blinks the LED and prints a counter on the top of the screen.</li>
</ol>
<pre class="lang:c++ decode:true">#include "mbed.h"
#include "Adafruit_SSD1306.h"

DigitalOut myled(LED1);

class I2CPreInit : public I2C
{
public:
    I2CPreInit(PinName sda, PinName scl) : I2C(sda, scl)
    {
        frequency(400000);
        start();
    };
};
I2CPreInit gI2C(P6_1,P6_0);
Adafruit_SSD1306_I2c gOled2(gI2C,P0_2,0x78,64,128);

int main()
{   uint16_t x=0;

    printf("Started\n");
    printf("%ux%u OLED Display\r\n", gOled2.width(), gOled2.height());
    printf("Rotation = %u\n",gOled2.getRotation());
    gOled2.display();
    while(1)
    {
        x += 1;
        myled = !myled;
        gOled2.printf("%u\r",x);
        gOled2.display();
        wait(1.0);
    }
}
</pre>
<p>In order to build this thing I run &#8220;mbed compile -t GCC_ARM -m CY8CPROTO_062_4343w&#8221;.  When I run the project it looks like this:</p>
<p><a href="https://iotexpert.com/2019/02/17/mbed-os-psoc-6-ssd1306/img_0228/" rel="attachment wp-att-6612"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/02/IMG_0228-e1550416310771-1024x768.jpg" alt="" width="1024" height="768" class="alignnone wp-image-6612 size-large" srcset="https://iotexpert.com/wp-content/uploads/2019/02/IMG_0228-e1550416310771-1024x768.jpg 1024w, https://iotexpert.com/wp-content/uploads/2019/02/IMG_0228-e1550416310771-600x450.jpg 600w, https://iotexpert.com/wp-content/uploads/2019/02/IMG_0228-e1550416310771-300x225.jpg 300w, https://iotexpert.com/wp-content/uploads/2019/02/IMG_0228-e1550416310771-768x576.jpg 768w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>There are several things to notice about this picture.  First, there is an Adafruit logo on the screen.  Where did this come from?  Simple on line 152 of Adafruit_ssd1306.cpp there is a function called &#8220;splash&#8221; which is called by the constructor.  The spash function just copies a bitmap into the frame buffer of the Adafruit_SSD1306 object.</p>
<pre class="start-line:152 EnlighterJSRAW" data-enlighter-language="c" ">void Adafruit_SSD1306::splash(void)
{
#ifndef NO_SPLASH_ADAFRUIT
	uint8_t adaFruitLogo[64 * 128 / 8] =
	{ 
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
</pre>
<p>The constructor is in Adafruit_ssd1306.h on line 152</p>
<pre class="start-line:173 lang:c++ decode:true ">	Adafruit_SSD1306_I2c(I2C &amp;i2c, PinName RST, uint8_t i2cAddress = SSD_I2C_ADDRESS, uint8_t rawHeight = 32, uint8_t rawWidth = 128)
	    : Adafruit_SSD1306(RST, rawHeight, rawWidth)
	    , mi2c(i2c)
	    , mi2cAddress(i2cAddress)
	    {
		    begin();
		    splash();
		    display();
	    };</pre>
<p>And if you don&#8217;t want to have this splash screen you can uncomment the #define NO_SPLASH_ADAFRUIT in the file &#8220;Adafruit_GFC_Config.h&#8221;</p>
<pre class="lang:c++ decode:true ">#ifndef _ADAFRUIT_GFX_CONFIG_H_
#define _ADAFRUIT_GFX_CONFIG_H_

// Uncomment this to turn off the builtin splash
#define NO_SPLASH_ADAFRUIT

// Uncomment this to enable all functionality
//#define GFX_WANT_ABSTRACTS

// Uncomment this to enable only runtime font scaling, without all the rest of the Abstracts
//#define GFX_SIZEABLE_TEXT


#endif</pre>
<p>The next thing to notice in the picture is that I have lead wires attached to the LCD pins&#8230; and those wires are attached to a logic analyzer because I typed the I2C incorrectly and I couldn&#8217;t figure out why they didn&#8217;t talk.  And finally notice my grandfathers magnifying glass which I use every day.</p>
<h1>Make a Cypress logo using GIMP</h1>
<p>For my project I am less interested in displaying Adafruits Logo and more interested in displaying Cypress&#8217;.  To do this I loaded up the Cypress logo in <a href="https://www.gimp.org" target="_blank" rel="noopener">Gimp</a>.</p>
<p><a href="https://iotexpert.com/2019/02/17/mbed-os-psoc-6-ssd1306/screen-shot-2019-02-17-at-10-22-23-am/" rel="attachment wp-att-6614"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.22.23-AM-1024x658.png" alt="" width="1024" height="658" class="alignnone size-large wp-image-6614" srcset="https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.22.23-AM-1024x658.png 1024w, https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.22.23-AM-600x385.png 600w, https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.22.23-AM-300x193.png 300w, https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.22.23-AM-768x493.png 768w, https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.22.23-AM.png 1194w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>I then converted it to pure black and white using the &#8220;Image-&gt;Mode-&gt;Indexed&#8230;&#8221;</p>
<p><a href="https://iotexpert.com/2019/02/17/mbed-os-psoc-6-ssd1306/screen-shot-2019-02-17-at-10-23-11-am/" rel="attachment wp-att-6616"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.23.11-AM.png" alt="" width="438" height="156" class="alignnone size-large wp-image-6616" srcset="https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.23.11-AM.png 438w, https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.23.11-AM-300x107.png 300w" sizes="(max-width: 438px) 100vw, 438px" /></a></p>
<p>Then selected &#8220;black and white palette&#8221;</p>
<p><a href="https://iotexpert.com/2019/02/17/mbed-os-psoc-6-ssd1306/screen-shot-2019-02-17-at-10-23-23-am/" rel="attachment wp-att-6615"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.23.23-AM.png" alt="" width="367" height="395" class="alignnone size-full wp-image-6615" srcset="https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.23.23-AM.png 367w, https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.23.23-AM-279x300.png 279w" sizes="(max-width: 367px) 100vw, 367px" /></a></p>
<p>Then I scaled the image to 128&#215;40 using the &#8220;Image-&gt;Scale Image&#8221;</p>
<p><a href="https://iotexpert.com/2019/02/17/mbed-os-psoc-6-ssd1306/screen-shot-2019-02-17-at-10-25-10-am/" rel="attachment wp-att-6619"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.25.10-AM.png" alt="" width="226" height="194" class="alignnone size-large wp-image-6619" /></a></p>
<p><a href="https://iotexpert.com/2019/02/17/mbed-os-psoc-6-ssd1306/screen-shot-2019-02-17-at-10-25-22-am/" rel="attachment wp-att-6618"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.25.22-AM.png" alt="" width="380" height="385" class="alignnone size-large wp-image-6618" srcset="https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.25.22-AM.png 380w, https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.25.22-AM-100x100.png 100w, https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.25.22-AM-296x300.png 296w" sizes="(max-width: 380px) 100vw, 380px" /></a></p>
<p>Unfortunately it made a bit of a mess of the logo during the scaling process&#8230; so I put my son to editing it.</p>
<p><a href="https://iotexpert.com/2019/02/17/mbed-os-psoc-6-ssd1306/screen-shot-2019-02-17-at-10-25-52-am/" rel="attachment wp-att-6617"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.25.52-AM.png" alt="" width="654" height="390" class="alignnone size-full wp-image-6617" srcset="https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.25.52-AM.png 654w, https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.25.52-AM-600x358.png 600w, https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.25.52-AM-300x179.png 300w" sizes="(max-width: 654px) 100vw, 654px" /></a></p>
<p>Which looks like this after he was done.  Pretty good eh?</p>
<p><a href="https://iotexpert.com/2019/02/17/mbed-os-psoc-6-ssd1306/screen-shot-2019-02-17-at-10-28-26-am/" rel="attachment wp-att-6620"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.28.26-AM.png" alt="" width="542" height="317" class="alignnone size-full wp-image-6620" srcset="https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.28.26-AM.png 542w, https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.28.26-AM-300x175.png 300w" sizes="(max-width: 542px) 100vw, 542px" /></a></p>
<p>In order to use the image you need a &#8220;C program&#8221; version of it.  It turns out that there is a format called &#8220;X11&#8221; or &#8220;xbm&#8221; which is exactly that (a c-file).  You can read about the format on <a href="http://www.fileformat.info/format/xbm/egff.htm" target="_blank" rel="noopener">this website</a>.  To get one of these files, just run &#8220;File-&gt;Export As&#8221;</p>
<p><a href="https://iotexpert.com/2019/02/17/mbed-os-psoc-6-ssd1306/screen-shot-2019-02-17-at-10-29-14-am/" rel="attachment wp-att-6623"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.29.14-AM.png" alt="" width="204" height="281" class="alignnone size-full wp-image-6623" /></a></p>
<p>Then give it a name with a &#8220;.xbm&#8221; on the end</p>
<p><a href="https://iotexpert.com/2019/02/17/mbed-os-psoc-6-ssd1306/screen-shot-2019-02-17-at-10-29-45-am/" rel="attachment wp-att-6622"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.29.45-AM.png" alt="" width="617" height="117" class="alignnone size-large wp-image-6622" srcset="https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.29.45-AM.png 617w, https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.29.45-AM-600x114.png 600w, https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.29.45-AM-300x57.png 300w" sizes="(max-width: 617px) 100vw, 617px" /></a></p>
<p>Make sure and &#8220;de-select the X10 format bitmap&#8221; (and older version of the xbm format)</p>
<p><a href="https://iotexpert.com/2019/02/17/mbed-os-psoc-6-ssd1306/screen-shot-2019-02-17-at-10-29-56-am/" rel="attachment wp-att-6621"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.29.56-AM.png" alt="" width="321" height="351" class="alignnone size-full wp-image-6621" srcset="https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.29.56-AM.png 321w, https://iotexpert.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.29.56-AM-274x300.png 274w" sizes="(max-width: 321px) 100vw, 321px" /></a></p>
<p>When all that is said and done you will find the xbm file with goodness in it.  Here is the top of it.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">#define cylogo_width 128
#define cylogo_height 40
static unsigned char cylogo_bits[] = {
   0x00, 0x00, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x3f,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0xfe, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
</pre>
<p>The format of this file is unsigned 8-bit integers&#8230; each bit represents the bit of one pixel&#8230; in BIG ENDIAN!!!! format.  In other words this table will be 128&#215;40/8 bytes long.</p>
<h1>Create a function to draw X11 bitmaps &amp; test</h1>
<p>But how do we use this format?  Well, write a new function in the Adafruit library to draw X11 bitmaps.</p>
<p>First add the new function name to the class on line 168 of &#8220;Adafruit_GFX.h&#8221;</p>
<pre class="start-line:72 EnlighterJSRAW" data-enlighter-language="c"">    virtual void drawX11BitMap(const uint8_t bitmap[],uint16_t bitMapWidth,uint16_t bitMapSize,uint16_t posX,uint16_t posY);
</pre>
<p>Then add the code.</p>
<pre class="start-line:152 EnlighterJSRAW" data-enlighter-language="c"">// Write an X11 formatted bitmap to the screen at posX, posY
void Adafruit_GFX::drawX11BitMap(const uint8_t bitmap[],uint16_t bitMapWidth,uint16_t bitMapSize,uint16_t posX,uint16_t posY)
{
  int16_t x1 = posX;
  int16_t y1 = posY;

  for(unsigned int i=0;i&lt;bitMapSize;i++)
  {
    uint8_t val = bitmap[i];

    for(int j=0;j&lt;8;j++)
    {
        uint16_t pixColor;
        if(val&gt;&gt;j &amp; 0x01)
          pixColor = 1;
        else
          pixColor = 0;

        drawPixel(x1,y1, pixColor);
        x1 = x1 + 1;
        if(x1 == posX + bitMapWidth)
        {
          x1 = posX;
          y1 = y1 + 1;
        }
    }
  }</pre>
<p>This may not be the most beautiful code in the world&#8230; which I suppose makes it fit right in with some of the other stuff in this driver.  Oh well it works.</p>
<p>Once you have added the function to the library, lets test it to see if it can draw the logo.  First, copy the &#8220;cylogo.xbm&#8221; into the project and call it &#8220;cylogo.h&#8221;.  Then modify the &#8220;main.cpp&#8221; to use it.  Add an include of the &#8220;cylogo.h&#8221;.  Then on line 26, call the function to draw it at 0,(half way down the screen)</p>
<pre class="lang:c++ decode:true ">#include "mbed.h"
#include "Adafruit_SSD1306.h"
#include "cylogo.h"
DigitalOut myled(LED1);

class I2CPreInit : public I2C
{
public:
    I2CPreInit(PinName sda, PinName scl) : I2C(sda, scl)
    {
        frequency(400000);
        start();
    };
};
I2CPreInit gI2C(P6_1,P6_0);
Adafruit_SSD1306_I2c gOled2(gI2C,P0_2,0x78,64,128);

int main()
{   uint16_t x=0;

    printf("Started\n");
    printf("%ux%u OLED Display\r\n", gOled2.width(), gOled2.height());
    printf("Rotation = %u\n",gOled2.getRotation());


    gOled2.drawX11BitMap(cylogo_bits,cylogo_width,sizeof(cylogo_bits),0,(64-cylogo_height)/2);

    gOled2.display();
</pre>
<p>When you program this&#8230; everything seems to be good.</p>
<p><a href="https://iotexpert.com/2019/02/17/mbed-os-psoc-6-ssd1306/img_0229/" rel="attachment wp-att-6625"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/02/IMG_0229-e1550418582969-1024x768.jpg" alt="" width="1024" height="768" class="alignnone size-large wp-image-6625" srcset="https://iotexpert.com/wp-content/uploads/2019/02/IMG_0229-e1550418582969-1024x768.jpg 1024w, https://iotexpert.com/wp-content/uploads/2019/02/IMG_0229-e1550418582969-600x450.jpg 600w, https://iotexpert.com/wp-content/uploads/2019/02/IMG_0229-e1550418582969-300x225.jpg 300w, https://iotexpert.com/wp-content/uploads/2019/02/IMG_0229-e1550418582969-768x576.jpg 768w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>By the way if it isn&#8217;t clear by now, I did a solder in a male header onto the board so that I could attach the I2C wires for the display.</p>
<p><a href="https://iotexpert.com/2019/02/17/mbed-os-psoc-6-ssd1306/img_0230/" rel="attachment wp-att-6626"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2019/02/IMG_0230-e1550418732146-1024x768.jpg" alt="" width="1024" height="768" class="alignnone size-large wp-image-6626" srcset="https://iotexpert.com/wp-content/uploads/2019/02/IMG_0230-e1550418732146-1024x768.jpg 1024w, https://iotexpert.com/wp-content/uploads/2019/02/IMG_0230-e1550418732146-600x450.jpg 600w, https://iotexpert.com/wp-content/uploads/2019/02/IMG_0230-e1550418732146-300x225.jpg 300w, https://iotexpert.com/wp-content/uploads/2019/02/IMG_0230-e1550418732146-768x576.jpg 768w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/mbed-os-psoc-6-ssd1306/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>PSoC 6, FreeRTOS &#038; SSD1306 OLED Display</title>
		<link>https://iotexpert.com/psoc-6-freertos-ssd1306-oled-display/</link>
					<comments>https://iotexpert.com/psoc-6-freertos-ssd1306-oled-display/#comments</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Tue, 05 Dec 2017 11:58:59 +0000</pubDate>
				<category><![CDATA[PSoC 6]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=4751</guid>

					<description><![CDATA[Summary This week I have been working with my friend Hassane El Khoury on his hobby project which has the SSD1306 in it. [if you want to know more about the project, leave a comment and maybe he will answer the question].  I have been helping him get a number of things going including this display [&#8230;]]]></description>
										<content:encoded><![CDATA[<h1>Summary</h1>
<p>This week I have been working with my friend <a href="http://www.cypress.com/hassane-el-khoury" target="_blank" rel="noopener">Hassane El Khoury</a> on his hobby project which has the SSD1306 in it. [if you want to know more about the project, leave a comment and maybe he will answer the question].  I have been helping him get a number of things going including this display which I have written <a href="https://iotexpert.com/?s=ssd1306" target="_blank" rel="noopener">about</a> before.  This article describes the integration of the SSD1306 OLED Display into his project with the PSoC 6 &amp; FreeRTOS.<a href="https://iotexpert.com/2017/12/05/psoc-6-freertos-ssd1306-oled-display/img_5897/" rel="attachment wp-att-4753"></a></p>
<h1>Firmware Architecture</h1>
<p>Hassane started his career as an Automotive System Designer, then he worked as an Applications Engineer, so he has &#8220;mad&#8221; skills in this area.  He is building his project with a PSoC 6 and is heavily using FreeRTOS (which is new for him).  He has been distracted with some other thing the last few years, so I have been serving as a consultant on the latest PSoC stuff to smooth the learning curve.  In this case PSoC6, FreeRTOS and the SSD1306 OLED Display.  I have only used the SSD1306 OLED Display with PSoC 4 and WICED, but I ASSUMED (incorrectly assumed&#8230; which I will talk about in the next article) that there would be no problems making it work in that environment.</p>
<p>Hassane is all about reuse and he had copied the design of this section of his project from my <a href="https://iotexpert.com/2017/06/22/psoc-freertos-sharing-the-i2c-bus/" target="_blank" rel="noopener">article</a> on using queues with FreeRTOS.  It looks like this.</p>
<ol>
<li>There is a task that manages the I2C and talks directly to the SCB hardware and the I2C devices</li>
<li>There is a task that manages the OLED</li>
</ol>
<p><a href="https://iotexpert.com/2017/12/05/psoc-6-freertos-ssd1306-oled-display/i2carch/" rel="attachment wp-att-4758"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/12/i2carch.png" alt="ssd1306 oled display architecture" width="987" height="281" class="alignnone wp-image-4758 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/12/i2carch.png 987w, https://iotexpert.com/wp-content/uploads/2017/12/i2carch-600x171.png 600w, https://iotexpert.com/wp-content/uploads/2017/12/i2carch-300x85.png 300w, https://iotexpert.com/wp-content/uploads/2017/12/i2carch-768x219.png 768w" sizes="(max-width: 987px) 100vw, 987px" /></a></p>
<p>Originally the OLED task was talking directly to the I2C via the SCB (the red line on the picture).  Remember from the article on the U8G2 library, the hardware abstraction layer looks like this.  Basically it</p>
<ol>
<li>Sends an I2C Start at the start of the U8G2 transaction</li>
<li>Sends an I2C Stop at the end of the tranaction</li>
<li>Send the number of bytes called for.</li>
</ol>
<pre class="lang:c decode:true">uint8_t u8x8_I2C_HW(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
    uint8_t *data;
    switch(msg)
    {
        case U8X8_MSG_BYTE_SEND:            
            data = (uint8_t *)arg_ptr;
            while( arg_int &gt; 0 )
            {
                Cy_SCB_I2C_MasterWriteByte(I2Cm1_HW, *data, I2C_TIMEOUT, &amp;I2Cm1_context);
  	            data++;
	            arg_int--;
            }
        break;
      
        case U8X8_MSG_BYTE_START_TRANSFER:
            Cy_SCB_I2C_MasterSendStart(I2Cm1_HW, u8x8_GetI2CAddress(u8x8)&gt;&gt;1, CY_SCB_I2C_WRITE_XFER, I2C_TIMEOUT, &amp;I2Cm1_context);
         break;
        
        case U8X8_MSG_BYTE_END_TRANSFER:
            Cy_SCB_I2C_MasterSendStop(I2Cm1_HW, I2C_TIMEOUT, &amp;I2Cm1_context);
        break;
    
        default:
            return 0;
    }
    
    return 1;
}
</pre>
<p>The problem with this design is that it takes over the I2C hardware and requires exclusive control.  Moreover, it leaves you program hung while the transaction is happening.  To solve this problem, there are three options</p>
<ol>
<li>&#8220;Assign&#8221; the SCB block to the exclusive use of this task (makes it hard to share with other I2C devices)</li>
<li>Create a mutex for the SCB.  This will work, but it will not allow the task to &#8220;queue&#8221; transactions and move on</li>
<li>Create a task to manage the SCB with a queue (the option that Hassane chose)</li>
</ol>
<p>The I2C message queue holds complete transactions.  Each transaction (which he called I2Cm_transaction_t) looks like this:</p>
<pre class="lang:c decode:true">typedef enum I2Cm_transactionMethod {
    I2CM_READ,
    I2CM_WRITE
} I2Cm_transactionMethod_t;

typedef enum I2Cm_registerAddresType {
    I2CM_NONE, 
    I2CM_BIT8,
    I2CM_BIT16
} i2cm_registerAddressType_t;

typedef struct I2Cm_transaction {
    I2Cm_transactionMethod_t I2Cm_method;        // I2CM_READ or I2CM_WRITE
    uint8_t I2Cm_address;                        // The I2C Address of the slave
    i2cm_registerAddressType_t I2Cm_regType;     // I2CM_8BIT or I2CM_16BIT
    uint16_t I2Cm_register;                      // The register in the slave    
    uint8_t *I2Cm_bytes;                         // A pointer to the data to be written (or a place to save the data)
    uint32_t *I2Cm_bytesProcessed;               // A return value with the number of bytes written
    uint32_t I2Cm_byteNum;                       // How many bytes are in the request
    SemaphoreHandle_t I2Cm_doneSemaphore;        // If you want a semaphore flagging that the transaction is done 
} I2Cm_transaction_t;
</pre>
<p>In order to fix the the HAL you just sets up a transaction at the start of the task:</p>
<pre class="lang:c decode:true">   memset(&amp;OLEDtransaction,0,sizeof(OLEDtransaction));
	OLEDtransaction.I2Cm_method = I2CM_WRITE;
	OLEDtransaction.I2Cm_address = OLED_ADDRESS_1;
	OLEDtransaction.I2Cm_regType = I2CM_NONE;
	OLEDtransaction.I2Cm_bytes = buff;
	OLEDtransaction.I2Cm_bytesProcessed = &amp;numProcessed;	
    OLEDtransaction.I2Cm_doneSemaphore = xSemaphoreCreateBinary();
</pre>
<p>Then queue up the bytes into a buffer, and flush the buffer when the &#8220;U8X8_MSG_BYTE_END_TRANSFER&#8221; message comes</p>
<pre class="lang:c decode:true">uint8_t u8x8_I2C_HW(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
    uint8_t *data;
    switch(msg)
    {
        case U8X8_MSG_BYTE_SEND:        
            data = (uint8_t *)arg_ptr;
            while( arg_int &gt; 0 )
            {
                buff[buffCount] = *data;
                buffCount += 1;
                CY_ASSERT(buffCount &lt; BUFFSIZE);              
  	            data++;
	            arg_int--;
            }
        break;
 
        case U8X8_MSG_BYTE_START_TRANSFER:
            buffCount = 0;
         break;
        
        case U8X8_MSG_BYTE_END_TRANSFER:
	        OLEDtransaction.I2Cm_byteNum = buffCount;
            I2Cm1RunTransaction(&amp;OLEDtransaction);
        break;
    
        default:
        return 0;
    }
    
    return 1;
}
</pre>
<h1>SSD1306 OLED Display</h1>
<p>Now, the short block of test code works perfect:</p>
<pre class="lang:c decode:true">    u8x8_Setup(&amp;MyI2Cu8x8, u8x8_d_ssd1306_128x32_univision, u8x8_cad_ssd13xx_i2c, u8x8_I2C_HW, u8x8_gpio_and_delay_PSoC6);
        
    u8x8_InitDisplay(&amp;MyI2Cu8x8);  
    u8x8_SetPowerSave(&amp;MyI2Cu8x8,0);
    u8x8_ClearDisplay(&amp;MyI2Cu8x8);
    u8x8_SetFont(&amp;MyI2Cu8x8,u8x8_font_amstrad_cpc_extended_f);
    u8x8_DrawString(&amp;MyI2Cu8x8,0,0," Killer Mustang ");
    u8x8_DrawString(&amp;MyI2Cu8x8,0,1,"   Test OLED    ");
    u8x8_DrawString(&amp;MyI2Cu8x8,0,2,"________________");</pre>
<p>And I get a nice output (I wonder what a &#8220;Killer Mustang&#8221; is?)</p>
<p><a href="https://iotexpert.com/2017/12/05/psoc-6-freertos-ssd1306-oled-display/img_7530/" rel="attachment wp-att-4770"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/12/IMG_7530-e1512313105277-1024x768.jpg" alt="" width="1024" height="768" class="alignnone size-large wp-image-4770" srcset="https://iotexpert.com/wp-content/uploads/2017/12/IMG_7530-e1512313105277-1024x768.jpg 1024w, https://iotexpert.com/wp-content/uploads/2017/12/IMG_7530-e1512313105277-600x450.jpg 600w, https://iotexpert.com/wp-content/uploads/2017/12/IMG_7530-e1512313105277-300x225.jpg 300w, https://iotexpert.com/wp-content/uploads/2017/12/IMG_7530-e1512313105277-768x576.jpg 768w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>In the next article Ill talk about the SS1306 and a problem that I created for myself.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/psoc-6-freertos-ssd1306-oled-display/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>ThingSoC: Four I2C OLED Displays with PSoC4L</title>
		<link>https://iotexpert.com/thingsoc-psoc4l-i2c-oled-displays/</link>
					<comments>https://iotexpert.com/thingsoc-psoc4l-i2c-oled-displays/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Mon, 06 Feb 2017 11:00:13 +0000</pubDate>
				<category><![CDATA[PSoC 4200]]></category>
		<category><![CDATA[PSoC Creator]]></category>
		<category><![CDATA[ThingSoC]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=2830</guid>

					<description><![CDATA[Pattern Agents are running a crowd funding effort for ThingSoC TSoC4L &#8230; help them here Summary In the previous ThingSoC post I took you through building the firmware to make the PSoC4L drive the ThingSoC I2C hub.  Now what?  When originally looking around I saw a picture with 4x LCDs connected to the I2C hub, which I [&#8230;]]]></description>
										<content:encoded><![CDATA[<h4><span style="color: #ff0000;"><span style="color: #008000;">Pattern Agents are running a crowd funding effort for ThingSoC TSoC4L &#8230; help them</span> <a href="https://www.crowdsupply.com/patternagents-llc/thingsoc-grovey?utm_source=thingSOC+Supporters&amp;utm_campaign=f1c4185485-launch_thingsoc_2017_01_23&amp;utm_medium=email&amp;utm_term=0_4aec98a7fc-f1c4185485-112421013" target="_blank" style="color: #ff0000;">here</a></span></h4>
<h2>Summary</h2>
<p>In the <a href="https://iotexpert.com/2017/02/02/thingsoc-tsoc-grovey-i2chub-i2c-hubswitch/" target="_blank">previous</a> ThingSoC post I took you through building the firmware to make the <a href="http://www.cypress.com/documentation/datasheets/psoc-4-psoc-4200l-family-datasheet">PSoC4L</a> drive the ThingSoC I2C hub.  Now what?  When originally looking around I saw a picture with 4x LCDs connected to the I2C hub, which I thought was cool. In this post Ill show you how to do the same thing with PSoC and the <a href="https://github.com/olikraus/u8g2" target="_blank">U8G2</a> library which I talked about in this <a href="https://iotexpert.com/2017/02/01/pinball-driving-oled-using-u8g2-library/" target="_blank">article</a>. To do this I will:</p>
<ol>
<li>Create New PSoC4L Project + Integrate the U8G2 Library</li>
<li>Update the PSoC4L Firmware</li>
<li>Test the PSoC4L Firmware</li>
</ol>
<p>Here is the picture:</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/02/lcd_rgb_13.jpg"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/02/lcd_rgb_13.jpg" alt="4 I2C Displays, Inspiration" width="640" height="640" class="alignnone wp-image-2839 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/02/lcd_rgb_13.jpg 640w, https://iotexpert.com/wp-content/uploads/2017/02/lcd_rgb_13-300x300.jpg 300w, https://iotexpert.com/wp-content/uploads/2017/02/lcd_rgb_13-100x100.jpg 100w, https://iotexpert.com/wp-content/uploads/2017/02/lcd_rgb_13-600x600.jpg 600w, https://iotexpert.com/wp-content/uploads/2017/02/lcd_rgb_13-150x150.jpg 150w" sizes="(max-width: 640px) 100vw, 640px" /></a></p>
<h2>Create New PSOC4L Project + Integrate the U8G2 Library</h2>
<p>Maybe it should have been obvious, but for some reason it never occurred to me to do a copy/paste to duplicate a project.  I guess that I&#8217;m slow that way.  To do this right click on a project in the workspace explorer and then do paste.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-03-at-8.04.36-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-03-at-8.04.36-AM.png" alt="PSoC Creator Edit Build Settings" width="820" height="1150" class="alignnone wp-image-2851 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-03-at-8.04.36-AM.png 820w, https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-03-at-8.04.36-AM-600x841.png 600w, https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-03-at-8.04.36-AM-214x300.png 214w, https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-03-at-8.04.36-AM-768x1077.png 768w, https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-03-at-8.04.36-AM-730x1024.png 730w" sizes="(max-width: 820px) 100vw, 820px" /></a></p>
<p>The next step is to integrate the firmware from the U8G2 Library. Start by &#8220;gitting&#8221; with &#8220;git@github.com:olikraus/u8g2.git&#8221;.  Then you need to add the directory to your project by right clicking the project and selecting &#8220;Build Settings&#8221;.  You need to add U8G2 Library to the additional include directories.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-03-at-8.09.47-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-03-at-8.09.47-AM.png" alt="Add the U8G2 Library" width="1588" height="1126" class="alignnone wp-image-2852 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-03-at-8.09.47-AM.png 1588w, https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-03-at-8.09.47-AM-600x425.png 600w, https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-03-at-8.09.47-AM-300x213.png 300w, https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-03-at-8.09.47-AM-768x545.png 768w, https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-03-at-8.09.47-AM-1024x726.png 1024w" sizes="(max-width: 1588px) 100vw, 1588px" /></a></p>
<p>Add the all of the .h and .c files by right clicking the project and selection &#8220;Add-&gt;Existing Item&#8221;</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-03-at-8.12.17-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-03-at-8.12.17-AM.png" alt="copy the u8g2 files into the PSoC4L project" width="972" height="1048" class="alignnone wp-image-2853 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-03-at-8.12.17-AM.png 972w, https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-03-at-8.12.17-AM-600x647.png 600w, https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-03-at-8.12.17-AM-278x300.png 278w, https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-03-at-8.12.17-AM-768x828.png 768w, https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-03-at-8.12.17-AM-950x1024.png 950w" sizes="(max-width: 972px) 100vw, 972px" /></a></p>
<p>Navigate to the U8G2 library and add all of the .c and .h files.  The last thing you need is to bring in the HAL that I wrote for PSoC and described in this <a href="https://iotexpert.com/2017/02/01/pinball-driving-oled-using-u8g2-library/" target="_blank">post</a>.  Specifically you need to bring in the two functions</p>
<ul>
<li>psoc_gpio_and_delay_cb</li>
<li>u8x8_byte_hw_i2c</li>
</ul>
<p>I suppose that I should package the whole thing up in a component.  But, Ill leave that as an exercise for the reader.</p>
<h2>Update the PSoC4L Firmware</h2>
<p>The cool thing about the whole setup with the I2CHUB is that it allows you to have 4 devices with the same I2C address attached to one PSoC SCB at the same time.  To get going with the firmware, I start by defining an array of u8x8_t structures to represent the 4 different displays attaches to the 4 different ports on the I2C hub. (line 186).  Then I create a function called setupDisplay that initializes the display etc. (lines 199-203).  The only trick in the firmware is that <a href="https://en.wikipedia.org/wiki/Dennis_Ritchie" target="_blank">Dennis Ritchie</a> defined arrays to run from 0-3 but the I2C busses are labeled 1-4,  this is the reason for subtracting 1 from the input lcd number.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-02-at-7.19.50-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-02-at-7.19.50-AM.png" alt="PSoC4L Firmware to initialize the U8G2 Display" width="1044" height="404" class="alignnone wp-image-2831 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-02-at-7.19.50-AM.png 1044w, https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-02-at-7.19.50-AM-600x232.png 600w, https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-02-at-7.19.50-AM-300x116.png 300w, https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-02-at-7.19.50-AM-768x297.png 768w, https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-02-at-7.19.50-AM-1024x396.png 1024w" sizes="(max-width: 1044px) 100vw, 1044px" /></a></p>
<p>The next step is modifying command processors in the main loop.  Specifically, I will add the commands q,w,e,r to startup the displays on I2C ports 1,2,3,4.  And, I will add those commands to the help print out.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-02-at-7.18.57-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-02-at-7.18.57-AM.png" alt="Modifying the PSoC4L CLI" width="652" height="545" class="alignnone wp-image-2832 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-02-at-7.18.57-AM.png 652w, https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-02-at-7.18.57-AM-600x502.png 600w, https://iotexpert.com/wp-content/uploads/2017/02/Screen-Shot-2017-02-02-at-7.18.57-AM-300x251.png 300w" sizes="(max-width: 652px) 100vw, 652px" /></a></p>
<h2>Test the PSoC4L Firmware</h2>
<p>In order to make a connection from the Grove 4-pin connectors to my breadboard I used <a href="http://www.switchdoc.com" target="_blank">Switch Doc Labs</a> connectors which I bought from <a href="https://www.amazon.com/Cables-Grove-Jumper-Grove-Conversion/dp/B01F25VYF2/ref=sr_1_3?ie=UTF8&amp;qid=1486038649&amp;sr=8-3&amp;keywords=grove+4+pin" target="_blank">Amazon.com</a>.  For some reason you can&#8217;t purchase them from the Switch Doc Labs website or the SeeedStudio website, but they are very handy.  As an unrelated side note I had never seen (or in fact ever heard of) Switch Doc Labs.  But their website has a bunch of tutorials about the Raspberry Pi and Grove ecosystem boards for use with IoT-ifying house plants.  Seemed pretty cool.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/02/41Z4kxiN9DL.jpg"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/02/41Z4kxiN9DL.jpg" alt="Grove to Breadboard Switch Doc Labs Breakout Cable" width="500" height="375" class="alignnone wp-image-2833 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/02/41Z4kxiN9DL.jpg 500w, https://iotexpert.com/wp-content/uploads/2017/02/41Z4kxiN9DL-300x225.jpg 300w" sizes="(max-width: 500px) 100vw, 500px" /></a></p>
<p>Now when I press &#8220;qwer&#8221; in my command console I get this:</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/02/IMG_3652.jpg"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/02/IMG_3652.jpg" alt="PSoC4L Driving 4 OLED LCDs" width="4032" height="3024" class="alignnone size-full wp-image-2860" /></a></p>
<p><span><p>You can find all of the projects in the TSoC Series at my GitHub ThingSoC repository git@github.com:iotexpert/ThingSoC.git</p>
<p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >Index</th>
<th >Description</th>
</tr>
</thead>
<tbody>
<tr><td ><a href="https://iotexpert.com/2017/01/25/thingsoc-psoc4l/">ThingSoc: TSoC PSoC4L Development Kit from PatternAgents</a></td>
<td >Introduction to ThingSoC</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2017/01/30/thingsoc4l-using-debugging-the-psoc4-clock/" target="_blank">ThingSoC PSoC4L: Using &amp; Debugging the PSoC4 Clock</a></td>
<td >Debugging a beta firmware problem</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2017/02/02/thingsoc-tsoc-grovey-i2chub-i2c-hubswitch/" target="_blank">ThingSoC: The TSoC GROVEY I2CHUB : I2C Hub/Switch</td>
<td >Evaluating the ThingSoC I2C Hub</a></td>
</tr>

<tr><td ><a href="https://iotexpert.com/2017/02/06/thingsoc-psoc4l-i2c-oled-displays/" target="_blank">ThingSoC: Multiple I2C Displays</td>
<td >Using the I2CHUB and U8X8 Library</a></td>
<td >A project using ThingSoC I2C Hub &amp; 4 OLED Displays</td>
</tr>
</tbody></table></div></p></span></p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/thingsoc-psoc4l-i2c-oled-displays/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Pinball: Driving the OLED using the U8G2 Library</title>
		<link>https://iotexpert.com/pinball-driving-oled-using-u8g2-library/</link>
					<comments>https://iotexpert.com/pinball-driving-oled-using-u8g2-library/#comments</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Wed, 01 Feb 2017 10:54:26 +0000</pubDate>
				<category><![CDATA[Pinball]]></category>
		<category><![CDATA[PSoC4 BLE]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=2357</guid>

					<description><![CDATA[In the previous Pinball post, I wrote about getting the OLED going and getting the footprint onto my printed circuit board.  Now I need to make PSoC firmware to drive the display.  I turns out that there are a number of different driver chips out there including at least SSD1306, SH1106, LD7032, SSD1325, and ST7920 that [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In the<a href="https://iotexpert.com/2016/12/26/pinball-oled-display/"> previous Pinball post</a>, I wrote about getting the OLED going and getting the footprint onto my printed circuit board.  Now I need to make PSoC firmware to drive the display.  I turns out that there are a number of different driver chips out there including at least <a href="https://cdn-shop.adafruit.com/datasheets/SSD1306.pdf" target="_blank">SSD1306</a>, <a href="https://www.elecrow.com/download/SH1106%20datasheet.pdf" target="_blank">SH1106</a>, <a href="http://www.seeedstudio.com/document/pdf/LD7032%20Device%20Spec%20(Rev%202.0).pdf" target="_blank">LD7032</a>, <a href="http://pdf.masters.com.pl/SOLOMON%20SYSTECH/SSD1325.pdf" target="_blank">SSD1325</a>, and <a href="http://www.fordata.cn/pdf/ic/st7920v30.pdf" target="_blank">ST7920</a> that handle multiplexing the columns/rows, managing frame buffers, power management, etc.  To make matters more fun, these chips support I2C, 3&amp;4 wire SPI and a couple of different parallel interfaces (6800, 8080).  I certainly didn&#8217;t want to go down the rathole of building up a complete driver library.  But I didn&#8217;t have to, as it turns out that that Oliver Kraus built and open-sourced a very nice library that you can get at <a href="https://github.com/olikraus/u8g2" target="_blank">www.github.com/olikraus/u8g2</a>.  This library (and its predecessor u8glib) seem to be in pretty wide use in Arduino and Raspberry Pi.</p>
<p>In order to make the library work with the PSoC I had to do several things</p>
<ol>
<li>Download it from GitHub (git clone git@github.com:olikraus/u8g2.git)</li>
<li>Created a new PSoC4200M project for the CY8CKIT-044 (which was the devkit that I happened to have sitting next to my computer)</li>
<li>Change the build settings (right click on the project and select building settings) then add the directory in &#8220;Additional Include Directories&#8221; and include the &#8220;u8g2/csrc&#8221; directory.<a href="https://iotexpert.com/wp-content/uploads/2016/12/Screen-Shot-2016-12-26-at-11.57.43-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/12/Screen-Shot-2016-12-26-at-11.57.43-AM.png" alt="" width="860" height="575" class="alignnone size-full wp-image-2354" srcset="https://iotexpert.com/wp-content/uploads/2016/12/Screen-Shot-2016-12-26-at-11.57.43-AM.png 860w, https://iotexpert.com/wp-content/uploads/2016/12/Screen-Shot-2016-12-26-at-11.57.43-AM-600x401.png 600w, https://iotexpert.com/wp-content/uploads/2016/12/Screen-Shot-2016-12-26-at-11.57.43-AM-300x201.png 300w, https://iotexpert.com/wp-content/uploads/2016/12/Screen-Shot-2016-12-26-at-11.57.43-AM-768x513.png 768w" sizes="(max-width: 860px) 100vw, 860px" /></a></li>
<li>Add the header files to the project by right clicking and selecting &#8220;Add-&gt;Existing item&#8221; so that the project can f<a href="https://iotexpert.com/wp-content/uploads/2016/12/Screen-Shot-2016-12-26-at-12.00.11-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/12/Screen-Shot-2016-12-26-at-12.00.11-PM.png" alt="" width="355" height="232" class="alignnone size-full wp-image-2355" srcset="https://iotexpert.com/wp-content/uploads/2016/12/Screen-Shot-2016-12-26-at-12.00.11-PM.png 355w, https://iotexpert.com/wp-content/uploads/2016/12/Screen-Shot-2016-12-26-at-12.00.11-PM-300x196.png 300w" sizes="(max-width: 355px) 100vw, 355px" /></a></li>
<li>Add the U8G2 C-Files to the project (same as step 4 but add the C files)</li>
<li>Build a schematic which has an I2C (for the display) and a debugging UART.  The I2C is configured as a master with 400kbs data rate.  The UART uses the default configuration.<a href="https://iotexpert.com/wp-content/uploads/2016/12/Screen-Shot-2016-12-27-at-6.10.45-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/12/Screen-Shot-2016-12-27-at-6.10.45-AM.png" alt="" width="742" height="721" class="alignnone size-full wp-image-2374" srcset="https://iotexpert.com/wp-content/uploads/2016/12/Screen-Shot-2016-12-27-at-6.10.45-AM.png 742w, https://iotexpert.com/wp-content/uploads/2016/12/Screen-Shot-2016-12-27-at-6.10.45-AM-600x583.png 600w, https://iotexpert.com/wp-content/uploads/2016/12/Screen-Shot-2016-12-27-at-6.10.45-AM-300x292.png 300w" sizes="(max-width: 742px) 100vw, 742px" /></a></li>
<li>Assign the pins<a href="https://iotexpert.com/wp-content/uploads/2016/12/Screen-Shot-2016-12-27-at-6.12.32-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2016/12/Screen-Shot-2016-12-27-at-6.12.32-AM.png" alt="" width="780" height="126" class="alignnone size-full wp-image-2376" srcset="https://iotexpert.com/wp-content/uploads/2016/12/Screen-Shot-2016-12-27-at-6.12.32-AM.png 780w, https://iotexpert.com/wp-content/uploads/2016/12/Screen-Shot-2016-12-27-at-6.12.32-AM-600x97.png 600w, https://iotexpert.com/wp-content/uploads/2016/12/Screen-Shot-2016-12-27-at-6.12.32-AM-300x48.png 300w, https://iotexpert.com/wp-content/uploads/2016/12/Screen-Shot-2016-12-27-at-6.12.32-AM-768x124.png 768w" sizes="(max-width: 780px) 100vw, 780px" /></a></li>
</ol>
<p>Now I am ready to build some firmware that will drive the display.  In order to use the library with a PSoC I need to create two functions for the U8G2 HAL to use as an interface to the PSoC hardware.  You initialize the U8G2 system with a call to the u8x8_Setup function.  In that call you need to provide function pointers too the two HAL functions</p>
<ol>
<li>The GPIO and Delay Interface</li>
<li>The byte oriented communication interface</li>
</ol>
<p>This is an example of the setup required:</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2018/01/Screen-Shot-2017-01-25-at-6.20.10-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/01/Screen-Shot-2017-01-25-at-6.20.10-AM.png" alt="" width="973" height="40" class="alignnone size-full wp-image-2775" srcset="https://iotexpert.com/wp-content/uploads/2018/01/Screen-Shot-2017-01-25-at-6.20.10-AM.png 973w, https://iotexpert.com/wp-content/uploads/2018/01/Screen-Shot-2017-01-25-at-6.20.10-AM-600x25.png 600w, https://iotexpert.com/wp-content/uploads/2018/01/Screen-Shot-2017-01-25-at-6.20.10-AM-300x12.png 300w, https://iotexpert.com/wp-content/uploads/2018/01/Screen-Shot-2017-01-25-at-6.20.10-AM-768x32.png 768w" sizes="(max-width: 973px) 100vw, 973px" /></a></p>
<p>The GPIO and Delay interface is used by the byte oriented communication functions to read/write the GPIOs and provide delays.  This function provides the underpinnings of a bit-banged I2C, UART, SPI etc.  Because I am only going to use PSoC Hardware to provide the I2C interface I will only respond to the delay messages.  All of the delay functions are implemented as busy wait loops, which I am not a big fan of.  The input to the function is a &#8220;message&#8221; that is one of a sprawling list of #defines in the file u8x8.h.  I believe that I found all of the possible cases, but I am not sure.</p>
<p>The first message, UX8X8_MSG_GPIO_AND_DELAY_INIT doesnt need to do anything because the GPIOs are configured correctly by the default.</p>
<p>I did not respond to the messages of the form U8X8_MSG_GPIO_X which are the read and write of the GPIOs as I am not going to use the bit-banged interface.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2018/01/Screen-Shot-2017-01-25-at-6.21.38-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/01/Screen-Shot-2017-01-25-at-6.21.38-AM.png" alt="" width="788" height="804" class="alignnone size-full wp-image-2776" srcset="https://iotexpert.com/wp-content/uploads/2018/01/Screen-Shot-2017-01-25-at-6.21.38-AM.png 788w, https://iotexpert.com/wp-content/uploads/2018/01/Screen-Shot-2017-01-25-at-6.21.38-AM-600x612.png 600w, https://iotexpert.com/wp-content/uploads/2018/01/Screen-Shot-2017-01-25-at-6.21.38-AM-294x300.png 294w, https://iotexpert.com/wp-content/uploads/2018/01/Screen-Shot-2017-01-25-at-6.21.38-AM-768x784.png 768w" sizes="(max-width: 788px) 100vw, 788px" /></a></p>
<p>The other function that needs to be provided is the byte-oriented communication function.  This function needs to respond to the messages to start, send, and end communication.  I just mapped those messages onto the PSoC hardware APIs.  While I was trying to understand what was happening with the system I implemented a debugging UART which you can see in the #ifdef DEBUG_UART sections.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2018/01/Screen-Shot-2017-01-25-at-6.22.45-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/01/Screen-Shot-2017-01-25-at-6.22.45-AM.png" alt="" width="797" height="741" class="alignnone size-full wp-image-2777" srcset="https://iotexpert.com/wp-content/uploads/2018/01/Screen-Shot-2017-01-25-at-6.22.45-AM.png 797w, https://iotexpert.com/wp-content/uploads/2018/01/Screen-Shot-2017-01-25-at-6.22.45-AM-600x558.png 600w, https://iotexpert.com/wp-content/uploads/2018/01/Screen-Shot-2017-01-25-at-6.22.45-AM-300x279.png 300w, https://iotexpert.com/wp-content/uploads/2018/01/Screen-Shot-2017-01-25-at-6.22.45-AM-768x714.png 768w" sizes="(max-width: 797px) 100vw, 797px" /></a></p>
<p><span><p>You can find all of the source code and files at the <a href="https://github.com/iotexpert/Pinball" target="_blank">IOTEXPERT</a> site on github.</p>
<p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >Index</th>
<th >Description</th>
</tr>
</thead>
<tbody>
<tr><td ><a href="https://iotexpert.com/2016/09/05/pinball-newtons-attic-pinball/">Pinball: Newton's Attic Pinball</a></td>
<td >An introduction to the project and the goals</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/06/pinball-lotsa-blinking-leds/">Pinball: Lotsa Blinking LEDs</a></td>
<td >Everyone needs a bunch of LEDs on their Pinball Machine</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/07/pinball-matrix-leds-part-1/">Pinball: Matrix LEDs (Part 1)</a></td>
<td >Saving PSoC pins by using a matrix scheme</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/08/pinball-matrix-leds-part-2/" target="_blank">Pinball: Matrix LEDs (Part 2)</a></td>
<td >Solving some problems with the matrix</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/09/pinball-matrix-leds-component/" target="_blank">Pinball: Matrix LEDs Component</a></td>
<td >How to turn the Matrix LED into a component</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/10/pinball-a-switch-matrix/">Pinball: A Switch Matrix</a></td>
<td >Implementing a bunch of switches</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/12/pinball-switch-matrix-component-part-1/" target="_blank">Pinball: Switch Matrix Component (Part 1)</a></td>
<td >The switch matrix component implementation</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/13/pinball-switch-matrix-component-part-2/" target="_blank">Pinball: Switch Matrix Component (Part 2)</a></td>
<td >The firmware for matrix component</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/14/pinball-switch-matrix-component-part-3/" target="_blank">Pinball: Switch Matrix Component (Part 3)</a></td>
<td >Test firmware for the matrix component</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/20/pinball-the-music-player-part-1/" target="_blank">Pinball: The Music Player (Part 1)</a></td>
<td >The schematic and symbol for a Music Player component</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/21/pinball-the-music-player-part-2/" target="_blank">Pinball: The Music Player (Part 2)</a></td>
<td >The Public API for the Music Player component</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/22/pinball-the-music-player-part-3/" target="_blank">Pinball: The Music Player (Part 3)</a></td>
<td >The firmware to make the sweet sweet music</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/23/pinball-the-music-player-part-4/">Pinball: The Music Player (Part 4)</a></td>
<td >The test program for the music player</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/26/pinball-the-motors-hbridge/" target="_blank">Pinball: The Motors + HBridge</a></td>
<td >Using an Bridge to control DC Motors</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/27/pinball-the-eagle-schematic/" target="_blank">Pinball: The Eagle Schematic</a></td>
<td >All of the circuits into an Eagle schematic</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/29/pinball-the-printed-circuit-board-version-1-0/" target="_blank">Pinball: The Printed Circuit Board 1.0</a></td>
<td >The first Eagle PCB layout of the printed circuit board</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/30/pinball-the-pcb-version-1-0-fail/" target="_blank">Pinball: The PCB Version 1.0 Fail</a></td>
<td >Problems with the first version of the Eagle PCB layout</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2017/01/05/pinball-pcb-1-2-updates-using-eagle/" target="_blank">Pinball: PCB Layout 1.2 Updates using Eagle</a></td>
<td >Fixing the errors on the first two versions of the Eagle PCB</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2017/01/12/pinball-pcb-solder-reflow-osh-park-eagle/">Pinball: Assemble and Reflow the 1.2 PCB</a></td>
<td >Assembling the Eagle PCB</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2017/01/23/pinball-testing-the-eagle-pcb/" target="_blank">Pinball: Testing the Eagle PCB</a></td>
<td > Firmware to test the newly built Pinball printed circuit board</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2017/02/09/pinball-debugging-psoc-motor-driver/" target="_blank">Pinball: Debugging the Motor Driver</a></td>
<td > Fixing the motor driver PSoC project</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2017/02/13/hot-air-solder-reworking-the-accelerometer/" target="_blank">Pinball: Hot-Air Reworking the Accelerometer Solder</a></td>
<td >Using a Hot-Air Rework tool to reflow a QFN</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2017/02/16/pinball-debugging-lm317-power-supply-tale-getting-lucky/" target="_blank">Pinball: Debugging the LM317 Power Supply- A Tale of Getting Lucky</a></td>
<td >Debugging the LM317/LM117 power supply</td>
</tr>
</tbody></table></div></p></span></p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/pinball-driving-oled-using-u8g2-library/feed/</wfw:commentRss>
			<slash:comments>16</slash:comments>
		
		
			</item>
		<item>
		<title>Pinball: Testing the Eagle PCB</title>
		<link>https://iotexpert.com/pinball-testing-the-eagle-pcb/</link>
					<comments>https://iotexpert.com/pinball-testing-the-eagle-pcb/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Mon, 23 Jan 2017 11:31:03 +0000</pubDate>
				<category><![CDATA[Pinball]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=2551</guid>

					<description><![CDATA[Summary In the previous post I talked about my process for assembling the Pinball PCB.  In this post I will take you through all of the steps that I took while testing the Eagle PCB functionality.  I have not yet written the full Pinball game firmware, so I used a small test program, an Oscilloscope [&#8230;]]]></description>
										<content:encoded><![CDATA[<h2>Summary</h2>
<p>In the <a href="https://iotexpert.com/2017/01/12/pinball-pcb-solder-reflow-osh-park-eagle/">previous post</a> I talked about my process for assembling the Pinball PCB.  In this post I will take you through all of the steps that I took while testing the Eagle PCB functionality.  I have not yet written the full Pinball game firmware, so I used a small test program, an Oscilloscope and a multimeter to test each of the subsystems.  In order these are the systems that i tested:</p>
<ol>
<li>Power Supply</li>
<li>I2C OLED LCD Screen</li>
<li>CapSense (creator bug)</li>
<li>Buzzers</li>
<li>Motor Driver</li>
<li>LEDs</li>
<li>Switches</li>
<li>Accelerometer</li>
<li>Bluetooth</li>
</ol>
<h2>Test the Power Supply</h2>
<p>My first step was to plug in the Eagle PCB and see what happens.  There was no smoke, but when I measured the power supply I got this:</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/01/IMG_3590.jpg"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/01/IMG_3590-e1483803789766.jpg" width="3024" height="4032" class="alignnone wp-image-2606 size-full" alt="fluke power supply measurement" /></a></p>
<p>Not perfect and I wondered why I got 4.1v instead of 3.3v.  But, the system will work at 4.1v so I deferred solving the problem until later.  [Edit: It turns out that I did something really stupid and then got lucky.  I will post soon about exactly what happened and how I fixed it.]</p>
<h2>Test the OLED LCD Screen</h2>
<p>Before I soldered in the LCD display, I decided to measure the I2C pins to make sure they were what I was expecting.  Unfortunately, when I measured them, I had about 800 ohms of resistance between the VCC and Ground which didn&#8217;t make a bit of sense.  To make matters worse the SDA and SCL were essentially shorted to ground.  After thinking about it for a while, I decided that the most likely culprit was the QFN accelerometer (which is also attached to the I2C bus).  That tiny little chip, with no-visible leads and 0.5mm pitch pads is an absolute beast to solder (more on this problem in a future post).  The accelerometer looked &#8220;OK&#8221;, but I decided to remove it anyway using my hot air tool.  As soon as I got it off the board I could see a big blob of solder on the pads.  After I cleaned up the blob of solder with a copper braid and soldering iron, I retested all of the pins.  They were now fine.  So I went ahead and soldered the display into the board (which also turned out to be a bad idea).  You can see the (unpopulated) accelerometer footprint just to the left of the display.</p>
<p><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/01/IMG_3528.jpg" alt="OLED Screen Test" width="4032" height="3024" class="alignnone wp-image-2560 size-full" /></p>
<p>To test the display I ported Oliver Kraus&#8217; <a href="https://github.com/olikraus/u8g2" target="_blank">U8G2 library</a> to the PSoC.  This library lets you use an I2C to interface with a bunch of different small OLEDs.  You can read more about using the display in a future post.  Here is the block of code that makes the display work:</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-22-at-11.59.59-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-22-at-11.59.59-AM.png" alt="" width="924" height="169" class="alignnone size-full wp-image-2698" srcset="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-22-at-11.59.59-AM.png 924w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-22-at-11.59.59-AM-600x110.png 600w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-22-at-11.59.59-AM-300x55.png 300w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-22-at-11.59.59-AM-768x140.png 768w" sizes="(max-width: 924px) 100vw, 924px" /></a></p>
<h2>Test the CapSense</h2>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/01/IMG_3530-1.jpg"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/01/IMG_3530-1.jpg" alt="PSoC CapSense Test" width="4032" height="3024" class="alignnone wp-image-2559 size-full" /></a></p>
<p>In order to test the CapSense buttons I wrote a simple block of firmware to read the state of the buttons and display that state on the screen:</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-22-at-12.05.12-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-22-at-12.05.12-PM.png" alt="" width="585" height="159" class="alignnone size-full wp-image-2697" srcset="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-22-at-12.05.12-PM.png 585w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-22-at-12.05.12-PM-300x82.png 300w" sizes="(max-width: 585px) 100vw, 585px" /></a></p>
<h2>Test the Buzzers</h2>
<p>In order to test the buzzers, I just connected them to the PWMs and drove a square wave of 262Hz and 440Hz.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/01/TEK00005.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/01/TEK00005.png" alt="Buzzer 0 PWM Test" width="480" height="234" class="alignnone wp-image-2619 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/01/TEK00005.png 480w, https://iotexpert.com/wp-content/uploads/2017/01/TEK00005-300x146.png 300w" sizes="(max-width: 480px) 100vw, 480px" /></a></p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/01/TEK00004.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/01/TEK00004.png" alt="Buzzer 1 PWM Test" width="480" height="234" class="alignnone wp-image-2620 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/01/TEK00004.png 480w, https://iotexpert.com/wp-content/uploads/2017/01/TEK00004-300x146.png 300w" sizes="(max-width: 480px) 100vw, 480px" /></a></p>
<p>Here is the schematic for that circuit:</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-22-at-12.08.19-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-22-at-12.08.19-PM.png" alt="Buzzer PWM Test Circuit" width="534" height="612" class="alignnone wp-image-2699 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-22-at-12.08.19-PM.png 534w, https://iotexpert.com/wp-content/uploads/2017/01/Screen-Shot-2017-01-22-at-12.08.19-PM-262x300.png 262w" sizes="(max-width: 534px) 100vw, 534px" /></a></p>
<h2>Test the Motor Driver</h2>
<p>In order to test the motor drivers, I used a PWM to drive a 50Hz Square wave onto the output.  Unfortunately, I got this:</p>
<h2><a href="https://iotexpert.com/wp-content/uploads/2017/01/TEK00001.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/01/TEK00001.png" alt="Motor Driver Oscilloscope Measurement" width="480" height="234" class="alignnone wp-image-2431 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/01/TEK00001.png 480w, https://iotexpert.com/wp-content/uploads/2017/01/TEK00001-300x146.png 300w" sizes="(max-width: 480px) 100vw, 480px" /></a></h2>
<p>Something is wrong.  When I first saw this waveform I wasn&#8217;t too happy.  But after doing some digging I figured out how to fix it.  This will be the subject of an upcoming post.  The good thing about this waveform is that my daughter, Anna, is studying exponentials functions in Calculus right now.  She recently asked me if there was an useful application of f(x) = e^x.  This was a perfect way to show her a practical application of a differential equation.</p>
<h2>Test the LEDs</h2>
<p>To test the LEDs I used the <a href="https://iotexpert.com/2016/09/09/pinball-matrix-leds-component/" target="_blank">switching LED matrix</a> component program that I showed in an earlier post.  To make things easier, I just stuck an LED in each pair of holes to make sure that they were working.  Here is a picture:</p>
<p><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/01/IMG_3533.jpg" alt="Matrix LED Test" width="4032" height="3024" class="alignnone wp-image-2553 size-full" /></p>
<h2>Test the Switches</h2>
<p>To test the switches, I used the <a href="https://iotexpert.com/2016/09/10/pinball-a-switch-matrix/" target="_blank">Switch Matrix Component</a> that I talked about in detail in a previous post.  In order to see the switches in their on state, I just plugged in a wire.  Here is a picture of a few of them being tested.</p>
<h2><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/01/IMG_3535.jpg" alt="Switch Matrix Component Test" width="4032" height="3024" class="alignnone wp-image-2552 size-full" /></h2>
<h2>Test the Accelerometer</h2>
<p>As I mentioned earlier in this post, the accelerometer had a big nasty blob of solder under it which shorted SDA/SCL to ground.  I am going to dedicate an entire post to fixing this problem.</p>
<h2>Test the Bluetooth</h2>
<p>The very last sub-system to test is the Bluetooth.  I decided to put in enough firmware that the device could:</p>
<ol>
<li>Advertise</li>
<li>Disconnect</li>
<li>Restart advertising</li>
</ol>
<p>And display all of that on the OLED.  Here is a picture:</p>
<p><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/01/IMG_3560-e1483711583485-768x1024.jpg" alt="OLED Display showing BLE Advertising State" width="768" height="1024" class="alignnone wp-image-2585 size-large" srcset="https://iotexpert.com/wp-content/uploads/2017/01/IMG_3560-e1483711583485-768x1024.jpg 768w, https://iotexpert.com/wp-content/uploads/2017/01/IMG_3560-e1483711583485-600x800.jpg 600w, https://iotexpert.com/wp-content/uploads/2017/01/IMG_3560-e1483711583485-225x300.jpg 225w, https://iotexpert.com/wp-content/uploads/2017/01/IMG_3560-e1483711583485-scaled.jpg 1920w" sizes="(max-width: 768px) 100vw, 768px" /></p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/01/IMG_3559.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/01/IMG_3559-576x1024.png" alt="iPhone Light Blue BLE Browser Showing Advertising Devices" width="576" height="1024" class="alignnone wp-image-2581 size-large" srcset="https://iotexpert.com/wp-content/uploads/2017/01/IMG_3559-576x1024.png 576w, https://iotexpert.com/wp-content/uploads/2017/01/IMG_3559-600x1067.png 600w, https://iotexpert.com/wp-content/uploads/2017/01/IMG_3559-169x300.png 169w, https://iotexpert.com/wp-content/uploads/2017/01/IMG_3559-768x1365.png 768w, https://iotexpert.com/wp-content/uploads/2017/01/IMG_3559.png 1242w" sizes="(max-width: 576px) 100vw, 576px" /></a></p>
<p><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/01/IMG_3561-e1483711711738-768x1024.jpg" width="768" height="1024" class="alignnone wp-image-2584 size-large" alt="Bluetooth Advertising Test" srcset="https://iotexpert.com/wp-content/uploads/2017/01/IMG_3561-e1483711711738-768x1024.jpg 768w, https://iotexpert.com/wp-content/uploads/2017/01/IMG_3561-e1483711711738-600x800.jpg 600w, https://iotexpert.com/wp-content/uploads/2017/01/IMG_3561-e1483711711738-225x300.jpg 225w, https://iotexpert.com/wp-content/uploads/2017/01/IMG_3561-e1483711711738-scaled.jpg 1920w" sizes="(max-width: 768px) 100vw, 768px" /></p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/01/IMG_3558.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/01/IMG_3558-576x1024.png" alt="Light Blue BLE GATT Database Explorer" width="576" height="1024" class="alignnone wp-image-2582 size-large" srcset="https://iotexpert.com/wp-content/uploads/2017/01/IMG_3558-576x1024.png 576w, https://iotexpert.com/wp-content/uploads/2017/01/IMG_3558-600x1067.png 600w, https://iotexpert.com/wp-content/uploads/2017/01/IMG_3558-169x300.png 169w, https://iotexpert.com/wp-content/uploads/2017/01/IMG_3558-768x1365.png 768w, https://iotexpert.com/wp-content/uploads/2017/01/IMG_3558.png 1242w" sizes="(max-width: 576px) 100vw, 576px" /></a></p>
<p><span><p>You can find all of the source code and files at the <a href="https://github.com/iotexpert/Pinball" target="_blank">IOTEXPERT</a> site on github.</p>
<p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >Index</th>
<th >Description</th>
</tr>
</thead>
<tbody>
<tr><td ><a href="https://iotexpert.com/2016/09/05/pinball-newtons-attic-pinball/">Pinball: Newton's Attic Pinball</a></td>
<td >An introduction to the project and the goals</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/06/pinball-lotsa-blinking-leds/">Pinball: Lotsa Blinking LEDs</a></td>
<td >Everyone needs a bunch of LEDs on their Pinball Machine</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/07/pinball-matrix-leds-part-1/">Pinball: Matrix LEDs (Part 1)</a></td>
<td >Saving PSoC pins by using a matrix scheme</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/08/pinball-matrix-leds-part-2/" target="_blank">Pinball: Matrix LEDs (Part 2)</a></td>
<td >Solving some problems with the matrix</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/09/pinball-matrix-leds-component/" target="_blank">Pinball: Matrix LEDs Component</a></td>
<td >How to turn the Matrix LED into a component</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/10/pinball-a-switch-matrix/">Pinball: A Switch Matrix</a></td>
<td >Implementing a bunch of switches</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/12/pinball-switch-matrix-component-part-1/" target="_blank">Pinball: Switch Matrix Component (Part 1)</a></td>
<td >The switch matrix component implementation</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/13/pinball-switch-matrix-component-part-2/" target="_blank">Pinball: Switch Matrix Component (Part 2)</a></td>
<td >The firmware for matrix component</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/14/pinball-switch-matrix-component-part-3/" target="_blank">Pinball: Switch Matrix Component (Part 3)</a></td>
<td >Test firmware for the matrix component</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/20/pinball-the-music-player-part-1/" target="_blank">Pinball: The Music Player (Part 1)</a></td>
<td >The schematic and symbol for a Music Player component</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/21/pinball-the-music-player-part-2/" target="_blank">Pinball: The Music Player (Part 2)</a></td>
<td >The Public API for the Music Player component</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/22/pinball-the-music-player-part-3/" target="_blank">Pinball: The Music Player (Part 3)</a></td>
<td >The firmware to make the sweet sweet music</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/23/pinball-the-music-player-part-4/">Pinball: The Music Player (Part 4)</a></td>
<td >The test program for the music player</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/26/pinball-the-motors-hbridge/" target="_blank">Pinball: The Motors + HBridge</a></td>
<td >Using an Bridge to control DC Motors</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/27/pinball-the-eagle-schematic/" target="_blank">Pinball: The Eagle Schematic</a></td>
<td >All of the circuits into an Eagle schematic</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/29/pinball-the-printed-circuit-board-version-1-0/" target="_blank">Pinball: The Printed Circuit Board 1.0</a></td>
<td >The first Eagle PCB layout of the printed circuit board</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2016/09/30/pinball-the-pcb-version-1-0-fail/" target="_blank">Pinball: The PCB Version 1.0 Fail</a></td>
<td >Problems with the first version of the Eagle PCB layout</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2017/01/05/pinball-pcb-1-2-updates-using-eagle/" target="_blank">Pinball: PCB Layout 1.2 Updates using Eagle</a></td>
<td >Fixing the errors on the first two versions of the Eagle PCB</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2017/01/12/pinball-pcb-solder-reflow-osh-park-eagle/">Pinball: Assemble and Reflow the 1.2 PCB</a></td>
<td >Assembling the Eagle PCB</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2017/01/23/pinball-testing-the-eagle-pcb/" target="_blank">Pinball: Testing the Eagle PCB</a></td>
<td > Firmware to test the newly built Pinball printed circuit board</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2017/02/09/pinball-debugging-psoc-motor-driver/" target="_blank">Pinball: Debugging the Motor Driver</a></td>
<td > Fixing the motor driver PSoC project</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2017/02/13/hot-air-solder-reworking-the-accelerometer/" target="_blank">Pinball: Hot-Air Reworking the Accelerometer Solder</a></td>
<td >Using a Hot-Air Rework tool to reflow a QFN</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2017/02/16/pinball-debugging-lm317-power-supply-tale-getting-lucky/" target="_blank">Pinball: Debugging the LM317 Power Supply- A Tale of Getting Lucky</a></td>
<td >Debugging the LM317/LM117 power supply</td>
</tr>
</tbody></table></div></p></span></p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/pinball-testing-the-eagle-pcb/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
