ATmega32 and Arduino

The Arduino NG board from arduino.cc. A circui...
The Arduino NG board from arduino.cc. A circuit board with an Atmel ATmega8 microcontroller. (Photo credit: Wikipedia)

I tested OLED display I bought on ebay just to see if it works. What better way to do it than use Arduino platform. Libraries are more or less available and you can do quick test. Unfortunately it took me some time, since there are a lot of different ways to connect displays – not to mention different pins.

Luckily – I managed to finally get the display working by using Adafruit library. Had to use SPI communication since the display uses only that.

Anyway – the success was nice, but what I really wanted was use ATMEL and connect the display to microcontroller and not use the whole board. So here we go with coding for the microcontroller, right?

Well, so I thought and then it dawned on me (I know, I know – obvious thing) – why not add Arduino bootloader to ATMEGA16 and do it like that. Unfortunately ATMEGA16 was too small (16k was not enough) and since I have ATMEGA32A lying around – let’s do it on the 32k micro, then.

And this is the story of how to do it:

You need to add the “board” (well, microcontroller in our case) to Arduino IDE. This can be easily done by following this. Although it is created for old version of Arduino IDE it works ok with latest one (1.6.4).  You just need to hack it to make it work with larger memory and (possibly) different fuses. I did that:

##############################################################
# Additional definitions for Arduino
# Author: Bostjan Jerko <http://www.japina.eu>
##############################################################
# Definitions for ATmega32A 8MHz 
##############################################################
atmega32a-8.name=Atmega32A (internal 8MHz clock)

atmega32a-8.upload.maximum_size=30720
atmega32a-8.upload.tool=arduino:avrdude
atmega32a-8.upload.verbose=true
atmega32a-8.bootloader.tool=arduino:avrdude

atmega32a-8.bootloader.low_fuses=0xc0
atmega32a-8.bootloader.high_fuses=0x99
atmega32a-8.bootloader.unlock_bits=0xff
#atmega32a-8.bootloader.lock_bits=0xef

atmega32a-8.build.mcu=atmega32
atmega32a-8.build.f_cpu=8000000L
atmega32a-8.build.core=arduino:arduino
atmega32a-8.build.variant=atmega32
atmega32a-8.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex

in boards.txt file (in /Applications/Arduino.app/Contents/Java/hardware/arduino/avr on Mac OSX).

I have just copied pins_arduino.h to new directory (name of the directory is under build.variant).

Connect the programmer to the scheme, select proper Board, Port and Programmer (AVRISP mkII in my case of stk500v2 programmer) in Arduino IDE. Click Burn Bootloader and hope for the best.

It didn’t work for me 🙁

So what now? Well, since I started Burn Bootloader I thought the .hex file should be created and it was (under bootloaders/atmega) and according to this you just need to do some manual programming.

I have used the ATmegaBOOT_168_atmega328.hex and it looks like it works ok. Well, at least OLED display works 🙂

Raspberry Pi and Wifi

 

It’s really simple:

 

apt-get install wpasupplicant

 

check with ifconfig if there is wlan0 in the list.

 

It should appear without IP address.

 

To get psk (pre shared key) type in:

 

wpa_passphrase ssidname wifipassword

 

and you will get example of the network setting, but you only need to copy bunch of characters and numbers after psk=.

 

Edit /etc/network/interfaces and change wlan0 to:

 

auto wlan0

 

iface wlan0 inet dhcp

 

    wpa-ssid ssidname

 

    wpa-psk charactersandumbersfrompsk

 

Reboot or restart network and voila. It works.

 

Resurrecting Atmel microcontroller

A 16.000 MHz (HC49/US) crystal oscillator driv...
A 16.000 MHz (HC49/US) crystal oscillator driving an Atmel AVR ATmega8 on the Arduino NG board from arduino.cc. (Photo credit: Wikipedia)

I had a ATMEGA16 with wrongly set up fuses and according to the web you can resurrect it by using external clock to XTAL1 and setting new values for fuses.

So I gave it a try:

I used Arduino Uno to set up the clock and since you need to have 1Mhz frequency I resorted to the code published on Arduino forum:

#define myOutputPin 9

void setup ()
{
 pinMode (myOutputPin, OUTPUT); 
 TCCR1A = 0;
 TCCR1B = 0;
 TCNT1  = 0;
 OCR1A = 7;   // toggle after counting to 8
 TCCR1A |= (1 << COM1A0);   // Toggle OC1A on Compare Match.
 TCCR1B |= (1 << WGM12);    // CTC mode
 TCCR1B |= (1 << CS10);     // clock on, no pre-scaler
}
void loop () { }

After that you just need to connect pin 9 of Arduino to XTAL1 of the microcontroller, set up power to it and connect the programmer.

To fix bad frequency I resorted to this post and I obviously changed device to atmega16.

After that it was simple way of setting new fuses but using fusecalc and I just set up internal RC oscillator with frequency 1Mhz.

Armadeus, kernel and rootfs

Menu configuration of a Gentoo Linux 2.6.17-ge...
Menu configuration of a Gentoo Linux 2.6.17-gentoo-r8 kernel, taken on a virtual terminal (gnome-terminal). (Photo credit: Wikipedia)

The time has came for me to create a new kernel for Armadeus (apf28) and the procedure is rather simple (if using Linux – so I resorted to virtual Linux):

1. Get the Armadeus toolset with:

git clone git://git.code.sf.net/p/armadeus/code armadeus

2. Go to the armadeus directory and you need to start the installation with starting make def28_makeconfig (for apf28 that is).

3. To set kernel use make menuconfig and make linux-menuconfig.

4. Copy kernel (apf28-linux.bin) and rootfs (apf28-rootfs.ubi) to TFTP server.

5. Reboot Armadeus developer board to BIOS (press any key while the board boots).

6. Check the ip addresses with printenv and setup proper addresses. For local IP address se ipaddr, for server IP use serverip (you might need to set up netmask or gatewayip). The syntax is similar to:

setenv ipaddr <ipaddress>

 

7. To install kernel use run update_kernel and to install rootfs use run update_rootfs.

8. Boot with boot.