Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arduino 我想得到很多热传感器的图案,但我没有';我不知道该怎么做,该怎么做?_Arduino_Sensors_Temperature - Fatal编程技术网

Arduino 我想得到很多热传感器的图案,但我没有';我不知道该怎么做,该怎么做?

Arduino 我想得到很多热传感器的图案,但我没有';我不知道该怎么做,该怎么做?,arduino,sensors,temperature,Arduino,Sensors,Temperature,我在M5Stack上编写了一个程序,每秒测量64个温度数据,并将其写入SD卡 如果您将其输出为txt。文件,如上图所示 现在我正试图重新编写程序,这样数据就可以连续显示测量温度的时间 我想要temp.txt的结果: #include <Wire.h> #include <M5Stack.h> #define PCTL 0x00 #define RST 0x01 #define FPSC 0x02 #define INTC 0x03 #define STAT 0x04

我在M5Stack上编写了一个程序,每秒测量64个温度数据,并将其写入SD卡

如果您将其输出为txt。文件,如上图所示

现在我正试图重新编写程序,这样数据就可以连续显示测量温度的时间

我想要temp.txt的结果:

#include <Wire.h>
#include <M5Stack.h>


#define PCTL 0x00
#define RST 0x01
#define FPSC 0x02
#define INTC 0x03
#define STAT 0x04
#define SCLR 0x05
#define AVE 0x07
#define INTHL 0x08
#define TTHL 0x0E
#define INT0 0x10
#define T01L 0x80

#define AMG88_ADDR 0x68 // in 7bit

#define WIDTH (320 / 8)
#define HEIGHT (240 / 8)

float gain = 10.0;
float offset_x = 0.2;
float offset_green = 0.6;

float sigmoid(float x, float g, float o) {
  return (tanh((x + o) * g / 2) + 1) / 2;
}

uint16_t heat(float x) {  // 0.0〜1.0の値を青から赤の色に変換する
  x = x * 2 - 1;  // -1 <= x < 1 に変換

  float r = sigmoid(x, gain, -1 * offset_x);
  float b = 1.0 - sigmoid(x, gain, offset_x);
  float g = sigmoid(x, gain, offset_green) + (1.0 - sigmoid(x, gain, -1 * offset_green)) - 1;

  return (((int)(r * 255) >> 3) << 11) | (((int)(g * 255) >> 2) << 5) | ((int)(b * 255) >> 3);
}

String tempS;

//bool brght = 0;
//bool ftmt = 4;

//int x = 37;

void listDir(fs::FS &fs, const char * dirname, uint8_t levels) {

  // Print blank line on screen
  M5.Lcd.printf(" \n  ");
  M5.Lcd.printf(" \n  ");

  Serial.printf("Listing directory: %s\n", dirname);
  M5.Lcd.printf("Listing directory: %s\n", dirname);

  File root = fs.open(dirname);
  if (!root) {
    Serial.println("Failed to open directory");
    M5.Lcd.println("Failed to open directory");
    return;
  }
  if (!root.isDirectory()) {
    Serial.println("Not a directory");
    M5.Lcd.println("Not a directory");
    return;
  }

  File file = root.openNextFile();
  while (file) {
    if (file.isDirectory()) {
      Serial.print("  DIR : ");
      M5.Lcd.print("  DIR : ");
      Serial.println(file.name());
      M5.Lcd.println(file.name());
      if (levels) {
        listDir(fs, file.name(), levels - 1);
      }
    } else {
      Serial.print("  FILE: ");
      M5.Lcd.print("  FILE: ");
      Serial.print(file.name());
      M5.Lcd.print(file.name());
      Serial.print("  SIZE: ");
      M5.Lcd.print("  SIZE: ");
      Serial.println(file.size());
      M5.Lcd.println(file.size());
    }
    file = root.openNextFile();
  }
}

void readFile(fs::FS &fs, const char * path) {
  //Serial.printf("Reading file: %s\n", path);
  //M5.Lcd.printf("Reading file: %s\n", path);

  File file = fs.open(path);
  /*if (!file) {
    Serial.println("Failed to open file for reading");
    M5.Lcd.println("Failed to open file for reading");
    return;
  }

  Serial.print("Read from file: ");
  M5.Lcd.print("Read from file: ");*/
  while (file.available()) {
    int ch = file.read();
    Serial.write(ch);
    M5.Lcd.write(ch);
  }
}

void writeFile(fs::FS &fs, const char * path, const char * message) {
  //Serial.printf("Writing file: %s\n", path);
  //M5.Lcd.printf("Writing file: %s\n", path);

  File file = fs.open(path, FILE_WRITE);
  if (!file) {
      Serial.println("Failed to open file for writing");
   // M5.Lcd.println("Failed to open file for writing");
    return;
  }
  if (file.print(message)) {
      Serial.println("File written");
      //M5.Lcd.println("File written");
      } else {
      Serial.println("Write failed");
    //M5.Lcd.println("Write failed");
  }
}


void setup() {
  // put your setup code here, to run once:
  M5.begin();
  Serial.begin(115200);
  pinMode(21, INPUT_PULLUP);
  pinMode(22, INPUT_PULLUP);
  Wire.begin();

  write8(AMG88_ADDR, FPSC, 0x00);  // 10fps
  write8(AMG88_ADDR, INTC, 0x00);  // INT出力無効
  write8(AMG88_ADDR, 0x1F, 0x50);  // 移動平均出力モード有効
  write8(AMG88_ADDR, 0x1F, 0x45);
  write8(AMG88_ADDR, 0x1F, 0x57);
  write8(AMG88_ADDR, AVE, 0x20);
  write8(AMG88_ADDR, 0x1F, 0x00);

   /////////////////////////////////////////////////////////////////////////
 // cal = String("cal = ") + String(x) + "\r\n";
 // lum = String("lum = ") + String(brght) + "\r\n";
 // unit = String("unit = ") + String(ftmt) + "\r\n";

 // writeFile(SD, "/cal.txt", cal.c_str()); // questa funziona!!!!
 // writeFile(SD, "/lum.txt", lum.c_str()); // questa funziona!!!!
 // writeFile(SD, "/unit.txt", unit.c_str()); // questa funziona!!!!
  /////////////////////////////////////////////////////////////////////////

  //readFile(SD, "/cal.txt");
  //readFile(SD, "/lum.txt");
  //readFile(SD, "/unit.txt");

}

void write8(int id, int reg, int data) {
  Wire.beginTransmission(id);
  Wire.write(reg);
  Wire.write(data);
  uint8_t result = Wire.endTransmission();
  // Serial.printf("reg: 0x%02x, result: 0x%02x\r\n", reg, result);
}

void dataread(int id, int reg, int *data, int datasize) {
  Wire.beginTransmission(id);
  Wire.write(reg);
  Wire.endTransmission();

  Wire.requestFrom(id, datasize);
  int i = 0;
  while (Wire.available() && i < datasize) {
    data[i++] = Wire.read();
  }
}

void loop() {
   M5.update();
  
  // put your main code here, to run repeatedly:
  float temp[64];

  int sensorData[128];
  dataread(AMG88_ADDR, T01L, sensorData, 128);


    for (int i = 0 ; i < 64 ; i++) {
      int16_t temporaryData = sensorData[i * 2 + 1] * 256 + sensorData[i * 2];
      if (temporaryData > 0x200) {
        temp[i] = (-temporaryData +  0xfff) * -0.25;
      } else {
        temp[i] = temporaryData * 0.25;
      }
      
      tempS = String("temp =") + "\n" + String("[") + String(temp[0])+ String("],")+ String("[") + String(temp[1])+ String("],") + String("[")+String(temp[2])+ String("],")+ String("[")+ String(temp[3])+ String("],")+ String("[")+ String(temp[4])+ String("],")+ String("[")+ String(temp[5])+ String("],")+ String("[")+ String(temp[6])+ String("],")+ String("[")+ String(temp[7])+ String("],")+ "\n" + String("[") + String(temp[8])+ String("],")+ String("[") + String(temp[9])+ String("],") + String("[")+String(temp[10])+ String("],")+ String("[")+ String(temp[11])+ String("],")+ String("[")+ String(temp[12])+ String("],")+ String("[")+ String(temp[13])+ String("],")+ String("[")+ String(temp[14])+ String("],")+ String("[")+ String(temp[15])+ String("],") + "\n" + String("[") + String(temp[16])+ String("],")+ String("[") + String(temp[17])+ String("],") + String("[")+String(temp[18])+ String("],")+ String("[")+ String(temp[19])+ String("],")+ String("[")+ String(temp[20])+ String("],")+ String("[")+ String(temp[21])+ String("],")+ String("[")+ String(temp[22])+ String("],")+ String("[")+ String(temp[23])+ String("],") + "\n" + String("[") + String(temp[24])+ String("],")+ String("[") + String(temp[25])+ String("],") + String("[")+String(temp[26])+ String("],")+ String("[")+ String(temp[27])+ String("],")+ String("[")+ String(temp[28])+ String("],")+ String("[")+ String(temp[29])+ String("],")+ String("[")+ String(temp[30])+ String("],")+ String("[")+ String(temp[31])+ String("],") + "\n" + String("[") + String(temp[32])+ String("],")+ String("[") + String(temp[33])+ String("],") + String("[")+String(temp[34])+ String("],")+ String("[")+ String(temp[35])+ String("],")+ String("[")+ String(temp[36])+ String("],")+ String("[")+ String(temp[37])+ String("],")+ String("[")+ String(temp[38])+ String("],")+ String("[")+ String(temp[39])+ String("],") + "\n" + String("[") + String(temp[40])+ String("],")+ String("[") + String(temp[41])+ String("],") + String("[")+String(temp[42])+ String("],")+ String("[")+ String(temp[43])+ String("],")+ String("[")+ String(temp[44])+ String("],")+ String("[")+ String(temp[45])+ String("],")+ String("[")+ String(temp[46])+ String("],")+ String("[")+ String(temp[47])+ String("],") + "\n" + String("[") + String(temp[48])+ String("],")+ String("[") + String(temp[49])+ String("],") + String("[")+String(temp[50])+ String("],")+ String("[")+ String(temp[51])+ String("],")+ String("[")+ String(temp[52])+ String("],")+ String("[")+ String(temp[53])+ String("],")+ String("[")+ String(temp[54])+ String("],")+ String("[")+ String(temp[55])+ String("],") + "\n" + String("[") + String(temp[56])+ String("],")+ String("[") + String(temp[57])+ String("],") + String("[")+String(temp[58])+ String("],")+ String("[")+ String(temp[59])+ String("],")+ String("[")+ String(temp[60])+ String("],")+ String("[")+ String(temp[61])+ String("],")+ String("[")+ String(temp[62])+ String("],")+ String("[")+ String(temp[63])+ String("]");
      
      
      writeFile(SD, "/temp.txt", tempS.c_str()); // questa funziona!!!!
      readFile(SD, "/temp.txt");
     
      
   }
   
  

  M5.Lcd.fillScreen(BLACK);
  int x, y;
  
    for (y = 0; y < 8; y++) {
      for (x = 0; x < 8; x++) {
        float t = temp[(8 - y - 1) * 8 + 8 - x - 1];
        uint16_t color = heat(map(constrain((int)t, 0, 60), 0, 60, 0, 100) / 100.0);
        M5.Lcd.fillRect(x * WIDTH, y * HEIGHT, WIDTH, HEIGHT, color);
        M5.Lcd.setCursor(x * WIDTH + WIDTH / 2, y * HEIGHT + HEIGHT / 2);
        M5.Lcd.setTextColor(BLACK, color);
        M5.Lcd.printf("%d", (int)t);
      
      }
    }
  
  delay(500);
}
temp =
[36.25],[36.50],[36.75],[36.50],[36.50],[36.50],[37.00],[37.25],
[36.25],[36.25],[36.50],[36.75],[36.75],[36.75],[37.00],[36.75],
[36.25],[36.50],[36.50],[37.00],[36.75],[38.25],[38.25],[38.25],
[37.50],[37.75],[37.75],[38.25],[38.25],[38.00],[38.50],[38.50],
[37.25],[38.00],[38.25],[38.25],[38.00],[38.25],[38.25],[38.25],
[37.25],[37.75],[38.00],[38.25],[38.00],[38.00],[38.25],[38.75],
[36.75],[37.50],[37.75],[37.75],[38.00],[38.00],[38.00],[38.00],
[36.00],[37.00],[37.50],[37.25],[37.25],[37.25],[37.25],[37.50]
但是这个代码不能做到这一点。 你能告诉我你知道怎么解决这个问题吗

temp =
[36.25],[36.50],[36.75],[36.50],[36.50],[36.50],[37.00],[37.25],
[36.25],[36.25],[36.50],[36.75],[36.75],[36.75],[37.00],[36.75],
[36.25],[36.50],[36.50],[37.00],[36.75],[38.25],[38.25],[38.25],
[37.50],[37.75],[37.75],[38.25],[38.25],[38.00],[38.50],[38.50],
[37.25],[38.00],[38.25],[38.25],[38.00],[38.25],[38.25],[38.25],
[37.25],[37.75],[38.00],[38.25],[38.00],[38.00],[38.25],[38.75],
[36.75],[37.50],[37.75],[37.75],[38.00],[38.00],[38.00],[38.00],
[36.00],[37.00],[37.50],[37.25],[37.25],[37.25],[37.25],[37.50]

temp =
[same form but have different result than before based on time]