如何将Arduinojson与SD.H库一起使用
我使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论