Arduino 写入屏幕的速度
Arduino writing speed to screen
我无法让我的GPS更新速度。它显示文本,如果我将 GPS 速度从位置更新循环中取出,它会显示一次当前速度,然后无法更新。知道吗?
void loop() {
while (serial_connections.available()) {
gps.encode(serial_connections.read());
if (gps.location.isUpdated()) {
DText = Serial.println(gps.speed.mps());
DSat = Serial.println(gps.satellites.value());
}
display.clearDisplay(); // clears last number
display.display(); // writes clear to screen
display.setCursor(10, 5); //Set drawing posision
display.print(DText); // what to draw
display.setCursor(35, 5);
display.print(" MPS");
display.setCursor(10, 18);
display.print(DSat);
display.setCursor(35, 18);
display.print(" Sat");
display.display(); // writes to the screen
delay (50);
}
}
它显示当前速度一次,然后无法更新。知道吗?
您的草图花费所有时间更新显示并等待。 以下是正在发生的事情:
1)当一个字符可用时,它被读取并传递给encode
。
2)然后它更新显示,这需要一些时间。 你没有给我们整个程序,也没有确定硬件,所以我真的不能说需要多长时间。
3)然后等待50ms。 在此期间,GPS字符继续到达。 它们将存储在输入缓冲区中,直到调用read()
,或者直到存储 64 个字符。 然后它们将被丢弃。
在 9600(我猜)时,可能会有 50 个字符。 现在输入缓冲区几乎已满。
4) 再次执行while
循环测试,读取并解析第二个字符(步骤 1),更新显示(没有新信息可用,步骤 2),再等待 50 毫秒。
15 毫秒后,输入缓冲区已满,Arduino 开始忽略字符。 当 50ms 延迟完成时,丢失了 35 个字符(在 9600 处)。
这会阻止成功解析收到的(部分)NMEA 句子,并且速度不会更新。 草图将继续使用旧信息更新显示,然后再等待一段时间,这会导致更多的字符丢失。
循环结构需要重新设计,以便仅在有新信息可用时才更新显示,并且切勿使用延迟:
#include <LiquidCrystal.h> ???
LiquidCrystal display; ???
#include <NMEAGPS.h>
NMEAGPS gps;
gps_fix fix;
// Here are three different ways to connect the GPS:
#define gpsPort Serial1
//#include <AltSoftSerial.h>
//AltSoftSerial gpsPort; // two specific pins required (8 & 9 on an UNO)
//#include <NeoSWSerial.h>
//NeoSWSerial gpsPort( 3, 4 );
void setup()
{
Serial.begin( 9600 );
gpsPort.begin( 9600 );
}
void loop()
{
// Read and parse any available characters from the GPS device
if (gps.available( gpsPort )) {
// Once per second, a complete fix structure is ready.
fix = gps.read();
Serial.print( F("Speed: ") );
float speed = 0.0;
if (fix.valid.speed) {
speed = fix.speed_kph() * 1000.0 / 3600.0;
Serial.print( speed );
}
Serial.println();
Serial.print( F("Sats: ") );
if (fix.valid.satellites)
Serial.println( fix.satellites );
Serial.println();
// Update the display ONCE PER SECOND
display.clearDisplay(); // clears last number
display.display(); // writes clear to screen
display.setCursor(10, 5); //Set drawing posision
if (fix.valid.speed)
display.print( speed ); // what to draw
display.setCursor(35, 5);
display.print(" MPS");
display.setCursor(10, 18);
if (fix.valid.satellites)
display.print( fix.satellites );
display.setCursor(35, 18);
display.print(" Sat");
display.display(); // writes to the screen
}
}
这使用我的NeoGPS库。 它比所有其他GPS库更小,更快,更可靠,更准确。 即使您不使用它,也应该阅读有关选择串行端口和故障排除的相关页面。
NeoGPS,AltSoftSerial和NeoSWSerial都可以从Arduino IDE库管理器中获得,在菜单Sketch ->Include Library -> Manage Libraries下。
- 为什么在读取文件大小时文件IO速度会发生变化
- UE4-如何在给定4个屏幕坐标的情况下缩放纹理或材质
- 为什么std::condition_variable notify_all的工作速度比notify_one快(对于随机请
- 文件系统:复制功能的速度秘诀是什么
- 如何在GTK程序运行时禁用屏幕保护程序/电源管理/屏幕消隐
- 使用 SFML 和 C++ 将 Pixel 打印到屏幕上
- 学习多线程C++:添加线程不会使执行速度更快,即使它看起来应该
- 在 Windows 8/10 技术中完全实时的屏幕捕获,没有延迟
- Winapi:屏幕截图未显示在窗口中
- 在C++中使用并行化的预期速度是多少(不是 OpenMp,而是 <thread>)
- 如何在快板的屏幕中显示子位图的绘制?
- 两个连续的 OpenMP 并行区域会相互减慢速度
- 查找标准::hash_map与标准::矢量的速度
- 按回车键后输出屏幕关闭
- 加快在C++中读取/处理日志文件的速度
- 要在屏幕上绘制一些小瓷砖,我应该使用 QQuickItem 还是 QQuickPaintedItem?
- SFML 向下移动时如何围绕屏幕中心旋转?
- Arduino 写入屏幕的速度
- 当屏幕上有很多东西时,Opengl会减慢速度
- 函数使用C++/OpenGL/Glut在屏幕上绘制文本的速度比glutBitmapCharacter快