我开始使用GPS模块,我的项目是使用带有陶瓷天线的近地天体6M GPS模块。所以,早些时候我尝试用Arduino Nano连接GPS模块,并成功地在Arduino IDE串行监视器上显示GPS NEMA语句输出,尽管GPS模块无法连接到任何卫星。
现在,我试图添加一个SSD1306 OLED模块到这个项目。因此,当GPS更新其位置时,就可以从GPS模块中获取纬度和经度值,并在OLED屏幕上显示。
到目前为止,我编写的代码是在Arduino IDE中正确编译的,但是OLED模块未能显示预期的信息。我一直在串行监视器上获取"SSD1306分配失败“错误。
我已经验证了我的OLED显示模块的I2C地址,它是0x3C而不是0x3D。
我还用单独的代码测试了OLED显示器,它工作得很好。
另外,我也无法弄清楚这段代码有什么问题,因为它导致了这些意想不到的结果。
下面是我在这个项目中使用的代码。
所以,如果社区的一位程序员能帮我解决这个问题,那将是非常感谢的。
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#define OLED_WIDTH 128
#define OLED_HEIGHT 64
#define OLED_RESET -1
#define OLED_ADDR 0x3C
Adafruit_SSD1306 oled(OLED_WIDTH, OLED_HEIGHT, &Wire, OLED_RESET);
SoftwareSerial serial_connect(4, 3); //Rx:pin(4) Tx:pin(3)
TinyGPSPlus gps;
void setup()
{
Serial.begin(9600);
serial_connect.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!oled.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR))
{
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
Serial.println("GPS start");
oled.clearDisplay();
oled.setTextSize(1);
oled.setTextColor(SSD1306_WHITE);
oled.setCursor(0, 0);
oled.print("Detecting GPS");
oled.setCursor(0, 10);
oled.print("Coordinates");
oled.display();
delay(5000); //5 seconds delay
}
void loop()
{
while(serial_connect.available())
{
gps.encode(serial_connect.read());
}
if(gps.location.isUpdated())
{
Serial.println("Satellite Count:");
Serial.println(gps.satellites.value());
Serial.println("Latitude:");
Serial.println(gps.location.lat(),6);
Serial.println("Longitude:");
Serial.println(gps.location.lng(),6);
Serial.println("Speed MPH:");
Serial.println(gps.speed.mph());
Serial.println("Altitude Feet:");
Serial.println(gps.altitude.feet());
Serial.println(" ");
oled.clearDisplay();
oled.setCursor(0, 0);
oled.print("Lati=");
oled.setCursor(0, 10);
oled.print(gps.location.lat(),6);
oled.setCursor(10, 0);
oled.print("Long=");
oled.setCursor(10, 10);
oled.print(gps.location.lng(),6);
oled.display();
delay(500);
}
}发布于 2022-07-27 02:50:57
现在有点晚了,但让我看看.这是个有趣的问题。
您的代码遵循Adafruit,w.r.t提供的示例。SSD1306。当您为GPS的UART定义引脚3和4时,您使用的是哪些引脚?D3和D4?用于I2C OLED显示器的引脚是什么?您必须确保OLED显示器分别连接到A4和A5。
当显示器工作时,你是否做了什么不同的事情,例如使用不同的平台或单片机?
https://stackoverflow.com/questions/72845820
复制相似问题