Limpkin's blog - Tag - usb<div>An electronics geek blog, dedicated to sharing and open source. Check out my stores: <a href="https://lectronz.com/stores/stephanelec" hreflang="en" title="Lectronz store">EU</a> / <a href="https://www.tindie.com/stores/stephanelec" hreflang="en" title="tindie store">EU & US</a>.</div>2024-03-29T00:41:47+00:00Mathieuurn:md5:51de6a3d917257edeff5a252fe925b02DotclearMy Business Card v2urn:md5:96c47c72f3d3651f0fcc4b7e9b0c70892014-06-15T17:54:00+01:002023-04-14T13:46:28+01:00limpkinMy Projectsavrbusiness cardlufausb<p>At the end of this month, I'll be leaving my current job. I therefore thought it'd be a nice occasion to build a new business card for my future interviews:<br /></p>
<p><img src="https://www.limpkin.fr/public/Business_card/.business_card_v2_m.jpg" alt="Business card v2" style="display:table; margin:0 auto;" title="Business card v2, juin 2014" /></p> <p>You may remember the <a href="https://www.limpkin.fr/index.php?post/2012/09/15/My-new-business-card" hreflang="en" title="business card v1">first version of my business card</a> made more than one and a half years ago (time flies!). It was basically made of two PCBs soldered together :<br /></p>
<p><a href="https://www.limpkin.fr/public/Business_card/business_card_assembled_lighten.JPG" title="Assembled business card"><img src="https://www.limpkin.fr/public/Business_card/.business_card_assembled_lighten_m.jpg" alt="Assembled business card" style="display:table; margin:0 auto;" title="Assembled business card, oct. 2012" /></a><br />
So why not simply assemble more of them? Well I wasn't completely happy with the way the two PCBs were assembled and wanted to try a new technique I had used for the top PCBs of the <a href="http://hackaday.com/tag/developed-on-hackaday/" hreflang="en" title="Mooltipass project">Mooltipass project</a>:<br /></p>
<p><a href="https://www.limpkin.fr/public/Business_card/mooltipass_top.JPG" title="Mooltipass top PCB"><img src="https://www.limpkin.fr/public/Business_card/.mooltipass_top_m.jpg" alt="Mooltipass top PCB" style="display:table; margin:0 auto;" title="Mooltipass top PCB, juin 2014" /></a><br />
As you can see the PCB was slightly milled so reverse mounted LEDs may be directly soldered on the board. Well for this new business card the only difference is that the LEDs are soldered on the bottom PCB:<br /></p>
<p><a href="https://www.limpkin.fr/public/Business_card/business_card_v2_bot.JPG" title="Business card v2 bottom"><img src="https://www.limpkin.fr/public/Business_card/.business_card_v2_bot_m.jpg" alt="Business card v2 bottom" style="display:table; margin:0 auto;" title="Business card v2 bottom, juin 2014" /></a><br />
The new card stackup perfectly fits into a USB connector as it is 2.4mm high (1.6+0.8). The old version was actually thinner so I had to apply solder on the USB pads, which was not so pretty in retrospect. You'll be surprised to know that the new card can still fit in a normal wallet as it is completely flat.<br />
However, the hard part was to solder the two PCBs together as a 1.5mm wide exposed copper 'band' was put near the cards' edges to this goal. Using a reflow oven with the card facing up turned the soldermask yellowish so I ended up soldering them by hand with a hot air gun.<br /><br /></p>
<h2>Schematics and functionalities<br /></h2>
<p>Pratically nothing changed between the new and the old version except the number of PWM channels. I therefore decided to switch to the <strong>ATMega32U4</strong> from Atmel (quite costly I know) as I could re-use all the code I had made for the v1. The card is still recognized as an external <strong>USB drive</strong> (2MB!) and can be reprogrammed via the integrated bootloader (launched by sliding some aluminium foil on the 3 exposed pads on the PCB shown above). You may also have noticed that the flash isn't exposed to the outside as I wanted to keep some kind of central symmetry.<br />
I migrated the old schematics and layout to <strong>Kicad</strong> :<br /></p>
<p><a href="https://www.limpkin.fr/public/Business_card/business_card_v2_schem.png" title="Business card schematics v2"><img src="https://www.limpkin.fr/public/Business_card/.business_card_v2_schem_m.jpg" alt="Business card schematics v2" style="display:table; margin:0 auto;" title="Business card schematics v2, juin 2014" /></a><br />
For a detailed schematics explanation and performance analysis, please head out <a href="https://www.limpkin.fr/index.php?post/2012/09/15/My-new-business-card" hreflang="en" title="business card v1">to my card v1 blog post</a>. The only thing worth mentionning here is that given the ATMega32U4 only had 7 PWM channels I had to use a given PWM channel <strong>complementary output</strong> and two extra I/O pins to enable/disable these given LEDs. Two groups of 2 LEDs will therefore always have the same duty cycle.<br /><br /></p>
<h2>End result and resources<br /></h2>
<p><a href="https://www.limpkin.fr/public/Business_card/business_card_v2.JPG" title="Business card v2"><img src="https://www.limpkin.fr/public/Business_card/.business_card_v2_m.jpg" alt="Business card v2" style="display:table; margin:0 auto;" title="Business card v2, juin 2014" /></a><br />
Click on the picture to zoom :-) . Here are the files you'll need to make your own custom business cards:<br />
<a href="https://www.limpkin.fr/public/Business_card/business_card_final_code.rar" hreflang="en" title="business card v1">Business card v2 final code</a> <a href="https://www.limpkin.fr/public/Business_card/business_card_kicad.rar" hreflang="en" title="business card v1">Business card v2 kicad solution</a><br /></p>
<p>Cheers!</p>Atsam3u + SDCard + USB cdc/msd + fat32 with at91lib & Chan's fat codeurn:md5:e7ae1913e881045b866e8cf92b1da4c12012-12-04T13:03:00+00:002024-03-09T10:37:52+00:00limpkinMy ProjectsARMAT91LIBATSAM3UCDCCortex m3FAT32MSDusb<p>Yep, for the first time this will be (mostly) a <strong>code</strong> article :-) .<br>
But if one day you want to make a <strong>Hi-Speed</strong> (480Mbit/s) USB composite device with <strong>CDC</strong> (communication) and <strong>MSD</strong> (mass storage) classes, this is the post you'll want to read.<br><br>
<img src="https://www.limpkin.fr/public/modules_code/.pcb_platform_m.jpg" alt="Platform PCB" class="media-center" title="Platform PCB, déc. 2012"></p> <p>At my current job we're currently working on a complete open software & hardware development platform for physicists,biologists.... <strong>hobbyists</strong>.<br>
This development platform is primarily aimed at facilitating the realization of high speed (several GHz) functions that quantum physicist need for their experiments, as well as providing data collection capabilities.<br>
Without going into many details, it will physically be a 3U rack where users can plug different eurocard modules that perform specific functions.<br></p>
<p>The platform is <strong>open hardware/software</strong> for <strong>Windows and Linux</strong>, which actually made the project's start quite difficult.<br>
Anyway, the chosen microcontroller is a cortex-m3 based ATSAM3U from Atmel, that provides <strong>USB 2.0</strong> connectivity.<br></p>
<p><a href="https://www.limpkin.fr/public/modules_code/module.png" title="Architecture"><img src="https://www.limpkin.fr/public/modules_code/.module_m.jpg" alt="Architecture" class="media-center" title="Architecture, déc. 2012"></a>
Each module put in the 3U rack will be connected by USB to a main computer.<br>
When connected, it will be recognized as a storage device in order to <strong>send to the computer the files required to operate it</strong> (matlab/labview/etc etc) and also be recognized as a communication device for the computer <strong>to send commands to the module</strong>.<br>
For this project, we therefore needed (from the host computer) to:<br>
- read/write data to a micro SDCard connected to the uC<br>
- dialog with the uC<br>
and from the microcontroller:<br>
- read all the files stored on the SDCard<br></p>
<p>The developments tools we then chose are:<br>
- <strong><a href="http://www.kicad-pcb.org/display/KICAD/KiCad+EDA+Software+Suite" hreflang="en" title="Kicad">Kicad</a></strong> for schematics and routing<br>
- <strong><a href="http://www.yagarto.de/" hreflang="en" title="Yagarto">Yagarto</a> and Eclipse</strong> for the hardware code<br></p>
<p>And for debugging, we picked the Segger J-Link JTAG:<br></p>
<p><a href="https://www.limpkin.fr/public/modules_code/segger.jpg" title="Segger J-Link"><img src="https://www.limpkin.fr/public/modules_code/segger.jpg" alt="Segger J-Link" class="media-center" title="Segger J-Link, déc. 2012"></a><br>
As you can guess, developping this kind of code from scratch can be <strong>insanely</strong> time consuming (I mean <strong>weeks</strong> of coding).<br>
Therefore, there was no other choice than to find libraries that provide a USB Stack with CDC/MSD classes, SDCard interfacing, FAT32 reads, while also supporting <strong>DMA transfers</strong>.<br></p>
<p>As you may know, I <strong>hate</strong> using libraries. They are usually not well documented and you have <strong>no clue</strong> on how they internally work.<br>
Well, after having spent a few days browsing through them, this impression was <strong>justified</strong>.<br>
But I finally managed to get things working with:<br>
- the AT91lib from gnumonks<br>
- the fat library from <a href="http://elm-chan.org/fsw/ff/00index_e.html">chan</a><br></p>
<p>As parts of the at91lib don't officially support the ATSAM3U, there were very few tweaks to do (mentionned in the main.c). There was one particular bug that took me 4 days to find (ATSAM3U DPRAM initialization).<br>
Finding all the files & flags to include in the makefile was quite a challenge, so I hope I'll save you the trouble. With one cheap micro SDCard, we managed to get <strong>5.5Mbyte/s writes</strong>. We (yet) haven't tried with other cards.<br></p>
<p>Anyway, here is the Eclipse source code, which is still in <strong>beta</strong> : <a href="https://www.limpkin.fr/public/modules_code/eclipse_template_code.rar">Eclipse template code</a><br>
Please note that this firmware doesn't have fancy options such as card detection (which we didn't need).<br></p>
<p><a href="https://www.limpkin.fr/public/modules_code/platform.png" title="Platform"><img src="https://www.limpkin.fr/public/modules_code/.platform_m.jpg" alt="Platform" class="media-center" title="Platform, déc. 2012"></a><br>
<a href="https://www.limpkin.fr/public/modules_code/pcb_platform.jpg" title="Platform PCB"><img src="https://www.limpkin.fr/public/modules_code/.pcb_platform_m.jpg" alt="Platform PCB" class="media-center" title="Platform PCB, déc. 2012"></a><br>
For those who are curious about the platform, here are the schematics of the two boards (also in beta) : <a href="https://www.limpkin.fr/public/modules_code/schematics_host.pdf" hreflang="en" title="gnumonks at91lib">Schematics host</a> <a href="https://www.limpkin.fr/public/modules_code/schematics_template.pdf" hreflang="en" title="gnumonks at91lib">Template schematics</a> .<br>
The PCB files will soon be released ;-) .<br></p>
<p>Cheers!<br></p>My new business cardurn:md5:a755ddae9225007009d2bdbe2d34fa932012-10-03T17:57:00+01:002023-04-14T13:52:26+01:00limpkinMy Projectsavrbusiness cardlufateensyusb<p>As it seems to be a new trend out there, I thought I would give it a go :-) <br /><br />
<img src="https://www.limpkin.fr/public/Business_card/.business_card_assembled_lighten_m.jpg" alt="Assembled business card" style="display:table; margin:0 auto;" title="Assembled business card, oct. 2012" /><br /></p> <p>You may have seen that there <a href="http://hackaday.com/2012/08/24/usb-business-card-packs-an-arm-processor/" hreflang="en">are</a> <a href="http://hackaday.com/2012/07/18/the-many-iterations-of-joes-pcb-business-card/" hreflang="en">a</a> <a href="http://hackaday.com/2012/06/08/555-business-card/" hreflang="en">couple</a> of <a href="http://hackaday.com/2010/10/29/tiny-usb-business-card/" hreflang="en">similar</a> <a href="http://hackaday.com/2010/05/25/mass-storage-business-card/" hreflang="en">projects</a> on the internet but most of them (in my opinion) are not very convenient.<br />
What I mean by that is that they either <strong>require external batteries</strong>, or are <strong>too thick/not flat</strong>.<br />
To me, a business card is meant to be <strong>stored in the wallet</strong> of the person you'll give it to. Therefore, it should be <strong>flat</strong> but also provide some <strong>super-ultra-funky</strong> functionalities ;-) .<br />
As its main goal is to sell yourself, I thought that making the card a <strong>mass storage USB key</strong> containing a resume & pictures of produced work was <strong>a must</strong>... and why not add a <strong>couple of LEDs</strong> while we are at it?<br /><br /></p>
<h2>The methodology<br /><br /></h2>
<p>First, let's recap our requirements. The business card should:<br />
- be flat<br />
- provide USB connectivity<br />
- have flash storage capability<br />
- have a USB bootloader to program it<br />
- have only <strong>low profile smd components</strong><br />
- be cheap to produce<br /><br />
Creating a cheap card usually involves <strong>dirty tricks</strong> that I will detail later.<br />
As for being flat, I had an epiphany: <strong>stacking two PCBs, where the top one has holes to let the components go through</strong>.<br />
And instead of using a USB connector, why not put traces on the PCB itself so it <strong>can directly plug in the computer</strong>?<br />
That gives us another requirement: <strong>the stackup needs to be 2mm high</strong>. Therefore, we need to reduce a little the card dimensions so it can fit in a wallet. I chose to make it <strong>50 by 80mm</strong>.<br /><br /></p>
<h2>The components<br /><br /></h2>
<p>I picked the <strong>AT90USB82/162</strong> from Atmel as it is quite cheap but also because there are a few libraries available for it: <strong><a href="http://www.fourwalledcubicle.com/LUFA.php" hreflang="en">Lufa</a></strong> and the <strong><a href="http://www.pjrc.com/teensy/usb_keyboard.html" hreflang="en">teensy examples</a></strong>.<br />
This microcontroller will be running at 8MHz, which is largely sufficient as the data transfers won't be huge :-) .<br />
Just to be extra precautious, I also added an ESD protection chip especially meant for the USB lines. As for the flash, I took the M25PX16 from numonyx which is (only) 16Mb:<br /></p>
<p><a href="https://www.limpkin.fr/public/Business_card/schematics.png" title="Business card schematics"><img src="https://www.limpkin.fr/public/Business_card/.schematics_m.jpg" alt="Business card schematics" style="display:table; margin:0 auto;" title="Business card schematics, sept. 2012" /></a><br />
Don't pay attention to all the "CON1" connectors, as they are pads to connect the bottom PCB with the top one.<br />
The AT90USB82 has an internal 3.3V regulator that I used <strong>to power the flash</strong>. Here is the dirty trick: as the flash only accepts 3.3v input voltages, I put resistors in series between the flash and uC so <strong>the internal flash protection diodes can lower the input voltage</strong>. Well, it's not for the price of the removed resistors (if I was doing a bridge), but more for the general aspect of the board.<br />
And the AVR recognizes a high level at its inputs if the voltage is <strong>above 3V</strong> when powered at 5V... neat right?<br />
Here is the bill of materials:<br /></p>
<p><a href="https://www.limpkin.fr/public/Business_card/BoM.png" title="Business card bill of materials"><img src="https://www.limpkin.fr/public/Business_card/.BoM_m.jpg" alt="Business card bill of materials" style="display:table; margin:0 auto;" title="Business card bill of materials, sept. 2012" /></a><br />
Total cost is a little <strong>under 5 dollars</strong> for a 100 units quantity, <strong>4</strong> if you remove the ESD protection chip. If you are curious about the BoM generation tool, have a look at <a href="https://www.limpkin.fr/index.php?post/2012/09/02/Automatic-Bill-of-Materials-generation-for-Digikey-components-in-an-Excel-file">my other post.</a><br /><br /></p>
<h2>The bottom PCB<br /><br /></h2>
<p><a href="https://www.limpkin.fr/public/Business_card/business_card_bottom.JPG" title="Business card bottom pcb"><img src="https://www.limpkin.fr/public/Business_card/.business_card_bottom_m.jpg" alt="Business card bottom pcb" style="display:table; margin:0 auto;" title="Business card bottom pcb, oct. 2012" /></a><br />
Yep, I tried to do some artistic routing ;-) .<br />
Unfortunately, wanting low profile components usually involves <strong>fine pitch soldering</strong>, so I hope you are skilled in this matter!<br />
You may have noticed the pads on the top of the PCB: <strong>by sliding a small piece of tin foil on these pins, it will make the AT90USB go into bootloader mode</strong> (reset and hwb pins).<br />
As you only need to program the microcontroller once, it is not a problem if they are hidden in the stacking up process.<br /><br /></p>
<h2>The firmware<br /><br /></h2>
<p>Well, at the beginning of this project, I thought an AT90USB82 (8KB flash) would be enough to accommodate a USB mass storage stack but unfortunately <strong>I was wrong</strong>.<br />
So I made two versions of the hardware (one with the 8KB AT90USB82, the other with the 16KB <strong>AT90USB162</strong>) and two versions of the software.<br />
The small software version <strong>has a USB HID stack</strong> adapted from teensy code examples, while the bigger one provides the mass storage functionalities I talked about.<br />
Why USB HID? Well, because now if you plug the card in your computer, it will <strong>input keyboard shortcuts to open a browser to go to my website</strong>. Ok, that may be considered a bit intrusive :-) .<br />
Adapting the Teensy code to my needs was pretty straight forward (the pll setting just needed to be changed).<br />
To handle all types of keyboard layouts, I'm entering the <strong>alt + xxx</strong> key codes to the computer.<br /><br /></p>
<h2>LUFA & USB mass storage<br /><br /></h2>
<p>Dealing with LUFA was quite tricky.<br />
I'm personally using AVR studio 6, as I really like its new features (code completion, syntax highlighting). However, LUFA is exclusively meant to be used with <strong>make</strong>.<br />
Therefore, it took me quite a while to learn which <strong>flags</strong> I needed to set for the compiler, as well as <strong>finding the .c files to include</strong> in the avr project (symbolic links).<br />
Anyway, I did it in such a way that <strong>you only need to put the LUFA folder in the avr project one for the solution to compile</strong>. It'll then automatically look for the correct files in the LUFA folder.<br />
LUFA, when using it with your <strong>own board</strong>, requires you to create the following files with given function names: <em>Buttons.h / Dataflash.h / LEDs.h / Joystick.h</em> (even if you don't have LEDs or a joystick).<br />
As for the flash management, you'll need to edit <em>DataflashManager.c & DataflashManager.h</em>. I advise you to <strong>start from scratch when dealing with these files</strong> as the template code structure may not be the good one for you.<br /></p>
<p><a href="https://www.limpkin.fr/public/Business_card/business_card_test.png" title="Business card speed test"><img src="https://www.limpkin.fr/public/Business_card/.business_card_test_m.jpg" alt="Business card speed test" style="display:table; margin:0 auto;" title="Business card speed test, sept. 2012" /></a><br />
The maximum write speed I managed to attain was 38kB/s, and 225kB/s for the read speed. <strong>Far from great</strong>, but <strong>enough</strong> for a 2MB USB stick.<br />
You'll need to learn about flash page sizes (the <strong>maximum</strong> amount of bytes <strong>you can write at once</strong>), flash erasable (sub)sector sizes (the <strong>minimum</strong> amount of pages you <strong>can erase in the flash</strong>) and <strong>OS block sizes</strong> (number of bytes the OS will consider as an <strong>undividable data unit</strong>).<br />
Therefore, if your erasable (sub)sector size is bigger than your OS block size, you'll <strong>maybe need to do some buffering in your microcontroller</strong>: read the entire erasable sector, change the data you want and resend all the data to the flash.<br />
Here comes a <strong>(very) dirty trick</strong> :-) .<br />
The M25PX16 erasable subsector size is <strong>4096bytes</strong> while its page size is 256bytes. By default, the LUFA <strong>OS block size is set to 512bytes</strong>.<br />
In the template code, it is explicitely said that <strong>this value shouldn't be changed</strong>, as not all operating systems can handle a bigger block size value.<br />
However, my <strong>AT90USB162 ram is only 512bytes</strong> so buffering was <strong>out of the question</strong>.<br />
Only choice: <strong>set the OS block size equal to my flash subsector size</strong>, which is 4096bytes.<br />
I got lucky and it <strong>worked</strong>... well for windows 7 / XP / Ubuntu 12 :-D , as I didn't try for the other operating systems.<br /><br /></p>
<h2>Top PCB and stackup<br /><br /></h2>
<p>Now that the firmware is done, it's time for the final assembly!<br /></p>
<p><a href="https://www.limpkin.fr/public/Business_card/business_card_assembled.JPG" title="Assembled business card"><img src="https://www.limpkin.fr/public/Business_card/.business_card_assembled_m.jpg" alt="Assembled business card" style="display:table; margin:0 auto;" title="Assembled business card, oct. 2012" /></a><br />
If you're using seeedstudio, you'll need to put the holes outlines in <strong>a .GML file</strong>. I made the mistake and the guys over there were kind enough to relaunch it into production.<br />
The cut quality could be better... but the final result is <strong>quite neat</strong>:<br /></p>
<p><a href="https://www.limpkin.fr/public/Business_card/business_card_assembled_lighten.JPG" title="Assembled business card"><img src="https://www.limpkin.fr/public/Business_card/.business_card_assembled_lighten_m.jpg" alt="Assembled business card" style="display:table; margin:0 auto;" title="Assembled business card, oct. 2012" /></a><br /><br /></p>
<h2>The sources<br /><br /></h2>
<p>If you appreciate this work and want to reproduce it, here are all the sources you'll need :-) :<br />
<a href="https://www.limpkin.fr/public/Business_card/schematics.pdf">Business card schematics</a> <a href="https://www.limpkin.fr/public/Business_card/BoM_templatev2.xlsm">Bill of Materials</a> <a href="https://www.limpkin.fr/public/Business_card/Bottom_PCB_gerbers.rar">Bottom PCB gerbers</a> <a href="https://www.limpkin.fr/public/Business_card/Top_PCB_gerbers.rar">Top PCB gerbers</a> <a href="https://www.limpkin.fr/public/Business_card/teensy_code.rar">Teensy code</a> <a href="https://www.limpkin.fr/public/Business_card/final_code.rar">LUFA final code</a><br /></p>
<p>If you want me to assemble one for you, you can drop me a message ;-)<br />
Cheers!</p>RGB led matrices with animated gifsurn:md5:4660fe52b82b554fb61f7fd5898e52f12011-05-12T07:51:00+01:002024-03-08T21:07:25+00:00limpkinMy Projectsavrfpslicled matrixMatlabmatlab programrgbusb<p>Hey guys, I just came back from a trip to China! Not only was it an occasion to visit this vast country but also a good opportunity to go to the numerous <strong>electronics markets</strong> in the cities of Xi'an and Beijing. Yes, even on holidays I'm still into electronics ;-) .<br>
So here are the few interesting things I brought back, and especially what I did with them...<br><br>
<img src="https://www.limpkin.fr/public/RGB_Matrix/.rgb_led_matrix_m.jpg" alt="RGB led matrix" class="media-center" title="RGB led matrix, mai 2011"></p> <p>For people following my blog, no surprises there, led matrices! I was actually surprised to not find any other things that I'd like. The reason for this is that most interesting components (for example the screen of my <a href="https://www.limpkin.fr/index.php?post/2011/01/11/The-Engine-Control-Unit-monitor-project">ECU monitor project</a>) are made by companies that are voluntarly not present in this kind of markets. You'll thus only find common components and of course a lot of leds! Prices are obviously much cheaper than in Europe ;-) . <br></p>
<p><a href="https://www.limpkin.fr/public/RGB_Matrix/IMG_4148.JPG" title="Led matrices from china"><img src="https://www.limpkin.fr/public/RGB_Matrix/.IMG_4148_m.jpg" alt="Led matrices from china" class="media-center" title="Led matrices from china, mai 2011"></a><br>
The matrices I bought were actually quite hard to find (especially the one on the left). From left to right, you'll thus see a <strong>64 * 32 RGB led matrix with a 4mm pitch</strong> (around 160 dollars) and a <strong>32 * 16 RGB led matrix with a 6mm pitch composed of SMD leds</strong> (around 40). If you compare their prices to the individual 8 * 8 elements you can find on <a href="http://www.sparkfun.com/products/683" hreflang="en" title="Sparkfun">Sparkfun</a>, well I would have been stupid by not buying them :-D .<br>
Two different types of led matrices for two very different types of uses: the one made of the 32 <strong>8*8 individual matrices</strong> put together is made for <strong>indoor</strong> use (normal brightness, good opacity, small pitch thus small viewing distance) while the other is meant for <strong>outdoor</strong> use (very high brightness and long viewing distance).<br></p>
<p><a href="https://www.limpkin.fr/public/RGB_Matrix/IMG_4122.JPG" title="Back of the led matrices"><img src="https://www.limpkin.fr/public/RGB_Matrix/.IMG_4122_m.jpg" alt="Back of the led matrices" class="media-center" title="Back of the led matrices, mai 2011"></a><br>
I have to say that the aspect and quality of these led panels seem <strong>very good</strong> when examining them (I still have the cliché that "made in china" = bad quality). Solders and assembly are neat, the seller even provided me with some <strong>magnet feet</strong> allowing me to put the led panels on every metalic surface (ie: my computer!). Very convenient if you don't have much space on your desk. The production date written on the board is end of september 2010 so I am very surprised that it is not possible to find this LED panel on the web.<br>
The main component in charge of controlling any of the (64 * 3 = 192) pixels of one line is the <strong>JXI5020</strong> chip (don't forget that you need to scan the array), which seems to be only used in china as I spent 3 hours to find its datasheet (which is in chinese of course). Look at the bottom of this page to download it. The JXI5020 is basically a 16bits shift register with store and output enable commands, and its outputs are inverted. The specified maximum clock frequency is 25 MHz and thus a maximum theoretical LED panel refresh rate of <strong>24.4KHz</strong>, allowing <strong>8 bits PWM</strong> for 60 FPS (thus 24bits / pixel).<br></p>
<p><a href="https://www.limpkin.fr/public/RGB_Matrix/IMG_4114.JPG" title="FPSLIC control board"><img src="https://www.limpkin.fr/public/RGB_Matrix/.IMG_4114_m.jpg" alt="FPSLIC control board" class="media-center" title="FPSLIC control board, mai 2011"></a><br>
As I wanted to quickly show you these matrices in action, I decided to adapt the wiring of my other FPSLIC based <a href="https://www.limpkin.fr/index.php?post/2010/02/14/The-FPSLIC-bicolor-matrix-project">led matrix control board</a> to make it work with these ones. This is when I was very happy that I applied my rule number one when producing this control board: always make <strong>two boards</strong> when you only need one! As the interface to control the pixels hasn't changed since single color led matrices (only additional contacts for the additional colors), <strong>no need to change my code in depth</strong>.<br></p>
<p><a href="https://www.limpkin.fr/public/RGB_Matrix/fpslic_arch.png" title="FPSLIC Architecture"><img src="https://www.limpkin.fr/public/RGB_Matrix/fpslic_arch.png" alt="FPSLIC Architecture" class="media-center" title="FPSLIC Architecture, mai 2011"></a><br>
<a href="https://www.limpkin.fr/index.php?post/2010/02/14/The-FPSLIC-bicolor-matrix-project">My other led matrix</a> is bi-color, composed of 3 64*32 led panels as well. As there is one additional color in the matrices I bought, with the same control board I can thus only control a 2 * 64*32 RGB led matrix panel without using any trick. One led panel interface is thus "sacrified" to connect its color data lines to the addional color on the other two indoor led panels (all the panels have synchronized signals). Of course it is possible to control more of these LED panels by soldering together the clock / latch / enable signals to free some pins on the FPSLIC.<br></p>
<p><a href="https://www.limpkin.fr/public/RGB_Matrix/IMG_4093.JPG" title="// Photo close up rgb"><img src="https://www.limpkin.fr/public/RGB_Matrix/.IMG_4093_m.jpg" alt="// Photo close up rgb" class="media-center" title="RGB Led matrix, mai 2011"></a><br>
The result looks quite nice! I didn't implement any PWM to correct the colors, but the white balance is still <strong>very</strong> sweet. Of course, if you are planning on assembling a bigger panel, you'll surely need to <strong>control this</strong>, as it is the biggest inconvenient of led screens nowadays.<br>
I indeed realize that my control board is now completely obsolete for the led panels I use, so a new one will be made in the coming months (I am thinking using an AT90SAM, FPGA + ARM in a single chip).<br><br>
In the meantime, I decided to tweak my VHDL & AVR code to allow additional functionalities and max my overall performances :<br>
- Separate buffers for red green and blue<br>
- Possibility to change the red, green and blue data buffer addresses on the FPGA side to allow double (or more) buffering<br>
- Higher display refresh rate: <strong> 480Hz!</strong> You don't see any flickering now...<br>
- Individual control of each color of the led matrix from the AVR side of the FPSLIC, with only one function call (on / off / normal / inverted). Cool effects are thus easy to do when bringing this led matrix to several shows :) .<br>
- 2bits PWM per color per pixel (woot!), thus allowing a total of <strong>160 frames per second</strong><br>
- <strong>1Mbit/s</strong> RS232 speed between the PC and the FPSLIC (through the use of the FTDI) to enable <strong>40 frames per second in streaming mode</strong><br></p>
<p><a href="https://www.limpkin.fr/public/RGB_Matrix/IMG_4091.JPG" title="RGB Led matrix"><img src="https://www.limpkin.fr/public/RGB_Matrix/.IMG_4091_m.jpg" alt="RGB Led matrix" class="media-center" title="RGB Led matrix, mai 2011"></a><br>
And then I wondered, as I always lack of things to display on my led matrices, where could I find nice animations to show on such small resolution screens? The solution was pretty obvious: <strong>animated gifs</strong>. Yes, these crappy things that are at least 10 years old, who were used so much at the time the internet was at its beginning! Small resolution, no anti-aliasing, simple design, this was perfect.<br>
As my control board is resource-limited, I created a simple <strong>100 lines Matlab script</strong> that display on the led matrix one after the other all the animated gifts in a given folder on your computer. Please look at the code below, you will see that Matlab makes it very easy to do such complex tasks. Ah yes, <a href="http://www.evilmadscientist.com/article.php/LEDpics" hreflang="en" title="photographing leds">photographing leds</a> (and even worse, filming them) is a very complex task that I still haven't mastered. So the colours you see in the different pictures and videos are not exactly the ones you actually see. Anyway, check out this video:<br></p>
<div class="external-media" style="margin: 1em auto; text-align: center;">
<object width="480" height="295"><param name="movie" value="https://www.youtube.com/v/Q9pLGGuIy7M?version=3"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="https://www.youtube.com/v/Q9pLGGuIy7M?version=3" type="application/x-shockwave-flash" width="600" height="395" allowscriptaccess="always" allowfullscreen="true"></embed></object>
<br /><a href="https://www.youtube.com/watch?v=Q9pLGGuIy7M">Animated gifs on a 64*64 RGB led matrix</a>
</div>
<p>And here is a small video of my <a href="https://www.limpkin.fr/index.php?post/2011/04/07/Electronic-projects-and-matlab">matlab program</a> adapted for this new led panel (you will see that I added a "lag effect" to show the different colours):<br></p>
<div class="external-media" style="margin: 1em auto; text-align: center;">
<object width="480" height="295"><param name="movie" value="https://www.youtube.com/v/vERS_CKG2iQ?version=3"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="https://www.youtube.com/v/vERS_CKG2iQ?version=3" type="application/x-shockwave-flash" width="600" height="395" allowscriptaccess="always" allowfullscreen="true"></embed></object>
<br /><a href="https://www.youtube.com/watch?v=vERS_CKG2iQ">64*64 RGB Led matrix + Matlab + Webcam</a>
</div>
<p>And if you are thinking of building a big led screen, look at what I found next to the Xidan metro station in Beijing (this is made with the SMD led panels):<br></p>
<div class="external-media" style="margin: 1em auto; text-align: center;">
<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/XqejXevyHCc?version=3"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/XqejXevyHCc?version=3" type="application/x-shockwave-flash" width="600" height="474" allowscriptaccess="always" allowfullscreen="true"></embed></object>
<br /><a href="http://www.youtube.com/watch?v=XqejXevyHCc">Led screen in Beijing</a>
</div>
<p>Here are all the files you might need:<br>
<a href="https://www.limpkin.fr/public/RGB_Matrix/JXI5020.pdf">JXI5020 datasheet</a> <a href="https://www.limpkin.fr/public/RGB_Matrix/fpslic_led_matrix.rar">FPSLIC VHDL display code</a> <a href="https://www.limpkin.fr/public/RGB_Matrix/rgb_screen_generation.m">Picture to led matrix transfer</a> <a href="https://www.limpkin.fr/public/RGB_Matrix/gif_screen_generation.m">Gif to led matrix transfer</a> <a href="https://www.limpkin.fr/public/RGB_Matrix/webcam.m">Webcam matlab script</a></p>Electronic projects and Matlaburn:md5:e60b7a8163b48abe325a003d4e7ad89e2011-04-07T19:33:00+01:002024-03-08T21:10:31+00:00limpkinMy Projectsavrfpgaledmatlabmatrixusb<p>I have to admit, I am usually not the biggest fan of interpreted languages and high level programming. But in this case, they were <strong>very</strong> convenient.<br>
This is thus a small article about what you can do in 3-4 hours with Matlab and a FTDI USB connectivity to your project. As an example, here is a project where my webcam output (well, kind of) gets displayed on my led matrix:<br><br>
<img src="https://www.limpkin.fr/public/.webcam_led_matrix_m.jpg" alt="Led matrix with webcam" class="media-center" title="Led matrix with webcam, avr. 2011"></p> <p>For quite some time now, on my projects, I have been using Matlab for various data processing operations, picture conversions...<br>
and also communication with my embedded systems using FTDI USB to RS232 converters. Nothing more convenient that a simple fread() and fwrite() to import/export your data to/from your computer!<br>
If you have read my blog, you may know that I have a 96*64 bi-color led matrix at my disposal. Until now, I was generating all the screen data on the fly and still hadn't implemented the possibility to directly write to the led matrix frame buffer through its USB port.<br>
So yesterday I finally got the motivation to modify my FPSLIC code and optimize it to receive streamed data. As double-buffering was already implemented, the coding part was pretty quick!<br>
To have a clear and simple application of this added functionality, I thought it would be nice to display some data coming from my computer... What kind of data? The obvious choice was the webcam feed.<br>
This is where Matlab was very useful. In only 50 lines of code, I was able to show the edges detected from my webcam feed:</p>
<pre> function[ output_args ] = webcam( input_args )
s = serial('COM3', 'Parity', 'none', 'ByteOrder', 'BigEndian', 'InputBufferSize', 2000000, 'OutputBufferSize', 1000000 , 'BaudRate', 520833, 'DataBits', 8, 'RequestToSend', 'off', 'StopBits', 1, 'ReadAsyncMode', 'continuous', 'FlowControl', 'none');
fopen(s);
vid = videoinput('winvideo', 1, 'RGB24_160x120');
himage = preview(vid);
buffer = uint8(zeros(768, 1));
for i=1:2000
%tic
data = getsnapshot(vid);
data = imresize(data, [64 96]);
data = rgb2gray(data);
BW = edge(data,'canny');
%toc
index_store = 1;
%tic
for x=1:96
for y=1:8
A = 0;
for j=1:8
val = BW((y-1)*8 + j, 97 - x);
A = A + val * 2^(8-j);
end
buffer(index_store) = A;
index_store = index_store + 1;
end
end
while(strcmp(s.TransferStatus, 'idle') == 0)
index_store = index_store + 1;
end
fwrite(s,buffer,'uint8', 'async');
%toc
%fprintf('\r\n');
end
while(strcmp(s.TransferStatus, 'idle') == 0)
index_store = index_store + 1;
end
fclose(s);
delete(s);
stoppreview(vid);
closepreview(vid);
end</pre>
<p>As you see, everything is pretty simple here. Snapshots getting acquired, image resizing, conversion to B&W for edge detection and some compression for direct write to the frame buffer.<br>
Of course, this code is based on the assumption that picture generation will not be faster than the link to the led matrix (which in my case is true). Actually in this mode, my led matrix constantly output its SYNC signal so frame synchronization could be implemented in the future.<br>
Asynchronous sending to the serial port is used, and the whole buffer is put in the queue at once. Not doing so would considerably increase the loop execution time in synchronous mode, and in asynchronous mode active waiting should be used between each call to fwrite.<br>
RS232 link speed is set to allow for 520833 / (96 * 64 * 2) = 42Hz refresh rate which is enough for what i want to do. Of course, the display is only bi-color with monochrome data for each color, so everything is simplified! Anyway, here is the final result:<br></p>
<div class="external-media" style="margin: 1em auto; text-align: center;">
<object width="480" height="295"><param name="movie" value="https://www.youtube.com/v/ILnxZHLTEpE?version=3"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="https://www.youtube.com/v/ILnxZHLTEpE?version=3" type="application/x-shockwave-flash" width="480" height="295" allowscriptaccess="always" allowfullscreen="true"></embed></object>
<br /><a href="https://www.youtube.com/watch?v=ILnxZHLTEpE">Demonstration video</a>
</div>
<p><a href="https://www.limpkin.fr/public/webcam_led_matrix.JPG" title="Led matrix with webcam"><img src="https://www.limpkin.fr/public/.webcam_led_matrix_m.jpg" alt="Led matrix with webcam" class="media-center" title="Led matrix with webcam, avr. 2011"></a></p>
<p>This result is obtained with only using Matlab pre-existing functions, leaving the door opened to additional improvements. Anyway, I just wanted to let you know that with this kind of high level tools, it is very easy & quick to get nice results!</p>