giovedì 7 luglio 2016

Interface Arduino UNO clone with a 2.4 TFT touchscreen 




Just a few information ,  about how this test I made with this amazing 2.4" TFT LCD screen with touch screen, bought .here

In order to function correctly, you need to download the Arduino libraries, kindly offered ( as open source ) by Adafruit..

The libraries are :



You need to install these libraries in the correct library folder and then start the Arduino IDE.

Let's go to compile and upload the below example sketch ( available into the "TFTLCD-Library" - sketch's name is "graphicstest.pde" ) on Arduino UNO .
To function , it has been necessary to insert one line ( see below , it has been highlighted in red ).
The driver is ILI9341 , but the firmware has  found a different code identifier ( not  0x9341, but 0x0101)

// IMPORTANT: Adafruit_TFTLCD LIBRARY MUST BE SPECIFICALLY
// CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD.
// SEE RELEVANT COMMENTS IN Adafruit_TFTLCD.h FOR SETUP.

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library

// The control pins for the LCD can be assigned to any digital or
// analog pins...but we'll use the analog pins as this allows us to
// double up the pins with the touch screen (see the TFT paint example).
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0

#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin

// When using the BREAKOUT BOARD only, use these 8 data lines to the LCD:
// For the Arduino Uno, Duemilanove, Diecimila, etc.:
//   D0 connects to digital pin 8  (Notice these are
//   D1 connects to digital pin 9   NOT in order!)
//   D2 connects to digital pin 2
//   D3 connects to digital pin 3
//   D4 connects to digital pin 4
//   D5 connects to digital pin 5
//   D6 connects to digital pin 6
//   D7 connects to digital pin 7
// For the Arduino Mega, use digital pins 22 through 29
// (on the 2-row header at the end of the board).

// Assign human-readable names to some common 16-bit color values:
#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
// If using the shield, all control and data lines are fixed, and
// a simpler declaration can optionally be used:
// Adafruit_TFTLCD tft;

void setup(void) {
  Serial.begin(9600);
  Serial.println(F("TFT LCD test"));

#ifdef USE_ADAFRUIT_SHIELD_PINOUT
  Serial.println(F("Using Adafruit 2.8\" TFT Arduino Shield Pinout"));
#else
  Serial.println(F("Using Adafruit 2.8\" TFT Breakout Board Pinout"));
#endif

  Serial.print("TFT size is "); Serial.print(tft.width()); Serial.print("x"); Serial.println(tft.height());

  tft.reset();

  uint16_t identifier = 0x9341;    //Need a fix here 

  if(identifier == 0x9325) {
    Serial.println(F("Found ILI9325 LCD driver"));
  } else if(identifier == 0x9328) {
    Serial.println(F("Found ILI9328 LCD driver"));
  } else if(identifier == 0x7575) {
    Serial.println(F("Found HX8347G LCD driver"));
  } else if(identifier == 0x9341) {
    Serial.println(F("Found ILI9341 LCD driver"));
  } else if(identifier == 0x8357) {
    Serial.println(F("Found HX8357D LCD driver"));
  } else {
    Serial.print(F("Unknown LCD driver chip: "));
    Serial.println(identifier, HEX);
    Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
    Serial.println(F("  #define USE_ADAFRUIT_SHIELD_PINOUT"));
    Serial.println(F("should appear in the library header (Adafruit_TFT.h)."));
    Serial.println(F("If using the breakout board, it should NOT be #defined!"));
    Serial.println(F("Also if using the breakout, double-check that all wiring"));
    Serial.println(F("matches the tutorial."));
    return;
  }

  tft.begin(identifier);

  Serial.println(F("Benchmark                Time (microseconds)"));

  Serial.print(F("Screen fill              "));
  Serial.println(testFillScreen());
  delay(500);

  Serial.print(F("Text                     "));
  Serial.println(testText());
  delay(3000);

  Serial.print(F("Lines                    "));
  Serial.println(testLines(CYAN));
  delay(500);

  Serial.print(F("Horiz/Vert Lines         "));
  Serial.println(testFastLines(RED, BLUE));
  delay(500);

  Serial.print(F("Rectangles (outline)     "));
  Serial.println(testRects(GREEN));
  delay(500);

  Serial.print(F("Rectangles (filled)      "));
  Serial.println(testFilledRects(YELLOW, MAGENTA));
  delay(500);

  Serial.print(F("Circles (filled)         "));
  Serial.println(testFilledCircles(10, MAGENTA));

  Serial.print(F("Circles (outline)        "));
  Serial.println(testCircles(10, WHITE));
  delay(500);

  Serial.print(F("Triangles (outline)      "));
  Serial.println(testTriangles());
  delay(500);

  Serial.print(F("Triangles (filled)       "));
  Serial.println(testFilledTriangles());
  delay(500);

  Serial.print(F("Rounded rects (outline)  "));
  Serial.println(testRoundRects());
  delay(500);

  Serial.print(F("Rounded rects (filled)   "));
  Serial.println(testFilledRoundRects());
  delay(500);

  Serial.println(F("Done!"));
}

void loop(void) {
  for(uint8_t rotation=0; rotation<4; rotation++) {
    tft.setRotation(rotation);
    testText();
    delay(2000);
  }
}

unsigned long testFillScreen() {
  unsigned long start = micros();
  tft.fillScreen(BLACK);
  tft.fillScreen(RED);
  tft.fillScreen(GREEN);
  tft.fillScreen(BLUE);
  tft.fillScreen(BLACK);
  return micros() - start;
}

unsigned long testText() {
  tft.fillScreen(BLACK);
  unsigned long start = micros();
  tft.setCursor(0, 0);
  tft.setTextColor(WHITE);  tft.setTextSize(1);
  tft.println("Hello World!");
  tft.setTextColor(YELLOW); tft.setTextSize(2);
  tft.println(1234.56);
  tft.setTextColor(RED);    tft.setTextSize(3);
  tft.println(0xDEADBEEF, HEX);
  tft.println();
  tft.setTextColor(GREEN);
  tft.setTextSize(5);
  tft.println("Groop");
  tft.setTextSize(2);
  tft.println("I implore thee,");
  tft.setTextSize(1);
  tft.println("my foonting turlingdromes.");
  tft.println("And hooptiously drangle me");
  tft.println("with crinkly bindlewurdles,");
  tft.println("Or I will rend thee");
  tft.println("in the gobberwarts");
  tft.println("with my blurglecruncheon,");
  tft.println("see if I don't!");
  return micros() - start;
}

unsigned long testLines(uint16_t color) {
  unsigned long start, t;
  int           x1, y1, x2, y2,
                w = tft.width(),
                h = tft.height();

  tft.fillScreen(BLACK);

  x1 = y1 = 0;
  y2    = h - 1;
  start = micros();
  for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = w - 1;
  for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  t     = micros() - start; // fillScreen doesn't count against timing

  tft.fillScreen(BLACK);

  x1    = w - 1;
  y1    = 0;
  y2    = h - 1;
  start = micros();
  for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = 0;
  for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  t    += micros() - start;

  tft.fillScreen(BLACK);

  x1    = 0;
  y1    = h - 1;
  y2    = 0;
  start = micros();
  for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = w - 1;
  for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  t    += micros() - start;

  tft.fillScreen(BLACK);

  x1    = w - 1;
  y1    = h - 1;
  y2    = 0;
  start = micros();
  for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = 0;
  for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);

  return micros() - start;
}

unsigned long testFastLines(uint16_t color1, uint16_t color2) {
  unsigned long start;
  int           x, y, w = tft.width(), h = tft.height();

  tft.fillScreen(BLACK);
  start = micros();
  for(y=0; y<h; y+=5) tft.drawFastHLine(0, y, w, color1);
  for(x=0; x<w; x+=5) tft.drawFastVLine(x, 0, h, color2);

  return micros() - start;
}

unsigned long testRects(uint16_t color) {
  unsigned long start;
  int           n, i, i2,
                cx = tft.width()  / 2,
                cy = tft.height() / 2;

  tft.fillScreen(BLACK);
  n     = min(tft.width(), tft.height());
  start = micros();
  for(i=2; i<n; i+=6) {
    i2 = i / 2;
    tft.drawRect(cx-i2, cy-i2, i, i, color);
  }

  return micros() - start;
}

unsigned long testFilledRects(uint16_t color1, uint16_t color2) {
  unsigned long start, t = 0;
  int           n, i, i2,
                cx = tft.width()  / 2 - 1,
                cy = tft.height() / 2 - 1;

  tft.fillScreen(BLACK);
  n = min(tft.width(), tft.height());
  for(i=n; i>0; i-=6) {
    i2    = i / 2;
    start = micros();
    tft.fillRect(cx-i2, cy-i2, i, i, color1);
    t    += micros() - start;
    // Outlines are not included in timing results
    tft.drawRect(cx-i2, cy-i2, i, i, color2);
  }

  return t;
}

unsigned long testFilledCircles(uint8_t radius, uint16_t color) {
  unsigned long start;
  int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;

  tft.fillScreen(BLACK);
  start = micros();
  for(x=radius; x<w; x+=r2) {
    for(y=radius; y<h; y+=r2) {
      tft.fillCircle(x, y, radius, color);
    }
  }

  return micros() - start;
}

unsigned long testCircles(uint8_t radius, uint16_t color) {
  unsigned long start;
  int           x, y, r2 = radius * 2,
                w = tft.width()  + radius,
                h = tft.height() + radius;

  // Screen is not cleared for this one -- this is
  // intentional and does not affect the reported time.
  start = micros();
  for(x=0; x<w; x+=r2) {
    for(y=0; y<h; y+=r2) {
      tft.drawCircle(x, y, radius, color);
    }
  }

  return micros() - start;
}

unsigned long testTriangles() {
  unsigned long start;
  int           n, i, cx = tft.width()  / 2 - 1,
                      cy = tft.height() / 2 - 1;

  tft.fillScreen(BLACK);
  n     = min(cx, cy);
  start = micros();
  for(i=0; i<n; i+=5) {
    tft.drawTriangle(
      cx    , cy - i, // peak
      cx - i, cy + i, // bottom left
      cx + i, cy + i, // bottom right
      tft.color565(0, 0, i));
  }

  return micros() - start;
}

unsigned long testFilledTriangles() {
  unsigned long start, t = 0;
  int           i, cx = tft.width()  / 2 - 1,
                   cy = tft.height() / 2 - 1;

  tft.fillScreen(BLACK);
  start = micros();
  for(i=min(cx,cy); i>10; i-=5) {
    start = micros();
    tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
      tft.color565(0, i, i));
    t += micros() - start;
    tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
      tft.color565(i, i, 0));
  }

  return t;
}

unsigned long testRoundRects() {
  unsigned long start;
  int           w, i, i2,
                cx = tft.width()  / 2 - 1,
                cy = tft.height() / 2 - 1;

  tft.fillScreen(BLACK);
  w     = min(tft.width(), tft.height());
  start = micros();
  for(i=0; i<w; i+=6) {
    i2 = i / 2;
    tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0));
  }

  return micros() - start;
}

unsigned long testFilledRoundRects() {
  unsigned long start;
  int           i, i2,
                cx = tft.width()  / 2 - 1,
                cy = tft.height() / 2 - 1;

  tft.fillScreen(BLACK);
  start = micros();
  for(i=min(tft.width(), tft.height()); i>20; i-=6) {
    i2 = i / 2;
    tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0));
  }

  return micros() - start;
}

sabato 18 aprile 2015

Buggy

I’m very pleased to introduce you  my last present, just arrived.
The “Buggy”, one of the last technological “toys” from MikroElektronika.
I said “toys”, but we can consider the Buggy a complete development system, useful to study a large number of microcontroller.



Mikroeektronika is very attentive to details. The package is very well done, robust and reliable. It is common for all the Mikroelektronika products.
Inside, all the parts are inserted in a foam base, that protect very well any single item
Kit includes :
–  base Buggy board, with 4 wheel+motors
– 3 Click board sockets
– 3 spare PCB parts, must be soldered, in order to give stability
– a 3.3V  LiIo battery
– USB cable
– Manual with schematic

I choose the kit that doesn’t include any Microcontroller board, since I already have a Clicker 2 x PIC32MX and a Mikromedia for PIC32MX.
All these products have been bought at  RS Components
On the picture below, you can see the Buggy base board from the bottom side.
Battery must be installed on the centre of the board, so the Buggy will be balanced very well.

Very impressive the geared motors.
The gear doesn’t include any part in plastic material, all are made by steel or iron. Basically, it not seem the classic “poor” low-cost plastic gearbox.

Prepare the robot is very easy , you just need an iron solder.
Anyway, the manual included describes very well, step by step, all the mounting operations.
On the next days, I will see to prepare a sample firmware example, to give life to my robot.

sabato 28 febbraio 2015

Practical use of 3D printer

Finally, a practical use of my 3D printer Prusa I3.
Was sunday morning, when a drama happened on my kitchen.
My girl was warming a cup of milk, suddendly, the microwawe stopped to function.
A gloomy silence filled the kitchen. the girl looked at me desperately and a scream broke the sound barrier.
" it is broke"
followed by a series of misfortunes similar to the invasion of locusts ( how can I warm my breakfast, my soup, the boiled potatoes ) .
STOP, I will fix the microwave - was my only statement.
While she was looking which electronic store were open on Sunday, I spent about half hour to open the microwave box, (I hate the torx screws, not having the correct screwdriver :-) )
Once I opened the patient, I have discovered that all was OK ( or , I supposed that ), but .....
the knob.....was only the knob used for time programming.... the center hole was stripped and did not more maintain the position.

IDEA - I can replicate a similar knob with my 3D printer.
Immediately on my computer, launch Design Spark mechanical and draw the my simple knob version.
Very easy and quick design

Then, save the G code file on my Prusa , used a 100 % infill to have a strong and reliable knob.
About 40 minutes and ....dadadadada.... an " economic" but functional knob was ready.

I will prepare a more complete version, just to avoid any claims from her

domenica 8 febbraio 2015

Some parts printed with Prusa I3 & Design Spark Mechanical

Here we can see some parts that I printed with Prusa I3 DIY 3D printer .
All these have been designed with Design Spark Mechiancal, a free 3D CAD, based on Space Claim CAD.
At the beginning I have some issues on have a perfect circle, but, the first failure was due to the low resolution on STL files.



The second image is  not a perfect circle, I will publish the second version that is better and we can see the differences

domenica 11 gennaio 2015

A new adjustable endstop for Z axis




Just finished and tested a new adjustable endstop for Z axis
Now it is possible to adjust the endstop with only a screwdriver ( wrenches are not necessary ) 
Turn the M4 bolt to adjust the zero position.
All the parts have been designed with Design Spark mechanical, then adjusted with NetFabb ( to remove the incorrect mesh ) and then printed with Repetier / Slic3r.


Here the complete vision

a better image of the parts

board plate that attach the original Prusa Z endstop plastic

plastic part that sustain a M4 nut, developed with Design Spark mechanical


Here the same part, adjusted with Netfabb

giovedì 8 gennaio 2015

Prusa i3 rework ready

After about 2 months, using the free time on evening ( and night ) , I can say that my Prusa I3 rework is finished and I'm pretty satisfy of the final result.
I made some small changes from the original design,  in order to improve :
-  the Z axis zero regulation
-  to give some  light /illumination
-  add a blower for the PLA

Some pictures , to show the Z axis zero regulation :
this is the Z axis zero regulation

below the blower and the illumination .
I have used a series of LED smd, soldered below the fan :

Fan and LED light


Below, the LCD board with the SD card socket :






On the next days, I will post some other info.
See you

venerdì 12 dicembre 2014

Adding a Real Clock Calendar to your Arduino UNO

The Arduino UNO  doesn’t have  a little coin-battery-powered 'Real Time Clock'  (RTC) module, which keeps time even when the power is off, or the battery removed.
So in this project we will show you how to add a RTC Click shield from Mikroelektronika, without the use of iron solder or breadboard.
This is possible using a Click Shield for Arduino UNO ( MIKROE 1581 ) from Mikroelektronika, 


We just need to insert the two Click boards as per below images.

 On top the Arduino UNO 
 On bottom the  Mikroelektronika Click Shield for Arduino ( on the left ) and a RTC Click shield ( on the right )


The RTC Click shield inserted on the Mikroe  Click shield for Arduino
                       

The 3 boards (  
Arduino UNO ( on the bottom ) – Mikroe Click Shield ( on the middle ) – RTC Click shield ( on the top )



The Mikroe Click shield for Arduino let’s permit to interface not one, but two Click shields.
The RTC Click shield uses a very popular Real Time Clock PCF8583 from NXP ( ex Philips ) .
On the web, there are a lot of open source libraries for Arduino, based on the PCF8583 .

I have used the following :




Not sure if it is the best, but it worked well on my test.
You just need to :
  • download the library “PCF8583-master” from github
  • unzip
  • copy the unzip files on the Arduino “library” directory ( take care – depending your Arduino IDE version , you should remove the “-“ character from the library name “PCF8583-master”. The newest versions don’t accept this char on the library’s name.
  • launch the “Arduino” IDE
  • upload the example file “ read_write_time.ino” ( from the library “PCF8583master” )

-    


  •           Compile & upload the sketch
  •           Open the serial monitor on the Arduino IDE

  •        On the first time, you could see a wrong date-time
  •        Write on the top bar the date-time to set on the following form “YYMMddhhmmss;”
  •        Send to Arduino
  •        That's all! – you can now see the correct date-time
  •        Try to switch off the UNO board and then switch on, to see if the date-time has been kept

The system should function also with Arduino Leonardo and Arduino Mega, but I didn’t tested these boards