Archive

Archive for the ‘Driving Displays’ Category

Simple Graph With Arduino NANO and TFT Library

September 7, 2016 Leave a comment

This is a simple plotting example to experiment with the TFT Library and the LCD Display with the ST7735 controller (128×160 pixels).

simple_graph_01_4

First, a clean wiring diagram to connect the Arduino NANO and the Display. The SD Card adapter was wired  (CS and MISO) but not used in this Sketch.

tft_sd_nano_dim_wiring

Then, a wiring plan to put them together in the breadboard:

tft_sd_nano_dim_jumpers

 

tft_sd_nano_dim_assembled


 

The Sketch:

 

/*TFT_Graph.ino      Arduining 7 AUG 2016

-Arduino NANO and ST7735 LCD Display 128×160
-using TFT library
-Brighness control in pin 6
-offset is used to adjust vertical position of the graph.
*/

#include <TFT.h>
#include <SPI.h>

//pin definitions:
#define CS          10
#define DC           9
#define RST          8
#define BKLIGHT      6              // Backlight control pin

#define BRIGHTNESS 204              // Backlight intensity (0-255)
#define RANGE      100              // Vertical size of the graph in pixels.
#define WIDTH      128              // Horizontal size of Display in pixels.
#define HEIGHT     160              // Vertical size of Display in pixels.
#define PERSIST    500              // persistence of the graph (milliseconds).

TFT TFTscreen = TFT(CS, DC, RST);

int value ;
int last_value;
int x_pos= 0;                       // cursor position
int offset= 40;                     // vertical graph displacement in pixels.

void setup(){
TFTscreen.begin();                // initialize the display
TFTscreen.setRotation(0);
TFTscreen.background(0,128,0);    // dark green background
TFTscreen.stroke(255,255,255);    // white stroke
analogWrite(BKLIGHT,BRIGHTNESS);  //Set brightness.
TFTscreen.setTextSize(1);
TFTscreen.text(“Arduining.com”,50,151);
drawFrame();
clearGraph();
}

void drawFrame(){
TFTscreen.stroke(255,255,255);      // white stroke
TFTscreen.fill( 255, 255, 255 );    // White fill
TFTscreen.rect(0, 0, WIDTH, 21);
TFTscreen.setTextSize(1);
TFTscreen.stroke(0,0,0);            // black text
TFTscreen.text(“Volts: 1.0V/Div”,2,2);  // Example text.
TFTscreen.text(“Time:  10mS/Div”,2,12); // Exanple text
}
void clearGraph(){
TFTscreen.stroke(127,127,127);      // grey for the border
TFTscreen.fill( 180, 0, 0 );        // dark Blue for the background
TFTscreen.rect(0, 22, 128, 128);
TFTscreen.line(65, 23, 65, 151);    // vertical line
TFTscreen.line(1, 85,127, 85);      // horizontal line
TFTscreen.stroke(0,255,255);        // yellow stroke for plotting.
}

void plotLine(int last,int actual){
if(x_pos==0)last= actual;                     // first value is a dot.
TFTscreen.line(x_pos-1, last, x_pos, actual); // draw line.
x_pos++;
if(x_pos > WIDTH){
x_pos=0;
delay(PERSIST);
clearGraph();
}
}

void loop(){
last_value= value;
value= analogRead(A0);
value= map(value,0,1023,149,23);
value -= offset;
if(value <= 23) value= 23;         //truncate off screen values.
plotLine(last_value ,value );
delay(10);
}

 


Thanks for visiting…

Tiva C LaunchPad Base Plate, Easy Wiring

September 2, 2016 3 comments

A week ago went back to to Tiva C launchPad, this time I am interested in to refresh some concepts and try examples of RTOS (Real Time Operating System). The use of a RTOS usually means several hardware peripherals (sensors, keypads, displays .. etc). A breadboard and many jumpers was filling my imagination.

 

Tiva_Clean_Wiring

I need a Base Plate to organize the wiring, also a way of use top and bottom connectors in the launchPad. This is the story of last two days…

First thing, I need to finish the assembly of a tablesaw from Grizzly (it was resting semi-assembled in the garage).

Grizzly_tableSaw.jpg

Note:This project will be done in a couple of hours using acrylic plastic  if you have access to a laser cutter, in my case I am fan of woodworking… (the laser will come some day…).

TivaC_BasePlate_4.jpg

A serie of images will explain the project…

TivaC_BasePlate_3

While dried, we need a pin reference for the bottom:

TivaC_Launchpad_Bottom_pin_ref

TivaC_bottom_01

Time to put all together…

TivaC_BasePlate_2

TivaC_BasePlate_1

Tiva_Clean_Wiring_3

Here is how looks the wiring of the TFT Display:

Tiva-Clear_Wiring_2

This is the wiring diagram of the ST7735 used:

TIVA_ST7735_Wiring_

… thanks for visiting.

 

 

 

Wiring TFT Display to Arduino NANO

August 27, 2016 2 comments
 Wiring Diagram:

TFT_SD_NANO_DIM_wiring

A clean approach to attach the Display to Arduino NANO:

TFT_SD_NANO_DIM_jumpers

 All the components in place. SD Card adapter also is connected to the Arduino.

TFT_SD_NANO_DIM_assembled

Reading the analog input A0:

Test_001

Plotting the analog channel A0 using vertical lines:

Test_002

A small video to show the wiring while enjoying a Tchaikovsky’s  Waltz:

 

Testing my small library. 5×7 font in different sizes.

MicroLib_03_text

Testing drawRect() and fillRect() of the small library:

MicroLib_03_Rect_test

 Using the small library to show A0 value and his histogram:

MicroLib_A0_test_img

 

 

… this post is in progress… some code and examples…

 

Arduino Trinket and Serial LCD

February 17, 2014 2 comments

Testing the bit bang serial transmission to connect the Trinket with the Serial LCD Module 16×2 from NKC Electronics.
The first Sketch with string functions use 3,634 bytes, the second Sketch, avoiding string functions, use 1,362 bytes.

20140217_125246

Sketch with string functions:

/*	Test_LCD.ino
	Arduining.com  16 FEB 2014
	Binary sketch size: 3,634 bytes (of a 5,310 byte maximum)

	A timer is implemented presenting minutes and seconds elapsed since start.
	Bit Banging Serial transmission at 9600 bauds.
	Example using the Trinket from Adafruit (5V, 8 Mhz)
	and Serial LCD Module 16x2 from NKC Electronics.
*/

//----- defining bit banging serial values:------------------------------------
#define	TXDATA    1         // Pin used to transmit data.
#define BITTIME   93        // Adjusted with osciloscope to obtain 9600 bauds.

//----------variables:---------------------------------------------------------
int 	seconds= 0;		//seconds counter
String 	number;			//String to be sent to the display.
//=============================================================================
void setup() {                
	pinMode(TXDATA, OUTPUT);   // initialize the TXDATA pin as an output.
	digitalWrite(TXDATA,HIGH); // TXDATA = 5V when is resting.
//---LCD Display initialisation---
	delay(500);
	sendChar(0xFE);
	sendChar(0x41);		//display on.
	sendChar(0xFE);
	sendChar(0x51);		//clear display.
	sendChar(0xFE);
	sendChar(0x4C);		//cursor blinking Off.
	sendChar(0xFE);
	sendChar(0x48);		//cursor Off.
	sendChar(0xFE);
	sendChar(0x46);		//cursor at home.
	sendChar(0xFE);
	sendChar(0x53);		//backlight brightness command.
	sendChar(4);		//brightness 1-8
	sendChar(0xFE);
	sendChar(0x52);		//contrast command.
	sendChar(45);		//contrast 1-50
	show(" Arduining.com");
}

//================= Main loop =================================================
void loop() {
	if ((millis() % 1000)<2){ 				//Skip until the next second.

		sendChar(0xFE);
		sendChar(0x45);						// Set cursor at
		sendChar(0x45);						// line 2 pos 6

		number = String (seconds/60);		//elapsed minutes
		while(number.length()<2)number= "0" + number;   //format to 2 characters.
		show(number); 						//Show minutes in the display

		sendChar(':');

		number = String (seconds % 60);		//elapsed seconds
		while(number.length()<2)number= "0" + number;   //format to 2 characters.
		show(number); 						//Show seconds in the display

   		seconds++;
   		if (seconds >= 3600) seconds=0;		//roll over
	}
}

//-----------------------------------------------------------------------------
void sendChar(char c){
	delayMicroseconds(BITTIME*2);          		// wait 2 Stop bits.
	digitalWrite(TXDATA,LOW);              		// TXDATA=0.
	delayMicroseconds(BITTIME);            		// wait Start bit.
	for (int i=0; i<8;i++){
		digitalWrite(TXDATA,bitRead(c, i)); 	// bit out.
		delayMicroseconds(BITTIME);          	// wait bit
	}
	digitalWrite(TXDATA,HIGH);            		//TXDATA=1.
}

//-----------------------------------------------------------------------------
void show(String s){
	int lenght=s.length();
	for(int i=0;i<lenght;i++){
	sendChar(s[i]);
	}
}

Sketch without string functions:

/*	Test_LCD_01.ino
	Arduining.com  17 FEB 2014
	Based in Test_LCD.ino (2,278 bytes less avoiding string functions).
	Binary sketch size: 1,356 bytes (of a 5,310 byte maximum)

	A timer is implemented presenting minutes and seconds elapsed since start.
	Bit Banging Serial transmission at 9600 bauds.
	Example using the Trinket from Adafruit (5V, 8 Mhz)
	and Serial LCD Module 16x2 from NKC Electronics.
*/

//----- defining bit banging serial values:------------------------------------
#define	TXDATA    1         // Pin used to transmit data.
#define BITTIME   93        // Adjusted with osciloscope to obtain 9600 bauds.

//----------variables:---------------------------------------------------------
int 	seconds= 0;		//seconds counter
//=============================================================================
void setup() {                
	pinMode(TXDATA, OUTPUT);   // initialize the TXDATA pin as an output.
	digitalWrite(TXDATA,HIGH); // TXDATA = 5V when is resting.
//---LCD Display initialisation---
	delay(500);
	sendChar(0xFE);
	sendChar(0x41);		//display on.
	sendChar(0xFE);
	sendChar(0x51);		//clear display.
	sendChar(0xFE);
	sendChar(0x4C);		//cursor blinking Off.
	sendChar(0xFE);
	sendChar(0x48);		//cursor Off.
	sendChar(0xFE);
	sendChar(0x46);		//cursor at home.
	sendChar(0xFE);
	sendChar(0x53);		//backlight brightness command.
	sendChar(4);		//brightness 1-8
	sendChar(0xFE);
	sendChar(0x52);		//contrast command.
	sendChar(45);		//contrast 1-50
	show(" Arduining.com");
}

//================= Main loop =================================================
void loop() {
	if ((millis() % 1000)<2){ 				//Skip until the next second.

		sendChar(0xFE);
		sendChar(0x45);						// Set cursor at
		sendChar(0x45);						// line 2 pos 6

		sendChar((seconds/600)+'0');		//show tens of minutes 
		sendChar(((seconds/60) % 10)+'0');	//show units of minutes
		sendChar(':');
		sendChar(((seconds % 60)/10)+'0');	//show tens of seconds
		sendChar((seconds % 10)+'0');		//show units of seconds
   		seconds++;
   		if (seconds >= 3600) seconds=0;		//roll over
	}
}

//-----------------------------------------------------------------------------
void sendChar(char c){
	delayMicroseconds(BITTIME*2);          		// wait 2 Stop bits.
	digitalWrite(TXDATA,LOW);              		// TXDATA=0.
	delayMicroseconds(BITTIME);            		// wait Start bit.
	for (int i=0; i<8;i++){
		digitalWrite(TXDATA,bitRead(c, i)); 	// bit out.
		delayMicroseconds(BITTIME);          	// wait bit
	}
	digitalWrite(TXDATA,HIGH);            		//TXDATA=1.
}

//-----------------------------------------------------------------------------
void show(char s[]){
	int i=0;
	while(s[i]!=0){					//looking for the string end.
		sendChar(s[i]);
		i++	;
	}
}

Arduining on the Go with Freetronics Arduino Clone

October 20, 2013 2 comments

A small project: Single digit counter with a seven-segments Led Display

image

Display pins:

LTS_4301JR_2

 

ToGo_7Seg_Wiring

Ready to download the Sketch:

Conexions

A working counter…

20131026_120615

The Sketch used:

/*ToGo_7Seg.ino
Arduining.com 26 OCT 2013
Driving the LTS-4301JR Common Cathode 7 Segments Display.
Using the Freetronics ELEVEN
*/

//Pins connections to segments: 
#define  segA   5
#define  segB   4
#define  segC   3
#define  segD   10
#define  segE   11
#define  segF   12
#define  segG   13
#define  segDP  2

//Array with the segments to represent the decimal numbers (0-9).
byte segments[10] = {
// pgfedcba  <--- segments
  B00111111, // number 0
  B00000110, // number 1
  B01011011, // number 2
  B01001111, // number 3
  B01100110, // number 4
  B01101101, // number 5
  B01111101, // number 6
  B00000111, // number 7
  B01111111, // number 8
  B01101111  // number 9
};

void setup(){

  pinMode(segA,OUTPUT);
  pinMode(segB,OUTPUT);
  pinMode(segC,OUTPUT);
  pinMode(segD,OUTPUT);
  pinMode(segE,OUTPUT);
  pinMode(segF,OUTPUT);
  pinMode(segG,OUTPUT);
  pinMode(segDP,OUTPUT);

}

//================================================================
void loop(){
  for(int i=0;i<10;i++){
  Display(i);

    delay(2000);
  }
}

/*-------------------------------------------------------------------
Put the segments according to the number.
--------------------------------------------------------------------*/
void Display(int number){
byte segs = segments[number]; 

digitalWrite(segA, bitRead(segs, 0) );
digitalWrite(segB, bitRead(segs, 1) );
digitalWrite(segC, bitRead(segs, 2) );
digitalWrite(segD, bitRead(segs, 3) );
digitalWrite(segE, bitRead(segs, 4) );
digitalWrite(segF, bitRead(segs, 5) );
digitalWrite(segG, bitRead(segs, 6) );
}

How to add a small breadboard to the freetronics ELEVEN:

ArdTogo

Will be nice to have a recessed zone near the USB connector to use the clam shell as board support.

20130725_111451

 

Arduino Parking Lot ( Filled )

October 13, 2012 175 comments

Wiring diagram:

Here is the code:

/*ParkingL02.pde
Arduining.com 08 JUL 2012
Code used in the production of the Youtube material.
*/

#include <Servo.h>
Servo myservo;  // create servo object to control a servo

#define ServoM    12        //Connected to the servo motor.
#define Bright    11        //servo library disable PWM on pins 9 and 10.
#define Exit      9         //Pin connected to the EXIT button.
#define In        8         //Pin connected to the IN button.

#define BarLow    177       //Low position of the barrier.
#define BarUp     95        //Up position of the barrier.
#define CAPACITY  8         //Capacity of the parking lot.
#define INTEN     80        //Display intensity %

//Pins conections to segments (cathodes).
#define  segA  0
#define  segB  1
#define  segC  2
#define  segD  3
#define  segE  4
#define  segF  5
#define  segG  6

//Array with the segments to represent the decimal numbers (0-9).
byte segments[10] = {
// pgfedcba  <--- segments
  B00111111, // number 0
  B00000110, // number 1
  B01011011, // number 2
  B01001111, // number 3
  B01100110, // number 4
  B01101101, // number 5
  B01111101, // number 6
  B00000111, // number 7
  B01111111, // number 8
  B01101111  // number 9
};

void setup(){
  myservo.attach(ServoM);          // attaches the servo.

  pinMode(Exit, INPUT);           // set "EXIT" button pin to input
  pinMode(In, INPUT);             // set "IN" button pin to input
  digitalWrite(Exit, HIGH);       // Connect Pull-Up resistor.
  digitalWrite(In, HIGH);         // Connect Pull-Up resistor.
  pinMode(segA,OUTPUT);
  pinMode(segB,OUTPUT);
  pinMode(segC,OUTPUT);
  pinMode(segD,OUTPUT);
  pinMode(segE,OUTPUT);
  pinMode(segF,OUTPUT);
  pinMode(segG,OUTPUT);
  pinMode(Bright,OUTPUT);
  analogWrite(Bright,255*INTEN/100);
  myservo.write(BarLow);          //Barrier in the low position
//  delay(1000);
}

int  Available= 9;                    // Number of places available.

//================================================================
void loop(){
Display(Available);
if(digitalRead(In)==0)
{
  if(Available != 0){
    Available--;
    myservo.write(BarUp);
    delay(3000);
    myservo.write(BarLow);
    }
  }
if(digitalRead(Exit)==0)
{
  if(Available != CAPACITY){
    Available++;
    myservo.write(BarUp);
    delay(3000);
    myservo.write(BarLow);
    }
  }
}

/*-------------------------------------------------------------------
Put the segments according to the number.
--------------------------------------------------------------------*/
void Display(int number){
byte segs =  ~segments[number];        //"~" is used for commom anode.

digitalWrite(segA, bitRead(segs, 0) );
digitalWrite(segB, bitRead(segs, 1) );
digitalWrite(segC, bitRead(segs, 2) );
digitalWrite(segD, bitRead(segs, 3) );
digitalWrite(segE, bitRead(segs, 4) );
digitalWrite(segF, bitRead(segs, 5) );
digitalWrite(segG, bitRead(segs, 6) );
}

See it in Youtube:

and how was done:

Arduino Knight Rider LED Scanner Bar

Driving 8 Leds to simulate the the Knight Rider car of the TV show.
A very simple algorithm was implemented.


Image

The Sketch:

/*
KnightR8L.pde
Arduining.com 1 MAY 2011
Driving 8 Leds to emulate the Knight Rider car.
Leds connected to the digital pins (0~7).
*/
byte n=0;       //The number to be displayed (8 bits).

void setup(){
  for(int i=0;i<8;i++){  // Digital pins 0~7 as outputs. 
    pinMode(i,OUTPUT);
  }
}

void loop(){
  for(n=1;n<128;n = n << 1){
    PORTD= n;
    delay(132);
//    delay(analogRead(0)/4);
  }
  for(n=128;n>1;n = n >> 1){
    PORTD= n;
    delay(132);
//    delay(analogRead(0)/4);
  }
}

A potentiometer was used to adjust the scanning frequency.
A delay dependent of the analog input 0 was used.This part is commented in the final code.

See the Youtube Video: