{"id":402,"date":"2015-03-14T21:26:06","date_gmt":"2015-03-14T20:26:06","guid":{"rendered":"http:\/\/heppg.de\/ikg\/wordpress\/?p=402"},"modified":"2016-04-03T17:34:26","modified_gmt":"2016-04-03T15:34:26","slug":"mcp23s17-supported-in-scratchclient","status":"publish","type":"post","link":"https:\/\/heppg.de\/ikg\/wordpress\/?p=402","title":{"rendered":"MCP23S17 aka piFace supported in scratchClient"},"content":{"rendered":"<p>The 23S17 is the chip used on piFace, It can be used also on a breadboard, providing 16 extra IO-pins for the raspberry.<br \/>\nThe adapter adapter.mcp23s17.MCP23S17_Adapter expands the IO-capabilities by 16 ports, either input or output.<\/p>\n<div class=\"section\">\n<h4 class=\"title\">\u00a0<a href=\"http:\/\/heppg.de\/ikg\/wordpress\/wp-content\/uploads\/2015\/03\/mcp23s17.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-403\" src=\"http:\/\/heppg.de\/ikg\/wordpress\/wp-content\/uploads\/2015\/03\/mcp23s17.png\" alt=\"mcp23s17\" width=\"600\" height=\"413\" \/><\/a><\/h4>\n<p>On the image you see the breadboard setup with the device 23s17, connected with an adafruit breadboard adapter to raspberry pi. The small boards plugged in vertically contain 8 LED with a resistor array. I use those whenever I need more than one LED on a setup.<\/p>\n<h4 class=\"title\">Programming details<\/h4>\n<p>This adapter was a challenge. It needed a configuration specific for each adapter instance of this type, and this complexity was beyond the available &lt;parameter\/&gt;-tags. The decision was to break the configuration phase into multiple steps, where after basic creation and setup of the adapter instance the configuration manager passes control to the adapter and provides the local xml config node in this call. The adapter reads the &lt;io\/&gt;-tags, configures the necessary adapter methods for sending and receiving variables and gets the device settings for input, output direction and pullup setup.<\/p>\n<h4 class=\"title\">Configuration details<\/h4>\n<p>The device 23s17 allows to have up to 8 devices &#8216;in parallel&#8217; on one SPI chip select. These devices have hardwired distinct slave addresses. In the configuration, this slave address must be given.<\/p>\n<pre class=\"screen\">        &lt;parameter name='spi.bus' value='0' \/&gt;\r\n        &lt;parameter name='spi.device' value='0' \/&gt;\r\n        &lt;!-- slave address must match the hard wired slave address on the device --&gt;\r\n        &lt;parameter name='23s17.addr' value='0' \/&gt;<\/pre>\n<p>The IO direction for the port pins is defined by &lt;io\/&gt;-tags.<\/p>\n<pre class=\"screen\">        &lt;io id='GPA0' dir='out' \/&gt;\r\n        &lt;io id='GPA1' dir='out' \/&gt;\r\n        &lt;io id='GPA2' dir='out' \/&gt;\r\n        &lt;io id='GPA3' dir='out' \/&gt;\r\n\r\n        &lt;io id='GPA4' dir='out' \/&gt;\r\n        &lt;io id='GPA5' dir='out' \/&gt;\r\n        &lt;io id='GPA6' dir='out' \/&gt;\r\n        &lt;io id='GPA7' dir='out' \/&gt;\r\n\r\n        &lt;io id='GPB0' dir='in' pullup='none'\/&gt;\r\n        &lt;io id='GPB1' dir='in' pullup='none'\/&gt;\r\n        &lt;io id='GPB2' dir='in' pullup='none'\/&gt;\r\n        &lt;io id='GPB3' dir='in' pullup='none'\/&gt;\r\n        \r\n        &lt;io id='GPB4' dir='in' pullup='weak'\/&gt;\r\n        &lt;io id='GPB5' dir='in' pullup='weak'\/&gt;\r\n        &lt;io id='GPB6' dir='in' pullup='weak'\/&gt;\r\n        &lt;io id='GPB7' dir='in' pullup='weak'\/&gt;<\/pre>\n<p>It is generally a good idea to define all of the port pins. Technically it is needed to define those which are used in the application. The id-values are predefined and must be used as seen here.<\/p>\n<p>For ports defined as dir=&#8217;out&#8217; outputs, the corresponding adapter input methods can be used:<\/p>\n<pre class=\"screen\">        &lt;input_value name='inputGPA4'&gt;\r\n            &lt;!-- variable name is the name of the scratch variable which is \r\n                 send out to the adapter --&gt;\r\n            &lt;variable name='input_4'\/&gt;\r\n        &lt;\/input_value&gt;\r\n<\/pre>\n<p>For ports defined as dir=&#8217;in&#8217; inputs, the corresponding adapter output methods can be used:<\/p>\n<pre class=\"screen\">        &lt;output_value name='outputGPB2'&gt;\r\n            &lt;sensor name='output_2'\/&gt;\r\n        &lt;\/output_value&gt;\r\n<\/pre>\n<p>The variables send out from scratch are &#8216;0&#8217;, &#8216;1&#8217; to set the output pin of the 23s17 to low, high.<\/p>\n<p>The sensor values received from scratch are &#8216;0&#8217;, &#8216;1&#8217; for the input pin of the 23s17 receiving low, high.<\/p>\n<\/div>\n<div class=\"section\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h4 class=\"title\"><a name=\"N10368\"><\/a>Start scratchClient<\/h4>\n<\/div>\n<\/div>\n<\/div>\n<p>scratchClient startup does not need special considerations.<\/p>\n<pre class=\"screen\">cd ~\/scratchClient\r\nsudo python src\/scratchClient.py -C config\/config_mcp23s17.xml\r\n<\/pre>\n<p>The file config\/config_mcp23s17.xml is an example of a full functional configuration.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>The 23S17 is the chip used on piFace, It can be used also on a breadboard, providing 16 extra IO-pins for the raspberry. The adapter adapter.mcp23s17.MCP23S17_Adapter expands the IO-capabilities by 16 ports, either input or output. \u00a0 On the image you see the breadboard setup with the device 23s17, connected with an adafruit breadboard adapter [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[30,17],"class_list":["post-402","post","type-post","status-publish","format-standard","hentry","category-scratchclient","tag-mcp23s17","tag-piface"],"_links":{"self":[{"href":"https:\/\/heppg.de\/ikg\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/402","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/heppg.de\/ikg\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/heppg.de\/ikg\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/heppg.de\/ikg\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/heppg.de\/ikg\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=402"}],"version-history":[{"count":4,"href":"https:\/\/heppg.de\/ikg\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/402\/revisions"}],"predecessor-version":[{"id":790,"href":"https:\/\/heppg.de\/ikg\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/402\/revisions\/790"}],"wp:attachment":[{"href":"https:\/\/heppg.de\/ikg\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=402"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/heppg.de\/ikg\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=402"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/heppg.de\/ikg\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=402"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}