Programming Microcontrollers – low power, small footprints, & fast prototypes, using Arduino, Atmel, & GForth

Spread the love

This article explains how to use the Arduino toolchain to program microcontrollers from the Arduino IDE using their bootloaders, and also burning bootloaders directly onto bare microcontroller chips. It covers developing interactively with Forth (rapid prototyping), and moving your creations from a development board (Nano, Uno) to a standalone, low-cost, low-power, small footprint chip such as the ATMega328P or ATTiny85 or ATTiny84. Each of these microcontrollers is powerful, inexpensive, and allows using 3V batteries directly without the need to boost voltage to 5V. Additionally, we describe how to build an inexpensive (under £5), standalone 3-chip Atmel AVR universal bootloading programmer that you can use to program all of the chips above.

To see what you can do with microcontrollers, check out the gallery here and here.

Our preferred microcontrollers

When building embedded projects, I typically use one of the following:
(1) Arduino Nano, a breadboard friendly 30-pin board built around the Atmega328P microcontroller, (2) Atmega328P, standalone 8-bit low power (3mA) microcontroller IC (P stands for PicoPower), and (3) Attiny85/84 which are standalone 8-bit low power (1mA) microcontrollers.

The Arduino Nano is an excellent 8-bit microcontroller for developing embedded applications. It is reasonable cost and power consumption (£3.70 ea, 19mA), is easy to program (Arduino IDE via USB serial connection, or via SPI 6-pin header), supports interactive tethered software development from PC over USB using 3-instruction Forth, is versatile (has digital I/O, analog IN, PWM analog OUT, can generate tones), has 18 I/O lines and several built-in communication protocols (asynchronous Serial UART, synchronous serial I2C and SPI).

Once your code is stable and you no longer require tethered software development, it is more economical to drop the finished code into the standalone 28-pin Atmega328P IC (c.50% cheaper at £1.95 and 80% lower power consumption at 4mA). Best part is that the code you’ve written for the Nano needs no modification to port to the standalone Atmega 328P, since it is the same microcontroller at the core of Arduino Nano and Uno boards.

For an even smaller footprint, you can drop down to the truly tiny 8-pin Attiny85 IC (£1.50ea, 3mA power), provided you can manage with 5 or fewer I/O pins.

This is probably as cheap/small as you can go with hobbyist-friendly microcontrollers (easy to program with low fixed cost investments, I’ve assembled a £5 three-chip programmer that works for any of Atmega328P, ATtiny84, and ATtiny85 using Arduino interface).

To get cheaper than this, you’re into the territory of chips that require special hardware to program and custom toolchains (see Appendix).

Microcontroller Comparison table: Arduino Nano, Attiny, ESP, etc.

Choosing a Microcontroller | Top Microcontrollers

History: Microcontrollers | Atmel | AVR family of uCs | Microchip’s acquisition of Atmel (2016) | Atmega 8-bit uCs | Atmega328 | Arduino

Examples of what can be accomplished, and supply links to try it out:


Building a £5 Atmel AVR bootloading programmer

This inexpensive programmer design has three independent channels each with a DIP socket and 6-pin ISP programming header required to directly program a particular Atmel AVR microcontroller: from left to right: Atmega328P (DIP-28) which is used in Arduino Uno/Nano single-board uC systems, ATtiny84 (DIP-14), and ATtiny85 (DIP-8). A custom 6-pin cable connects the desired channel to an Arduino Nano running the ArduinoISP code which turns it into an in-system programmer (ISP).

User connects the bootload programmer to Arduino IDE via USB. The Arduino IDE is used to program the chips, i.e. to write compiled code to the target chip. The 3-chip programmer is easy to assemble on a 4cm x 6cm PCB and uses less than a dozen through-hole components. Total parts cost, including the Nano, is c.£5. If interested, ask in the comments.

Usage:

  1. Insert chip into socket.
  2. Move ISP header cable to corresponding 6-pin header, keeping pin1 (purple) in position (top left).
  3. Apply power via USB mini cable.
  4. Load code into Arduino IDE (best to have pretested with Nano).
  5. If code is for ATtiny, make the relevant modifications going from Nano to Tiny pin numbers (see below).
  6. Select Tools > Programmer > “Arduino as ISP”.
  7. If target uC is Atmega328P with no change to Nano code, select Tools > Boards > “Uno” (you will need a 16MHz crystal and 2x 22pF caps in the target board). Then Tools > Burn Bootloader…. Then jump to burn program. (Important to burn bootloader to ensure that the chip’s timing fuses are setup correctly, especially if you use the same chips between internal clock and external.)
  8. If target uC is Atmega328P in standalone mode (but timing will be half as fast), select Tools > Boards > “Atmega328P on a breadboard (8MHz internal clock)”.
  9. If target uC is ATtiny, select Tools > Boards > “Attiny” and Tools > Processor > “Attiny84 or Attiny85” and Tools > Clock > 1 MHz or 8MHz or 16MHz.
  10. IMPORTANT: To burn program, select Sketch > Upload using Programmer (Ctrl+Shift+U).
  11. Program should burn successfully.
  12. Remove chip carefully from socket and install onto breadboard or PCB.
  13. Done!

1. Programming the Nano board

Arduino Nano can be most easily programmed from Windows PC using usb-mini cable (note there are now usb-micro and usb-type-c variants) and the Arduino IDE. Programming is done in C modified with Arduino specific functions, or 3-instruction Forth that uses a serial umbilical to connect a host Forth (GForth) to the Arduino, permitting interactive remote development on the target Nano chip.

Programming the Arduino Nano via the USB-mini cable from the Arduino IDE. Equally able to interactively program it using 3-instruction Forth over UBS-mini cable running GForth on Windows PC.

Programming Arduino Nano from Arduino IDE:

  1. Tools > Board > Arduino Nano
  2. Tools > Processor > ATmega328P (Old Bootloader) – Try the Old Bootloader first. Most of the Nano clones that you can buy inexpensively have this burned into them by default. If it doesn’t work try the standard ATmega328P processor choice. Note, the P at the end of the chip name stands for PicoPower, i.e. ultra-low power functionality.
  3. Select the correct Serial COM port in which the mini cable is plugged into.

    Configuring the Arduino IDE to program Arduino Nano board with ATmega 328P chip

  4. Write your program (Arduino calls this a sketch) in the IDE editor (or load from source file written in another editor).
  5. Upload your program directly (Ctrl+U) to the Arduino.

  6. Wire up your circuit referring to the Nano’s pinouts.

    Arduino Nano, 30-DIP form factor, with Atmel 328P microcontroller, and 16 i/o lines, + serial + i2C, 5V and 3.3V

Arduino Nano running untethered with a separate 5V power supply (boost converter + AAA battery) with the program loaded using USB-mini cable and the Arduino IDE on the PC.

3-instruction Forth for Arduino Nano

Interactive software development allows real-time exploration of a chip/sensor’s capabilities, and can speed application development by 10x! For this I use Forth Forth , which has the additional advantage of making it easy to write a domain specific language, which is very handy for embedded development.

Over the COVID period (2020) I wrote a fully-functioning 3-instruction Forth for Arduino Nano/Uno (Arduino 3iForth), following the approach of Frank Sergeant (“A 3-INSTRUCTION FORTH FOR EMBEDDED SYSTEMS WORK”, 1991). The result has indeed accelerated embedded development. I can now take a new sensor, and get it up and running in less than 30 minutes using Forth to probe how to communicate with/use the sensor’s capabilities. Once the right instructions/command sequence are tested, it’s a simple matter to translate back to C code to create standalone (untethered) application, or add extended capabilities that run on the remote chip with a single command from the host PC. For the full code, request in the comments.

A complication in building 3iForth for Arduino is the Harvard architecture that means program/instruction memory (Flash) is physically separate from user/data memory (SRAM), unlike a von Neumann architecture chip such as the Motorola 68HC11 (Sergeant’s target), where memory is shared between program and data. To get around this, I used function pointers to the functions desired to be remotely called, and these are stored in a table held in user memory. This means that 3iForth is not technically self-extensible on the Nano itself, but because it is tethered, the user does not perceive it, as the host Forth on the PC is extensible. As mentioned above, additional capabilities must be added to the C program core and a pointer exported to the user exposing the functionality. This technique is useful generally, since most modern, low-cost microcontrollers use a Harvard architecture.

The core of Arduino 3iForth is 44 lines of C code. The code creates a combined data and address stack in the remote chip’s data space, and stores the 3 instructions xfetch, xstore, xcall, along with two useful additions x_s (inspect remote stack) and xdrop, into an array of function pointers. The design allows the user to export any of the capabilities of the chip through functions written to use the remote chip’s stack. These functions can then be added to the function pointer array, and called using their index. The user connects to the remote Forth using using serial UART. The remote chip responds only to these 3 (actually 5) commands, but due to xcall, it is unlimited in how many instructions can be added. The user can now work in any Forth that can make and maintain a serial connection. I use GForth on Windows.

To initialize the serial port, I use a hack: RealTerm first makes the connection (startup flags: baud=9600 display=2 half port=1), after which GForth under 3iForth.fs the command X open-com works.
TODO: Need to find get C function call working from GForth to initialize serial port from within GForth

RealTerm configured at startup with the flags: baud=9600 display=2 half port=1. Note the signature 0xFF 0xFE sent by the Nano under 3iForth confirming it is operational and listening for instructions on the serial line.

Start GForth in the directory containing 3iForth.fs. include 3iForth.fs
You’ll see the help file shown [help]. Each module has an associated help file to help the user use the new vocabulary provided.

After shutting down RealTerm, the serial port is configured correctly. The instructions: 1 open-com makes the connection in GForth.
Note the signature 255 254 (0xFF 0xFE) upon checking the rx queue.

Writing to flash directly is possible using AVR assembly language. (TODO: write a native extensible 3iForth for Nano in assembly.) AVR Instruction Set. AVR1 is the minimal core language. AVR2.5 is the superset that works for Attiny 84/85. AVR5 or AVR5.1 is the superset that works for ATmeg328.


2. Standalone Atmega328P uC IC

The Atmega 328P is available in a sub-£2 package package convenient for use in breadboards. It is the same microcontroller chip that is integrated into the Arduino Uno and Nano boards, so the same code can be used in standalone mode without modification, with the advantage that total power consumption is 3mA (85% reduction) instead of the 19mA used by the Nano board.

To use the Atemga328P as a standalone chip requires a breadboard and at a minimum 2x 100nF (0.1uF, 100kpF, #104) capacitors between VCC and GND pins and between AVCC and GND. (Note BOTH power/ground pairs need to be connected for the chip to work.) The programming a standalone Atmega328P is easy: just use an Arduino Uno that accepts the through-hole part.

As a trade-off for this simplicity, the standalone uC requires connection to an external 16MHz crystal oscillator and 2x 22pF capacitors, hooked up from the oscillator pins to ground. This ensures that the code will run at 16MHz, which is the standard clock speed of the Nano and Uno, so that there are no timing differences and no code adjustments required.

Programming the Atmega328P for standalone mode using the Uno board with the 328P inserted into the through-hole DIP IC socket. Demonstrating the code via 2-wire I2C connection to the OLED, and 2-wires for VCC/GNC.

Running code in an Atmega328P in standalone mode. Requires a 16MHz crystal oscillator (external clock) and 2x 22pF capacitors to ground, and 2x 0.1uF capacitors between VCC/GND and AVCC/GND. Note BOTH power/ground pairs need to be connected for the chip to work. This shrinks the footprint considerably from Nano, while allowing identical code to be used with no modification. Only addition is 2x 0.1uF smoothing capacitors, a 16MHz crystal oscillator, and 2x 22pF capacitors to run the Atmega328P in standalone mode. The chip programming starts off easy, just use an Arduino Uno that accepts the through-hole part or the 3-chip standalone programmer

Instructions for programming Atmega328P for use with 16MHz external oscillator

  1. Insert the Atmega328P IC into the socket of the target UNO.
  2. Connect the target UNO to the PC using the USB cable.
  3. In the Arduino IDE, select Tools > Board > Uno. Select the appropriate COM port (Tools > Board > COM > …)
  4. Upload your sketch: Sketch > Upload. Done!
  5. Remove power from board. Pry the chip carefully from the socket using a small screwdriver so the pins don’t get bent.
  6. Insert the programmed chip into your breadboard circuit.
  7. Connect 16MHz crystal oscillator to pins 9/10 (XTAL1/XTAL2) and 2x 22pF capacitors from pins 9/10 to ground. Ref: Wiring up 16MHz crystal NOTE: crystal oscillators have no polarity – they can be inserted in either direction.
  8. Ensure rest of your connections are correct using the Atmega328P pinout (see below)
  9. Add 0.1uF (#104, 100k pF) capacitors between pins 7/8 VCC/GND and pins 20/22 AVCC/AGND
  10. Apply PROPERLY REGULATED 5V power. (The example image shows the use of a boost converter with a single 1.5V AAA battery.) You should see the programmed functionality working!

Atmega328P pinout for DIP-28 package, per datasheet (in black) and using standard Arduino pin names (in red)


Source: https://www.arduino.cc/en/Hacking/PinMapping168

Schematic showing connection of 16MHz crystal oscillator to pins 9,10 (XTAL1, XTAL2), with each bypassed to ground with 22pF caps.
Source: https://wolles-elektronikkiste.de/en/using-the-atmega328p-standalone

WARNING1: When applying 5V power do NOT just use a 5V rated wall-wart. This unregulated power and will typically kill your micro. You need to supply regulated power. You can use an Arduino and piggy back off its 5V and GND pins. Or you can use a battery and boost convert it to 5V. Or you can use a regulated power supply.

WARNING2: Make sure you don’t reverse power and ground. This will fry your micro. And probably your OLED. And probably everything else in your ciruit. You should wire in a switch instead of disconnecting/reconnecting wires (which you are likely at some point to put in backwards by mistake). You can also put in a protection diode 1N4001 1A diode to be safe.

WARNING3: Ensure you connect BOTH VCC/GND and AVCC/GND to the 5V and Ground rails respectively. Otherwise the chip does not function correctly (display stutters in the OLED example).

PRECAUTIONS: Use power smoothing caps as a matter of course: 100uF for input power (can ignore if powering from a battery as batteries are low-noise power sources), 10uF for output power, e.g. coming out of a boost converter, 0.1uF (#104 caps) across the power/ground inputs for EACH IC.

Power supply basics here.

In summary:
Simplest way to program Atmega328P to run in standalone mode is to:
Program and test in situ on the Arduino Uno.
Pull the DIP chip, mount onto breadboard, adding 2 sets of power connections and 2x 0.1uF smoothing caps.
Also add external 16MHz crystal oscillator and 2x 22 pF caps connecting the ends of the crystal to ground, and it should work just fine when powered!

Reference:
[1]Woole’s Blog post showing the wiring of thec crystal oscillator (16MHz) and two 22pF caps to ground

[2]Programming an Atmega328p and using it without Arduino board

[3]Step-by-Step Photo-Illustrated Process

Minimal parts count standalone Atmega328P – Burning Bootloaders and Uploading using ISP Programmer

To reduce parts count further, we would need to get rid of the external 16MHz oscillator and the 2x 22pF capacitors from the previous instruction. Doing so will require burning a new bootloader to the uC in order to set the appropriate fuses of the Atmega328P to use the 8MHz INTERNAL clock, but timing will be half as fast as a result, and if this is critical for your code, you may need to introduce appropriate corrections.
Ref: AVR Fuses Calculator and here
Ref: Atmega328P on a breadboard | Arduino to breadboard

Instructions for programming Atmega328P for use with 8MHz internal clock using fewer parts

  1. Put the chip into the TARGET Arduino UNO (ensure you match up the indentation on the chip with the outline). (The source system is the PC’s Arduino IDE.)
  2. On your PC, download and the board definition file Atmega328p_breadboard-1-6-x_board_def.zip (original source)
  3. Unpack to Arduino folder: .\arduino\hardware\..
  4. Restart Arduino IDE to see the new board definition: “Arduino 328 on a breadboard 8MHz internal clock”
  5. Select it: Tools > Boards > “Arduino 328 on a breadboard 8MHz internal clock”

Download board definition for Atmega328P with 8MHz internal clock. Install to hardware folder, and then select Boards > …

You’re now ready to burn the bootloader and upload the program, both of which you can do using an AVR ISP programmer. You can buy one (TinyAVR or PocketAVR), or if you have a spare Arduino Nano or Uno lying around you can build one for a lot less! (£3 – the cost of the Nano). (See figure for three AVR ISP programmers.)
Ref: Arduino instructions for burning bootloader

Three options for using an AVR ISP programmer: (a) using Nano as ISP programmer (cheapest); (b) using TinyAVR (easiest); (c) using UNO as ISP programmer

Setting up an AVR ISP Programmer

  1. To use the Tiny AVR as your AVR ISP programmer (EASIEST – but you will need to install the device drivers for this, so maybe not as easy… see here for files & screenshots post-installation):
    NOTE: if the TinyAVR programmer is not recognized, you will need to install device driver files from here.

    • Connect PC to Tiny AVR programmer with built in USB
    • Now connect the Tiny AVR programmer to the target UNO with 6 pins from the 8-pin Tiny85 header.
    • No additional adjustments necessary.
    • Choose Tools > Programmer > “USBtinyISP” (not ArduinoISP or anything else)
    • Now connect the TinyAVR to the 6-pin ICSP header on the target UNO. Not special connections are required.

    Using Tiny AVR as ISP.
    In Arduino IDE, select Programmer > USBtinyISP. The wiring is for Attiny85 socket (see wiring diagram)

    Connecting the SPI pins of Tiny85 to use Sparkfun’s Tiny AVR as an ISP programmer. Works for Atmega328P, Tiny84, and Tiny85.

  2. To use a Nano as your AVR ISP programmer (CHEAPEST):
    • Connect PC to programmer Nano with USB-mini cable
    • Tools > Board: select Nano. Tools COM: select
    • Load ArduinoISP.avr into Arduino IDE
    • Sketch > Upload
      This makes the Nano the ISP programmer.

    • Choose Tools > Programmer > “Arduino as ISP” (not ArduinoISP or anything else)
    • Now connect the Nano programmer to the target UNO via the two 6-pin ICSP headers, EXCEPT (a) connect pin 5 (\RESET) of the target UNO with pin10 (SS) on the programming Nano AND (b) connect \RESET to GND with 10uF capacitor.

    Using the Arduino Nano (right) as AVR ISP programmer for programming/burning bootloader on Atmega328P IC inserted into socket on Arduino UNO target board (left),

    Ref: Nano as Programmer

  3. To use a second Uno as your AVR ISP programmer:
    • Connect PC to programmer Uno with standard USB cable
    • Tools > Board: select Uno. Tools COM: select
    • Load ArduinoISP.avr into Arduino IDE
    • Sketch > Upload
      This makes the UNO the ISP programmer.

    • Choose Tools > Programmer > “Arduino as ISP” (not ArduinoISP or anything else)
    • Now connect the UNO programmer to the target UNO via the two 6-pin ICSP headers, EXCEPT (a) connect pin 5 (\RESET) of the target UNO with pin10 (SS) on the programming UNO.

Using the Arduino Uno (right) as AVR ISP programmer for programming/burning bootloader on Atmega328P IC inserted into socket on Arduino UNO target board (left).

Next step is to make the connections between the AVR ISP programmer and the 6-pin ICSP/SPI header on the target. See the pinouts:

Pinout reference for 6-pin ICSP / SPI headers. Be careful in connecting these pins between PROGRAMMER and TARGET UNO boards, noting the warnings/additional connections.

Final steps:

  1. Burn the bootloader for the Atmega328P with 8MHz internal clock. Tools > Board > …. | Tools > Programmer > … | Tools > Burn Bootloader
  2. Upload your program using the ISP programmer: Sketch > Upload using Programmer (Ctrl+Shift+U). Done!
  3. You can now carefully pry out the Atmega328P chip, install to your breadboard, make the appropriate circuit connections, and cautiously apply power. SEE PRECAUTIONS from above [link].

For using standalone Atmega328P with minimal supporting components, you will need to burn a bootloader to set the 328P fuses to use the internal 8MHz clock. (Not shown: 5V boost converter, 1x AAA 1.5V battery with holder, switch.)

References:

  1. Another blog collection for 15 minutes
  2. A third discussion
  3. Breadboarding without oscillator
  4. Programmers for Atmel AVR uCs: TinyAVR Hookup Guide,
    PocketAVR

  5. Installing an Arduino Bootloader Alternate instructions
  6. change the bootloader
  7. The successor chip is the Atmega328PB with additional capabilities.

3. ATtiny85/84 uC IC

Benefits of choosing an ATtiny85

The ATtiny family

The Atmel Tiny85 is an ultra low power (2mA idle, 10x less power draw than the Nano), DIP-8 8-bit microcontroller with 5 i/o pins + reset (see [5], I2C/SPI comms, 2x 10-bit ADC channels, 4x 8-bit PWM output (256 levels), and a timer.

The Atmel Tiny84 is a low power, DIP-14 8-bit microcontroller with 11 i/o pins + reset, I2C/SPI comms, 2x 8-bit (256 levels) 2x 16-bit (65k levels) PWM outputs,

Easiest way to program Tiny85 is with the Sparkfun Tiny AVR Programmer board. This has a DIP-8 socket which you can push a new IC into (remember to line up pin1 on the chip with the notch on the chip footprint). The programmer uses the SPI pins of the Tiny85. Plugging it into USB port will not show any visual indicator that it is on/working. Programming a Tiny85 to flash pin0 flashes built-in LED on the board.

The Arduino IDE needs some software extensions (see here for how).[links]

After that, almost any Arduino code should work on the Tiny. Just keep in mind that memory is even more precious at 8KB of flash memory (program space), 4x smaller than the Nano (32KB), i.e. minimize use of libraries.

Code that works on the Nano typically needs only a new pin assignment to Atiny using preprocessing conditionals #ifdef TINY85 … #endif and #ifdef NANO … #endif to keep a single code base. For an example with details on how to do this, including code for dropping from Nano into ATTiny, and what you need to do to compile for the Tiny uCs, see my article on Making Sensors Talk for Under £5.

Using the Arduino IDE:

Setting up TinyAVR ISP programmer and the Arduino IDE for programming ATtiny family chips.


First you need to use the Board Manager to add the ATtiny85 driver files. See [2] below.

Then select the ATtiny board (Tools > Board > ATtiny) — scroll down, it will have been added near the bottom of a long list.

Select Tools > Processor > ATtiny85

Select Tools > Clock > 1MHz (internal)
Can also choose 8MHz (internal) for more processing power, but its usually not needed, and slower draws less power.

Select Tools > Programmer > USBtinyISP
This is for using the Sparkfun Tiny AVR programmer

Configuring Arduino IDE to program ATtiny85 using Sparkfun Tiny AVR programmer

You’re ready to go!

Sketch > Upload using Programmer (Ctrl+Shift+U).

The program will compile and then upload, and start.

You can use the female header pins on the Tiny AVR programmer to directly test to breadboard.

Tiny Photo – 3cm x 7cm photo viewer powered by ATTiny85 8-bit microcontroller sending pixel level image data to OLED display (128×64 pixels), powered by 3V coin cell battery. Cycles through 5 images stored in 5kB of on-chip Flash RAM. (Note, this is 1 million times less memory than on a Windows PC with 8GB RAM).

Read about TinyPhoto here.

What’s really cool is that you can use the same Arduino/Forth development chain and drop from the Nano/UNO board or even the Atmega328P IC down to the ATTiny85 (DIP-8, 5 I/O pins) microcontroller. This really shrinks things down and delivers lower power, at lower cost, in a significantly smaller overall footprint (ATTiny85 is DIP-8, Nano is DIP-30). The ATTiny85 sips on avg 1-3mA power in a benchmark use vs. 20mA power for the Nano. The really fun part? As long as none of the rest of your components require 5VDC (especially watch out for ICs), you can get away with the need for a DC boost converter and directly power your whole device with 3V (could be a 3V coin cell, a 3V LiIon battery, or 2x any 1.5V battery whether button cell, AAA, or AA, C or D batteries)! With a bit of soldering and some small prototype PCB you can make some nifty little gadgets.

Knight Rider LED device powered by ATtiny85 controlling shift out register IC 74595 all powered by 3V button cell battery

References:
[1] Integrating ATtiny85 into your project
[2] Programming ATtiny85 using Arduino and the Sparkfun Tiny Programmer board
[3] Step-by-Step programming ATtiny85 – SparkFun Tutorial
[4] Writing direct AVR-C (bypassing the Arduino IDE)
[5] Using the 6th (reset) pin on Tiny85 for I/O is painful
[6] Programming instruction using Arduino UNO as an ISP programmer

3.1 ATtiny84

Wiring the Tiny84 to program it using Sparkfun’s Tiny AVR programmer (intended for Tiny85).

The Tiny AVR programmer then works with the Tiny84 chip as well. Just choose the Tiny84 processor in the Arduino IDE.

Choose Tiny84 processor and hookup MISO, MOSI, SCK, RESET, VCC, and GND of the Tiny84 to the appropriate pins of the Toy AVR Programmer.

TIP: You can write code for the Arduino Nano, and then move directly to Tiny84, by putting chip specific pin definitions in #ifdef NANO … #endif and #ifdef TINY84 … #endif respectively, and then modifying the code with #define NANO or #define TINY84 before compilation.


Appendix 0. Additional controllers

The above are likely to cover applications that don’t require wireless connectivity/internet of things, have huge volume potential requiring sub-£1 pricing, or involve large scale sensor control requiring massively parallel controllers. Controllers suited for these niches will be covered in a future article, and include:

(4) For wireless/internet of things applications, the 32-bit Espressif (ESP8266, NodeMCU (based on ESP8266), and ESP32) microcontrollers are exceptionally well suited featuring built-in wireless connectivity (802.11 WiFi, Bluetooth) and are programmable using the Arduino IDE. With the ESP8266 it is possible to interface with Alexa.

(5) For high volume applications, the ultra-low cost category can be worth a look: there are the sub-30p reprogrammable ISP microcontrollers and the sub-10p one time programmable (OTP) microcontrollers. While these are really inexpensive and quite powerful, they are not easy for hobbyists to use, typically requiring specialized high voltage programming equipment, assembly language coding using proprietary toolchains with limited documentation. Examples: Padauk PMS150C example, full review);

(6) for large-scale ubiquitous computing, the ultra-low power GA-144 multi-core controller with 144 individual controllers, invented by Chuck Moore, the father of Forth and of ultra-low power MISC (minimal instruction set computing) hardware designs, offer intriguing possibilities are a sensible price point. The GA-144 has 144 independently programmable microcontrollers, interconnected in a defined topology, on a single-die!
Ultra-low power. Usage: Wherever there is a need for dedicated continuous real-time monitoring and control, instead of multiple discrete components and a lot of communication interconnects, this chip allows integration. Application: Piano-25 PCB (small scale, 3 dedicated controllers, 1 coordinating controller), smart sensored car (many dedicated controllers, 1 coordinating controller). Sort of like CAN bus in automotive control.

Appendix 1. Design choices

Nano vs. Tiny

What designs can use the Tiny85 (5 i/o pins, £1.30 ea), Tiny84 (11 i/o pins), and what need the Nano (usb interface, 16-22 i/o lines)? Note Tiny85 can run on 2.7-5.5V, so does not need converter, just 2x 1.5V AAA batteries.

  1. PIR sensor (Tiny85): requires 1 output for buzzer, 1 signal input from PIR sensor, and 2 pins for red/green light state signalling (total 4 pins). Low power of Tiny85 is perfect (2mA) running from 1x 1.5V AAA battery boosted to 5V using CR012 converter, needed to provide 5V to the PIR sensor, which runs a signal processing chip onboard to reduce false detections. Total cost: £3.50 (£1.30 for Tiny85, £1.10 for PIR sensor, 35p for AAA battery holder, 30p for AAA battery, 35p for 170 tie points beadboard, 10p for misc parts LEDs, wiring, resistors). Total time to wire up, program, and test: 2 hrs. Requires: USBTiny programmer, Laptop with Arduino IDE. ATTiny85 code
  2. 4-way Traffic lights (Tiny84): requires 3 outputs to control a pair of Traffic lights, so 6 outputs for 4 traffic lights, plus need signals (buttons) so additional one if one signal and two if two signals for total of 7-8 i/o lines. No need for Forth interface. Tiny84 works.
  3. Step motor control (Tiny85): requires 4 outputs to control.
  4. Piano (Nano): Uses Nano as the tone generator (later could use AY-3-8913 or YM*). I/O has a few different flavors/options:
    • Piano direct (Nano): Basic requires 13 pins for keys, 1 for speaker, 14 total.
    • Piano-13 PCB (Nano): 13-key PCB uses priority encoder and channel selector/demultiplexer for LEDs, requires 5 pins for keys, 5 pins for LEDs, 1 for speaker, 2 for I2C, and 4 for Menu buttons, total of 17 pins.
    • Piano-25 PCB (Nano/Tiny85/Tiny84): uses two 25-key shift IN/OUT registers each requiring 3 pins, allowing 2x Tiny85s to be used talking to Nano via I2C, or 1x Tiny84 talking to Nano via I2C. Nano required because also want tethered operation capability via USB using 3iForth.
  5. Complex Sound Effects Generator using 76477 chip
  6. Mixer Generator breakout board (Tiny84): uC uses 3 pins to encode inputs from mixer buttons selected by user and 3 outputs to 3 pins on 76477 controller (6 total), so cannot use 1 Tiny85, but could do 2 Tiny85s talking via I2C. Better to use 1 Tiny84. Rest is manual switches and the 76477 controller.
  7. Drum sequencer with 76477 complex sound generator IC using Tiny85: Tiny85 uses 3 pins to input from shift-in register which can have up to 32 inputs from DIP switch bank. With the two remaining pins, one is for one-shot trigger IC, and an analog variable resistor to indicate the beat pace. The Tiny85 loops through the beat sequence in code. For more complicated effects, the two pins on the Tiny85 can be I2C to a control micro feeding in the user requested beat sequence (i.e. a UX board interface) and the control micro could issue the beats interfacing to 76477 CSG or the more powerful 3-voice chip AY-3-8910 fully programmable sound generator (PSG)
  8. Keypad (Tiny84): 8 pins for keypad I/O, 2 for I2C
  9. 3D robotic wrist (pan/tilt/roll) (Nano): requires programmable PWM outputs when using precision position motor controllers (actuators)
  10. Etch-a-sketch (Nano): OLED driver (X KB) exceeds the 8KB max flash memory space of Tiny, so needs Nano.
    ACTION: simplify the OLED driver to the essentials. Then may be able to use Tiny. Needs 2 pins for I2C. Two PWM pins for horizontal and vertical cursor movements.

  11. Remote Control Car (RF-Nano): Need wireless capability for communicating with the car

Appendix 2. Supporting silicon to expand uC choice

ATtiny85 + Encoders and Shift-in registers, Decoders and Shift-out registers, and Channel select multiplexers.

ATtiny85 is an ideal shift register controller. It has 5 I/O pins, for which 3 can control the ‘165 shift IN register, and 2 can be used for I2C communication with the master CPU. With this design, can now readily extend to controlling 25 inputs/outputs or more from the Tiny85.

74148 (DIP-16) is an 8-input priority encoder with a cascade feature. It takes 8-inputs and encodes the highest active input into a 3-bit binary output. Cascading two ‘148s into a 7408 AND chip allows a 16-input priority encoder producing a 4-bit binary output. Usage: keypad where only one key is permitted to be active at a time (more get subject to the prioritization). Application: 13-key Piano-PCB + 3 function keys.

74165 (DIP-16) is an 8-input shift IN register with a cascade feature. This is ideal for encoding independent states where more than one can be active at the same time. Takes 3 control lines (data, latch, clock) and best part is cascading more inputs does not require any more control pins, just a longer sweep time to latch out all of the state bits in serial. To ensure dedicated CPU service, pair with a low-cost microcontroller. Usage: keyboard input, drum machine beat input, keypad input.

4 comments to Programming Microcontrollers – low power, small footprints, & fast prototypes, using Arduino, Atmel, & GForth

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  

  

  

Your comments are valued! (Please indulge the gatekeeping question as spam-bots cannot (yet) do simple arithmetic...) - required

Optionally add an image (JPEG only)

 

Stats: 1,066,417 article views since 2010 (March update)

Dear Readers:

Welcome to the conversation!  We publish long-form pieces as well as a curated collection of spotlighted articles covering a broader range of topics.   Notifications for new long-form articles are through the feeds (you can join below).  We love hearing from you.  Feel free to leave your thoughts in comments, or use the contact information to reach us!

Reading List…

Looking for the best long-form articles on this site? Below is a curated list by the main topics covered.

Mathematics-History & Philosophy

  1. What is Mathematics?
  2. Prehistoric Origins of Mathematics
  3. The Mathematics of Uruk & Susa (3500-3000 BCE)
  4. How Algebra Became Abstract: George Peacock & the Birth of Modern Algebra (England, 1830)
  5. The Rise of Mathematical Logic: from Laws of Thoughts to Foundations for Mathematics
  6. Mathematical Finance and The Rise of the Modern Financial Marketplace
  7. A Course in the Philosophy and Foundations of Mathematics
  8. The Development of Mathematics
  9. Catalysts in the Development of Mathematics
  10. Characteristics of Modern Mathematics

Electronic & Software Engineering

  1. Electronics in the Junior School - Gateway to Technology
  2. Coding for Pre-Schoolers - A Turtle Logo in Forth
  3. Experimenting with Microcontrollers - an Arduino development kit for under £12
  4. Making Sensors Talk for under £5, and Voice Controlled Hardware
  5. Computer Programming: A brief survey from the 1940s to the present
  6. Forth, Lisp, & Ruby: languages that make it easy to write your own domain specific language (DSL)
  7. Programming Microcontrollers: Low Power, Small Footprints & Fast Prototypes
  8. Building a 13-key pure analog electronic piano.
  9. TinyPhoto: Embedded Graphics and Low-Fat Computing
  10. Computing / Software Toolkits
  11. Assembly Language programming (Part 1 | Part 2 | Part 3)
  12. Bare Bones Programming: The C Language

Pure & Applied Mathematics

  1. Fuzzy Classifiers & Quantile Statistics Techniques in Continuous Data Monitoring
  2. LOGIC in a Nutshell: Theory & Applications (including a FORTH simulator and digital circuit design)
  3. Finite Summation of Integer Powers: (Part 1 | Part 2 | Part 3)
  4. The Mathematics of Duelling
  5. A Radar Tracking Approach to Data Mining
  6. Analysis of Visitor Statistics: Data Mining in-the-Small
  7. Why Zero Raised to the Zero Power IS One

Technology: Sensors & Intelligent Systems

  1. Knowledge Engineering & the Emerging Technologies of the Next Decade
  2. Sensors and Systems
  3. Unmanned Autonomous Systems & Networks of Sensors
  4. The Advance of Marine Micro-ROVs

Math Education

  1. Teaching Enriched Mathematics, Part 1
  2. Teaching Enriched Mathematics, Part 2: Levelling Student Success Factors
  3. A Course in the Philosophy and Foundations of Mathematics
  4. Logic, Proof, and Professional Communication: five reflections
  5. Good mathematical technique and the case for mathematical insight

Explore…

Timeline