User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

AVRPi: ATmega32U4 and ATmega328 addon boards ("arduino")

Sun Apr 05, 2015 8:47 pm

Hi,

I'm introducing 2 Atmel AVR microcontroller addon boards for the Raspberry Pi Model A+/B+/Pi2. One of them with an ATmega32U4 (AVRPi-32U4), the other one with an ATmega328p (AVRPi-328).

AVRPi-32U4
Image
The AVRPi-32U4 runs on [email protected] and is Arduino Leonardo (software) compatible, but it also runs Dean Camera's LUFA library very well.

The ATmega32U4 is programmable as a USB device. This is useful if you want a USB HID [device] that can be controlled by the Raspberry Pi or yourself such as a keyboard, joystick, mouse, midi, audio, virtual serial or generic HID.

AVRPi-32U4 has a USB connector that you can connect to the Raspberry Pi itself or an external USB host like a laptop, desktop or other Raspberry Pi. Now you can control anything that takes commands from a device connected to the USB port. Send high level commands from the Raspberry Pi to the AVRPi (over the internet if you want) which sends USB commands from the AVRPi to the USB host you want to control.

AVRPi-328
Image
The AVRPi-328 has the familiar ATmega328p on it like the Arduino Uno, Gertboard, Gertduino, RasPiO Duino and other boards. It also runs on 3.3V, but you decide how fast. Choose between 8, 12 or 16MHz (or any other speed, each has its pros and cons).

All Raspberry Pi GPIO pins are broken out on the top, and the ATmega328p GPIO pins at the bottom of the board in a convenient, single row of 25 pins. It's very easy to solder 'shields' for your project. Everything aligns to the default 0.1" grid. There are 13 rows of free holes between the pins on the AVRPi-32U4, and 14 rows of free holes on the AVRPi-328p.

Software examples
Both boards are programmable in the Arduino IDE, but also with a Makefile and your favourite text-editor. The software comes with plenty examples to compile Arduino 'sketches' (just regular c++ files, really) with the Arduino-Makefile. You should seriously check that out. After that you don't want to go back to the Arduino IDE.

For the AVRPi-32U4 there's a LUFA directory with ready-to-compile examples. There's also a 'testblinky' using a generic Makefile that's easy to adapt for your own 'plain asm/c/c++' projects.

avrpi-tools
I have script files on github that make it easy to set everything up. Get the 'avrpi-tools' repository, run ./setup, choose 'e)install everything in 1 easy step', and 'f) set fuses for [your board]'. That's basically it. The menu for the AVRPi-32U4 has the most options:

Code: Select all

#######################################################################
#                          avrpi-tools                                #
#######################################################################

  Install everything in 1 easy step:
    e)    Arduino IDE/libs + avrdude

  Custom install:
    a)    apt-get dependencies and AVR toolchain (without Arduino)
    b)    install pre-compiled avrdude binary
    c)    compile + install avrdude from source
    p)    patch arduino

  First time - fuses and test:
    s)    change to different board/chip
    f)    set fuses for atmega32u4 on avrpi32u4 board
    t)    make + upload test/blinky.hex
    o)    install Arduino Caterina bootloader
    g)    install Atmel DFU bootloader

  Optional extra:
    x)    uninstall wiringPi
    u)    uninstall avrpi tool
    d)    install dfu-programmer

  Software and projects:
    m)    install Arduino-Makefile
    l)    install LUFA-AVRPI32U4

    q)    quit

Enter your choice:
In the setup menu you can choose what board you have, install a variety of other tools and projects or do a custom install.

The 'avrpi' tool makes it easier to control the board from the Raspberry Pi (reset, flash firmware, start serial terminal etcetera).

Code: Select all

[email protected] ~ $ avrpi -h
Usage: avrpi [options] <filename>

[options] is any of the following:
  -f <file>   flash <file>    flash <file> to avrpi board
  -u <file>   upload <file>   upload <file> using caterina bootloader
  -d <file>   upload <file>   upload <file> using Atmel DFU bootloader
  -i          info            show info about chip
  -r          reset           reset AVR chip
  -b          bootloader      enter bootloader mode (HWB fuses set)
  -m          minicom         start minicom on /dev/ttyAMA0 @ 9600
  -n          screen          start screen on /dev/ttyAMA0 @ 9600
  -h          help            show this info
  -c          config          edit avrpi config file
  -s          show            show config

avrdude and arduino
The software comes with the latest avrdude-6.1 with linuxgpio enabled (no patches to the original source code other than having gpio pin 8,9,10,11 set in /etc/avrdude.conf).

When using the Arduino IDE or Arduino-Makefile, you can choose the following compatible boards that are programmable with avrdude's linuxgpio interface:

Code: Select all

BOARD_TAG = avrpi328_8     # AVRPi-328 ATmega328 @ 8 MHz
BOARD_TAG = avrpi328_12    # AVRPi-328 ATmega328 @ 12 MHz
BOARD_TAG = avrpi328_16    # AVRPi-328 ATmega328 @ 16 MHz
BOARD_TAG = avrpi32u4_8    # AVRPi-32U4 ATmega32U4 @ 8 MHz
BOARD_TAG = avrpi32u4_8cat # AVRPi-32U4 ATmega32U4 @ 8 MHz Caterina bootloader
BOARD_TAG = gert168        # Gertboard ATmega168 @ 12 MHz
BOARD_TAG = gert328        # Gertboard ATmega328 @ 12 MHz
BOARD_TAG = gertduino48    # Gertduino ATmega48 @ 8 MHz
BOARD_TAG = gertduino328   # Gertduino ATmega328 @ 16 MHz
BOARD_TAG = raspioduino    # RasPiO Duino ATmega328 @ 12 MHz
This is taken from the 'board.mk' file in the 'src/arduino-mk/' directory. These are the boards currently added to the Arduino 'boards.txt' file. If you have a Gertboard, Gertduino or RasPiO Duino you can also use the avrpi-tools software to make your life easier.

All documentation is here: http://www.onandoffables.com
Install everything from this setup script: https://github.com/onandoffables/avrpi-tools

Available now (as a kit) on Tindie: https://www.tindie.com/stores/onandoffables/
Microcontroller addon boards and software for Raspberry Pi A+/B+/Pi2:
- ARMinARM: ARM Cortex-M3 (STM32)
- AVRPi: ATmega32U4 & ATmega328 ("Arduino")
http://www.onandoffables.com

User avatar
DougieLawson
Posts: 36816
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: AVRPi: ATmega32U4 and ATmega328 addon boards ("arduino")

Sun Apr 05, 2015 8:58 pm

Does a regular Arduino Uno hardware shield fit your board? If not then it's mostly useless.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: AVRPi: ATmega32U4 and ATmega328 addon boards ("arduino")

Sun Apr 05, 2015 9:28 pm

DougieLawson wrote:Does a regular Arduino Uno hardware shield fit your board? If not then it's mostly useless.
It's trivial to design a converter board that makes it possible to plug them in if there's demand. But I don't think there is demand.

There is demand on paper of course, but in practice the Arduino shields often aren't as compatible as they look. Try to fit an Arduino Uno compatible shield on an Arduino Leonardo for example. And the number of 0.1" compatible sensor/motordriver/whatnot breakoutboards available in 2015 outweigh the number of available Arduino shields. Where '0.1" compatible' is 'the rest of the world compatible', I might add.

With 'useless', are you saying that any official Arduino that doesn't have the shield pinout (Esplora, Micro, Lilypad, Fio, Mini) is also useless?
Microcontroller addon boards and software for Raspberry Pi A+/B+/Pi2:
- ARMinARM: ARM Cortex-M3 (STM32)
- AVRPi: ATmega32U4 & ATmega328 ("Arduino")
http://www.onandoffables.com

jwatte
Posts: 203
Joined: Sat Aug 13, 2011 7:28 pm

Re: AVRPi: ATmega32U4 and ATmega328 addon boards ("arduino")

Sun Apr 05, 2015 9:44 pm

That was my thought as well -- the Arduino form factor would be the #1 thing someone would be looking for in a case like this.

Also, why 8 MHz? There's 5V available on the RPi header, so running at 16 MHz (like the Arduino) is probably a better match to people's expectations.

User avatar
DougieLawson
Posts: 36816
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: AVRPi: ATmega32U4 and ATmega328 addon boards ("arduino")

Sun Apr 05, 2015 10:28 pm

panik wrote: With 'useless', are you saying that any official Arduino that doesn't have the shield pinout (Esplora, Micro, Lilypad, Fio, Mini) is also useless?
The whole reason for the Uno is to host a multitude of hardware add-ons that are driven by the Atmel382. If your board doesn't do that then I'll stick with plugging in a regular 5V0 Arduino as a USB device.

The Arduberry got it 90% right, you can fit shields on their board (as long as they don't need the ICSP header).
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: AVRPi: ATmega32U4 and ATmega328 addon boards ("arduino")

Sun Apr 05, 2015 10:30 pm

jwatte wrote:That was my thought as well -- the Arduino form factor would be the #1 thing someone would be looking for in a case like this.
The only reason I added ("arduino") in the topic title is so that people would know what they are, or could be. Even though they strictly aren't Arduinos, but Atmel AVR addon boards for the Raspberry Pi Model A+/B+/Pi 2 that also happen to be able to run the Arduino library. Possibly. Not necessarily.

The world is slowly but steadily moving away from the Arduino form factor, and back to the 0.1" compatible standard where we came from and that always kept existing in the mean time. Outside the Arduino bubble.
jwatte wrote:Also, why 8 MHz? There's 5V available on the RPi header, so running at 16 MHz (like the Arduino) is probably a better match to people's expectations.
The world is also moving away from 5V. Most modern sensors and chips take 3.3V. The slower speed is a trade off. That's exactly the reason why there are official Arduinos running on [email protected] To make it easier to connect your peripherals. The Arduino Due (while still full speed) also has 3.3V GPIOs.

It's only going to get 'worse' in the future. You can keep fighting with voltage level conversion, but it's much easier to accept it. Digital logic doesn't need high voltages.

Also, 16MHz ('like the Arduino') is an arbitrary number. It may make perfect sense to select an 11.0592MHz crystal because you want 0.0% error rate on the USART. Or some other speed because you can select just the right prescaler for your timers. That said, the ATmega328p reportedly can be 'overclocked' to 16MHz quite well.

On the AVRPi-32U4, it's either 8MHz or 16MHz if you want to use the USB capability and I didn't want the overclock.

People's expectations are going to change as well. We managed to get used to the 3.3V GPIO pins on the Raspberry Pi. We are also getting used to the 3.3V GPIO on the Arduino Due. That's what we do best as a species. Adapt to our surroundings. Especially if adapting makes things easier.
Microcontroller addon boards and software for Raspberry Pi A+/B+/Pi2:
- ARMinARM: ARM Cortex-M3 (STM32)
- AVRPi: ATmega32U4 & ATmega328 ("Arduino")
http://www.onandoffables.com

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: AVRPi: ATmega32U4 and ATmega328 addon boards ("arduino")

Sun Apr 05, 2015 10:47 pm

DougieLawson wrote:
panik wrote: With 'useless', are you saying that any official Arduino that doesn't have the shield pinout (Esplora, Micro, Lilypad, Fio, Mini) is also useless?
The whole reason for the Uno is to host a multitude of hardware add-ons that are driven by the Atmel382. If your board doesn't do that then I'll stick with plugging in a regular 5V0 Arduino as a USB device.

The Arduberry got it 90% right, you can fit shields on their board (as long as they don't need the ICSP header).
If using existing 5.0V only Arduino shields is important to you, then I recommend you do what you propose. Those are probably your best options.

If you want more flexibility and choice, you can buy any sensor/chip breakout board with 0.1" aligned holes somewhere and it'll fit on a piece of protoboard. You'll also have access to all the Raspberry Pi GPIO pins.
Microcontroller addon boards and software for Raspberry Pi A+/B+/Pi2:
- ARMinARM: ARM Cortex-M3 (STM32)
- AVRPi: ATmega32U4 & ATmega328 ("Arduino")
http://www.onandoffables.com

jwatte
Posts: 203
Joined: Sat Aug 13, 2011 7:28 pm

Re: AVRPi: ATmega32U4 and ATmega328 addon boards ("arduino")

Mon Apr 06, 2015 12:15 am

Then why would I want an AVR board at all? The Pi already has SPI, I2C, USART, and GPIO.

The reason to use AVR 8-bit is to re-use existing Arduino libraries and shields. Else you might as well go with a more capable chip like the M4 used on the Teensy 3.1. BTW, the $20 Teensy is a great 3.3V, 5V tolerant, Arduino IDE compatible device. (Another good ARM board is the $10 OpenCM-9.04.)

So, I guess I don't yet see what particular hole your design fills. Why do I want this particular implementation?

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: AVRPi: ATmega32U4 and ATmega328 addon boards ("arduino")

Mon Apr 06, 2015 1:24 am

jwatte wrote:Then why would I want an AVR board at all? The Pi already has SPI, I2C, USART, and GPIO.
I think we can all agree that any 'realtime' microcontroller makes a great addition to a Pi running a 'less predictable' Linux. ADC, DAC, PWM, USB HID, more GPIO, all that jazz. But I also agree that the Raspberry Pi by itself and all the excellent libraries that are developed for it over the past years kick serious ass.
jwatte wrote:The reason to use AVR 8-bit is to re-use existing Arduino libraries and shields. Else you might as well go with a more capable chip like the M4 used on the Teensy 3.1. BTW, the $20 Teensy is a great 3.3V, 5V tolerant, Arduino IDE compatible device. (Another good ARM board is the $10 OpenCM-9.04.)
Or the ARMinARM board with the Cortex-M3 I also sell if you need the power. But only if you really need it because an 8, 12 or 16 MHZ AVR might also do the trick. Maybe not. Depends.

I totally agree that being able to use existing libraries (be it Arduino, LUFA, Espruino, libmaple, libopencm3, eLua, you name it) is extremely important. But 'AVR8' does not equal 'Arduino' automatically. And it certainly does not equal 'Arduino shield form factor'. It may equal 'LUFA', or 'straight c'. On another frequency than "16MHz, because I heard that I should have that". Nothing weird or scary, just 'not Arduino'.

Also, 'AVR8' and even 'Arduino' absolutely does NOT equal 'Arduino IDE'. Friends don't let friends use the Arduino IDE. The Arduino library is a great thing, but there are way better options of compiling firmware using the Arduino libraries. Arduino-Makefile.
jwatte wrote:So, I guess I don't yet see what particular hole your design fills. Why do I want this particular implementation?
All of the microcontroller awesomeness described above, in a form factor that's tightly coupled with the Raspberry Pi which provides the high level applications, network access, audio, GPU and all other greatness.

Because form factor is important. To have all Raspberry Pi and AVR GPIO pins easily accessible on a standard 0.1" grid. So that it's compatible with what else is available in the world. Because compatibility is important.
Microcontroller addon boards and software for Raspberry Pi A+/B+/Pi2:
- ARMinARM: ARM Cortex-M3 (STM32)
- AVRPi: ATmega32U4 & ATmega328 ("Arduino")
http://www.onandoffables.com

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: AVRPi: ATmega32U4 and ATmega328 addon boards ("arduino")

Fri Apr 10, 2015 6:06 pm

To make it easier to wrap your head around the concept, flip it upside down and consider it to be an "Arduino with a Raspberry Pi shield". The AVRPi plays the "Arduino", you provide the Raspberry Pi and cheap protoboard in the size you want.

Image

Even though the Raspberry Pi is the 'top shield', all Raspberry Pi pins are still available in an easy accessible straight line on one side, all AVR pins in straight line on the other side. Enough power and ground on both sides.

Pretty sturdy too. No wobbles. Everything is either bolted, soldered and/or plugged in with rows of 25 pin headers. Still easy to (dis)assemble.

Use a standard 'euro' size protoboard and the whole contraption fits nicely in a standard 'euro' casing.
panik wrote:
DougieLawson wrote:Does a regular Arduino Uno hardware shield fit your board? If not then it's mostly useless.
It's trivial to design a converter board that makes it possible to plug them in if there's demand. But I don't think there is demand.
I've been experimenting with an "Arduino pinout shield cap":
Image
While it works as expected with a small selection of existing Arduino shields (the ones compatible with the newer Arduino Due), I feel it gives unrealistic expectations and more often than not it leads to disappointment. There are just too many incompatibilities and workarounds needed.

But above all: it's not going to add anything to the landscape to make the world a better place, so as it is now I'm not going to sell them. No matter how profitable it may be.

The 'proto caps' I sell for the ARMinARM board also fit on the AVRPi-32U4 board. They are basically protoboards that fit the Pi perfectly (but as you know, different sizes of protoboard can be bought on eBay for next to nothing).
Microcontroller addon boards and software for Raspberry Pi A+/B+/Pi2:
- ARMinARM: ARM Cortex-M3 (STM32)
- AVRPi: ATmega32U4 & ATmega328 ("Arduino")
http://www.onandoffables.com

Return to “HATs and other add-ons”