<?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>Embedded World 2019 &#8211; IoT Expert</title>
	<atom:link href="https://iotexpert.com/category/misc/embedded-world-2019/feed/" 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.4</generator>

<image>
	<url>https://iotexpert.com/wp-content/uploads/2017/01/cropped-Avatar-32x32.jpg</url>
	<title>Embedded World 2019 &#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="auto, (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="auto, (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="auto, (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="auto, (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="auto, (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="auto, (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="auto, (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="auto, (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="auto, (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="auto, (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="auto, (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="auto, (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="auto, (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>
	</channel>
</rss>
