GPS module on ESP32 not giving valid logs - arduino

Environments
osx
esp32
vscode
platformio
I am working on an ESP32 module with this GPS module (very similar except the one I have has "ublox" logo on it - bought about 2 years ago).
#include <Arduino.h>
#include <HardwareSerial.h>
#include <TinyGPS++.h>
TinyGPSPlus gps;
HardwareSerial SerialGPS(2);
void setup() {
Serial.begin(115200); // RX TX
SerialGPS.begin(9600, SERIAL_8N1, 16, 17);
}
void loop() {
Serial.println("------------");
Serial.print("available(): ");
Serial.println(SerialGPS.available());
Serial.println("------------");
while (SerialGPS.available() > 0) {
char c = SerialGPS.read();
Serial.print(c);
gps.encode(c);
}
Serial.println();
if (gps.location.isValid()) {
Serial.print("LAT=");
Serial.println(gps.location.lat(), 6);
Serial.print("LONG=");
Serial.println(gps.location.lng(), 6);
Serial.print("ALT=");
Serial.println(gps.altitude.meters());
} else {
Serial.println("not valid");
}
delay(1000);
}
I took it outside and ran it for over 15 mins, and I see the data are still invalid.
------------
available(): 195
------------
$GPRMC,023424.00,V,,,,,,,051120,,,N*79
$GPVTG,,,,,,,,,N*30
$GPGGA,023424.00,,,,,0,00,99.99,,,,,,*65
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
$GPGSV,1,1,00*79
$GPGLL,,,,,023424.00,V,N*49
not valid
------------
available(): 195
------------
$GPRMC,023425.00,V,,,,,,,051120,,,N*78
$GPVTG,,,,,,,,,N*30
$GPGGA,023425.00,,,,,0,00,99.99,,,,,,*64
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
$GPGSV,1,1,00*79
$GPGLL,,,,,023425.00,V,N*48
not valid
Since I see letters coming in, I don't think TX and RX are mixed up.
I am giving it 5V (although not exactly sure if it should be 3.3v or 5v).
How can I get valid GPS data coming in from this module?

To me it looks like the GPS module is sending data properly, but hasn't got any available. It could still be looking for satellites. You can try printing the number of available ones, and simply wait longer:
Add the following lines to your program before your if statement:
Serial.println(gps.time.value()); // Raw time in HHMMSSCC format (u32)
Serial.println(gps.time.hour()); // Hour (0-23) (u8)
Serial.println(gps.time.minute()); // Minute (0-59) (u8)
Serial.println(gps.time.second()); // Second (0-59) (u8)
Serial.println(gps.satellites.value()); // Number of satellites in use (u32)
The first step should be that your GPS module gets the correct time. This should happen after a few minutes, probably. Then the number of satellites in use should go up, and you should start getting valid results once a reasonable number of satellites are found. I tend to get a reading with probably about 9 satellites.
If it is a cheaper module it might take a while, especially from a cold start.

Related

Arduino Uno sim808 init error

Hey so I have arduino uno and a sim808 with gps antenna and gsm antenna. So here's the sample code:
#include <DFRobot_sim808.h>
#include <SoftwareSerial.h>
#define PIN_TX 3
#define PIN_RX 4
SoftwareSerial mySerial(PIN_TX,PIN_RX);
//DFRobot_SIM808 sim808(&mySerial);//Connect RX,TX,PWR,
DFRobot_SIM808 sim808(&mySerial);
void setup() {
//mySerial.begin(9600);
Serial.begin(9600);
//******** Initialize sim808 module *************
while(!sim808.init()) {
delay(1000);
Serial.print("Sim808 init error\r\n");
}
//************* Turn on the GPS power************
if( sim808.attachGPS())
Serial.println("Open the GPS power success");
else
Serial.println("Open the GPS power failure");
}
void loop() {
//************** Get GPS data *******************
if (sim808.getGPS()) {
Serial.print(sim808.GPSdata.year);
Serial.print("/");
Serial.print(sim808.GPSdata.month);
Serial.print("/");
Serial.print(sim808.GPSdata.day);
Serial.print(" ");
Serial.print(sim808.GPSdata.hour);
Serial.print(":");
Serial.print(sim808.GPSdata.minute);
Serial.print(":");
Serial.print(sim808.GPSdata.second);
Serial.print(":");
Serial.println(sim808.GPSdata.centisecond);
Serial.print("latitude :");
Serial.println(sim808.GPSdata.lat);
Serial.print("longitude :");
Serial.println(sim808.GPSdata.lon);
Serial.print("speed_kph :");
Serial.println(sim808.GPSdata.speed_kph);
Serial.print("heading :");
Serial.println(sim808.GPSdata.heading);
Serial.println();
//************* Turn off the GPS power ************
sim808.detachGPS();
}
}
So I'm always getting a result of "sim808 init error"
I don't know what the problem is but I do hope that the sim808 isn not broken because it has light in STA(status) and in NET(network) that is slowly blinking but there's no light in PPS(gps) I don't know what's the problem I'm really really confused.
//mySerial.begin(9600);
This line just below the void setup must be a code part not comment, delete the
'//'
mySerial.begin(9600);
Serial.begin(9600);
Also 6th line
//DFRobot_SIM808 sim808(&mySerial);//Connect RX,TX,PWR,
must be part of code not comment, delete the '//'
Try again as
DFRobot_SIM808 sim808(&mySerial);//Connect RX,TX,PWR,
It should work, since it is a cold start it might take time, if you had problem again correcting those comment lines into code, just swap the pins
You must use pins 7 and 8 of the Arduino as Tx and Rx. With the 3 and 2 you have selected it will not work for you.

Error on sending AT+CWJAP_DEF commands to ESP8266

I am trying to send AT commands to ESP8266 to get connected with internet with the Wifi.
When I am sending AT and AT+RST command on serial monitor then I am getting OK and ready response which seems perfect.
Then I am sending AT+CWLAP to get list of available wifi networks which is also executing correctly.
AT+CWLAP
+CWLAP:(3,"Moto",-42,"a4:70:d6:7a:fa:6c",1,25,0)
+CWLAP:(4,"PRANJAL",-95,"1c:a5:32:3d:f5:c4",1,-16,0)
+CWLAP:(2,"VIHAN",-94,"c8:3a:35:2f:1d:81",1,-21,0)
+CWLAP:(3,"Tenda",-93,"c8:3a:35:20:a9:b1",9,-4,0)
OK
Then I sent AT+CWMODE? which is also perfect.
AT+CWMODE?
+CWMODE:1
OK
Now I am trying to connect ESP8266 with above listed Wifi with this command, it is sending an ERROR on serial monitor.
AT+CWJAP_DEF="Moto","reset1234"
Error
⸮=IRe"Moto","reset1234"
ERROR
Can anyone suggest me what could be the reason of this issue ?
#include "SoftwareSerial.h"
SoftwareSerial esp8266(2, 3); // RX, TX
void setup()
{
Serial.begin(9600); // serial port used for debugging
esp8266.begin(9600); // your ESP's baud rate might be different
}
void loop()
{
if(esp8266.available()) // check if the ESP is sending a message
{
while(esp8266.available())
{
char c = esp8266.read(); // read the next character.
Serial.write(c); // writes data to the serial monitor
}
}
if(Serial.available())
{
delay(10); // wait to let all the input command in the serial buffer
// read the input command in a string
String cmd = "";
while(Serial.available())
{
cmd += (char)Serial.read();
}
// send to the esp8266
esp8266.println(cmd);
}
}
The current official AT command set seems to be documented on https://github.com/espressif/ESP8266_AT/wiki/AT_Description
http://espressif.com/sites/default/files/documentation/4a-esp8266_at_instruction_set_en.pdf
https://www.itead.cc/wiki/ESP8266_Serial_WIFI_Module#AT_Commands
If the module is to be configured as a client, i.e. to connect to an access point, the following AT commands have to be sent (11500 baud 8N1, CR-LF line termination):
AT+RST
AT+CWMODE=3 (1 is "Station" only (wifi client), 3 is mixed mode "Station and Access-Point", both should work)
AT+CWJAP="Moto","reset1234"
AT+CWJAP_CUR="Moto","reset1234" (temporary) or
AT+CWJAP_DEF="Moto","reset1234" (stored)
For reference, a "success story" (ESP8266 module with USB-UART, Software: HTerm, Access Point with WPA2 (both TKIP / CCMP tested)):
AT<\r><\r><\n><\r><\n>
OK<\r><\n>
AT+RST<\r><\r><\n><\r><\n>
OK<\r><\n>
<\r><\n>
ets Jan 8 2013,rst cause:2, boot mode:(3,6)<\r><\n>
<\r><\n>
load 0x40100000, len 1856, room 16 <\r><\n>
tail 0<\r><\n>
chksum 0x63<\r><\n>
load 0x3ffe8000, len 776, room 8 <\r><\n>
tail 0<\r><\n>
chksum 0x02<\r><\n>
load 0x3ffe8310, len 552, room 8 <\r><\n>
tail 0<\r><\n>
chksum 0x79<\r><\n>
csum 0x79<\r><\n>
<\r><\n>
2nd boot version : 1.5<\r><\n>
SPI Speed : 40MHz<\r><\n>
SPI Mode : DIO<\r><\n>
SPI Flash Size & Map: 32Mbit(512KB+512KB)<\r><\n>
jump to run user1 # 1000<\r><\n>
<\r><\n>
??r?d?l<18>?<31><\0><\f>?l`<3>??s?l?<28>?<19>?<4><4><4>$ <2>??r?$<4>??<27>?<4><4>ll`<3>r$?<18>?"<\0>????"<4>l?cs|<\f>?`?22???<27>BB<18>c??o??<18>NN?<16><2><\0><2>d$??<2>d??<\0>?<4>d??<\0>ll????d??l`<2>?<2>N?<\0>????"<4>d??<28>p<4><4><2><2>???"b<4>$<4>?"prlrl<\r><\n>
Ai-Thinker Technology Co. Ltd.<\r><\n>
<\r><\n>
ready<\r><\n>
WIFI DISCONNECT<\r><\n>
AT+CWMODE?<\r><\r><\n>+CWMODE:3<\r><\n>
<\r><\n>
OK<\r><\n>
AT+CWJAP_CUR="Moto","reset1234"<\r><\r><\n>
WIFI CONNECTED<\r><\n>
WIFI GOT IP<\r><\n>
<\r><\n>
OK<\r><\n>
AT+CIFSR<\r><\r><\n>+CIFSR:APIP,"0.0.0.0"<\r><\n>
+CIFSR:APMAC,"00:00:00:00:00:00"<\r><\n>
+CIFSR:STAIP,"0.0.0.0"<\r><\n>
+CIFSR:STAMAC,"00:00:00:00:00:00"<\r><\n>
<\r><\n>
OK<\r><\n>
AT+GMR<\r><\r><\n>AT version:1.1.0.0(May 11 2016 18:09:56)<\r><\n>
SDK version:1.5.4(baaeaebb)<\r><\n>
Ai-Thinker Technology Co. Ltd.<\r><\n>
Jun 13 2016 11:29:20<\r><\n>
OK<\r><\n>
This also works with mode=1.
Major rewrite.
Questions and ideas to test:
what is your module firmware version?
access point issues (e.g. MAC address restrictions)?
power supply good?
might there be any old configuration or other code running on the module?
what is the byte code of ⸮ in the error message - Is it two bytes 0x2E2E?
are you using the Arduino serial monitor for communication?
in contrast to my comment, maybe the arduino does have an influence (timing?). Try to rule this out by
doing the pass-through character-based instead of line-based, e.g.:
(end of list, no code possible otherwise:)
loop(){
if( esp8266.available() )
Serial.write(esp8266.read());
if( Serial.available() )
esp8266.write(Serial.read());
}
keeping the AVR in reset and connecting the ESP8266 serial lines directly to the USB-UART converter
Alright! I just tried to connect with different wifi and it got connected with it. It was some kinda issue with mobile hotspot.

Interfacing with SparkFun mpu-6050 with a Texas Instruments TM4C123G LaunchPad

I am trying to interface with the MPU-6050 as part of a robotics project using the Texas Instruments TM4C123G LaunchPad. I am uploading code onto this from Energia and am using the serial monitor to see the raw data output, however I am only receiving the following output when I upload it to the micro controller and run it:
Initialising I2C devices...
Here is the code that I am trying to run:
#include <Wire.h>
#include <I2Cdev.h>
#include <MPU6050.h>
MPU6050 accelgyro;
void Setup_MPU6050()
{
Wire.begin();
Serial.println("Initialising I2C devices...");
accelgyro.initialize();
Serial.println("Testing device connections...");
Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
}
void Update_MPU6050()
{
int16_t ax, ay, az;
int16_t gx, gy, gz;
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
Serial.print("i");Serial.print("\t");
Serial.print(ax);Serial.print("\t");
Serial.print(ay);Serial.print("\t");
Serial.print(az);Serial.print("\t");
Serial.print(gx);Serial.print("\t");
Serial.print(gy);Serial.print("\t");
Serial.println(gz);
Serial.print("\n");
}
void setup()
{
Serial.begin(115200);
Setup_MPU6050();
}
void loop()
{
Update_MPU6050();
}
The pins on the breakout board are connected to the Launchpad as follows:
VDD -> Pin 1 (3.3v)
GND -> Pin 12 (GND)
INT -> Pin 34 (PF0)
FSYNC -> None
SCL -> Pin 13 (PD0)
SDA - > Pin 14 (PD1)
VIO -> None
CLK -> None
ASCL -> None
ASDA -> None
I have got the MPU6050 and I2Cdev libraries from GitHub and have got the Wire library from github.com/codebendercc/arduino-library-files/blob/master/libraries/Wire/Wire.h but am thinking that either the wire.begin() or accelgyro.initialize() methods are not functioning properly? I am a relative beginner when it comes to programming in this language but I am undertaking an ambitious task to create a robot for a scholarship that I am applying for, and would therefore appreciate some assistance on this subject area.
I just met the same question as you. Here is a useful linkage:
enter link description here
I referred it and added some code before
Wire.begin()
--just like this
enter image description here
then I upload it and run, it works perfectly. And there is another thing to be minded that you can't connect INT pin when you don't use DMP but when you use DMP then you must connect INT pin.
I try to explain it.
Why should we add the two lines codes? The Library is from Arduino, although Energia is compatible with Arduino programming in most cases but not always. So we should explictly acclaim something.
And why should we pay attention the interruption. Because when we use DMP we use it, if we don't connect the INT pin, it willn't work normally.

Arduino builds fail with "Reset.h: No such file or directory"

When I'm trying to build what seems to be any code in the Arduino IDE, it fails with this error:
Arduino: 1.6.5 (Mac OS X), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/USBCore.cpp:19:19: fatal error: Reset.h: No such file or directory
#include "Reset.h"
^
compilation terminated.
Error compiling.
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
The code I'm trying to build is from https://www.arduino.cc/en/Tutorial/Fade:
/*
Fade
This example shows how to fade an LED on pin 9
using the analogWrite() function.
The analogWrite() function uses PWM, so if
you want to change the pin you're using, be
sure to use another PWM capable pin. On most
Arduino, the PWM pins are identified with
a "~" sign, like ~3, ~5, ~6, ~9, ~10 and ~11.
This example code is in the public domain.
*/
int led = 9; // the PWM pin the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
// the setup routine runs once when you press reset:
void setup() {
// declare pin 9 to be an output:
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// set the brightness of pin 9:
analogWrite(led, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
}
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
Why is this happening? I don't think I've changed any of the Arduino libraries, but wondering if that's the case now. A find in /Applications/Arduino.app/ lists no files called Reset.h, however, I did find a ~/Library/Arduino15/packages/arduino/hardware/sam/1.6.4/cores/arduino/Reset.h.
Building with Arduino IDE 1.6.5, using a Mega 2560 and /dev/cu.usbmodem1421.
It turns out my Android installation was modified, and the modified USBCore.cpp wasn't really correct for this version (1.6.5) of Arduino. Reinstalling fixed the problem.

Reading a text file off of an Arduino SD card through Ethernet Shield

I'm working on an Arduino Project and I've wrapped up the portion of connecting the sensors, collecting data for a week, and saving that data. My problem now is taking that data and putting on a website to graph. I have to send data over ethernet for the project so I figured I'll send the information from the text file on the SD card to my computer and go from there with it. The problem is I cannot open the text file and view it in serial monitor. Here is the code
/*
SD card read/write
This example shows how to read and write data to and from an SD card file
The circuit:
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4
created Nov 2010
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
*/
#include <SPI.h>
#include <SD.h>
File myFile;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
myFile = SD.open("test.txt", FILE_WRITE);
// if the file opened okay, write to it:
if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println("testing 1, 2, 3.");
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
// re-open the file for reading:
myFile = SD.open("test.txt");
if (myFile) {
Serial.println("test.txt:");
// read from the file until there's nothing else in it:
while (myFile.available()) {
Serial.write(myFile.read());
}
// close the file:
myFile.close();
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}
void loop() {
// nothing happens after setup
}
As you can see this is just the ReadWrite code from the example library. It works fine, it writes the data and reads it properly. The problem occurs when I modify it to use my sampledata.txt. It doesn't read it.
Here is an example of a few lines of sampledatatxt.
2015-11-25 12:16:10 758
2015-11-25 12:16:12 757
2015-11-25 12:16:14 757
2015-11-25 12:16:16 758
Am I missing some of the finer semantics of reading data? Is the data being read too large? It's around a 66MB file.
Any direction would be awesome!

Resources