如何将Arduinojson与SD.H库一起使用

发布于 2025-01-21 06:26:55 字数 954 浏览 4 评论 0原文

我使用Arduinojson从Arduino Uno到Nodemcu ESP8266的两个传感器分析传感器数据。在我在Arduino代码中安装SD.H库之前,这效果很好。我需要它,因为有必要将数据保存在SD卡上。现在,当我在代码上使用此库时,我在串行监视器上只有两个数据。它应该是数据的连续输出。我检查了一下,当我删除serializejson(doc,nodemcu); line时,我得到了所有数据。 我该怎么做如何使用Arduinojson解析数据,还可以使用SD.H库?

这是Arduino的代码:

#include <SoftwareSerial.h>
#include <ArduinoJson.h>
#include <SD.h>
#include <SPI.h>

SoftwareSerial nodemcu(5, 6);

float emg1, emg2, emgdiff;


char filename1[30];
char filename2[30];

void setup() {
  Serial.begin(115200);
   nodemcu.begin(4800);
  delay(1000);

}

void loop() {
  StaticJsonDocument<1000> doc;
  float sensorValue01 = analogRead(A0);
  float sensorValue02 = analogRead(A1);


  emg1 = sensorValue01/1023 * 5;
  emg2 = sensorValue02/1023 * 5;
  emgdiff = emg1 - emg2;
  Serial.println(emg1);
  Serial.println(emg2);

   doc["emg1"] = emg1;
   doc["emg2"] = emg2;
  serializeJson(doc, nodemcu);
}

I use ArduinoJson to parse Sensor Data from two Sensors from Arduino Uno to nodemcu ESP8266. This worked pretty well until I installed the SD.h library in the Code of the Arduino. I need it because it is necessary to save the data also on the SD Card. When I use this library now on my code I got only two Datas on the Serial Monitor. It should be a continuous output of data. I checked, when I delete theserializeJson(doc, nodemcu); line, I got all the datas.
What can I do to parse data with ArduinoJson and use also the SD.h library ?

Here's the code of the Arduino:

#include <SoftwareSerial.h>
#include <ArduinoJson.h>
#include <SD.h>
#include <SPI.h>

SoftwareSerial nodemcu(5, 6);

float emg1, emg2, emgdiff;


char filename1[30];
char filename2[30];

void setup() {
  Serial.begin(115200);
   nodemcu.begin(4800);
  delay(1000);

}

void loop() {
  StaticJsonDocument<1000> doc;
  float sensorValue01 = analogRead(A0);
  float sensorValue02 = analogRead(A1);


  emg1 = sensorValue01/1023 * 5;
  emg2 = sensorValue02/1023 * 5;
  emgdiff = emg1 - emg2;
  Serial.println(emg1);
  Serial.println(emg2);

   doc["emg1"] = emg1;
   doc["emg2"] = emg2;
  serializeJson(doc, nodemcu);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文