MCP9808 temperature displayed on an LCD4884 Shield example

In a previous example we presented a basic example with the LCD4884 shield but to take this a bit further we will combine that with a temperature sensor and display the readings on the LCD – Connect an LCD4884 Joystick shield to an Arduino

We picked the MCP9808 sensor, here is some information about that sensor

The MCP9808 digital temperature sensor converts temperatures between -20°C and +100°C to a digital word with ±0.5°C (max.) accuracy. The MCP9808 comes with user-programmable registers that provide flexibility for temperature sensing applications. The registers allow user-selectable settings such as Shutdown or low-power modes and the specification of temperature Event and Critical output boundaries. When the temperature changes beyond the specified boundary limits, the MCP9808 outputs an Event signal.

The user has the option of setting the event output signal polarity as an active-low or active-high comparator output for thermostat operation, or as temperature event interrupt output for microprocessor-based systems. The event output can also be configured as a Critical temperature output. This sensor has an industry standard 2-wire, SMBus and Standard I2C™Compatible compatible (100kHz/400kHz bus clock) serial interface, allowing up to eight sensors to be controlled in a single serial bus.

 

Layout

This layout shows the MCP9808 module connected to the LCD4884

lcd4884 and mcp9808_bb
lcd4884 and mcp9808_bb

Code

You need to install a couple of libraries

The LCD4884 – LCD4884_Joystick_Shield_Demo and the Adafruit MCP9808 one – https://github.com/adafruit/Adafruit_MCP9808_Library

[codesyntax lang=”cpp”]

#include <LCD4884.h>
#include <Wire.h>
#include "Adafruit_MCP9808.h"

#define LCD_BACKLIGHT_PIN  7

Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();

char tempstringC[5];
char tempstringF[5];

void setup()
{
  Serial.begin(9600);
  pinMode(LCD_BACKLIGHT_PIN, OUTPUT);
  lcd.LCD_init();
  lcd.LCD_clear(); // blanks the display

  lcd.LCD_write_string(0, 1, "MCP9808 Test", MENU_NORMAL);
  delay(1000);
  lcd.LCD_clear();   // blanks the display
  if (!tempsensor.begin()) {
    Serial.println("Couldn't find MCP9808!");
    while (1);
  }
}


void loop()
{
  float tempC = tempsensor.readTempC();
  float tempF = tempC * 9.0 / 5.0 + 32;
  itoa(tempC,tempstringC,10);
  itoa(tempF,tempstringF,10);
  lcd.LCD_write_string(0, 1, "Temperature", MENU_NORMAL);
  lcd.LCD_write_string(0, 3, tempstringC, MENU_NORMAL);
  lcd.LCD_write_string(16, 3, " celsius", MENU_NORMAL);
  lcd.LCD_write_string(0, 4, tempstringF, MENU_NORMAL);
  lcd.LCD_write_string(16, 4, " fahr", MENU_NORMAL);
}

[/codesyntax]

 

Link

LCD4884 LCD Joystick Shield v2.0 4884 LCD Expansion Board Raspberrypi

High Accuracy I2C IICTemperature Sensor MCP9808 Breakout Board 0.25C /0.0625C

This div height required for enabling the sticky sidebar
Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views :