Analog pins for LCD?

Hello,

Im trying to send data over 2 arduinos using SPI. I would like the master to read the temperature and the humidity from a DHT11 sensor then send the values over SPI to the slave which will display the information on a 1602A LCD. The output variables of the DHT11 are float type variables which are 8 bits so i will need all 8 data bits to be in use by the LCD screen.

My question is is it possible for the RS and Enable pins on the 1602A LCD to be anything other than digital pins 2-13 as all of these ports are taken.

I'd appreciate any help thank you :slight_smile:

Which float type has only 8 bits?

And yes, the analog pins also can be used as ordinary digital pins. At least on the typical ATmega controllers.

1 Like

if you ask if you can use the "Analog Pins" A0-A5 for the LCD also, then it's a yes.

1 Like

My apologies i just googled how many bits are floats and the first thing that came up said 8 so i assumed that was correct. So will it not be possible to display my value from the DHT11?

In this case better consult the data sheets of your devices. I suspect a fundamental misunderstanding in the bitness of a floating point number.

1 Like

Okay, the DHT11 data sheet is a mess. It looks like values are transmitted as fixed point values with 8 bits before and 8 bits after the decimal point. Don't care if you use the Adafruit library that returns (16 bit) float values.

Which library do you use for output on the LCD? Does it have functions to display floating point values?

1 Like

Not a direct answer to the question, but I use these with my 1602 LCD displays. (Fewer wires on a breadboard):

They are currently out of stock, but they are available elsewhere. Google I2C Backpack.

1 Like

The LCD interface can use either 4 bit or 8 bit mode, most if not all libraries use 4 bit mode.

The number of bits in a float has no connection whatsoever with the interface to the LCD. A float on most arduino boards is 4 bytes or 32 bits long, with 6 to 7 significant digits. Any library for the DHT will convert the reading to this float format. You then use print to send the ASCII characters representing the float to the LCD.

1 Like

It's always appreciated when posters show up their final code as solution, but please:

  • add comments which libraries are used or
  • if you have a local modifed "dht.h", add this to your post also
  • and mostly: post code only in code tags to make it readable. If you don't know code tags read in the forum how to, how to post code
1 Like

Here is my final code with full functionality, hopefully in the right format this time

* Master */
#include <SPI.h>
#include "dht.h" //This is an older version of the dht.h library v0.1.15
#define dht_apin A0

dht DHT;

uint8_t storage [12];
void setup()
{
  digitalWrite(SS, HIGH);
  SPI.begin();
  Serial.begin(9600);
  SPI.setClockDivider(SPI_CLOCK_DIV8);
  delay(1500);
}

void loop()
{

   DHT.read11(dht_apin);
    
    Serial.print("Current humidity = ");
    Serial.print(DHT.humidity);
    Serial.print("%  ");

  digitalWrite(SS, LOW);
  memcpy(storage, &DHT.humidity, 8);
  SPI.transfer(storage, sizeof storage );
   
  delay(1000);
  
  memcpy(storage, &DHT.temperature, 8);
  SPI.transfer(storage, sizeof storage ); 
  
  digitalWrite(SS, HIGH);
  delay(1000);
}
/* Slave */

#include <SPI.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(9, 8, 5, 4, 3, 2);


byte storage [8];
volatile byte pos;
volatile boolean process;
float buff[2];
static char bufout[16];

void setup()
{
  lcd.begin(16, 2);
  pinMode(MISO,OUTPUT);
  SPCR |= _BV(SPE);
  SPCR |= _BV(SPIE);
  pos = 0;
  process = false;
  Serial.begin(9600);

}

ISR(SPI_STC_vect)
{
  byte gathered = SPDR;
  if( pos < sizeof storage)
    {
      storage[pos++] = gathered;
    }
    else 
    process = true;
}

void loop()
{
  if( process )
  {
    
   
    memcpy(buff,&storage,8);
    dtostrf(buff[0],3, 3, bufout);
   
    lcd.setCursor(0,0);
    lcd.print("RH = ");
    lcd.print(bufout);
    lcd.print(" %");
    
    storage[pos] = 0;
    pos = 0;
    process = false;
    
    delay(1000);
    
    memcpy(buff,&storage,8);
    dtostrf(buff[0],3, 0, bufout);
   
    lcd.setCursor(0,1);
    lcd.print("Temp = ");
    lcd.print(bufout);
    lcd.print(" C");
    
    storage[pos] = 0;
    pos = 0;
    process = false;

    delay(1000);
  }
}
1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.