<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-658034019742100389</id><updated>2024-09-02T09:03:56.438+01:00</updated><category term="Arduino"/><category term="Bread board"/><category term="Electronics"/><category term="LED control library"/><category term="LED matrix"/><category term="MAX7219"/><category term="shift register"/><title type='text'>Spiral Out</title><subtitle type='html'>A blog dedicated to what tinkering I&#39;m doing with Arduino, Raspberry Pi, electronics, robots and any other techy stuff.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://rideonthespiral.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/658034019742100389/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://rideonthespiral.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Jake_F</name><uri>http://www.blogger.com/profile/09213449539257524662</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSjPzmu4i-mg7KoQQho1OGcnTR59TCCTBJioSb8IOOJ2vqMdCUUeK8HD2Kgnah4HB7_GSCBWfl59uM01ebRraZl9G2I5PDYyS1ORC4_plrTD8pjqtp7fJiChxX1Ffxrdk/s1600/Reaching_color_high.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-658034019742100389.post-4343558110654948886</id><published>2012-05-18T23:41:00.001+01:00</published><updated>2015-07-28T21:47:12.283+01:00</updated><title type='text'>Arduino: How to read in from a text file and alternatives</title><content type='html'>Greetings all,&lt;br /&gt;
&lt;br /&gt;
Apologies its been so long since my last post, I blame a BSc with a dissertation (which I will post about soon) which has basically made me disabled since February.&lt;br /&gt;
&lt;br /&gt;
This post is aimed at trying to help overcome the fact that the Arduino doesn&#39;t have a file structure and therefore there is no direct way to read/write to files, the most common file of course being a text file. I haven&#39;t written any examples myself as the best ones are in the links provided. I have however tried out these examples and they have all worked.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #dd7700;&quot;&gt;&lt;u&gt;Solution 1: Using the Processing IDE and serial port&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
The first solution I&#39;ve only discovered from writing this post and its fair to say that its the best solution.&lt;br /&gt;
&lt;br /&gt;
It involves using the Processing IDE which can be downloaded&amp;nbsp;&lt;a href=&quot;http://processing.org/&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;. Having only just discovered Processing I can&#39;t say too much about it, but what I do know is its a sister program to the Arduino IDE so things are very similar between the two. It incorporates many examples including file I/O, graphics and simulations which make it a very handy and useful program.&lt;br /&gt;
&lt;br /&gt;
I will maybe post about it once I&#39;ve got to grips with it.&lt;br /&gt;
&lt;br /&gt;
As for how to read in the text file, the work has been done in this blog&amp;nbsp;&lt;a href=&quot;http://arduinobasics.blogspot.co.uk/2012/05/reading-from-text-file-and-sending-to.html&quot;&gt;http://arduinobasics.blogspot.co.uk/2012/05/reading-from-text-file-and-sending-to.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
A few points to note: The example in the blog may or may not use the RX/TX library. I already have that library installed on my PC so I&#39;m not sure if it requires it or not (it probably doesn&#39;t).&lt;br /&gt;
&lt;br /&gt;
The example works by communicating over a COM port and so Arduino just has to read the serial input given to it.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #dd7700;&quot;&gt;&lt;u&gt;Solution 2: Using the RX/TX library&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
As mentioned in solution 1, there is an RX/TX library that allows communication over ports (usually COM3 or COM10). It can also be interfaced with Java and so can be used in IDEs such as NetBeans or Eclipse.&lt;br /&gt;
&lt;br /&gt;
Its not worth producing examples as they have already been done well on the Arduino website:&lt;br /&gt;
&lt;a href=&quot;http://arduino.cc/playground/Interfacing/Java&quot;&gt;http://arduino.cc/playground/Interfacing/Java&lt;/a&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #dd7700;&quot;&gt;&lt;u&gt;Solution 3: Using an SD card shield&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
Another solution is using an Arduino SD card shield with the SD card library. This can be quite handy, especially as data can easily be stored on an SD card.&lt;br /&gt;
&lt;br /&gt;
Your standard shield can be one like&amp;nbsp;&lt;a href=&quot;http://www.sparkfun.com/products/9802&quot; target=&quot;_blank&quot;&gt;this&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
You will then of course need the SD card library which can be downloaded &amp;nbsp;&lt;a href=&quot;http://code.google.com/p/sdfatlib/downloads/list&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;&amp;nbsp;( i think).&lt;br /&gt;
&lt;br /&gt;
The best examples are on the&amp;nbsp;&lt;a href=&quot;http://arduino.cc/&quot; target=&quot;_blank&quot;&gt;arduino.cc&lt;/a&gt;&amp;nbsp;website, the most relevant one being this one:&amp;nbsp;&lt;a href=&quot;http://arduino.cc/en/Tutorial/ReadWrite&quot;&gt;http://arduino.cc/en/Tutorial/ReadWrite&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #dd7700;&quot;&gt;&lt;u&gt;Solution 4: Treating your .ino file as a text file&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
So this is a bit of a hack that I actually used for my dissertation. Its not the best way but at least it is a solution.&lt;br /&gt;
&lt;br /&gt;
For this to work, you simply treat the .ino file (was formerly a .pde file) as a text file.&lt;br /&gt;
&lt;br /&gt;
From my experience in Java, you can read/edit/write the .ino file with no problems, thus I can only assume it will be the case for other programming languages.&lt;br /&gt;
&lt;br /&gt;
Its not really worth showing an example as its fairly straight forward, the difficulty lies in finding the right place to insert the new code/text.&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #dd7700;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
Unfortunately, this isn&#39;t great, its cumbersome and requires a lot of string manipulation. However it worked for my dissertation which required large amounts of&amp;nbsp;amended&amp;nbsp;text. The benefit is that this avoids using any other components, save time and the number of pins used.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #dd7700;&quot;&gt;&lt;u&gt;In conclusion&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
In my personal opinion, the best solution is the first one. By having the data sent over a port, it means the Arduino can be active whilst the processing program runs.&lt;br /&gt;
&lt;br /&gt;
Of course you may have a scenario where one of the other solutions suits you more.&lt;br /&gt;
&lt;br /&gt;
Hope you&#39;ve found this post helpful, next post should be about natural computing.&lt;br /&gt;
&lt;br /&gt;
Any questions/comments/suggestions welcomed.&lt;br /&gt;
&lt;br /&gt;
Jake.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://rideonthespiral.blogspot.com/feeds/4343558110654948886/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rideonthespiral.blogspot.com/2012/05/arduino-how-to-read-in-from-text-file.html#comment-form' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/658034019742100389/posts/default/4343558110654948886'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/658034019742100389/posts/default/4343558110654948886'/><link rel='alternate' type='text/html' href='http://rideonthespiral.blogspot.com/2012/05/arduino-how-to-read-in-from-text-file.html' title='Arduino: How to read in from a text file and alternatives'/><author><name>Jake_F</name><uri>http://www.blogger.com/profile/09213449539257524662</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSjPzmu4i-mg7KoQQho1OGcnTR59TCCTBJioSb8IOOJ2vqMdCUUeK8HD2Kgnah4HB7_GSCBWfl59uM01ebRraZl9G2I5PDYyS1ORC4_plrTD8pjqtp7fJiChxX1Ffxrdk/s1600/Reaching_color_high.jpg'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-658034019742100389.post-3919078135161509244</id><published>2012-02-26T21:04:00.003+00:00</published><updated>2015-07-28T21:49:49.907+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Arduino"/><category scheme="http://www.blogger.com/atom/ns#" term="Bread board"/><category scheme="http://www.blogger.com/atom/ns#" term="Electronics"/><category scheme="http://www.blogger.com/atom/ns#" term="LED control library"/><category scheme="http://www.blogger.com/atom/ns#" term="LED matrix"/><category scheme="http://www.blogger.com/atom/ns#" term="MAX7219"/><category scheme="http://www.blogger.com/atom/ns#" term="shift register"/><title type='text'>Arduino - How to power LED matrices using shift registers: Part 2</title><content type='html'>Welcome to part two.&lt;br /&gt;
&lt;br /&gt;
This has all the steps you need to get your creations up and running. But first, the code for my program can be found here:&amp;nbsp;&lt;a href=&quot;http://dl.dropbox.com/u/16309910/test.ino&quot;&gt;&lt;span style=&quot;color: #dd7700;&quot;&gt;http://dl.dropbox.com/u/16309910/test.ino&lt;/span&gt;&lt;/a&gt;&amp;nbsp;or search for me on github: &lt;span style=&quot;color: #dd7700;&quot;&gt;j-fray &lt;/span&gt;or clone it using&amp;nbsp;&lt;span style=&quot;color: #dd7700;&quot;&gt;https://j-fray@github.com/j-fray/Arduino---Simulating-bead-sort.git&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #dd7700;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
There are also some pictures of the schematics which you can find here:&lt;br /&gt;
Imput layer:&amp;nbsp;&lt;a href=&quot;http://dl.dropbox.com/u/16309910/inputlayer.png&quot;&gt;http://dl.dropbox.com/u/16309910/inputlayer.png&lt;/a&gt;&lt;br /&gt;
Output layer:&amp;nbsp;&lt;a href=&quot;http://dl.dropbox.com/u/16309910/outputlayer.png&quot;&gt;http://dl.dropbox.com/u/16309910/outputlayer.png&lt;/a&gt;&lt;br /&gt;
Power layer:&amp;nbsp;&lt;a href=&quot;http://dl.dropbox.com/u/16309910/powerlayer.png&quot;&gt;http://dl.dropbox.com/u/16309910/powerlayer.png&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
I will upload any remaining documents to my github as listed above.&lt;br /&gt;
&lt;br /&gt;
Now obviously this program is meant for 6 matrices, but it should be pretty straight forward to alter it for any number of matrices.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #dd7700;&quot;&gt;&lt;u&gt;Step 1 - Setup&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
A good place to start is to get one matrix up and running. You need 3 pins on your Arduino board, one for data, one for clock and one for load pins. With the MAX7219 these correspond to pins 1, 13 and 12 respectively on the shift register. Put the shift register on a breadboard and connect these up.&lt;br /&gt;
&lt;br /&gt;
Then its time to connect the ground and power pins up. The ground pins on the 7219 are 4 and 9, the power pins are 18 and 19 (check the link to the schematic in part 1). Pin 18 needs to be connected to a 40KOhm resistor (or equivalent combinations) and then connected to the power supply.&lt;br /&gt;
&lt;br /&gt;
Arduino boards in general have a 5V output and that&#39;s what I used, just make sure the pins are connected in series and not in parallel.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #dd7700;&quot;&gt;&lt;u&gt;Step 2 - Connecting to matrix&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
Now to start connecting up the matrix. As mentioned in part 1 the pins mappings of LED matrices vary for each make so check the datasheet of your matrix to see what pins use what. In my case pins 1 - 4 and 20-24 control the rows.13-19 control the red cols and 5-12 control the green cols.&lt;br /&gt;
&lt;br /&gt;
Connect your matrix up appropriately. It is worth uploading the program to the Arduino board first and connecting the pins one at a time so that you can see the matrix working and deduce if there are any problems with a particular row.&lt;br /&gt;
&lt;br /&gt;
The result should be a small sequence on the matrix.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #dd7700;&quot;&gt;&lt;u&gt;Step 3 - Repeat&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
Repeat steps 1 and 2 for however many matrices you want, remember to do small bits at a time and test them. The last thing you want is to wire the whole thing and find it doesn&#39;t work or you&#39;ve wired it wrong.&lt;br /&gt;
&lt;br /&gt;
Here are some pictures of my creation:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEWVC5zfGpKYxrPPb_xUBG9kkJcAjdBIB8pugnuXYFlV-NIKGdMNRPa8jSwSDBRSOKvTwnMcgcOUHHzDA4HcfpYTPqbxcAuPnKjk_IKMnazFLgTDnjsQ-CQTfyjg-YCcOCzfefABanjPw/s1600/Photo-0001.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;256&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEWVC5zfGpKYxrPPb_xUBG9kkJcAjdBIB8pugnuXYFlV-NIKGdMNRPa8jSwSDBRSOKvTwnMcgcOUHHzDA4HcfpYTPqbxcAuPnKjk_IKMnazFLgTDnjsQ-CQTfyjg-YCcOCzfefABanjPw/s320/Photo-0001.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgX_iwHKUOY6CE_Nq1Hx6zcrnMjY5895PntMmIER3uT1REjGAUEBMSEGryg64i4mzgcUrLYVPG7AnLjKQgdUj-f5Y6lg3t_UKeJh7CiU4Ym8dAYMM13GnnmzNJgC2io_oLyTRVMyO4PvZg/s1600/Photo-0007.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;256&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgX_iwHKUOY6CE_Nq1Hx6zcrnMjY5895PntMmIER3uT1REjGAUEBMSEGryg64i4mzgcUrLYVPG7AnLjKQgdUj-f5Y6lg3t_UKeJh7CiU4Ym8dAYMM13GnnmzNJgC2io_oLyTRVMyO4PvZg/s320/Photo-0007.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRxrkRvp_zDqUe8VPxSuwRGmeUtjcqdUKmQmi6TlTsN8Gfm8RA6rYxJjFWDIjAQPpQGnip_Aq3E8R9Lxoe2qE2MNkQ0Jbn-d2NSP1C3m2iD3rqadWUe48Jlp6SyU2r-M5UXN_wXFAdnso/s1600/Photo-0008.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;256&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRxrkRvp_zDqUe8VPxSuwRGmeUtjcqdUKmQmi6TlTsN8Gfm8RA6rYxJjFWDIjAQPpQGnip_Aq3E8R9Lxoe2qE2MNkQ0Jbn-d2NSP1C3m2iD3rqadWUe48Jlp6SyU2r-M5UXN_wXFAdnso/s320/Photo-0008.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiF-F8-1bX7oBseLZuTm96LF9gjkEZvSkTIr1XkzyXIlt_tu-3TdXLb822XKh613W8OfbbbgSPUyzkV_fpOZBDM7lspbLm_sWe0tM80264xcpGn3Qh1q6ZlKDJmkzWIVNafUxVMNOu9fqA/s1600/Photo-0009.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;256&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiF-F8-1bX7oBseLZuTm96LF9gjkEZvSkTIr1XkzyXIlt_tu-3TdXLb822XKh613W8OfbbbgSPUyzkV_fpOZBDM7lspbLm_sWe0tM80264xcpGn3Qh1q6ZlKDJmkzWIVNafUxVMNOu9fqA/s320/Photo-0009.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #dd7700;&quot;&gt;&lt;u&gt;Schematics&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgjHVj9mTgNg5ADrrgA0GAPYwg5HYcEWdrOkFbP6PfJuHizUVr6Fajsyb0i-QMIqx-fu48rPyTSreCwpMuelrg5SfAtMpQxrfhaQoLW5yq2xuB_igQa-ogv631pc939hxuKLrZKJ4ACv0/s1600/inputlayer.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;259&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgjHVj9mTgNg5ADrrgA0GAPYwg5HYcEWdrOkFbP6PfJuHizUVr6Fajsyb0i-QMIqx-fu48rPyTSreCwpMuelrg5SfAtMpQxrfhaQoLW5yq2xuB_igQa-ogv631pc939hxuKLrZKJ4ACv0/s320/inputlayer.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;color: #dd7700;&quot;&gt;Input layer&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAFuRo0-QF_rRta_hAD0b4qPnxsv6N3JSAfyHoAdUS3p2cytbelb12h69wEmiSYC-vlEjxXUFUH7vNtupAqTEfAGs-WILiSd5q15h4l6mVUhOXiZJ3GJrzFGtfFTq7UjenTQQNWHl1OnU/s1600/outputlayer.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAFuRo0-QF_rRta_hAD0b4qPnxsv6N3JSAfyHoAdUS3p2cytbelb12h69wEmiSYC-vlEjxXUFUH7vNtupAqTEfAGs-WILiSd5q15h4l6mVUhOXiZJ3GJrzFGtfFTq7UjenTQQNWHl1OnU/s320/outputlayer.png&quot; width=&quot;306&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;color: #dd7700;&quot;&gt;Output layer&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQB9P4QRKNpRWJhcic6qwRI-2xTFv_6j3FnT26pKpzxfiUsYQek5S4ZoetCIs7BfecxA8oleMZc_5fUBxD4PqCV6JMdwy0rLPL9JwOfGoUzEY58d8fy4sRk7OTYyQYIsKfOpJYurFmyDk/s1600/powerlayer.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;237&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQB9P4QRKNpRWJhcic6qwRI-2xTFv_6j3FnT26pKpzxfiUsYQek5S4ZoetCIs7BfecxA8oleMZc_5fUBxD4PqCV6JMdwy0rLPL9JwOfGoUzEY58d8fy4sRk7OTYyQYIsKfOpJYurFmyDk/s320/powerlayer.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;color: #dd7700;&quot;&gt;Power layer&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;u&gt;&lt;span style=&quot;color: #dd7700;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/u&gt;&lt;br /&gt;
&lt;u&gt;&lt;span style=&quot;color: #dd7700;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/u&gt;&lt;br /&gt;
&lt;span style=&quot;color: #dd7700;&quot;&gt;&lt;u&gt;Common problems (I found)&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: yellow;&quot;&gt;&lt;u&gt;Matrix kept turning off&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
The most common problem I had was finding the matrix would just randomly turn off and wouldn&#39;t turn back on until I reset the Arduino board. I found out this was due to the resistance of the resistor I was using. There is a handy table on selecting the value for this resistor (Rset) in the guide in part 1.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: yellow;&quot;&gt;&lt;u&gt;The matrix is displaying my sequence/pattern incorrectly&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
This is most likely due to connecting the pins up incorrectly. Remember to check the pin mappings for your matrix and whether its common cathode or&amp;nbsp;anode.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: yellow;&quot;&gt;&lt;u&gt;My sequence will stop/freeze&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
This will probably be due to the delays used in the program. If its anything like mine there will be a delay at the start/end of the sequence code. Playing round with that should get it working again.&lt;br /&gt;
&lt;br /&gt;
Any other problems you have you&#39;re welcome to ask me about them, but I can&#39;t guarantee I&#39;ll be able to solve your problem :)&lt;br /&gt;
&lt;br /&gt;
Thanks for reading and I hope this was helpful&lt;br /&gt;
&lt;br /&gt;
Jake&lt;br /&gt;
&lt;span style=&quot;color: #dd7700;&quot;&gt;&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://rideonthespiral.blogspot.com/feeds/3919078135161509244/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rideonthespiral.blogspot.com/2012/02/arduino-how-to-power-led-matrices-using_26.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/658034019742100389/posts/default/3919078135161509244'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/658034019742100389/posts/default/3919078135161509244'/><link rel='alternate' type='text/html' href='http://rideonthespiral.blogspot.com/2012/02/arduino-how-to-power-led-matrices-using_26.html' title='Arduino - How to power LED matrices using shift registers: Part 2'/><author><name>Jake_F</name><uri>http://www.blogger.com/profile/09213449539257524662</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSjPzmu4i-mg7KoQQho1OGcnTR59TCCTBJioSb8IOOJ2vqMdCUUeK8HD2Kgnah4HB7_GSCBWfl59uM01ebRraZl9G2I5PDYyS1ORC4_plrTD8pjqtp7fJiChxX1Ffxrdk/s1600/Reaching_color_high.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEWVC5zfGpKYxrPPb_xUBG9kkJcAjdBIB8pugnuXYFlV-NIKGdMNRPa8jSwSDBRSOKvTwnMcgcOUHHzDA4HcfpYTPqbxcAuPnKjk_IKMnazFLgTDnjsQ-CQTfyjg-YCcOCzfefABanjPw/s72-c/Photo-0001.jpg" height="72" width="72"/><thr:total>3</thr:total><georss:featurename>Wales, UK</georss:featurename><georss:point>52.1306607 -3.7837117</georss:point><georss:box>50.883206200000004 -6.3105671999999995 53.378115199999996 -1.2568562</georss:box></entry><entry><id>tag:blogger.com,1999:blog-658034019742100389.post-4996530163444321789</id><published>2012-02-26T21:04:00.002+00:00</published><updated>2015-07-28T21:52:51.940+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Arduino"/><category scheme="http://www.blogger.com/atom/ns#" term="Bread board"/><category scheme="http://www.blogger.com/atom/ns#" term="Electronics"/><category scheme="http://www.blogger.com/atom/ns#" term="LED control library"/><category scheme="http://www.blogger.com/atom/ns#" term="LED matrix"/><category scheme="http://www.blogger.com/atom/ns#" term="MAX7219"/><category scheme="http://www.blogger.com/atom/ns#" term="shift register"/><title type='text'>Arduino - How to power LED matrices using shift registers: Part 1</title><content type='html'>I intend for this to be a comprehensive guide to controlling LED matrices, there are some guides out there (also as blogs) but it all depends on what you&#39;re doing.&lt;br /&gt;
&lt;br /&gt;
If you&#39;re looking for a quick step by step guide, skip to part 2, if you want to know everything about what you&#39;re doing, read this before part 2.&lt;br /&gt;
&lt;br /&gt;
Note - I have only been doing Arduino stuff since July 2011 and so I still consider myself to be a novice at it. While I have completed what I set out to do, there may be some things which I may have done wrong or are bad practice. If you have any questions please feel free to email me or ask in the comments below.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #dd7700;&quot;&gt;&lt;u&gt;Background&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
LED matrices can be used for many things, I have chosen to use it to represent the bead sort algorithm (this is for my dissertation, I will probably post about that at some point in the future). This is where beads are sorted using the properties of gravity, and is handy because each LED can represent 1 bead. Here is a gif I found on google images that show you how it works:&amp;nbsp;&lt;a href=&quot;http://mgs.spatial-computing.org/ImageGallery/EXEMPLES/BeadSort/anim_bead_julien.gif&quot;&gt;http://mgs.spatial-computing.org/ImageGallery/EXEMPLES/BeadSort/anim_bead_julien.gif&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #dd7700;&quot;&gt;&lt;u&gt;The equipment&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
Unfortunately the components for any build like this will be a little expensive, but it depends how you do it.&lt;br /&gt;
Here is a list of my equipment:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;color: #f1c232;&quot;&gt;2x&amp;nbsp;BB830 Solderless Plug-in Breadboard&lt;/span&gt;&amp;nbsp;&lt;a href=&quot;http://www.amazon.co.uk/BB830-Solderless-Plug--BreadBoard-tie-points/dp/B0040Z4QN8/ref=sr_1_1?s=electronics&amp;amp;ie=UTF8&amp;amp;qid=1328450466&amp;amp;sr=1-1&quot;&gt;http://www.amazon.co.uk/BB830-Solderless-Plug--BreadBoard-tie-points/dp/B0040Z4QN8/ref=sr_1_1?s=electronics&amp;amp;ie=UTF8&amp;amp;qid=1328450466&amp;amp;sr=1-1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f1c232;&quot;&gt;6 x MAX7219 CNG shift register&lt;/span&gt;&amp;nbsp;
&lt;a href=&quot;http://proto-pic.co.uk/led-display-driver-8-digit-max7219cng/&quot;&gt;http://proto-pic.co.uk/led-display-driver-8-digit-max7219cng/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f1c232;&quot;&gt;6 x Bi-colour LED matrix (8x8)&amp;nbsp;&lt;/span&gt;
&lt;a href=&quot;http://proto-pic.co.uk/led-matrix-dual-color-medium/&quot;&gt;http://proto-pic.co.uk/led-matrix-dual-color-medium/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f1c232;&quot;&gt;Pack of 100 M/F 12&quot; Jumper wires&lt;/span&gt;&amp;nbsp;
&lt;a href=&quot;http://proto-pic.co.uk/jumper-wires-premium-12-m-f-pack-of-100/&quot;&gt;http://proto-pic.co.uk/jumper-wires-premium-12-m-f-pack-of-100/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f1c232;&quot;&gt;Around 30 M/M 6&quot; Jumper wires&lt;/span&gt;&amp;nbsp;
&lt;a href=&quot;http://proto-pic.co.uk/jumper-wires-premium-6-m-m-pack-of-10/&quot;&gt;http://proto-pic.co.uk/jumper-wires-premium-6-m-m-pack-of-10/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f1c232;&quot;&gt;12 x 20KOhm resistors&lt;/span&gt;&amp;nbsp;
&lt;a href=&quot;http://proto-pic.co.uk/resistor-10k-ohm-1-6th-watt-pth/&quot;&gt;http://proto-pic.co.uk/resistor-10k-ohm-1-6th-watt-pth/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f1c232;&quot;&gt;Prototyping board&lt;/span&gt;&amp;nbsp;
&lt;a href=&quot;http://proto-pic.co.uk/pc-vectorboard-0-1-spacing-approx-165-x-114-mm/&quot;&gt;http://proto-pic.co.uk/pc-vectorboard-0-1-spacing-approx-165-x-114-mm/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: #f1c232;&quot;&gt;Any general Arduino board and its connecting cable, needs 18 free pins, 5V and GND, I&#39;m using an Arduino Uno but i&#39;m sure a Diecimila or Mega will do just fine.&lt;/span&gt;
&lt;a href=&quot;http://proto-pic.co.uk/arduino-uno/&quot;&gt;http://proto-pic.co.uk/arduino-uno/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;span style=&quot;color: #dd7700;&quot;&gt;&lt;u&gt;How the LED&amp;nbsp;matrices&amp;nbsp;work&lt;/u&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
When I first started using them, it was a bit of an alien world to me so hopefully this part will help. Remember the details for the matrices will be different for each model, check the matrix datasheet for all the necessary information. The matrices I&#39;m using are a common cathode 24 pin matrix. The common cathode part of it means that for a row to be on, it has to be set to LOW (cathode-negative). For this particular matrix pins 1-4 and 21-24 control the rows, pins 5-12 control the&amp;nbsp;columns&amp;nbsp;with green, pins 13-20 control the columns with red. The mappings are below:&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvco1r4e77Qz6cXlBX1dwNt5TJQrr8I_jW6xub4H-jeOhQ4b-H-VxdcrVejz22FDi_SdJfQQOT-iWtfQTM3q8OmEE2Sr1hRrFH1uIlKytMP9OSo9GpBIXe1B_q8uf97EhYRiYnXKFR-uc/s1600/pinmap.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvco1r4e77Qz6cXlBX1dwNt5TJQrr8I_jW6xub4H-jeOhQ4b-H-VxdcrVejz22FDi_SdJfQQOT-iWtfQTM3q8OmEE2Sr1hRrFH1uIlKytMP9OSo9GpBIXe1B_q8uf97EhYRiYnXKFR-uc/s320/pinmap.png&quot; width=&quot;270&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;color: #dd7700;&quot;&gt;&lt;u&gt;How the shift registers work&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
Shift registers are still a bit of an enigma to me. I don&#39;t know exactly how they work but know how to use them. The shift register I&#39;m using (MAX7219) is meant for LED control. It will take serial input (bits, one after another) and give parallel output (all the bits, all at once). It has 24 connections in total. Rather than explain each one in detail, this guide on the Arduino website covers pretty much everything:&amp;nbsp;&lt;a href=&quot;http://arduino.cc/playground/Main/MAX72XXHardware&quot;&gt;http://arduino.cc/playground/Main/MAX72XXHardware&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
The guide above also tells you how to choose the correct resistance value of Rset (in my case 30-40KOhms).&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #dd7700;&quot;&gt;&lt;u&gt;Arduino program&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
My source code will be as a link on part 2, but I will explain a bit about the program here.&lt;br /&gt;
&lt;br /&gt;
My program uses the LED control library (explained below) so that needs to be imported.&lt;br /&gt;
&lt;br /&gt;
One of the first lines is&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;LedControl lc=LedControl(2,3,4,1); &lt;/span&gt;This basically means create a new instance of LED control, using pins 2,3 and 4. The number 1 corresponds to the number of devices (which will always be 1 for my program).&lt;br /&gt;
&lt;br /&gt;
Next I have the &lt;span style=&quot;color: orange;&quot;&gt;step definitions&lt;/span&gt;. Each step consists of and array of 48 bytes, as I have 24 steps thats 24 * 48 bytes or 1.125KB which is a heck of a lot to hard code. Luckily I have created a program to do that for me, but that&#39;s another subject. It is likely that anyone following this will be using far smaller &quot;steps&quot; and fewer devices.&lt;br /&gt;
&lt;br /&gt;
After the step definitions there is a small bit of code denoting the delay between each step, this is mainly so I can simulate a bit of acceleration by reducing the delay per step.&lt;br /&gt;
&lt;br /&gt;
Following that are the &lt;span style=&quot;color: orange;&quot;&gt;step assignments. &lt;/span&gt;In brief these assignments tell the program which parts of the array to assign to which LED control instance.&lt;br /&gt;
&lt;br /&gt;
For my particular case at the end of each set of steps I wipe the LEDs and start again.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: black; color: red;&quot;&gt;IMPORTANT - &lt;/span&gt;&lt;span style=&quot;background-color: black;&quot;&gt;There must always be a delay at the beginning/end of your step definitions, I&#39;m not sure why but it messes up otherwise.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
And that&#39;s it :)&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #dd7700;&quot;&gt;&lt;u&gt;Using the LED control library&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
Firstly make sure you have the Arduino software running and working (version 1.0 was released not too long ago).&lt;br /&gt;
&lt;br /&gt;
I have used the LED control library, details of which can be found here:&amp;nbsp;&lt;a href=&quot;http://www.arduino.cc/playground/Main/LedControl&quot;&gt;http://www.arduino.cc/playground/Main/LedControl&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
You can also download the library as a .zip file from that link, the link to the file is in the section &quot;Sourcecode and download&quot;.&lt;br /&gt;
&lt;br /&gt;
Make sure the Library files go to the &quot;Libraries&quot; or &quot;Lib&quot; folders in the Arduino program.&lt;br /&gt;
&lt;br /&gt;
To use the library, go to Tools -&amp;gt; Import Library -&amp;gt; LED control. You may have to close and open the Arduino program again if it was open when you added the library files.&lt;br /&gt;
&lt;br /&gt;
Now you&#39;re set to go :D.&lt;br /&gt;
&lt;br /&gt;
I will gladly try to answer any questions so please feel free to comment/email me with any queries.&lt;br /&gt;
&lt;br /&gt;
Now have a look at part 2&lt;br /&gt;
&lt;br /&gt;
Jake&lt;br /&gt;
&lt;span style=&quot;color: #dd7700;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://rideonthespiral.blogspot.com/feeds/4996530163444321789/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rideonthespiral.blogspot.com/2012/02/arduino-how-to-power-led-matrices-using.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/658034019742100389/posts/default/4996530163444321789'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/658034019742100389/posts/default/4996530163444321789'/><link rel='alternate' type='text/html' href='http://rideonthespiral.blogspot.com/2012/02/arduino-how-to-power-led-matrices-using.html' title='Arduino - How to power LED matrices using shift registers: Part 1'/><author><name>Jake_F</name><uri>http://www.blogger.com/profile/09213449539257524662</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSjPzmu4i-mg7KoQQho1OGcnTR59TCCTBJioSb8IOOJ2vqMdCUUeK8HD2Kgnah4HB7_GSCBWfl59uM01ebRraZl9G2I5PDYyS1ORC4_plrTD8pjqtp7fJiChxX1Ffxrdk/s1600/Reaching_color_high.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvco1r4e77Qz6cXlBX1dwNt5TJQrr8I_jW6xub4H-jeOhQ4b-H-VxdcrVejz22FDi_SdJfQQOT-iWtfQTM3q8OmEE2Sr1hRrFH1uIlKytMP9OSo9GpBIXe1B_q8uf97EhYRiYnXKFR-uc/s72-c/pinmap.png" height="72" width="72"/><thr:total>1</thr:total><georss:featurename>Wales, UK</georss:featurename><georss:point>52.1306607 -3.7837117</georss:point><georss:box>50.883206200000004 -6.3105671999999995 53.378115199999996 -1.2568562</georss:box></entry></feed>