tag:blogger.com,1999:blog-15333811186077808652024-03-18T20:38:55.353-07:00Thinking In 16 BitsthinkingIn16Bitshttp://www.blogger.com/profile/16782553204614961567noreply@blogger.comBlogger20125tag:blogger.com,1999:blog-1533381118607780865.post-54253625265583432782019-07-31T15:44:00.002-07:002019-07-31T15:56:58.440-07:00Using Resources to store images in a windows forms C# program<br />
<div class="MsoTitle">
</div>
<div class="MsoNormal">
It is useful to store the images used by a program inside the executable as resources. Visual studio offers an efficient way to do that.</div>
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
<a href="https://www.blogger.com/blogger.g?blogID=1533381118607780865" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="https://www.blogger.com/blogger.g?blogID=1533381118607780865" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="https://www.blogger.com/blogger.g?blogID=1533381118607780865" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="https://www.blogger.com/blogger.g?blogID=1533381118607780865" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="https://www.blogger.com/blogger.g?blogID=1533381118607780865" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="https://www.blogger.com/blogger.g?blogID=1533381118607780865" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><a href="https://www.blogger.com/blogger.g?blogID=1533381118607780865" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"></a><br /></div>
<div class="MsoNormal">
The method is very simple but I always forget how to do it. So, this is a very short tutorial.<o:p></o:p><br />
<br /></div>
<div class="MsoNormal">
Note: I use Visual studio 2017 but the procedure is similar with other versions.<o:p></o:p></div>
<h1 style="margin-left: .25in; mso-list: l0 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]--><span style="mso-bidi-font-family: "Calibri Light"; mso-bidi-theme-font: major-latin; mso-fareast-font-family: "Calibri Light"; mso-fareast-theme-font: major-latin;"><span style="mso-list: Ignore;">1.<span style="font: 7.0pt "Times New Roman";"> </span></span></span><!--[endif]-->Create the project<o:p></o:p></h1>
<div class="MsoNormal">
We use Visual studio to create a windows Forms App.<o:p></o:p><br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirGfko1go0jvIkObF5h_qjekCoBuZW9wfYbK3zmnbEa6tmeA3pNx1mf1SVTYu4cp9Yw9aESNJYLQLc4d9aH4jCGljnH401oqJAT7fiLI8ckLWp4qd3BIVFMw3GeFaDTENvlM8RUFQE9To/s1600/resimg1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="652" data-original-width="942" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirGfko1go0jvIkObF5h_qjekCoBuZW9wfYbK3zmnbEa6tmeA3pNx1mf1SVTYu4cp9Yw9aESNJYLQLc4d9aH4jCGljnH401oqJAT7fiLI8ckLWp4qd3BIVFMw3GeFaDTENvlM8RUFQE9To/s1600/resimg1.png" /></a></div>
<br /></div>
<div class="MsoNormal">
<span style="mso-no-proof: yes;"><!--[if gte vml 1]><v:shapetype
id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t"
path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"> <v:stroke joinstyle="miter"/> <v:formulas> <v:f eqn="if lineDrawn pixelLineWidth 0"/> <v:f eqn="sum @0 1 0"/> <v:f eqn="sum 0 0 @1"/> <v:f eqn="prod @2 1 2"/> <v:f eqn="prod @3 21600 pixelWidth"/> <v:f eqn="prod @3 21600 pixelHeight"/> <v:f eqn="sum @0 0 1"/> <v:f eqn="prod @6 1 2"/> <v:f eqn="prod @7 21600 pixelWidth"/> <v:f eqn="sum @8 21600 0"/> <v:f eqn="prod @7 21600 pixelHeight"/> <v:f eqn="sum @10 21600 0"/> </v:formulas> <v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/> <o:lock v:ext="edit" aspectratio="t"/> </v:shapetype><v:shape id="Image_x0020_1" o:spid="_x0000_i1029" type="#_x0000_t75"
style='width:451.5pt;height:312.75pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:/Users/pierr/AppData/Local/Temp/msohtmlclip1/01/clip_image001.png"
o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]--></span><o:p></o:p></div>
<h1 style="margin-left: .25in; mso-list: l0 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]--><span style="mso-bidi-font-family: "Calibri Light"; mso-bidi-theme-font: major-latin; mso-fareast-font-family: "Calibri Light"; mso-fareast-theme-font: major-latin;"><span style="mso-list: Ignore;">2.<span style="font: 7.0pt "Times New Roman";"> </span></span></span><!--[endif]-->Put the resource in the project<o:p></o:p></h1>
<div class="MsoNormal">
Open the <span style="color: red;">Resource.resx </span>file by double clicking on it. (Visual studio will open a specific editor)</div>
<div class="MsoNormal">
<span style="mso-no-proof: yes;"><!--[if gte vml 1]><v:shape
id="Image_x0020_2" o:spid="_x0000_i1028" type="#_x0000_t75" style='width:451.5pt;
height:164.25pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:/Users/pierr/AppData/Local/Temp/msohtmlclip1/01/clip_image003.png"
o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]--></span><o:p></o:p></div>
<div class="MsoNormal">
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihSzacmV_Ii2lpY0znMAvVn9DOO9pnLAMxPD7qUwEGtyvLFadU1WjlR0VpzH19JKnIx3UDE-AmomWXbnckfRi2sGtc49QNxYBLeKdGxgo62tVXk3_QxvNlDOaQo1yUkIzjNa8HEAYUfy0/s1600/resimg2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="462" data-original-width="1273" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihSzacmV_Ii2lpY0znMAvVn9DOO9pnLAMxPD7qUwEGtyvLFadU1WjlR0VpzH19JKnIx3UDE-AmomWXbnckfRi2sGtc49QNxYBLeKdGxgo62tVXk3_QxvNlDOaQo1yUkIzjNa8HEAYUfy0/s1600/resimg2.png" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://www.blogger.com/blogger.g?blogID=1533381118607780865" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://www.blogger.com/blogger.g?blogID=1533381118607780865" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://www.blogger.com/blogger.g?blogID=1533381118607780865" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://www.blogger.com/blogger.g?blogID=1533381118607780865" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://www.blogger.com/blogger.g?blogID=1533381118607780865" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://www.blogger.com/blogger.g?blogID=1533381118607780865" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://www.blogger.com/blogger.g?blogID=1533381118607780865" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"></a></div>
<br />
In the toolbar of this editor select <span style="color: red;">Add Resource </span>and select <span style="color: red;">“Add existing file” </span>then choose the desired image file (here I will use summer.bmp).<o:p></o:p><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNDuYF9klRtXI6txXmog_JweGQ8BRu5B8o_lsBYiawiQ1OblhlqxEOE-dMM93W96o2Mm8NqTd1TGcwTEjCn-RLMnTk7gJdJxRzVxNhJrwvJuRdFdD5VDs63GyGLkdcvbpRke4kdQPTjr8/s1600/resimg3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="217" data-original-width="669" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNDuYF9klRtXI6txXmog_JweGQ8BRu5B8o_lsBYiawiQ1OblhlqxEOE-dMM93W96o2Mm8NqTd1TGcwTEjCn-RLMnTk7gJdJxRzVxNhJrwvJuRdFdD5VDs63GyGLkdcvbpRke4kdQPTjr8/s1600/resimg3.png" /></a></div>
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
This will create a new resource containing the desired image<o:p></o:p><br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheWGj0UC2pgkUGV59SzmNLjryb_DLIHXxhYMUACXFIO7todDSHQaiZ6Lct2uRVn0iBjZGij7xlqxMG7gTViGcr2sJL93xAgAw62tsC5tI4qbSCdFSaF0x4LBSzOmeoQ72huNHwE1PamF4/s1600/resimg4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="261" data-original-width="687" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheWGj0UC2pgkUGV59SzmNLjryb_DLIHXxhYMUACXFIO7todDSHQaiZ6Lct2uRVn0iBjZGij7xlqxMG7gTViGcr2sJL93xAgAw62tsC5tI4qbSCdFSaF0x4LBSzOmeoQ72huNHwE1PamF4/s1600/resimg4.png" /></a></div>
<br /></div>
<div class="MsoNormal">
<div class="separator" style="clear: both; text-align: center;">
</div>
<span style="mso-no-proof: yes;"><!--[if gte vml 1]><v:shape
id="Image_x0020_5" o:spid="_x0000_i1026" type="#_x0000_t75" style='width:451.5pt;
height:171.75pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:/Users/pierr/AppData/Local/Temp/msohtmlclip1/01/clip_image007.png"
o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]--></span><o:p></o:p></div>
<h1 style="margin-left: .25in; mso-list: l0 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]--><span style="mso-bidi-font-family: "Calibri Light"; mso-bidi-theme-font: major-latin; mso-fareast-font-family: "Calibri Light"; mso-fareast-theme-font: major-latin;"><span style="mso-list: Ignore;">3.<span style="font: 7.0pt "Times New Roman";"> </span></span></span><!--[endif]-->Use the image<o:p></o:p></h1>
<div class="MsoNormal">
You can now use the image resource in the designer i.e. as the image property of a Picture box<o:p></o:p><br />
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<img border="0" data-original-height="841" data-original-width="1578" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjM1Kz_7E9QUbz8fMqcdbvOVz_1MajwNMzscFBVpYDRPR45h4AENXEhyphenhyphenzHw1Ft6EA_-eBZbXWBl2THApY26k55_2P3MmX86Qvadc3c9sX1aMv92HrazRGIN6XkGq7U11f_fAincaXiMvpo/s1600/resimg5.png" /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
But you can also access the image in the code by using <program_name>.Properties.Resources.<resourcename>.<o:p></o:p><br />
<br /></div>
<div class="MsoNormal">
See example below:<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div; padding: 1.0pt 4.0pt 1.0pt 4.0pt;">
<div class="MsoNormal" style="border: none; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;">
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">namespace</span><span style="color: black; font-family: "consolas"; font-size: 9.5pt;"> image_in_ressource<o:p></o:p></span></div>
<div class="MsoNormal" style="border: none; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 9.5pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="border: none; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">public</span><span style="color: black; font-family: "consolas"; font-size: 9.5pt;"> </span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">partial</span><span style="color: black; font-family: "consolas"; font-size: 9.5pt;"> </span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">class</span><span style="color: black; font-family: "consolas"; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: "consolas"; font-size: 9.5pt;">Form1</span><span style="color: black; font-family: "consolas"; font-size: 9.5pt;"> : </span><span style="color: #2b91af; font-family: "consolas"; font-size: 9.5pt;">Form</span><span style="color: black; font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="border: none; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div>
<div class="MsoNormal" style="border: none; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">private</span><span style="color: black; font-family: "consolas"; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: "consolas"; font-size: 9.5pt;">Image</span><span style="color: black; font-family: "consolas"; font-size: 9.5pt;"> summerImage;<o:p></o:p></span></div>
<div class="MsoNormal" style="border: none; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">public</span><span style="color: black; font-family: "consolas"; font-size: 9.5pt;"> Form1()<o:p></o:p></span></div>
<div class="MsoNormal" style="border: none; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div>
<div class="MsoNormal" style="border: none; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span>InitializeComponent();<o:p></o:p></span></div>
<div class="MsoNormal" style="border: none; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span>summerImage = </span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">new</span><span style="color: black; font-family: "consolas"; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: "consolas"; font-size: 9.5pt;">Bitmap</span><span style="color: black; font-family: "consolas"; font-size: 9.5pt;">(image_in_ressource.Properties.</span><span style="color: #2b91af; font-family: "consolas"; font-size: 9.5pt;">Resources</span><span style="color: black; font-family: "consolas"; font-size: 9.5pt;">.summer);<o:p></o:p></span></div>
<div class="MsoNormal" style="border: none; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNormal" style="border: none; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="border: none; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">private</span><span style="color: black; font-family: "consolas"; font-size: 9.5pt;"> </span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">void</span><span style="color: black; font-family: "consolas"; font-size: 9.5pt;"> Form1_Paint(</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">object</span><span style="color: black; font-family: "consolas"; font-size: 9.5pt;"> sender, </span><span style="color: #2b91af; font-family: "consolas"; font-size: 9.5pt;">PaintEventArgs</span><span style="color: black; font-family: "consolas"; font-size: 9.5pt;"> e)<o:p></o:p></span></div>
<div class="MsoNormal" style="border: none; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div>
<div class="MsoNormal" style="border: none; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span>e.Graphics.DrawImageUnscaled(summerImage, </span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">new</span><span style="color: black; font-family: "consolas"; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: "consolas"; font-size: 9.5pt;">Point</span><span style="color: black; font-family: "consolas"; font-size: 9.5pt;">(0, 0));<o:p></o:p></span></div>
<div class="MsoNormal" style="border: none; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNormal" style="border: none; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 9.5pt;"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<div class="MsoNormal" style="border: none; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-border-alt: solid windowtext .5pt; mso-layout-grid-align: none; mso-padding-alt: 1.0pt 4.0pt 1.0pt 4.0pt; padding: 0in; text-autospace: none;">
<span style="color: black; font-family: "consolas"; font-size: 9.5pt;">}<o:p></o:p></span></div>
</div>
<div class="MsoNormal">
<br /></div>
<br />thinkingIn16Bitshttp://www.blogger.com/profile/16782553204614961567noreply@blogger.com1tag:blogger.com,1999:blog-1533381118607780865.post-69980782784619534862019-05-14T15:05:00.001-07:002019-05-14T15:05:13.281-07:00<br />
<h2>
<span style="font-size: x-large;">Making a feeder for Märklin M Tracks</span></h2>
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Even if Märklin M tracks are not manufactured anymore, it is very easy to find a lot of them online and since they are obsolete, they are often quite cheap.<o:p></o:p></div>
<div class="MsoNormal">
<br />
But it is sometimes more problematic to find feeder tracks. So, let’s build our own.<o:p></o:p><br />
<br /></div>
<div class="MsoNormal">
<span style="mso-no-proof: yes;"><!--[if gte vml 1]><v:shapetype
id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t"
path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"> <v:stroke joinstyle="miter"/> <v:formulas> <v:f eqn="if lineDrawn pixelLineWidth 0"/> <v:f eqn="sum @0 1 0"/> <v:f eqn="sum 0 0 @1"/> <v:f eqn="prod @2 1 2"/> <v:f eqn="prod @3 21600 pixelWidth"/> <v:f eqn="prod @3 21600 pixelHeight"/> <v:f eqn="sum @0 0 1"/> <v:f eqn="prod @6 1 2"/> <v:f eqn="prod @7 21600 pixelWidth"/> <v:f eqn="sum @8 21600 0"/> <v:f eqn="prod @7 21600 pixelHeight"/> <v:f eqn="sum @10 21600 0"/> </v:formulas> <v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/> <o:lock v:ext="edit" aspectratio="t"/> </v:shapetype><v:shape id="Image_x0020_1" o:spid="_x0000_i1029" type="#_x0000_t75"
style='width:451.5pt;height:240.75pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:/Users/pierr/AppData/Local/Temp/msohtmlclip1/01/clip_image001.jpg"
o:title="" cropbottom="18906f"/> </v:shape><![endif]--><!--[if !vml]--><img height="321" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxKwSuipf9xcu9Yggk8RxvXuxlCpEgPAj3PhajYqM5xo6skcyUnjtG4bsPGyj7xp6B2isEtFDOpDXFLOhkKm4tBosLDLO8fgGqudeymLllPXWxwHlX3iXaaSAwigcdt3nQ3fcXmbzIgkE/s320/track1.PNG" v:shapes="Image_x0020_1" width="602" /><!--[endif]--></span><o:p></o:p></div>
<div class="MsoNormal">
<br />
We will use the very common 5106 straight M track.<o:p></o:p></div>
<div class="MsoNormal">
We will solder the wires at the indicated places.<o:p></o:p><br />
<br /></div>
<div class="MsoNormal">
<span style="mso-no-proof: yes;"><!--[if gte vml 1]><v:shape
id="Image_x0020_3" o:spid="_x0000_i1028" type="#_x0000_t75" style='width:450pt;
height:181.5pt;visibility:visible;mso-wrap-style:square'> </v:shape><![endif]--><!--[if !vml]--><img height="242" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHCY5qMOKwiz00o9IJE3yluA80HMYKuxSrwBWQWs-SZHKXlGwxMonh0K_kbeVw80hrnyGAK5WB1xMWAKOMqEirjgNJN5WTzinjCUBZeHyLvcGP7nQO8IOX-Q_KO76xcPCINnlLyOoxPWE/s320/track2.PNG" v:shapes="Image_x0020_3" width="600" /><!--[endif]--></span><o:p></o:p><br />
<span style="mso-no-proof: yes;"><br /></span></div>
<div class="MsoNormal">
<br />
Before soldering the wires, we must use a small knife (I have used the blade a small flat screwdriver) to scratch the paint and the oxide.<o:p></o:p></div>
<div class="MsoNormal">
<br />
To let the wires go out it is easy to drill a small hole on the metallic side of the track.<o:p></o:p><br />
<br /></div>
<div class="MsoNormal">
<div class="separator" style="clear: both; text-align: center;">
<span style="margin-left: 1em; margin-right: 1em;"><!--[if gte vml 1]><v:shape
id="Image_x0020_4" o:spid="_x0000_i1027" type="#_x0000_t75" style='width:181.5pt;
height:212.25pt;rotation:90;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:/Users/pierr/AppData/Local/Temp/msohtmlclip1/01/clip_image005.jpg"
o:title="" cropright="16333f"/> </v:shape><![endif]--><!--[if !vml]--><img height="547" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiv-K95hGaQtSzW0svDrPQzy1R_aGVNvdpak7okGPXjjxlzNHbyjk8Fbmj8jurjspbxBqTZu7TZxc0F6PyruAFRuhCHXqVoEQ4aLLTN9JeLcqOs69bhz765oVcQVJ0YsdQVoXWhfm4TJ60/s640/track3.PNG" v:shapes="Image_x0020_4" width="640" /><!--[endif]--></span></div>
<o:p></o:p></div>
<div class="MsoNormal">
<br />
The metal is not hard at all to drill<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Once everything is finished don’t forget to make a knot in the wires to prevent excessive constrains on the solders<o:p></o:p></div>
<div class="MsoNormal">
<br />
And here it is, just as good as the original much harder to find 5111, ready to provide power to all your trains.<o:p></o:p><br />
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="mso-no-proof: yes;"><!--[if gte vml 1]><v:shape
id="Image_x0020_6" o:spid="_x0000_i1026" type="#_x0000_t75" style='width:227.25pt;
height:171pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:/Users/pierr/AppData/Local/Temp/msohtmlclip1/01/clip_image007.jpg"
o:title=""/> </v:shape><![endif]--><!--[if !vml]--><img height="228" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcZ-2OVf1hZei23bp6PhhV_lv8qdtdHUTbaSX_y4Cz7zRp3I5dvnkGrPKDEbKDAaNMPdl6CvDdrA1VGGf2eBXPUtMgIuYDsVhRuOof9V5OTfYE3wrjc1e6K1aXdRtf7rKszuPDSPREwMo/s320/track5.PNG" v:shapes="Image_x0020_6" width="303" /> <!--[endif]--><!--[if gte vml 1]><v:shape id="Image_x0020_5"
o:spid="_x0000_i1025" type="#_x0000_t75" style='width:226.5pt;height:169.5pt;
visibility:visible;mso-wrap-style:square'> <v:imagedata
o:title=""/> </v:shape><![endif]--><!--[if !vml]--><img height="226" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJJLuEBsweueJdU97N6Twty_FtU2fzvUQ_nuo7fmIaPhfMV3XSKg8NZHTZspz2mLrPQrlLRb0hzOuaaNtBBkjcYPrf6u1j6KlyKuG6NlGpHtEcaeFYvV_82p1owkiOv4I6yZfDL56CyXk/s320/track4.PNG" v:shapes="Image_x0020_5" width="302" /><!--[endif]--></span><o:p></o:p></div>
<br />
<br />
<div class="MsoNormal" style="-webkit-text-stroke-width: 0px; color: black; font-family: "Times New Roman"; font-size: medium; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
</div>
<br />
<div class="MsoNormal" style="-webkit-text-stroke-width: 0px; color: black; font-family: "Times New Roman"; font-size: medium; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<div style="margin: 0px;">
Thank you to my father who shown mehow to do that in 1979.<o:p></o:p></div>
</div>
thinkingIn16Bitshttp://www.blogger.com/profile/16782553204614961567noreply@blogger.com0tag:blogger.com,1999:blog-1533381118607780865.post-33295514597238282562018-06-10T15:03:00.003-07:002018-06-10T15:30:27.253-07:00Scrolling Text On LCD with Arduino<h2>
Introduction</h2>
<div>
<div class="MsoNormal">
We want to program the Arduino so that it will scroll (possibly very long) text acroos an LCD screen.<o:p></o:p></div>
<div class="MsoNormal">
The text shall be sent to the Arduino via the serial port<o:p></o:p></div>
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDPujMu1CZamgmCOO5Fx9g2FaeKWTf0F2r1KeJn-TwR4UOAw8zMY8ay4Uml1L6vjZsW3QweQCU4-whdHMIBWXcx3TsCck_K1zOSA8e6RvRtBSw6opeCMsAYoWOwr3gmbtuXdr8LqRk5Hc/s1600/lcd_Principle.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="234" data-original-width="966" height="153" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDPujMu1CZamgmCOO5Fx9g2FaeKWTf0F2r1KeJn-TwR4UOAw8zMY8ay4Uml1L6vjZsW3QweQCU4-whdHMIBWXcx3TsCck_K1zOSA8e6RvRtBSw6opeCMsAYoWOwr3gmbtuXdr8LqRk5Hc/s640/lcd_Principle.PNG" width="640" /></a></div>
<div>
<div class="MsoNormal">
The text transmitted by the PC via the USB link is stored in the Arduino Memory and displayed as a scrolling text on the LCD display.<o:p></o:p></div>
<div class="MsoNormal">
The major risk is to lose data in case of very long text since the Arduino internal serial port buffer is limited to 64 bytes<o:p></o:p></div>
</div>
<h2>
The Hardware</h2>
<div>
<div class="MsoNormal">
The hardware is the classical Interfacing of an Arduino UNO with a 2x16 HD44780 LCD module. Note that for the module I did use did include a current limiting resistor in the circuit backlight. This may not be the case for your module. So be careful. You may destroy the module if you don’t include an external resistance on a module that has no internal limiting resistance. <span style="mso-spacerun: yes;"> </span>(see <a href="https://electronics.stackexchange.com/questions/212197/is-it-necessary-to-use-resistor-when-connecting-backlight-of-16x2-lcd-display">https://electronics.stackexchange.com/questions/212197/is-it-necessary-to-use-resistor-when-connecting-backlight-of-16x2-lcd-display</a> for details).<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
For the NPN transistor. I did use a BC547 but any similar transistor (BC108, 2N222,…) may be used instead.<o:p></o:p></div>
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1_epcgpWYZ3H8r_COS3hegjXCwpD3HR0TKFVXZ82IQikdgbO45Xrijq1STl6YJ4Yyq0p6B9W8JQyDlEbe3h8qtRdFk0UE9WDioL1nyKCBuxDv7gzjPav16OQJruj3pUG0_rd3B8CwhX0/s1600/circuit.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1480" data-original-width="1012" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1_epcgpWYZ3H8r_COS3hegjXCwpD3HR0TKFVXZ82IQikdgbO45Xrijq1STl6YJ4Yyq0p6B9W8JQyDlEbe3h8qtRdFk0UE9WDioL1nyKCBuxDv7gzjPav16OQJruj3pUG0_rd3B8CwhX0/s640/circuit.png" width="436" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<h2 style="clear: both; text-align: left;">
The software</h2>
<div>
<div class="MsoNormal">
The software is made of 2 parts:<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<h3>
The display part</h3>
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
The display part builds a 16 characters string containing the part of the buffer to print (if needed padded with white spaces) and display it with a lcd.print command. This has the advantage of not disturbing the other lines of the display.<o:p></o:p></div>
<div class="MsoNormal">
Since the Arduino serial port input buffer is very small (64 bytes), the display routine is immediately stopped once bytes are received in the serial port input buffer. (note: the process could probably be optimized using interrupts but tests did show the program was working correctly without using interrupts<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<h3>
The communication Part</h3>
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
This routine simply fills a large (256 bytes) buffer with the data received on the serial port using the method Serial.readBytesUntil('\n',buffer,256);<o:p></o:p></div>
<div class="MsoNormal">
The handshaking is done via an XON XOFF mechanism. <o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<h3>
Full listing</h3>
<div class="MsoNormal">
<o:p></o:p></div>
</div>
<div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">/*<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>LCD Serial ScrollPrint<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<pre id="license-text" style="background-color: white; border-radius: 3px; border: 1px solid rgb(238, 238, 238); color: #5c5855; overflow: auto; padding: 20px;"><span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"><b>MIT License
Copyright (c) 2018 Pierre Poliakoff
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.</b></span></pre>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>*/<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">// include the library code:<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">#include <LiquidCrystal.h><o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">//declare the hardware<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">LiquidCrystal lcd(2, 3, 4, 5, 6, 7);<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">int pinBacklight=9;<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">//const<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">//=====<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">const byte XOFF=19;<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">const byte XON=17;<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">//variables<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">//=========<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">char buffer[256];<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">void LcdPrintAndScroll(char *buffer,int len)<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">{<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">int offset =-16;<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">String screen="<span style="mso-spacerun: yes;"> </span>"; //16 chars buffer string<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">while(Serial.available()==0)<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>lcd.setCursor(0,0);<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>offset++;<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>if(offset>len)<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>offset=-16;<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>for (int i=0; i <16 && Serial.available()==0 ;i++)<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>if((i+offset<len)&&(i+offset>=0)&&buffer[i+offset]>31)<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>screen[i]=buffer[i+offset];<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>else<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>{ <o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>screen[i]=' ';<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>lcd.print(screen);<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>unsigned long now=millis();<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>while(millis()-now<250 && Serial.available()==0)<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>//do nothing<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">}<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">void setup() {<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>// initialize Hardware<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>pinMode(pinBacklight,OUTPUT);<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>digitalWrite(pinBacklight,HIGH);<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>Serial.begin(9600);<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>// set up the LCD's number of columns and rows:<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>lcd.begin(16, 2);<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>lcd.print("Waiting for Data");<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>lcd.setCursor(0,1);<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>lcd.print("Scroll Text Demonstration");<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">}<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">//===========================================<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">void loop() {<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">int len;<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">// receive data<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">while (Serial.available()==0)<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>//Do nothing<span style="mso-spacerun: yes;"> </span><o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">len=Serial.readBytesUntil('\n',buffer,256);<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">Serial.write(XOFF); // pause the transmission<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">Serial.flush();<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">// insert herre any long computation on Buffer<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">Serial.write(XON);//reactivate the transmission<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">//Print Data<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">if (len>0)<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>LcdPrintAndScroll(buffer,len);<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></span></b></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: .0001pt; margin-bottom: 0in;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "courier new"; line-height: 107%;"><span style="font-size: x-small;">}<o:p></o:p></span></span></b></div>
<div class="MsoNormal">
<br /></div>
<h2>
Sending Data from the PC</h2>
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
We do not want to write a specific software on the PC to send the data. We simply use the Windows Command line features:<o:p></o:p></div>
<div class="MsoNormal">
On my PC the Arduino is visible as COM4 (check on you PC for the exact value)<o:p></o:p></div>
<div class="MsoNormal">
We configure the com port communication via the following command<o:p></o:p></div>
<div align="center" class="MsoNormal" style="text-align: center;">
<b><span style="font-family: "courier new";"><br />
</span></b></div>
<h3 style="text-align: center;">
<b><span style="font-family: "courier new";">mode COM4 BAUD=9600 xon=on data=8</span></b></h3>
<div align="center" class="MsoNormal" style="text-align: center;">
<b><span style="font-family: "courier new";"><br />
</span></b></div>
<div class="MsoNormal">
Note that each time you upload a new firmware version in the Arduino, you must reconfigure the com port with the above command<o:p></o:p></div>
<div class="MsoNormal">
Then you can send the data to display via a simple copy command<o:p></o:p></div>
<h3 style="text-align: center;">
<b><span style="font-family: "courier new";">copy mydata.txt com4:</span></b></h3>
<div class="MsoNormal">
if you prefer to enter the data directly with the keyboard, you can use<o:p></o:p></div>
<h3 style="text-align: center;">
<b><span style="font-family: "courier new";">copy con: com4:</span></b></h3>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
Press enter to display the text on the Arduino and CTRL-Z to exit.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAIt1zIGORKV15N1tIpBf5h43dbJpDZEMwIFgwAHpSngFhvwPJJFOrdz9wtzHM79QUH_1qfBwyyJKizTJE3oVziC4ODq7HUFr5iYO5RMp_wltGj_GcebepZAwMroTixAcgbzHPJDY3Nbk/s1600/cmd.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="581" data-original-width="1264" height="294" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAIt1zIGORKV15N1tIpBf5h43dbJpDZEMwIFgwAHpSngFhvwPJJFOrdz9wtzHM79QUH_1qfBwyyJKizTJE3oVziC4ODq7HUFr5iYO5RMp_wltGj_GcebepZAwMroTixAcgbzHPJDY3Nbk/s640/cmd.PNG" width="640" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<h2>
The Final Result</h2>
</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<iframe allowfullscreen="" class="YOUTUBE-iframe-video" data-thumbnail-src="https://i.ytimg.com/vi/6SVPFMVbfbc/0.jpg" frameborder="0" height="266" src="https://www.youtube.com/embed/6SVPFMVbfbc?feature=player_embedded" width="320"></iframe><br />
<div>
<br /></div>
thinkingIn16Bitshttp://www.blogger.com/profile/16782553204614961567noreply@blogger.com0tag:blogger.com,1999:blog-1533381118607780865.post-20565014495134050442018-04-01T10:13:00.001-07:002018-04-01T10:13:08.279-07:00TTL Logic families compatibility<h2>
Logic families compatibility</h2>
<h3>
Introduction</h3>
<div>
A few year ago, the logic gates were all using 5V and everything was clear. But today (2018) we see more and more 3.3V logic. The Raspberry PI, the Arduino M0, the Digilent Basys3, the Wemos D1 Mini have all 3.3V inputs But the classical Arduino UNO has 5V logic ports.</div>
<div>
<br /></div>
<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHlkOSpiO2LS63ZdoIzWCI2yMPi0_zEgaflvZ9zw4aFxMhK5Gq3bzmWDf_frofhGFAmjFF0_li8LOu5f_csgrUQYxW_fgZMZdpKLgeJwqFgB-Ri9ffj3QHzz6k_-tvX5tmStRXC82K1wE/s1600/20180401_175319.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="900" data-original-width="1600" height="180" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHlkOSpiO2LS63ZdoIzWCI2yMPi0_zEgaflvZ9zw4aFxMhK5Gq3bzmWDf_frofhGFAmjFF0_li8LOu5f_csgrUQYxW_fgZMZdpKLgeJwqFgB-Ri9ffj3QHzz6k_-tvX5tmStRXC82K1wE/s320/20180401_175319.jpg" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
This WEMOS D1 MINI PRO is has 3.3V ports but the Arduino MEGA ADK has 5V ports</div>
</div>
<div>
<br /></div>
<div>
This means that when you are designing a circuit, you have to take care of the logic level you are using and when needed use level shifters that will convert the logic signal to the correct level.</div>
<div>
<br /></div>
<h3>
Logic families</h3>
<div>
There are quite a few digital circuits families. The most common are the 74HCxxx, the 74HCTxxx and the very old 74LSxxx but there are many others.</div>
<div>
<br /></div>
<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXFRPxaVBgQWyk62t_CEd0yVyFwpdEcOGiQqMmlxH8RaAaOTPbhtG0PE9XVnoxP1uts2GRPMyrJyrglGzRPTwcuSjQXRFQpu_Ap3c_5RY9-TZu-iXga2MrsQfYhUaOt_ylfzhpfa-mOAo/s1600/20180401_175341.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="900" data-original-width="1600" height="180" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXFRPxaVBgQWyk62t_CEd0yVyFwpdEcOGiQqMmlxH8RaAaOTPbhtG0PE9XVnoxP1uts2GRPMyrJyrglGzRPTwcuSjQXRFQpu_Ap3c_5RY9-TZu-iXga2MrsQfYhUaOt_ylfzhpfa-mOAo/s320/20180401_175341.jpg" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
The input level determine what voltage range is acceptable for a HIGH level and what voltage level is acceptable for a LOW level</div>
<div>
<br /></div>
<div>
For a 74HCT00 input, the LOW level is associated to a voltage between 0V and 0.8V and a HIGH level is associated to a voltage between 2V and 5V.</div>
<div>
<br /></div>
<div>
This means that voltage below 0V or above 5 V may damage the chip and any voltage between 0.8V and 2V is not a well defined logic signal.</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXrQAeY_sFDmyp3NrKthLxHsY9c_6hF7IYYjRm2Hcb5pYVs7y7BA-_cQNtX7P4uRtetDIRwdTsOAUPtpcsaJUSFOWQSY5EPtjKE-c8MlBAW1l9a4-bOAjGZ_w-O4kCXTqD1n2eYhCG7FU/s1600/74HCT+Voltage.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="379" data-original-width="271" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXrQAeY_sFDmyp3NrKthLxHsY9c_6hF7IYYjRm2Hcb5pYVs7y7BA-_cQNtX7P4uRtetDIRwdTsOAUPtpcsaJUSFOWQSY5EPtjKE-c8MlBAW1l9a4-bOAjGZ_w-O4kCXTqD1n2eYhCG7FU/s320/74HCT+Voltage.png" width="228" /></a></div>
<div>
<br /></div>
<div>
To know if the output of a gate is compatible with the 74HCT family we must know if the gate output level fall within the acceptable values. However, this is not as simple as one would expect as the gate output voltage is dependent on the gate power supply voltage (i.e. the VCC value) and the current that the gate provide (the more current is drawn from the gate the lower the HIGH voltage shall become).</div>
<div>
<br /></div>
<div>
If we take a <a href="http://www.ti.com/lit/ds/symlink/sn74alvc00.pdf" target="_blank">74ALVC00</a> with VCC = 2.7V and an output current of 12mA we have the HIGH voltage = 2.2V and a LOW output voltage of 0.4V.</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div>
We see that the the 74ALVC00 output voltage HIGH (2.2V in the selected conditions) fits inside the 74HCT00 High voltage input range (between 2 and 5V) and that the 74ALVC00 output voltage LOW (0.4V in the selected conditions) fits inside the 74HCT00 LOW voltage input range (between 0 and 0.8V)</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxxhAUg2UX3gKP1oTSLKYkiUJOjJoT05Zz6QLg9B8euB8zKK7INhOOobQphrBd44zypxJhZdrCEvXMqDVHlULqMJTFMSUgMkSR4hbwPfRjDbzIqRQEeG2eYXdcM5O-Qt8tdlSDLfga9Cg/s1600/74HCT+Voltage2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" data-original-height="379" data-original-width="372" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxxhAUg2UX3gKP1oTSLKYkiUJOjJoT05Zz6QLg9B8euB8zKK7INhOOobQphrBd44zypxJhZdrCEvXMqDVHlULqMJTFMSUgMkSR4hbwPfRjDbzIqRQEeG2eYXdcM5O-Qt8tdlSDLfga9Cg/s320/74HCT+Voltage2.png" width="314" /></a></div>
<div>
</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
So Yes a 74ALVC00 with VCC2.7V can drive a 74HCT00 wit VCC=5V</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOEaWvGCK3RPai57WSYqtL8c_9Vat_5PbaQ5tOT79hZMMcegl3_-rb0Kp3dLxjjHKoOew44m6Vm2yyYnf7M6rWjZiK1z2KDnoGwneOiGy6rI3JDcx6_6rrWV549BH_Pn-4LMwm1gzMJ7g/s1600/gateCompatible.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="493" data-original-width="1006" height="312" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOEaWvGCK3RPai57WSYqtL8c_9Vat_5PbaQ5tOT79hZMMcegl3_-rb0Kp3dLxjjHKoOew44m6Vm2yyYnf7M6rWjZiK1z2KDnoGwneOiGy6rI3JDcx6_6rrWV549BH_Pn-4LMwm1gzMJ7g/s640/gateCompatible.JPG" width="640" /></a></div>
<div>
<br /></div>
<div>
What happens if we do the opposite</div>
<div>
<br /></div>
<div>
The 74ALCV LOW input voltage ranges is between 0 and 0.7V and the HIGH input voltage is between 2V and 3.6V. The 74HCT has an output voltage LOW between 0 and 0.44V and an output voltage HIGH of at least 0.44V</div>
<div>
<br /></div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZmSFOHQgHylMGt9VMKwI5VizUXExwr0A8LolTp3tO4F7dJRW-K5ZSOOhI8441ByboiLpHmU0bQb7KoNFYHeDe9n_oPi-CjqgrkFOtdJJU6dm5sQFgYeyUkRBio0MAmGotMvemumRCvT8/s1600/74HCT+Voltage3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="379" data-original-width="372" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZmSFOHQgHylMGt9VMKwI5VizUXExwr0A8LolTp3tO4F7dJRW-K5ZSOOhI8441ByboiLpHmU0bQb7KoNFYHeDe9n_oPi-CjqgrkFOtdJJU6dm5sQFgYeyUkRBio0MAmGotMvemumRCvT8/s320/74HCT+Voltage3.png" width="314" /></a></div>
<div>
<br /></div>
<div>
This means that contrarily to the previous case, here the gates are not compatible and connecting them that way could damage the 74ALVC00 gate.</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5h_cyTVTVuQ9_zUbvmAkLa3V6Qi2zbtkBd3POIotPwEs_LmMYj0pH929A-vDoJfwYRoXTQNODdXGcqSjC2IGvmVKJIUm3rIyuApNiy5hlyDS7qhy_bCKl3cp_XhH7SXyVb_bFh8H0HK4/s1600/incompatible+gate.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="498" data-original-width="1016" height="312" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5h_cyTVTVuQ9_zUbvmAkLa3V6Qi2zbtkBd3POIotPwEs_LmMYj0pH929A-vDoJfwYRoXTQNODdXGcqSjC2IGvmVKJIUm3rIyuApNiy5hlyDS7qhy_bCKl3cp_XhH7SXyVb_bFh8H0HK4/s640/incompatible+gate.JPG" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
This incompatibility is due to the fact that the 74ALVC is not 5V tolerant. If we had used a 74LVC instead (which is a 5V tolerant family) it would have been OK.<br />
<br />
<h3>
Compatibility table</h3>
<div>
The table below was obtained by analyzing the datasheets of a NAND gate (7400 or equivalent) from each logic family and comparing the input and output voltage ranges.</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<style id="logiccompatibility_25852_Styles"><!--table
{mso-displayed-decimal-separator:"\.";
mso-displayed-thousand-separator:"\,";}
.xl1525852
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:black;
font-size:11.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:0;
mso-number-format:General;
text-align:general;
vertical-align:bottom;
mso-background-source:auto;
mso-pattern:auto;
white-space:nowrap;}
.xl6325852
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:black;
font-size:11.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:0;
mso-number-format:General;
text-align:general;
vertical-align:bottom;
mso-background-source:auto;
mso-pattern:auto;
white-space:normal;}
.xl6425852
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:black;
font-size:11.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:0;
mso-number-format:General;
text-align:center;
vertical-align:bottom;
mso-background-source:auto;
mso-pattern:auto;
white-space:nowrap;}
.xl6525852
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:black;
font-size:11.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:0;
mso-number-format:General;
text-align:general;
vertical-align:bottom;
border:.5pt solid windowtext;
mso-background-source:auto;
mso-pattern:auto;
white-space:normal;}
.xl6625852
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:black;
font-size:11.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:0;
mso-number-format:General;
text-align:center;
vertical-align:middle;
border:.5pt solid windowtext;
mso-background-source:auto;
mso-pattern:auto;
white-space:nowrap;}
.xl6725852
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:black;
font-size:11.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:0;
mso-number-format:General;
text-align:center;
vertical-align:bottom;
border:.5pt solid windowtext;
mso-background-source:auto;
mso-pattern:auto;
white-space:nowrap;}
.xl6825852
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:black;
font-size:11.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:0;
mso-number-format:General;
text-align:right;
vertical-align:bottom;
border:.5pt solid windowtext;
mso-background-source:auto;
mso-pattern:auto;
white-space:normal;}
.xl6925852
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:black;
font-size:11.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:0;
mso-number-format:General;
text-align:center;
vertical-align:middle;
border:.5pt solid windowtext;
mso-background-source:auto;
mso-pattern:auto;
white-space:normal;}
.xl7025852
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:black;
font-size:11.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:0;
mso-number-format:General;
text-align:center;
vertical-align:bottom;
border:.5pt solid windowtext;
mso-background-source:auto;
mso-pattern:auto;
white-space:normal;}
.xl7125852
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:black;
font-size:11.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:0;
mso-number-format:General;
text-align:general;
vertical-align:bottom;
border-top:.5pt solid windowtext;
border-right:.5pt solid windowtext;
border-bottom:.5pt solid windowtext;
border-left:none;
mso-background-source:auto;
mso-pattern:auto;
white-space:normal;}
.xl7225852
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:black;
font-size:11.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:0;
mso-number-format:General;
text-align:center;
vertical-align:middle;
border-top:.5pt solid windowtext;
border-right:none;
border-bottom:none;
border-left:.5pt solid windowtext;
mso-background-source:auto;
mso-pattern:auto;
white-space:normal;}
.xl7325852
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:black;
font-size:11.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:0;
mso-number-format:General;
text-align:general;
vertical-align:bottom;
border-top:none;
border-right:.5pt solid windowtext;
border-bottom:.5pt solid windowtext;
border-left:.5pt solid windowtext;
mso-background-source:auto;
mso-pattern:auto;
white-space:normal;}
.xl7425852
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:black;
font-size:11.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:0;
mso-number-format:General;
text-align:right;
vertical-align:bottom;
border:.5pt solid windowtext;
mso-background-source:auto;
mso-pattern:auto;
white-space:nowrap;}
--></style>To use the table select an output family (e.g. 74HCT: last line) it will indicate to what kind of gate input it can be connected. In the 74HCT example, any family except the 74AC,74HC (if VCC is 3.3V) ,and 74 ALVC.<br />
<br />
As you can see in the table there is much more green than red which is a very good news since this means that many families are indeed compatible<br />
<div align="center" id="logiccompatibility_25852" x:publishsource="Excel">
<br />
<br />
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse; table-layout: fixed; width: 986px;"><colgroup><col style="mso-width-alt: 1792; mso-width-source: userset; width: 37pt;" width="49"></col> <col style="mso-width-alt: 2084; mso-width-source: userset; width: 43pt;" width="57"></col> <col class="xl6325852" style="width: 60pt;" width="80"></col> <col span="10" style="width: 60pt;" width="80"></col> </colgroup><tbody>
<tr height="20" style="height: 15.0pt;"> <td class="xl1525852" height="20" style="height: 15.0pt; width: 37pt;" width="49"></td> <td class="xl1525852" style="width: 43pt;" width="57"></td> <td class="xl6325852" style="width: 60pt;" width="80"></td> <td class="xl1525852" style="width: 60pt;" width="80"></td> <td class="xl6725852" colspan="9" style="width: 540pt;" width="720">input</td> </tr>
<tr height="20" style="height: 15.0pt;"> <td class="xl1525852" height="20" style="height: 15.0pt;"></td> <td class="xl1525852"></td> <td class="xl6325852" style="text-align: center; width: 60pt;" width="80"></td> <td class="xl6425852" style="text-align: center;"></td> <td class="xl6725852" colspan="4"><div style="text-align: center;">
PSU =3V</div>
</td> <td class="xl6725852" colspan="5" style="border-left: none;"><div style="text-align: center;">
PSU=5V</div>
</td> </tr>
<tr class="xl6325852" height="80" style="height: 60.0pt;"> <td class="xl6325852" height="80" style="height: 60pt; text-align: center; width: 37pt;" width="49"></td> <td class="xl6325852" style="text-align: center; width: 43pt;" width="57"></td> <td class="xl7225852" style="width: 60pt;" width="80"><div style="text-align: center;">
Logic type</div>
</td> <td class="xl7125852" style="width: 60pt;" width="80"><div style="text-align: center;">
<br /></div>
</td> <td class="xl7025852" style="border-left: none; border-top: none; width: 60pt;" width="80"><div style="text-align: center;">
CMOS in 3V</div>
</td> <td class="xl7025852" style="border-left: none; border-top: none; width: 60pt;" width="80"><div style="text-align: center;">
TTL3V ONLY</div>
</td> <td class="xl7025852" style="border-left: none; border-top: none; width: 60pt;" width="80"><div style="text-align: center;">
CMOS in 3V 5V Tolerant</div>
</td> <td class="xl7025852" style="border-left: none; border-top: none; width: 60pt;" width="80"><div style="text-align: center;">
TTL3V ONLY 5VTolerant</div>
</td> <td class="xl7025852" style="border-left: none; border-top: none; width: 60pt;" width="80"><div style="text-align: center;">
CMOS in 5V</div>
</td> <td class="xl7025852" style="border-left: none; border-top: none; width: 60pt;" width="80"><div style="text-align: center;">
CMOS in 5V</div>
</td> <td class="xl7025852" style="border-left: none; border-top: none; width: 60pt;" width="80"><div style="text-align: center;">
old CMOS</div>
</td> <td class="xl7025852" style="border-left: none; border-top: none; width: 60pt;" width="80"><div style="text-align: center;">
TTL5V only</div>
</td> <td class="xl7025852" style="border-left: none; border-top: none; width: 60pt;" width="80"><div style="text-align: center;">
CMOS 5V only compatible TTL</div>
</td> </tr>
<tr height="100" style="height: 75.0pt;"> <td class="xl1525852" height="100" style="height: 75pt; text-align: center;"></td> <td class="xl1525852" style="text-align: center;"></td> <td class="xl7325852" style="width: 60pt;" width="80"><div style="text-align: center;">
<br /></div>
</td> <td class="xl6925852" style="border-left: none; border-top: none; width: 60pt;" width="80"><div style="text-align: center;">
Family names</div>
</td> <td class="xl7025852" style="border-left: none; border-top: none; width: 60pt;" width="80"><div style="text-align: center;">
AC</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
HC</div>
</td> <td class="xl6725852" style="border-left: none; border-top: none;"><div style="text-align: center;">
ALVC</div>
</td> <td class="xl7025852" style="border-left: none; border-top: none; width: 60pt;" width="80"><div style="text-align: center;">
AHC</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
LV</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
VHC</div>
</td> <td class="xl7025852" style="border-left: none; border-top: none; width: 60pt;" width="80"><div style="text-align: center;">
LCX</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
LVC</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
LVX</div>
</td> <td class="xl7025852" style="border-left: none; border-top: none; width: 60pt;" width="80"><div style="text-align: center;">
AC</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
HC</div>
</td> <td class="xl7025852" style="border-left: none; border-top: none; width: 60pt;" width="80">AHC<br />
<br />
LV<br />
<br />
VHC</td> <td class="xl6725852" style="border-left: none; border-top: none;">CD4xxx</td> <td class="xl7025852" style="border-left: none; border-top: none; width: 60pt;" width="80">ALS<br />
<br />
AS<br />
<br />
F<br />
<br />
LS<br />
<br />
S</td> <td class="xl7025852" style="border-left: none; border-top: none; width: 60pt;" width="80">ACT<br />
<br />
AHCT<br />
<br />
HCT</td> </tr>
<tr height="40" style="height: 30.0pt; mso-height-source: userset;"> <td class="xl6625852" height="480" rowspan="9" style="height: 360.0pt;">output</td> <td class="xl6625852" rowspan="4">PSU =3V</td> <td class="xl6525852" style="border-left: none; border-top: none; width: 60pt;" width="80">CMOS in 3V</td> <td class="xl6825852" style="border-left: none; border-top: none; width: 60pt;" width="80"><div style="text-align: center;">
AC</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
HC</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #f4b084; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
N</div>
</td> <td class="xl6625852" style="background: #f4b084; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
N</div>
</td> <td class="xl6625852" style="background: #f4b084; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
N</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> </tr>
<tr height="20" style="height: 15.0pt;"> <td class="xl6525852" height="20" style="border-left: none; border-top: none; height: 15.0pt; width: 60pt;" width="80"><div style="text-align: center;">
TTL3V ONLY</div>
</td> <td class="xl7425852" style="border-left: none; border-top: none;"><div style="text-align: center;">
ALVC</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
y</div>
</td> <td class="xl6625852" style="background: #f4b084; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
N</div>
</td> <td class="xl6625852" style="background: #f4b084; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
N</div>
</td> <td class="xl6625852" style="background: #f4b084; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
N</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> </tr>
<tr height="60" style="height: 45.0pt;"> <td class="xl6525852" height="60" style="border-left: none; border-top: none; height: 45.0pt; width: 60pt;" width="80"><div style="text-align: center;">
CMOS in 3V 5V Tolerant</div>
</td> <td class="xl6825852" style="border-left: none; border-top: none; width: 60pt;" width="80"><div style="text-align: center;">
AHC</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
LV</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
VHC</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #f4b084; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
N</div>
</td> <td class="xl6625852" style="background: #f4b084; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
N</div>
</td> <td class="xl6625852" style="background: #f4b084; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
N</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> </tr>
<tr height="60" style="height: 45.0pt;"> <td class="xl6525852" height="60" style="border-left: none; border-top: none; height: 45.0pt; width: 60pt;" width="80"><div style="text-align: center;">
TTL3V ONLY 5VTolerant</div>
</td> <td class="xl6825852" style="border-left: none; border-top: none; width: 60pt;" width="80"><div style="text-align: center;">
LCX</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
LVC</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
LVX</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #f4b084; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
N</div>
</td> <td class="xl6625852" style="background: #f4b084; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
N</div>
</td> <td class="xl6625852" style="background: #f4b084; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
N</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> </tr>
<tr height="40" style="height: 30.0pt;"> <td class="xl6625852" height="300" rowspan="5" style="border-top: none; height: 225.0pt;"><div style="text-align: center;">
PSU=5V</div>
</td> <td class="xl6525852" style="border-left: none; border-top: none; width: 60pt;" width="80"><div style="text-align: center;">
CMOS in 5V</div>
</td> <td class="xl6825852" style="border-left: none; border-top: none; width: 60pt;" width="80"><div style="text-align: center;">
AC</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
HC</div>
</td> <td class="xl6625852" style="background: #f4b084; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
N</div>
</td> <td class="xl6625852" style="background: #f4b084; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
N</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> </tr>
<tr height="60" style="height: 45.0pt;"> <td class="xl6525852" height="60" style="border-left: none; border-top: none; height: 45.0pt; width: 60pt;" width="80"><div style="text-align: center;">
CMOS in 5V</div>
</td> <td class="xl6825852" style="border-left: none; border-top: none; width: 60pt;" width="80"><div style="text-align: center;">
AHC</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
LV</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
VHC</div>
</td> <td class="xl6625852" style="background: #f4b084; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
N</div>
</td> <td class="xl6625852" style="background: #f4b084; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
N</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> </tr>
<tr height="20" style="height: 15.0pt;"> <td class="xl6525852" height="20" style="border-left: none; border-top: none; height: 15.0pt; width: 60pt;" width="80"><div style="text-align: center;">
old CMOS</div>
</td> <td class="xl7425852" style="border-left: none; border-top: none;"><div style="text-align: center;">
CD4xxx</div>
</td> <td class="xl6625852" style="background: #f4b084; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
N</div>
</td> <td class="xl6625852" style="background: #f4b084; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
N</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> </tr>
<tr height="100" style="height: 75.0pt;"> <td class="xl6525852" height="100" style="border-left: none; border-top: none; height: 75.0pt; width: 60pt;" width="80"><div style="text-align: center;">
TTL5V only</div>
</td> <td class="xl6825852" style="border-left: none; border-top: none; width: 60pt;" width="80"><div style="text-align: center;">
ALS</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
AS</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
F</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
LS</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
S</div>
</td> <td class="xl6625852" style="background: #f4b084; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
N</div>
</td> <td class="xl6625852" style="background: #f4b084; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
N</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #f4b084; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
N</div>
</td> <td class="xl6625852" style="background: #f4b084; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
N</div>
</td> <td class="xl6625852" style="background: #f4b084; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
N</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;"><div style="text-align: center;">
Y</div>
</td> </tr>
<tr height="80" style="height: 60.0pt;"> <td class="xl6525852" height="80" style="border-left: none; border-top: none; height: 60.0pt; width: 60pt;" width="80"><div style="text-align: center;">
CMOS 5V only compatible TTL</div>
</td> <td class="xl6825852" style="border-left: none; border-top: none; width: 60pt;" width="80"><div style="text-align: center;">
ACT</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
AHCT</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
HCT</div>
</td> <td class="xl6625852" style="background: #f4b084; border-left: none; border-top: none; border: 0.5pt solid;">N</td> <td class="xl6625852" style="background: #f4b084; border-left: none; border-top: none; border: 0.5pt solid;">N</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;">Y</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;">Y</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;">Y</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;">Y</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;">Y</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;">Y</td> <td class="xl6625852" style="background: #a9d08e; border-left: none; border-top: none; border: 0.5pt solid;">Y</td> </tr>
<tr height="0" style="display: none;"> <td style="width: 37pt;" width="49"></td> <td style="width: 43pt;" width="57"></td> <td style="width: 60pt;" width="80"></td> <td style="width: 60pt;" width="80"></td> <td style="width: 60pt;" width="80"></td> <td style="width: 60pt;" width="80"></td> <td style="width: 60pt;" width="80"></td> <td style="width: 60pt;" width="80"></td> <td style="width: 60pt;" width="80"></td> <td style="width: 60pt;" width="80"></td> <td style="width: 60pt;" width="80"></td> <td style="width: 60pt;" width="80"></td> <td style="width: 60pt;" width="80"></td> </tr>
</tbody></table>
<br /></div>
<h2>
Adapting levels</h2>
<div>
As can be seen in the table above, there 3 types of incompatibilities</div>
<h3>
TTL 5V driving CMOS 5V</h3>
<div>
This is a very old incompatibility that dates back to 1970!</div>
<div>
<br /></div>
<div>
e.g. a 74LS driving a 74HC or a 74F driving a CD4000</div>
<div>
<br /></div>
<div>
The TTL 5V gates have an HIGH voltage level that is not high enough to be identified as a HIGH level by the CMOS gate</div>
<div>
<br /></div>
<div>
One simple solution is to interface both systems using a 74HCT gate. indeed the input of a 74HCT gate is compatible with TTL 5V and its output is compatible CMOS</div>
<div>
<br /></div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZj24D9CxAiIOR8FtVm9E3fJXlK8HZVAzfw29HTMRpuqfZBSbnIJbt7CPRxAZxU4BeX-QCBkrfroFet-n2YSsvwQbZVm86icJEq-zMqkd8UaNYeg250Qd4G2CAF4uis6GzWtlNbRnc4CQ/s1600/LsDriveCMOS.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="339" data-original-width="1398" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZj24D9CxAiIOR8FtVm9E3fJXlK8HZVAzfw29HTMRpuqfZBSbnIJbt7CPRxAZxU4BeX-QCBkrfroFet-n2YSsvwQbZVm86icJEq-zMqkd8UaNYeg250Qd4G2CAF4uis6GzWtlNbRnc4CQ/s1600/LsDriveCMOS.JPG" /></a></div>
<div>
<br /></div>
<div>
<br /></div>
<h3>
TTL 3.3V driving CMOS 5V</h3>
<div>
This is the same incompatibility as for TTL 5V driving CMOS 5V: the TTL 3V output voltage HIGH is not HIGH enough. Here also, using a 74HCT is a good workaround.</div>
<div>
<br /></div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgw9eLfLg8ongPlHbtWEqSwqY9FM0BXqhRQhlyv6biOpLkR96eys-I6RNupCrhg-fKzfOZoJ3p_PwN3nZMacdhFvN1-s05YQBub5rKxeBqN2Es8Pi3nvLfOOr8gHRuETHrqiriTNOb0I-E/s1600/3v3DriveCMOS.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="342" data-original-width="1425" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgw9eLfLg8ongPlHbtWEqSwqY9FM0BXqhRQhlyv6biOpLkR96eys-I6RNupCrhg-fKzfOZoJ3p_PwN3nZMacdhFvN1-s05YQBub5rKxeBqN2Es8Pi3nvLfOOr8gHRuETHrqiriTNOb0I-E/s1600/3v3DriveCMOS.JPG" /></a></div>
<br />
<h3>
5V Logic driving 3V3 Non 5V tolerant logic</h3>
</div>
<div>
This is the problem: that occurs when you want to drive a Raspberry PI input with a 5V signal. You risk to damage the 3V3 raspberry PI chip with the 5V output. The workaround is to use 5V tolerant 3V3 logic gate.e.g. a 74LVC gate as interface.</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgI9JlVCUZ8QEVOh7KRCUvtCMFp9VvYEKd6431pRyoqhs4XHYdbNxQXVeeU4JmbsUc2MJCCWv2fbKNY0V4wp-libYRSUIwLYoBWQkTis19iINbpD4nujMTlXtlugBFqhnW_95XxzprC5aA/s1600/5Vto3V.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="342" data-original-width="1411" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgI9JlVCUZ8QEVOh7KRCUvtCMFp9VvYEKd6431pRyoqhs4XHYdbNxQXVeeU4JmbsUc2MJCCWv2fbKNY0V4wp-libYRSUIwLYoBWQkTis19iINbpD4nujMTlXtlugBFqhnW_95XxzprC5aA/s1600/5Vto3V.JPG" /></a></div>
<div>
<br /></div>
<div>
<h3>
DISCLAIMER:</h3>
The compatibility table was made by analyzing the datasheet of one manufacturer (most of the times Texas Instruments and sometimes ON SEMI or other manufacturers) .Some extrapolation was needed when the datasheet did not contain the value of VCC (3.3V / 5V) or the gate output current (12mA). This means that t<b>he table is for reference only and I cannot guarantee it does not contain some errors or inaccuracies. This table is no replacement for consulting the manufacturer datasheet</b></div>
thinkingIn16Bitshttp://www.blogger.com/profile/16782553204614961567noreply@blogger.com0tag:blogger.com,1999:blog-1533381118607780865.post-21081691731851878222017-04-30T07:45:00.002-07:002017-05-01T13:39:53.406-07:00Using the PI Cobbler on an Arduino<h2>
Introduction</h2>
<div>
<br /></div>
<div>
The PI Cobbler (made by Adafruit) is a great tool that is used to connect a Raspberry PI to a bread board.<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuPfep5zTNztXXdrjHIKnQ0lgfoKfyX8liXC3txQcPDd66niGffSpjLHdmfWIPoxkQaHW8feM8EatVyApKulbA_561_ufAarB7Q300Ue64YoY8-djX_Ga9dJ2iOME_aKV2Ixn010sn2-A/s1600/PiCobbler.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="182" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuPfep5zTNztXXdrjHIKnQ0lgfoKfyX8liXC3txQcPDd66niGffSpjLHdmfWIPoxkQaHW8feM8EatVyApKulbA_561_ufAarB7Q300Ue64YoY8-djX_Ga9dJ2iOME_aKV2Ixn010sn2-A/s320/PiCobbler.jpg" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">PI Cobbler</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
The Arduino Uno board on the other hand is not so straight forward to connect to a breadboard. You often end up with a mess of many wires</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPP54CaGBbybQothwj1rLSyiWmBCCEUtIjCDwZ1VcYFefFLa1vgfCcK-vqgEEkdrhYCPzFMAvM_as9_ENj8I4vg4yXkDIZ8ArUXGO9JmYfN05ybXruQGh-JviGSUW4bJRHu4_TQAI83TE/s1600/arduino.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="336" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPP54CaGBbybQothwj1rLSyiWmBCCEUtIjCDwZ1VcYFefFLa1vgfCcK-vqgEEkdrhYCPzFMAvM_as9_ENj8I4vg4yXkDIZ8ArUXGO9JmYfN05ybXruQGh-JviGSUW4bJRHu4_TQAI83TE/s400/arduino.jpg" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Arduino Uno requires individual wires towards the breadboard</td></tr>
</tbody></table>
An alternative is to use an Arduino Nano that fits directly on the breadboard</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIFHPtBpLlS_d_tMHdEXYEsHnEeNQ7Z5tp1aYxVWMVkm0Nnp-ejyRNStBCfv76dsn9fB3UE3nRvKqBzHri76t9PfezNQ0wQt46-fb57l56ihnkbbmgLttsdIK4zjjywgQ5BfMTKQhGJSk/s1600/nano.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="262" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIFHPtBpLlS_d_tMHdEXYEsHnEeNQ7Z5tp1aYxVWMVkm0Nnp-ejyRNStBCfv76dsn9fB3UE3nRvKqBzHri76t9PfezNQ0wQt46-fb57l56ihnkbbmgLttsdIK4zjjywgQ5BfMTKQhGJSk/s400/nano.jpg" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Arduino Nano fits directly on Breadboard</td></tr>
</tbody></table>
<div>
<br />
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
It would be great to be able to connect a flat cable directly to the Arduino UNO. So let's build an adapter UNO -> Flat cable<br />
<h2 style="clear: both; text-align: left;">
Assembly instructions</h2>
<h3>
Needed stuff</h3>
<div>
You will need</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyWxOtyTllwh73TSJgjcSvoSpeMXjHxTV9VKdeyJ4ktUd7NWI2_bllJvSo77RXMHLnyCQqiMlAoAiun-XzADqqgqMH4usiCYuWt0VVJRe6Db9KezBwq4aRTEetFQ2q7G50DknZnxtMSJg/s1600/stuff.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="468" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyWxOtyTllwh73TSJgjcSvoSpeMXjHxTV9VKdeyJ4ktUd7NWI2_bllJvSo77RXMHLnyCQqiMlAoAiun-XzADqqgqMH4usiCYuWt0VVJRe6Db9KezBwq4aRTEetFQ2q7G50DknZnxtMSJg/s640/stuff.jpg" width="640" /></a></div>
<ol>
<li>A PI Cobbler</li>
<li>A 2x40 Positions Header, Breakaway Connector 0.100" (2.54mm) Through Hole</li>
<li>An Arduino Uno</li>
<li>An Arduino Protoshield (I use the one from Adafruit) </li>
<li>Some cabling wire</li>
<li>Some solder</li>
</ol>
<strong><span style="color: red; font-size: large;">Update on May 2 2017: </span></strong><br />
<strong><span style="color: red; font-size: large;">STOP DON'T USE THE ADAFRUIT PI COBBLER!! it is only intended for the Raspberry PI. It contains internal wiring that connect all the Raspberry PI GND together this may damage your Arduino and / or prevent your project from working </span></strong><br />
<ol>
</ol>
<a name='more'></a><br />
<h3>
Building the adapter</h3>
<h4>
Assemble the protoshield kit</h4>
<h4>
Break the pin header</h4>
<div>
We will use a 34 (2x17 pins) so break the pin header to this length and solder it on the protoshield</div>
<div>
<br /></div>
<h4>
Solder the pin header on the protoshield at the specified place</h4>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8hRSHvmobHENzkaqZxBs346O7El0M08n3Xu9WmCSAKF4KxlnQSNcuP6kOiSd2JPtSp1H6kFALEAp_ThZRKFoTLdkrRWn0izdA1oaEkLH0ZNd2jyCS1emJR7cOh7n4H9IxuXzt-IVJn0U/s1600/proto0.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="302" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8hRSHvmobHENzkaqZxBs346O7El0M08n3Xu9WmCSAKF4KxlnQSNcuP6kOiSd2JPtSp1H6kFALEAp_ThZRKFoTLdkrRWn0izdA1oaEkLH0ZNd2jyCS1emJR7cOh7n4H9IxuXzt-IVJn0U/s400/proto0.jpg" width="400" /></a></div>
<div>
<br /></div>
<h4>
Solder each output pin of the Arduino Uno connectors to the pin header</h4>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhW7zQF6T0DdRRO_eeTxT1tjNGvZDmi-8V_ghMpTPZ34M0NtD7W43tVBXvHlubgN7YlExefTqcYpG5HK9DC5naz1abslKK7tCfUQi25-8mvYvp6Q1cWmJXjRYEcshvGRJDIKyw7nOdntjo/s1600/proto3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="538" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhW7zQF6T0DdRRO_eeTxT1tjNGvZDmi-8V_ghMpTPZ34M0NtD7W43tVBXvHlubgN7YlExefTqcYpG5HK9DC5naz1abslKK7tCfUQi25-8mvYvp6Q1cWmJXjRYEcshvGRJDIKyw7nOdntjo/s640/proto3.jpg" width="640" /></a></div>
<div>
<br /></div>
<div>
This is the view from below. as you can see the soldering work is very limited</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLSLRonTE8AuWMeR3sdqTOeanMfsbbfllww-c_XG5Oi5X3Xuj2AM0Phloan6WQ8KYuv6jhBq49ETLgXHhVDLrHrUhyphenhyphenNlQaJBhoderOejEdA99gjfeBNqZZUzC2jmPVKB7d-Xz5EWRl3go/s1600/below.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="237" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLSLRonTE8AuWMeR3sdqTOeanMfsbbfllww-c_XG5Oi5X3Xuj2AM0Phloan6WQ8KYuv6jhBq49ETLgXHhVDLrHrUhyphenhyphenNlQaJBhoderOejEdA99gjfeBNqZZUzC2jmPVKB7d-Xz5EWRl3go/s320/below.jpg" width="320" /></a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
Now you can take a flat cable (e.g. <strike>the one from the PI cobbler</strike><span style="color: red;"> DO NOT USE THE PI COBBLER! it will short some Arduino signals</span>) and connect it directly to the Arduino Uno.</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOVk_ZsQG4KvV3MLvmfB7bVTVizWA0sjyGP4M3iIWRLSozfms1ifgQTOdHYvHPdOC1SfiJu-2CHKaLKX6DowDfdqzof9hVPoN_seRqB-cdBEE2M_PHAlaeGt0MPgkJXAy1XnU8RTHaGDU/s1600/fina.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="226" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOVk_ZsQG4KvV3MLvmfB7bVTVizWA0sjyGP4M3iIWRLSozfms1ifgQTOdHYvHPdOC1SfiJu-2CHKaLKX6DowDfdqzof9hVPoN_seRqB-cdBEE2M_PHAlaeGt0MPgkJXAy1XnU8RTHaGDU/s400/fina.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
Et voila! you have an "Arduino Cobbler".</div>
<div>
<br /></div>
<div>
<h2>
The Pinout</h2>
</div>
<div>
This is the pin out of the Arduino Uno <strike>on the PI cobbler.</strike><span style="background-color: white; color: red;">DO NOT USE THE PI COBBLER</span></div>
<div>
They are organized exactly as on the Arduino except for the SCL that had to go on the other side because there was not enough pins on the left side.</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjx2-UVu7szZQKa6YKEo84YPCabcPWO6jWmLyLM5snLcfVwBDuDG_bv0iHiJPpDKOKSVKwmVDKlekn6P4bMhGC9QRePkBJ4EZ8pwO-qGWAlpKMeHx72b6BtyLXzPdaGgIITbWJ5VdxUk-o/s1600/pinout.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjx2-UVu7szZQKa6YKEo84YPCabcPWO6jWmLyLM5snLcfVwBDuDG_bv0iHiJPpDKOKSVKwmVDKlekn6P4bMhGC9QRePkBJ4EZ8pwO-qGWAlpKMeHx72b6BtyLXzPdaGgIITbWJ5VdxUk-o/s320/pinout.jpg" width="234" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div>
</div>
<div>
<br /></div>
<div>
</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
</div>
thinkingIn16Bitshttp://www.blogger.com/profile/16782553204614961567noreply@blogger.com0tag:blogger.com,1999:blog-1533381118607780865.post-63791236377214307932017-01-02T16:09:00.001-08:002017-01-02T16:09:43.641-08:00Creating a WASD joystick with an Arduino Esplora <h2>
Introduction</h2>
The classic WASD game keys are very popular. But if this key layout is nice on QWERTY keyboard, it is not so logical on an AZERTY keyboard.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVUDm7DXCqr9qXjjB2E_ju7JNcxGcrqOZKmTNlohp1QCpVuDBh8wbQ0TCmBzmCCP_UBTFRescxC0sMB2QunC7Q_phnJuS3XXuTNL5TkDm08wSAHcdTp9npTp3hm6SMnp5xxUnn5_PyB0o/s1600/Azerty.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVUDm7DXCqr9qXjjB2E_ju7JNcxGcrqOZKmTNlohp1QCpVuDBh8wbQ0TCmBzmCCP_UBTFRescxC0sMB2QunC7Q_phnJuS3XXuTNL5TkDm08wSAHcdTp9npTp3hm6SMnp5xxUnn5_PyB0o/s1600/Azerty.jpg" /></a></div>
<div class="separator" style="clear: both;">
<br /></div>
With such layout you cannot make great score at any game.<br />
The classic solution is to configure the keyboard as a US QWERTY keyboard for the duration of the game. But that's not a very satisfactory solution. What we need is a joystick that behaves like the WASD keys.<br />
<br />
<h2>
The Arduino Esplora board</h2>
<div>
The Arduino Esplora board is an Arduino Leonardo board that implement a joystick.</div>
<div>
This is exactly what we need.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhK0qtt_kyoA5fJI3auYUMAempj6TU0uMJxpFT8f6cHNnDUWWfhocBa8l5LB0__kErucEtOiuuI3jcNquYtguGetajrwVL0y1BG7FqpSHTKv7LtWvOW8nhTiwkK2ZR6csILGehYwBrDjPo/s1600/esplora.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="179" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhK0qtt_kyoA5fJI3auYUMAempj6TU0uMJxpFT8f6cHNnDUWWfhocBa8l5LB0__kErucEtOiuuI3jcNquYtguGetajrwVL0y1BG7FqpSHTKv7LtWvOW8nhTiwkK2ZR6csILGehYwBrDjPo/s320/esplora.jpg" width="320" /></a></div>
<div class="separator" style="clear: both;">
<br /></div>
The Leonardo (and the Esplora) board can behave like an HID device. This means that they can be programmed to behave as an USB mouse or as an USB keyboard by the computer. <br />
<br />
Now all we need is to program it so that the board joystick generates the WSAD key press.<br />
<br />
<h2>
The program</h2>
<div>
Enrico Gueli has written a program called "EsploraKart" <a href="https://www.arduino.cc/en/Tutorial/EsploraKart" target="_blank">(www.arduino.cc/en/Tutorial/EsploraKart)</a> that does exactly what we want except that he has used the arrow keys instead of the WSAD keys.</div>
<div>
Now lets modify his program to get the WSAD keys mapping:</div>
<div>
<br /></div>
<div>
<span style="color: blue; font-family: "Courier New", Courier, monospace; font-size: x-small;">/*<br /> esploraWASD<br /> This is a sketch is a modification of "EsploraKart" written by Enrico Gueli</span></div>
<div>
<span style="color: blue; font-family: "Courier New", Courier, monospace; font-size: x-small;"> The joystick will send the WASD keys and<br /> the switches will send "space"</span></div>
<div>
<span style="color: blue; font-family: "Courier New", Courier, monospace; font-size: x-small;">*/</span></div>
<div>
<span style="color: blue; font-family: "Courier New", Courier, monospace; font-size: x-small;">#include <Esplora.h><br />#include <Keyboard.h></span></div>
<div>
<span style="color: blue; font-family: "Courier New", Courier, monospace; font-size: x-small;">boolean buttonStates[8];</span></div>
<div>
<span style="color: blue; font-family: "Courier New", Courier, monospace; font-size: x-small;">const byte buttons[] = {<br /> JOYSTICK_DOWN,<br /> JOYSTICK_LEFT,<br /> JOYSTICK_UP,<br /> JOYSTICK_RIGHT,<br /> <br /> SWITCH_RIGHT,<br /> SWITCH_LEFT, <br /> SWITCH_UP, <br /> SWITCH_DOWN<br />};</span></div>
<div>
<span style="color: blue; font-family: "Courier New", Courier, monospace; font-size: x-small;">const char keystrokes[] = {<br /><span style="color: red;"> 's',<br /> 'a',<br /> 'w',<br /> 'd',<br /> ' ',<br /> ' ',<br /> ' ',<br /> ' '</span><br />};</span></div>
<div>
<span style="color: blue; font-family: "Courier New", Courier, monospace; font-size: x-small;">void setup() {<br /> Keyboard.begin();<br />}</span></div>
<div>
<span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue; font-size: x-small;">void loop() {<br /> for (byte thisButton = 0; thisButton < 8; thisButton++) {<br /> boolean lastState = buttonStates[thisButton];<br /> boolean newState = Esplora.readButton(buttons[thisButton]);<br /> if (lastState != newState) { // Something changed!<br /> if (newState == PRESSED) {<br /> Keyboard.press(keystrokes[thisButton]);<br /> }<br /> else if (newState == RELEASED) {<br /> Keyboard.release(keystrokes[thisButton]);<br /> }<br /> }<br /> buttonStates[thisButton] = newState;<br /> }<br /> delay(50);<br />}</span></span></div>
<div>
<span style="color: blue; font-family: Courier New; font-size: x-small;"><br /></span></div>
I have removed the comments and marked in <span style="color: red;">red</span> the modified lines<br />
<span style="font-family: "Courier New", Courier, monospace;"></span><h2>
Return of the AZERTY problem</h2>
<div>
The above program will work great if you have a QWERTY (or a German QWERTZ) keyboard, but strangely, it does not work with a computer configured with an AZERTY keyboard.</div>
<div>
<br /></div>
<div>
On a AZERTY computer the Esplora board outputs are ZQSD instead of WASD.</div>
<div>
If you look at the position of the ZQSD keys on an AZERTY keyboard you will notice that they are at the same location as the WASD keys on a QWERTY keyboard.</div>
<div>
<br /></div>
<div>
This is a limitation of the Arduino Keyboard library: this library allows to simulate a keyboard with a Leonardo or an Esplora board but the simulated keyboard is expecting that the computer uses a US QWERTY keyboard layout. </div>
<div>
<br /></div>
<div>
This origin of this restriction comes from the HID protocol: It specifies a key location on the keyboard and it is the computer responsibility to map this key location to a key symbol (or a special key).</div>
<div>
<br /></div>
<div>
I should have tried to adapt the Arduino Keyboard library to support multiple keyboard layouts. But I was too lazy ( this guy did something like that <a href="http://www.zem.fr/utiliser-mouse-keyboard-azerty-arduino-pro-micro-teensy/" target="_blank">www.zem.fr</a>). I simply have mapped the AZERTY keys in my program. This makes the program only usable on an AZERTY PC.</div>
<div>
<br /></div>
<div>
<span style="color: red; font-family: "Courier New", Courier, monospace; font-size: x-small;">const char keystrokes[] = {<br /> 's',//s<br /> 'q',//a<br /> 'z',//w<br /> 'd',//d<br /> ' ',<br /> ' ',<br /> ' ',<br /> ' '<br />};</span></div>
<br />
With this mapping the Esplora board is behaving like a WASD joystick. This is what I needed.<br />
<br />thinkingIn16Bitshttp://www.blogger.com/profile/16782553204614961567noreply@blogger.com0tag:blogger.com,1999:blog-1533381118607780865.post-49395729556190725482016-12-18T12:49:00.002-08:002016-12-18T12:49:54.616-08:00Using mouse events on an HTML 5 Canvas in typescriptIn this tutorial, I will show how to add a mouse event handler to an HTML 5 canvas using typescript.<br />
<br />
<u>Acknowledgements:</u> Writing this would not have been possible without the excellent documentation I have found in <a href="http://www.typescriptgames.com/" target="_blank">http://www.typescriptgames.com/</a> <br />
<br />
<h2>
The sample document:</h2>
<div>
To demonstrate the use of the mouse on a canvas, I have created a very simple page:</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHXTFtHyKQCcFsUQJKZZSBQtskKPfuvviyx0nLGiFRT0zSFWaLN53aEYcpj7_XpSm2nEmIZEKOXvbLzp-sar-s3npde8KKuI3wft3Hf27d3BJ3GaI5uj-o9gL68rULisk4VgLXf9w2N7Y/s1600/canvasDemo.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHXTFtHyKQCcFsUQJKZZSBQtskKPfuvviyx0nLGiFRT0zSFWaLN53aEYcpj7_XpSm2nEmIZEKOXvbLzp-sar-s3npde8KKuI3wft3Hf27d3BJ3GaI5uj-o9gL68rULisk4VgLXf9w2N7Y/s640/canvasDemo.PNG" width="640" /></a></div>
<div>
<br /></div>
<div>
This page is a primitive drawing program that just draws a line on the canvas till the point where the mouse was clicked.</div>
<div>
<br /></div>
<div>
The html is below:</div>
<div>
<br /></div>
<br />
<blockquote class="tr_bq">
<span style="font-family: "courier new" , "courier" , monospace;"><!doctype html><br />
<html><br />
<head><br />
<title>Demonstration of Canvas and Typescript</title><br />
<link rel="stylesheet" href="canvas.css"><br />
</head><br />
<body><br />
<header><br />
<h1>Mouse events on a canvas using typescript</h1><br />
</header><br />
<aside><br />
<h2><br />
Instructions<br />
</h2><br />
<p><br />
Click on the canvas to draw a line from the last point to the point where you have clicked The first point is at the canvas center.<br />
</p><br />
<p><br />
note: the canvas is cleared on resize.<br />
</p><br />
</aside><br />
<canvas id="canvas">This is the canvas</canvas><br />
<script src=canvas.js></script><br />
</body><br />
</html></span></blockquote>
<div>
And this is the CSS</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<blockquote>
<span style="font-family: "courier new" , "courier" , monospace;">h1{<br />
margin: 10px;<br />
}<br />
h2{<br />
margin: 0px;<br />
}<br />
aside {<br />
float: left;<br />
border: 1px solid black;<br />
padding: 10px;<br />
margin: 20px;<br />
width: 20%;<br />
}<br />
aside p{<br />
font-family: Arial, Helvetica, sans-serif;<br />
}<br />
#canvas {<br />
float: left;<br />
background: lightgray;<br />
border: 1px solid black;<br />
margin: 20px;<br />
width: 65%;<br />
}</span></blockquote>
</div>
<h2>
Handling the mouse event</h2>
<div>
Since we are using typescript, It is a good opportunity to make use of OOP. So let's create a class named canvasDraw that will handle all the operations related to drawing.</div>
<div>
<br /></div>
<div>
This class shall include an event handler that will receive the "mousedown" events</div>
<div>
<blockquote>
<span style="font-family: "courier new" , "courier" , monospace;">class CanvasDraw {<br />
canvas: HTMLCanvasElement;<br />
context: CanvasRenderingContext2D;<br />
private x: number;<br />
private y: number;<br />
public constructor() {<br />
this.canvas = <HTMLCanvasElement>document.getElementById("canvas");<br />
this.context = this.canvas.getContext("2d");<br />
this.canvas.addEventListener("mousedown", this.click, false);<br />
}<br />
public click = (event: MouseEvent): void => {<br />
this.context.beginPath();<br />
this.context.moveTo(this.x, this.y);<br />
let rect = this.canvas.getBoundingClientRect();<br />
this.x = (event.clientX - rect.left)/rect.width*this.canvas.width;<br />
this.y = (event.clientY - rect.top)/rect.height*this.canvas.height;<br />
this.context.lineTo(this.x, this.y);<br />
this.context.stroke();<br />
event.preventDefault();<br />
}<br />
}<br />
let canvasDraw: CanvasDraw = new CanvasDraw();</span></blockquote>
</div>
<div>
<h3>
Syntax to declare the event handler:</h3>
</div>
<div>
We assign a lambda function to an attribute of the class:</div>
<div>
<br /></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"> public click = (event: MouseEvent): void => { ... }</span></div>
<div>
<br /></div>
<div>
and we use this attribute to as a mousedown event listenr<br />
<br />
<span style="font-family: "courier new", courier, monospace;">this.canvas.addEventListener("mousedown", this.click, false);</span><br />
<br />
This allows us to define the full code inside the class<br />
<br />
<h3>
Finding the clicked x/y position inside the canvas</h3>
</div>
<div>
The mouse event attributes clientX and ClientY cannot be used directly.</div>
<div>
<br /></div>
<div>
They need to be offset by the client top/left position and must be adapted by the canvas scaling.</div>
<div>
<br /></div>
<div>
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace;"> let rect = this.canvas.getBoundingClientRect();<br /> x = (event.clientX - rect.left)/rect.width*this.canvas.width;<br /> y = (event.clientY - rect.top)/rect.height*this.canvas.height;</span></blockquote>
<br />
<h2>
The canvas scaling problem</h2>
If you try the above program (don't forget to compile the typescript into JavaScript) You will see that the result is not as good as expected. This is because the HTML 5 canvas maintain a distinction between the canvas size (i.e. the image drawn) and the displayed size.<br />
<br />
By default the canvas size is 300px x 150 px but the displayed size is determined by the css. This means that most probably the displayed size will be much larger than the canvas drawing size leading to a "zoomed" image where all the pixels are visible and blurry.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiH_FP5OpcW58brHS8LBHIUfJ13cH8pjSE-ne48Du_IJCbhf1sLkzi7ha7ThONfm530BI3XMy0Cf9Pt9VDtLbUa6nzwqd8SIpLGMIZydD6-I9pHPGxytSbnvtsN0-dzGz8nzJ9HYpSLh2k/s1600/blurry.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiH_FP5OpcW58brHS8LBHIUfJ13cH8pjSE-ne48Du_IJCbhf1sLkzi7ha7ThONfm530BI3XMy0Cf9Pt9VDtLbUa6nzwqd8SIpLGMIZydD6-I9pHPGxytSbnvtsN0-dzGz8nzJ9HYpSLh2k/s1600/blurry.PNG" /></a></div>
<br />
<br />
<br />
To avoid this we should align the canvas size on the display size. But doing this is not straight forward.<br />
<br />
<h3>
Aligning canvas size on display size</h3>
<div>
To do this we use the following code</div>
<div>
<br /></div>
<div>
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace;"> this.canvas.height = this.canvas.offsetHeight;<br /> this.canvas.width = this.canvas.offsetWidth;</span></blockquote>
</div>
<div>
<br /></div>
This works great but we need to find a way to call it at program startup and each time the canvas is resized.<br />
<br />
<h3>
The resize event</h3>
There is no resize event on canvas in HTML 5 so we will have to use the event associated with the window object instead of the canvas object<br />
<br />
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace;">class CanvasDraw {<br /> canvas: HTMLCanvasElement;<br /> context: CanvasRenderingContext2D;<br /> private x: number;<br /> private y: number;<br /> public constructor() {<br /> this.canvas = <HTMLCanvasElement>document.getElementById("canvas");<br /> this.context = this.canvas.getContext("2d");<br /> this.canvas.addEventListener("mousedown", this.click, false);<br /> //note resize event cannot be attached to the canvas<br /> window.addEventListener("resize", this.resize, false);<br /> this.resize(null);<br /> }<br /> public click = (event: MouseEvent): void => {<br />...<br /> }<br /> public resize = (event: UIEvent): void => {<br /> this.canvas.height = this.canvas.offsetHeight;<br /> this.canvas.width = this.canvas.offsetWidth;<br /> }<br />}</span></blockquote>
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">Note the call to resize at the end of the constructor that ensure that the </span>initial<span style="font-family: inherit;"> canvas drawing area size is correct at the application startup</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
Important note: on most browser the canvas is cleared after resize but this behavior is not guaranteed. To avoid compatibility problems we always clear the canvas with<br />
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace;"> this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);</span></blockquote>
<br />
<h2>
The Complete program</h2>
<div>
Just for completeness and if you want to try it, this is the full listing of canvas.ts</div>
<div>
<br /></div>
<div>
<blockquote>
class CanvasDraw {<br /> canvas: HTMLCanvasElement;<br /> context: CanvasRenderingContext2D;<br /> private x: number;<br /> private y: number;<br /> public constructor() {<br /> this.canvas = <HTMLCanvasElement>document.getElementById("canvas");<br /> this.context = this.canvas.getContext("2d");<br /> this.canvas.addEventListener("mousedown", this.click, false);<br /> //note resize event cannot be attached to the canvas<br /> window.addEventListener("resize", this.resize, false);<br /> this.resize(null);<br /> }<br /> public click = (event: MouseEvent): void => {<br /> this.context.beginPath();<br /> this.context.moveTo(this.x, this.y);<br /> let rect = this.canvas.getBoundingClientRect();<br /> this.x = (event.clientX - rect.left);///rect.width*this.canvas.width;<br /> this.y = (event.clientY - rect.top);///rect.height*this.canvas.height;<br /> this.context.lineTo(this.x, this.y);<br /> this.context.stroke();<br /> event.preventDefault();<br /> }<br /> public resize = (event: UIEvent): void => {<br /> //the problem is that we must align canvas resolution on CSS set display size<br /> // otherwise there will be a zoom at display that will blur the lines<br /> this.canvas.height = this.canvas.offsetHeight;<br /> this.canvas.width = this.canvas.offsetWidth;<br /> this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);<br /> this.x = this.canvas.width / 2;<br /> this.y = this.canvas.height / 2;<br /> }<br />}<br />let canvasDraw: CanvasDraw = new CanvasDraw();</blockquote>
</div>
</div>
<div>
<br /></div>
thinkingIn16Bitshttp://www.blogger.com/profile/16782553204614961567noreply@blogger.com1tag:blogger.com,1999:blog-1533381118607780865.post-29718992398351174622016-06-26T13:43:00.000-07:002016-06-26T13:44:24.155-07:00Redirecting stdout and stderr under Windows<h2>
Introduction</h2>
A console program (i.e. a program that is executed from the command line) can write its output on two separate streams: <strong>stdout</strong> and <strong>stderr</strong>. Theoretically <strong>stdout</strong> is used to display the program results and <strong>stderr</strong> is used to write error messages.<br />
<br />
In a normal execution text written on both the stdout and the stderr isdisplayed on the console.<br />
<br />
Lets try with an example. The following simplistic C# code writes a message on stdout and another message in stderr.<br />
<br />
<table style="width: 100%;"><tbody>
<tr style="background-color: #0f0f0f;"> <td><br />
<span style="color: cyan; font-family: "courier new" , "courier" , monospace; font-size: large;"><br />
using System;<br />
namespace TestStdout<br />
{<br />
class Program<br />
{<br />
static void Main(string[] args)<br />
{<br />
Console.Error.WriteLine("STDERR message");<br />
Console.Out.WriteLine("STDOUT message");<br />
}<br />
}<br />
} <br />
<br />
</span></td> </tr>
</tbody></table>
<br />
If we execute this program on the windows command line we get<br />
<br />
<table style="width: 100%;"><tbody>
<tr style="background-color: #0f0f0f;"> <td><br />
<span style="color: lime; font-family: "courier new" , "courier" , monospace; font-size: large;"><br />
D:\test><span style="color: white;">TestStdout.exe</span><br />
STDERR message<br />
STDOUT message<br />
<br />
D:\test></span></td> </tr>
</tbody></table>
<br />
<h2>
Redirection </h2>
The redirection of stdout and stderr is well known by Linux users but strangely not so much popular for Windows users. However, it works (nearly) the same way with both operating systems<br />
<br />
<h3>
Redirect stdout to a file</h3>
To redirect the program output (stdout) to a file, use the operator <strong><span style="color: red;">></span></strong> <br />
<br />
<table style="width: 100%;"><tbody>
<tr style="background-color: #0f0f0f;"> <td><br />
<span style="color: lime; font-family: "courier new" , "courier" , monospace; font-size: large;"><br />
D:\test><span style="color: white;">TestStdout.exe >out.txt</span><br />
STDERR message<br />
<br />
D:\test><span style="color: white;">type out.txt</span><br />
STDOUT message<br />
<br />
D:\test><br />
</span></td> </tr>
</tbody></table>
<br />
To get rid of stdout you may redirect it to a special file called <strong>NUL</strong> that throws away anything sent to it. (note that in Linux it is called /dev/null).<br />
<br />
<table style="width: 100%;"><tbody>
<tr style="background-color: #0f0f0f;"> <td><br />
<span style="color: lime; font-family: "courier new" , "courier" , monospace; font-size: large;"><br />
D:\test><span style="color: white;">TestStdout.exe >NUL</span><br />
STDERR message<br />
<br />
D:\test><br />
</span></td> </tr>
</tbody></table>
<br />
<br />
<h3>
Redirect stderr to a file</h3>
To redirect the stderr you use the operator <strong><span style="color: red;">2></span></strong><br />
<br />
<table style="width: 100%;"><tbody>
<tr style="background-color: #0f0f0f;"><td><br />
<span style="color: lime; font-family: "courier new" , "courier" , monospace; font-size: large;"><br />
D:\test><span style="color: white;">TestStdout.exe 2>err.txt</span><br />
STDOUT message<br />
<br />
D:\test><span style="color: white;">type err.txt</span><br />
STDERR message<br />
<br />
D:\test><br />
</span></td></tr>
</tbody></table>
<br />
<br />
You may also redirect stderr to NUL if you want to get rid of it<br />
<br />
<table style="width: 100%;"><tbody>
<tr style="background-color: #0f0f0f;"><td><br />
<span style="color: lime; font-family: "courier new" , "courier" , monospace; font-size: large;"><br />
</span><span style="color: lime; font-family: "courier new"; font-size: large;">D:\test><span style="color: white;">TestStdout.exe 2>NUL</span><br />
STDOUT message</span><br />
<span style="color: lime; font-family: "courier new"; font-size: large;"></span><br />
<span style="color: lime; font-family: "courier new"; font-size: large;">D:\test></span><span style="color: lime; font-family: "courier new" , "courier" , monospace; font-size: large;"><br />
</span></td></tr>
</tbody></table>
<br />
<h3>
Redirect both stdout and stderr to a file</h3>
You may combine > and 2> to redirect both stdout and stderr<br />
<br />
<table style="width: 100%;"><tbody>
<tr style="background-color: #0f0f0f;"><td><br />
<span style="color: lime; font-family: "courier new" , "courier" , monospace; font-size: large;"><br />
D:\test><span style="color: white;">TestStdout.exe >out.txt 2>err.txt</span></span><br />
<br />
<span style="color: lime; font-family: "courier new" , "courier" , monospace; font-size: large;">D:\test><br />
</span></td></tr>
</tbody></table>
<br />
It is also possible to redirect both stdout and stderr to the <strong>same file</strong> by using<strong> <span style="color: red;">2>&1</span></strong> to first redirect stderr to stdout (&1 is in fact stdout) and redirect stdout to a file.<br />
<br />
<table style="width: 100%;"><tbody>
<tr style="background-color: #0f0f0f;"><td><br />
<span style="color: lime; font-family: "courier new" , "courier" , monospace; font-size: large;"><br />
D:\test><span style="color: white;">TestStdout.exe >OutAndErr.txt 2>&1</span></span><br />
<br />
<span style="color: lime; font-family: "courier new" , "courier" , monospace; font-size: large;">D:\test><span style="color: white;">type OutAndErr.txt</span><br />
STDERR message<br />
STDOUT message</span><br />
<br />
<span style="color: lime; font-family: "courier new" , "courier" , monospace; font-size: large;">D:\test> <br />
</span></td></tr>
</tbody></table>
<br />
<h2>
Redirecting to the clipboard</h2>
On Windows sytsems, it is possible to redirect directly to the clipboard instead of redirecting to a file (thank yo to <a href="http://www.hanselman.com/blog/ForgottenButAwesomeWindowsCommandPromptFeatures.aspx" target="_blank">Scott Hanselman</a> for this trick ) by using<span style="color: red;"><strong> | clip</strong></span><br />
<br />
<h3>
You can redirect stdout to the clipboard</h3>
<table style="width: 100%;"><tbody>
<tr style="background-color: #0f0f0f;"><td><br />
<span style="color: lime; font-family: "courier new" , "courier" , monospace; font-size: large;"><br />
D:\test><span style="color: white;">TestStdout.exe |clip</span><br />
STDERR message</span><br />
<span style="color: lime; font-family: "courier new"; font-size: large;"></span><br />
<span style="color: lime; font-family: "courier new" , "courier" , monospace; font-size: large;">D:\test></span><br />
<span style="color: lime; font-family: "courier new" , "courier" , monospace; font-size: large;"> </span></td></tr>
</tbody></table>
<br />
<h3>
You can redirect both stdout and stderr to the clipboard by first redirecting stderr to stdout </h3>
<table style="width: 100%;"><tbody>
<tr style="background-color: #0f0f0f;"><td><br />
<span style="color: lime; font-family: "courier new" , "courier" , monospace; font-size: large;"><br />
D:\test><span style="color: white;">TestStdout.exe 2>&1 |clip</span></span><br />
<span style="color: lime; font-family: "courier new"; font-size: large;"></span><br />
<span style="color: lime; font-family: "courier new" , "courier" , monospace; font-size: large;">D:\test></span><span style="color: lime; font-family: "courier new" , "courier" , monospace; font-size: large;"><br />
</span></td></tr>
</tbody></table>
<br />
<h3>
You can redirect only stderr to the clipboard</h3>
But this is tricky: you have to redirect stderr to stdout and stdout to null and pipe to clip. Warning swapping the operations does not get the correct result.<br />
<table style="width: 100%;"><tbody>
<tr style="background-color: #0f0f0f;"><td><br />
<span style="color: lime; font-family: "courier new" , "courier" , monospace; font-size: large;"><br />
D:\test><span style="color: white;">TestStdout.exe 2>&1 >NUL |clip</span></span><br />
<span style="color: lime; font-family: "courier new"; font-size: large;"></span><br />
<span style="color: lime; font-family: "courier new" , "courier" , monospace; font-size: large;">D:\test></span><span style="color: lime; font-family: "courier new" , "courier" , monospace; font-size: large;"><br />
</span></td></tr>
</tbody></table>
thinkingIn16Bitshttp://www.blogger.com/profile/16782553204614961567noreply@blogger.com0tag:blogger.com,1999:blog-1533381118607780865.post-1135880253918004462016-02-28T06:09:00.002-08:002016-02-28T07:43:50.792-08:00Connecting multiple LCD displays to an Arduino<h2>
The LCD Display</h2>
The LCD Display based on Hitachi HD (or equivalent) have been around for many years. They are a very popular way to display information on any microcontroller circuit. <br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiih274hq5xIImTgWXemImnQ3B-2fWdBopKWgck5tnLjjxoCVBMU4PmCpgeRzp0MR1ErXtbVxL-WNIpMemK8M8dtd7UGXEvaYkyhEws1eW5qEpdBPfoHOYxUgpi0fzBetQgSheERn5BG2A/s1600/LcdDisplay.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="152" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiih274hq5xIImTgWXemImnQ3B-2fWdBopKWgck5tnLjjxoCVBMU4PmCpgeRzp0MR1ErXtbVxL-WNIpMemK8M8dtd7UGXEvaYkyhEws1eW5qEpdBPfoHOYxUgpi0fzBetQgSheERn5BG2A/s320/LcdDisplay.png" width="320" /></a></div>
<br />
<br />
They are available from many manufacturer and are in various display size. The usual size is 16x2 characters but you can find variants in 40x2 characters or 16x4 characters.<br />
<br />
The display includes the full circuitry to drive the display and interface with the microcontroller.<br />
<br />
<h2>
Interfacing with the Arduino</h2>
Interfacing with the Arduino is very straight forward and very well documented in <a href="http://www.arduino.cc/en/Tutorial/HelloWorld" rel="nofollow" target="_blank">www.arduino.cc/en/Tutorial/HelloWorld</a><br />
<br />
The schematic is quite simple:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUxTa00oFqBU4HU2o3hvsEzDerQ8e3siw7KqbuxJcpHFofBaNb0Pt3OIzgcCbrXlA8Oz5CqF-cE9G7HP0YdWFcNqYIhjmDy1bPJ9nfDhcVgXvw1wthgH9WXVN7V6Fp3FoaSnTzPeUIV6I/s1600/Arduino1LCD.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="569" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUxTa00oFqBU4HU2o3hvsEzDerQ8e3siw7KqbuxJcpHFofBaNb0Pt3OIzgcCbrXlA8Oz5CqF-cE9G7HP0YdWFcNqYIhjmDy1bPJ9nfDhcVgXvw1wthgH9WXVN7V6Fp3FoaSnTzPeUIV6I/s640/Arduino1LCD.PNG" width="640" /></a></div>
<br />
We can limit the number of wires used on the Arduino by using a 4 bits interface instead of 8 bits and hardwiring the R/W pin to VSS since we don't need to read back information for the display.<br />
<br />
This means that the interface is reduced to 4 data bits (DB4...DB7) and the 2 control wires: RS and E.<br />
RS is used to select the register where the data shall be written (one register is used to display text and the other one is used to control the display behaviour) . The E wire is used to perform the actual data write operation.<br />
<br />
To access the LCD display from the Arduino sketch we use an object of the LiquidCrystal class (for the standard Arduino library LiquidCrystal.h) by creating it with the correct pin assignation: <br />
<br />
<div style="text-align: center;">
<span style="font-family: "courier new" , "courier" , monospace;"> lcd<span class="br0">(</span><span class="nu0">12</span><span class="sy0">,</span> <span class="nu0">10</span><span class="sy0">,</span> <span class="nu0">5</span><span class="sy0">,</span> <span class="nu0">4</span><span class="sy0">,</span> <span class="nu0">3</span><span class="sy0">,</span> <span class="nu0">2</span><span class="br0">)</span><span class="sy0">;</span></span></div>
<br />
<strong>Warning</strong>: When wiring the display, check carefully the manufacturer datasheet to find the correct pinout. Every manufacturer agrees that there are 14 pins to control the LCD + 2 pins to control the backlight but the exact pin assignation varies slightly from a manufacturer to another.<br />
<br />
<h2>
Multiple Displays</h2>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglqY0me6nGuBNpCJLnJQcrIV3XDtFb53plY3e6EUvRVaIS4AQXWnR-YThMcmLzFEr1rgIDHt-LjhJCgr-MKAo3F7c_klK_ryI0r4Aus66SCj7oq0xFnES34tLJcR_xzGpwET59a6XpCDE/s1600/2lcd.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglqY0me6nGuBNpCJLnJQcrIV3XDtFb53plY3e6EUvRVaIS4AQXWnR-YThMcmLzFEr1rgIDHt-LjhJCgr-MKAo3F7c_klK_ryI0r4Aus66SCj7oq0xFnES34tLJcR_xzGpwET59a6XpCDE/s320/2lcd.jpg" width="320" /></a></div>
<br />
Now we want to connect one (or more) additional displays to the Arduino<br />
<br />
As explained above the LCD display takes the data into account only when the E pin is activated. This means that you can connect all the displays signals in parallel on the Arduino digital outputs as long as you keep the E signals separated.<br />
<br />
In the schematics below I have used digital output D10 to control E signal of LCD1 and output D11 to control E signal of LCD2<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_B1NMm1-ur5ni_UKkS-kK0LRoGtn45U90V59x3NhhwCgCooRmSApBAOb1JhRemMez5WxBCb1B11GZVWDFSJz_vppB4DoUGRPrW7A1Xg39nUJdLMWK9dIqE1oYSK_zn0nRUj9CIq_PHo4/s1600/Arduino2LCD.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="603" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_B1NMm1-ur5ni_UKkS-kK0LRoGtn45U90V59x3NhhwCgCooRmSApBAOb1JhRemMez5WxBCb1B11GZVWDFSJz_vppB4DoUGRPrW7A1Xg39nUJdLMWK9dIqE1oYSK_zn0nRUj9CIq_PHo4/s640/Arduino2LCD.PNG" width="640" /></a></div>
<br />
<h2>
The Software</h2>
The Arduino sketch to control multiple displays is very similar to the one used to control one display.<br />
<br />
You simply have to create one object of the LiquidCrystal class for each display. I have found that the easiest way to do it is to store them in array by using the following code:<br />
<span style="color: blue;"> </span><br />
<span style="color: blue; font-family: "courier new" , "courier" , monospace; font-size: x-small;">LiquidCrystal lcd[2]={LiquidCrystal(12, 11, 5, 4, 3, 2), LiquidCrystal(12, 10, 5, 4, 3, 2)};</span><br />
<br />
<br />
This allows to easily select on which display to print (or to send any command) as shown in the very simple "Hello World" example below.<br />
<br />
warning, since arrays begin at index zero, the 2 LCD displays shall be numbered zero and on1 (instead of one and two).<br />
<br />
<span lang=""><span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">/*</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">
This sketch prints "Hello World!" on 2 LCD displays</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">
The circuit:</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">
* LCD RS pin to digital pin 12</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">
* LCD Enable pin to digital pin 11 for LCD1 pin 10 for LCD 0</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">
* LCD D4 pin to digital pin 5</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">
* LCD D5 pin to digital pin 4</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">
* LCD D6 pin to digital pin 3</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">
* LCD D7 pin to digital pin 2</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">
* LCD R/W pin to ground</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">
* LCD VSS pin to ground</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">
* LCD VCC pin to 5V</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">
* 10K pot</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">
* ends to +5V and ground</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">
* wiper to LCD VO pin</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">
*/</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">
</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">// Directly based on the Arduino example LiquidCrystal HelloWorld</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">
</span></span><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: xx-small;"><span style="color: blue;"><span style="color: blue;">#include</span></span> <span style="color: #a31515;"><span style="color: #a31515;"><LiquidCrystal.h></span></span></span></span><br />
<span style="color: #a31515;"><span style="color: #a31515; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">
</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">LiquidCrystal lcd[2] = { LiquidCrystal(12, 11, 5, 4, 3, 2),LiquidCrystal(12, 10, 5, 4, 3, 2) };</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">
</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: xx-small;"><span style="color: blue;"><span style="color: blue;">void</span></span> setup() {</span></span><br />
<span style="color: green;"><span style="color: green; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">// set up the LCD's number of columns and rows:</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">lcd[0].begin(16, 2);</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">
lcd[1].begin(16, 2);</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">
lcd[0].setCursor(0, 0);</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"></span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">lcd[0].print(<span style="color: #a31515;"><span style="color: #a31515;">"Hello"</span></span>);</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">lcd[1].setCursor(0, 0);</span><span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"></span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">lcd[1].print(<span style="color: #a31515;"><span style="color: #a31515;">"World!"</span></span>);</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">}</span><br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">
</span><br />
<span style="color: blue;"><span style="color: blue;"></span></span><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: xx-small;"><span style="color: blue;"><span style="color: blue;">void</span></span> loop() {</span></span><br />
<span style="font-size: x-small;"><span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">}</span><br />
</span>thinkingIn16Bitshttp://www.blogger.com/profile/16782553204614961567noreply@blogger.com0tag:blogger.com,1999:blog-1533381118607780865.post-35281520446076687472015-11-30T13:39:00.002-08:002015-12-02T16:09:52.799-08:00GPIO pins allocation under windows 10 IOT build on Raspberry PIThe Windows 10 IOT documentation <a href="https://ms-iot.github.io/content/en-US/win10/samples/PinMappingsRPi2.htm">https://ms-iot.github.io/</a><br />
indicates that only the following pins are available 4,5,6,12,13,16,17,18,19,20,21,22,23,24,25,26,27 for GPIO.<br />
<br />
<div style="margin-bottom: 0cm;">
If you wonder why so many pins are not usable as GPIO. This is because </div>
<div style="margin-bottom: 0cm;">
<ul>
<li>GPIO 2, and 3 are reserved for I2C interface</li>
<li>GPIO 7,8,9,10,11 are reserved for SPIO interface</li>
<li>GPIO 14,15 are reserved for UART interface.</li>
</ul>
</div>
<br />
<br />
<div style="margin-bottom: 0cm;">
<strong>Note</strong> that 35 and 47 are also available but they drive LEDs soldered on the board and not pins on the GPIO connector.</div>
<br />
<div style="margin-bottom: 0cm;">
If you are still using <strong>Windows10 IOT build 10.0.10240</strong> you must know that for some unknown reasons the Raspberry PI GPIO pins 17, 19, 20, 21 are not usable. I think this is a very good reason to update to build 10.0.10556.</div>
<h3 style="margin-bottom: 0cm;">
</h3>
<h3 style="margin-bottom: 0cm;">
Program To list all the available GPIOs</h3>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
I have developed a small program that list all the available GPIOs.</div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
The XAML is the following</div>
<div style="margin-bottom: 0cm;">
</div>
<br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New", Courier, monospace;"><Page</span><br />
<div style="margin-bottom: 0cm;">
<span style="font-family: "Courier New", Courier, monospace;">x:Class="CountGPIO.MainPage"</span></div>
<div style="margin-bottom: 0cm;">
<span style="font-family: "Courier New", Courier, monospace;">xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span></div>
<div style="margin-bottom: 0cm;">
<span style="font-family: "Courier New", Courier, monospace;">xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"</span></div>
<div style="margin-bottom: 0cm;">
<span style="font-family: "Courier New", Courier, monospace;">xmlns:local="using:CountGPIO"</span></div>
<div style="margin-bottom: 0cm;">
<span style="font-family: "Courier New", Courier, monospace;">xmlns:d="http://schemas.microsoft.com/expression/blend/2008"</span></div>
<div style="margin-bottom: 0cm;">
<span style="font-family: "Courier New", Courier, monospace;">xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"</span></div>
<div style="margin-bottom: 0cm;">
<span style="font-family: "Courier New", Courier, monospace;">mc:Ignorable="d"></span></div>
<div style="margin-bottom: 0cm;">
<span style="font-family: "Courier New", Courier, monospace;"> </span></div>
<span style="font-family: "Courier New", Courier, monospace;"><Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"></span><br />
<div style="margin-bottom: 0cm;">
<span style="font-family: "Courier New", Courier, monospace;"><TextBlock x:Name="TextblockOutput" HorizontalAlignment="Center" VerticalAlignment="Center" /></span></div>
<div style="margin-bottom: 0cm;">
<span style="font-family: "Courier New", Courier, monospace;"></Grid></span></div>
<div style="margin-bottom: 0cm;">
<span style="font-family: "Courier New", Courier, monospace;"></Page></span></div>
</blockquote>
<br />
<div style="margin-bottom: 0cm;">
<span style="background-color: white;"> </span></div>
<div style="margin-bottom: 0cm;">
<span style="background-color: white;"> </span></div>
<div style="margin-bottom: 0cm;">
<span style="background-color: white;">And the C# code associated</span></div>
<div style="margin-bottom: 0cm;">
<span style="background-color: white;"> </span></div>
<span style="font-family: "consolas"; font-size: x-small;"></span><br />
<blockquote class="tr_bq">
<span style="font-family: "Courier New", Courier, monospace;">using System;</span><br />
<span style="font-family: "Courier New", Courier, monospace;"> using Windows.Devices.Gpio;</span><br />
<span style="font-family: "Courier New", Courier, monospace;"> using Windows.UI.Xaml.Controls;</span><br />
<span style="font-family: "Courier New", Courier, monospace;"> namespace CountGPIO</span><br />
<span style="font-family: "Courier New", Courier, monospace;"> {<br />
public sealed partial class MainPage : Page</span><br />
<span style="font-family: "Courier New", Courier, monospace;"> {<br />
private GpioController gpio;</span><br />
<span style="font-family: "Courier New", Courier, monospace;"> public MainPage()</span><br />
<span style="font-family: "Courier New", Courier, monospace;"> {<br />
this.InitializeComponent();</span><br />
<span style="font-family: "Courier New", Courier, monospace;"> gpio = GpioController.GetDefault();</span><br />
<span style="font-family: "Courier New", Courier, monospace;"> this.TextblockOutput.Text = "List of Supported GPIO pins:" + Environment.NewLine;</span><br />
<span style="font-family: "Courier New", Courier, monospace;"> for (int port = 0; port < 64; port++)</span><br />
<span style="font-family: "Courier New", Courier, monospace;"> {<br />
try</span><br />
<span style="font-family: "Courier New", Courier, monospace;"> {<br />
gpio.OpenPin(port);<br />
this.TextblockOutput.Text += "GPIO Pin: " + port.ToString() + " is OK" + Environment.NewLine;</span><br />
<span style="font-family: "Courier New", Courier, monospace;"> }<br />
catch (Exception)</span><br />
<span style="font-family: "Courier New", Courier, monospace;"> { }<br />
}<br />
}<br />
}<br />
}</span> </blockquote>
<br />
<br />thinkingIn16Bitshttp://www.blogger.com/profile/16782553204614961567noreply@blogger.com0tag:blogger.com,1999:blog-1533381118607780865.post-41612196495148107042015-11-15T15:08:00.001-08:002015-11-15T15:08:03.244-08:00How to use a PC To Connect a Raspberry PI to a WIFI network
<br />
<h2 style="margin-bottom: 0cm;">
Introduction</h2>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
The problem is the following : I
am using have a standard Raspberry PI (i.e. without any WIFI
interface) at a location where the only way to access the Internet is
the WIFI. Is it possible to use my portable PC running Windows as a
router to connect the Raspberry PI to the Internet ?</div>
<div style="margin-bottom: 0cm;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbFxwBP9IiwLqkkaUWBpbV8_axFye8ubnZ5Zrm1W_uWeU-PvwiLjARRD0KkSkef4mhWvNkvtSHZiUOJM9D8EiN93mPy8RHWShxR5MrUg8DSUIHsjd3Ea68Hlw1GZ78X7B6De9QCjkzLzI/s1600/wifi4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="302" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbFxwBP9IiwLqkkaUWBpbV8_axFye8ubnZ5Zrm1W_uWeU-PvwiLjARRD0KkSkef4mhWvNkvtSHZiUOJM9D8EiN93mPy8RHWShxR5MrUg8DSUIHsjd3Ea68Hlw1GZ78X7B6De9QCjkzLzI/s640/wifi4.png" width="640" /></a></div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
The answer is <b>YES</b> and it is very
<b>easy</b></div>
<div style="margin-bottom: 0cm;">
<strong></strong> </div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
</div>
<h2 style="margin-bottom: 0cm;">
Step1: Activate ICS</h2>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
Activate the ICS on the WIFI connection
of the Windows computer. The ICS (Internet Connection Sharing) allows
other computers to use the WIFI connection of the Windows computer.
</div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
This is done in the network
control panel (you may reach it by using the command)
</div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm; text-align: center;">
<span style="font-family: Courier New, monospace;"><span style="background-color: yellow; font-size: large;">control
ncpa.cpl</span> </span></div>
<div style="margin-bottom: 0cm;">
</div>
Then select properties on the WIFI network<br />
<div style="margin-bottom: 0cm;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6PDx9ygGYEMaHQIFT7DiJ0LSEL1RhxkpIQWabg1v4Brw4jK4BU1oVtN2suPn5Tq1UO_PHRxGSB8xpn4wDpM1T1IZ9TGR3HwiZ-EBMK7HRv2sYw3eIeVqcQ1Q7uQs2k2_xXvroi-jnlQ4/s1600/wifi1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="background-color: white;"><img border="0" height="392" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6PDx9ygGYEMaHQIFT7DiJ0LSEL1RhxkpIQWabg1v4Brw4jK4BU1oVtN2suPn5Tq1UO_PHRxGSB8xpn4wDpM1T1IZ9TGR3HwiZ-EBMK7HRv2sYw3eIeVqcQ1Q7uQs2k2_xXvroi-jnlQ4/s640/wifi1.png" width="640" /></span></a></div>
<div style="margin-bottom: 0cm;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div style="margin-bottom: 0cm;">
<br />
</div>
<div style="margin-bottom: 0cm;">
And then activate the sharing of the
the WIFI connection</div>
<div style="margin-bottom: 0cm;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnKOB_9yaUxnNiSTSI5y7uzLcvZXm0jWrWYLJdlpQ6GL03q3DUgytXyABDkmn4QJaF-Bt24QtdA8v9L2ttRHfXA8bRUUl5i0CFsDVMH7QX3ZufCRQxk0T6MpWaqgnCnoGDM4CNLga7QS0/s1600/wifi2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnKOB_9yaUxnNiSTSI5y7uzLcvZXm0jWrWYLJdlpQ6GL03q3DUgytXyABDkmn4QJaF-Bt24QtdA8v9L2ttRHfXA8bRUUl5i0CFsDVMH7QX3ZufCRQxk0T6MpWaqgnCnoGDM4CNLga7QS0/s400/wifi2.png" width="373" /></a></div>
<div align="left" class="separator" style="clear: both; text-align: center;">
</div>
<div style="margin-bottom: 0cm;">
Once this is done any computer connected
to the PC ethernet port shall receive via DHCP an IP address in the
192.168.137.X network (note the PC is located at 192.168.137.1)</div>
<div align="left" class="separator" style="clear: both; text-align: center;">
</div>
<div align="left" class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjroQSlCc502XNClH9ytuCgUtT-EgMExVielhYNSbR_JJ8N5Zl6XJz-wj2MrnY6RYMCqiXHyeiFAYkb-mH3gWQUz7x9LAvwDti35CUawTUhosGrPx8T3lduevUhzhPqmNxAC6FueYCTeYg/s1600/wifi5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="302" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjroQSlCc502XNClH9ytuCgUtT-EgMExVielhYNSbR_JJ8N5Zl6XJz-wj2MrnY6RYMCqiXHyeiFAYkb-mH3gWQUz7x9LAvwDti35CUawTUhosGrPx8T3lduevUhzhPqmNxAC6FueYCTeYg/s640/wifi5.png" width="640" /></a></div>
<div align="left" class="separator" style="clear: both; text-align: center;">
</div>
<div align="left" class="separator" style="clear: both; text-align: center;">
</div>
<div align="left" class="separator" style="clear: both; text-align: center;">
</div>
<h2 style="margin-bottom: 0cm;">
Step2 Connect the Raspberry PI to the PC</h2>
<div style="margin-bottom: 0cm;">
<br />
</div>
<div style="margin-bottom: 0cm;">
Connect the Raspberry PI with a standard
Ethernet cable equipped with standard RJ45 connectors). You don't
even need a crossed cable because the Raspberry PI support auto MDI-X
(which means that the Raspberry PI will detect that a crossed cable
is needed and automatically preform the « cross »
internally) .</div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
Now everything is done and your
raspberry PI can access the Internet. But If You don't have keyboard
and display connected to it you need to know which IP address the
Windows PC DHCP has given to it.</div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
</div>
<h2 style="margin-bottom: 0cm;">
Step 3 retrieve the Raspberry PI IP
address</h2>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
The simplest way to obtain this address
is to query the ARP table. Start a Windows command prompt (if you
don't know how to do it just press WINDOWS+R and type cmp ENTER)</div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
and type the following command</div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm; text-align: center;">
<span style="background-color: yellow;">arp -a -N 192.168.137.1</span></div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
This will give you a reply that looks
like that</div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMYC52UMaGwY2eowagrDY4Vby5_-bveKUvzY-rvfOawAlcv0pYYzYiKsSPeLzzE38c7C441Dsh2b_y2vJl09bYtqbzfB4OoQaBBKgH0ZY5YoAisEV0uo8-gTq02hJQXUkP3LMkWmZAVMQ/s1600/wifi6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="408" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMYC52UMaGwY2eowagrDY4Vby5_-bveKUvzY-rvfOawAlcv0pYYzYiKsSPeLzzE38c7C441Dsh2b_y2vJl09bYtqbzfB4OoQaBBKgH0ZY5YoAisEV0uo8-gTq02hJQXUkP3LMkWmZAVMQ/s640/wifi6.png" width="640" /></a></div>
<div style="margin-bottom: 0cm;">
<span style="font-family: Courier New, monospace;"></span> </div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
In this list you see that the Rasberry
PI has been granted the addres 192.168.137.55</div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
<em>Note : the 192,168,137,255, all
the 224.x.x.x and the 239.255.255.250 addresses are all multicast
addresses (we don't care about them)</em></div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
You can now connect to you Rasberry PI
via SSH and from the Raspberry PI communicate with the Internet.</div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLrCQZnw71ElbMi0t8eG9CRDETjH2Q0HAtQfh65HwDY1B-8l2TYb3MWdrFgYxS3_cEuwPy7D1YDCKzq04A83IkYfR77H0UpBz0QHcAEMXVjvS8t9iK5mqAsihyphenhyphenqPZs7GaiIZUOAX-uRHs/s1600/wifi3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="566" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLrCQZnw71ElbMi0t8eG9CRDETjH2Q0HAtQfh65HwDY1B-8l2TYb3MWdrFgYxS3_cEuwPy7D1YDCKzq04A83IkYfR77H0UpBz0QHcAEMXVjvS8t9iK5mqAsihyphenhyphenqPZs7GaiIZUOAX-uRHs/s640/wifi3.png" width="640" /></a></div>
<div align="left" class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: left;">
</div>
thinkingIn16Bitshttp://www.blogger.com/profile/16782553204614961567noreply@blogger.com0tag:blogger.com,1999:blog-1533381118607780865.post-75937318986179797872015-10-18T15:58:00.002-07:002015-10-18T15:58:47.460-07:00How to connect a PC to the Arduino Yun<h2>
Introduction</h2>
<br />
<div style="margin-bottom: 0cm;">
The Arduino Yun board is a relatively new member
of the Arduino family.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgq56id6BAOG3rTYTgSJ53FrWJwc-sR2Frpposi9smR_QfPMoVbJ4t5ZN2et3AzTRB1FJA9Gv0mQbN8wPRE4V_EOgqn2a6EJ1gJ47_Uo4Wcyhr_0veE7Am9IjdHqDE4h8YqtRaOwrp_6U8/s1600/Yun.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="257" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgq56id6BAOG3rTYTgSJ53FrWJwc-sR2Frpposi9smR_QfPMoVbJ4t5ZN2et3AzTRB1FJA9Gv0mQbN8wPRE4V_EOgqn2a6EJ1gJ47_Uo4Wcyhr_0veE7Am9IjdHqDE4h8YqtRaOwrp_6U8/s320/Yun.png" width="320" /></a></div>
<div style="margin-bottom: 0cm;">
</div>
<br />
<div style="margin-bottom: 0cm;">
It is similar to a Leonardo board (
i.e. An Arduino board with a Atmega32 processor) except that it has
an additional processor (Atheros AR9331) running Linux (OpenWRT) , a
microSD disk connector and many additional interfaces.</div>
<br />
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
The Arduino Yun has many interfaces
(not counting the usual Arduino connectors). There is a USB device
micro type B connector, there is
a USB host (Type A Connector). There is a wired Ethernet and there is
also a possibility to connect via Wifi.</div>
<div style="margin-bottom: 0cm;">
</div>
<h2 style="margin-bottom: 0cm;">
The USB Device Connector</h2>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCGx3_Rl40lluxraWJMoZzikQNytjYMGm6HrZERPwmgwj09IMGj3UFxJ6ytlKTBC-l2yP_su5FHEZySRsJCusuSbad81c6uT_yzlAuY5lZHuaN2gcTxp2Js1VXh7OskWV2vNZx2hAD-VM/s1600/usbB.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="217" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCGx3_Rl40lluxraWJMoZzikQNytjYMGm6HrZERPwmgwj09IMGj3UFxJ6ytlKTBC-l2yP_su5FHEZySRsJCusuSbad81c6uT_yzlAuY5lZHuaN2gcTxp2Js1VXh7OskWV2vNZx2hAD-VM/s320/usbB.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div style="margin-bottom: 0cm;">
This connector is the « standard »
connector that we are used to see on every Arduino board except that
it is a micro connector (like the one found on a smart phone) instead
of a standard Type B connector.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div style="margin-bottom: 0cm;">
As on an ordinary Arduino UNO you can use this
connector to power the Arduino Yun board.
</div>
<div style="margin-bottom: 0cm;">
From the PC connected to the Yun board,
this USB port appears as a standard COM port</div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdV7HK73aFZ0kvfmz5cNwOfLSip7R0kpGkoN7sinCjSYZ04gW7wy_qGX8-OWBNwOv7u5S-f7_nFWVzn3dRriPhbvHNFnjbTlYfI6okngf28hGmg07L0gFW8y30Gpyv7DL27XtHZXZxYfM/s1600/arduinoCOM3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdV7HK73aFZ0kvfmz5cNwOfLSip7R0kpGkoN7sinCjSYZ04gW7wy_qGX8-OWBNwOv7u5S-f7_nFWVzn3dRriPhbvHNFnjbTlYfI6okngf28hGmg07L0gFW8y30Gpyv7DL27XtHZXZxYfM/s640/arduinoCOM3.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div style="margin-bottom: 0cm;">
As usual with Arduino boards, you may
use this COM port to transfer a compiled sketch to the board and, a
running sketch may use it to communicate using the well known serial
class <a href="http://www.arduino.cc/en/Reference/Serial">www.arduino.cc/en/Reference/Serial</a></div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDVSWnRoz8QWChAQeaids2jOaZ1OZTP_Vd3hF22iDZGHyvR99DssYcUhC61VQQTShCPLghLf56r45gyTgCzsLVTnWWzcwtslQ4V3FGWbhulmrdiEdbCTUU9OQez3yh-Hkz8-0gmaxkFsc/s1600/SerialArduionCom.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="576" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDVSWnRoz8QWChAQeaids2jOaZ1OZTP_Vd3hF22iDZGHyvR99DssYcUhC61VQQTShCPLghLf56r45gyTgCzsLVTnWWzcwtslQ4V3FGWbhulmrdiEdbCTUU9OQez3yh-Hkz8-0gmaxkFsc/s640/SerialArduionCom.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<h2 style="margin-bottom: 0cm;">
The USB Host connector</h2>
<div style="margin-bottom: 0cm;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4Q_iJ28j2yH6DGi0wsTeiL7FZhKqDHxAkN-hrDLgiaIBJGc8ENY0qXyHFSwDaDhYE6zp2EKWIj3ATgSW1LSqXPlmkXygLMJNjQi9ijjoe9_ofbshS8LLrpSVBzFjXnYbBwjYCFhOYji8/s1600/usbA.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="210" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4Q_iJ28j2yH6DGi0wsTeiL7FZhKqDHxAkN-hrDLgiaIBJGc8ENY0qXyHFSwDaDhYE6zp2EKWIj3ATgSW1LSqXPlmkXygLMJNjQi9ijjoe9_ofbshS8LLrpSVBzFjXnYbBwjYCFhOYji8/s320/usbA.png" width="320" /></a></div>
<div style="margin-bottom: 0cm;">
</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div style="margin-bottom: 0cm;">
This is a full size type A connector
for connecting devices like USB keyboards, or mouse to the Yun. I
have not yet experimented with it So I cannot say much about it. Just
note that this port is connected to the Atheros AR9331 so it is
controlled from LINUX. Which does not mean that the Atmega processor
cannot acces it indirectly by going through the bridge that connects
the 2 processors together.</div>
<div style="margin-bottom: 0cm;">
</div>
<h2 style="margin-bottom: 0cm;">
The Wired Ethernet</h2>
<div style="margin-bottom: 0cm;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhImPufnWkT89b8JODKx6pOl9wtqK3MrZ_PZg8a9cW90J0NF1ddglF0rX2RR1nBNFdlSgE2PXZme21_8FTDOVejIgA3MXzWGl8FfxQpLBTGm-4S2ZkTRZaTQuR0wh3mQDIIrjdz9hWh0YU/s1600/ethernet.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="210" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhImPufnWkT89b8JODKx6pOl9wtqK3MrZ_PZg8a9cW90J0NF1ddglF0rX2RR1nBNFdlSgE2PXZme21_8FTDOVejIgA3MXzWGl8FfxQpLBTGm-4S2ZkTRZaTQuR0wh3mQDIIrjdz9hWh0YU/s320/ethernet.png" width="320" /></a></div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
Note: when using the Ethernet connection, don't forget to power your Yun board
(if you don't use PoE) either via the USB micro connector or via the
Vin pin (be careful with polarity an voltage).</div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
Once the board is connected you need to
know its IP address. The easiest way is to ask to your DHCP
server/router the list of connected devices.</div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
But you can also retrieve et IP address
with this simple sketch (that you will have to upload via USB).</div>
<div style="margin-bottom: 0cm;">
</div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "Courier New", Courier, monospace;"><span style="font-size: x-small;"></span></span> </div>
<div style="margin-bottom: 0cm;">
<br />
<div style="background: rgb(255, 255, 102); margin-bottom: 0cm;">
<span style="font-family: Courier New, monospace;">#include
<Process.h></span></div>
<div style="background: rgb(255, 255, 102); margin-bottom: 0cm;">
</div>
<div style="background: rgb(255, 255, 102); margin-bottom: 0cm;">
<span style="font-family: Courier New, monospace;">void
setup() {</span></div>
<div style="background: rgb(255, 255, 102); margin-bottom: 0cm;">
<span style="font-family: Courier New, monospace;">//
Initialize Bridge</span></div>
<div style="background: rgb(255, 255, 102); margin-bottom: 0cm;">
<span style="font-family: Courier New, monospace;">Bridge.begin();</span></div>
<div style="background: rgb(255, 255, 102); margin-bottom: 0cm;">
</div>
<div style="background: rgb(255, 255, 102); margin-bottom: 0cm;">
<span style="font-family: Courier New, monospace;">//
Initialize Serial</span></div>
<div style="background: rgb(255, 255, 102); margin-bottom: 0cm;">
<span style="font-family: Courier New, monospace;">Serial.begin(9600);</span></div>
<div style="background: rgb(255, 255, 102); margin-bottom: 0cm;">
</div>
<div style="background: rgb(255, 255, 102); margin-bottom: 0cm;">
<span style="font-family: Courier New, monospace;">//
Wait until a Serial Monitor is connected.</span></div>
<div style="background: rgb(255, 255, 102); margin-bottom: 0cm;">
<span style="font-family: Courier New, monospace;">while
(!Serial);</span></div>
<div style="background: rgb(255, 255, 102); margin-bottom: 0cm;">
</div>
<div style="background: rgb(255, 255, 102); margin-bottom: 0cm;">
<span style="font-family: Courier New, monospace;">Process
p; </span></div>
<div style="background: rgb(255, 255, 102); margin-bottom: 0cm;">
<span style="font-family: Courier New, monospace;">p.begin("ifconfig");
</span></div>
<div style="background: rgb(255, 255, 102); margin-bottom: 0cm;">
<span style="font-family: Courier New, monospace;">p.addParameter("-a");
// -a list all IP ports. Replace it by eth1 if you only </span></div>
<div style="background: rgb(255, 255, 102); margin-bottom: 0cm;">
<span style="font-family: Courier New, monospace;">// want the
wired Ethernet</span></div>
<div style="background: rgb(255, 255, 102); margin-bottom: 0cm;">
<span style="font-family: Courier New, monospace;">p.run();
// Run the process and wait for its termination</span></div>
<div style="background: rgb(255, 255, 102); margin-bottom: 0cm;">
</div>
<div style="background: rgb(255, 255, 102); margin-bottom: 0cm;">
<span style="font-family: Courier New, monospace;">while
(p.available()>0) {</span></div>
<div style="background: rgb(255, 255, 102); margin-bottom: 0cm;">
<span style="font-family: Courier New, monospace;">char
c = p.read();</span></div>
<div style="background: rgb(255, 255, 102); margin-bottom: 0cm;">
<span style="font-family: Courier New, monospace;">Serial.print(c);</span></div>
<div style="background: rgb(255, 255, 102); margin-bottom: 0cm;">
<span style="font-family: Courier New, monospace;">}</span></div>
<div style="background: rgb(255, 255, 102); margin-bottom: 0cm;">
</div>
<div style="background: rgb(255, 255, 102); margin-bottom: 0cm;">
<span style="font-family: Courier New, monospace;">Serial.flush();</span></div>
<div style="background: rgb(255, 255, 102); margin-bottom: 0cm;">
<span style="font-family: Courier New, monospace;">}</span></div>
<div style="background: rgb(255, 255, 102); margin-bottom: 0cm;">
</div>
<div style="background: rgb(255, 255, 102); margin-bottom: 0cm;">
<span style="font-family: Courier New, monospace;">void
loop() {</span></div>
<div style="background: rgb(255, 255, 102); margin-bottom: 0cm;">
<span style="font-family: Courier New, monospace;">//do
nothing </span></div>
<div style="background: rgb(255, 255, 102); margin-bottom: 0cm;">
<span style="font-family: Courier New, monospace;">}</span></div>
<br />
<div style="margin-bottom: 0cm;">
The script result lista all the IP adresses used by the Yun board.<br />
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRfzDWxL4hoGMjYZJmg7XTkybtcnJfZ3_1QqKAotZyrnkngLCtsq3AgNoTQ7k9qE0y3m8zb23wCALt5Or53z5T3sDIoVpIo__fXGaY0_H1OtolHP0gSybi-9VtOaSOv7udQ7elA6cyRr4/s1600/ifConfig.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRfzDWxL4hoGMjYZJmg7XTkybtcnJfZ3_1QqKAotZyrnkngLCtsq3AgNoTQ7k9qE0y3m8zb23wCALt5Or53z5T3sDIoVpIo__fXGaY0_H1OtolHP0gSybi-9VtOaSOv7udQ7elA6cyRr4/s640/ifConfig.png" width="585" /></a></div>
</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div style="margin-bottom: 0cm;">
Note: Arduino Yun
assigns the wired ethernet to <strong>eth1</strong> and not eth0.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
You can then connect to the Arduino Yun
using any web browser</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div style="margin-bottom: 0cm;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjV8zSvzH1HkgK5q5xqw0mP5sv_68OlQWCJIg4CKj4EG4iuCXN3a65FA8TJA5LKfDLC2fVOPnDmNh-b0bTGWd9Wg3E5fM4e21g_7erHFQB7UPCqUdJDfJ4koK0ZcJGCNmpOOXHX9ti4D80/s1600/BrowseArduino.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="278" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjV8zSvzH1HkgK5q5xqw0mP5sv_68OlQWCJIg4CKj4EG4iuCXN3a65FA8TJA5LKfDLC2fVOPnDmNh-b0bTGWd9Wg3E5fM4e21g_7erHFQB7UPCqUdJDfJ4koK0ZcJGCNmpOOXHX9ti4D80/s400/BrowseArduino.png" width="400" /></a></div>
<br />
<br />
<div style="margin-bottom: 0cm;">
The password is « <strong>arduino</strong> »</div>
<br />
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
An arduino sketch has no acces direct
to the Ethernet port. To get acces to it You need to use the
« bridge » object.</div>
<br />
<div style="margin-bottom: 0cm;">
<br />
You may connect to the Linux terminal
running on the Atheros AR9331 by using a ssh connection (on windows,
the most popular ssh terminal is Putty (available on
<a href="http://www.putty.org/">http://www.putty.org/</a>)</div>
<br />
<div style="margin-bottom: 0cm;">
<br />
The login is <strong>root</strong> and the default
password is « <strong>arduino</strong> »</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnZcaTCSFA2R7X1_Vt9XxoSPkKooNeLqT3Gng9a7ogoBsHGmHpUpGX8ehBIgUOqPQndUbcoHCUemWCgeNnr9F0j2lShXthkvzL1IJf-acWxMKlzdNJAt_bl-um-485ZACfBrC_288HA_E/s1600/puttyprompt.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="404" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnZcaTCSFA2R7X1_Vt9XxoSPkKooNeLqT3Gng9a7ogoBsHGmHpUpGX8ehBIgUOqPQndUbcoHCUemWCgeNnr9F0j2lShXthkvzL1IJf-acWxMKlzdNJAt_bl-um-485ZACfBrC_288HA_E/s640/puttyprompt.png" width="640" /></a></div>
</div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<div style="margin-bottom: 0cm;">
This gives you access to a surprisingly
complete and powerful Linux computer.</div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<div style="margin-bottom: 0cm;">
</div>
<div class="separator" style="clear: both; text-align: left;">
It is possible to upload the sketch
using the Wired Ethernet. To do that you need to install the
« Bonjour » service and open the UDP port 5353 in your
firewall. I have not tried it because I am happy with the USB
transfer and I already have much too many services running on my PC.</div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<h2 class="separator" style="clear: both; text-align: left;">
The Wifi</h2>
<div class="separator" style="clear: both; text-align: left;">
</div>
<div style="margin-bottom: 0cm;">
The Arduino YUN is by default a Wifi
access point (i.e. a hotspot) This means that it creates a network on
which you can connect your computer.</div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
This is useful to reach the newly
bought Yun board wifi but you will probably want to reconfigure it as
a wireless adapter that connects to your Wifi network.</div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<div style="margin-bottom: 0cm;">
</div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<div style="margin-bottom: 0cm;">
To do that connect your computer or any
Wifi capable terminal (even a smartphone is ok) to the Yun Wifi
network.
</div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<div style="margin-bottom: 0cm;">
<br />
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTEw36UEYc6a2k5ySI3Bn5qLrkzOYIrQAojUaEfwM2cc3BdEnhj0OgOdsq241PD5sB5YeudghTuN6pHw06lhAjSOTgCblJZKRIVzfznHeWJY-Q42U7Pa4TtBDddsplgKZ3H6rWx043QsM/s1600/WifiConnect.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="406" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTEw36UEYc6a2k5ySI3Bn5qLrkzOYIrQAojUaEfwM2cc3BdEnhj0OgOdsq241PD5sB5YeudghTuN6pHw06lhAjSOTgCblJZKRIVzfznHeWJY-Q42U7Pa4TtBDddsplgKZ3H6rWx043QsM/s640/WifiConnect.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<div style="margin-bottom: 0cm;">
Use a browser to access the Yun board
(it's address is 192.168.240.1)</div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<div style="margin-bottom: 0cm;">
The password is « arduino »</div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<div style="margin-bottom: 0cm;">
you can then configure the Wifi port so
that it connects to your network</div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhiU3PnY_-sHaBGxR1FaifXUVu-4sYhiBAE-cYTwglh6j9zb5szjgBqxAnuvneaYrs220c5uz5es1OR_tn_NKY69BZ2SNZn51UZMeecVZE9iQH8JmP0m4PkM2dMtbRbsSmqPK1DSX-i7B8/s1600/WifiConfig.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhiU3PnY_-sHaBGxR1FaifXUVu-4sYhiBAE-cYTwglh6j9zb5szjgBqxAnuvneaYrs220c5uz5es1OR_tn_NKY69BZ2SNZn51UZMeecVZE9iQH8JmP0m4PkM2dMtbRbsSmqPK1DSX-i7B8/s640/WifiConfig.png" width="468" /></a></div>
<div style="margin-bottom: 0cm;">
<br />
</div>
<div style="margin-bottom: 0cm;">
Once it is done the Wifi behave as the
wired Ethernet (see explanation above)</div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
Note : it is possible to turn off
the Wifi. You may want to do that for security reasons. The code to
execute to turn off the Wifi is quite complex. It is available is
<a href="https://gist.github.com/sgk/6641198">https://gist.github.com/sgk/6641198</a></div>
<div style="margin-bottom: 0cm;">
</div>
<div style="margin-bottom: 0cm;">
<br />
</div>
<div style="margin-bottom: 0cm;">
</div>
<div class="separator" style="clear: both; text-align: left;">
</div>
thinkingIn16Bitshttp://www.blogger.com/profile/16782553204614961567noreply@blogger.com0tag:blogger.com,1999:blog-1533381118607780865.post-27655627774710572662015-09-10T15:33:00.000-07:002015-09-21T23:46:29.085-07:00Creating A C# Desktop Program That Must Run With Administrator Privilege<h3>
<span style="font-size: x-large;"></span>The problem</h3>
<div>
Sometimes you want that your program requires to run with "administrator" privilege. For instance, if your program needs to listen to the TCP port 80.</div>
<div>
<br /></div>
<div>
This means that you would like to have this kind of message to appear at program start to request the user to grant the program elevated privilege.</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOtY-0eaD_PvmjRa69uL7DUmsx8s6vugUfa2cst7eIWmYxPaoXJwElmsO3xlwG8Gn40CO9yr0Rs9_qQG5oaFO-vd2C8uDXzoY-Paz6b7-iua_uNYcqO6rBsAb9L8jjY8kZgk4N4aNJ6JE/s1600/admin.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="196" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOtY-0eaD_PvmjRa69uL7DUmsx8s6vugUfa2cst7eIWmYxPaoXJwElmsO3xlwG8Gn40CO9yr0Rs9_qQG5oaFO-vd2C8uDXzoY-Paz6b7-iua_uNYcqO6rBsAb9L8jjY8kZgk4N4aNJ6JE/s320/admin.png" width="320" /></a></div>
<h3>
</h3>
<h3>
The solution</h3>
It is possible to specify in Visual Studio to specify that an executable must be run with administrator privileges.<br />
<br />
To do that you need to perform the 2 following steps:<br />
<ol>
<li>Add to the solution an "app.manifest" file <br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjw59lgDN8PrqTiuV0rMClhxvdjxq-TVwoxhvSsrSsRsi0gLbvtPMpklzyCh4NkZxuYRO0SRKNwV_GvVJPreEpabyqHIrjHYkAvMd9oMMAw-oxMI7fgGuuC2FpWQy5kezj8e2hZnbHTACg/s1600/AddManifest.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="444" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjw59lgDN8PrqTiuV0rMClhxvdjxq-TVwoxhvSsrSsRsi0gLbvtPMpklzyCh4NkZxuYRO0SRKNwV_GvVJPreEpabyqHIrjHYkAvMd9oMMAw-oxMI7fgGuuC2FpWQy5kezj8e2hZnbHTACg/s640/AddManifest.png" width="640" /></a></div>
<br />
The app.manifest is added to your solution
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5hKoEvpY0GZ70UCOBzzkdmQhm-37XAAFf_993Rmtk6YeLyP4lJ2bvLUABMyBdw9kpgDhelPUonfVOyIfqpyLOxVvpgx7ch-BlgEI8NxKxmoemgyfXEljK5YQrILrOECUoFDS87YHMr1Y/s1600/solexplor.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5hKoEvpY0GZ70UCOBzzkdmQhm-37XAAFf_993Rmtk6YeLyP4lJ2bvLUABMyBdw9kpgDhelPUonfVOyIfqpyLOxVvpgx7ch-BlgEI8NxKxmoemgyfXEljK5YQrILrOECUoFDS87YHMr1Y/s400/solexplor.png" /></a></div>
</li>
<li>Modify this file to set the correct value to requestedExectionLevel:<span style="background-color: #999999;"></span><span style="background-color: #999999;"></span></li>
</ol>
<table>
<tbody>
<tr><td bgcolor="#cccccc"><pre>
<span courier="" monospace="" new="" ourier="" quot="">
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" /></span>
</pre>
</td>
</tr>
</tbody>
</table>
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHWLeaeYV2a5uLRj-sIgPI5_vQHZqq3gobrr_Y_Z8MDZFf-5_YQj5rhtDzXaeCeA-n8E1fTkzeV0CrvdmmAkWna13u8sgLJvl-8JRDUhbUr2MnTW0KhxEY9wXj2lqHOCQEVkudytMQZ-4/s1600/Manifest.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHWLeaeYV2a5uLRj-sIgPI5_vQHZqq3gobrr_Y_Z8MDZFf-5_YQj5rhtDzXaeCeA-n8E1fTkzeV0CrvdmmAkWna13u8sgLJvl-8JRDUhbUr2MnTW0KhxEY9wXj2lqHOCQEVkudytMQZ-4/s1600/Manifest.png" /></a></div>
<br />
<br />
<br />
<strong>Note:</strong> When you try to debug such program inside the Visual studio environment, The visual studio shall detect that the administrator privileges are needed and request you to restart Visual studio in administrator mode.thinkingIn16Bitshttp://www.blogger.com/profile/16782553204614961567noreply@blogger.com0tag:blogger.com,1999:blog-1533381118607780865.post-11706545486030473682014-02-16T06:55:00.000-08:002014-02-16T06:55:58.987-08:00How to avoid the Exception "A cycle occurred while laying out the GUI." in a Windows store APP<br />
<h3>
The Observed Problem</h3>
Sometimes the exception "<strong>A cycle occurred while laying out the GUI.</strong>" occurs in Windows 8 store application in an unpredicatble way. This can be very frustrating especially when the problem is observed only on some computers and not on others .<br />
<br />
Note that when this occurs on a released and deployed Application the Application terminates silently without indicating any error message.<br />
<br />
<h3>
The explanation</h3>
The reason for this exception is in fact very simple: as the description says, we have an endless loop in the layout of the GUI.
I have found that this nearly always occurs in the <strong>SizeChanged </strong>event handler.<br />
<br />
<table>
<tbody>
<tr><td bgcolor="#cccccc"><pre>
border.SizeChanged += _SizeChanged; </pre>
</td></tr>
</tbody></table>
<br />
What can be puzzling is that this can occur even if the <b>SizeChanged</b> Handler does something that should not trigger any endless loop.
Example
<br />
<br />
<table>
<tbody>
<tr><td bgcolor="#cccccc"><pre>
private void _SizeChanged(object sender,
Windows.UI.Xaml.SizeChangedEventArgs e)
{
if (e.NewSize.Width < 150)
{
(border.Child as TextBlock).FontSize = 40;
}
else
{
(border.Child as TextBlock).FontSize = 80;
}
}
}</pre>
</td></tr>
</tbody></table>
<br />
Theoretically, the above code should never trigger an endless loop. But this is not the case. For some graphic résolutions, this method triggers endless calls to the _SizeChanged event Handler.
<br />
<br />
<h3>
The work around
</h3>
There is a simple way to make sure that the<strong> SizeChanged </strong>event is not called endlessly: ignore the event when it is called for nothing.
Detecting useless <strong>SizeChanged</strong> events can easily be done by comparing the old size and the new size; if they are identical then the <strong>SizeChanged</strong> event was called for nothing and it can safely be ignored.<br />
<br />
<table>
<tbody>
<tr><td bgcolor="#cccccc"><pre>
if (e.PreviousSize != e.NewSize) </pre>
</td></tr>
</tbody></table>
<br />
Example: to prevent any risk of endless loop we should update the the following code to make it look like this:<br />
<br />
<table><tbody>
<tr><td bgcolor="#cccccc"><pre>
private void _SizeChanged(object sender,
Windows.UI.Xaml.SizeChangedEventArgs e)
{
if (e.PreviousSize != e.NewSize)
{
if (e.NewSize.Width < 150)
{
(border.Child as TextBlock).FontSize = 40;
}
else
{
(border.Child as TextBlock).FontSize = 80;
}
}
}
</pre>
<br /></td></tr>
</tbody></table>
thinkingIn16Bitshttp://www.blogger.com/profile/16782553204614961567noreply@blogger.com0tag:blogger.com,1999:blog-1533381118607780865.post-63192589599839564252013-09-08T14:24:00.000-07:002013-09-13T13:22:56.192-07:00Reading Text from an embedded file in a WinRT applicationWhen you want to provide data to a WinRT application (a.k.a. Windows Store App) it is sometimes useful to embed a file in your application package. This file may for instance contain help information, initial user settings, sample data...<br />
<br />
To do that you need<br />
<ol>
<li>to include the file in the project<br />
<li>to read the data</li>
</li>
</ol>
Let's make an example using a text file.<br />
To include the text file in the application, just add the text file to the solution
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuWNZT23HKV0QVI_yV5jBKOrVxZNLPJEeCxVQF7B6L-18cToV2rUvDGBdmeFerxA8H6Rg24AtWhsln02gHMiD1pprq-h2oEUQvriAz9goV5ygXWFwYUHfZpcdZcHRXgVHzkJbgx7f-ZrY/s1600/textFile1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuWNZT23HKV0QVI_yV5jBKOrVxZNLPJEeCxVQF7B6L-18cToV2rUvDGBdmeFerxA8H6Rg24AtWhsln02gHMiD1pprq-h2oEUQvriAz9goV5ygXWFwYUHfZpcdZcHRXgVHzkJbgx7f-ZrY/s400/textFile1.png" /></a></div>
<br>
Note that I have created a folder to put my text files .This avoid cluttering the project with too many files.<br>
<br>
It is important to correctly select the build action <b>Content</b> to ensure that the file shall effectively be embedded in the application file.<br>
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwwu4Wn94zpaOSTCZTwjK5GltU9Mj2phwMFmTCr5TeySuPyYtRcCcJ6OArKFhrtblhri73C0zOOKQuGMnorG0oPgPAPyz18qeNPMymXt19GUkrTbZqMH3Qv8Sfpf8W61rprnpVCxWt4f4/s1600/textFile2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwwu4Wn94zpaOSTCZTwjK5GltU9Mj2phwMFmTCr5TeySuPyYtRcCcJ6OArKFhrtblhri73C0zOOKQuGMnorG0oPgPAPyz18qeNPMymXt19GUkrTbZqMH3Qv8Sfpf8W61rprnpVCxWt4f4/s400/textFile2.png" /></a></div>
<br>
Now that the file is included in the application package we must get access to it.<br>
The code below shows how to read the whole text file and display its first two lines in textblocks
<br>
<table>
<td bgcolor="#cccccc">
<pre>
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
//retrieve the text file content
Uri uri = new Uri("ms-appx:///MyTextFiles/MyTextFile1.txt");
StorageFile file =
await StorageFile.GetFileFromApplicationUriAsync(uri);
IList<String> lines = await FileIO.ReadLinesAsync(file);
//use the retrieved data
TextBlock1.Text = lines[0];
TextBlock2.Text = lines[1];
}
</pre>
</td></table>
<br>
Note the usage of an <b>URI</b> instead of a path to identify the file. Embedded files cannot be accessed using a file path.<br>
<br>
Note also the very strange URI syntax with a triple slash <b>ms-appx:///</b>
<br><br>
Obviously, the same technique can be used to embed other things than text files. You could embed images, sounds or binary data.<br>
I hope this will help you the next time you need to embed a data file inside a Windows store application.<br>
thinkingIn16Bitshttp://www.blogger.com/profile/16782553204614961567noreply@blogger.com0tag:blogger.com,1999:blog-1533381118607780865.post-9791419580266855442013-05-23T23:49:00.001-07:002013-05-24T13:17:46.614-07:00Preventing the winrt combox to jump around when it is openedThe combox in windows 8 (winrt) XAML has a bad tendency to jump around when the user opens it.<br />
See the example below:<br />
<br />
<table>
<tbody>
<tr><td bgcolor="#cccccc"><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;">
<ComboBox HorizontalAlignment="Center" VerticalAlignment="Center"<br />
Grid.RowSpan="2" Grid.ColumnSpan="2" SelectedIndex="0" > <br />
<TextBlock Text="first"/> <br />
<TextBlock Text="second"/> <br />
<TextBlock Text="Third"/> <br />
<TextBlock Text="Very long text................." /><br />
</ComboBox> </span>
</td>
</tr>
</tbody></table>
<br />
<br />
When the combobox is closed it is well centered on the cross But when it becomes open it is not centered at all. <br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhC1WOmaghz0HSlDZgyvVPoXJYYNqc4Aoj_ymOdDPLPd1ULOPFlh_5PZYykwT1S8ygE6p40fpXdVF5FDn6yc7_7njDCgd5MuD_JDgRtVfYKquGBMeFcDXXSjaGYZN5q9aKwlgZvz4pg-ec/s1600/Combobox.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="244" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhC1WOmaghz0HSlDZgyvVPoXJYYNqc4Aoj_ymOdDPLPd1ULOPFlh_5PZYykwT1S8ygE6p40fpXdVF5FDn6yc7_7njDCgd5MuD_JDgRtVfYKquGBMeFcDXXSjaGYZN5q9aKwlgZvz4pg-ec/s640/Combobox.png" width="640" /></a></div>
<br />
Note this does not occur when the combobox alignment is set to <em><span style="color: blue;"><strong>stretch</strong></span></em> but this is not always a solution that fits with your XAML layout.<br />
<br />
Vertically the opened combobox is arranged so that the selected line is at right place. That's OK but the horizontal movement is (I think) awful for the user.<br />
<br />
The best way that I have found to avoid it is to force a <strong><span style="color: blue;"><em>MinWidth </em></span></strong>value that is large enough to display the longest text that shall have to be displayed in the combobox. This is a bit a dirty trick but it works nicely.<br />
<br />
<table>
<tbody>
<tr><td bgcolor="#cccccc"><span style="font-family: "Courier New", Courier, monospace; font-size: x-small;"> <ComboBox HorizontalAlignment="Center" VerticalAlignment="Center" </span>
<br />
<span style="font-family: "Courier New", Courier, monospace; font-size: x-small;"><span style="background-color: #cccccc;"> Grid.RowSpan="2" Grid.ColumnSpan="2" SelectedIndex="0" <span style="color: red;">MinWidth="200"</span>><br /> <TextBlock Text="first"/> <br /> <TextBlock Text="second"/> <span style="background-color: #cccccc;"> </span><br /> <TextBlock Text="Third"/> <br /> <TextBlock Text="Very long text................." /> <br /> </ComboBox> </span></span>
</td></tr>
</tbody></table>
<br />
<br />
With this modification we get:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEic2cai_EuoSVcdJq_8rEWf2DhqrnLHBKBvfRNN8Xixj0wHFfdEh6g-0FY5jqVySAj73F3d-LaNEAb5GbfAX1v35xYZEe_QaK1ApOAbdw3iNJZ3kM3nnsesT3dSiWDzONcaNGygsGbJf5s/s1600/Combobox2.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="246" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEic2cai_EuoSVcdJq_8rEWf2DhqrnLHBKBvfRNN8Xixj0wHFfdEh6g-0FY5jqVySAj73F3d-LaNEAb5GbfAX1v35xYZEe_QaK1ApOAbdw3iNJZ3kM3nnsesT3dSiWDzONcaNGygsGbJf5s/s640/Combobox2.png" width="640" /></a>
</div>
<br />
The opened combobox stays horizontally centered on at the correct position.
<br />
<br />
<br />
<br />
thinkingIn16Bitshttp://www.blogger.com/profile/16782553204614961567noreply@blogger.com0tag:blogger.com,1999:blog-1533381118607780865.post-65020837829415587052012-08-26T15:37:00.000-07:002012-08-26T15:39:12.061-07:00How to change the graphical resolution supported by Virtualbox<h2>
</h2>
Oracle's virtual machine Virtualbox is a great way to experiment with the new Windows8 but by default the video driver of virtualbox 4.1.20 offers only the following resolutions:<br />
<ul>
<li>1600x1200</li>
<li>1280x1024</li>
<li>1152x864</li>
<li>1024x768</li>
</ul>
There is however a trick to enable other resolutions by using the command. <br />
<br />
<pre><strong>VBoxManage.exe</strong></pre>
<br />
I wanted to have access to my screen native resolution (1920x1080) as well as the minimum screen resolution used by Windows8 (1366x768)<br />
<br />
By using the following commands I was able to add those 2 resolutions<br />
<br />
<pre><strong><span style="background-color: black; color: lime;">> </span><span style="background-color: black; color: lime;">VBoxManage.exe setextradata "WIN8RTM" CustomVideoMode1 1920x1080x32
> VBoxManage.exe setextradata "WIN8RTM" CustomVideoMode2 1366x768x32 </span></strong>
</pre>
<br />
Where WIN8RTM is the name of my virtual machine<br />
<br />
NOTE:<br />
<ol>
<li>The 32 is the color depth (32 = a color depth of 32 bits i.e. 16.7millions of colors)</li>
<li>You must restart the virtual machine to take those settings into account (rebooting the virtual machine is not enough)</li>
<li>Don't overlook the quotes around the virtual machine name! (I lost half an hour searching what was wrong because I had forgotten the quotes</li>
</ol>
<br />
Once the setting is done you can check if it is correct by using the command<br />
<br />
<pre><strong><span style="background-color: black; color: lime;">> VBoxManage.exe getextradata "WIN8RTM" enumerate </span></strong></pre>
<br />
which produces the following result<br />
<br />
<pre><strong><span style="background-color: black; color: lime;">Key: CustomVideoMode1, Value: 1920x1080x32
Key: CustomVideoMode2, Value: 1366x768x32
Key: GUI/Fullscreen, Value: on
Key: GUI/LastCloseAction, Value: powerOff
Key: GUI/LastGuestSizeHint, Value: 1024,768
Key: GUI/LastNormalWindowPosition, Value: 640,218,1024,819,max
Key: GUI/MiniToolBarAlignment, Value: bottom
Key: GUI/MiniToolBarAutoHide, Value: off
Key: GUI/SaveMountedAtRuntime, Value: yes
Key: GUI/ShowMiniToolBar, Value: yes
Key: GUI/VirtualScreenToHostScreen0, Value: 1 </span></strong></pre>
<strong><span style="background-color: black; color: lime;">
</span>
</strong>
<br />
<br />thinkingIn16Bitshttp://www.blogger.com/profile/16782553204614961567noreply@blogger.com0tag:blogger.com,1999:blog-1533381118607780865.post-12245006669826471332011-11-13T14:12:00.000-08:002011-11-14T13:08:14.484-08:00Testing an HTML page on your local computerI wanted to test some HTML code I had just written with Microsoft Visual Web Developper 2010 Express, so I saved the page on my local hard drive and opened it with Internet Explorer 9. But I had a surprise: Internet explorer indicated a warning "Internet Explorer restricted this webpage from running scripts or ActiveX controls." (or on my french speaking version "Internet Explorer a restreint l'execution des scripts ou des controles ActiveX sur cette page Web"). <br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXisnrwuzsuJ41v2P5GPtE_xbOTVze5zPQa4hoV1HiFOX78v3qfdi-XU7gtrl93Qe94oD6uro8m9Q7FsIT5Onio4XTunYrwCj6CTS11uhb5ErmA_vuZLKrAEHwn5aexeoQaDGHfsgT7h4/s1600/IE9.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="472" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXisnrwuzsuJ41v2P5GPtE_xbOTVze5zPQa4hoV1HiFOX78v3qfdi-XU7gtrl93Qe94oD6uro8m9Q7FsIT5Onio4XTunYrwCj6CTS11uhb5ErmA_vuZLKrAEHwn5aexeoQaDGHfsgT7h4/s640/IE9.jpg" width="640" /></a></div><br />
<br />
This is somewhat annoying to have to disable this restriction each time the page is loaded.<br />
<br />
There is a very simple solution to allow Internet Explorer 9 to accept scripts on a local page: in the "Advanced" tab, check the checkbox "Allow Active Content to be run in files on My Computer" (on in my French Internet Explorer "Autoriser l'exécution du contenu actif dans les fichiers de mon ordinateur")<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiILYPpfa6tB0Ao27c7CEWjCsc66HgGdtfU9UQ1JaHpu2DNp7tSM66g5gAOW3P5GD9iXJppCtGw-afpj4Xg8Z4avf_io8_Mjfkyq8-I3yJutUua5ooK32NNbqL1ZCGG1-Wzdb5qcckicxM/s1600/Authorize.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiILYPpfa6tB0Ao27c7CEWjCsc66HgGdtfU9UQ1JaHpu2DNp7tSM66g5gAOW3P5GD9iXJppCtGw-afpj4Xg8Z4avf_io8_Mjfkyq8-I3yJutUua5ooK32NNbqL1ZCGG1-Wzdb5qcckicxM/s640/Authorize.jpg" width="592" /></a></div>thinkingIn16Bitshttp://www.blogger.com/profile/16782553204614961567noreply@blogger.com0tag:blogger.com,1999:blog-1533381118607780865.post-53135674554038814332011-08-21T13:46:00.000-07:002011-08-21T13:46:20.135-07:00Be careful with your directory seperator when using SlverlightI have observed something weird with the images in Silverlight:<br />
<br />
In Visual studio you may specify the path towards an image using slash ("/") or backslash ("\") as separator: both give the correct result.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpSA1R9SsBrUefRhf-zXbBnyRQf6K0lkpdEdN19KhxIUI880QHP7whZb0TZtD1kchA7vcbn8j0xcQiRUUHrnD-IDt1yy_GkBIMKMXBIneO5T8SvtPjUcNOvG31io32znx9GdhDyWMsqoI/s1600/visual.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="563" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpSA1R9SsBrUefRhf-zXbBnyRQf6K0lkpdEdN19KhxIUI880QHP7whZb0TZtD1kchA7vcbn8j0xcQiRUUHrnD-IDt1yy_GkBIMKMXBIneO5T8SvtPjUcNOvG31io32znx9GdhDyWMsqoI/s640/visual.jpg" width="640" /></a></div><br />
But if you run the silverlight application only the picture with the slash in the path does appear: the image whose path contains backslashes remains invisible.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsIqMNBzOJq8LuCxsYUUY9SRWIrl63GHSdZMXZcms8-EggZyJRBYEN5X61d0HOjstrdmID5Tt9eIQMK3M7r01B4TP5GR2vvKrFP-IvB6ObeFr5s4X3iHZ9OQx04OeTaR365COuR64ilx0/s1600/VResult.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="560" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsIqMNBzOJq8LuCxsYUUY9SRWIrl63GHSdZMXZcms8-EggZyJRBYEN5X61d0HOjstrdmID5Tt9eIQMK3M7r01B4TP5GR2vvKrFP-IvB6ObeFr5s4X3iHZ9OQx04OeTaR365COuR64ilx0/s640/VResult.jpg" width="640" /></a></div><br />
May be the engine within visual studio uses Windows service to retrieve files and that service accepts both "/" and "\" as separators while the browser uses the HTTP conventions where the separator is always "/". Anyway for yor Silverlight developments be sure to always use "/" to avoid any problem.<br />
<br />
thinkingIn16Bitshttp://www.blogger.com/profile/16782553204614961567noreply@blogger.com0tag:blogger.com,1999:blog-1533381118607780865.post-73849019651569067632011-08-09T14:46:00.000-07:002011-08-21T13:47:57.415-07:00Building my own pocket CalculatorI always wanted to make my own pocket calculator (in the 80's this seemed quite an impossible dream). With the currently available components this has become much easier. <br />
<br />
I made it using a <a href="http://ww1.microchip.com/downloads/en/devicedoc/30292c.pdf">PIC 16F877</a>, an 2x16 characters LCD display, and a telephone keyboard.<br />
<br />
The schematics is quite straightforward<br />
<div class="separator" style="clear: both; text-align: center;"><img border="0" height="640" naa="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjV8QkOLjDGT_fAKCLRmuWw9XCgVSLX6c1Y6qDVtTDYmB9nBjLQ85etx0rrdFLeseM5kQ6UnQufVGTHKj6pEuoLrw04hb5I34LGI-s2x_o1gRkC2Gr6ZTpDnCvqocf0L9BCwpngdlrTT3E/s640/calculator.jpg" width="492" /></div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;">I used <a href="http://www.expresspcb.com/ExpressPCBHtm/Free_schematic_software.htm">ExpressSCH</a> to draw it.</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: left;">For the programming I used the classic MPLAB 8.30 from <a href="http://www.microchip.com/">microchip</a> with the C compiler from <a href="http://www.htsoft.com/">Hi-tech software</a>. This is a free C compiler that makes something I would think as nearly impossible for a C compiler: support the PIC 16 architecture.</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: left;">The C compiler saved me from the mess of having to perform floating point operations in assembly language.</div><div class="separator" style="clear: both; text-align: left;">But to get the right accuracy, I had to set correctly the floating point size to 32bits</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7owRErKZyU2FG6bmhBfnj-WOM3WubLKIYrnwhAisko4kEKF_dxpgfezZPjSwcXnHipsSGQeBiv4ANUjS-oQnwrLL2yMAoKNOJK1qwy8GaRFOWZYn_sX3eAHHZ_Z4B0RTTUAOaNgqinO0/s1600/mplab.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="256" naa="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7owRErKZyU2FG6bmhBfnj-WOM3WubLKIYrnwhAisko4kEKF_dxpgfezZPjSwcXnHipsSGQeBiv4ANUjS-oQnwrLL2yMAoKNOJK1qwy8GaRFOWZYn_sX3eAHHZ_Z4B0RTTUAOaNgqinO0/s320/mplab.jpg" width="320" /></a></div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: left;">In the first time it did not work at all and I had to search to find why. In the end I found that I had incorrectly set the 16F877 chip options: I had forgotten to disable the "Low Voltage Programming". Since the Low Voltage programming interacts with Port B bit 3 which I use for keyboard this was preventing my software from working</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: left;">by using:</div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: center;"><span style="background-color: #d5a6bd;">__CONFIG(WDTDIS & HS & UNPROTECT & LVPDIS);</span></div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times, "Times New Roman", serif;">I did solve the problem.</span></div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: left;"><span style="font-family: Times;">And now my pocket calculator is ready.</span></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWaMD1Rb5lSF6uBEGRqDhIdGGd1zfQ5z26zuhG0SOEV0ZO__YlqTLLr8VZpKpLZH5MYEMD8yUS00X6Vh-b-4mBWHP-D1EnZM2TvLlw6Vlg2MGglvzuKJ7b_-ubeIShwChDbHE4WlIE0Ng/s1600/calc.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" naa="true" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWaMD1Rb5lSF6uBEGRqDhIdGGd1zfQ5z26zuhG0SOEV0ZO__YlqTLLr8VZpKpLZH5MYEMD8yUS00X6Vh-b-4mBWHP-D1EnZM2TvLlw6Vlg2MGglvzuKJ7b_-ubeIShwChDbHE4WlIE0Ng/s320/calc.jpg" width="255" /></a></div><div class="separator" style="clear: both; text-align: left;"><br />
</div>thinkingIn16Bitshttp://www.blogger.com/profile/16782553204614961567noreply@blogger.com0