# Machine control USB using a mega2560

**URL:** <https://discourse.agopengps.com/t/machine-control-usb-using-a-mega2560/1684>\
**Category:** Hardware\
**Created:** [13 April 2020 13:27 UTC](https://discourse.agopengps.com/t/machine-control-usb-using-a-mega2560/1684 "2020-04-13T13:27:38Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![hagre](https://discourse.agopengps.com/letter_avatar_proxy/v4/letter/h/9dc877/32.png) [@hagre](https://discourse.agopengps.com/u/hagre)\
**Post date:** [1 May 2020 20:03 UTC](https://discourse.agopengps.com/t/machine-control-usb-using-a-mega2560/1684/21 "2020-05-01T20:03:35Z")

</div>

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](https://github.com/hagre/AgOpenGPS/blob/copy_of_v4201/ArduinoCode/Machine_USB_4201/AGOpenGpsMachineUSB_4.2.02_16pins_V3.3.ino)

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

---

<div class="post-metadata">

**Author:** ![alexlan](https://discourse.agopengps.com/letter_avatar_proxy/v4/letter/a/848f3c/32.png) [@alexlan](https://discourse.agopengps.com/u/alexlan)\
**Post date:** [10 May 2020 14:41 UTC](https://discourse.agopengps.com/t/machine-control-usb-using-a-mega2560/1684/22 "2020-05-10T14:41:53Z")

</div>

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 😛

---

<div class="post-metadata">

**Author:** ![hagre](https://discourse.agopengps.com/letter_avatar_proxy/v4/letter/h/9dc877/32.png) [@hagre](https://discourse.agopengps.com/u/hagre)\
**Post date:** [10 May 2020 19:01 UTC](https://discourse.agopengps.com/t/machine-control-usb-using-a-mega2560/1684/23 "2020-05-10T19:01:35Z")

</div>

@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](https://github.com/farmerbriantee/AgOpenGPS/pull/164) 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](https://github.com/hagre/AgOpenGPS)  
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](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

---

<div class="post-metadata">

**Author:** ![hagre](https://discourse.agopengps.com/letter_avatar_proxy/v4/letter/h/9dc877/32.png) [@hagre](https://discourse.agopengps.com/u/hagre)\
**Post date:** [19 May 2020 21:39 UTC](https://discourse.agopengps.com/t/machine-control-usb-using-a-mega2560/1684/24 "2020-05-19T21:39:34Z")

</div>

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](https://github.com/hagre/AgOpenGPS/blob/my_Master/ArduinoCode/Machine_USB_4310/MachineUSB_4310_MEGA16pins_IN_OUT_hagreV3.5.ino)

---

<div class="post-metadata">

**Author:** ![BrianTee\_Admin](https://discourse.agopengps.com/user_avatar/discourse.agopengps.com/briantee_admin/32/7_2.png) [@BrianTee\_Admin](https://discourse.agopengps.com/u/BrianTee_Admin)\
**Post date:** [21 May 2020 23:34 UTC](https://discourse.agopengps.com/t/machine-control-usb-using-a-mega2560/1684/25 "2020-05-21T23:34:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hagre](https://discourse.agopengps.com/letter_avatar_proxy/v4/letter/h/9dc877/32.png) [@hagre](https://discourse.agopengps.com/u/hagre)\
**Post date:** [22 May 2020 09:26 UTC](https://discourse.agopengps.com/t/machine-control-usb-using-a-mega2560/1684/26 "2020-05-22T09:26:48Z")

</div>

@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](https://github.com/farmerbriantee/AgOpenGPS/pull/164)  
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

---

<div class="post-metadata">

**Author:** ![BrianTee\_Admin](https://discourse.agopengps.com/user_avatar/discourse.agopengps.com/briantee_admin/32/7_2.png) [@BrianTee\_Admin](https://discourse.agopengps.com/u/BrianTee_Admin)\
**Post date:** [22 May 2020 18:18 UTC](https://discourse.agopengps.com/t/machine-control-usb-using-a-mega2560/1684/27 "2020-05-22T18:18:56Z")

</div>

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.

[Previous page](https://discourse.agopengps.com/t/machine-control-usb-using-a-mega2560/1684.md?page=1)
