Printing numerals on the MPTH with I2C

Printing numerals on the MPTH with I2C

Postby domR » Mon Sep 20, 2010 12:05 pm

I cant seem to get the LCD to display numbers on the display via I2C.

I don't mean numbers formatted as test, i.e. "2" but actual numbers.
domR
 
Posts: 4
Joined: Mon Sep 20, 2010 12:02 pm

Re: Printing numerals on the MPTH with I2C

Postby Spike » Mon Sep 20, 2010 12:54 pm

I think the MPTH may be interpreting the numbers as unrecognized codes (unprintable ASCII characters). If the numbers are single digits try adding 48 to the value so that the number matches the ACSII chart. Were zero is 48, see chart below.
Attachments
ASCIICHART.png
ASCII Chart is a screen shot from Arduino web page.
ASCIICHART.png (20.65 KiB) Viewed 2457 times
Spike
Site Admin
 
Posts: 95
Joined: Tue Feb 16, 2010 12:51 pm

Re: Printing numerals on the MPTH with I2C

Postby domR » Tue Sep 21, 2010 7:58 pm

it is. I'm using an Arduino using the standard I2c commands.

when i try to print a number, say decimal 100 and want to see 100 on the LCD screen i get the d

in serial i can use the command serial.print(100, DEC) or just serial.print(100) and i get 100 on the lcd?

cant seem to make that work using I2c
domR
 
Posts: 4
Joined: Mon Sep 20, 2010 12:02 pm

Re: Printing numerals on the MPTH with I2C

Postby Spike » Tue Sep 21, 2010 10:15 pm

This is the problem of the way I2C sends the decimal value vs the ASCII text.

Here is a quick solution that I came up with. (Not fully tested but it seems to work.) This solution is good for "printing" positive integer values to the MPTH using I2C.

Code: Select all
void I2C_TX_NUMBER(byte device, int numb)
{
  int tthous   = 0;
  int thous    = 0;
  int hunds    = 0;
  int tens     = 0;
  int ones     = 0;
  boolean alldigits = false;


  if(numb > 9999)
  {
    tthous = numb / 10000;
    numb = numb - (tthous * 10000);
    tthous = tthous + 48;
    I2C_TX(device,tthous);
    alldigits = true;
  }


  if(numb > 999)
  {
    thous = numb / 1000;
    numb = numb - (thous * 1000);
    thous = thous + 48;
    I2C_TX(device,thous);
    alldigits = true;
  } else if(alldigits)
  {
    I2C_TX(device,48);
  }


  if(numb > 99)
  {
    hunds = numb / 100;
    numb = numb - (hunds * 100);
    hunds = hunds + 48;
    I2C_TX(device,hunds);
    alldigits = true;
  } else if(alldigits)
  {
    I2C_TX(device,48);
  }


  if(numb > 9)
  {
    tens = numb / 10;
    numb = numb - (tens * 10);
    tens = tens + 48;
    I2C_TX(device,tens);
    alldigits = true;   
  } else if(alldigits)
  {
    I2C_TX(device,48);
  }

  numb = numb+48;
  I2C_TX(device,numb);
}
Spike
Site Admin
 
Posts: 95
Joined: Tue Feb 16, 2010 12:51 pm

Re: Printing numerals on the MPTH with I2C

Postby domR » Fri Sep 24, 2010 4:15 pm

That works. I'll try to figure out how to make negative numbers work.

thanks
domR
 
Posts: 4
Joined: Mon Sep 20, 2010 12:02 pm


Return to MPTH

Who is online

Users browsing this forum: No registered users and 0 guests