Getting Started With a Bare Bone AVR128 Board

by slviajero in Circuits > Arduino

771 Views, 1 Favorites, 0 Comments

Getting Started With a Bare Bone AVR128 Board

IMG_5638.png

One of the more interesting non Arduino AVR board on the market are the bare bone AVR128 boards. They offer a lot of free GPIO pins for a price of about 8 Euros.

The boards are really bare bone, they have no USB port, no programmer, and no voltage regulator. This makes them a little harder to handle than the classical Arduinos but ideal for low power situations. Everything that needs power can be disconnected or switched of by software.

Unfortunately there is not much documentation on these boards and using them is not easy for beginners. This tutorial is a beginners guild how to program these devices with the Arduino IDE.

Supplies

IMG_5637.png

Hardware components


Software components

  • The Arduino IDE Version 1.8.15 or newer. Most of this tutorial is based on the old IDE because it works reliably with programmers.
  • The drivers for the programmer and the USB/TTL module for your OS.

Take a Look at the Board

Bild 31.10.22 um 17.46.jpeg
FLOZZQGL9TXQCBF.png

At the centre of the board there is the ATMEGA AVR128 chip. Most pins are directly lead out to four rows of connectors at the upper and lower side of the board. There is a total of 53 general purpose I/O pins organised as ports PA to PF plus 5 bits as PG0-PG4. The port numbers are printed on the upper side of the board. The numbers do not correspond to the Arduino IO pin numbers. I will write more about this further down.

On one side there is a JTAG and an ISP connector. We will use the latter to program the board. The pins of the ISP header are PE0 and PE1 which work as MISO and MOSI during programming, SCK and RESET to control the programming process as well as a power and ground pin. The location of the pins can best be seen in the schematic diagram attached as pdf.

The board has two LEDs connected to PA0 and PA1 which is pin 44 and 43. The LEDs can be disconnected with a jumper next to the ISP connector. This is a huge advantage of the board. Sometimes the resistors and LEDS can be a problem (see my tutorial on ZX81 keyboards for an example). Also, 44 and 43 are analogue pins. The LEDs should be disconnected if they are used for this purpose.

There is a second jumper on the board. This controls whether the 8MHz crystal on the board is used or the empty socket next to it. Again, this is a huge advantage for low power applications. The clock frequency of the board can be reduced according to the need of the project. Please set the jumper to connect the 8MHz crystal for now.

Next to the crystal is a power socket and some components. This looks like an Arduino, but be careful here. There is no voltage regulator. The circuitry is just smoothing the external power and directs it unregulated to the chip. One false move and the board is dead as the chip can only take a maximum of 5.5V. The socket can be switched on and off with a button next to it.

Then there is a reset button with the usual 10k pullup resistor and a 100nF capacitor.

Get the Core.

Bild 23.10.22 um 08.30.jpeg
Bild 30.10.22 um 09.31.jpeg

To use the board you need an Arduino core and board definition. I use the MCUdude Megacore which is pretty much the standard for these chips. The github repository of this software is https://github.com/MCUdude/MegaCore.

The easiest way to get the core is to add the link

https://mcudude.github.io/MegaCore/package_MCUdude_MegaCore_index.json

to your Arduino IDE board preferences as shown in the picture.

Once this is done, open the board manager menu in the Arduino IDE and search for MegaCore. Install this and you are done for now.

Get Your Programmer and TTL Converter Ready

IMG_5639.png
IMG_5640.png

First plug in the TTL connector to your computer. Open the Arduino IDE and check is there is a serial device in the port menu. I use a Mac and see the device file /dev/cu.usbserial-0001. Good!

If you don't see any device, follow the steps in this instructable https://www.instructables.com/Usb-to-SerialTTL-adapter/.

Unplug the TTL converter and plug in the USBasp device. No device will show up in the port menu as the programmer does not use a serial connection.

On a Mac you don't need to do anything. On Windows you might need drivers. Follow the steps described here https://www.instructables.com/Programming-Microcontrollers-With-a-USBasp-Program/ for this.

On both platforms you can check your USB device tree to see if the programmer is connected. On Mac this is in "About this Mac" -> "System Report" -> Hardware -> USB. You will probably see something like this

USBasp:
 Produkt-ID: 0x05dc
 Hersteller-ID:0x16c0
 Version: 1.02
 Geschwindigkeit: Bis zu 1,5 MBit/s
 Hersteller: www.fischl.de
 Standort-ID: 0x14100000 / 25
 Verfügbare Stromstärke (mA): 500
 Zusätzlicher Betriebsstrom (mA): 0

in your system language.

With this you are good to go to upload the first sketch and also upload a boot loader at the same time.

Upload the Blink

Bild 31.10.22 um 18.39.jpeg
Bildschirmfoto 2022-10-31 um 18.40.34.png

Load the blink sketch from the Arduino examples into your IDE and set the correct LED pin.

void setup() {
 pinMode(44, OUTPUT);
}
void loop() {
 digitalWrite(44, HIGH); 
 delay(1000);           
 digitalWrite(44, LOW); 
 delay(1000);          
}

Now set the parameters of the compilation but don't upload yet. Be patient.

The right settings are "AVR128" for the board. Clock "8MHz External". This is the external crystal of the board. Don't forget to set the jumper. "Bootloader: Yes (UART0)" installs the boot loader and it will listen to UART0 afterwards. This is important for the next step. All other settings don't matter right now.

The programmer must be "USBasp (MegaCore)".

Plug in the programmer now and connect the ISP cable to the ISP port. This should be a 10 pin cable and connector.

To upload the sketch, don't press the upload button. Go to the sketch menu instead and select "Upload with programmer" there. Now avrdude does a lot of work and displays the status in the compile window.

After a while you should see a blinking LED.

As USBasp does not provide a serial port, the normal upload button does not work. It assumes a valid serial port and checks it before it even thinks of consulting the programmer setting.

If you are just using the board with no need of any serial communication, you are done now. All sketches can be uploaded with the programmer.

One word on using an Arduino as ISP: theoretically one could use another Arduino as ISP. There are many tutorial on how to do this. I don't do this normally and I didn't get it working with MegaCore and the AVR128. Using a programmer is much simpler and more stable.

Serial Communication

IMG_5664.png

To check serial communication, upload a little test program with the programmer.

void setup() {
 Serial.begin(9600);
}
void loop() {
 Serial.println("Hello World");
 delay(1000);
}

To use serial, plug in the USB converter. Connect the Tx pin of the converter with PE0 of the board. Connect the Rx pin to PE1 of the board. The connect the 5V power and GND to the respective pins. Ignore the breadboard in the picture. It will be explained in the next step.

Open the serial monitor of the Arduino IDE and set the baud rate to 9600. Reset the board.

You should see the output

Hello World

every second.

Now that you know that serial works and you have a boot loader, you can go a step further.

The Bootloader and a Pitfall

IMG_5640 (1).png

Uploading the sketch should also have installed a working boot loader. From now on sketches can be uploaded with the serial converter. With just Rx, Tx and power connected, this requires a bit of timing.

Load the blink sketch again now.

Select AVR ISP (MegaCore) as programmer now.

Press the upload button and when compilation begins press and hold the reset button. Release it immediately after compilation is done. The bootloader will listen to the Serial port after reset and start the programming if it sees the right serial communication.

You should see the LED blink now after successful upload.

The whole press and release sequence is fairly tedious. Life can be easier if you have a TTL converter with a DTR output like the ones shown in the picture.

Theoretically connecting the DTR via a 100nF capacitor to the reset pin of the ISP header should auto reset the board once data transmission on the serial port begins. This, however, does not work with this board.

A minimum of 600nF is needed to trigger the programming sequence. Connecting DTR to the reset ping with two parallel 470nF ceramic capacitors does the job.

You now have a board that can be programmed almost as easily as a standard Arduino board.

Pinout of the Board

The pins of the board are mapped like this to Arduino IDE pin numbers

PE0-7: 0-7
PB0-7: 8-15
PG3: 16
PG4: 17
PD0-7: 18-25
PG0: 26
PG1: 27
PC0-7: 28-35
PG2: 36
PA7-0: 36-44 (reverse order!)
PF0-7: 45-52

The analogue pins are A0=45 to A7=52 which is PF0-7.

I2C pins are

SDA: 4 = PE4
SCL: 5 =PE5

The SPI default pins are

SS: 8 = PB0
SCK: 9 = PB1
MOSI: 10 = PB2
MISO: 11 = PB3

UART0 is connected to

Rx: PE1
Tx: PE0

UART1 is connected to

Rx: PD2
Tx: PD3

The full datasheet https://datasheetspdf.com/pdf-file/219533/ATMELCorporation/ATMEGA128/1 is definitely not beginners material. It may help to find all the other pin functions.

Troubleshooting

If you have problems with uploading with the boot loader, disconnect the board from power and restart the Arduino IDE. I experienced some strange side effects with running avrdudes in the background.

If the bootloader is damaged, best reinstall it by using the programmer and do a "burn boot loader" sequence in the Arduino IDE's tools section.

Make sure that you use the right clock setting for your board. With an 8Mhz crystal you need the "8MHz external" setting. If you upload with the wrong settings, baud rates don't match.

The value of the reset capacitor in step 6 was found by trial and error. I assume that the timing of the board, the clock speed, and the reset circuitry determines this. Increase the value if you find sporadic problems with the reset.

What's Next?

IMG_5678.png
IMG_5677.png

The main use case for this board in my lab will be low power. Just a few figures here.

An idle Arduino UNO board will use 50 mA. Power consumption can be brought down to 30 mA in sleep mode.

The AVR128 board will need 32 mA in idle mode. In sleep mode the power consumption goes down to 3.2 mA even without complete power down sequences. This would mean 15mW power consumption. An AA battery pack could last 100 hours with this load.

I will write some more on this in another instructable.