This is what you need to do: Show us your code.I have two Teensy 4.0 microcontrollers. The digital and analog pins can be read and written,Code:
but the serial hardware and serial software are not working.
The programs I'm using, e.g., Tiny GPS, run perfectly on an Arduino Mega.
What am I doing wrong?
Arduino ExambelThis is what you need to do: Show us your code.
```cpp
/*
* TimeGPS.pde
* example code illustrating time synced from a GPS
*
*/
#include <TimeLib.h>
#include <TinyGPS.h> // http://arduiniana.org/libraries/TinyGPS/
//#include <SoftwareSerial.h>
// TinyGPS and SoftwareSerial libraries are the work of Mikal Hart
//SoftwareSerial SerialGPS = SoftwareSerial(10, 11); // receive on pin 10
TinyGPS gps;
// To use a hardware serial port, which is far more efficient than
// SoftwareSerial, uncomment this line and remove SoftwareSerial
#define SerialGPS Serial1
// Offset hours from gps time (UTC)
const int offset = 1; // Central European Time
//const int offset = -5; // Eastern Standard Time (USA)
//const int offset = -4; // Eastern Daylight Time (USA)
//const int offset = -8; // Pacific Standard Time (USA)
//const int offset = -7; // Pacific Daylight Time (USA)
// Ideally, it should be possible to learn the time zone
// based on the GPS position data. However, that would
// require a complex library, probably incorporating some
// sort of database using Eric Muller's time zone shape
// maps, at http://efele.net/maps/tz/
time_t prevDisplay = 0; // when the digital clock was displayed
void setup()
{
Serial.begin(9600);
while (!Serial) ; // Needed for Leonardo only
SerialGPS.begin(4800);
Serial.println("Waiting for GPS time ... ");
}
void loop()
{
while (SerialGPS.available()) {
if (gps.encode(SerialGPS.read())) { // process gps messages
// when TinyGPS reports new data...
unsigned long age;
int Year;
byte Month, Day, Hour, Minute, Second;
gps.crack_datetime(&Year, &Month, &Day, &Hour, &Minute, &Second, NULL, &age);
if (age < 500) {
// set the Time to the latest GPS reading
setTime(Hour, Minute, Second, Day, Month, Year);
adjustTime(offset * SECS_PER_HOUR);
}
}
}
if (timeStatus()!= timeNotSet) {
if (now() != prevDisplay) { //update the display only if the time has changed
prevDisplay = now();
digitalClockDisplay();
}
}
}
void digitalClockDisplay(){
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(" ");
Serial.print(day());
Serial.print(" ");
Serial.print(month());
Serial.print(" ");
Serial.print(year());
Serial.println();
}
void printDigits(int digits) {
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}
```
#define GPS_SERIAL Serial1
// Very basic sketch to monitor GPS data from GPS_SERIAL
void setup() {
GPS_SERIAL.begin(9600);
Serial.begin(9600);
}
void loop() {
// while there's data from the GPS, send it to the computer
while(GPS_SERIAL.available() > 0) {
Serial.write(GPS_SERIAL.read());
}
// while there's data from the computer, send it to the GPS
while(Serial.available() > 0) {
GPS_SERIAL.write(Serial.read());
}
}
$GPGGA,163847.000,52xx.5645,N,106xx.7871,W,1,9,0.90,513.5,M,-20.6,M,,*62
$GPGSA,A,3,04,29,09,26,03,31,07,16,11,,,,1.19,0.90,0.78*0E
$GPRMC,163847.000,A,52xx.5645,N,106.7871,W,0.19,350.12,171225,,,A*74
$GPVTG,350.12,T,,M,0.19,N,0.36,K,A*35
$PGTOP,11,3*6F
SerialGPS.begin(9600);