Sketch runs on Duemilanove but not Nano Every

The code compiles and uploads okay on both boards. I've double-checked the wiring. I found some other threads where people were having a similar problem going from Unos to Nano Everys. Like me, they were trying to interface with a GPS module. One solved the problem by not using SoftwareSerial, but that isn't an option for me. A reply on another thread said the current is very limited on the 3.3 V pin on some clones, but mine is the real deal. The module I am interfacing with draws 45 mA, by the way. Any thoughts?

My first thought is "what sketch is he/she talking about ?" and my second thought is "I wonder what the schematic of the project looks like ?"

Have you got the hint ?

Using MegaCoreX The NanoEvery has 3 hardware serial ports available as well as the usb serial.

Can you use D0/D1 or D2/D7 or D6/D3

//pins are defined in megacoreX core files pins.h varients
//#define TX1 D0
//#define RX1 D1

//#define RX2 D2 PIN_PA0
//#define TX2 D7 PIN_PA1

//#define PIN_HWSERIAL3_TX    D6 PIN_PF4
//#define PIN_HWSERIAL3_RX    D3 PIN_PF5
1 Like

Thank you. I will give that a try.

Cattledog, I couldn't figure out MegaCoreX, but I found some other posts about enabling the other serial ports, including one from you back in January (Arduino Nano Every SoftwareSerial Issues - #9 by cattledog). I copied and pasted your code into arduino_pins.h. But the output device is still not receiving from the Nano. I am using an inverter gate on the output to make the logic compatible with NMEA 0183 (in my tests with the Duemilanove, I used SoftwareSerial with the inverse flag set and that worked fine).

Is there a problem with running two ports at different baud rates?

//#include <SoftwareSerial.h>

// Define baud rates for the serial ports

int GPSBaud = 9600; // default for the YIC module
int VHFBaud = 4800; // NMEA std for radio input

// Define parameters for reading/writing text strings

const byte numChars = 80;
char receivedChars[numChars];   // an array to store the received data
boolean newData = false;
char crlfstr[] = "\r\n";


void setup() 
{
  
  // Start the Arduino hardware serial port at 9600 baud
  
  Serial.begin(9600);

  // Start the I/O serial ports 
  
  Serial1.begin(GPSBaud);
  Serial2.begin(VHFBaud);   // Modified file C:\Users\...\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.7\variants\nona4809\pins_arduino.h
                            // to make pin D7 Rx and pin D2 Tx

}

// Text string processing functions
// From tutorial https://forum.arduino.cc/t/serial-input-basics-updated/382007

void recvWithEndMarker() 
{
    // Variable definitions
    
    static byte ndx = 0;
    char endMarker = '\n';
    char rc;

    // Read text string if buffer is not empty and hasn't been read before
    
    while ( Serial1.available() > 0 && newData == false ) 
    {
        // Read characters until the end marker is reached
        
        rc = Serial1.read();

        if ( rc != endMarker ) 
        {
            receivedChars[ndx] = rc;

            // Overrun prevention
            
            ndx++;
            if ( ndx >= numChars ) 
            {
                ndx = numChars - 1;
            }
        }
        else 
        {
            receivedChars[ndx] = '\0'; // terminate the string
            ndx = 0;
            newData = true;
        }
    }
}

void showNewData() 
{

  // Define character string to identify which NMEA sentence is for position
  
  char posstr[] = "$GNGGA";

  // Check for position message
  
  char *ptr = strstr( receivedChars, posstr );
   
  if ( strlen(ptr) > 1 )
  { 
    // Replace 'N' with 'P'
    
    ptr[2] = 'P';
    
    /********** APPEND CR-LF *****************/
    strcat( ptr, crlfstr );     
    
    Serial.print( ptr );   // Check for correct output string in Serial Monitor  

    // Write to output device
        
    Serial2.write( ptr );

  }
  newData = false;
  *ptr = '\0';

}

void loop() 
{

  // Check for new message
  
  recvWithEndMarker();

  // Write to output if there is a new message
  
  if ( newData ) 
  {
    showNewData();
  }

}

image

Why have you got a 220 Ohm resistor and a capacitor in the serial connection from the GPS receiver to the Nano Every?

Can you get a scope on the Rx line of the VHF?

If Serial2 with the inverter is not sending correctly to the VHF, I see that a software serial library is indeed available on the megaavr core. Have your tried that with the inverted = true?

The datasheet for the GPS module has a schematic for an example "application circuit" with them. I don't know exactly why they are there, but the Nano is receiving from the GPS just fine.

I started out using SoftwareSerial, but it wasn't working. I saw some other posts where other people had problems with it on the Nano Every. I also saw that on the N.E. it does not support a baud rate of 4800, which is an absolute must.

I couldn't figure out MegaCoreX

Please explain your issues with MegaCoreX. It has several useful features that the megaavr core does not have, and it is better maintained. If you are going to work with a Nano Every, I strongly recommend that you use MegaCoreX.

I'm not clear why the revisions to the avr core suggested in the linked thread did not produce output on Serial2. Have you tried a simple loop back test on the Every between Serial1 and Serial2 after you made the changes? As an alternative, It may be easier to take serial tx/rx from another Arduino and feed it to Serial2 for a test. Remember to cross tx>rx and rx>tx.

EDIT: Your schematic shows grounds from every device. Are they all connected?

RE: MegaCoreX - It's not clear how to actually use it. There isn't much documentation. It also appears you need to use a UPDI programming interface.

RE: ground - Yes, all connected through a ground rail on the proto-board.

I assume that when you edit the header file, that gets compiled when you compile the sketch. Or is there something else I need to do?

There is no programmer required for the nano every. You select the 4809 board with the Nano Every pin out, no bootloader, and press download.

There is extensive documentation with the Read Me here
https://github.com/MCUdude/MegaCoreX/tree/master

I will be happy to answer any questions you have.

Did you actually install MegaCoreX following this procedure
https://github.com/MCUdude/MegaCoreX/tree/master#how-to-install

I assume that when you edit the header file, that gets compiled when you compile the sketch

Yes. Did you save the changes and confirm that the file was indeed modified.

Ok, thank you. Looks odd to me but if it's working then nothing to be concerned about. I'll leave it alone.

+1 for using MegacoreX, it's excellent and worth learning. I don't understand your comments about documentation, it's well documented.

Yes, the changes to the header file were saved.

As a test, I disconnected the GPS module, created sample messages, and sent them out with the VHF connected to the Serial1 Tx pin. That worked fine.

Yes, I installed MegaCoreX as in the directions. The documentation does not say exactly how you invoke MegaCoreX, but I see it under Tools>Boards Manager (which seems odd, since it isn't a board). I selected "ATmega4809", and "Nano Every" for the pinout. The sketch compiles and uploads okay, but the output is still not being received by the VHF connected to D2.

created sample messages, and sent them out with the VHF connected to the Serial1 Tx pin. That worked fine.

That's good. It means the inverter and the hardware connection is correct,

the output is still not being received by the VHF connected to D2.

Perhaps D2 on your board has been damaged. Since you are now using MegaCoreX, you can try to send to the VHF on D6 which is the Tx pin for Serial3. Try to switch from using Serial2 to using Serial3 and from D2 to D6 as the Every Tx pin.

That helped. I switched the output to D6, and the sample messages were getting through. However, when I use the actual message from the GPS module, the VHF does not read it. I am printing out the GPS module message in the Serial Monitor, so I copied that and made a new sample message. The VHF will not read that either. Strange. The VHF is an older model, so maybe there is something in the formatting it doesn't understand.

char TXstr1[80] = "$GPGGA,232418.41,3722.6133,N,12203.4880,W,1,04,4.8,00038,M,,,,*3E";  // Works
char TXstr2[80] = "$GPGGA,011957.086,3722.6528,N,12203.5074,W,0,3,,97.2,M,-25.7,M,,*51"; // Does not work

I got the first string from an old GPS receiver that I can interface with my computer and interfaces just fine with the VHF directly through a serial cable.

Have you tried leaving it along alone, not inverting?

Great news. :grinning: It sounds like the Hardware Serial issues on the Nano Every are resolved.

when I use the actual message from the GPS module, the VHF does not read it

Can you provide the documentation on the VHF module.

Can you see any difference in length between the messages which are OK and those which are not OK?

How do you know it is not reading the incoming message, as opposed to not sending it back out? What is reading the messages sent by the VHF?

When you say that the sketch ran on the Duemilanove with software serial did you see any of these issues with sentences not being read by the VHF?

Not inverting doesn't work. I found that out when I was using the Duemilanove.