MATLAB Answers

Read data from DS18B20 digital temperature sensor connected to a Raspberry Pi into Simulink

최근 활동 Walter Roberson 님이 편집함. 30 Nov 2016
I wanted to implement temperature control using DS18B20 temperature sensor in Raspberry Pi 3 using Simulink external mode. Has anyone created SFunction to acquire temperature sensor readings connected to a Raspberry Pi? The code shown below shows error when I build in external mode.
#ifndef MATLAB_MEX_FILE
int main (void) {
DIR *dir;
DIR *dir1;
DIR *dir2;
char buf[256]; // Data from device
char buf1[256];
char buf2[256];
char tmpData[5]; // Temp C * 1000 reported by device
char tmpData1[5];
char tmpData2[5];
const char path[] = "/sys/bus/w1/devices/28-00000784ac50";
const char path1[] = "/sys/bus/w1/devices/28-00000783ea53";
const char path2[] = "/sys/bus/w1/devices/28-000007840c97";
char devPath[128]; // Path to device
char devPath1[128]; // Path to device
char devPath2[128]; // Path to device
ssize_t numRead;
int i = 0;
dir = opendir (path);
dir1 = opendir (path1);
dir2 = opendir (path2);
sprintf(devPath, "%s/%s/w1_slave", path);
sprintf(devPath1, "%s/%s/w1_slave", path1);
sprintf(devPath2, "%s/%s/w1_slave", path2);
while(1) {
int fd = open(path, O_RDONLY);
int fd1 = open(path1, O_RDONLY);
int fd2 = open(path2, O_RDONLY);
if(fd == -1){
y0=0;
}
if(fd1 == -1) {
y1=0;
}
if(fd2 == -1) {
y2=0;
}
while((numRead = read(fd, buf, 256)) > 0) {
strncpy(tmpData, strstr(buf, "t=") + 2, 5);
float tempC = strtof(tmpData, NULL);
y0 = tempC/1000;
}
while((numRead = read(fd1, buf1, 256)) > 0) {
strncpy(tmpData1, strstr(buf1, "t=") + 2, 5);
float tempC1 = strtof(tmpData1, NULL);
y1 = tempC1/1000;
}
while((numRead = read(fd2, buf2, 256)) > 0) {
strncpy(tmpData2, strstr(buf2, "t=") + 2, 5);
float tempC2 = strtof(tmpData2, NULL);
y2 = tempC2/1000;
}
}
}
# endif
The error shows -
"Error executing command "touch -c /home/pi/DS18B20_Trial2_ert_rtw/*.*;make -f DS18B20_Trial2.mk all -C /home/pi/DS18B20_Trial2_ert_rtw". Details:
STDERR: cc1: fatal error: DS18B20_Trial2.c.d: No such file or directory
compilation terminated.
make: *** [DS18B20_Trial2.c.o] Error 1"
I think the problem is with Matlab 2016a compiler? Any idea to solve this? Thanks a ton!!!!

  댓글 수: 0

로그인 to comment.

답변 수: 0


Translated by