TMP421 and LCD

Making your program work.
Xrim
Posts: 7
Joined: Sun Feb 28, 2010 8:39 am

TMP421 and LCD

Post by Xrim »

Horray! I just got the TMP421.

Well I tried to get it to work with the 117 lcd kit with no success. I have tried all kinds of solutions and running out of ideas (remember I only have two months of experience).

Here is the code I'm trying to run, as you can see have used the same code as with the LM35DZ sensor (http://forum.moderndevice.com/phpBB3/vi ... ?f=9&t=374)but with some changes.

Code: Select all

#include <SoftwareSerial.h>

#define rxPin 4  // rxPin is immaterial - not used - just make this an unused Arduino pin number
#define txPin 14 // pin 14 is analog pin 0, on a BBB just use a servo cable :), see Reference pinMode
SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);

#include "Wire.h"
#include <LibTemperature.h>

LibTemperature temp = LibTemperature(0);

// mySerial is connected to the TX pin so mySerial.print commands are used
// one could just as well use the software mySerial library to communicate on another pin

void setup(){


   pinMode(txPin, OUTPUT);
   mySerial.begin(9600);      // 9600 baud is chip comm speed

   mySerial.print("?G420");   // set display geometry,  4 x 20 characters in this case
   delay(500);                // pause to allow LCD EEPROM to program

   mySerial.print("?Bff");    // set backlight to ff hex, maximum brightness
   delay(1000);                // pause to allow LCD EEPROM to program

   mySerial.print("?c0");     // set tabs to six spaces
   delay(1000);               // pause to allow LCD EEPROM to program
   
    mySerial.print("?>4");       // define special characters
   delay(300);                                  // delay to allow write to EEPROM
                                                
   mySerial.print("?f");                   // clear the LCD
   delay(10);                                              
        
                                               
   }

void loop(){

   mySerial.print("?>4"); 
   mySerial.print("?x00?y0");
   mySerial.print(temp.GetTemperature()); //display temp  [b]This line is the problem[/b]
   mySerial.print("?x18?y0");
   mySerial.print("C");
   
   
   
   delay(3000);                           

   
}

I get the following error
Error:Call of overloaded'print(float)' is ambiuous

C:\Arduino\arduino-0017\hardware\libraries\SoftwareSerial/SoftwareSerial.h:43: note:
void SoftwareSerial::print(long unsigned int)

Oh, by the way! Thank you for sending me the cable, OUTSTANDING service. Unfortunately it was the wrong one :)

oz
Site Admin
Posts: 542
Joined: Mon May 12, 2008 4:19 pm

Re: TMP421 and LCD

Post by oz »

Xrim,

Give me some more details on what your are trying to do, and what is not working please.
Also see the note in the code below.

Code: Select all

    #include <SoftwareSerial.h>

    #define rxPin 4  // rxPin is immaterial - not used - just make this an unused Arduino pin number
    #define txPin 14 // pin 14 is analog pin 0, on a BBB just use a servo cable :), see Reference pinMode
    SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);

    #include "Wire.h"
    #include <LibTemperature.h>

    LibTemperature temp = LibTemperature(0);

    // mySerial is connected to the TX pin so mySerial.print commands are used
    // one could just as well use the software mySerial library to communicate on another pin

    void setup(){


       pinMode(txPin, OUTPUT);
       mySerial.begin(9600);      // 9600 baud is chip comm speed

       mySerial.print("?G420");   // set display geometry,  4 x 20 characters in this case
       delay(500);                // pause to allow LCD EEPROM to program

       mySerial.print("?Bff");    // set backlight to ff hex, maximum brightness
       delay(1000);                // pause to allow LCD EEPROM to program

       mySerial.print("?c0");     // set tabs to six spaces
       delay(1000);               // pause to allow LCD EEPROM to program
       
        mySerial.print("?>4");       // define special characters
       delay(300);                                  // delay to allow write to EEPROM
                                                   
       mySerial.print("?f");                   // clear the LCD
       delay(10);                                             
           
                                                   
       }

    void loop(){

       mySerial.print("?>4");
       mySerial.print("?x00?y0");

// try this
int tmp = temp.GetTemperature();


       mySerial.print(tmp); //display temp  [b]This line is the problem[/b]
       mySerial.print("?x18?y0");
       mySerial.print("C");
       
       
       
       delay(3000);                           

       
    }

Xrim
Posts: 7
Joined: Sun Feb 28, 2010 8:39 am

Re: TMP421 and LCD

Post by Xrim »

I'm trying to get the temperature to get displayed in a 4x20 LCD with the 117 connected to it.
Your change worked perfect. However, I don't get any decimals displayed on the LCD. If I use the same code but watch the value on the serial monitor I get the value by two decimals.

oz
Site Admin
Posts: 542
Joined: Mon May 12, 2008 4:19 pm

Re: TMP421 and LCD

Post by oz »

You have to print the decimal point and the fraction manually I think.

int fraction = ( temp * 100) % 100; // use something like this to calculate the fraction - don't forget to look up the modulo operator - very useful!

I'm in a rush right now - there's another thread about exactly this subject on the forum - poke around and you'll find the code.

Paul

oz
Site Admin
Posts: 542
Joined: Mon May 12, 2008 4:19 pm

Re: TMP421 and LCD

Post by oz »

Re: TMP421 and LCD

You have to print the decimal point and the fraction manually I think.

you might need this - cast float to an int

int fraction = (int)(temp * 100) % 100; // use something like this to calculate the fraction - don't forget to look up the modulo operator - very useful!

Paul

Xrim
Posts: 7
Joined: Sun Feb 28, 2010 8:39 am

Re: TMP421 and LCD

Post by Xrim »

Done!

I put really easy to understand remarks in the code so other newbies like me can understand it. Well I learned a lot!
I´ll start to bug you again as soon as I have ordered the compass module :twisted:

Code: Select all

/*Getting your RBBB/BBB, TMP421 and 4x20 LCD with a LCD117 to display
the temperature in big digit mode with two decimals.
Many thanks to Paul at Moderndevice.com who helped me*/

#include <SoftwareSerial.h>
#include "Wire.h"
#include <LibTemperature.h>

#define rxPin 4  // rxPin is immaterial - not used - just make this an unused Arduino pin number
#define txPin 14 // pin 14 is analog pin 0, on a BBB just use a servo cable :), see Reference pinMode

SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);

LibTemperature temp = LibTemperature(0);

void setup(){


   pinMode(txPin, OUTPUT);
   mySerial.begin(9600);      // 9600 baud is chip comm speed

   mySerial.print("?G420");   // set display geometry,  4 x 20 characters in this case
   delay(500);                // pause to allow LCD EEPROM to program

   mySerial.print("?B40");    // set backlight to ff hex, maximum brightness
   delay(1000);               // pause to allow LCD EEPROM to program
                                                       
   mySerial.print("?f");      // clear the LCD
   delay(10);                                              
                                                   
   }

void loop(){
int tmp = temp.GetTemperature();        //Since the MySerial cant display a float value we have to turn it into int 
                                        //problem is that a 25.43 C value turns into a two digit value, so 25 C is displayed
int dec = (temp.GetTemperature()*100);  //Turns the 25.43 C value into 2543
int decimal = dec%100;                  //Remove the two first digits in dec, For some reason this cannot be done in mySerial
   mySerial.print("?>3");               //Enter Big digit mode
   mySerial.print("?x00?y0");           //Start at line one, column one
   mySerial.print(tmp);                 //Display temp
   mySerial.print(".");                 //Print the .
   mySerial.print(decimal);             //Displays the decimals
   mySerial.print("?<");                //Exit big number mode
   mySerial.print("?x17?y0");
   mySerial.print("DEG");
   mySerial.print("?x17?y1");
   mySerial.print("C");
   
   
   
   delay(100);                          //Chose what update intervall you want in the display

   
}


JudgeDup
Posts: 5
Joined: Tue May 14, 2019 7:02 am
Location: Greece
Contact:

TMP421 and LCD

Post by JudgeDup »

I reflashed my firmware with the firmware version on the Printrbot site but the LCD isnt working is there a firmware build that includes support for both the LCD and heated bed?

oz
Site Admin
Posts: 542
Joined: Mon May 12, 2008 4:19 pm

Re: TMP421 and LCD

Post by oz »

I'm clueless about which LCD and "heated bed" you are using this with. Care to send some links?
With the LCD 117 it's all serial so getting the baud rate correct is crucial.

If you reflashed it did you get the baud rate right?

Post Reply