Menu

How to Program Arduino UNO R3 With GCBASIC

2015-01-28
2023-06-30
1 2 3 4 > >> (Page 1 of 4)
  • William Roth

    William Roth - 2015-01-28

    WAY OUT OF DATE = SEE MUCH LATER POSTS - see https://sourceforge.net/p/gcbasic/discussion/chipfileforum/thread/5e307aada6/

    INTRODUCTION:

    While most GCB users are likely to be using PIC Microcontrollers, GCB also supports many ATMEL Microcontrollers. If you happen to have an Arduino UNO you can easily use this board with Great Cow Basic. Below are the steps for setting up GCB@Syn to use the UNO R3.

    Note: Programming the UNO with GCB WILL NOT erase the bootloader on the microcontroller! This means that the UNO can still be programmed via the Arduino IDE.

    STEPS:
    
    1.  Download and install the latest GCB@Syn, if not already installed.
    
    2.  Run IDE.EXE from the GCB.SYN folder. This is the correct/normal way to start the IDE. 
    
    4.  Select the menu bar, then click on "Tools " then "External Tools" then "Edit AVR programmer batchfile"
    
    3.  Change the active line as follows:
    
         "AVRdude\avrdude.exe" -c arduino -P COM3 -b 115200 -p AT%2 -U flash:w:%1:i
    
        If your UNO R3 is on a com port other than COM3, then open Device Manager
        "Ports (COM&LPT)" and note which COM port the UNO R3 is on.  Then change the
        line above to  reflect the correct COM Port.
    
    5. Save and close the file.
    

    '

    That's all there is to it. You can now program an UNO R3 with Great Cow Basic. To test, load the following program in GCB@Syn and hex/flash the Arduino.

    ~~~~

    ; Blink_UNO_R3 routine for Great Cow BASIC
    ; Copyright (C) 2015 William Roth
    ;
    ; This library is free software; you can redistribute it and/or
    ; modify it under the terms of the GNU Lesser General Public
    ; License as published by the Free Software Foundation; either
    ; version 2.1 of the License, or (at your option) any later version.
    ; This library is distributed in the hope that it will be useful,
    ; but WITHOUT ANY WARRANTY; without even the implied warranty of
    ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    ; Lesser General Public License for more details.
    ;
    ; You should have received a copy of the GNU Lesser General Public
    ; License along with this library; if not, write to the Free Software
    ; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

    ; Set chip model for Arduino UNO R3:

    chip mega328p, 16

    ; Define LED

    define LED = PORTB.5

    ; Set pin direction
    dir portb.5 Out

    ; Blink LED every 1 second
    do forever 'Blink Yellow LED every second
    set LED ON
    wait 1 s
    set LED OFF
    wait 1 s
    loop
    ~~~~~

     

    Last edit: Anobium 2023-06-30
  • Erdy

    Erdy - 2015-01-31

    Hello,

    Previously, I used Xloader.exe to upload codes(.hex files) to my Pro Mini(chinese Arduino 328P, <2€). Now with your Avrdude.exe command line, it works directly from GCB, it's somewhat easier and faster.

    I modified the avrdude.exe command line with GCB@syn menu/tools/edit AVR programmer batchfile, I used the following command line :

    "AVRdude\avrdude.exe" -c arduino -P COM10 -b 57600 -p AT%2 -U flash:w:%1:i

    I played with 328P comparator, AD, interrupts, RS232, I2C, ... I got everything working rather easily. It's sometime necessary to look in the chipdata file mega328p.dat to get some information.

    Thank you,

    Erdy

    The 'Pro Mini' does not have an USB to Serial chip onboard, an external USB to serial module must be used, see : https://www.youtube.com/watch?v=Vawhrr4COjI

     

    Last edit: Erdy 2015-01-31
  • Steve McCauley

    Steve McCauley - 2015-08-09

    I downloaded and installed GCB@SYN this morning (8/8/2015). The download and installation went smoothly. Since my primary interest in GCB at this point is using it to program an Arduino UNO R3 I found that the process of making GCB communicate with the Arduino Uno R3 was not entirely intuitive. By using the information from the posts above and other source(s) on the internet I found a way to configure GCB to do this quite easily. Here is the process that worked for me.

    1. Open the GCB IDE
    2. Goto "Tools"
    3. Select "Edit AVR programmer batchfile"
    4. In the "Your code here" section of the batchfile you will see several lines with
      configuration information for various programmers. All of the lines except one will be "REM"arked
      out. Add a REM at the beginning of that line so that it will be ignored and then:
    5. Add the following lines in the "Your code here" section of the batch file
      Strictly speaking, only the AVRdude line is necessary, you could eliminate the REMark lines, but
      I did it as a reminder to myself for the future.
      Note: Ignore the underscore near the end of the line. I can't get rid of it in this post, just enter
      the characters as shown. Use the line in the previous post for reference.

    REM *********
    REM Add the line below to allow programming the Arduino UNO R3
    "AVRdude\avrdude.exe" -c arduino -P COM9 -b 115200 -p AT%2 -U flash:w:%1:i
    REM This batch file modified 8/8/2015 by Steve McCauley
    REM
    *********

    6.Be sure to change the COM9 in the line to match the port number that you are using and the
    baudrate if yours is different
    7. Use the standard "Blink" demo program to verify your ability to download to the Arduino UNO R3.

    I don't know if this is the correct or only way to do it, but everything seems to be working fine and it does not appear to interfere with the original Arduino programming environment if you still want to use it.

    Hopefully this saves someone some time.

     
  • Steve McCauley

    Steve McCauley - 2015-08-09

    Please ignore the reference to the underscore at the end of the "AVRdude line mentioned in my note above. It didn't show up in the posting. Not sure why it showed up during the composition phase before posting. Again, view the line in the second post for reference and change the com port and baudrate to
    match your requirements. Happy coding!!

     
  • Craig Gardner

    Craig Gardner - 2015-10-07

    I've programed an Uno with no problems but when I try to program a Leonardo I get the error

    flashAVR.bat

    avrdude.exe: stk500_getsync(): not in sync: resp=0x3f

    avrdude.exe done. Thank you.

    ERROR running: "C:\Users\Craig\Dropbox\GCB\GCB@Syn\G@Stools\flashAVR.bat" with parameters "C:\Users\Craig\Dropbox\GCB\GCB@Syn_MyFiles\Blink_mega32u4.hex" MEGA32U4

    Any idea of how to get this working?

     
  • Anobium

    Anobium - 2015-10-07

    Hello, try this following to determine the correct parameters.

    Use avrdudess.exe in your install to determine the correct comms parameters. Then, transfer those parameters to the flashAVR batch file.

     
  • Frank Steinberg

    Frank Steinberg - 2015-10-07

    After some "googleing" I think this may work (change COM9 to your needs):

    "AVRdude\avrdude.exe" -c avr109 -P COM9 -b 57600 -p AT%2 -U flash:w:%1:i
    

    while your GCB-Source must contain:

    #chip mega32u4, 16
    

    Please let us know, if this works for you so we can add it to the flashAVR.bat of the next GCB@Syn-Release.

    Regards
    Steini

     
  • Craig Gardner

    Craig Gardner - 2015-10-08

    That didn't work but I did find info and after some experimentation found this does work

    "AVRdude\avrdude.exe" -c -patmega32u4 -P COM4 -c avr109 -b 57600 -p AT%2 -U flash:w:%1:i

    The Arduino bootloader for the leanardo will install as one port in my case com3 and then when the board is reset it goes into bootloader mode for about 8 seconds and comes up as another com port in my case com4 at which point it will program. The Arduino software resets the board by opening the com port at 1200 baud and then closing it then it waits for the new port and programs on that port.

    Thank you for the help

     
  • Frank Steinberg

    Frank Steinberg - 2015-10-09

    Hi Craig!

    Thank you for testing.

    I've read, that the leonardo can be "kicked" into bootloader mode without pushing the reset button by opening the (normally activated) com port with 1200 baud by software. After that, another com port comes up as you described. This one normally is one count higher (COM3 -> COM4 in your case). So this may work for you without the need uf pushing the reset button:
    (The ping command ist only to have a delay of 200 mS, maybe you can delete it)

    "AVRdude\avrdude.exe" -c avr109 -P COM3 -b 1200 -n
    ping 1.1.1.1 -n 1 -w 200 >NUL
    "AVRdude\avrdude.exe" -c avr109 -P COM4 -b 57600 -p AT%2 -U flash:w:%1:i
    

    Please note: -patmega32u4 and -p AT%2 in your code does the same thing. You only need one. -patmega32u4 is o.k. because the chip of a leonardo ist allways an ATmega32u4.

    Regards
    Steini

     
  • Craig Gardner

    Craig Gardner - 2015-10-13

    That works once and then the module no longer shows up as a com port I can then press my reset button on the module and program it and it shows up again but when I next program it without resetting it with the button it starts all over again.

    BTW I found 2 other programs for loading hex files to Arduino and they have the same problem.

     

    Last edit: Craig Gardner 2015-10-13
    • Erdy

      Erdy - 2015-10-20

      Not sure this is an answer to your question ? New FTDI driver rejects clone chips.
      (search 'with FTDI driver issue')
      https://www.sparkfun.com/news/1629

      Erdy

       
  • William Roth

    William Roth - 2015-10-14

    Since the USB is incorporated into the ATmega32U4, anytime the chip is reset, the Virtual Port instance on the PC is lost. When the processor/bootloader restarts, the PC then has to detect and re-enumerate to create a new Virtual Com Port. Why it creates a different Virtual Com Port, I do not know, but suspect it is a "feature" of the Windows OS and how USB devices are enumerated.

    This creates a problem that the avr batch file and AVRDude may not be able to easily handle.

    When uploading a new "sketch", the Arduino software "knows" that a Leonardo is being used and after the sowtware reset it then waits for a new Virtual CDC port to appear before uploading the sketch to the newly created Virtual Port.

    We may be able to modify the batch file to add a delay as a workaround of sorts. I do not have a Leonado or Micro to play with at this time and other things are pressing.

    There are some notes at the link below that may be helpful.
    See the section titled "Uploading Code to the Leonardo and Micro"

    . https://www.arduino.cc/en/Guide/ArduinoLeonardoMicro

     
  • Hugh Considine

    Hugh Considine - 2015-10-14

    For anyone trying to program an Arduino Leonardo, a very small command line tool that I wrote when playing with an Arduino Robot a few years back may be of interest. It will wait for a new serial port to appear on the system, and then call avrdude with that port.

    Source is in SVN at http://sourceforge.net/p/gcbasic/code/HEAD/tree/utils/ArduinoRobotLoader/ and a binary is at http://gcbasic.sourceforge.net/temp/ArduinoRobotLoader.exe. Download the binary, put it in the same directory as avrdude.exe, and you should be able to call it from a batch file with just the filename as a parameter. If the device is currently enumerated, you can also supply the port with /P:COM2 (for example) and it will open COM2 at 1200 baud, then close it and wait for a new port to appear, before programming on that one.

     
    • Anobium

      Anobium - 2015-10-14

      @Hugh. I will move the program into the Great Cow Basic release with a nice covering note. As I think we should not loose this good information and the application.

       
  • Chuck Hellebuyck

    I tried to program a Arduino Pro Mini.
    I modified the AVRflash.bat file to remove the REM from the programming line for the Pro Mini.
    I changed the COM port to match my setup.
    It communicates but tells me this:

    avrdude.exe: AVR device initialized and ready to accept instructions

    Reading | ################################################## | 100% 0.00s

    avrdude.exe: Device signature = 0x1e950f
    avrdude.exe: Expected signature for ATmega168 is 1E 94 06
    Double check chip, or use -F to override this check.

    avrdude.exe done. Thank you.

    I tried to add the -F to the command line but I got the same results.
    Any help would be appreciated.
    I'm a PIC user so this is somewhat new to me.

     
    • Anobium

      Anobium - 2016-03-30

      Using AVRDude can you make this work? If you can then the parameters will be shown that you have to use in the batch file.

       
      • Chuck Hellebuyck

        This was using AVRdude and the settings in the batch file for the mini pro. For some reason the device signature doesn't match.

         
        • Anobium

          Anobium - 2016-03-30

          Use the presets in AVRDUDE. Do they work? If so, transfer these to the batch file.

           
          • Chuck Hellebuyck

            Sorry, I'm not sure where to find that. I was able to add the -F at the beginning of the command line in the batch file and that seemed to fix it. I was able to program and flash the onboard LED.

             
  • kent_twt4

    kent_twt4 - 2016-03-30

    I have an UNO R3 and it is an ATmega328. Sorry, no help with avrdude, as I use an AVRisp MKII programmer.

     
  • William Roth

    William Roth - 2016-06-01

    The Arduino Pro Mini was originally based upon ATMega168 with dev signature of 1E 94 06. But at some point Pro Mini changed to using ATMega328P.

    When queried by AVRDude the AVR chip on the Pro Mini in question is returning the device signature for a 328P. (1E 95 0F)

    What does the chip label say? If it says 168 then it is mislabeled ( Could be a knockoff ?)

    Try configuring both GCB source code and FlashAVR.bat where the chip is a 328P and see what happens.

    Bill

     
  • jose moreno

    jose moreno - 2018-06-11

    This work for me, i'm using an Arduino Uno Clone, and the GCB version "0.98.02 2018-05-10"

    You Just need to find the flashAVR.bat file on the following location:

    C:\GCB@Syn\G+Stools\flashAVR.bat

    Then edit the .bat file with Notepad++ or any other tool and look for the following line

    REM Call AVRdude for Arduino_Uno bootloader:
    REM You will have to confirm the com (communications) port - currently set for com6
    "AVRdude\avrdude.exe" -c Arduino -P Com9 -b 115200 -p AT%2 -U flash:w:%1:i
    just remove the rem text on this line and select your Com port

    After that you will see the following output message

     

    Last edit: jose moreno 2018-06-11
  • Keith

    Keith - 2022-09-11

    Hello again William, I have eventually bit the bullet and I am trying to code up an Arduino Uno with a Atmega328 processor to drive my mini Surface Grinder. Basically it is a CNC Mill with a high speed X axis table.
    I want to use the Uno as it fits the bill in price with both the CPU board, keypad and display for less than a tenner. It has more input and output ports than you shake a stick at. it is fast enough to drive the 3 stepper motor drivers on the machine.
    So I started to prowl around for some code to get me started on but frankly the Arduino coding turns my clay cold, then I remembered seeing a post about using Atmega328 on GCB - now you are talking my language.
    Great stuff, easy peasy I thought - Like Not !
    I started reading your post from the top about persuading the GCB@Syn IDE to talk to the Atmega328 and that's when it all went South.
    There must have been some changes to GCB@Syn IDE since you wrote this up seven years ago. I cannot find the 'Tools' or External Tools' you mention ?
    Do you know of any Demo Code examples which will get me started on my project?

     

    Last edit: Keith 2022-09-11
  • Anobium

    Anobium - 2022-09-11

    This post is way out of date - we dont edit batch files any more.

    Let me post a YouTube video tomorrow - they only take a few minutes to create. I will explain the changes,

     
  • Keith

    Keith - 2022-09-11

    Thank you Evan.

     
1 2 3 4 > >> (Page 1 of 4)

Log in to post a comment.