Machine control USB using a mega2560

hi all,
I have noticed that machine control on a mega does not work. I changed the ports names to the mega controller like PORTD 5 is pin 5 on nano and PORTB 0 is pin22 on mega right?
It seems when I connect the mega it does not want to communicate to AOG,
appart changing the ports I did not changed something else.
I used the latest files v4.1.12

I looked further in to it. I tried te autosteerusb sketch on mega and connect it to aog, it can connect but the board just freeze only the receive led blinks.
it is a blank mega without any pin connected.
its like aog dont like arduino mega boards or visaversa :stuck_out_tongue:

I would use a mega to have more pins for turning led on and off and use some switches for the uturn signal. just for ease.
or it can be better to send hydrauliclift byte also through the autosteer port. I can change code to send those byte with i2c to my mega witch is better only one usb to my pc :slight_smile:
thanks .

IT should work, aren’t the lower Digital pins the same on nano and mega?

No they are not but its not even the ports it is just communicating with aog that freeze it. I removed al te output code like bitset and digitalwrite, only communication code stays in and it does the same, it freezes.
Maybe the mega can not take the uart of aog fast enough. I don’t know.

IT really really should though. I have a MEGA, i can try and see what happens.

Yes it should work and I see not why it doesn’t. Or maybe a eeprom thing?
But anyway if I have the hydraulic lift and u turn via autosteer Im also happy :stuck_out_tongue:
Actually could you make a video to show how to change some code in AOG, in the old version I could change some, but now with the .exe application I dont know how to debug and start the program. it gives me… when clikking the start button
Erreur Impossible de traiter le fichier Forms\FormGPS.resx car il se trouve dans la zone Internet ou Restreinte ou il contient Mark of the Web. Pour traiter ces fichiers, supprimez Mark of the Web. AgOpenGPS 1
thanks for your time.

I just found the problem frezzing the MEGA2560:
if you change the line 84 to →
unsigned long time = currentTime;
the Mega2560 is not freezing any more (you still need to adapt the correct ports/pins (PORTB,…) or use digitalWrite() to make it more easy

Thanks for your time but it is still the same and its no port problem or digitalwrite because I just delete that part.
In the Serialmonitor it shows what it should, but when connecting to AOG it still freezes.

Can you post the code?

Machine_USB_forMega.ino (7,3 Ko)
I just change unsigned long and the digitalWrite().

I have reduced the arduino code to a minimum, but it is still working different with NANO/UNO or MEGA2560.

Compiled with Arduino IDE 1.8.10 on Win10.

Machine_USB_forMega_minimal.ino (693 Bytes)

The indication in AgOpernGPS Beta4.2.01 is for the
UNO/NANO: 127,248,0,0,0,0,0,0,0,0
MEGA2560: ** Machine Module Not Connected
the Serial Led is Flashing on the boards, and the Output is exactly the same (checked with Hterm 0.8.1)


If you try to repoduce this, use the MEGA first. After the UNO was found, the text in the box stays the same until a complete restart of the program.

The only difference i have discovert is the WindowsDriver
USB\VID_2341&PID_0042.… for MEGA
USB\VID_2341&PID_0043.… for UNO

I found an additional bug, maybe you can help me?
If i disconnect the arduino bord from the USB port during it is connected in the software, AgOpenGPS freezes forever, even after reset/reboot/… .I have to copy the complete program to a new folder (with a new name) to recover the software. I tryed to delete AG folder in documents, deleted all found regedit points. ???

I tried it to and AOG froze also for ever :frowning:, it was when I connected the mega first and then run AOG V4112, it connected automatically, I couldn’t even see the program.
The code you send works just fine, so its somewhere in between :stuck_out_tongue: .

hello again!

Now i think i found the problem/bug in AgOpenGPS software!

Line 519 have to be disabled to work witch my MEGA2560
(//spMachine.DtrEnable = true;)
I think the implementation (if there is any) of the DTR pin on the MEGA is not done.

But now i managed to freeze it again (even in the debugging run of VS2019).
If you had an usb device connected in the last session, the next time during boot it will be reconnected. This is the point in time to freeze, if the old comport or connection is not safely disconned befor shutdown.

Tommorow i will continue to find out more about this problem. Maybe we get some help by @BrianTee_Admin :pray:

Sounds like the total freeze there was many versions ago when trying to connect gps device to wrong USB port. Remember that the solution was to delete one file where the last settings were hidden. Must be on computer to find it again somewhere on combine forum.

Thank you @Larsvest for the hint with the forum and the settingsfile. I have now found the file(s) under C:\Users<USERNAME>\AppData\Local\AgOpenGPS. (Windows10)
After removing the files it is up and running again!
Saves me a lot of time. :relaxed:

What i found out so far:

The communication and indication of the received serial data in AgOpernGPS depends on the implementation of the serial to usb chip (typ of com-chip and schematics on the different arduino boards and clones).
I have used
UNO/NANO: with CH340G everything is fine ->127,248,0,0,0,0,0,0,0,0
ESP8266 - MX DevKit: with CH340 everything is fine ->127,248,0,0,0,0,0,0,0,0
ESP32 - NodeMCU - ESP32S: with C2102 everything is fine ->127,248,0,0,0,0,0,0,0,0
Due on programming port: (NO EEPROM!) with 16u2 everything is fine ->127,248,0,0,0,0,0,0,0,0
Due on native usb port: avoid!!! complete freeze of all
MEGA2560: (clone) with 32u2 resulting in problems and freezes ->** Machine Module Not Connected
Solving posibilities:

  • find and use working orginal/clone with a differnet serial chip (other then 32u2), or maybe update firmware on chip
  • cut the connection line at the “RESET-EN” position
    disable Line 519 in SerialComm.Designer.cs //spMachine.DtrEnable = true;
    both resulting in NOT reseting the board when connection is established

I think it have to do somthing with the timing of the reset via the USB - DTR pin. Normaly it is working perfect with arduino IDE,… during programming, but not completly wich the serial port implementation in VS2019/AgOpenGPS

After receiving different MEGA2560 board, i will continue to dig deeper in it.

That is very odd that mega would do that! I will have to see if i have one and test quick like you did - justy load and see what happens

Update: :grin:
I have now tried some versions of MEGA2560, but the DTR reset-circuit made troubles.
I discovert by surprise that connecting an external serial to usb converter on the TX and RX Pins and GND is solving the Problem due to one of the resistors pulling down to GND. I have not invastigated the exact reason. Finaly i found a special version i had in stock with a CH340G chip. It is very smal (about 2xnano) with all pins avaliable. All i tested now works out perfectly.

mini mega_smal

Ebay Link: mini Mega

That’s a really cool form factor!

Update: check this posting - all my MEGA2560 board are now working

1 Like