AGO GPS with Arduino Mega

Hello everybody,

im interessted in upgrading our Steyr 9094 with AGO GPS.
Caused of tramline control i am using an Arduino Mega already on our tractor.
Thats why i want to use this also for AGO GPS.

If i connect an Arduino Uno with the 4.3.10 Code to my PC, everythin works fine.
The same procedure with the Mega and i dont get a serial connection.
If cut the code to a minimum but it still doesnt work.

Does anyone have an idea?

Arduino Code:
bool isDataFound = false, isSettingFound = false, isMachineFound = false, isAogSettingsFound = false;
int header = 0, tempHeader = 0, temp;
void setup() {
Serial.begin(38400);
}
void loop() {
if (Serial.available() > 0 && !isDataFound && !isSettingFound && !isMachineFound && !isAogSettingsFound)
{
int temp = Serial.read();
header = tempHeader << 8 | temp;
tempHeader = temp;
if (header == 32766) isDataFound = true;
}
if (isDataFound == true)
{
isDataFound = false;
Serial.read();
Serial.read();
Serial.read();
Serial.read();
Serial.read();
Serial.read();
Serial.read();
Serial.read();
Serial.read();
Serial.read();
Serial.print(“127,253,”);
Serial.print(32325);
Serial.print(“,”);
Serial.print(0);
Serial.print(“,”);
Serial.print(“0,”);
Serial.print(“0,”);
Serial.print(7);
Serial.print(“,”);
Serial.print(0);
Serial.println(“,0,0”);
Serial.flush();
}
}

Does the minimized code work with the Uno?

Yes, with the minimized Code and the Arduino Uno i get back the data from serial.print in AGO GPS.The TX Led is flashing.
The Mega doesnt even send any data back (the TX Led stays off)
Both work with 16MHz. I changed the Baudrate a little bit wether if this the problem. I also tried another Arduino Mega, still the same.
I doesnt understand whtats the difference between the Mega and the Uno.

Can you get the basic blink sketch to work on the mega?

You mean the examples/basics/blink sktech?
Yes, it works :smiley:

I can’t see anything wrong. I successfully ran this on an Uno and Mega 2560. I added a pot on A0 and a switch on D3. The pot is reported for WAS, roll and PWM to AoG, D3 is workSwitch and steerAngleSetPoint is also sent back.

bool isDataFound = false, isSettingFound = false, isMachineFound = false, isAogSettingsFound = false;
int header = 0, tempHeader = 0, temp;
float steerAngleSetPoint;

void setup(){
  pinMode(3, INPUT_PULLUP);
  Serial.begin(38400);
  Serial.print("\r\nBooting");
}

void loop(){
  if (Serial.available() > 0 && !isDataFound && !isSettingFound && !isMachineFound && !isAogSettingsFound){
    int temp = Serial.read();
    header = tempHeader << 8 | temp;
    tempHeader = temp;
    if (header == 32766) isDataFound = true;
  }

  if (Serial.available() > 7 && isDataFound == true){
    isDataFound = false;
    Serial.read();  // unused, old section control byte
    Serial.read();  // gps speed * 4
    Serial.read();  // dist from line high byte
    Serial.read();  // dist from line low byte
    steerAngleSetPoint = ((float)(Serial.read() << 8 | Serial.read()))*0.01; // steer angle set point high/low bytes
    //Serial.read();  // steer angle set point high byte
    //Serial.read();  // steer angle set point low byte
    Serial.read();  // unused
    Serial.read();  // unused but should read 8 bytes (2 header bytes already read earlier)
    
    Serial.print("127,253,"); // header, num 0 & 1
    Serial.print((analogRead(A0) - 512) * 10);  // WAS, num 2
    Serial.print(",");
    Serial.print(steerAngleSetPoint * 100); // steer angle setpoint, num 3
    Serial.print(",");
    Serial.print("0");            // heading from BNO or 0, num 4
    Serial.print(",");
    Serial.print((analogRead(A0) - 512) / 3); // roll or 0, num 5
    Serial.print(",");
    Serial.print(digitalRead(3)); // switch byte, num 6
    Serial.print(",");
    Serial.print((analogRead(A0) - 512));    // pwm, num 7
    Serial.println(",0,0");       // num 8 & 9
    Serial.flush();
  }
}

Tried your Code but doesnt work on the Mega.
I’ve made a Video but its impossible to do someting wrong :sweat_smile:
https://youtu.be/5RGOUlsJkPo
What i alread tried:
-Another Arduino Mega
-Another USB cable
-reinstalling AGO GPS
-reinstalling Arduino IDE
-Changed the COM port of the Arduino in the Hardware Settings
-Changed the baudrate from 30000 to 48000 in stepps of 1000
-Tried all this things on my Laptop and PC

The last thing i trie now is to buy a new Mega. If this doesnt help i give up the project :sleepy:

Greetz
Skyliiine

I’m stumped. If you can run any other sketch on the mega then I just don’t know anymore.

Maybe use another computer to upload to the arduino? Long shot but it’s an odd issue. In follow this because I’m having some strange issues trying to alter the code to run on an esp32. Most my fault but some compiler difference related.

In the Arduino Mega spec they say to plug nothing on the 2 serial0 communication pin to have USB serial communication. it’s the only thing I could see.

I already tried another Laptop with Windows 7 and one with Windows 10 and my PC :sweat_smile:
For both uploading the Arduino Code and AGO GPS.

Its nothing connected to the Mega, just the USB cable.

Greetz
Skyliiine

Hi, I had a test and found the same fault.

I made a quick basic serial test program and the Mega cant handle the RX from AgOpen straight away it must setup serial connection first.

Connect the Mega to a TTL to USB adaptor and let them connect, then hit connect button in AgOpen to the TTL/USB. I think it will work.

Somehow you must be able to delay AgOpen sending data for a bit when connecting?

image

The code I shared with ran on my 2560 just fine using it’s built-in USB. I suspect every time I connected with AoG via the Mega’s built-in USB it rebooted the Mega and there were no problems.

I tried the code of elias with he TTL/USB adapter and finaly it is working.
Also the original code of AGO is working now with the adpter and the mega.

Thanks to all for your help :upside_down_face:

Greetz
Skyliiine

I have found the problem with mega.

After connecting via agopen in c# you need to wait one second before you send your first data…

Does

while(!Serial)

after Serial.begin help?

I tried that, didn’t help because it’s the data coming in on the RX from agopen too fast that causes the port problem. Without a delay from the agopen end, I think it just has to be done with the TTL/USB. Don’t know why

I don’t understand why the TTL adapter makes any difference. On my Arduinos the on board USB adapter works fine. Do you know which chip your on board and TTL adapter are?

There must be a difference in how the 2560 opens a serial port vs the 328? The USB chip doesn’t make any difference tried all 3 CH340, 16U2, FT232.

Are you connecting through usb hub? I have found my 2560 clones are finicky with how long the cables are and which hubs I use but that usually shows up already when programming. It’s the only cloned board I have had issues with.

It’s not the 328 or 2560 handling the USB. The other chips you mentioned convert the usb to TTL via IO 0 & 1. They also handle auto reset.