Machine control USB using a mega2560

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)

Htem-screenshot

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!

SerialComm.Designer.cs
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
    OR
    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!

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

1 Like

Hello again.
@alexlan
One furher update/bugfix V3.3 of the arduino Code can be found on AgOpenGPS/AGOpenGpsMachineUSB_4.2.02_16pins_V3.3.ino at copy_of_v4201 · hagre/AgOpenGPS · GitHub

(I fixed some troubles with the timed loops. Buffer overflow/wrong starting sequenz until first intervall is finished.)

thanks @hagre for all your time i this, and sorry for a long time no response.
My regular mega’s don’t work with V3.3 and AOGv4.3.1 or v4.2
Do I have to cut on the board on the reset pin like you said earlier to make it work or
do I forget something?
Maybe better, I buy a mini mega and we are all happy :stuck_out_tongue:

@alexlan i have initialy got good resaults with the mini mega board, but suddenly i had the same connection problems again.

During trying to debug the AOG i found that it is enough to have a 1 second delay during the inizialistion of the seriel/usb connection. The reason for that is (my guess) that the mega needs a litle bit more time to boot, pull the nessesary pin down to gnd (connection to the serial chip) and establish a good serial/usb connection, otherwise it freezes AOG and or the mega. I made a pull request on github (the changed/corrected code is waiting to be insertet by the admin), but is not included by now. Make it possible to connect to MEGA2560 and include new MachineUSB_4310_MEGA16pins_V3.5.ino by hagre · Pull Request #164 · farmerbriantee/AgOpenGPS · GitHub We will see. …
If you are able to compile your own version of AOG you can use my repository as a source. GitHub - hagre/AgOpenGPS: Ag Precision Mapping, Section Control and Guidance Software
If you need help with the compiling, i can send you a updated copy of the latest released (and still a little bit bugy) version of AOG.

I discovert by surprise that connecting an external serial to usb converter on the TX and RX Pins and GND is solving the Problem as well (guess: due to one of the resistors pulling down to GND). maby just one more resiston can doo the job (have not tested jet)

Cutting the connection line at the “RESET-EN” position is not completly solving the problem, because the mega is not booting any more when a new usb connection is established (what is in general a nice feature to reset the arduino board for a clean start/boot).

As written in my last post use my latest arduino code https://github.com/hagre/AgOpenGPS/blob/my_Master/ArduinoCode/Machine_USB_4310/MachineUSB_4310_MEGA16pins_hagreV3.4.ino i have done a lot of debuging from the previous uploads.

Never the less, the mini mega is a cool board in a fantastic form factor.

best regards

Update:
First try of implementing 16 SectionSwitches if you are using Mega2560. ToDo - MAN switch (ON/AUTO/OFF) AgOpenGPS/MachineUSB_4310_MEGA16pins_IN_OUT_hagreV3.5.ino at my_Master-old_v4 · hagre/AgOpenGPS · GitHub

Sorry for the delay, been seeding and harvesting like crazy. Cool INO for the mega. Is there anything you need from AOG changed?

@BrianTee_Admin thanks for the nice anser. No problem. Seeding is much more important than software bugs!

As discribed in pull request Make it possible to connect to MEGA2560 and include new MachineUSB_4310_MEGA16pins_V3.5.ino by hagre · Pull Request #164 · farmerbriantee/AgOpenGPS · GitHub
There are just two lines of code to be inserted in GPS/Forms/SerialComm.Designer.cs line 502and 503.

//short delay for the use of mega2560, it is working in debugmode with breakpoint
System.Threading.Thread.Sleep(1000); // 500 was not enough

And i am still working to improve the .ino:
+Add Auto/Man/Main Switch
+upgrade with i2c port extender for input and output

ok i will add those, it’ll hold up the gui, but people can wait 1 second i am sure lol.

I’ll just remove the pull request - but know it will be in in the future code. Every time a github action is made always a risk something goes horribly wrong with winforms.