Obsługa ekranu LCD - Raspberry Pi

0

Witam, mam problem z zainicjalizowaniem ekranu lcd w raspberry pie. Chciałbym, aby na wyświetlaczu pokazywała się aktualna godzina i data oraz aktualny pomiar z czujnika temperatury. Wejście z czujnika jest podpięte do pinu 24.
Oto mój program:

#include <wiringPi.h> //WiringPi headers 
#include <lcd.h> //LCD headers from WiringPi 
#include <stdio.h> //Needed for the printf func-tion below 
#include <dirent.h> 
#include <string.h> 
#include <fcntl.h> 
#include <stdlib.h> 
#include <unistd.h> 
//Pin numbers below are the WiringPi pin numbers 
#define LCD_RS 15 //Register select pin 
#define LCD_E 16 //Enable Pin 
#define LCD_D4 1 //Data pin 4 
#define LCD_D5 4 //Data pin 5 
#define LCD_D6 5 //Data pin 6 
#define LCD_D7 6 //Data pin 7 
float temp(void) 
{ 
DIR *dir; 
struct dirent *dirent; 
char dev[16]; // Dev ID 
char devPath[128]; // Path to device 
char buf[256]; // Data from device 
char tmpData[6]; // Temp C * 1000 reported by device 
char path[] = "/sys/bus/w1/devices"; 
ssize_t numRead;
dir = opendir (path); 
if (dir != NULL) 
{ 
while ((dirent = readdir (dir))) 
// 1-wire devices are links beginning with 28- 
if (dirent->d_type == DT_LNK && 
strstr(dirent->d_name, "28-") != NULL) { 
strcpy(dev, dirent->d_name); 
printf("\nDevice: %s\n", dev); 
} 
(void) closedir (dir); 
} 
else 
{ 
perror ("Couldn't open the w1 devices directory"); 
return 1; 
} 
// Assemble path to OneWire device 
sprintf(devPath, "%s/%s/w1_slave", path, dev); 
// Read temp continuously 
// Opening the device's file triggers new reading 
while(1) { 
int fd = open(devPath, O_RDONLY); 
if(fd == -1) 
{ 
perror ("Couldn't open the w1 device."); 
return 1; 
} 
while((numRead = read(fd, buf, 256)) > 0) 
{ 
strncpy(tmpData, strstr(buf, "t=") + 2, 5); 
float tempC = strtof(tmpData, NULL); 
printf("Device: %s - ", dev);
printf("Temp: %.3f C ", tempC / 1000); 
printf("%.3f F\n\n", (tempC / 1000) * 9 / 5 + 32); 
return tempC / 1000; 
} 
close(fd); 
} 
/* return 0; --never called due to loop */ 
} 
int main(int argc, char *argv[]) 
{ 
int lcd; //Handle for LCD 
wiringPiSetup(); //Initialise WiringPi 
//Initialise LCD(int rows, int cols, int bits, int rs, int enable, int d0, int d1, int d2, int d3, int d4, int d5, int d6, int d7) 
if (lcd = lcdInit (2, 16,4,LCD_RS ,LCD_E ,LCD_D4 ,LCD_D5 ,LCD_D6 ,LCD_D7 ,0,0,0,0)){ 
printf ("lcdInit failed! \n"); 
return -1 ; 
} 
while(1) 
{ 
lcdPosition(lcd,0,0); 
float fl; 
fl = temp(); 
unsigned char str[50]; 
sprintf(str,"Temp : %0.3f C",fl); 
lcdPuts(lcd, str); 
delay(1000); 
} 
}

0

Ambitny plan, gratuluję okazji do zabawy.
Może wrzuć screenshota przy następnym poście jak to wygląda.

0

Z realnym sprzętem dopiero podziałam za 1.5 tygodnia, pokaże co się udało zrobić :) A co do kodu, czy ten kod z 1 postu pozwoli na wyświetlenie odczytu z czujnika temperatury ? Pozdrawiam

1 użytkowników online, w tym zalogowanych: 0, gości: 1