7

I currently do most of my AVR work on breadboards, but the large variety of Arduino shields and code out there makes me wonder if I'm not beating my head against the wall sometimes, and looking up port to pin mappings both wastes time and slows me down. Is there any convenient way to adapt AVRs (other than those pin-compatible with current Arduinos) to Arduino shields?

  • Are you asking: Is there a way to make wiring a bare microprocessor to a shield easier? – Cybergibbons Mar 24 '14 at 7:56
  • 1
    @Cybergibbons: That is exactly what I'm asking. – Ignacio Vazquez-Abrams Mar 24 '14 at 7:56
  • 1
    To that one, I don't have an answer. Honestly, my way of working around this is to almost exclusively use I2C or SPI devices so there are only a few pins to remember. – Cybergibbons Mar 24 '14 at 8:14
  • @JarrodRoberson You have replaced the AVR in the title with microprocessor, AVRs are not microprocessors, they are microcontrollers which is a microprocessor+memory+peripherals etc. You have also removed the word Arduino from the shields but the question refers to Arduino shields, not shields in general. – alexan_e Mar 24 '14 at 18:08
  • @alexan_e read the OP comments right about yours ... – user278 Mar 24 '14 at 18:14
4

You can make adapter boards (one for each mcu model).

The bottom side (male headers) would plug to the breadboard and the upper side would have female headers with the same pinout as an Arduino board (female hearers placed in the appropriate positions to match Arduino shields).

Such a board shouldn't be difficult to design.

Here is an image that resembles what I describe

enter image description here

It would adapt the pinout of a bare AVR to the pinout of a typical Arduino so that shields can by directly plugged on top of it.


Also a pinout diagram may come handy to speedup things when you use a bare chip with Arduino code.
(image source) enter image description here

Another similar solution is a small printed sticker placed on top of the AVR
(image source)

enter image description here

  • +1 for the didatic effect of the adapter board picture AND VERY TIDY breadboarding. – Ricardo Mar 24 '14 at 14:08
  • @Ricardo Although I do agree it's a good picture, it is from another site (source listed). Otherwise, great answer! BTW: Be cautious if the shield connects to ICSP... the Ethernet r.3 does to add Mega compatibility. – Anonymous Penguin Mar 25 '14 at 0:25
2

The Arduino-way of doing that is making a lookup table that translates pin number to PORTn / DDRn / PINn SFR and the related bit. You can use the same trick and make GPIO pins count in a convenient way as they are in the package. Only special peripherals (like SPI / PWM) cannot be accounted for in this way because they are hard wired to a pin.

A good start is the below Arduino.h library sniplet if you want to re-use that concept.

// Get the bit location within the hardware port of the given virtual pin.
// This comes from the pins_*.c file for the active board configuration.

#define analogInPinToBit(P) (P)

// On the ATmega1280, the addresses of some of the port registers are
// greater than 255, so we can't store them in uint8_t's.
extern const uint16_t PROGMEM port_to_mode_PGM[];
extern const uint16_t PROGMEM port_to_input_PGM[];
extern const uint16_t PROGMEM port_to_output_PGM[];

extern const uint8_t PROGMEM digital_pin_to_port_PGM[];
// extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];
extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];
extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];

// Get the bit location within the hardware port of the given virtual pin.
// This comes from the pins_*.c file for the active board configuration.
// 
// These perform slightly better as macros compared to inline functions
//
#define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )
#define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )
#define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
#define analogInPinToBit(P) (P)
#define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) )
#define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) )
#define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) )

The pinMode, digitalWrite and digitalRead functions are defined in /usr/share/arduino/hardware/arduino/cores/arduino/wiring_digital.c which can be used for further inspiration.

  • While this answer covers the software part, my question actually asks about the hardware part. – Ignacio Vazquez-Abrams Mar 24 '14 at 7:14
  • @IgnacioVazquez-Abrams can you elaborate a bit more in your question then? Not sure if I understand what you're asking. – jippie Mar 24 '14 at 7:28
  • I have bare AVR chips, and I want to use them with existing Arduino shields without having to add a couple dozen jumper wires. – Ignacio Vazquez-Abrams Mar 24 '14 at 7:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.