Wellys Dev

  • Home
  • Search/Topics
  • Writings
  • About
  • 2022-07-23
    Developing in C for the ATmega328P: Edit

    Where I describe the process of developing code for the Arduino Uno(AVR ATmega328P), specifically, editing the code.

    Keyboard Commands Cheatsheet (in all applications)

    Description Windows Keys macOS Keys
    Copy selection Ctrl - c Cmd - c
    Paste clipboard Ctrl - v Cmd - v
    Select all Ctrl - a Cmd - a

    VS Code Keyboard Commands Cheatsheet

    Description Windows Keys macOS Keys
    Tool Palette Ctrl-Shift-p Cmd-Shift-p
    Build Task Ctrl-Shift-b Cmd-Shift-b

    Terminal Commands Cheatsheet

    Description Command/key Comments
    Change directories cd Use to change folders
    Expand current text to a folder name Tab Type first few letters then hit Tab
    Present working directory pwd What folder are you in?
    List contents of directory ls Show what is in the folder
    List folder in tree format tree Show what is in the folder
    Previous command Up arrow display previous command
    Open serial monitor tio [ acm | usb ] Pick one of the two options based on your controller board serial port

    Setup Raspberry Pi Development Screen

    This is a a very simple configuration. The left-half of your window is VS Code and the right half of your window is your CLI (terminal application.) Use tabs on both to view multiple files or instances.

  • 2022-07-23
    Developing in C for the ATmega328P: Upload

    Where I describe the process of developing code for the Arduino Uno(AVR ATmega328P), specifically, uploading code to the Uno.

    Introduction (from Edit)

    The middle three steps compile/link/locate are typically called the build process, which can simplify the five steps to three:

    1. Edit
    2. Build
    3. Upload

    Upload

    Determine the port

    The most important step in uploading to the Uno is to ensure your env.make file is using the correct serial port. The easiest method for this is to plug-in your Uno and use the Arduino IDE and Tools -> Port to identify the port used by the Uno. Here is a screenshot of this process on the Mac:

  • 2022-07-07
    Developing in C for the ATmega328P: Using git

    Where I discuss how to implement and use git to develop code in C for the Arduino Uno.

    Sources

    • Beginner’s Guide to Git and GitHub

    Introduction

    In this post, I’ll describe how to use git to add the Lab content. I’ll also offer some guidance as to how to use git in your own projects. I am not a git expert and I’ll try not to stray too far from status->add->commit-push…

  • 2022-06-23
    GCC 12 AVR array subscript 0 is outside array bounds

    Where I describe a new error caused by a bug in GCC 12 as it relates to the AVR microcontrollers.

    Sources:

    • GCC Bug report
    • Another bread crumb

    Description

    While debugging a setup script, I ran across this error on my Linux system, however, it didn’t show up on my macOS or Windows computers.

    $ make flash
    avr-gcc -Os -mcall-prologues -g3 -std=gnu99 -Wall -Werror -Wundef -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums  -ffunction-sections -fdata-sections  -DF_CPU=16000000UL   -DBAUD=9600UL -DSOFT_RESET=0 -I.  -I../../Library -mmcu=atmega328p -c -o main.o main.c
    main.c: In function 'main':
    main.c:33:9: error: array subscript 0 is outside array bounds of 'volatile uint8_t[0]' {aka 'volatile unsigned char[]'} [-Werror=array-bounds]
       33 |   PORTB &= ~_BV(PORTB5);
          |         ^~
    cc1: all warnings being treated as errors
    make: *** [<builtin>: main.o] Error 1
    $
    

    It does seem rather odd as 0 is certainly not “outside array bounds”, therefor I had no idea as to how to remediate it.

  • 2022-05-29
    Flashforth: Using the Three Values of Forth

    Where I demonstrate the three values of Forth; speed, extensibility and interactive, to develop a better understanding of the ATmega328P.

    Sources

    • Flashforth Example on Github

    Introduction

    In describing Forth to others, I typically use what I call the “Three Values of Forth”. They are speed, both in execution and development, extensibility, the capability to easily add to the language and interactive, the ability to easily interact with Forth using the serial terminal. It is these three values which make Forth, a great language to use for programming microcontroller boards.

  • 2022-04-20
    Using Makefiles to Automate Development

    Where I demonstrate how to use make and makefiles to automate your build process.

    Update

    While this entry accurately describes how to use a Makefile, the approach has changed significantly. See Developing in C for the ATmega328P: Make, Makefile and env.make for the latest information.

    Automate using a Makefile

    We’ll use the Makefile from Elliot William’s book, he has in the folder setupProject. This Makefile is comprehensive and delivers an Arduino IDE type of simplicity with significantly increased speed. I’ve made some changes to it to make it easier to switch between different types of systems. Here is the file:

  • 2022-04-19
    Comparing Board and Language Speeds

    Where I compare the execution speeds of different combinations of boards and languages. I will continue to update this post with other languages and processor combinations.

    Table for the impatient

    ucontroller/Speed(MHz) Method* frequency Language
    ATSAMD21/48Mhz Integral .6kHz CircuitPython
    ATSAMD21/48Mhz Integral function .7kHz CircuitPython
    ATSAMD21/48Mhz Library .7kHz CircuitPython
    RP2040/133Mhz Integral function 1.0kHz CircuitPython
    RP2040/133Mhz Library 1.44kHz CircuitPython
    ATmega328/16MHz struct/function pointer 6.1kHz Arduino C++
    ATmega328/16MHz words in an infinite loop 27KHz FlashForth
    ATmega328/16MHz struct/function pointer 55kHz C
    ATmega328/16MHz struct/function pointer 56kHz Arduino C++ w/ native toggle
    ATmega328/16MHz Assembly language toggle 108kHz FlashForth
    ATmega328/16MHz Assembly language toggle inlined 444kHz FlashForth
    RP2040/133Mhz struct/function pointer 578.7kHz C
    RP2040/133Mhz words in an infinite loop 2.841 MHz Mecrisp Forth
    *See text for an explanation of method.

    Introduction

    While writing about CircuitPython and the FIDI board, I was curious as to the execution speed of CircuitPython on a extremely powerful (relative to the AVR ATmega328) ARM M0+ microcontroller. The M0+ is a modern RISC 32-bit processor with a considerable amount of memory, while the ATmega is 20 year old RISC 8-bit processor with a limited amount of memory. That said, one can’t run CircuitPython on ATmega processors, one must use C or Forth.

  • 2022-03-31
    Git: Beginning to Use It (ESP32)

    Where I discuss what to do once you’ve downloaded a repository from Github.

    Introduction

    I’ve advocated using the AVR_C (among others) repository to learn how to use C instead of the Arduino “C++” language. (I write C++ in quotes as while the language used is C++, there are some extensions which some people assume are part of the language, causing more confusion.) In this post, I want to start a short series on using Git as it is extremely helpful, once you begin to develop code. And it becomes mandatory, once you begin using someone’s git repository.

  • 2022-03-07
    Developing in C for the ATmega328: PRNG, FSM and more!

    Where I discuss psuedo-random number generators (PRNG), finite state machines (FSM) and other software topics.

    Sources

    Mersenne Twister

    • TinyMT - Tiny Mersenne Twister
    • TinyMT on GitHub
    • Mersenne Twister Readings

    Introduction

    This entry covers several topics, random number generation, finite state machines and native programming. All of the code discussed is in AVR_C on GitHub. The objective is to continue to expand on the development of a standard C library for the Arduino Uno and other ATmega328-based microcontroller boards.

  • 2022-01-02
    Hardware Debug: Exploring the ATmega328PB Xplained Mini

    Where I demonstrate how to use the ATmega328PB Xplained Mini from Microchip to understand how to program in Standard C.

    Sources

    • ATmega328PB Xplained Mini
    • ATmega168PB Xplained Mini
    • Adding support for ATmega328PB to avr-gcc and avrdude
    • Bloom (replaces avarice) (Linux only)
    ATmega328PB XPLAINED Mini Board Image

    Introduction

    Due to its size and shape, I’m conflicted on this board. For the price, its fantastic! Why the conflicting thoughts? The good is that this board has an embedded hardware debugger which solves the controller board/debugger tool issue and it only costs $12! The bad is the board is physically large without adding extra value, thus it requires two breadboards to easily interface. All this said, I would recommend this board over any other, if you plan to do any hardware debugging.

Page 6 of 8
Copyright © 2025 Lief Koepsel
  • Home
  • Search/Topics
  • Writings
  • About