通常:程序应将使用SHT21_Read()(温度传感器)读取的数据写入csv文件。使用带有rasbian的覆盆子pi模型2。
这是c代码:
int main(){
unsigned long Counter;
signed short Temperature;
unsigned char Humidity;
File *fp;
Counter = 0;
I2C_Open("/dev/i2c-1"); // Hardware Revision 2.0
fp= fopen("sht21-data.csv", "w+");
I2C_Setup(I2C_SLAVE, 0x40);
while(1)
{
SHT21_Read(&Temperature,&Humidity);
printf("%lu\t%.1f\t%u\n",Counter++,((float)Temperature)/10,Humidity); //console output -> works
fprintf(fp, "%lu,%.1f,%u\n",Counter,((float)Temperature)/10,Humidity);
system("sleep 1");
}
fclose(fp);
I2C_Close();
return(0);
}
程序会创建文件,但它不包含任何数据。是否可能存在用户/文件权限问题?