I am trying to learn how to use this module on a UNO R4 Minima [connected by SPI].
Looking at the Example1_Basics.ino for this module, what does this line do?
#define SERIAL_PORT Serial
Why not just use Serial.print commands?
Sorry but I need to understand because I keep having problems when I try to add an I2C OpenLog SD module.
Thanks in advance
Johnny
On many Arduinos, there is more than one serial port, with names like Serial1, and the above preprocessor command allows an easy way to switch between them.
What is the actual problem?
As far as I can tell the UNO R4 Minima only has one serial port.
The 20948 example code uses
#define SERIAL_PORT Serial
and
SERIAL_PORT.begin(115200);
and
SERIAL_PORT.print(F("Initialization of the sensor returned: "));
etc.
[I am still not sure why the need to create a SERIAL_PORT object. Is this just to make it easier on boards that have multiple serial ports?].
When I try to merge another example, currently the RTC example [on I2C], it uses:
Serial.begin(115200);
Should I just change all the Serial.print to SERIAL_PORT.print, and rely on the 20948 SERIAL_PORT.begin for both the 20948 and RTC?
I am also unclear if any of the above affects the I2C being used for the RTC, or is that all handled separately in the #include<Wire.h> and Wire.begin() ?
Thanks in advance
Johnny
I still don’t understand the problem. Please post evidence (like an error message) that there is, in fact, a problem.
The #define directs the preprocessor to replace of all instances of the character string SERIAL_PORT with Serial, before the code is sent to the compiler.
So in all cases, the compiler sees Serial.begin(), Serial.print(), and never sees SERIAL_PORT.
Thank you. I understand this a bit better now having looked up the term “preprocessor” and how it would replace all those per the #define.
I was getting a lot of these errors:
“Failed to retrieve language identifiers, error get_status: LIBUSB_ERROR_TIMEOUT, failed uploading: uploading error: exit status 74.”
“Port monitor error: command ‘open’ failed: serial port busy. Could not connect to COM6 serial port.”
“No monitor available for the port protocol dfu. could not connect to 1-4 dfu port.”
Earlier I was trying to also use the I2C GPS module [which seems to have its own issues] so seeing all those “serial-ish” errors I figured I better understand what SERIAL_PORT etc was doing when I merged the example codes. This line in Example 1 was leading me to think it was taking control of the I2C bus and preventing the other I2C modules from communicating:
myGNSS.setI2COutput(COM_TYPE_UBX | COM_TYPE_NMEA); //Set the I2C port to output both NMEA and UBX messages
I’ve actually got my UNO R4 Minima + Accelerometer IMU-20948 [SPI] + RTC DS 3231 [I2C] + SD card OpenLog 15164 [QWIIC] breadboarded and my code essentially working. The SD card module connections seem a bit flaky as the power LED will only light if I wiggle the wires going to the breadboard. This breadboard seems to be unreliable and I have ordered a shield to solder these connections.
Thanks again for your help. I am new to Arduino.
Johnny