Another project using an Arduino UNO and a 2.2" TFT graphics display. This sketch just generates pretty patterns using epicycles.

Have a look at my other instructables for some of the development background.

Step 1: Connecting Up the UNO to the TFT Screen

The UNO is connected to the ILI9241 2.2" TFT display like this:

    • UNO +5V to display pin 1 (VCC)
    • UNO +5V through a 56 Ohm resistor to display pin 8 (LED)
    • UNO 0V (GND) to display pin 2 (GND)
    • UNO digital pin 7 through a 1K2 resistor to display pin 4 (RESET), add a 1K8 resistor from display pin 4 to GND
    • UNO digital pin 9 through a 1K2 resistor to display pin 5 (DC/RS), add a 1K8 resistor from display pin 5 to GND
    • UNO digital pin 10 through a 1K2 resistor to display pin 3 (CS), add a 1K8 resistor from display pin 3 to GND
    • UNO digital pin 11 through a 1K2 resistor to display pin 6 (SDI/MOSI), add a 1K8 resistor from display pin 6 to GND
    • UNO digital pin 13 through a 1K2 resistor to display pin 7 (SCK), add a 1K8 resistor from display pin 7 to GND

    It is important to include the 1K8 resistors to GND with this 2.2" display as otherwise it will not work. The 1K2 and 1K8 resistors are a "potential divider", acting as a logic level shifter so that the logic level at the display is reduced from 5V to around 3V. Pin 9 of the display does not need to be connected up.

    Step 2: Spiro Sketch and Libraries

    The graphics libraries needed are in the attached zip file. The Spiro sketch is within the examples of the "Adafruit_ILI9341_AS" library.

    The libraries are the latest version superseding the version here. Some more enhancements have been made to improve drawing speeds.

    Step 3: Pattern Algorithm

    The patterns are produced by drawing single coloured pixels at the tip of a rotating vector, the centre of this vector is also rotating about the centre of the screen. Various parameters (radii and ratios) are changed at random before each pattern is drawn, in this way thousands of different patterns are generated. The pixel drawn changes through the colours of the rainbow, generating some nice aliasing effects.

    The pictures presented are deliberately blurred slightly as this is the only way that my webcam can capture the vibrant colours properly.

    Step 4: Your Patterns?

    If you have created a sketch that generates amazing coloured patterns using the hardware setup and libraries in this instructable, then it would be great if you post the sketch below. Thanks and have fun!

    <p>Nice work - I've been looking at graphics libraries for the 9341 that will fit on the smaller arduinos (Uno / Pro Mini); the UTFT and ucgLib libs are good, but BIG, and I think your libs are the best compromise between size and aesthetics.</p>
    <p>Thank you. Reducing the size of the compiled sketch to fit in the UNO and Mini Pro was the prime reason for adapting and developing the libraries. I have reduced the compiled size even more by Run Length Encoding the larger fonts (size 4 upwards), a new library will be released in a couple of week when I have migrated my test code to drive the 9341 based display.</p>
    <p>great job, thank you very much<br>i use a 9340 2.2 tft, it works unless i can't change pins cs rst and dc<br>in your sketch can we change these pins ? with using a tft 9341 of course.<br>my tft doesn't work with adafruit_9341 lib but ok with adafruit_9340 and choice free of dc,rst,cs, so i think it's a 9340 driver, it looks like yours <br>but not matter it's ok for me<br>cheers from belgium</p>
    <p>You can change the pins but then you must comment out the line:</p><p>#define F_AS_T</p><p>in the library file &quot;Adafruit_ILI9241_FAST.h&quot; within the library. It will then run more slowly as direct port access for the control signals is not used. Not sure the library will work if you have a ILI9340 chip in your display.</p>
    <p>Hi again Bodmer, just a quick question - if you want to use a Arduino MEGA how would you set the pins for this, as I know that the MEGA's use hardware SPI on pins 51(MOSI) and 52(SCK) instead of the Uno's 12 and 13. Is this an easy change to make? I have reached the memory limit of my Uno that's all! Thanks! </p>
    <p>Sorry for the delay in replying. Yes, the library should work fine with a Mega. As you say just use the pins 51 and 52 instead. Have you tried this?</p>
    <p>Replace the loop() with the text below and you will see an image produced from part of the Mandlebrot set (due to the maths involved drawing is slow!):</p><p>void loop()<br>{<br> tft.fillScreen(ILI9341_BLACK);<br> for (int px = 1; px &lt; 320; px++)<br> {<br> for (int py = 0; py &lt; 240; py++)<br> {<br> float x0 = (map(px, 0, 320, -250000/2, -237500/2)) / 100000.0; //scaled x coordinate of pixel (scaled to lie in the Mandelbrot X scale (-2.5, 1))<br> float y0 = (map(py, 0, 240, -75000/4, -56000/4)) / 100000.0; //scaled y coordinate of pixel (scaled to lie in the Mandelbrot Y scale (-1, 1))<br> float xx = 0.0;<br> float yy = 0.0;<br> int iteration = 0;<br> int max_iteration = 128;<br> while ( ((xx * xx + yy * yy) &lt; 4) &amp;&amp; (iteration &lt; max_iteration) )<br> {<br> float xtemp = xx * xx - yy * yy + x0;<br> yy = 2 * xx * yy + y0;<br> xx = xtemp;<br> iteration++;<br> }<br> int color = rainbow((3*iteration+64)%128);<br> tft.drawPixel(px, py, color);<br> }<br> }<br> while(1);<br>}</p>

    About This Instructable




    More by Bodmer:Arduino - TFT display of icons and images from FLASH memory Arduino - TFT display of bitmap images from an SD Card Arduino analogue 'ring' meter on colour TFT display 
    Add instructable to: