<?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 2021 &#8211; IoT Expert</title>
	<atom:link href="https://iotexpert.com/category/misc/embedded-world-2021/feed/" rel="self" type="application/rss+xml" />
	<link>https://iotexpert.com</link>
	<description>Engineering for the Internet of Things</description>
	<lastBuildDate>Wed, 31 Mar 2021 17:52:23 +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 2021 &#8211; IoT Expert</title>
	<link>https://iotexpert.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>EW21: Lesson 0: Introduction &#038; Resources</title>
		<link>https://iotexpert.com/ew21-lesson-0-introduction-resources/</link>
					<comments>https://iotexpert.com/ew21-lesson-0-introduction-resources/#comments</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Wed, 24 Feb 2021 15:27:25 +0000</pubDate>
				<category><![CDATA[Embedded World 2021]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=10777</guid>

					<description><![CDATA[Summary Hello everyone.  This is lesson 0 of a series of 7 lessons about creating an IoT application using the Infineon ModusToolbox Software Environment to create a WiFi enabled drone.  In the next two hours we will build a remote control that uses the PSoC 6 MCU, WiFi, MQTT, CapSense and a 3-D Magnetic Joystick. [&#8230;]]]></description>
										<content:encoded><![CDATA[<h1>Summary</h1>
<p>Hello everyone.  This is lesson 0 of a series of 7 lessons about creating an IoT application using the Infineon ModusToolbox Software Environment to create a WiFi enabled drone.  In the next two hours we will build a remote control that uses the PSoC 6 MCU, WiFi, MQTT, CapSense and a 3-D Magnetic Joystick.  Then we will build the drone which will use a PSoC 6, WiFi, MQTT, CapSense and a BLDC motor controller.</p>
<p>What I will do today is take you lesson by lesson through the class and talk about how it all works and what you need to do.  When I built the class it was absolutely my goal to have every button click and line of code described.  That being said,  it is likely that I made some errors.  So, during the class you will be able to send messages to my team who will answer the questions, or ask me and I&#8217;ll answer live.  If you missed the class, that’s OK, you will be able to watch it on replay.  In addition if you have a question after the live stream is over, leave a comment here and I&#8217;ll answer.</p>
<p>I will attempt to go slowly enough for you to follow along, but if I go to fast, don’t worry you should be able to follow along with the instructions on this website.</p>
<p>Every lesson will have this table in it and you will be able to click to follow along with the different lessons.</p>
<p><span><h1>Embedded World 2021 - Infineon ModusToolbox PSoC 6 Drone </h1>
<p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >#</th>
<th >Description</th>
</tr>
</thead>
<tbody>
<tr><td >0</td>
<td ><a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/" target="_blank" rel="noopener">Introduction &amp; Resources</a></td>
</tr>

<tr><td >1</td>
<td ><a href="https://iotexpert.com/ew21-lesson-1-freertos-capsense/" target="_blank" rel="noopener">FreeRTOS &amp; CapSense</a></td>
</tr>

<tr><td >2</td>
<td ><a href="https://iotexpert.com/ew21-lesson-2-joystick/" target="_blank" rel="noopener">3-D Magnetic Sensing XENSIV Joystick</a></td>
</tr>

<tr><td >3</td>
<td ><a href="https://iotexpert.com/ew21-lesson-3-wifi/" target="_blank" rel="noopener">WiFi</a></td>
</tr>

<tr><td >4</td>
<td ><a href="https://iotexpert.com/ew21-lesson-4-mqtt/" target="_blank" rel="noopener">MQTT</a></td>
</tr>

<tr><td >5</td>
<td ><a href="https://iotexpert.com/ew21-lesson-5-low-power/" target="_blank" rel="noopener">Low Power</a></td>
</tr>

<tr><td >6</td>
<td ><a href="https://iotexpert.com/ew21-lesson-6-motor-control/" target="_blank" rel="noopener">BLDC Motor Control</a></td>
</tr>

<tr><td >7</td>
<td ><a href="https://iotexpert.com/ew21-lesson-7-ws2812-led-strip/" target="_blank" rel="noopener">WS2812 Strip LEDs</a></td>
</tr>
</tbody></table></div></p>
<p>&nbsp;</p></span></p>
<p>Here is the overall system architecture:</p>
<p><a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/arch-1/" rel="attachment wp-att-10972"><img fetchpriority="high" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/arch-1-1-1024x433.png" alt="" width="1024" height="433" class="alignnone size-large wp-image-10972" srcset="https://iotexpert.com/wp-content/uploads/2021/02/arch-1-1-1024x433.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/arch-1-1-300x127.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/arch-1-1-768x324.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/arch-1-1-1536x649.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/arch-1-1-600x253.png 600w, https://iotexpert.com/wp-content/uploads/2021/02/arch-1-1.png 1631w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>The Remote Control</h1>
<p>The remote control is built with two Infineon development boards</p>
<div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >Kit</th>
<th >Features</th>
</tr>
</thead>
<tbody>
<tr><td ><a href="https://www.cypress.com/documentation/development-kitsboards/psoc-6-wi-fi-bt-prototyping-kit-cy8cproto-062-4343w" target="_blank" rel="noopener">CY8CPROTO-062-4343W</a></td>
<td >PSoC 6,CYW4343W WiFi Bluetooth Combo Radio,CapSense</td>
</tr>

<tr><td ><a href="https://www.infineon.com/cms/en/product/evaluation-boards/tle493d-w2b6-ms2go/" target="_blank" rel="noopener">TLE493D-W2B6</a></td>
<td >XENSIV 3-D Magnetic Sensor</td>
</tr>
</tbody></table></div>
<p>Here are some pictures.</p>
<p>CY8CPROTO-062-4343W.  The top left of the board is a KitProg programmer.  The middle third on the left is the 4343W and the PSoC 6.  The bottom right are the CapSense buttons.  Just to the right of the programmer is a SD Card holder and S512FL Quad SPI Flash.</p>
<p><a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/img_0496/" rel="attachment wp-att-11018"><img decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0496-1024x806.jpg" alt="" width="1024" height="806" class="alignnone size-large wp-image-11018" srcset="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0496-1024x806.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0496-300x236.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0496-768x605.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0496-1536x1210.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0496-2048x1613.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0496-600x473.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>This the the top of the TLE-493D-W2B6 3-D magnetic sensor board.  On the far right, the tiny 6 pin chip is the actual sensor.  The big hole to the left of the sensor is to mount a magnet.  The two chips on the left are used as a bridge to USB (if you are developing).  I attach to this device using the I2C interface pins.</p>
<p><a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/img_0503/" rel="attachment wp-att-11027"><img decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0503-1024x402.jpg" alt="" width="1024" height="402" class="alignnone size-large wp-image-11027" srcset="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0503-1024x402.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0503-300x118.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0503-768x302.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0503-1536x604.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0503-2048x805.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0503-600x236.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Here is the back where you can see the SCL, SDA, Power and Ground labeled.  Unfortunately, they are in the wrong order to plug directly into the PSoC kit so Greg had to make a little wire switcher.</p>
<p><a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/img_0504/" rel="attachment wp-att-11026"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0504-1024x397.jpg" alt="" width="1024" height="397" class="alignnone size-large wp-image-11026" srcset="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0504-1024x397.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0504-300x116.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0504-768x297.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0504-1536x595.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0504-2048x793.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0504-600x232.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Here is the board with the really really cool 3-d printed joystick.  Simply two pieces of plastic with a magnet in the bottom.</p>
<p><a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/img_0494/" rel="attachment wp-att-11020"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0494-1024x914.jpg" alt="" width="1024" height="914" class="alignnone size-large wp-image-11020" srcset="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0494-1024x914.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0494-300x268.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0494-768x686.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0494-1536x1371.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0494-2048x1828.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0494-600x536.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>This picture show how the magnetic sense board is mounted onto the kit</p>
<p><a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/img_0505/" rel="attachment wp-att-11029"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0505-686x1024.jpg" alt="" width="686" height="1024" class="alignnone size-large wp-image-11029" srcset="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0505-686x1024.jpg 686w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0505-201x300.jpg 201w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0505-768x1146.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0505-1029x1536.jpg 1029w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0505-1372x2048.jpg 1372w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0505-600x895.jpg 600w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0505-scaled.jpg 1716w" sizes="(max-width: 686px) 100vw, 686px" /></a></p>
<p>Here is the whole thing assembled.</p>
<p><a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/img_0493-2/" rel="attachment wp-att-11021"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0493-1024x595.jpg" alt="" width="1024" height="595" class="alignnone size-large wp-image-11021" srcset="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0493-1024x595.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0493-300x174.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0493-768x446.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0493-1536x893.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0493-2048x1191.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0493-600x349.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>The Crazy Drone</h1>
<p>The drone was built with</p>
<div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >Kit</th>
<th >Features</th>
</tr>
</thead>
<tbody>
<tr><td ><a href="https://www.cypress.com/documentation/development-kitsboards/psoc-62s2-wi-fi-bt-pioneer-kit-cy8ckit-062s2-43012" target="_blank" rel="noopener">CY8CKIT-062S2-43012</a></td>
<td >PSoC 6 + CYW43012 Low Power Bluetooth WiFI Combo</td>
</tr>

<tr><td ><span><a href="https://www.infineon.com/cms/en/product/evaluation-boards/bldc_shield_tle9879/" target="_blank" rel="noopener">TLE9879WXA40</a></td>
<td >BLDC Control Shield</span></td>
</tr>
</tbody></table></div>
<p>Here is a picture of the CY8CKIT-062S2-43012.  On the far right in the middle is the PSoC 6 and CYW43012.  In the lower right are the CapSense Buttons and Slider.  The KitProg IC is just below the top Arduino Header.</p>
<p><a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/img_0495/" rel="attachment wp-att-11017"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0495-1024x748.jpg" alt="" width="1024" height="748" class="alignnone size-large wp-image-11017" srcset="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0495-1024x748.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0495-300x219.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0495-768x561.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0495-1536x1122.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0495-600x438.jpg 600w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0495.jpg 2018w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>In order to drive the BLDC motor I use the TLE9879WXA40 Motor Shield.  This has everything needed to do Field Oriented Control of a 3-phase BLDC motor.  The Blue, Green and White wires are the 3-phases of the BLDC.  The Red and Black are simply +12V and Ground.  You interface from the PSoC to the BLDC shield via a SPI interface (attached to the Arduino pins).</p>
<p><a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/img_0497/" rel="attachment wp-att-11019"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0497-1024x781.jpg" alt="" width="1024" height="781" class="alignnone size-large wp-image-11019" srcset="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0497-1024x781.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0497-300x229.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0497-768x585.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0497-1536x1171.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0497-2048x1561.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0497-600x457.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>The BLDC motor is mounted into a 3-d printed holder.  The mount is attached to hollow carbon fiber tubes that run on bearings that you see below.  The wires run down through the tubes.</p>
<p><a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/img_0502/" rel="attachment wp-att-11016"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0502-768x1024.jpg" alt="" width="768" height="1024" class="alignnone size-large wp-image-11016" srcset="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0502-768x1024.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0502-225x300.jpg 225w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0502-1152x1536.jpg 1152w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0502-1536x2048.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0502-600x800.jpg 600w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0502-scaled.jpg 1920w" sizes="(max-width: 768px) 100vw, 768px" /></a></p>
<p>At the bottom, the blue box just provides +12v to the drone and the PSoC board.</p>
<p><a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/img_0500/" rel="attachment wp-att-11015"></a> <a href="https://iotexpert.com/?attachment_id=11014" rel="attachment wp-att-11014"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0501-1024x662.jpg" alt="" width="1024" height="662" class="alignnone size-large wp-image-11014" srcset="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0501-1024x662.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0501-300x194.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0501-768x496.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0501-1536x993.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0501-2048x1324.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0501-600x388.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Here is a closer picture of the BLDC motor.</p>
<p><a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/img_0499/" rel="attachment wp-att-11013"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0499-1024x768.jpg" alt="" width="1024" height="768" class="alignnone size-large wp-image-11013" srcset="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0499-1024x768.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0499-300x225.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0499-768x576.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0499-1536x1152.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0499-2048x1536.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0499-600x450.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Here is a picture of the whole crazy thing running.  If you look in the background you can see a top secret new PSoC motor controller.  Is that an Easter egg?</p>
<p><a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/img_0491-2/" rel="attachment wp-att-11024"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0491-2-1024x947.jpg" alt="" width="1024" height="947" class="alignnone size-large wp-image-11024" srcset="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0491-2-1024x947.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0491-2-300x277.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0491-2-768x710.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0491-2-1536x1420.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0491-2-2048x1894.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0491-2-600x555.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>And yes, it will cut your fingers off if you aren&#8217;t careful.</p>
<p><a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/img_0492-2/" rel="attachment wp-att-11022"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0492-2-1024x674.jpg" alt="" width="1024" height="674" class="alignnone size-large wp-image-11022" srcset="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0492-2-1024x674.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0492-2-300x198.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0492-2-768x506.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0492-2-1536x1012.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0492-2-600x395.jpg 600w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0492-2.jpg 1998w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>Resources</h1>
<p>You will need a few things for this class:</p>
<ul>
<li><a href="https://www.cypress.com/products/modustoolbox-software-environment" target="_blank" rel="noopener">ModusToolbox Software Environment</a></li>
<li><a href="https://www.cypress.com/documentation/development-kitsboards/psoc-6-wi-fi-bt-prototyping-kit-cy8cproto-062-4343w" target="_blank" rel="noopener">PSoC 6 WiFi-BT Prototyping Kit (CY8CPROTO-062-4343W)</a></li>
<li>(optional) <a href="https://www.cypress.com/documentation/development-kitsboards/psoc-62s2-wi-fi-bt-pioneer-kit-cy8ckit-062s2-43012" target="_blank" rel="noopener">PSoC 62S2 WiFi-BT Pioneer Kit  (CY8CKIT-062S2-43012)</a></li>
<li>(optional) <a href="https://www.infineon.com/cms/en/product/evaluation-boards/tle493d-w2b6-ms2go/" target="_blank" rel="noopener">XENSIV TLE493D-W2B6 MS2GO and JOYSTICK FOR 3D 2 GO KIT</a></li>
<li>(optional) <a href="https://www.infineon.com/cms/en/product/evaluation-boards/bldc_shield_tle9879/" target="_blank" rel="noopener">BLDC SHIELD TLE9879TOBO1</a></li>
<li>(optional) Readytosky 2212 920KV Brushless Motors and Readytosky 10&#215;4.5 1045 Propeller</li>
</ul>
<h1>ModusToolbox Software Environment</h1>
<p>You can download Modus Toolbox from <a href="https://www.cypress.com/products/modustoolbox-software-environment" target="_blank" rel="noopener">here</a></p>
<p><a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/screen-shot-2021-02-24-at-7-20-59-am/" rel="attachment wp-att-11041"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-7.20.59-AM-1008x1024.jpg" alt="" width="1008" height="1024" class="alignnone size-large wp-image-11041" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-7.20.59-AM-1008x1024.jpg 1008w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-7.20.59-AM-295x300.jpg 295w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-7.20.59-AM-768x781.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-7.20.59-AM-1511x1536.jpg 1511w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-7.20.59-AM-600x610.jpg 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-7.20.59-AM.jpg 1716w" sizes="(max-width: 1008px) 100vw, 1008px" /></a></p>
<h1>CY8CPROTO-062-4343W</h1>
<p>You can read all about this development kit on the <a href="https://www.cypress.com/documentation/development-kitsboards/psoc-6-wi-fi-bt-prototyping-kit-cy8cproto-062-4343w" target="_blank" rel="noopener">website</a> or in the <a href="https://www.cypress.com/file/457891/download" target="_blank" rel="noopener">KitGuide</a></p>
<p><a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/screen-shot-2021-02-24-at-6-48-47-am/" rel="attachment wp-att-11031"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.48.47-AM-817x1024.jpg" alt="" width="817" height="1024" class="alignnone size-large wp-image-11031" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.48.47-AM-817x1024.jpg 817w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.48.47-AM-239x300.jpg 239w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.48.47-AM-768x963.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.48.47-AM-1225x1536.jpg 1225w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.48.47-AM-1634x2048.jpg 1634w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.48.47-AM-600x752.jpg 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.48.47-AM.jpg 1752w" sizes="(max-width: 817px) 100vw, 817px" /></a></p>
<h1>CY8CKIT-062S2-43012</h1>
<p>You can read all about this development kit on the <a href="https://www.cypress.com/documentation/development-kitsboards/psoc-62s2-wi-fi-bt-pioneer-kit-cy8ckit-062s2-43012" target="_blank" rel="noopener">website</a> or in the <a href="https://www.cypress.com/file/487006/download" target="_blank" rel="noopener">KitGuide</a></p>
<p><a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/screen-shot-2021-02-24-at-6-55-57-am/" rel="attachment wp-att-11032"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.55.57-AM-1024x713.jpg" alt="" width="1024" height="713" class="alignnone size-large wp-image-11032" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.55.57-AM-1024x713.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.55.57-AM-300x209.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.55.57-AM-768x535.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.55.57-AM-1536x1070.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.55.57-AM-2048x1426.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.55.57-AM-600x418.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p><a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/screen-shot-2021-02-24-at-6-56-23-am/" rel="attachment wp-att-11033"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.56.23-AM-1024x745.png" alt="" width="1024" height="745" class="alignnone size-large wp-image-11033" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.56.23-AM-1024x745.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.56.23-AM-300x218.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.56.23-AM-768x559.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.56.23-AM-1536x1118.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.56.23-AM-2048x1490.png 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.56.23-AM-600x437.png 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a> <a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/screen-shot-2021-02-24-at-6-56-41-am/" rel="attachment wp-att-11034"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.56.41-AM-1024x668.png" alt="" width="1024" height="668" class="alignnone size-large wp-image-11034" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.56.41-AM-1024x668.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.56.41-AM-300x196.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.56.41-AM-768x501.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.56.41-AM-1536x1002.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.56.41-AM-2048x1336.png 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.56.41-AM-600x391.png 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a> <a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/screen-shot-2021-02-24-at-6-56-48-am/" rel="attachment wp-att-11035"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.56.48-AM-1024x714.png" alt="" width="1024" height="714" class="alignnone size-large wp-image-11035" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.56.48-AM-1024x714.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.56.48-AM-300x209.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.56.48-AM-768x536.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.56.48-AM-1536x1071.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.56.48-AM-2048x1428.png 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.56.48-AM-600x418.png 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a> <a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/screen-shot-2021-02-24-at-6-56-56-am/" rel="attachment wp-att-11036"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.56.56-AM-1024x684.png" alt="" width="1024" height="684" class="alignnone size-large wp-image-11036" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.56.56-AM-1024x684.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.56.56-AM-300x200.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.56.56-AM-768x513.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.56.56-AM-1536x1025.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.56.56-AM-2048x1367.png 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-6.56.56-AM-600x400.png 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>TLE9879QXA40 BLDC Motor Controller</h1>
<p>You can read all about this development kit on the <a href="https://www.infineon.com/cms/en/product/evaluation-boards/bldc_shield_tle9879/" target="_blank" rel="noopener">website</a> or in the <a href="https://www.infineon.com/dgdl/Infineon-TLE9879QXA40-DS-v01_00-EN.pdf?fileId=5546d4625a888733015a89d10a283f20" target="_blank" rel="noopener">KitGuide</a></p>
<p><a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/img_0506/" rel="attachment wp-att-11037"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0506-1024x861.jpg" alt="" width="1024" height="861" class="alignnone size-large wp-image-11037" srcset="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0506-1024x861.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0506-300x252.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0506-768x645.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0506-1536x1291.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0506-2048x1721.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0506-600x504.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>XENSIV TLE493D</h1>
<p>You can read all about this development kit on the <a href="https://www.infineon.com/cms/en/product/evaluation-boards/tle493d-w2b6-ms2go/" target="_blank" rel="noopener">website</a> or in the <a href="https://www.infineon.com/dgdl/Infineon-Infineon-3DMS2GO_TLE493D-W2B6-UM-v01_01-EN-UserManual-v01_01-EN.pdf?fileId=5546d462636cc8fb016418342fea3f54" target="_blank" rel="noopener">KitGuide</a></p>
<p><a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/screen-shot-2021-02-24-at-7-08-06-am/" rel="attachment wp-att-11038"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-7.08.06-AM-1024x492.jpg" alt="" width="1024" height="492" class="alignnone size-large wp-image-11038" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-7.08.06-AM-1024x492.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-7.08.06-AM-300x144.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-7.08.06-AM-768x369.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-7.08.06-AM-1536x738.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-7.08.06-AM-2048x984.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-7.08.06-AM-600x288.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/ew21-lesson-0-introduction-resources/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>EW21: Lesson 1: FreeRTOS + CapSense</title>
		<link>https://iotexpert.com/ew21-lesson-1-freertos-capsense/</link>
					<comments>https://iotexpert.com/ew21-lesson-1-freertos-capsense/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Wed, 24 Feb 2021 15:26:52 +0000</pubDate>
				<category><![CDATA[Embedded World 2021]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=10776</guid>

					<description><![CDATA[Summary In lesson 1 we will create our first project, which like every good embedded project, will start with the blinking LED.  Then I will show you how to add a CapSense slider and two buttons.  At the end of lesson one you will have the &#8220;CapSense Task&#8221; colored green.  Here is the architecture: Learning [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><span><h1>Embedded World 2021 - Infineon ModusToolbox PSoC 6 Drone </h1>
<p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >#</th>
<th >Description</th>
</tr>
</thead>
<tbody>
<tr><td >0</td>
<td ><a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/" target="_blank" rel="noopener">Introduction &amp; Resources</a></td>
</tr>

<tr><td >1</td>
<td ><a href="https://iotexpert.com/ew21-lesson-1-freertos-capsense/" target="_blank" rel="noopener">FreeRTOS &amp; CapSense</a></td>
</tr>

<tr><td >2</td>
<td ><a href="https://iotexpert.com/ew21-lesson-2-joystick/" target="_blank" rel="noopener">3-D Magnetic Sensing XENSIV Joystick</a></td>
</tr>

<tr><td >3</td>
<td ><a href="https://iotexpert.com/ew21-lesson-3-wifi/" target="_blank" rel="noopener">WiFi</a></td>
</tr>

<tr><td >4</td>
<td ><a href="https://iotexpert.com/ew21-lesson-4-mqtt/" target="_blank" rel="noopener">MQTT</a></td>
</tr>

<tr><td >5</td>
<td ><a href="https://iotexpert.com/ew21-lesson-5-low-power/" target="_blank" rel="noopener">Low Power</a></td>
</tr>

<tr><td >6</td>
<td ><a href="https://iotexpert.com/ew21-lesson-6-motor-control/" target="_blank" rel="noopener">BLDC Motor Control</a></td>
</tr>

<tr><td >7</td>
<td ><a href="https://iotexpert.com/ew21-lesson-7-ws2812-led-strip/" target="_blank" rel="noopener">WS2812 Strip LEDs</a></td>
</tr>
</tbody></table></div></p>
<p>&nbsp;</p></span></p>
<h1>Summary</h1>
<p>In lesson 1 we will create our first project, which like every good embedded project, will start with the blinking LED.  Then I will show you how to add a CapSense slider and two buttons.  At the end of lesson one you will have the &#8220;CapSense Task&#8221; colored green.  Here is the architecture:</p>
<p><a href="https://iotexpert.com/ew21-lesson-1-freertos-capsense/l1-arch/" rel="attachment wp-att-10974"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/l1-arch-1024x433.png" alt="" width="1024" height="433" class="alignnone size-large wp-image-10974" srcset="https://iotexpert.com/wp-content/uploads/2021/02/l1-arch-1024x433.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/l1-arch-300x127.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/l1-arch-768x324.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/l1-arch-1536x649.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/l1-arch-600x253.png 600w, https://iotexpert.com/wp-content/uploads/2021/02/l1-arch.png 1631w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>Learning Objectives</h1>
<p>By the end of this lesson I would like you to know about:</p>
<ol>
<li>Creating and building your first ModusToolbox PSoC 6 MCU Project</li>
<li>The organization of a ModusToolbox project</li>
<li>An introduction to CapSense</li>
</ol>
<h1>Procedure</h1>
<p>We will follow these steps:</p>
<ol>
<li>Update manifest.loc</li>
<li>Create the new project</li>
<li>A Tour of your project</li>
<li>Test the basic project</li>
<li>Add a CapSense task header file</li>
<li>Add a CapSense task dot-c file</li>
<li>Update main.c</li>
<li>Test the CapSense</li>
</ol>
<ol></ol>
<h3>1. Update the manifest.loc</h3>
<p>After you install ModusToolbox, there is a subdirectory in your home directory called &#8220;.modustoolbox&#8221;.  You will almost never need to look in this directory.  However, it contains two interesting things:</p>
<ol>
<li>A cache of the libraries (more on this later)</li>
<li>A file called &#8220;manifest.loc&#8221; which will allow you to extend the functionality of Modus Toolbox.</li>
</ol>
<p>By adding a URL to the manifest.loc you can add in new</p>
<ol>
<li>Middleware</li>
<li>Board Support Packages</li>
<li>Example Projects</li>
</ol>
<p>To make the Embedded World easier, I have extended ModusToolbox to give you access to some example projects and libraries that I created.  To get access you need to add the line &#8220;https://github.com/iotexpert/mtb2-iotexpert-manifests/raw/master/iotexpert-super-manifest.xml&#8221; into the manifest.loc file.  You can do that with any editor.  Here is how it looks on my Mac.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">arh ~ $ cd .modustoolbox/
arh .modustoolbox $ ls
cache		manifest.loc	manifest.loc~
arh .modustoolbox $ more manifest.loc
https://github.com/iotexpert/mtb2-iotexpert-manifests/raw/master/iotexpert-super-manifest.xml
</pre>
<h3>2. Create the new project</h3>
<p>Now I start the new project creator from the start menu.  Our first project will be using the CY8CPROTO-062-4343W, pick it and press next.</p>
<p><a href="https://iotexpert.com/ew21-lesson-1-freertos-capsense/screen-shot-2021-02-22-at-5-40-40-pm/" rel="attachment wp-att-10840"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-5.40.40-PM-1024x710.jpg" alt="" width="1024" height="710" class="alignnone size-large wp-image-10840" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-5.40.40-PM-1024x710.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-5.40.40-PM-300x208.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-5.40.40-PM-768x532.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-5.40.40-PM-1536x1064.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-5.40.40-PM-2048x1419.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-5.40.40-PM-600x416.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>In the filter box type &#8220;IoT&#8221; which will filter to my template projects.  To start with we will use the &#8220;IoT Expert FreeRTOS Template&#8221; which is a basic project I created that gives you a blinking LED, a UART console and FreeRTOS.  Pick that and give it a sensible name.</p>
<p><a href="https://iotexpert.com/ew21-lesson-1-freertos-capsense/screen-shot-2021-02-22-at-5-42-12-pm/" rel="attachment wp-att-10841"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-5.42.12-PM-1024x709.jpg" alt="" width="1024" height="709" class="alignnone size-large wp-image-10841" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-5.42.12-PM-1024x709.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-5.42.12-PM-300x208.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-5.42.12-PM-768x532.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-5.42.12-PM-1536x1063.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-5.42.12-PM-2048x1418.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-5.42.12-PM-600x415.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>After a bit of processing you will have a new application, press close.</p>
<p><a href="https://iotexpert.com/ew21-lesson-1-freertos-capsense/screen-shot-2021-02-22-at-6-00-13-pm/" rel="attachment wp-att-10842"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.00.13-PM-1024x223.png" alt="" width="1024" height="223" class="alignnone size-large wp-image-10842" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.00.13-PM-1024x223.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.00.13-PM-300x65.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.00.13-PM-768x167.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.00.13-PM-1536x334.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.00.13-PM-2048x445.png 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.00.13-PM-600x130.png 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>For this class I am going to use Visual Studio Code.  ModusToolbox also has an Eclipse IDE which you can use, or you can use the command line, IAR, or MicroVision &#8211; it&#8217;s entirely up to you.  To tell Visual Studio code about my project I will run &#8220;make vscode&#8221; which will build a vscode project.  Then I run vscode with &#8220;code .&#8221;</p>
<p><a href="https://iotexpert.com/ew21-lesson-1-freertos-capsense/screen-shot-2021-02-22-at-6-08-43-pm/" rel="attachment wp-att-10844"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.08.43-PM-888x1024.jpg" alt="" width="888" height="1024" class="alignnone size-large wp-image-10844" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.08.43-PM-888x1024.jpg 888w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.08.43-PM-260x300.jpg 260w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.08.43-PM-768x885.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.08.43-PM-1332x1536.jpg 1332w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.08.43-PM-600x692.jpg 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.08.43-PM.jpg 1530w" sizes="(max-width: 888px) 100vw, 888px" /></a><a href="https://iotexpert.com/ew21-lesson-1-freertos-capsense/screen-shot-2021-02-22-at-6-06-49-pm/" rel="attachment wp-att-10843"></a></p>
<p>The make vscode will build all of the files you need including a workspace.  Click&#8221;Open Workspace&#8221;</p>
<p><a href="https://iotexpert.com/?attachment_id=10846" rel="attachment wp-att-10846"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.10.16-PM.png" alt="" width="946" height="292" class="alignnone size-large wp-image-10846" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.10.16-PM.png 946w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.10.16-PM-300x93.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.10.16-PM-768x237.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.10.16-PM-600x185.png 600w" sizes="(max-width: 946px) 100vw, 946px" /></a></p>
<h3>3. A Tour of your Project</h3>
<p>Start a file browser and look around inside your project.</p>
<p><a href="https://iotexpert.com/ew21-lesson-1-freertos-capsense/screen-shot-2021-02-22-at-6-06-49-pm/" rel="attachment wp-att-10843"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.06.49-PM-1024x773.jpg" alt="" width="1024" height="773" class="alignnone size-large wp-image-10843" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.06.49-PM-1024x773.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.06.49-PM-300x226.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.06.49-PM-768x580.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.06.49-PM-1536x1159.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.06.49-PM-600x453.jpg 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.06.49-PM.jpg 1638w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>You can also see these in Visual Studio Code.</p>
<p><a href="https://iotexpert.com/ew21-lesson-1-freertos-capsense/screen-shot-2021-02-22-at-6-12-36-pm/" rel="attachment wp-att-10847"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.12.36-PM-1024x817.jpg" alt="" width="1024" height="817" class="alignnone size-large wp-image-10847" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.12.36-PM-1024x817.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.12.36-PM-300x239.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.12.36-PM-768x613.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.12.36-PM-1536x1225.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.12.36-PM-2048x1634.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.12.36-PM-600x479.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h3>4. Test the basic project</h3>
<p>Now click the debug icon along the left and click the play button to build the project, program it and launch the debugger.</p>
<p>(You can use the drop-down menu to select &#8220;Program (KitProg3_MiniProg4)&#8221; and then click the play button if you just want to build and program without launching the debugger.)</p>
<p><a href="https://iotexpert.com/ew21-lesson-1-freertos-capsense/screen-shot-2021-02-22-at-6-16-29-pm/" rel="attachment wp-att-10850"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.16.29-PM.png" alt="" width="832" height="588" class="alignnone size-full wp-image-10850" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.16.29-PM.png 832w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.16.29-PM-300x212.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.16.29-PM-768x543.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.16.29-PM-600x424.png 600w" sizes="(max-width: 832px) 100vw, 832px" /></a></p>
<p>Notice on the console a bunch of stuff comes ripping out&#8230; then it programs your development board.</p>
<p><a href="https://iotexpert.com/ew21-lesson-1-freertos-capsense/screen-shot-2021-02-22-at-6-13-07-pm/" rel="attachment wp-att-10848"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.13.07-PM-1024x763.png" alt="" width="1024" height="763" class="alignnone size-large wp-image-10848" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.13.07-PM-1024x763.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.13.07-PM-300x223.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.13.07-PM-768x572.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.13.07-PM-1536x1144.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.13.07-PM-600x447.png 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.13.07-PM.png 1842w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Once that is done the debugger starts and runs until the start of main.  Press play to get things going.</p>
<p><a href="https://iotexpert.com/ew21-lesson-1-freertos-capsense/screen-shot-2021-02-22-at-6-16-52-pm/" rel="attachment wp-att-10851"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.16.52-PM-1024x815.jpg" alt="" width="1024" height="815" class="alignnone size-large wp-image-10851" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.16.52-PM-1024x815.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.16.52-PM-300x239.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.16.52-PM-768x611.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.16.52-PM-1536x1223.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.16.52-PM-2048x1631.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.16.52-PM-600x478.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h3>5. Add a CapSense task header file</h3>
<p>Now that we have a functioning blinking LED project, let&#8217;s add CapSense.  Remember from the architecture picture above that I am going to have a task just for CapSense.  Start by making the public header file called &#8220;capsense_task.h&#8221;</p>
<p><a href="https://iotexpert.com/ew21-lesson-1-freertos-capsense/screen-shot-2021-02-22-at-6-19-09-pm/" rel="attachment wp-att-10853"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.19.09-PM.png" alt="" width="880" height="828" class="alignnone size-large wp-image-10853" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.19.09-PM.png 880w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.19.09-PM-300x282.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.19.09-PM-768x723.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.19.09-PM-600x565.png 600w" sizes="(max-width: 880px) 100vw, 880px" /></a></p>
<p>In that file there will only be the definition of the task.</p>
<p><a href="https://iotexpert.com/ew21-lesson-1-freertos-capsense/screen-shot-2021-02-22-at-6-19-46-pm/" rel="attachment wp-att-10852"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.19.46-PM-1024x474.png" alt="" width="1024" height="474" class="alignnone size-large wp-image-10852" data-wp-editing="1" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.19.46-PM-1024x474.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.19.46-PM-300x139.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.19.46-PM-768x355.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.19.46-PM-1536x711.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.19.46-PM-600x278.png 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.19.46-PM.png 2032w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h3>6. Add a CapSense task dot-c file</h3>
<p>Now we will create capsense_task.c.  In that file, you will need some includes to bring in the Infineon drivers.  After the includes I will define several functions</p>
<ol>
<li>capsense_init: Starts up the CapSense block</li>
<li>process_touch: Figures out what is being touched on the buttons and slider</li>
<li>capsense_isr: Used by the CapSense middleware to process the CapSense interrupt</li>
<li>capsense_end_of_scan_callback: Tells your application when the scanning is done</li>
<li>capsense_register_deepsleep: This allows the CPU to know when it can go to Deep Sleep without interfering with CapSense</li>
</ol>
<p>Finally I will define a semaphore to use to block my task until the CapSense scanning is done.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">#include &lt;stdio.h&gt;

#include "cybsp.h"
#include "cyhal.h"
#include "cycfg.h"
#include "cycfg_capsense.h"

#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"

#include "capsense_task.h"

static void capsense_init(void);
static void process_touch(void);
static void capsense_isr(void);
static void capsense_end_of_scan_callback(cy_stc_active_scan_sns_t* active_scan_sns_ptr);
static void capsense_register_deepsleep(void);
static QueueHandle_t capsense_done; // Semaphore set in Capsense Callback End of Scan</pre>
<p>The capsense_task function is called by FreeRTOS when it starts up.  This function does what it says</p>
<ol>
<li>Sets up a sempahore</li>
<li>Initializes the CapSense</li>
<li>Starts scanning</li>
<li>Waits for a scan to complete using a semaphore</li>
<li>Process the widgets</li>
<li>Looks at the touches</li>
<li>Starts another scan</li>
<li>Waits, then loops back</li>
</ol>
<pre class="EnlighterJSRAW" data-enlighter-language="c">/*******************************************************************************
* Function Name: task_capsense
********************************************************************************
* Summary:
*  Task that initializes the CapSense block and processes the touch input.
*
* Parameters:
*  void *param : Task parameter defined during task creation (unused)
*
*******************************************************************************/
void capsense_task(void* param)
{
    (void)param;

    capsense_done = xQueueCreateCountingSemaphore(1,0);

    capsense_init();

    Cy_CapSense_ScanAllWidgets(&amp;cy_capsense_context);

    for(;;)
    {
        xSemaphoreTake(capsense_done,portMAX_DELAY);

        Cy_CapSense_ProcessAllWidgets(&amp;cy_capsense_context);
        process_touch();
        Cy_CapSense_ScanAllWidgets(&amp;cy_capsense_context);
        vTaskDelay(50); // ~20hz update
    }
}
</pre>
<p>To initialize the CapSense you need to</p>
<ol>
<li>Initialize the  CapSense block</li>
<li>Setup the CapSense interrupt</li>
<li>Register the DeepSleep function</li>
<li>Ask to be called back when a scan finishes</li>
<li>Enable the CapSense block</li>
</ol>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">/*******************************************************************************
* Function Name: capsense_init
********************************************************************************
* Summary:
*  This function initializes the CSD HW block, and configures the CapSense
*  interrupt.
*******************************************************************************/
static void capsense_init(void)
{
    Cy_CapSense_Init(&amp;cy_capsense_context);
    
    static const cy_stc_sysint_t capSense_intr_config =
    {
        .intrSrc = csd_interrupt_IRQn,
        .intrPriority = 7,
    };

    /* Initialize CapSense interrupt */
    Cy_SysInt_Init(&amp;capSense_intr_config, &amp;capsense_isr);
    NVIC_ClearPendingIRQ(capSense_intr_config.intrSrc);
    NVIC_EnableIRQ(capSense_intr_config.intrSrc);

    capsense_register_deepsleep();
    Cy_CapSense_RegisterCallback(CY_CAPSENSE_END_OF_SCAN_E,
                                              capsense_end_of_scan_callback, &amp;cy_capsense_context);
    
    Cy_CapSense_Enable(&amp;cy_capsense_context);
}
</pre>
<p>Infineon provides the ISR which is part of the CapSense scanning engine</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">/*******************************************************************************
* Function Name: capsense_isr
********************************************************************************
* Summary:
*  Wrapper function for handling interrupts from CSD block.
*
*******************************************************************************/
static void capsense_isr(void)
{
    Cy_CapSense_InterruptHandler(CYBSP_CSD_HW, &amp;cy_capsense_context);
}</pre>
<p>When a scan is done we want to unlock the capsense_task by giving the semaphore.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">/*******************************************************************************
* Function Name: capsense_end_of_scan_callback
********************************************************************************
* Summary:
*  CapSense end of scan callback function. This function sends a command to
*  CapSense task to process scan.
*
* Parameters:
*  cy_stc_active_scan_sns_t * active_scan_sns_ptr (unused)
*
*******************************************************************************/
static void capsense_end_of_scan_callback(cy_stc_active_scan_sns_t* active_scan_sns_ptr)
{
    BaseType_t xYieldRequired;

    (void)active_scan_sns_ptr;
    xYieldRequired = xSemaphoreGiveFromISR(capsense_done,&amp;xYieldRequired);

    portYIELD_FROM_ISR(xYieldRequired);
}</pre>
<p>The DeepSleep registration function looks like this:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">/*******************************************************************************
* Function Name: capsense_register_deepsleep
********************************************************************************
* Summary:
*  Wrapper function for setting up the Deep Sleep callback for CapSense.
*  This is necessary so that a transition from active to Deep Sleep does not
*  occur during a CapSense scan.
*
*  See the "MTB CAT1 Peripheral driver library documentation &gt; PDL API Reference &gt; SysPM"
*  link in the Quick Panel Documentation for information on setting up the SysPm callbacks
*******************************************************************************/
static void capsense_register_deepsleep(void)
{
    static cy_stc_syspm_callback_params_t callback_params =
    {
        .base       = CYBSP_CSD_HW,
        .context    = &amp;cy_capsense_context
    };

    static cy_stc_syspm_callback_t capsense_deep_sleep_cb =
    {
        Cy_CapSense_DeepSleepCallback,
        CY_SYSPM_DEEPSLEEP,
        0,
        &amp;callback_params,
        NULL,
        NULL
    };

    Cy_SysPm_RegisterCallback(&amp;capsense_deep_sleep_cb);
}</pre>
<p>The last bit of magic is the processing of the touches.  We will</p>
<ol>
<li>Look at the buttons</li>
<li>If they are pressed do a print out</li>
<li>Look a the slider (which gives you a value between 0 and 300).</li>
<li>If the slider is being pressed, print out the value</li>
<li>Save the current state of the buttons and slider for next time around.</li>
</ol>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">/*******************************************************************************
* Function Name: process_touch
*******************************************************************************/
static void process_touch(void)
{
    /* Variables used to store previous touch information */
    static uint32_t button0_status_prev = 0;
    static uint32_t button1_status_prev = 0;
    static uint16_t slider_pos_prev = 0;

    uint32_t button0_status = 0;
    uint32_t button1_status = 0;
    uint16_t slider_pos = 0;
    uint8_t slider_touched = 0;
    cy_stc_capsense_touch_t *slider_touch;

// Process the buttons

    button0_status = Cy_CapSense_IsWidgetActive(CY_CAPSENSE_BUTTON0_WDGT_ID,&amp;cy_capsense_context);
    button1_status = Cy_CapSense_IsSensorActive( CY_CAPSENSE_BUTTON1_WDGT_ID, CY_CAPSENSE_BUTTON1_SNS0_ID, &amp;cy_capsense_context);

    if((0u != button0_status) &amp;&amp; (0u == button0_status_prev))
    {
        printf("Button 0 pressed\n");
    }

    if((0u != button1_status) &amp;&amp; (0u == button1_status_prev))
    {
        printf("Button 1 pressed\n");
    }

// Process the slider
    slider_touch = Cy_CapSense_GetTouchInfo( CY_CAPSENSE_LINEARSLIDER0_WDGT_ID, &amp;cy_capsense_context);
    slider_pos = (slider_touch-&gt;ptrPosition-&gt;x / 3); // Transform 0-300 into 0-100
    slider_touched = slider_touch-&gt;numPosition;

    if((0u != slider_touched) &amp;&amp; (slider_pos_prev != slider_pos ))
    {
        printf("Slider position %d\n",slider_pos);
    }

    button0_status_prev = button0_status;
    button1_status_prev = button1_status;
    slider_pos_prev = slider_pos;
}</pre>
<h3>7. Update main.c</h3>
<p>In main.c we need to include the capsense_task header file</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">#include "capsense_task.h"
</pre>
<p>And startup the capsense_task</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">xTaskCreate(capsense_task, "CapSense", configMINIMAL_STACK_SIZE*4, NULL, 1, 0 );
</pre>
<h3>8. Test the CapSense</h3>
<p>Program your kit and you will be able to press the buttons and slider.</p>
<p><a href="https://iotexpert.com/ew21-lesson-1-freertos-capsense/screen-shot-2021-02-22-at-6-32-39-pm/" rel="attachment wp-att-10855"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.32.39-PM-1024x330.png" alt="" width="1024" height="330" class="alignnone size-large wp-image-10855" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.32.39-PM-1024x330.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.32.39-PM-300x97.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.32.39-PM-768x248.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.32.39-PM-1536x496.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.32.39-PM-600x194.png 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-6.32.39-PM.png 1618w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>Resources for Project</h1>
<p>Remember above when I started the project creator there was a list of projects.  This exact completed project is available to you as &#8220;IoT Expert Embedded World 2021 Lesson1&#8221;</p>
<p><a href="https://iotexpert.com/ew21-lesson-1-freertos-capsense/screen-shot-2021-02-22-at-4-32-53-pm/" rel="attachment wp-att-10814"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.32.53-PM-1024x584.png" alt="" width="1024" height="584" class="alignnone size-large wp-image-10814" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.32.53-PM-1024x584.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.32.53-PM-300x171.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.32.53-PM-768x438.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.32.53-PM-1536x876.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.32.53-PM-2048x1168.png 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.32.53-PM-600x342.png 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>You can also clone this project from git@github.com:iotexpert/ew21-lesson1.git or https://github.com/iotexpert/ew21-lesson1.git</p>
<div>For reference, here is the whole capsense_task.c file in one chunk</div>
<div>
<pre class="EnlighterJSRAW" data-enlighter-language="c">#include &lt;stdio.h&gt;

#include "cybsp.h"
#include "cyhal.h"
#include "cycfg.h"
#include "cycfg_capsense.h"

#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"

#include "capsense_task.h"

static void capsense_init(void);
static void process_touch(void);
static void capsense_isr(void);
static void capsense_end_of_scan_callback(cy_stc_active_scan_sns_t* active_scan_sns_ptr);
static void capsense_register_deepsleep(void);

static QueueHandle_t capsense_done; // Semaphore set in Capsense Callback End of Scan

/*******************************************************************************
* Function Name: task_capsense
********************************************************************************
* Summary:
*  Task that initializes the CapSense block and processes the touch input.
*
* Parameters:
*  void *param : Task parameter defined during task creation (unused)
*
*******************************************************************************/
void capsense_task(void* param)
{
    (void)param;

    capsense_done = xQueueCreateCountingSemaphore(1,0);

    capsense_init();

    Cy_CapSense_ScanAllWidgets(&amp;cy_capsense_context);

    for(;;)
    {
        xSemaphoreTake(capsense_done,portMAX_DELAY);

        Cy_CapSense_ProcessAllWidgets(&amp;cy_capsense_context);
        process_touch();
        Cy_CapSense_ScanAllWidgets(&amp;cy_capsense_context);
        vTaskDelay(50); // ~20hz update
    }
}

/*******************************************************************************
* Function Name: process_touch
*******************************************************************************/
static void process_touch(void)
{
    /* Variables used to store previous touch information */
    static uint32_t button0_status_prev = 0;
    static uint32_t button1_status_prev = 0;
    static uint16_t slider_pos_prev = 0;

    uint32_t button0_status = 0;
    uint32_t button1_status = 0;
    uint16_t slider_pos = 0;
    uint8_t slider_touched = 0;
    cy_stc_capsense_touch_t *slider_touch;

// Process the buttons

    button0_status = Cy_CapSense_IsWidgetActive(CY_CAPSENSE_BUTTON0_WDGT_ID,&amp;cy_capsense_context);
    button1_status = Cy_CapSense_IsSensorActive( CY_CAPSENSE_BUTTON1_WDGT_ID, CY_CAPSENSE_BUTTON1_SNS0_ID, &amp;cy_capsense_context);

    if((0u != button0_status) &amp;&amp; (0u == button0_status_prev))
    {
        printf("Button 0 pressed\n");
    }

    if((0u != button1_status) &amp;&amp; (0u == button1_status_prev))
    {
        printf("Button 1 pressed\n");
    }

// Process the slider
    slider_touch = Cy_CapSense_GetTouchInfo( CY_CAPSENSE_LINEARSLIDER0_WDGT_ID, &amp;cy_capsense_context);
    slider_pos = (slider_touch-&gt;ptrPosition-&gt;x / 3); // Transform 0-300 into 0-100
    slider_touched = slider_touch-&gt;numPosition;

    if((0u != slider_touched) &amp;&amp; (slider_pos_prev != slider_pos ))
    {
        printf("Slider position %d\n",slider_pos);
    }

    button0_status_prev = button0_status;
    button1_status_prev = button1_status;
    slider_pos_prev = slider_pos;
}


/*******************************************************************************
* Function Name: capsense_init
********************************************************************************
* Summary:
*  This function initializes the CSD HW block, and configures the CapSense
*  interrupt.
*******************************************************************************/
static void capsense_init(void)
{
    Cy_CapSense_Init(&amp;cy_capsense_context);
    
    static const cy_stc_sysint_t capSense_intr_config =
    {
        .intrSrc = csd_interrupt_IRQn,
        .intrPriority = 7,
    };

    /* Initialize CapSense interrupt */
    Cy_SysInt_Init(&amp;capSense_intr_config, &amp;capsense_isr);
    NVIC_ClearPendingIRQ(capSense_intr_config.intrSrc);
    NVIC_EnableIRQ(capSense_intr_config.intrSrc);

    capsense_register_deepsleep();

    Cy_CapSense_RegisterCallback(CY_CAPSENSE_END_OF_SCAN_E,
                                              capsense_end_of_scan_callback, &amp;cy_capsense_context);
    
    Cy_CapSense_Enable(&amp;cy_capsense_context);
}

/*******************************************************************************
* Function Name: capsense_end_of_scan_callback
********************************************************************************
* Summary:
*  CapSense end of scan callback function. This function sends a command to
*  CapSense task to process scan.
*
* Parameters:
*  cy_stc_active_scan_sns_t * active_scan_sns_ptr (unused)
*
*******************************************************************************/
static void capsense_end_of_scan_callback(cy_stc_active_scan_sns_t* active_scan_sns_ptr)
{
    BaseType_t xYieldRequired;

    (void)active_scan_sns_ptr;
    xYieldRequired = xSemaphoreGiveFromISR(capsense_done,&amp;xYieldRequired);

    portYIELD_FROM_ISR(xYieldRequired);
}

/*******************************************************************************
* Function Name: capsense_isr
********************************************************************************
* Summary:
*  Wrapper function for handling interrupts from CSD block.
*
*******************************************************************************/
static void capsense_isr(void)
{
    Cy_CapSense_InterruptHandler(CYBSP_CSD_HW, &amp;cy_capsense_context);
}

/*******************************************************************************
* Function Name: capsense_register_deepsleep
********************************************************************************
* Summary:
*  Wrapper function for setting up the Deep Sleep callback for CapSense.
*  This is necessary so that a transition from active to Deep Sleep does not
*  occur during a CapSense scan.
*
*  See the "MTB CAT1 Peripheral driver library documentation &gt; PDL API Reference &gt; SysPM"
*  link in the Quick Panel Documentation for information on setting up the SysPm callbacks
*******************************************************************************/
static void capsense_register_deepsleep(void)
{
    static cy_stc_syspm_callback_params_t callback_params =
    {
        .base       = CYBSP_CSD_HW,
        .context    = &amp;cy_capsense_context
    };

    static cy_stc_syspm_callback_t capsense_deep_sleep_cb =
    {
        Cy_CapSense_DeepSleepCallback,
        CY_SYSPM_DEEPSLEEP,
        0,
        &amp;callback_params,
        NULL,
        NULL
    };

    Cy_SysPm_RegisterCallback(&amp;capsense_deep_sleep_cb);
}
</pre>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/ew21-lesson-1-freertos-capsense/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>EW21: Lesson 2: Joystick</title>
		<link>https://iotexpert.com/ew21-lesson-2-joystick/</link>
					<comments>https://iotexpert.com/ew21-lesson-2-joystick/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Wed, 24 Feb 2021 15:26:13 +0000</pubDate>
				<category><![CDATA[Embedded World 2021]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=10781</guid>

					<description><![CDATA[Summary In lesson 2 we will add the Infineon XENSIV 3-D Magnetic Sensor with a Joystick to the project .  At the end of lesson two you will have the &#8220;JoyStick Task&#8221; colored green.  Here is the architecture: Learning Objectives In this lesson I will teach you about Libraries &#38; the Library Manager Multiple RTOS [&#8230;]]]></description>
										<content:encoded><![CDATA[<div>
<p><span><h1>Embedded World 2021 - Infineon ModusToolbox PSoC 6 Drone </h1>
<p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >#</th>
<th >Description</th>
</tr>
</thead>
<tbody>
<tr><td >0</td>
<td ><a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/" target="_blank" rel="noopener">Introduction &amp; Resources</a></td>
</tr>

<tr><td >1</td>
<td ><a href="https://iotexpert.com/ew21-lesson-1-freertos-capsense/" target="_blank" rel="noopener">FreeRTOS &amp; CapSense</a></td>
</tr>

<tr><td >2</td>
<td ><a href="https://iotexpert.com/ew21-lesson-2-joystick/" target="_blank" rel="noopener">3-D Magnetic Sensing XENSIV Joystick</a></td>
</tr>

<tr><td >3</td>
<td ><a href="https://iotexpert.com/ew21-lesson-3-wifi/" target="_blank" rel="noopener">WiFi</a></td>
</tr>

<tr><td >4</td>
<td ><a href="https://iotexpert.com/ew21-lesson-4-mqtt/" target="_blank" rel="noopener">MQTT</a></td>
</tr>

<tr><td >5</td>
<td ><a href="https://iotexpert.com/ew21-lesson-5-low-power/" target="_blank" rel="noopener">Low Power</a></td>
</tr>

<tr><td >6</td>
<td ><a href="https://iotexpert.com/ew21-lesson-6-motor-control/" target="_blank" rel="noopener">BLDC Motor Control</a></td>
</tr>

<tr><td >7</td>
<td ><a href="https://iotexpert.com/ew21-lesson-7-ws2812-led-strip/" target="_blank" rel="noopener">WS2812 Strip LEDs</a></td>
</tr>
</tbody></table></div></p>
<p>&nbsp;</p></span></p>
<h1>Summary</h1>
<p>In lesson 2 we will add the Infineon XENSIV 3-D Magnetic Sensor with a Joystick to the project .  At the end of lesson two you will have the &#8220;JoyStick Task&#8221; colored green.  Here is the architecture:</p>
<p><a href="https://iotexpert.com/ew21-lesson-2-joystick/l2-arch/" rel="attachment wp-att-10977"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/l2-arch-1024x433.png" alt="" width="1024" height="433" class="alignnone size-large wp-image-10977" srcset="https://iotexpert.com/wp-content/uploads/2021/02/l2-arch-1024x433.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/l2-arch-300x127.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/l2-arch-768x324.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/l2-arch-1536x649.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/l2-arch-600x253.png 600w, https://iotexpert.com/wp-content/uploads/2021/02/l2-arch.png 1631w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>Learning Objectives</h1>
<p>In this lesson I will teach you about</p>
<ol>
<li>Libraries &amp; the Library Manager</li>
<li>Multiple RTOS Tasks</li>
<li>XENSIV 3-D Magnetic JoyStick</li>
</ol>
<h1>Procedure</h1>
<p>I am going to follow these steps:</p>
<ol>
<li>Look at the Sensor GUI</li>
<li>Start a new project</li>
<li>Add the TLx493D library</li>
<li>Create the joystick_task public header</li>
<li>Create the joystick_task implementation file</li>
<li>Test</li>
</ol>
<h3>1.Look at the Sensor GUI</h3>
<p>Start the GUI and click the connect button.</p>
<p><a href="https://iotexpert.com/ew21-lesson-2-joystick/screen-shot-2021-02-23-at-7-10-53-am/" rel="attachment wp-att-10881"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-7.10.53-AM-1024x652.png" alt="" width="1024" height="652" class="alignnone size-large wp-image-10881" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-7.10.53-AM-1024x652.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-7.10.53-AM-300x191.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-7.10.53-AM-768x489.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-7.10.53-AM-600x382.png 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-7.10.53-AM.png 1234w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Press start and you will now see x,y,z values.</p>
<p><a href="https://iotexpert.com/ew21-lesson-2-joystick/screen-shot-2021-02-23-at-7-11-26-am/" rel="attachment wp-att-10882"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-7.11.26-AM-1024x812.png" alt="" width="1024" height="812" class="alignnone size-large wp-image-10882" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-7.11.26-AM-1024x812.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-7.11.26-AM-300x238.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-7.11.26-AM-768x609.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-7.11.26-AM-1536x1219.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-7.11.26-AM-600x476.png 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-7.11.26-AM.png 1578w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Click on the joystick view to see how it looks as a joystick.</p>
<p><a href="https://iotexpert.com/ew21-lesson-2-joystick/screen-shot-2021-02-23-at-7-11-41-am/" rel="attachment wp-att-10883"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-7.11.41-AM-1024x807.jpg" alt="" width="1024" height="807" class="alignnone size-large wp-image-10883" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-7.11.41-AM-1024x807.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-7.11.41-AM-300x236.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-7.11.41-AM-768x605.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-7.11.41-AM-1536x1210.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-7.11.41-AM-600x473.jpg 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-7.11.41-AM.jpg 1584w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h3>2. Start a new project</h3>
<p>Start the new project creator and pick out &#8220;CY8CPROTO-062-4343W&#8221;</p>
<p><a href="https://iotexpert.com/ew21-lesson-2-joystick/screen-shot-2021-02-23-at-6-06-28-am/" rel="attachment wp-att-10864"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.06.28-AM-1024x700.jpg" alt="" width="1024" height="700" class="alignnone size-large wp-image-10864" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.06.28-AM-1024x700.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.06.28-AM-300x205.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.06.28-AM-768x525.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.06.28-AM-1536x1050.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.06.28-AM-600x410.jpg 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.06.28-AM.jpg 2046w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>This time I will start from the previous project.  Press the &#8220;Import&#8221; button and select your old project to open.</p>
<p><a href="https://iotexpert.com/ew21-lesson-2-joystick/screen-shot-2021-02-23-at-6-07-16-am/" rel="attachment wp-att-10866"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.07.16-AM-1024x698.jpg" alt="" width="1024" height="698" class="alignnone size-large wp-image-10866" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.07.16-AM-1024x698.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.07.16-AM-300x204.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.07.16-AM-768x523.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.07.16-AM-1536x1047.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.07.16-AM-2048x1396.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.07.16-AM-600x409.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Give your project a new name (notice that we are starting from 1 as the template)</p>
<p><a href="https://iotexpert.com/ew21-lesson-2-joystick/screen-shot-2021-02-23-at-6-07-37-am/" rel="attachment wp-att-10867"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.07.37-AM-1024x164.png" alt="" width="1024" height="164" class="alignnone size-large wp-image-10867" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.07.37-AM-1024x164.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.07.37-AM-300x48.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.07.37-AM-768x123.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.07.37-AM-1536x246.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.07.37-AM-600x96.png 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.07.37-AM.png 2036w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
</div>
<p>Open up the command line and make vscode.</p>
<p><a href="https://iotexpert.com/ew21-lesson-2-joystick/screen-shot-2021-02-23-at-6-09-37-am/" rel="attachment wp-att-10868"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.09.37-AM-768x1024.jpg" alt="" width="768" height="1024" class="alignnone size-large wp-image-10868" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.09.37-AM-768x1024.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.09.37-AM-225x300.jpg 225w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.09.37-AM-1152x1536.jpg 1152w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.09.37-AM-600x800.jpg 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.09.37-AM.jpg 1520w" sizes="(max-width: 768px) 100vw, 768px" /></a></p>
<p>Do a command line build/program by running &#8220;make -j program&#8221;.</p>
<p><a href="https://iotexpert.com/ew21-lesson-2-joystick/screen-shot-2021-02-23-at-6-12-01-am/" rel="attachment wp-att-10869"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.12.01-AM-1024x944.jpg" alt="" width="1024" height="944" class="alignnone size-large wp-image-10869" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.12.01-AM-1024x944.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.12.01-AM-300x276.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.12.01-AM-768x708.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.12.01-AM-600x553.jpg 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.12.01-AM.jpg 1502w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>It will finish compiling and then program your board.</p>
<p><a href="https://iotexpert.com/ew21-lesson-2-joystick/screen-shot-2021-02-23-at-6-11-48-am/" rel="attachment wp-att-10870"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.11.48-AM-762x1024.jpg" alt="" width="762" height="1024" class="alignnone size-large wp-image-10870" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.11.48-AM-762x1024.jpg 762w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.11.48-AM-223x300.jpg 223w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.11.48-AM-768x1032.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.11.48-AM-1143x1536.jpg 1143w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.11.48-AM-600x806.jpg 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.11.48-AM.jpg 1508w" sizes="(max-width: 762px) 100vw, 762px" /></a></p>
<p>Now look at the serial terminal and make sure that the CapSense is still working</p>
<p><a href="https://iotexpert.com/ew21-lesson-2-joystick/screen-shot-2021-02-23-at-6-41-00-am/" rel="attachment wp-att-10879"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.41.00-AM-1024x366.png" alt="" width="1024" height="366" class="alignnone size-large wp-image-10879" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.41.00-AM-1024x366.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.41.00-AM-300x107.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.41.00-AM-768x274.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.41.00-AM-600x214.png 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.41.00-AM.png 1142w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<div>
<h3>3. Add the<span style="font-size: 16px;"> TLx493D library</span></h3>
<p>In order to interact with the TLx493D it would be much simpler if you had a library.  Well, I have just the solution for that.  Start the library browser and filter for IoT.  Notice that one of your choices is the TLx493D 3D Magnetic Sensor library.  Check the box, then press Update. Once the update finishes, press Close.</p>
<p><a href="https://iotexpert.com/ew21-lesson-2-joystick/screen-shot-2021-02-23-at-6-13-10-am/" rel="attachment wp-att-10871"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.13.10-AM-1024x790.jpg" alt="" width="1024" height="790" class="alignnone size-large wp-image-10871" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.13.10-AM-1024x790.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.13.10-AM-300x231.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.13.10-AM-768x592.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.13.10-AM-1536x1185.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.13.10-AM-2048x1580.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.13.10-AM-600x463.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>After running the update you will notice some new stuff.  First there is a file in your &#8220;deps&#8221; directory.  We will look at that in a second.  Also notice that there is a new directory in the mtb_shared directory.</p>
</div>
<p><a href="https://iotexpert.com/ew21-lesson-2-joystick/screen-shot-2021-02-23-at-6-24-46-am/" rel="attachment wp-att-10873"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.24.46-AM-929x1024.jpg" alt="" width="929" height="1024" class="alignnone size-large wp-image-10873" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.24.46-AM-929x1024.jpg 929w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.24.46-AM-272x300.jpg 272w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.24.46-AM-768x846.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.24.46-AM-1394x1536.jpg 1394w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.24.46-AM-600x661.jpg 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.24.46-AM.jpg 1488w" sizes="(max-width: 929px) 100vw, 929px" /></a></p>
<p>When you look at the dot-MTB file you will see that it is just a</p>
<ol>
<li>URL to GitHub</li>
<li>A branch name = &#8220;master&#8221;</li>
<li>A location to put it = mtb_shared/TLx493D_3Dmagnetic/master</li>
</ol>
<p>This is JUST A SIMPLE GIT REPOSITORY.</p>
<p><a href="https://iotexpert.com/ew21-lesson-2-joystick/screen-shot-2021-02-23-at-6-25-58-am/" rel="attachment wp-att-10874"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.25.58-AM-1024x252.png" alt="" width="1024" height="252" class="alignnone size-large wp-image-10874" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.25.58-AM-1024x252.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.25.58-AM-300x74.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.25.58-AM-768x189.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.25.58-AM-1536x378.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.25.58-AM-2048x504.png 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.25.58-AM-600x148.png 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>When you open vscode and look in the repository you will see normal c-code.</p>
<p><a href="https://iotexpert.com/ew21-lesson-2-joystick/screen-shot-2021-02-23-at-6-27-02-am/" rel="attachment wp-att-10875"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.27.02-AM-1024x768.jpg" alt="" width="1024" height="768" class="alignnone size-large wp-image-10875" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.27.02-AM-1024x768.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.27.02-AM-300x225.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.27.02-AM-768x576.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.27.02-AM-1536x1152.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.27.02-AM-2048x1536.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.27.02-AM-600x450.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<div>
<h3>4. Create the Joystick_task public header</h3>
<p>We want to have a task called &#8220;joystick_task&#8221;.  So create the public header file for that task.</p>
<p><a href="https://iotexpert.com/ew21-lesson-2-joystick/screen-shot-2021-02-23-at-6-31-42-am/" rel="attachment wp-att-10877"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.31.42-AM.png" alt="" width="850" height="710" class="alignnone size-full wp-image-10877" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.31.42-AM.png 850w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.31.42-AM-300x251.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.31.42-AM-768x642.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.31.42-AM-600x501.png 600w" sizes="(max-width: 850px) 100vw, 850px" /></a></p>
</div>
<p>Then add the long and extensive code.  Just a function prototype for the joystick task.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">#pragma once

void joystick_task(void *param);
</pre>
<div>
<h3>5. Create the joystick_task implementation file</h3>
</div>
<p>Now the actual code for the joystick is straight forward</p>
<ol>
<li>Some includes</li>
<li>The task definition</li>
<li>Initialize the interface to the joystick with TLxI2CInit</li>
<li>Initialize the library with TLx493xInit</li>
<li>Loop repeatedly</li>
<li>Read one frame from the joystick sensor</li>
<li>Convert the frame to x-y coordinates</li>
<li>If there is a new position print it.</li>
<li>Save the old data</li>
<li>Wait a bit</li>
<li>Loop back to the start</li>
</ol>
<pre class="EnlighterJSRAW" data-enlighter-language="c">#include "cybsp.h"
#include "FreeRTOS.h"
#include "task.h"
#include &lt;stdio.h&gt;

#include "joystick_task.h"

#include "PSoC_TLx_interface.h"
#include "TLxJoystick.h"

#define JOYSTICK_INTERVAL_MS    (100)   /* in milliseconds*/
#define JOYSTICK_HYSTERESIS		(1)

/*******************************************************************************
* Function Name: task_joystick
********************************************************************************
* Summary:
*  Task that initializes the Joystick block and processes the input.
*
* Parameters:
*  void *param : Task parameter defined during task creation (unused)
*
*******************************************************************************/
void joystick_task(void* param)
{
    (void)param;

    cy_rslt_t result;

    TLx493D_data_frame_t frame;
    TLxJoyStickXY_t joystick_curr;
    TLxJoyStickXY_t joystick_prev;

    /* Initialize I2C interface to talk to the TLx493D sensor */
    TLxI2CInit(CYBSP_I2C_SDA,
                        CYBSP_I2C_SCL,
                        0 /* Use Default Sensor Address */,
                        0 /* Use Default Speed */,
                        NULL /* Use Auto-assigned clock */);


    /* Configure the TLx493D sensor */
    result = TLx493D_init();
    if (result != CY_RSLT_SUCCESS)
    {
    	printf("Joystick not detected. Exiting Joystick task.\n");
    	vTaskDelete(NULL);
    }
    
    /* Set Sensor to Master Control Mode */
    TLx493D_set_operation_mode(TLx493D_OP_MODE_MCM);

    /* Repeatedly running part of the task */
    for(;;)
    {
        TLx493D_read_frame(&amp;frame);

        TLxJoystickCovertXY(&amp;frame,&amp;joystick_curr);

        /* Only update/print new value if it has changed by more than the hysteresis value */
        if((joystick_curr.x &gt; (joystick_prev.x + JOYSTICK_HYSTERESIS)) || (joystick_curr.x &lt; (joystick_prev.x - JOYSTICK_HYSTERESIS)))
        {
            printf("Joystick Position: %d\n", joystick_curr.x);

            joystick_prev.x = joystick_curr.x;
            joystick_prev.y = joystick_curr.y;
        }
        vTaskDelay(JOYSTICK_INTERVAL_MS);
    }
}
</pre>
<div>
<h3>6. Edit main.c</h3>
<p>In main.c you need to include the joystick_task.h and then start the task</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">#include "cyhal.h"
#include "cybsp.h"
#include "cy_retarget_io.h"
#include &lt;stdio.h&gt;
#include "FreeRTOS.h"
#include "task.h"
#include "capsense_task.h"
#include "joystick_task.h"

volatile int uxTopUsedPriority ;

void blink_task(void *arg)
{
    cyhal_gpio_init(CYBSP_USER_LED,CYHAL_GPIO_DIR_OUTPUT,CYHAL_GPIO_DRIVE_STRONG,0);

    for(;;)
    {
    	cyhal_gpio_toggle(CYBSP_USER_LED);
    	vTaskDelay(500);
    }
}


int main(void)
{
    uxTopUsedPriority = configMAX_PRIORITIES - 1 ; // enable OpenOCD Thread Debugging

    /* Initialize the device and board peripherals */
    cybsp_init() ;
    __enable_irq();

    cy_retarget_io_init(CYBSP_DEBUG_UART_TX, CYBSP_DEBUG_UART_RX, CY_RETARGET_IO_BAUDRATE);

    // Stack size in WORDs
    // Idle task = priority 0
    xTaskCreate(blink_task,    "blink"     ,configMINIMAL_STACK_SIZE*1  ,0 /* args */ ,0 /* priority */, 0 /* handle */);
    xTaskCreate(capsense_task, "CapSense"  ,configMINIMAL_STACK_SIZE*4  , NULL, 1, 0);
    xTaskCreate(joystick_task, "Joystick"  ,configMINIMAL_STACK_SIZE*4  , NULL, 1, 0);

    vTaskStartScheduler();
}</pre>
<h3>7. Test</h3>
<p>When you test, you will see that the joystick moves around and prints new values.  Plus the CapSense still works.</p>
<p><a href="https://iotexpert.com/ew21-lesson-2-joystick/screen-shot-2021-02-23-at-6-36-50-am/" rel="attachment wp-att-10878"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.36.50-AM.png" alt="" width="972" height="816" class="alignnone size-full wp-image-10878" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.36.50-AM.png 972w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.36.50-AM-300x252.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.36.50-AM-768x645.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.36.50-AM-600x504.png 600w" sizes="(max-width: 972px) 100vw, 972px" /></a></p>
<h1>Resources for Project</h1>
<p>You can find this completed project in your project creator dialog by filtering for &#8220;IoT Expert Embedded&#8221;.  This is lesson2</p>
<p><a href="https://iotexpert.com/?attachment_id=10819" rel="attachment wp-att-10819"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.33.24-PM-1024x585.png" alt="" width="1024" height="585" class="alignnone size-large wp-image-10819" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.33.24-PM-1024x585.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.33.24-PM-300x171.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.33.24-PM-768x439.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.33.24-PM-1536x878.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.33.24-PM-2048x1171.png 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.33.24-PM-600x343.png 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>You can also clone this project at git@github.com:iotexpert/ew21-lesson2.git or https://github.com/iotexpert/ew21-lesson2</p>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/ew21-lesson-2-joystick/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>EW21: Lesson 3: WiFi</title>
		<link>https://iotexpert.com/ew21-lesson-3-wifi/</link>
					<comments>https://iotexpert.com/ew21-lesson-3-wifi/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Wed, 24 Feb 2021 15:25:45 +0000</pubDate>
				<category><![CDATA[Embedded World 2021]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=10782</guid>

					<description><![CDATA[Summary In lesson 3 we will add a task to manage the &#8220;Cloud&#8221;, this is IoT after all.  We will start by adding the connection to the WiFi network using the AnyCloud Wireless Connection Manager within ModusToolbox.  At the end of lesson three you will have the &#8220;Cloud Task&#8221; colored green &#8211; well actually partially [&#8230;]]]></description>
										<content:encoded><![CDATA[<div>
<p><span><h1>Embedded World 2021 - Infineon ModusToolbox PSoC 6 Drone </h1>
<p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >#</th>
<th >Description</th>
</tr>
</thead>
<tbody>
<tr><td >0</td>
<td ><a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/" target="_blank" rel="noopener">Introduction &amp; Resources</a></td>
</tr>

<tr><td >1</td>
<td ><a href="https://iotexpert.com/ew21-lesson-1-freertos-capsense/" target="_blank" rel="noopener">FreeRTOS &amp; CapSense</a></td>
</tr>

<tr><td >2</td>
<td ><a href="https://iotexpert.com/ew21-lesson-2-joystick/" target="_blank" rel="noopener">3-D Magnetic Sensing XENSIV Joystick</a></td>
</tr>

<tr><td >3</td>
<td ><a href="https://iotexpert.com/ew21-lesson-3-wifi/" target="_blank" rel="noopener">WiFi</a></td>
</tr>

<tr><td >4</td>
<td ><a href="https://iotexpert.com/ew21-lesson-4-mqtt/" target="_blank" rel="noopener">MQTT</a></td>
</tr>

<tr><td >5</td>
<td ><a href="https://iotexpert.com/ew21-lesson-5-low-power/" target="_blank" rel="noopener">Low Power</a></td>
</tr>

<tr><td >6</td>
<td ><a href="https://iotexpert.com/ew21-lesson-6-motor-control/" target="_blank" rel="noopener">BLDC Motor Control</a></td>
</tr>

<tr><td >7</td>
<td ><a href="https://iotexpert.com/ew21-lesson-7-ws2812-led-strip/" target="_blank" rel="noopener">WS2812 Strip LEDs</a></td>
</tr>
</tbody></table></div></p>
<p>&nbsp;</p></span></p>
<h1>Summary</h1>
<p>In lesson 3 we will add a task to manage the &#8220;Cloud&#8221;, this is IoT after all.  We will start by adding the connection to the WiFi network using the AnyCloud Wireless Connection Manager within ModusToolbox.  At the end of lesson three you will have the &#8220;Cloud Task&#8221; colored green &#8211; well actually partially green.  Here is the architecture:</p>
<p><a href="https://iotexpert.com/ew21-lesson-3-wifi/l3-arch-2/" rel="attachment wp-att-10979"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/l3-arch-1-1024x433.png" alt="" width="1024" height="433" class="alignnone size-large wp-image-10979" srcset="https://iotexpert.com/wp-content/uploads/2021/02/l3-arch-1-1024x433.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/l3-arch-1-300x127.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/l3-arch-1-768x324.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/l3-arch-1-1536x649.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/l3-arch-1-600x253.png 600w, https://iotexpert.com/wp-content/uploads/2021/02/l3-arch-1.png 1631w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>Learning Objectives</h1>
<ol>
<li>AnyCloud Wireless Libraries</li>
<li>Architecture of the PSoC 6 + 43xxxx WiFi Combo</li>
<li>Wireless Connection Manager</li>
</ol>
<h1>Procedure</h1>
<p>In this lesson we will follow these steps:</p>
<ol>
<li>Create a new project by copying lesson 2</li>
<li>Add the WiFi Libraries</li>
<li>Copy the wireless configuration templates files into your project</li>
<li>Look at the Wireless Library Documentation</li>
<li>Update the Makefile</li>
<li>Add cloud_task.h</li>
<li>Add cloud_task.c</li>
<li>Update main.c</li>
<li>Test</li>
</ol>
<h3>1. Create a new project by copying lesson 2</h3>
<p>Start the new project creator and select the CY8CPROTO-062-4343W</p>
<p><a href="https://iotexpert.com/ew21-lesson-3-wifi/screen-shot-2021-02-23-at-8-58-21-am/" rel="attachment wp-att-10885"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-8.58.21-AM-1024x706.jpg" alt="" width="1024" height="706" class="alignnone size-large wp-image-10885" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-8.58.21-AM-1024x706.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-8.58.21-AM-300x207.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-8.58.21-AM-768x530.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-8.58.21-AM-1536x1059.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-8.58.21-AM-2048x1413.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-8.58.21-AM-600x414.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Click the import button.  Then select your previous project and press open.</p>
<p><a href="https://iotexpert.com/ew21-lesson-3-wifi/screen-shot-2021-02-23-at-8-58-49-am/" rel="attachment wp-att-10886"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-8.58.49-AM-1024x699.png" alt="" width="1024" height="699" class="alignnone size-large wp-image-10886" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-8.58.49-AM-1024x699.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-8.58.49-AM-300x205.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-8.58.49-AM-768x525.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-8.58.49-AM-600x410.png 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-8.58.49-AM.png 1306w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Select your new template and give it a reasonable name.</p>
<p><a href="https://iotexpert.com/ew21-lesson-3-wifi/screen-shot-2021-02-23-at-8-59-04-am/" rel="attachment wp-att-10887"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-8.59.04-AM-1024x143.png" alt="" width="1024" height="143" class="alignnone size-large wp-image-10887" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-8.59.04-AM-1024x143.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-8.59.04-AM-300x42.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-8.59.04-AM-768x107.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-8.59.04-AM-1536x214.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-8.59.04-AM-2048x286.png 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-8.59.04-AM-600x84.png 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Now program your project to make sure that things are still working.</p>
<p><a href="https://iotexpert.com/ew21-lesson-3-wifi/screen-shot-2021-02-23-at-9-03-00-am/" rel="attachment wp-att-10889"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.03.00-AM-1024x687.jpg" alt="" width="1024" height="687" class="alignnone size-large wp-image-10889" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.03.00-AM-1024x687.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.03.00-AM-300x201.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.03.00-AM-768x515.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.03.00-AM-600x403.jpg 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.03.00-AM.jpg 1434w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
</div>
<p>Here is the serial terminal.</p>
<p><a href="https://iotexpert.com/ew21-lesson-3-wifi/screen-shot-2021-02-23-at-9-03-21-am/" rel="attachment wp-att-10890"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.03.21-AM-1024x469.png" alt="" width="1024" height="469" class="alignnone size-large wp-image-10890" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.03.21-AM-1024x469.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.03.21-AM-300x137.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.03.21-AM-768x352.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.03.21-AM-1536x703.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.03.21-AM-600x275.png 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.03.21-AM.png 1560w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<div>
<h3>2. Add the WiFi Libraries</h3>
<p>Start up the library manager and go to the Libraries tab.  Click on wireless connection manager.  Notice that it will bring in a bunch of other libraries that it depends on.</p>
<p><a href="https://iotexpert.com/ew21-lesson-3-wifi/screen-shot-2021-02-23-at-9-05-31-am/" rel="attachment wp-att-10891"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.05.31-AM-943x1024.jpg" alt="" width="943" height="1024" class="alignnone size-large wp-image-10891" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.05.31-AM-943x1024.jpg 943w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.05.31-AM-276x300.jpg 276w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.05.31-AM-768x834.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.05.31-AM-600x651.jpg 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.05.31-AM.jpg 1144w" sizes="(max-width: 943px) 100vw, 943px" /></a></p>
<h3>3. Copy the wireless configuration templates into your project</h3>
<p>MBED TLS and LWIP have about a billion options.  We provide a template for those options which you will need to copy into your project.  The templates are located in the wifi-mw-core library in the &#8220;config&#8221; directory.  Copy and paste them into your project.</p>
<p><a href="https://iotexpert.com/ew21-lesson-3-wifi/screen-shot-2021-02-23-at-9-11-26-am/" rel="attachment wp-att-10892"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.11.26-AM-340x1024.jpg" alt="" width="340" height="1024" class="alignnone size-large wp-image-10892" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.11.26-AM-340x1024.jpg 340w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.11.26-AM-100x300.jpg 100w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.11.26-AM-768x2315.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.11.26-AM-510x1536.jpg 510w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.11.26-AM-600x1809.jpg 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.11.26-AM.jpg 826w" sizes="(max-width: 340px) 100vw, 340px" /></a></p>
</div>
<p>Here is a clip of the lwip configuration options.  I wouldn&#8217;t recommend changing anything unless you are sure you know what you are doing.</p>
<p><a href="https://iotexpert.com/ew21-lesson-3-wifi/screen-shot-2021-02-23-at-9-12-37-am/" rel="attachment wp-att-10893"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.12.37-AM-819x1024.jpg" alt="" width="819" height="1024" class="alignnone size-large wp-image-10893" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.12.37-AM-819x1024.jpg 819w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.12.37-AM-240x300.jpg 240w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.12.37-AM-768x960.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.12.37-AM-1228x1536.jpg 1228w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.12.37-AM-600x750.jpg 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.12.37-AM.jpg 1350w" sizes="(max-width: 819px) 100vw, 819px" /></a></p>
<div>
<h3>4. Look at the Wireless Library Documentation</h3>
<p>All of the Infineon libraries will have a directory called &#8220;doc&#8221; and inside of that directory there will be a file called api_reference_manual.html</p>
<p><a href="https://iotexpert.com/ew21-lesson-3-wifi/screen-shot-2021-02-23-at-9-41-17-am/" rel="attachment wp-att-10900"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.41.17-AM.png" alt="" width="700" height="810" class="alignnone size-full wp-image-10900" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.41.17-AM.png 700w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.41.17-AM-259x300.png 259w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.41.17-AM-600x694.png 600w" sizes="(max-width: 700px) 100vw, 700px" /></a></p>
<p>When you open the file you will  see our doxygen generated documentation.  Here the WiFi connection manager documentation.</p>
<p><a href="https://iotexpert.com/ew21-lesson-3-wifi/screen-shot-2021-02-23-at-9-41-42-am/" rel="attachment wp-att-10901"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.41.42-AM-1024x659.jpg" alt="" width="1024" height="659" class="alignnone size-large wp-image-10901" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.41.42-AM-1024x659.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.41.42-AM-300x193.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.41.42-AM-768x494.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.41.42-AM-1536x988.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.41.42-AM-2048x1318.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.41.42-AM-600x386.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h3>5. Update the Makefile</h3>
</div>
<p>The makefile controls all of the libraries.  To enable these libraries you need to add the following &#8220;components&#8221; to the list if they aren&#8217;t already there. (Note that all of this information is in the Quick Start section of the library&#8217;s documentation).</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">COMPONENTS= FREERTOS LWIP MBEDTLS</pre>
<p>And you need to tell the system about the configuration.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">DEFINES+= MBEDTLS_USER_CONFIG_FILE='"mbedtls_user_config.h"' 
DEFINES+=CYBSP_WIFI_CAPABLE
DEFINES+=CY_RTOS_AWARE</pre>
<div>
<h3>6. Add the cloud_task.h</h3>
</div>
<p>Just like the other lessons you will need to create a public header file for the cloud task.</p>
<p><a href="https://iotexpert.com/ew21-lesson-3-wifi/screen-shot-2021-02-23-at-9-14-48-am/" rel="attachment wp-att-10895"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.14.48-AM.png" alt="" width="778" height="504" class="alignnone size-full wp-image-10895" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.14.48-AM.png 778w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.14.48-AM-300x194.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.14.48-AM-768x498.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.14.48-AM-600x389.png 600w" sizes="(max-width: 778px) 100vw, 778px" /></a></p>
<p>Inside of that file there will be only one function prototype for the task.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">#pragma once

void cloud_task(void *param);</pre>
<div>
<h3>7. Add the cloud_task.c</h3>
<p>Make the cloud_task.c file to add the cloud infrastructure to your project.</p>
</div>
<p><a href="https://iotexpert.com/ew21-lesson-3-wifi/screen-shot-2021-02-23-at-9-15-42-am/" rel="attachment wp-att-10896"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.15.42-AM.png" alt="" width="760" height="532" class="alignnone size-full wp-image-10896" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.15.42-AM.png 760w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.15.42-AM-300x210.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.15.42-AM-600x420.png 600w" sizes="(max-width: 760px) 100vw, 760px" /></a></p>
<p>At the top of the file we will have some includes.  And I will define some macros that tell WiFi which AP to attach to. When you do this on your own, you will need to update those to match your WiFi AP SSID and password. The task itself is really simple for now, just connect to WiFi and then do nothing.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">#include &lt;stdio.h&gt;

#include "FreeRTOS.h"
#include "task.h"

#include "cy_wcm.h"

#include "cloud_task.h"

#define CLOUD_WIFI_AP        "ew2021"
#define CLOUD_WIFI_PW        "ew2021ap"
#define CLOUD_WIFI_SECURITY  CY_WCM_SECURITY_WPA2_MIXED_PSK
#define CLOUD_WIFI_BAND      CY_WCM_WIFI_BAND_ANY

static void cloud_connectWifi();

void cloud_task(void* param)
{
    (void)param;

    cloud_connectWifi();

    while(1)
    {
        vTaskDelay(1);

    }
}</pre>
<p>The connect to WiFi function will</p>
<ol>
<li>Setup the Access Point information</li>
<li>Initialize the wireless connection manager</li>
<li>Then go into a loop that will attempt to connect until there is success.</li>
<li>Once a connection is made, it will print out the IP information.</li>
</ol>
<pre class="EnlighterJSRAW" data-enlighter-language="c">static void cloud_connectWifi()
{
    cy_rslt_t result;

    cy_wcm_connect_params_t connect_param = {
        .ap_credentials.SSID = CLOUD_WIFI_AP,
        .ap_credentials.password = CLOUD_WIFI_PW,
        .ap_credentials.security = CLOUD_WIFI_SECURITY,
        .BSSID = {0},
        .band = CLOUD_WIFI_BAND,
    };
    cy_wcm_config_t config = {.interface = CY_WCM_INTERFACE_TYPE_STA}; // We are a station (not a Access Point)

    cy_wcm_init(&amp;config); // Initialize the connection manager

    printf("\nWi-Fi Connection Manager initialized.\n");

    do
    {
        cy_wcm_ip_address_t ip_address;

        printf("Connecting to Wi-Fi AP '%s'\n", connect_param.ap_credentials.SSID);
        result = cy_wcm_connect_ap(&amp;connect_param, &amp;ip_address);

        if (result == CY_RSLT_SUCCESS)
        {
            printf("Successfully connected to Wi-Fi network '%s'.\n",
                    connect_param.ap_credentials.SSID);

            // Print IP Address
            if (ip_address.version == CY_WCM_IP_VER_V4)
            {
                printf("IPv4 Address Assigned: %d.%d.%d.%d\n", (uint8_t)ip_address.ip.v4,
                        (uint8_t)(ip_address.ip.v4 &gt;&gt; 8), (uint8_t)(ip_address.ip.v4 &gt;&gt; 16),
                        (uint8_t)(ip_address.ip.v4 &gt;&gt; 24));
            }
            else if (ip_address.version == CY_WCM_IP_VER_V6)
            {
                printf("IPv6 Address Assigned: %0X:%0X:%0X:%0X\n", (unsigned int)ip_address.ip.v6[0],
                        (unsigned int)ip_address.ip.v6[1], (unsigned int)ip_address.ip.v6[2],
                        (unsigned int)ip_address.ip.v6[3]);
            }
            break; /* Exit the for loop once the connection has been made */
        }
        else
        {
            printf("WiFi Connect Failed Retrying\n");
            vTaskDelay(2000); // wait 2 seconds and try again;
        }

    } while (result != CY_RSLT_SUCCESS);
}
</pre>
<div>
<h3>8. Update main.c</h3>
</div>
<p>In main.c you need to include the cloud task</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">#include "cloud_task.h"</pre>
<p>Then start the cloud task.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">xTaskCreate(cloud_task,    "Cloud"     ,configMINIMAL_STACK_SIZE*8  , NULL, 2, 0);  
</pre>
<div>
<h3>9. Test</h3>
<p>Program your project and make sure that it connects, and the CapSense and joystick still work.</p>
<p><a href="https://iotexpert.com/ew21-lesson-3-wifi/screen-shot-2021-02-23-at-9-23-40-am/" rel="attachment wp-att-10897"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.23.40-AM-1024x267.png" alt="" width="1024" height="267" class="alignnone size-large wp-image-10897" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.23.40-AM-1024x267.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.23.40-AM-300x78.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.23.40-AM-768x200.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.23.40-AM-1536x401.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.23.40-AM-600x156.png 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-9.23.40-AM.png 1710w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>Resources for Project</h1>
<p>You can find this projects in your project creator dialog by filtering for &#8220;IoT Expert Embedded&#8221;.  This is lesson3</p>
<p><a href="https://iotexpert.com/ew21-lesson-1-freertos-capsense/screen-shot-2021-02-22-at-4-33-41-pm/" rel="attachment wp-att-10818"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.33.41-PM-1024x583.png" alt="" width="1024" height="583" class="alignnone size-large wp-image-10818" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.33.41-PM-1024x583.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.33.41-PM-300x171.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.33.41-PM-768x437.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.33.41-PM-1536x874.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.33.41-PM-2048x1165.png 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.33.41-PM-600x341.png 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>You can also clone this project at git@github.com:iotexpert/ew21-lesson3.git or https://github.com/iotexpert/ew21-lesson3</p>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/ew21-lesson-3-wifi/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>EW21: Lesson 4: MQTT</title>
		<link>https://iotexpert.com/ew21-lesson-4-mqtt/</link>
					<comments>https://iotexpert.com/ew21-lesson-4-mqtt/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Wed, 24 Feb 2021 15:23:52 +0000</pubDate>
				<category><![CDATA[Embedded World 2021]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=10783</guid>

					<description><![CDATA[Summary In lesson 4 we will finish the cloud task by adding a connection to the MQTT broker.  Then I will make a very minor update to the CapSense and Joystick tasks to send their data to the Cloud.  At the end of this lesson you will have the Cloud truly colored green.  Here is [&#8230;]]]></description>
										<content:encoded><![CDATA[<div>
<p><span><h1>Embedded World 2021 - Infineon ModusToolbox PSoC 6 Drone </h1>
<p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >#</th>
<th >Description</th>
</tr>
</thead>
<tbody>
<tr><td >0</td>
<td ><a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/" target="_blank" rel="noopener">Introduction &amp; Resources</a></td>
</tr>

<tr><td >1</td>
<td ><a href="https://iotexpert.com/ew21-lesson-1-freertos-capsense/" target="_blank" rel="noopener">FreeRTOS &amp; CapSense</a></td>
</tr>

<tr><td >2</td>
<td ><a href="https://iotexpert.com/ew21-lesson-2-joystick/" target="_blank" rel="noopener">3-D Magnetic Sensing XENSIV Joystick</a></td>
</tr>

<tr><td >3</td>
<td ><a href="https://iotexpert.com/ew21-lesson-3-wifi/" target="_blank" rel="noopener">WiFi</a></td>
</tr>

<tr><td >4</td>
<td ><a href="https://iotexpert.com/ew21-lesson-4-mqtt/" target="_blank" rel="noopener">MQTT</a></td>
</tr>

<tr><td >5</td>
<td ><a href="https://iotexpert.com/ew21-lesson-5-low-power/" target="_blank" rel="noopener">Low Power</a></td>
</tr>

<tr><td >6</td>
<td ><a href="https://iotexpert.com/ew21-lesson-6-motor-control/" target="_blank" rel="noopener">BLDC Motor Control</a></td>
</tr>

<tr><td >7</td>
<td ><a href="https://iotexpert.com/ew21-lesson-7-ws2812-led-strip/" target="_blank" rel="noopener">WS2812 Strip LEDs</a></td>
</tr>
</tbody></table></div></p>
<p>&nbsp;</p></span></p>
<h1>Summary</h1>
<p>In lesson 4 we will finish the cloud task by adding a connection to the MQTT broker.  Then I will make a very minor update to the CapSense and Joystick tasks to send their data to the Cloud.  At the end of this lesson you will have the Cloud truly colored green.  Here is the architecture:</p>
<p><a href="https://iotexpert.com/ew21-lesson-4-mqtt/l4-arch/" rel="attachment wp-att-10981"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/l4-arch-1024x433.png" alt="" width="1024" height="433" class="alignnone size-large wp-image-10981" srcset="https://iotexpert.com/wp-content/uploads/2021/02/l4-arch-1024x433.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/l4-arch-300x127.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/l4-arch-768x324.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/l4-arch-1536x649.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/l4-arch-600x253.png 600w, https://iotexpert.com/wp-content/uploads/2021/02/l4-arch.png 1631w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>Learning Objectives</h1>
<ol>
<li>MQTT</li>
<li>AnyCloud use of AWS libraries</li>
</ol>
<h1>Procedure</h1>
<ol>
<li>Create a new project by copying lesson 3</li>
<li>Add the MQTT Library</li>
<li>Copy the core MQTT configuration</li>
<li>Update the Makefile</li>
<li>Update the cloud_task.h</li>
<li>Update the cloud_task.c</li>
<li>Update joystick_task.c</li>
<li>Update capsense_task.c</li>
<li>Test (using an MQTT Client)</li>
<li>Test (using our C++/Qt GUI)</li>
</ol>
<h3>1. Create a new project by copying lesson 3</h3>
<p>Start the new project creator.  Pick the CY8CPROTO-062-4343W and press next.</p>
<p><a href="https://iotexpert.com/ew21-lesson-4-mqtt/screen-shot-2021-02-23-at-10-07-52-am/" rel="attachment wp-att-10904"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.07.52-AM-1024x966.png" alt="" width="1024" height="966" class="alignnone size-large wp-image-10904" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.07.52-AM-1024x966.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.07.52-AM-300x283.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.07.52-AM-768x724.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.07.52-AM-600x566.png 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.07.52-AM.png 1194w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Click on the import button</p>
<p><a href="https://iotexpert.com/ew21-lesson-4-mqtt/screen-shot-2021-02-23-at-10-08-06-am/" rel="attachment wp-att-10905"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.08.06-AM-1024x225.png" alt="" width="1024" height="225" class="alignnone size-large wp-image-10905" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.08.06-AM-1024x225.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.08.06-AM-300x66.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.08.06-AM-768x169.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.08.06-AM-600x132.png 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.08.06-AM.png 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>And select project three to start from.</p>
<p><a href="https://iotexpert.com/ew21-lesson-4-mqtt/screen-shot-2021-02-23-at-10-08-21-am/" rel="attachment wp-att-10906"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.08.21-AM-1024x700.png" alt="" width="1024" height="700" class="alignnone size-large wp-image-10906" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.08.21-AM-1024x700.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.08.21-AM-300x205.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.08.21-AM-768x525.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.08.21-AM-600x410.png 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.08.21-AM.png 1320w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Give it a sensible name</p>
<p><a href="https://iotexpert.com/ew21-lesson-4-mqtt/screen-shot-2021-02-23-at-10-08-38-am/" rel="attachment wp-att-10907"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.08.38-AM-1024x707.jpg" alt="" width="1024" height="707" class="alignnone size-large wp-image-10907" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.08.38-AM-1024x707.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.08.38-AM-300x207.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.08.38-AM-768x530.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.08.38-AM-1536x1060.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.08.38-AM-2048x1413.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.08.38-AM-600x414.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h3>2. Add the MQTT Library</h3>
<p>Start the library browser and pick out the MQTT library.  Notice that it brings in a bunch of other libraries including the AWS libraries.</p>
<p><a href="https://iotexpert.com/ew21-lesson-4-mqtt/screen-shot-2021-02-23-at-10-11-17-am/" rel="attachment wp-att-10908"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.11.17-AM-1024x795.jpg" alt="" width="1024" height="795" class="alignnone size-large wp-image-10908" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.11.17-AM-1024x795.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.11.17-AM-300x233.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.11.17-AM-768x596.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.11.17-AM-1536x1192.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.11.17-AM-2048x1589.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.11.17-AM-600x466.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h3>3. Copy the core MQTT configuration</h3>
</div>
<p>When you look at the README for the MQTT it tells you to copy the file core_mqtt_config.h into your project.  Do so.</p>
<p><a href="https://iotexpert.com/ew21-lesson-4-mqtt/screen-shot-2021-02-23-at-10-29-54-am/" rel="attachment wp-att-10910"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.29.54-AM-1024x991.jpg" alt="" width="1024" height="991" class="alignnone size-large wp-image-10910" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.29.54-AM-1024x991.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.29.54-AM-300x290.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.29.54-AM-768x743.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.29.54-AM-1536x1486.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.29.54-AM-2048x1981.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.29.54-AM-600x580.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<div>
<h3>4. Update the Makefile</h3>
</div>
<p>For this to work you need to make two changes to your Makefile.  First enable the secure sockets.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">COMPONENTS= FREERTOS LWIP MBEDTLS SECURE_SOCKETS</pre>
<p>Then ignore a few files from the AWS library.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">CY_IGNORE+=$(SEARCH_aws-iot-device-sdk-embedded-C)/libraries/standard/coreHTTP
CY_IGNORE+=libs/aws-iot-device-sdk-embedded-C/libraries/standard/coreHTTP
</pre>
<h3>5. Update the cloud_task.h</h3>
<div>
<p>In order for other tasks to send a message I will create a function where they can send a &#8220;speed&#8221; also known as a percent 0-100.  This function will be called from both the CapSense task as well as the JoyStick task.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">void cloud_sendMotorSpeed(int speed);
</pre>
<h3>6. Update the cloud_task.c</h3>
</div>
<p>In the previous lesson we created the cloud task which connects to the WiFI network.  In this lesson we add MQTT.  Start by adding the includes for the MQTT and the RTOS queue.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">#include "cy_mqtt_api.h"
#include "queue.h"</pre>
<p>Rather than have magic numbers (or values) hidden in my code I provide #defines for:</p>
<ol>
<li>The MQTT broker</li>
<li>My Client ID</li>
<li>The Topic to broadcast to</li>
<li>The JSON key for the motor speed</li>
</ol>
<p>For other tasks to talk to this task they will push a value of the speed into a queue.  So I need to define that queue.  I will also use a static local variable to hold the handle of the MQTT connection.</p>
<p>I then define functions to</p>
<ol>
<li>Connect to MQTT</li>
<li>Start MQTT</li>
<li>Publish to MQTT</li>
</ol>
<pre class="EnlighterJSRAW" data-enlighter-language="c">#define CLOUD_MQTT_BROKER        "mqtt.eclipseprojects.io"


#define CLOUD_MQTT_CLIENT_PREFIX "remote"
#define CLOUD_MQTT_TOPIC         "motor_speed"

#define MOTOR_KEY                "motor"

static QueueHandle_t motor_value_q;
static cy_mqtt_t mqtthandle;

static void cloud_connectWifi();
static void cloud_startMQTT();
static void cloud_mqtt_event_cb( cy_mqtt_t mqtt_handle, cy_mqtt_event_t event, void *user_data);

static void cloud_publishMessage(char *topic,char *message);</pre>
<p>The updates to the cloud task are:</p>
<ol>
<li>Start WiFi</li>
<li>Start MQTT</li>
<li>Start the queue</li>
<li>In the main loop, wait for a message, then publish it.</li>
</ol>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">void cloud_task(void* param)
{
    (void)param;

    cloud_connectWifi();
    cloud_startMQTT();

    motor_value_q = xQueueCreate(1,sizeof(uint32_t));

    for(;;)
    {
        int motorSpeed;
        char message[32];

    	xQueueReceive(motor_value_q, &amp;motorSpeed, portMAX_DELAY);
        snprintf(message, sizeof(message)-1, "{\"%s\":%d}",MOTOR_KEY,motorSpeed);
        cloud_publishMessage(CLOUD_MQTT_TOPIC,message);
    }
}
</pre>
<p>This function is used in other tasks to send the motor speed into the queue.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">void cloud_sendMotorSpeed(int speed)
{
    if(motor_value_q)
        xQueueOverwrite(motor_value_q,&amp;speed);
}
</pre>
<p>To start MQTT you need to</p>
<ol>
<li>Define the MQTT broker structure</li>
<li>Create the MQTT system</li>
<li>Define your connection information</li>
<li>Create a random clientID (so there are no duplicated clients on the MQTT broker)</li>
<li>Make the connection</li>
</ol>
<pre class="EnlighterJSRAW" data-enlighter-language="c">static void cloud_startMQTT()
{
    static cy_mqtt_connect_info_t    	connect_info;
    static cy_mqtt_broker_info_t     	broker_info;
    static uint8_t buffer[1024];

    cy_rslt_t result;

    result = cy_mqtt_init();
    broker_info.hostname = CLOUD_MQTT_BROKER;
    broker_info.hostname_len = strlen(broker_info.hostname);
    broker_info.port = 1883;

    result = cy_mqtt_create( buffer, sizeof(buffer),
                              NULL, &amp;broker_info,
                              cloud_mqtt_event_cb, NULL,
                              &amp;mqtthandle );

    CY_ASSERT(result == CY_RSLT_SUCCESS);

    static char clientId[32];
    srand(xTaskGetTickCount());
    snprintf(clientId,sizeof(clientId),"%s%6d",CLOUD_MQTT_CLIENT_PREFIX,rand());
    memset( &amp;connect_info, 0, sizeof( cy_mqtt_connect_info_t ) );
    connect_info.client_id      = clientId;
    connect_info.client_id_len  = strlen(connect_info.client_id);
    connect_info.keep_alive_sec = 60;
    connect_info.will_info      = 0;
    connect_info.clean_session = true;


    result = cy_mqtt_connect( mqtthandle, &amp;connect_info );
    CY_ASSERT(result == CY_RSLT_SUCCESS);
    printf("MQTT Connect Success to %s Client=%s\n",CLOUD_MQTT_BROKER,clientId);

}</pre>
<p>You need an MQTT callback.  This is unused in this lesson but we will modify it for the drone.  Just copy it into your project</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">static void cloud_mqtt_event_cb( cy_mqtt_t mqtt_handle, cy_mqtt_event_t event, void *user_data )
{
    cy_mqtt_publish_info_t *received_msg;
    printf( "\nMQTT App callback with handle : %p \n", mqtt_handle );
    (void)user_data;
    switch( event.type )
    {
        case CY_MQTT_EVENT_TYPE_DISCONNECT :
            if( event.data.reason == CY_MQTT_DISCONN_TYPE_BROKER_DOWN )
            {
                printf( "\nCY_MQTT_DISCONN_TYPE_BROKER_DOWN .....\n" );
            }
            else
            {
                printf( "\nCY_MQTT_DISCONN_REASON_NETWORK_DISCONNECTION .....\n" );
            }
            break;
        case CY_MQTT_EVENT_TYPE_PUBLISH_RECEIVE :
            received_msg = &amp;(event.data.pub_msg.received_message);
            printf( "Incoming Publish Topic Name: %.*s\n", received_msg-&gt;topic_len, received_msg-&gt;topic );
            printf( "Incoming Publish message Packet Id is %u.\n", event.data.pub_msg.packet_id );
            printf( "Incoming Publish Message : %.*s.\n\n", ( int )received_msg-&gt;payload_len, ( const char * )received_msg-&gt;payload );
            break;
        default :
            printf( "\nUNKNOWN EVENT .....\n" );
            break;
    }
}</pre>
<p>To publish a message you</p>
<ol>
<li>Create the message</li>
<li>Send the publish</li>
</ol>
<pre class="EnlighterJSRAW" data-enlighter-language="c">static void cloud_publishMessage(char *topic,char *message)
{
    cy_mqtt_publish_info_t  pub_msg;
        
    pub_msg.qos = CY_MQTT_QOS0;
    pub_msg.topic = topic;
    pub_msg.topic_len = strlen(pub_msg.topic);
    pub_msg.payload = message;
    pub_msg.payload_len = strlen(message);
    
    cy_mqtt_publish( mqtthandle, &amp;pub_msg );
    printf("Published to Topic=%s Message=%s\n",topic,message);
    
}
</pre>
<div>
<h3>7. Update joystick_task.c</h3>
</div>
<p>We want the joystick task to be able to send joystick positions.  Include the cloud_task.h so that it gets access to the function to send messages.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">#include "cloud_task.h"</pre>
<p>Update the joystick function to call the send message function.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">/* Only update/print new value if it has changed by more than the hysteresis value */
if((joystick_curr.x &gt; (joystick_prev.x + JOYSTICK_HYSTERESIS)) || (joystick_curr.x &lt; (joystick_prev.x - JOYSTICK_HYSTERESIS)))
{
    printf("Joystick Position: %d\n", joystick_curr.x);
    cloud_sendMotorSpeed(joystick_curr.x); 

}</pre>
<div>
<h3>8. Update capsense_task.c</h3>
</div>
<p>We want the CapSense task to be able to send CapSense positions.  Include the cloud_task.h so that it gets access to the function to send messages.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">#include "cloud_task.h"</pre>
<p>Update the button code to send either 0 or 75 (0=STOP!!!#*##&amp;&amp;#) (75=take off)</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">if((0u != button0_status) &amp;&amp; (0u == button0_status_prev))
{
    printf("Button 0 pressed\n");
    cloud_sendMotorSpeed(0); // Stop the Motor
}

if((0u != button1_status) &amp;&amp; (0u == button1_status_prev))
{
    printf("Button 1 pressed\n");
    cloud_sendMotorSpeed(75); // Set the motor to 75%
}</pre>
<p>The slider just sends the current position.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">if((0u != slider_touched) &amp;&amp; (slider_pos_prev != slider_pos ))
{
    printf("Slider position %d\n",slider_pos);
    cloud_sendMotorSpeed(slider_pos);
}</pre>
<h3>9. Test (using an MQTT Client)</h3>
<p>You can download/install MQTTBox from <a href="http://workswithweb.com/mqttbox.html" target="_blank" rel="noopener">here</a>  This is a Mac/Linux/Windows MQTT client.  This will enable you to attach to the MQTT broker and then subscribe to the motor speed topic.</p>
<p><a href="https://iotexpert.com/ew21-lesson-4-mqtt/screen-shot-2021-02-23-at-10-53-16-am/" rel="attachment wp-att-10916"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.53.16-AM-1024x673.jpg" alt="" width="1024" height="673" class="alignnone size-large wp-image-10916" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.53.16-AM-1024x673.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.53.16-AM-300x197.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.53.16-AM-768x504.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.53.16-AM-1536x1009.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.53.16-AM-2048x1345.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.53.16-AM-600x394.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Setup the configuration for the MQTT broker by pressing the gear button</p>
<p><a href="https://iotexpert.com/ew21-lesson-4-mqtt/screen-shot-2021-02-23-at-10-53-02-am/" rel="attachment wp-att-10915"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.53.02-AM-1024x485.png" alt="" width="1024" height="485" class="alignnone size-large wp-image-10915" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.53.02-AM-1024x485.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.53.02-AM-300x142.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.53.02-AM-768x364.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.53.02-AM-1536x728.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.53.02-AM-2048x971.png 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.53.02-AM-600x284.png 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Then program your remote control and send some joystick and CapSense values.</p>
<p><a href="https://iotexpert.com/ew21-lesson-4-mqtt/screen-shot-2021-02-23-at-10-52-48-am/" rel="attachment wp-att-10914"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.52.48-AM-1024x564.jpg" alt="" width="1024" height="564" class="alignnone size-large wp-image-10914" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.52.48-AM-1024x564.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.52.48-AM-300x165.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.52.48-AM-768x423.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.52.48-AM-1536x847.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.52.48-AM-600x331.jpg 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.52.48-AM.jpg 1836w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>And you will see them coming out on the MQTTBox client</p>
<p><a href="https://iotexpert.com/ew21-lesson-4-mqtt/screen-shot-2021-02-23-at-10-52-39-am/" rel="attachment wp-att-10913"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.52.39-AM-1024x769.jpg" alt="" width="1024" height="769" class="alignnone size-large wp-image-10913" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.52.39-AM-1024x769.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.52.39-AM-300x225.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.52.39-AM-768x577.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.52.39-AM-1536x1154.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.52.39-AM-600x451.jpg 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-10.52.39-AM.jpg 1922w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h3>10. Test (using our C++/Qt GUI)</h3>
<p>My friend Butch created a C++/Qt GUI to &#8220;simulate&#8221; the drone.  You can find it in the &#8220;simulator&#8221; directory of project 4.  Here is what it looks like.  You will need to put in</p>
<ol>
<li>Which broker you are using</li>
<li>The name of your Topic</li>
</ol>
<p><a href="https://iotexpert.com/ew21-lesson-4-mqtt/screen-shot-2021-02-23-at-11-13-18-am/" rel="attachment wp-att-10919"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-11.13.18-AM-813x1024.png" alt="" width="813" height="1024" class="alignnone size-large wp-image-10919" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-11.13.18-AM-813x1024.png 813w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-11.13.18-AM-238x300.png 238w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-11.13.18-AM-768x968.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-11.13.18-AM-600x756.png 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-11.13.18-AM.png 838w" sizes="(max-width: 813px) 100vw, 813px" /></a></p>
<div>
<h1>Resources for Project</h1>
<p>You can find this completed project in your project creator dialog by filtering for &#8220;IoT Expert Embedded&#8221;.  This is lesson 4</p>
<p><a href="https://iotexpert.com/ew21-lesson-1-freertos-capsense/screen-shot-2021-02-22-at-4-33-54-pm/" rel="attachment wp-att-10817"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.33.54-PM-1024x581.png" alt="" width="1024" height="581" class="alignnone size-large wp-image-10817" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.33.54-PM-1024x581.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.33.54-PM-300x170.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.33.54-PM-768x436.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.33.54-PM-1536x872.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.33.54-PM-2048x1162.png 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.33.54-PM-600x341.png 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>You can also clone this project at git@github.com:iotexpert/ew21-lesson4.git or https://github.com/iotexpert/ew21-lesson4</p>
</div>
<div>
<p>Here is the final cloud_task.c</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">#include &lt;stdio.h&gt;

#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"

#include "cy_wcm.h"
#include "cy_mqtt_api.h"

#include "cloud_task.h"


#define CLOUD_WIFI_AP        "ew2021"
#define CLOUD_WIFI_PW        "ew2021ap"
#define CLOUD_WIFI_SECURITY  CY_WCM_SECURITY_WPA2_AES_PSK
#define CLOUD_WIFI_BAND      CY_WCM_WIFI_BAND_ANY

#define CLOUD_MQTT_BROKER        "mqtt.eclipseprojects.io"


#define CLOUD_MQTT_CLIENT_PREFIX "remote"
#define CLOUD_MQTT_TOPIC         "motor_speed"

#define MOTOR_KEY                "motor"

static QueueHandle_t motor_value_q;
static cy_mqtt_t mqtthandle;

static void cloud_connectWifi();
static void cloud_startMQTT();
static void cloud_mqtt_event_cb( cy_mqtt_t mqtt_handle, cy_mqtt_event_t event, void *user_data);

static void cloud_publishMessage(char *topic,char *message);

void cloud_task(void* param)
{
    (void)param;

    cloud_connectWifi();
    cloud_startMQTT();

    motor_value_q = xQueueCreate(1,sizeof(uint32_t));

    for(;;)
    {
        int motorSpeed;
        char message[32];

    	xQueueReceive(motor_value_q, &amp;motorSpeed, portMAX_DELAY);
        snprintf(message, sizeof(message)-1, "{\"%s\":%d}",MOTOR_KEY,motorSpeed);
        cloud_publishMessage(CLOUD_MQTT_TOPIC,message);
    }
}

void cloud_sendMotorSpeed(int speed)
{
    if(motor_value_q)
        xQueueSend(motor_value_q,&amp;speed,0);
}

static void cloud_connectWifi()
{
    cy_rslt_t result;

    cy_wcm_connect_params_t connect_param = {
        .ap_credentials.SSID = CLOUD_WIFI_AP,
        .ap_credentials.password = CLOUD_WIFI_PW,
        .ap_credentials.security = CLOUD_WIFI_SECURITY,
    	.static_ip_settings = 0,
        .BSSID = {0},
        .band = CLOUD_WIFI_BAND,
    };
    cy_wcm_config_t config = {.interface = CY_WCM_INTERFACE_TYPE_STA}; // We are a station (not a Access Point)

    cy_wcm_init(&amp;config); // Initialize the connection manager

    printf("\nWi-Fi Connection Manager initialized.\n");

    do
    {
        cy_wcm_ip_address_t ip_address;

        printf("Connecting to Wi-Fi AP '%s'\n", connect_param.ap_credentials.SSID);
        result = cy_wcm_connect_ap(&amp;connect_param, &amp;ip_address);

        if (result == CY_RSLT_SUCCESS)
        {
            printf("Successfully connected to Wi-Fi network '%s'.\n",
                    connect_param.ap_credentials.SSID);

            // Print IP Address
            if (ip_address.version == CY_WCM_IP_VER_V4)
            {
                printf("IPv4 Address Assigned: %d.%d.%d.%d\n", (uint8_t)ip_address.ip.v4,
                        (uint8_t)(ip_address.ip.v4 &gt;&gt; 8), (uint8_t)(ip_address.ip.v4 &gt;&gt; 16),
                        (uint8_t)(ip_address.ip.v4 &gt;&gt; 24));
            }
            else if (ip_address.version == CY_WCM_IP_VER_V6)
            {
                printf("IPv6 Address Assigned: %0X:%0X:%0X:%0X\n", (unsigned int)ip_address.ip.v6[0],
                        (unsigned int)ip_address.ip.v6[1], (unsigned int)ip_address.ip.v6[2],
                        (unsigned int)ip_address.ip.v6[3]);
            }
            break; /* Exit the for loop once the connection has been made */
        }
        else
        {
            printf("WiFi Connect Failed Retrying\n");
            vTaskDelay(2000); // wait 2 seconds and try again;
        }

    } while (result != CY_RSLT_SUCCESS);

}

static void cloud_startMQTT()
{
    static cy_mqtt_connect_info_t    	connect_info;
    static cy_mqtt_broker_info_t     	broker_info;
    static uint8_t buffer[1024];

    cy_rslt_t result;

    result = cy_mqtt_init();
    broker_info.hostname = CLOUD_MQTT_BROKER;
    broker_info.hostname_len = strlen(broker_info.hostname);
    broker_info.port = 1883;

    result = cy_mqtt_create( buffer, sizeof(buffer),
                              NULL, &amp;broker_info,
                              cloud_mqtt_event_cb, NULL,
                              &amp;mqtthandle );

    CY_ASSERT(result == CY_RSLT_SUCCESS);

    static char clientId[32];
    srand(xTaskGetTickCount());
    snprintf(clientId,sizeof(clientId),"%s%6d",CLOUD_MQTT_CLIENT_PREFIX,rand());
    memset( &amp;connect_info, 0, sizeof( cy_mqtt_connect_info_t ) );
    connect_info.client_id      = clientId;
    connect_info.client_id_len  = strlen(connect_info.client_id);
    connect_info.keep_alive_sec = 60;
    connect_info.will_info      = 0;
    connect_info.clean_session = true;


    result = cy_mqtt_connect( mqtthandle, &amp;connect_info );
    CY_ASSERT(result == CY_RSLT_SUCCESS);
    printf("MQTT Connect Success to %s Client=%s\n",CLOUD_MQTT_BROKER,clientId);

}

static void cloud_mqtt_event_cb( cy_mqtt_t mqtt_handle, cy_mqtt_event_t event, void *user_data )
{
    cy_mqtt_publish_info_t *received_msg;
    printf( "\nMQTT App callback with handle : %p \n", mqtt_handle );
    (void)user_data;
    switch( event.type )
    {
        case CY_MQTT_EVENT_TYPE_DISCONNECT :
            if( event.data.reason == CY_MQTT_DISCONN_TYPE_BROKER_DOWN )
            {
                printf( "\nCY_MQTT_DISCONN_TYPE_BROKER_DOWN .....\n" );
            }
            else
            {
                printf( "\nCY_MQTT_DISCONN_REASON_NETWORK_DISCONNECTION .....\n" );
            }
            break;
        case CY_MQTT_EVENT_TYPE_PUBLISH_RECEIVE :
            received_msg = &amp;(event.data.pub_msg.received_message);
            printf( "Incoming Publish Topic Name: %.*s\n", received_msg-&gt;topic_len, received_msg-&gt;topic );
            printf( "Incoming Publish message Packet Id is %u.\n", event.data.pub_msg.packet_id );
            printf( "Incoming Publish Message : %.*s.\n\n", ( int )received_msg-&gt;payload_len, ( const char * )received_msg-&gt;payload );
            break;
        default :
            printf( "\nUNKNOWN EVENT .....\n" );
            break;
    }
}

static void cloud_publishMessage(char *topic,char *message)
{
    cy_mqtt_publish_info_t  pub_msg;
        
    pub_msg.qos = CY_MQTT_QOS0;
    pub_msg.topic = topic;
    pub_msg.topic_len = strlen(pub_msg.topic);
    pub_msg.payload = message;
    pub_msg.payload_len = strlen(message);
    
    cy_mqtt_publish( mqtthandle, &amp;pub_msg );
    printf("Published to Topic=%s Message=%s\n",topic,message);
    
}
</pre>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/ew21-lesson-4-mqtt/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>EW21: Lesson 5: Low Power</title>
		<link>https://iotexpert.com/ew21-lesson-5-low-power/</link>
					<comments>https://iotexpert.com/ew21-lesson-5-low-power/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Wed, 24 Feb 2021 15:23:04 +0000</pubDate>
				<category><![CDATA[Embedded World 2021]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=10784</guid>

					<description><![CDATA[Summary The FreeRTOS template we started with already enables low power mode transitions such as Sleep and Deep Sleep. In lesson 5 we will update our remote control project to have even lower power as remote controls are almost always driven by batteries.  We will do this by using lower power regulators, slowing down clocks, [&#8230;]]]></description>
										<content:encoded><![CDATA[<div>
<p><span><h1>Embedded World 2021 - Infineon ModusToolbox PSoC 6 Drone </h1>
<p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >#</th>
<th >Description</th>
</tr>
</thead>
<tbody>
<tr><td >0</td>
<td ><a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/" target="_blank" rel="noopener">Introduction &amp; Resources</a></td>
</tr>

<tr><td >1</td>
<td ><a href="https://iotexpert.com/ew21-lesson-1-freertos-capsense/" target="_blank" rel="noopener">FreeRTOS &amp; CapSense</a></td>
</tr>

<tr><td >2</td>
<td ><a href="https://iotexpert.com/ew21-lesson-2-joystick/" target="_blank" rel="noopener">3-D Magnetic Sensing XENSIV Joystick</a></td>
</tr>

<tr><td >3</td>
<td ><a href="https://iotexpert.com/ew21-lesson-3-wifi/" target="_blank" rel="noopener">WiFi</a></td>
</tr>

<tr><td >4</td>
<td ><a href="https://iotexpert.com/ew21-lesson-4-mqtt/" target="_blank" rel="noopener">MQTT</a></td>
</tr>

<tr><td >5</td>
<td ><a href="https://iotexpert.com/ew21-lesson-5-low-power/" target="_blank" rel="noopener">Low Power</a></td>
</tr>

<tr><td >6</td>
<td ><a href="https://iotexpert.com/ew21-lesson-6-motor-control/" target="_blank" rel="noopener">BLDC Motor Control</a></td>
</tr>

<tr><td >7</td>
<td ><a href="https://iotexpert.com/ew21-lesson-7-ws2812-led-strip/" target="_blank" rel="noopener">WS2812 Strip LEDs</a></td>
</tr>
</tbody></table></div></p>
<p>&nbsp;</p></span></p>
<h1>Summary</h1>
<p>The FreeRTOS template we started with already enables low power mode transitions such as Sleep and Deep Sleep. In lesson 5 we will update our remote control project to have even lower power as remote controls are almost always driven by batteries.  We will do this by using lower power regulators, slowing down clocks, and by offloading some functionality to the WiFi chip. This will be the final lesson on the remote control.  Here is the architecture:</p>
<p><a href="https://iotexpert.com/ew21-lesson-5-low-power/l5-arch/" rel="attachment wp-att-10983"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/l5-arch-1024x433.png" alt="" width="1024" height="433" class="alignnone size-large wp-image-10983" srcset="https://iotexpert.com/wp-content/uploads/2021/02/l5-arch-1024x433.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/l5-arch-300x127.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/l5-arch-768x324.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/l5-arch-1536x649.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/l5-arch-600x253.png 600w, https://iotexpert.com/wp-content/uploads/2021/02/l5-arch.png 1631w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>Learning Objectives</h1>
<p>This lesson will show you two important features of Modus Toolbox.</p>
<ol>
<li>How to reduce system power using the Low Power Assistant</li>
<li>How to create a custom board support package</li>
</ol>
<h1>Procedure</h1>
<ol>
<li>Create your project</li>
<li>Create a custom Board Support Package</li>
<li>Modify the Makefile to use the new BSP</li>
<li>Add the Low Power Assistant to the project</li>
<li>Use the Configurator to setup Low Power</li>
<li>Examine FreeRTOSConfig.h</li>
<li>Test the project</li>
</ol>
<h3>1. Create the project</h3>
<p>Start the project creator and make a copy of your 4th project.</p>
<p><a href="https://iotexpert.com/ew21-lesson-5-low-power/screen-shot-2021-02-23-at-5-27-11-pm/" rel="attachment wp-att-10987"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-5.27.11-PM-1024x708.jpg" alt="" width="1024" height="708" class="alignnone size-large wp-image-10987" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-5.27.11-PM-1024x708.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-5.27.11-PM-300x207.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-5.27.11-PM-768x531.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-5.27.11-PM-1536x1062.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-5.27.11-PM-2048x1416.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-5.27.11-PM-600x415.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Call it Lesson_5</p>
<p><a href="https://iotexpert.com/ew21-lesson-5-low-power/screen-shot-2021-02-23-at-5-27-51-pm/" rel="attachment wp-att-10988"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-5.27.51-PM-1024x717.jpg" alt="" width="1024" height="717" class="alignnone size-large wp-image-10988" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-5.27.51-PM-1024x717.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-5.27.51-PM-300x210.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-5.27.51-PM-768x538.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-5.27.51-PM-1536x1076.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-5.27.51-PM-2048x1435.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-5.27.51-PM-600x420.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h3>2. Override the BSP Configuration</h3>
<p>Make a directory called &#8220;COMPONENT_CUSTOM_DESIGN_MODUS&#8221; to contain the configuration files that will override the configuration from the BSP.  This will be brought into the project automatically by the build system.</p>
<p>Note: You can also create a complete custom BSP which allows changing things like linker scripts, startup code, etc. See the ModusToolbox User Guide for details on how to do that.</p>
<p><a href="https://iotexpert.com/ew21-lesson-5-low-power/screen-shot-2021-02-23-at-1-48-42-pm/" rel="attachment wp-att-10943"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.48.42-PM-1024x276.png" alt="" width="1024" height="276" class="alignnone size-large wp-image-10943" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.48.42-PM-1024x276.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.48.42-PM-300x81.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.48.42-PM-768x207.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.48.42-PM-600x161.png 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.48.42-PM.png 1152w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Make a directory called &#8220;TARGET_CY8CPROTO-062-4343W&#8221; in your project.  This directory will hold the custom BSP files.</p>
<p><a href="https://iotexpert.com/ew21-lesson-5-low-power/screen-shot-2021-02-23-at-1-49-09-pm/" rel="attachment wp-att-10944"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.49.09-PM-1024x258.png" alt="" width="1024" height="258" class="alignnone size-large wp-image-10944" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.49.09-PM-1024x258.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.49.09-PM-300x76.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.49.09-PM-768x194.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.49.09-PM-600x151.png 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.49.09-PM.png 1150w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Copy and paste the configuration files from the Modus Toolbox BSP directly into your project.</p>
<p><a href="https://iotexpert.com/ew21-lesson-5-low-power/screen-shot-2021-02-23-at-1-49-32-pm/" rel="attachment wp-att-10945"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.49.32-PM-988x1024.png" alt="" width="988" height="1024" class="alignnone size-large wp-image-10945" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.49.32-PM-988x1024.png 988w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.49.32-PM-289x300.png 289w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.49.32-PM-768x796.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.49.32-PM-600x622.png 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.49.32-PM.png 1140w" sizes="(max-width: 988px) 100vw, 988px" /></a></p>
<p>Now your project should have these files:</p>
</div>
<p><a href="https://iotexpert.com/ew21-lesson-5-low-power/screen-shot-2021-02-24-at-8-33-25-am/" rel="attachment wp-att-11048"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-8.33.25-AM-1024x317.png" alt="" width="1024" height="317" class="alignnone size-large wp-image-11048" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-8.33.25-AM-1024x317.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-8.33.25-AM-300x93.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-8.33.25-AM-768x238.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-8.33.25-AM-600x186.png 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-24-at-8.33.25-AM.png 1136w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<div>
<h3>3. Modify the Makefile</h3>
</div>
<p>You need to</p>
<ol>
<li>Enable your new BSP</li>
<li>Disable the existing BSP</li>
</ol>
<p>Do this by adding to the COMPONENTS and DISABLE_COMPONENTS line in the Makefile</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">COMPONENTS= FREERTOS LWIP MBEDTLS SECURE_SOCKETS CUSTOM_DESIGN_MODUS WCM
DISABLE_COMPONENTS=BSP_DESIGN_MODUS</pre>
<div>
<h3>4. Add the Low Power Assistant to the project</h3>
<p>Start the Library Manager and add the LPA (Low Power Assistant) library to your project</p>
<p><a href="https://iotexpert.com/ew21-lesson-5-low-power/screen-shot-2021-02-23-at-1-12-02-pm/" rel="attachment wp-att-10939"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.12.02-PM-1024x795.jpg" alt="" width="1024" height="795" class="alignnone size-large wp-image-10939" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.12.02-PM-1024x795.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.12.02-PM-300x233.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.12.02-PM-768x596.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.12.02-PM-1536x1193.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.12.02-PM-2048x1590.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.12.02-PM-600x466.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h3>5. Use the configurator to Setup for Low Power</h3>
<p>Set the System Active Power Mode to ULP and enable the &#8220;Normal Current Buck&#8221;.</p>
<p>Notice that the System Idle Power Mode is already set to System Deep Sleep. This means that when the RTOS is not busy, it will attempt to enter Deep Sleep mode.</p>
<p><a href="https://iotexpert.com/ew21-lesson-5-low-power/screen-shot-2021-02-23-at-1-03-49-pm/" rel="attachment wp-att-10934"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.03.49-PM-1024x918.jpg" alt="" width="1024" height="918" class="alignnone size-large wp-image-10934" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.03.49-PM-1024x918.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.03.49-PM-300x269.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.03.49-PM-768x689.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.03.49-PM-1536x1378.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.03.49-PM-2048x1837.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.03.49-PM-600x538.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Turn down the FLL to 50 Mhz</p>
<p><a href="https://iotexpert.com/ew21-lesson-5-low-power/screen-shot-2021-02-23-at-1-05-04-pm/" rel="attachment wp-att-10935"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.05.04-PM-1024x918.jpg" alt="" width="1024" height="918" class="alignnone size-large wp-image-10935" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.05.04-PM-1024x918.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.05.04-PM-300x269.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.05.04-PM-768x689.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.05.04-PM-1536x1377.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.05.04-PM-2048x1836.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.05.04-PM-600x538.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Lower the frequency of the peripherals by cutting the divider in half.</p>
<p><a href="https://iotexpert.com/ew21-lesson-5-low-power/screen-shot-2021-02-23-at-1-05-16-pm/" rel="attachment wp-att-10936"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.05.16-PM-1024x465.jpg" alt="" width="1024" height="465" class="alignnone size-large wp-image-10936" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.05.16-PM-1024x465.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.05.16-PM-300x136.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.05.16-PM-768x348.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.05.16-PM-1536x697.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.05.16-PM-2048x929.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.05.16-PM-600x272.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>In order to save power the host can sleep and wait for WiFi packets.  The WiFi chip needs to be able to wakeup the host PSoC.  Enable P0[4] as the wakeup pin and turn on the interrupt.</p>
<p><a href="https://iotexpert.com/ew21-lesson-5-low-power/screen-shot-2021-02-23-at-1-09-32-pm/" rel="attachment wp-att-10937"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.09.32-PM-1024x906.png" alt="" width="1024" height="906" class="alignnone size-large wp-image-10937" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.09.32-PM-1024x906.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.09.32-PM-300x265.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.09.32-PM-768x679.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.09.32-PM-600x531.png 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.09.32-PM.png 1318w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>&nbsp;</p>
<p>Click on the CYW4343WKUGB tab.  Enable the host wakeup option.  Set the pin to P0[4].  Enable ARP off loads.  You can also look through the other low power offload filters.</p>
<p><a href="https://iotexpert.com/ew21-lesson-5-low-power/screen-shot-2021-02-23-at-1-46-37-pm/" rel="attachment wp-att-10941"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.46.37-PM-1024x480.jpg" alt="" width="1024" height="480" class="alignnone size-large wp-image-10941" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.46.37-PM-1024x480.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.46.37-PM-300x141.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.46.37-PM-768x360.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.46.37-PM-1536x720.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.46.37-PM-2048x960.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-1.46.37-PM-600x281.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h3>6. Examine FreeRTOSConfig.h</h3>
<p>Along with the System Idle Power Mode in the Configurator, this block of code tells FreeRTOS that when the system is idle that it should go to sleep.</p>
<p>The function vApplicationSleep is in the abstraction-rtos library and it allows the system to go to sleep and wake up cleanly in the context of FreeRTOS.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">#if CY_CFG_PWR_SYS_IDLE_MODE == CY_CFG_PWR_MODE_SLEEP || CY_CFG_PWR_SYS_IDLE_MODE == CY_CFG_PWR_MODE_DEEPSLEEP
extern void vApplicationSleep( uint32_t xExpectedIdleTime );
#define portSUPPRESS_TICKS_AND_SLEEP( xIdleTime ) vApplicationSleep( xIdleTime )
#define configUSE_TICKLESS_IDLE  2
#endif

#if CY_CFG_PWR_DEEPSLEEP_LATENCY&gt;0
#define configEXPECTED_IDLE_TIME_BEFORE_SLEEP CY_CFG_PWR_DEEPSLEEP_LATENCY
#endif
</pre>
<h3>7. Test</h3>
<p>Program and test to make sure that things still work.  If you have a DMM plug it in and find out how much power you saved.</p>
<p><a href="https://iotexpert.com/ew21-lesson-5-low-power/screen-shot-2021-02-23-at-2-11-04-pm/" rel="attachment wp-att-10947"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-2.11.04-PM-1024x552.jpg" alt="" width="1024" height="552" class="alignnone size-large wp-image-10947" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-2.11.04-PM-1024x552.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-2.11.04-PM-300x162.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-2.11.04-PM-768x414.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-2.11.04-PM-1536x828.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-2.11.04-PM-2048x1104.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-2.11.04-PM-600x324.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>Resources for Project</h1>
<p>You can find the completed project in your project creator dialog by filtering for &#8220;IoT Expert Embedded&#8221;.  This is lesson5</p>
<p><a href="https://iotexpert.com/ew21-lesson-1-freertos-capsense/screen-shot-2021-02-22-at-4-34-13-pm/" rel="attachment wp-att-10816"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.34.13-PM-1024x586.png" alt="" width="1024" height="586" class="alignnone size-large wp-image-10816" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.34.13-PM-1024x586.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.34.13-PM-300x172.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.34.13-PM-768x439.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.34.13-PM-1536x879.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.34.13-PM-2048x1172.png 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.34.13-PM-600x343.png 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>You can also clone this project at git@github.com:iotexpert/ew21-lesson5.git or https://github.com/iotexpert/ew21-lesson5</p>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/ew21-lesson-5-low-power/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>EW21: Lesson 6: Motor Control</title>
		<link>https://iotexpert.com/ew21-lesson-6-motor-control/</link>
					<comments>https://iotexpert.com/ew21-lesson-6-motor-control/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Wed, 24 Feb 2021 15:22:28 +0000</pubDate>
				<category><![CDATA[Embedded World 2021]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=10785</guid>

					<description><![CDATA[Summary In lesson 6 we will turn our attention to the drone. Everything on the drone side is almost exactly the same as remote control, so I will copy all of that code to start with then add the motor controller.  At the end of lesson one you will have the functioning drone controller.  Here [&#8230;]]]></description>
										<content:encoded><![CDATA[<div>
<p><span><h1>Embedded World 2021 - Infineon ModusToolbox PSoC 6 Drone </h1>
<p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >#</th>
<th >Description</th>
</tr>
</thead>
<tbody>
<tr><td >0</td>
<td ><a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/" target="_blank" rel="noopener">Introduction &amp; Resources</a></td>
</tr>

<tr><td >1</td>
<td ><a href="https://iotexpert.com/ew21-lesson-1-freertos-capsense/" target="_blank" rel="noopener">FreeRTOS &amp; CapSense</a></td>
</tr>

<tr><td >2</td>
<td ><a href="https://iotexpert.com/ew21-lesson-2-joystick/" target="_blank" rel="noopener">3-D Magnetic Sensing XENSIV Joystick</a></td>
</tr>

<tr><td >3</td>
<td ><a href="https://iotexpert.com/ew21-lesson-3-wifi/" target="_blank" rel="noopener">WiFi</a></td>
</tr>

<tr><td >4</td>
<td ><a href="https://iotexpert.com/ew21-lesson-4-mqtt/" target="_blank" rel="noopener">MQTT</a></td>
</tr>

<tr><td >5</td>
<td ><a href="https://iotexpert.com/ew21-lesson-5-low-power/" target="_blank" rel="noopener">Low Power</a></td>
</tr>

<tr><td >6</td>
<td ><a href="https://iotexpert.com/ew21-lesson-6-motor-control/" target="_blank" rel="noopener">BLDC Motor Control</a></td>
</tr>

<tr><td >7</td>
<td ><a href="https://iotexpert.com/ew21-lesson-7-ws2812-led-strip/" target="_blank" rel="noopener">WS2812 Strip LEDs</a></td>
</tr>
</tbody></table></div></p>
<p>&nbsp;</p></span></p>
<h1>Summary</h1>
<p>In lesson 6 we will turn our attention to the drone. Everything on the drone side is almost exactly the same as remote control, so I will copy all of that code to start with then add the motor controller.  At the end of lesson one you will have the functioning drone controller.  Here is the architecture:</p>
<p><a href="https://iotexpert.com/ew21-lesson-6-motor-control/l6-arch/" rel="attachment wp-att-10985"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/l6-arch-1024x433.png" alt="" width="1024" height="433" class="alignnone size-large wp-image-10985" srcset="https://iotexpert.com/wp-content/uploads/2021/02/l6-arch-1024x433.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/l6-arch-300x127.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/l6-arch-768x324.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/l6-arch-1536x649.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/l6-arch-600x253.png 600w, https://iotexpert.com/wp-content/uploads/2021/02/l6-arch.png 1631w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>Learning Objectives</h1>
<ol>
<li>Retargeting a project to a different board</li>
<li>Using the Infineon BLDC Motor Controller</li>
<li>Subscribing to a MQTT topic</li>
</ol>
<h1>Procedure</h1>
<ol>
<li>Make a new project</li>
<li>Rip out the joystick_task.c/h and fix main.c</li>
<li>Add the motor driver library</li>
<li>Create motor_task.h</li>
<li>Create motor_task.c</li>
<li>Update the CapSense task to submit to the motor_task</li>
<li>Fix the Cloud Task to perform MQTT subscribe instead of publish</li>
<li>Fix main.c to start the motor task</li>
<li>Test</li>
</ol>
<h3>1. Make a new project</h3>
<p>In order to control the BLDC motor I am going to a development kit that has Arduino headers, the CY8CKIT-062S2-43012.  Start your project from that BSP.</p>
<p><a href="https://iotexpert.com/ew21-lesson-6-motor-control/screen-shot-2021-02-23-at-3-07-24-pm/" rel="attachment wp-att-10951"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.07.24-PM-1024x708.jpg" alt="" width="1024" height="708" class="alignnone size-large wp-image-10951" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.07.24-PM-1024x708.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.07.24-PM-300x208.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.07.24-PM-768x531.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.07.24-PM-1536x1062.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.07.24-PM-2048x1417.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.07.24-PM-600x415.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Our project is basically the same as Lesson4, so import that as a template.</p>
<p><a href="https://iotexpert.com/ew21-lesson-6-motor-control/screen-shot-2021-02-23-at-3-07-37-pm/" rel="attachment wp-att-10952"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.07.37-PM-1024x583.png" alt="" width="1024" height="583" class="alignnone size-large wp-image-10952" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.07.37-PM-1024x583.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.07.37-PM-300x171.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.07.37-PM-768x437.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.07.37-PM-1536x875.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.07.37-PM-600x342.png 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.07.37-PM.png 1594w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Don&#8217;t sully your project&#8217;s name, pick something good.</p>
<p><a href="https://iotexpert.com/ew21-lesson-6-motor-control/screen-shot-2021-02-23-at-3-08-08-pm/" rel="attachment wp-att-10953"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.08.08-PM-1024x489.jpg" alt="" width="1024" height="489" class="alignnone size-large wp-image-10953" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.08.08-PM-1024x489.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.08.08-PM-300x143.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.08.08-PM-768x367.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.08.08-PM-1536x734.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.08.08-PM-2048x979.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.08.08-PM-600x287.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h3>2. Rip out the joystick_task</h3>
<p>This project will not have the joystick task.  Nuke it! Don&#8217;t forget to remove the task start from main.c</p>
<p><a href="https://iotexpert.com/ew21-lesson-6-motor-control/screen-shot-2021-02-23-at-3-09-27-pm/" rel="attachment wp-att-10954"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.09.27-PM-1024x578.png" alt="" width="1024" height="578" class="alignnone size-large wp-image-10954" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.09.27-PM-1024x578.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.09.27-PM-300x169.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.09.27-PM-768x434.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.09.27-PM-600x339.png 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.09.27-PM.png 1172w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h3>3. Add the Motor Driver Library and Remove the Magnetic Sensor</h3>
<p>For this project we will be talking to the TLE9879 BLDC motor shield.  I provide you a driver library for that.  And we won&#8217;t need the 3-D Magnetic sensing library any more.</p>
</div>
<p><a href="https://iotexpert.com/ew21-lesson-6-motor-control/screen-shot-2021-02-23-at-3-23-18-pm/" rel="attachment wp-att-10956"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.23.18-PM-1024x793.jpg" alt="" width="1024" height="793" class="alignnone size-large wp-image-10956" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.23.18-PM-1024x793.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.23.18-PM-300x232.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.23.18-PM-768x595.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.23.18-PM-1536x1190.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.23.18-PM-2048x1586.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.23.18-PM-600x465.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<div>
<h3>4. Create motor_task.h</h3>
</div>
<p>Create a motor_task.h  This will have the definition of the task, plus a function to set the motor speed by submitting to a queue.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">#pragma once

void motor_task(void* param);

void motor_update(int speed);
</pre>
<div>
<h3>5. Create motor_task.c</h3>
</div>
<p>The motor task needs some include files.  This task will also use a queue to manage other tasks (cloud and CapSense) that will submitting data to change the speed of the motor.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">#include "cybsp.h"
#include "cyhal.h"
#include "cycfg.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;math.h&gt;

#include "motor_task.h"

#include "tle9879_system.h"

static QueueHandle_t motor_value_q;</pre>
<p>I will define a few constants that will help me map 0-100% into 0-5500 RPM (the max for this motor). The motor needs to run at a decent speed to start up properly so we will map 10% to 1000 RPM. Below 10%, the motor will be off.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">/*******************************************************************************
* Global constants
*******************************************************************************/
#define		RPM_CHANGE_INTERVAL		(100)
#define		RPM_CHANGE_RATE			(10)
#define		RPM_PERCENT_MIN			(10)

#define  	RPM_MAX 				5500.0
#define  	RPM_MIN 				1000.0
</pre>
<p>The task is pretty simple, but with one trick.  Apparently you ramp changes in motor speed, so I use a timeout in the message queue to give me a periodic change.  The task is</p>
<ol>
<li>Start the shield</li>
<li>Then wait for a new value in the queue (or the timeout)</li>
<li>If it is a new value then change the desired value</li>
<li>If the current value is not the same as the desired value then take a step towards the desired value</li>
</ol>
<pre class="EnlighterJSRAW" data-enlighter-language="c">void motor_task(void* param)
{
    (void)param;

    tle9879_sys_t tle9879_sys;

    uint8_t numberOfBoards = 1;
    BaseType_t rtos_api_result;

    motor_value_q = xQueueCreate(1,sizeof(int));

    /* Initialize and configure the motor driver */
    tle9879sys_init(&amp;tle9879_sys,
    					CYBSP_D11,
                        CYBSP_D12,
                        CYBSP_D13,
                        NULL,
                        CYBSP_D4,
                        CYBSP_D5,
                        CYBSP_D6,
                        CYBSP_D7,
                        &amp;numberOfBoards);
    if (tle9879_sys.board_count == 0)
    {
        printf("Motor board not detected. Exiting Motor task.\n");
        vTaskDelete(NULL);
    }

    tle9879sys_setMode(&amp;tle9879_sys, FOC, 1, false);
    
    bool motorState=false;
    int currentPercentage=0;
    int desiredPercentage=0;

    while(1)
    {
    	rtos_api_result = xQueueReceive(motor_value_q, &amp;desiredPercentage, RPM_CHANGE_INTERVAL);

       	/* Value has been received from the queue (i.e. not a timeout) */
        if(rtos_api_result == pdTRUE)
        {
            if(desiredPercentage &lt; RPM_PERCENT_MIN) /* Any value less than 10% will result in stopping the motor */
                desiredPercentage = 0;
        
            if(desiredPercentage&gt;100)
                desiredPercentage = 100;
        }

        if(currentPercentage != desiredPercentage)
        {
            if(abs(currentPercentage-desiredPercentage) &lt; RPM_CHANGE_RATE)
                currentPercentage = desiredPercentage;

            if (currentPercentage &lt; desiredPercentage)
                currentPercentage = currentPercentage + RPM_CHANGE_RATE;
            if (currentPercentage &gt; desiredPercentage)
                currentPercentage = currentPercentage - RPM_CHANGE_RATE;

            if(currentPercentage&gt;0 &amp;&amp; motorState==false)
            {
                tle9879sys_setMotorMode(&amp;tle9879_sys, START_MOTOR, 1);
                motorState = true;
            }
            if(currentPercentage == 0 &amp;&amp; motorState==true)
            {
                tle9879sys_setMotorMode(&amp;tle9879_sys, STOP_MOTOR, 1);
                motorState = false;
            }

            float motorSpeed = ((float)(currentPercentage-RPM_PERCENT_MIN))/(float)(100.0-RPM_PERCENT_MIN) * (RPM_MAX - RPM_MIN) + RPM_MIN;

            tle9879sys_setMotorSpeed(&amp;tle9879_sys, motorSpeed, 1);
            printf("Current %d%% Desired=%d%% Speed=%f\n",currentPercentage,desiredPercentage,motorSpeed);
        }
    }
}</pre>
<p>In order to simplify the CapSense and cloud tasks I provide a function to submit a new percent to the queue.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">void motor_update(int speed)
{
    if(motor_value_q)
        xQueueOverwrite(motor_value_q,&amp;speed);
}
</pre>
<div>
<h3>6. Update the CapSense task to submit to the motor_task</h3>
</div>
<p>Lets fix the CapSense task to submit to the motor queue.  First fix the include.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">#include "motor_task.h"</pre>
<p>Then update the buttons to use the submit function</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">if((0u != button0_status) &amp;&amp; (0u == button0_status_prev))
{
    printf("Button 0 pressed\n");
    motor_update(0); // Stop the Motor
}

if((0u != button1_status) &amp;&amp; (0u == button1_status_prev))
{
    printf("Button 1 pressed\n");
    motor_update(75); // Set the motor to 75%
}
</pre>
<p>Fix the slider to use the submit function as well.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">if((0u != slider_touched) &amp;&amp; (slider_pos_prev != slider_pos ))
{
    printf("Slider position %d\n",slider_pos);
    motor_update(slider_pos);
}
</pre>
<p>7. Fix the Cloud Task</p>
<p>Remember that we copied our cloud task from the remote control.  It publishes MQTT messages.  We need to fix the cloud task to subscribe instead of publish.   If you recall from Lesson 4 we submit the messages as JSON.  To decode the JSON I will use a JSON parser.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">#include "cy_json_parser.h"</pre>
<p>The function prototypes are almost the same, except for a subscribe instead of publish, plus a JSON callback</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">static void cloud_connectWifi();
static void cloud_startMQTT();
static void cloud_subscribeMQTT();
static void cloud_mqtt_event_cb( cy_mqtt_t mqtt_handle, cy_mqtt_event_t event, void *user_data);
static cy_rslt_t json_cb(cy_JSON_object_t *json_object, void *arg);
</pre>
<p>The cloud task is much simpler this time.  connect, start, subscribe and then wait for some action.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">void cloud_task(void* param)
{
    (void)param;

    cloud_connectWifi();
    cloud_startMQTT();
    cloud_subscribeMQTT();

    for(;;)
    {
        vTaskSuspend(NULL);
    }
}</pre>
<p>To subscribe you just setup a subscribe info structure.  Then call the subscribe.  You also need to configure the JSON parser.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">static void cloud_subscribeMQTT()
{

    cy_rslt_t result;

    cy_mqtt_subscribe_info_t    sub_msg[1];

    /* Subscribe to motor speed MQTT messages */
    sub_msg[0].qos = 0;
    sub_msg[0].topic = CLOUD_MQTT_TOPIC;
    sub_msg[0].topic_len = strlen(sub_msg[0].topic);

    result = cy_mqtt_subscribe( mqtthandle, sub_msg, 1 );
    CY_ASSERT(result == CY_RSLT_SUCCESS);
    printf("Subscribe Success to Topic %s\n",CLOUD_MQTT_TOPIC);

    /* Register JSON callback function */
    cy_JSON_parser_register_callback(json_cb, NULL);

}
</pre>
<p>When you get a callback from the MQTT, you will look and see which topic.  If it matches the motor topic then call the JSON parser.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">static void cloud_mqtt_event_cb( cy_mqtt_t mqtt_handle, cy_mqtt_event_t event, void *user_data )
{
    cy_mqtt_publish_info_t *received_msg;
    printf( "\nMQTT App callback with handle : %p \n", mqtt_handle );
    (void)user_data;
    switch( event.type )
    {
        case CY_MQTT_EVENT_TYPE_DISCONNECT :
            if( event.data.reason == CY_MQTT_DISCONN_TYPE_BROKER_DOWN )
            {
                printf( "\nCY_MQTT_DISCONN_TYPE_BROKER_DOWN .....\n" );
            }
            else
            {
                printf( "\nCY_MQTT_DISCONN_REASON_NETWORK_DISCONNECTION .....\n" );
            }
            break;
        case CY_MQTT_EVENT_TYPE_PUBLISH_RECEIVE :
            received_msg = &amp;(event.data.pub_msg.received_message);
            printf( "Incoming Publish Topic Name: %.*s\n", received_msg-&gt;topic_len, received_msg-&gt;topic );
            printf( "Incoming Publish message Packet Id is %u.\n", event.data.pub_msg.packet_id );
            printf( "Incoming Publish Message : %.*s.\n\n", ( int )received_msg-&gt;payload_len, ( const char * )received_msg-&gt;payload );
            if(memcmp(received_msg-&gt;topic, CLOUD_MQTT_TOPIC, strlen(CLOUD_MQTT_TOPIC)) == 0) /* Topic matches the motor speed topic */
            {
                    cy_JSON_parser(received_msg-&gt;payload, received_msg-&gt;payload_len);
            }
            
            break;
        default :
            printf( "\nUNKNOWN EVENT .....\n" );
            break;
    }
}</pre>
<p>If the JSON parser matches, you call the motor_update function with the new requested speed.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">/* This is the callback from the cy_JSON_parser function. It is called whenever
 * the parser finds a JSON object. */
static cy_rslt_t json_cb(cy_JSON_object_t *json_object, void *arg)
{
    int motorSpeed;

    if(memcmp(json_object-&gt;object_string, MOTOR_KEY, json_object-&gt;object_string_length) == 0)
    {
        if(json_object-&gt;value_type == JSON_NUMBER_TYPE)
        {
            /* Add null termination to the value and then convert to a number */
            char resultString[json_object-&gt;value_length + 1];
            memcpy(resultString, json_object-&gt;value, json_object-&gt;value_length);
            resultString[json_object-&gt;value_length] = 0;
            motorSpeed = (uint8_t) atoi(resultString);
            printf("Received speed value from cloud: %d\n", motorSpeed);
            motor_update(motorSpeed);
        }
    }
    return CY_RSLT_SUCCESS;
}
</pre>
<div>
<h3>8. Fix main.c to start the motor task</h3>
</div>
<p>In main.c you need to &#8220;do the needful&#8221; starting with an include.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">#include "motor_task.h"</pre>
<p>Then starting the motor task.</p>
<div>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">xTaskCreate(motor_task,    "Motor"     ,configMINIMAL_STACK_SIZE*8  , NULL, 1, 0);
</pre>
<h3>9. Test</h3>
<p><a href="https://iotexpert.com/ew21-lesson-6-motor-control/screen-shot-2021-02-23-at-3-48-46-pm/" rel="attachment wp-att-10959"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.48.46-PM-1024x584.jpg" alt="" width="1024" height="584" class="alignnone size-large wp-image-10959" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.48.46-PM-1024x584.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.48.46-PM-300x171.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.48.46-PM-768x438.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.48.46-PM-1536x877.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.48.46-PM-600x342.jpg 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-3.48.46-PM.jpg 2022w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>Resources for Project</h1>
<p>You can find the completed project in your project creator dialog by filtering for &#8220;IoT Expert Embedded&#8221;.  This is lesson6</p>
<p><a href="https://iotexpert.com/ew21-lesson-1-freertos-capsense/screen-shot-2021-02-22-at-4-34-40-pm/" rel="attachment wp-att-10815"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.34.40-PM-1024x581.png" alt="" width="1024" height="581" class="alignnone size-large wp-image-10815" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.34.40-PM-1024x581.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.34.40-PM-300x170.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.34.40-PM-768x436.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.34.40-PM-1536x872.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.34.40-PM-2048x1163.png 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-22-at-4.34.40-PM-600x341.png 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>You can also clone this project at git@github.com:iotexpert/ew21-lesson6.git or https://github.com/iotexpert/ew21-lesson6</p>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/ew21-lesson-6-motor-control/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>EW21: Lesson 7: WS2812 LED Strip</title>
		<link>https://iotexpert.com/ew21-lesson-7-ws2812-led-strip/</link>
					<comments>https://iotexpert.com/ew21-lesson-7-ws2812-led-strip/#comments</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Wed, 24 Feb 2021 15:21:20 +0000</pubDate>
				<category><![CDATA[Embedded World 2021]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=10831</guid>

					<description><![CDATA[Summary In lesson 7 we will finish this Frankenstein drone setup by adding WS2812 Strip LEDs.  At the end of lesson one you will have the &#8220;WS2812 LED&#8221; block colored green.  Here is the architecture: Learning Objectives Have fun by adding another cool library &#8211; WS2812 Procedure Create a new project Add the IoT Expert [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><span><h1>Embedded World 2021 - Infineon ModusToolbox PSoC 6 Drone </h1>
<p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >#</th>
<th >Description</th>
</tr>
</thead>
<tbody>
<tr><td >0</td>
<td ><a href="https://iotexpert.com/ew21-lesson-0-introduction-resources/" target="_blank" rel="noopener">Introduction &amp; Resources</a></td>
</tr>

<tr><td >1</td>
<td ><a href="https://iotexpert.com/ew21-lesson-1-freertos-capsense/" target="_blank" rel="noopener">FreeRTOS &amp; CapSense</a></td>
</tr>

<tr><td >2</td>
<td ><a href="https://iotexpert.com/ew21-lesson-2-joystick/" target="_blank" rel="noopener">3-D Magnetic Sensing XENSIV Joystick</a></td>
</tr>

<tr><td >3</td>
<td ><a href="https://iotexpert.com/ew21-lesson-3-wifi/" target="_blank" rel="noopener">WiFi</a></td>
</tr>

<tr><td >4</td>
<td ><a href="https://iotexpert.com/ew21-lesson-4-mqtt/" target="_blank" rel="noopener">MQTT</a></td>
</tr>

<tr><td >5</td>
<td ><a href="https://iotexpert.com/ew21-lesson-5-low-power/" target="_blank" rel="noopener">Low Power</a></td>
</tr>

<tr><td >6</td>
<td ><a href="https://iotexpert.com/ew21-lesson-6-motor-control/" target="_blank" rel="noopener">BLDC Motor Control</a></td>
</tr>

<tr><td >7</td>
<td ><a href="https://iotexpert.com/ew21-lesson-7-ws2812-led-strip/" target="_blank" rel="noopener">WS2812 Strip LEDs</a></td>
</tr>
</tbody></table></div></p>
<p>&nbsp;</p></span></p>
<h1>Summary</h1>
<p>In lesson 7 we will finish this Frankenstein drone setup by adding WS2812 Strip LEDs.  At the end of lesson one you will have the &#8220;WS2812 LED&#8221; block colored green.  Here is the architecture:</p>
<p><a href="https://iotexpert.com/ew21-lesson-7-ws2812-led-strip/l7-arch/" rel="attachment wp-att-11046"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/l7-arch-1024x433.png" alt="" width="1024" height="433" class="alignnone size-large wp-image-11046" srcset="https://iotexpert.com/wp-content/uploads/2021/02/l7-arch-1024x433.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/l7-arch-300x127.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/l7-arch-768x324.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/l7-arch-1536x649.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/l7-arch-600x253.png 600w, https://iotexpert.com/wp-content/uploads/2021/02/l7-arch.png 1631w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>Learning Objectives</h1>
<ol>
<li>Have fun by adding another cool library &#8211; WS2812</li>
</ol>
<h1>Procedure</h1>
<ol>
<li>Create a new project</li>
<li>Add the IoT Expert WS2812 Library</li>
<li>Modify motor_task.c</li>
<li>Test</li>
</ol>
<h3>1. Create a new project</h3>
<p>Start from the CY8CKIT-062S2-43012</p>
<p><a href="https://iotexpert.com/ew21-lesson-7-ws2812-led-strip/screen-shot-2021-02-23-at-6-01-36-pm/" rel="attachment wp-att-10992"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.01.36-PM-1024x708.jpg" alt="" width="1024" height="708" class="alignnone size-large wp-image-10992" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.01.36-PM-1024x708.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.01.36-PM-300x207.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.01.36-PM-768x531.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.01.36-PM-1536x1062.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.01.36-PM-2048x1416.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.01.36-PM-600x415.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Give the project a sensible name.  In this case IoT_Expert_Embedded_World_2021_Lesson7</p>
<p><a href="https://iotexpert.com/ew21-lesson-7-ws2812-led-strip/screen-shot-2021-02-23-at-6-02-10-pm/" rel="attachment wp-att-10990"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.02.10-PM-1024x711.jpg" alt="" width="1024" height="711" class="alignnone size-large wp-image-10990" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.02.10-PM-1024x711.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.02.10-PM-300x208.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.02.10-PM-768x533.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.02.10-PM-1536x1066.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.02.10-PM-2048x1422.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.02.10-PM-600x417.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h3>2. Add the IoT Expert WS2812 Library</h3>
<p>You need to find the IoT Expert WS2812 library and include it into your project.</p>
<p><a href="https://iotexpert.com/ew21-lesson-7-ws2812-led-strip/screen-shot-2021-02-23-at-6-03-31-pm/" rel="attachment wp-att-10991"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.03.31-PM-937x1024.jpg" alt="" width="937" height="1024" class="alignnone size-large wp-image-10991" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.03.31-PM-937x1024.jpg 937w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.03.31-PM-275x300.jpg 275w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.03.31-PM-768x839.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.03.31-PM-600x656.jpg 600w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.03.31-PM.jpg 1142w" sizes="(max-width: 937px) 100vw, 937px" /></a></p>
<h3>3. Modify motor_task.c</h3>
<p>Include the header file for the library.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">#include "ws2812.h"</pre>
<p>The number of LEDs in our system</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">#define		NUM_LEDS				(61)</pre>
<p>Define some colors to use and initialize the LED strip</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">/* LED color array - 7 different colors each with RGB values */
uint8_t ledColors[7][3] = {
        { 0,  0,  0},	// Off
        {20,  0, 30},	// Violet
        { 0,  0, 50},	// Blue
        { 0, 50,  0},	// Green
        {30, 20,  0},	// Yellow
        {42,  8,  0},	// Orange
        {50,  0,  0},	// Red
};

 uint8_t ledColorRow = 0;
 uint8_t ledColorRowPrev = 0;
/* Initialize LED strips */
ws2812_init(NUM_LEDS, P10_0, P10_1, P10_2);
</pre>
<p>A bit of code to send updates to the LED strip based on the status of the motor.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">/* Calculate LED color and update if it has changed */
            if(motorState == false)
            {
                /* Turn off LEDs */
                ws2812_setMultiRGB(0, NUM_LEDS-1, 0, 0, 0);
                ws2812_update();
                ledColorRowPrev = 0;
            }
            else
            {
                ledColorRow = 1 + (uint8_t)((( (uint16_t)motorSpeed - (uint16_t)RPM_MIN ) * 5) / ((uint16_t)RPM_MAX - (uint16_t)RPM_MIN)); /* Determine row to use */
                if(ledColorRowPrev != ledColorRow)
                {
                    ws2812_setMultiRGB(0, NUM_LEDS-1, ledColors[ledColorRow][0], ledColors[ledColorRow][1], ledColors[ledColorRow][2]);
                    ws2812_update();
                    ledColorRowPrev = ledColorRow;
                }
            }</pre>
<h3>4. Test</h3>
<p>Let it rip tater chip</p>
<p><a href="https://iotexpert.com/ew21-lesson-7-ws2812-led-strip/img_0492/" rel="attachment wp-att-10995"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0492-1024x674.jpg" alt="" width="1024" height="674" class="alignnone size-large wp-image-10995" srcset="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0492-1024x674.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0492-300x198.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0492-768x506.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0492-1536x1012.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0492-600x395.jpg 600w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0492.jpg 1998w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Here it is with the LED strips on&#8230;</p>
<p><a href="https://iotexpert.com/ew21-lesson-7-ws2812-led-strip/img_0491/" rel="attachment wp-att-10994"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0491-1024x947.jpg" alt="" width="1024" height="947" class="alignnone size-large wp-image-10994" srcset="https://iotexpert.com/wp-content/uploads/2021/02/IMG_0491-1024x947.jpg 1024w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0491-300x277.jpg 300w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0491-768x710.jpg 768w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0491-1536x1420.jpg 1536w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0491-2048x1894.jpg 2048w, https://iotexpert.com/wp-content/uploads/2021/02/IMG_0491-600x555.jpg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>Resources for Project</h1>
<p>You can find the completed project in your project creator dialog by filtering for &#8220;IoT Expert Embedded&#8221;.  This is lesson 7</p>
<p><a href="https://iotexpert.com/ew21-lesson-7-ws2812-led-strip/screen-shot-2021-02-23-at-6-23-45-pm/" rel="attachment wp-att-10996"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.23.45-PM-1024x491.png" alt="" width="1024" height="491" class="alignnone size-large wp-image-10996" srcset="https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.23.45-PM-1024x491.png 1024w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.23.45-PM-300x144.png 300w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.23.45-PM-768x369.png 768w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.23.45-PM-1536x737.png 1536w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.23.45-PM-2048x983.png 2048w, https://iotexpert.com/wp-content/uploads/2021/02/Screen-Shot-2021-02-23-at-6.23.45-PM-600x288.png 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></p>
<p>You can also clone this project at git@github.com:iotexpert/ew21-lesson2.git or https://github.com/iotexpert/ew21-lesson2</p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/ew21-lesson-7-ws2812-led-strip/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
