Application Demo: 7 Digit Voltmeter Interfacing with CTE UART TFT LCD

Hi, I am attempting (and failing miserably!) to convert the original sketch used to output the results from an LTC2400 to a TFT display. I can get the serial output version of the sketch to work fine.
The TFT version of the sketch uses a library <UARTLCD.h> which was made available by coldtear electronics . My idea was that if I ould get a copy of the original library I would change the tft portions to use the "new" MCUFRIEND_kbv library along with the ADAFRUIT_GFX. I want to fabricate two of these "precision" DVM's such that I can incorperate them in a dual Bench Power supply I am building. I have already posted this query in another stream but really didn't receive any useful help. The coldtears Web site has closed down so it is not possible to contact them to get a copy of the library.
As the guru on TFT devices and the range of drivers etc used, and my belief that you were probably heavily involved in the creation of the original TFT LTC2400 script can you point me in the right direction on modifying the sketch to use the new TFT libraries.

Thank you in anticipation,

Don

Post a link to the actual display you want to use.
Draw a pencil sketch of what you want the screen to look like. e.g. Analog dial or decimal digits

If you have a working program for different hardware, paste it.

There is nothing too complicated about displaying a voltage reading.
But we do need to know what hardware is available.

David.

David,
Thank you for your prompt response. I purchased this on EBAY:http://www.ebay.co.uk/itm/2-4-inch-TFT-LCD-Display-Shield-Touch-Panel-ILI9341-240X320-for-Arduino-UN-D1E3-/112639859701?_trksid=p2349526.m4383.l4275.c10#. Whilst the seller says it uses a 1L19341 controller it doesnt, having read your posts about the stuff sold on EBAY and using the test in MCUFRIEND_kbv it identifies it as a HE8347D. Setting this as controller in the Library code (.cpp file) it runs through all the graphicstest_kbv tests perfectly.

The sketch I am using is as follows:

[code//LTC2400 24bit ADC Module 
//
//Application Demo: 7 digit voltmeter interfacing with CTE UART TFT LCD
//24bit ADC IC: LTC2400
//4.096 precision reference: TI REF3040
//
//By coldtears electronics
//
//LTC2400 code is adapted from Martin Nawrath
//Kunsthochschule fuer Medien Koeln
//Academy of Media Arts Cologne
//
//UART TFT Library from coldtears electronics is used
//as to display results

#include <UARTLCD.h>
#include <Stdio.h>
#include<stdlib.h>

UARTLCD uartlcd(true,false); //(single wire mode,checksum enable)

#ifndef cbi
#define cbi(sfr, bit)     (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit)     (_SFR_BYTE(sfr) |= _BV(bit))
#endif

#define LTC_CS 2         // LTC2400 Chip Select Pin  on Portb 2
#define LTC_MISO  4      // LTC2400 SDO Select Pin  on Portb 4
#define LTC_SCK  5       // LTC2400 SCK Select Pin  on Portb 5


void setup() {

cbi(PORTB,LTC_SCK);      // LTC2400 SCK low
sbi (DDRB,LTC_CS);       // LTC2400 CS HIGH

cbi (DDRB,LTC_MISO);
sbi (DDRB,LTC_SCK);

Serial.begin(38400);
uartlcd.Clr_screen(BLACK); delay(400);     //Clear screen Black color
uartlcd.Clr_screen(BLACK); delay(400);     //Clear screen Black color
uartlcd.Draw_image(412,15,6); delay(100); 
uartlcd.Draw_text(BLACK, PURPLE,"LTC2400 24bit", 100, 4, 319,230,  6); delay(70);
uartlcd.Draw_text(BLACK, CYAN,"ADC Module ", 110, 35, 319,230,  6); delay(70);

// init SPI Hardware
sbi(SPCR,MSTR) ; // SPI master mode
sbi(SPCR,SPR0) ; // SPI speed
sbi(SPCR,SPR1);  // SPI speed
sbi(SPCR,SPE);   //SPI enable

//Serial.println("LTC2400 ADC Test");

}
float volt;
float v_ref=4.094;          // Reference Voltage, 5.0 Volt for LT1021 or 3.0 for LP2950-3

long int ltw = 0;         // ADC Data ling int
int cnt;                  // counter
byte b0;                  //
byte sig;                 // sign bit flag
char st1[20];             // float voltage text

/********************************************************************/
void loop() {

cbi(PORTB,LTC_CS);             // LTC2400 CS Low
delayMicroseconds(1);
if (!(PINB & (1 << 4))) {    // ADC Converter ready ?
  //    cli();
  ltw=0;
  sig=0;

  b0 = SPI_read();             // read 4 bytes adc raw data with SPI
  if ((b0 & 0x20) ==0) sig=1;  // is input negative ?
  b0 &=0x1F;                   // discard bit 25..31
  ltw |= b0;
  ltw <<= 8;
  b0 = SPI_read();
  ltw |= b0;
  ltw <<= 8;
  b0 = SPI_read();
  ltw |= b0;
  ltw <<= 8;
  b0 = SPI_read();
  ltw |= b0;

  delayMicroseconds(1);

  sbi(PORTB,LTC_CS);           // LTC2400 CS Low

  if (sig) ltw |= 0xf0000000;    // if input negative insert sign bit
  ltw=ltw/16;                    // scale result down , last 4 bits have no information
  volt = ltw * v_ref / 16777216; // max scale
  char tmp[10];
  dtostrf(volt,6,6,tmp);
  tmp[8]='V';
  tmp[9]='\n';
//   Serial.print(cnt++);
//   Serial.print(";  ");
//   printFloat(volt,6);           // print voltage as floating number
//   Serial.println("  ");
 uartlcd.Draw_text(BLACK, YELLOW,tmp,   10, 100, 319, 220,  9);   delay(50);
 
}
sbi(PORTB,LTC_CS); // LTC2400 CS hi
delay(20);

}
/********************************************************************/
byte SPI_read()
{
SPDR = 0;
while (!(SPSR & (1 << SPIF))) ; /* Wait for SPI shift out done */
return SPDR;
}
/********************************************************************/
//  printFloat from  tim / Arduino: Playground
// printFloat prints out the float 'value' rounded to 'places' places
//after the decimal point
void printFloat(float value, int places) {
// this is used to cast digits
int digit;
float tens = 0.1;
int tenscount = 0;
int i;
float tempfloat = value;

// if value is negative, set tempfloat to the abs value

  // make sure we round properly. this could use pow from
//<math.h>, but doesn't seem worth the import
// if this rounding step isn't here, the value  54.321 prints as

// calculate rounding term d:   0.5/pow(10,places)
float d = 0.5;
if (value < 0)
  d *= -1.0;
// divide by ten for each decimal place
for (i = 0; i < places; i++)
  d/= 10.0;
// this small addition, combined with truncation will round our

tempfloat +=  d;

if (value < 0)
  tempfloat *= -1.0;
while ((tens * 10.0) <= tempfloat) {
  tens *= 10.0;
  tenscount += 1;
}

// write out the negative if needed
if (value < 0)
  Serial.print('-');

if (tenscount == 0)
  Serial.print(0, DEC);

for (i=0; i< tenscount; i++) {
  digit = (int) (tempfloat/tens);
  Serial.print(digit, DEC);
  tempfloat = tempfloat - ((float)digit * tens);
  tens /= 10.0;
}

// if no places after decimal, stop now and return
if (places <= 0)
  return;

// otherwise, write the point and continue on
Serial.print(',');

for (i = 0; i < places; i++) {
  tempfloat *= 10.0;
  digit = (int) tempfloat;
  Serial.print(digit,DEC);
  // once written, subtract off that digit
  tempfloat = tempfloat - (float) digit;
}
}
]

I also have a serial out sketch which works fine. If i had carried on failing so dramatically i was going to try and convert this to output to a TFT display :o

Hardware: Arduino R3, LTC2400 on breakout, TFT panel. I have had the DVM working fine and the TFT panel working fine , just not with this sketch.

I don't need anything clever on the display:


| |
| PSU N | N = Constant 1 or 2
| |
| XX.XXXX Volts |
| |
| X.XXXX Amps |

If you can help me with the basics I am sure I can tart this up. As I said if I could get a copy of the original Library (UARtLCD so I could compile the sketch I have, I am sure I could have solved this myself, however I am most grateful for whatever help you can give.

I have to add some logic to the DVM so I can switch the input between the two measurements being made (Voltage and Current). This will require me to hang an output onto the arduino/sketch so the input matches what is being displayed (or vice versa).

Once again many thanks for the help

Don

I have no idea what UARTLCD.h is. Google does not get me very far.

I just guess that it is a proprietary "intelligent TFT" from ColdTears.

MCUFRIEND_kbv is designed for "mcufriend uno" shields. i.e. plug and go.
Yes, you can drive most parallel TFT modules but you have to configure a "SPECIAL"

Your Voltmeter is pretty straightforward:

read LTC2400 via SPI.
create formatted xxxx.xxV in a buffer
print the buffer to your TFT

If you use Mcufriend Shield, you can connect your SPI LTC2400 to the hardware SPI pins.
And use either D10 or A5 as your "chip-select" on a Uno. A Mega has lots of spare pins.

Post a link to the display. Say which Arduino. We could write the code for you.

David.

Thank you for the response.
The tft is labelled mcufriend 2.4 tft
As I said I have had all this working just using the serial output version of this SKETCH on my Arduino R3.
I guess from your response I should simply (?) Take the output being sent serially and send that to the tft

I shall give it a go.

Back to the drawing board :o

Regards,

Don