AVR ISP (ATmega328P, Addr. auto inc., STK500v1 at 115.2 kbps)

You happen to have an Arduino Nano laying around, and wanted to program some AVRs but don’t have an AVRISP programmer?

No worries. If you use the Arduino IDE, then you can opt for the built-in example, the 11.ArduinoISP. This out-of-the-box option is certainly useful for a lot of people, however it has some shortcomings. Like you need to use the Arduino ecosystem -which makes your compiled code big- with the bundled compiler toolchain. Also the ArduinoISP is slow, it uses 19.200 kbps for the serial communication with your computer. Also, it uses a fixed SPI clock -which cannot be changed dynamically at runtime-, which can be too fast for targets running at low frequencies.

Since these shortcomings were not suitable for my application, and I wanted to learn some AVR assembly, the project avrispm328p was born.

It turns your ATmega328P-based board (like an Arduino Nano, Uno, etc.) into an AVR ISP with adjustable SCK half-period, using the STK500v1 protocol.

It’s open-source and free, check it out on GitHub!

AVR ISP (ATmega328P, Addr. auto inc., STK500v1 at 115.2 kbps)

Programming an AVR MCU in JavaScript

arduinoyun

I have launched a project exploring some aspects of moving the development of an AVR MCU from the AVR/C++ world to the MIPS Linux/JavaScript world.

Code example:

// PWM glowing example.
// Copyright (C) 2015 Imre Horvath
//
// Build a circuit using a breadboard like this:
// Arduino Yun digital pin 11 (PWM) --> 270 R 5% --> 5 mm LED --> Arduino Yun GND
//
// This code below will cause the LED to glow first brighter and brighter gradually,
// then it will glow dimmer and dimmer till off.
// And then, this will repeat forever.

var firmata = require('firmata');
var board = new firmata.Board('/dev/ttyATH0', function (err) {

  var pwmPin = 11;
  var value = 0;
  var up = true;
  var incr = 10;

  if (err) {
    console.log(err);
    return;
  }

  function cleanExit() {
    board.reset();
    process.exit();
  }

  process.on('SIGTERM', cleanExit);
  process.on('SIGINT', cleanExit);

  board.pinMode(pwmPin, board.MODES.PWM);
  
  setInterval(function () {

    board.analogWrite(pwmPin, value);

    if (up) {
      if (value < 250) {
        value += incr;
      } else {
        up = false;
        value -= incr;
      }
    } else {
      if (value > 0) {
        value -= incr;
      } else {
        up = true;
        value += incr;
      }
    }
  }, 125);

});

Actually all the parts to assemble a system for experimenting are available.

  1. They have created the Arduino Yun, which is an ATMega AVR MCU connected to a Atheros MIPS Linux SOC with a serial line on board.
  2. There is the Arduino software to program the MCU
  3. There is the StandardFirmata sketch and the modification of it to enable it’s use within the Yun
  4. There is the Node.js and the serialport module with native extension provided through the Yun package repository
  5. You can configure BusyBox to start your node app at the end of the boot process, hence having a similar behaviour as with a native MCU, but with slower startup time
  6. You have SCP to transfer your app from your development machine to the Yun
  7. You can create a simple helper script to stop the old app on the Yun, transfer the new app and finally start it again.

It is an interesting idea to program an MCU in JavaScript, because of the language’s powerful features like closures, first-class function objects and higher-order functions. These features enable enormous expressive power compared to plain C/C++.

However transferring control from the AVR to the Embedded Linux on-board through a serial line (57600 baud) and the Firmata protocol on top of it, might render this idea useless for time critical real-time applications.

Also a lot of low-level (C/C++) libraries are available for the Arduino platform like the Arduino-IRremote which are unavailable and unusable on the Node.js side. While other low-level libraries like the one for controlling a WiFi shield are rendered unnecessary when using a Yun with the Linux side which already has WiFI capabilities.

Check out my GitHub repo on the topic!

Programming an AVR MCU in JavaScript