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

Gertboard AVR without Arduino IDE (howto)

Sun Nov 11, 2012 4:02 pm

Thanks to the awesome combined efforts of Gordon and Gert, we're able to program the ATmega328 on the Gertboard with the Arduino IDE. I'm sure you found your way to Gordon's website for instructions. I'm not a big fan of the Arduino IDE and Arduino's form factor, so I prefer to program AVR's with a good old Makefile. No need to run X, no need to install Java, no 'restrictions' posed by Arduino's abstraction layer, just use any text editor you like and go on your merry way.

Before the Raspberry Pi and the Arduino, there was a 'catch 22' situation. An AVR could only be programmed with an already programmed AVR, or with an expensive ($30,-) hardware AVR programmer. The Arduino uses a bootloader that makes programming over serial/USB possible, but you couldn't just buy a $2,- AVR and simply get started. Since Gordon patched avrdude, we can use the Raspberry Pi as an AVR programmer. Not only to program the ATmega328p on the Gertboard, but in fact *any* AVR you fancy.

You'll have to dive in the datasheet (found here: http://www.atmel.com/Images/doc8161.pdf). There isn't much hand-holding, so it's not for the faint of heart. But it's very rewarding, and you'll actually learn something.

Here's how to get started.

No matter what, you need Gordon's patched avrdude. Go to: https://projects.drogon.net/raspberry-p ... ation-isp/ and follow instructions on how to install avrdude. You can safely skip everything else. For Raspbian, I'll repeat it here:

Code: Select all

cd /tmp
wget http://project-downloads.drogon.net/gertboard/avrdude_5.10-4_armhf.deb
sudo dpkg -i avrdude_5.10-4_armhf.deb
sudo chmod 4755 /usr/bin/avrdude
The rest of the AVR toolchain can be installed the 'regular' way:

Code: Select all

sudo apt-get install gcc-avr binutils-avr avr-libc
If you already installed the Arduino IDE earlier, you could also make CC and OBJCOPY in the Makefile below point to the correct binaries in wherever the Arduino IDE is installed. I don't think there's any harm in installing it 'twice' though.

Connect the AVR on the Gertboard to the Raspberry Pi GPIO pins as instructed in the 'Gertboard User Manual', Figure 23 (page 31). In anticipation of the blinky 'sketches' I'll post below, also connect 3 wires from AVR pins PD7, PD6 and PD5 to 3 LED's of your choice on the Gertboard. I connected them to buffer U3 (B1, B2, B3) configured as outputs.

In a new directory on the Raspberry Pi, save the following as 'Makefile' (with a capital M). It's not the most flexible Makefile you ever saw, but I tried to keep things as short and simple as possible.

Code: Select all

# ======================================================================
#  Makefile for ATmega328p on Gertboard
# ======================================================================
TARGET = blinky
SRC = blinky.c

# ======================================================================
# You shouldn't have to edit below this line
# ======================================================================
AVRDUDE = avrdude
CC = avr-gcc
OBJCOPY = avr-objcopy

MCU = atmega328p
CFLAGS = -Wall -Os -std=gnu99 -mmcu=$(MCU) -I.

AVRDUDE_PROGRAMMER = gpio
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
AVRDUDE_FLAGS = -p $(MCU) -c $(AVRDUDE_PROGRAMMER) -v

all:
	$(CC) $(SRC) -o $(TARGET) $(CFLAGS)
	$(OBJCOPY) -O ihex $(TARGET) $(TARGET).hex
	rm -f $(TARGET)

clean:
	rm -f $(TARGET).hex

install: all
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) 

fuse:
	$(AVRDUDE) $(AVRDUDE_FLAGS) -U lfuse:w:0xE7:m -U hfuse:w:0xD9:m -U efuse:w:0x07:m 

.PHONY:	all clean install fuse
If you have a virgin ATmega328p, cd to the directory you made in a terminal, and run:

Code: Select all

make fuse
This sets up the ATmega328 to run at 12Mhz. If you already followed Gordon's full instructions and executed his script 'avrsetup', you don't need to do this. You only need to do this once, anyway.

Next, copy and paste the following code in a file named 'blinky.c', and save it in the same directory:

Code: Select all

#define F_CPU 12000000L

#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
	DDRD = 0xFF;	// PORTD is output
	PORTD = 0x00;	// LED's are off
	
	for (;;) {
		PORTD ^= 0xFF;	// invert the pins 
		_delay_ms(500); // wait half a second
	}
	
	return 0;
}
Now run:

Code: Select all

make install
The application will be compiled and uploaded to the AVR, and you should see all the LED's you connected to the AVR's PORTD (PD7:PD0) blink on and off. If you followed instructions above to the letter, that's 3 LED's. They all blink at the same time.

That's all nice and well, but also pretty silly. The '_delay_ms(500);' function halts our application completely, and we're not able to do anything else while the LED's are blinking. Let's set up some interrupts, to turn this into something more fancy and flexible.

Copy and paste the following code in 'blinky.c':

Code: Select all

#define F_CPU 12000000L

#include <avr/io.h>
#include <avr/interrupt.h>

#define LED_MASK	((1 << 7) | (1 << 6) | (1 << 5))

// prototypes
void init(void);
void init_timer0(void);
void init_timer1(void);
void init_timer2(void);

// main
int main(void)
{
	init();
	
	for (;;) {
		; // nop
	}
	
	return 0;
}

// CTC interrupt for Timer 0
volatile int interval0;
volatile int counter0 = 0;
float sec0 = 0.1;

ISR(TIMER0_COMPA_vect)
{
	interval0 = (int) (sec0 * 7500); // 7500 is 1 second
	if (counter0 == interval0) {
		PORTD ^= (1 << 7);
		counter0 = 0;
	}
	counter0++;
}

// CTC interrupt for Timer 1
volatile int interval1;
volatile int counter1 = 0;
float sec1 = 0.2;

ISR(TIMER1_COMPA_vect)
{
	interval1 = (int) (sec1 * 1000); // 1000 is 1 second
	if (counter1 == interval1) {
		PORTD ^= (1 << 6);
		counter1 = 0;
	}
	counter1++;
}

// CTC interrupt for Timer 2
volatile int interval2;
volatile int counter2 = 0;
float sec2 = 0.5;

ISR(TIMER2_COMPA_vect)
{
	interval2 = (int) (sec2 * 1500); // 1500 is 1 second
	if (counter2 == interval2) {
		PORTD ^= (1 << 5);
		counter2 = 0;
	}
	counter2++;
}

// Setup
void init(void)
{
	// setup outputs for PORTD
	DDRD = LED_MASK;
	
	// init the timers
	init_timer0();
	init_timer1();
	init_timer2();
	
	// enable interrupts
	sei();
}

void init_timer0(void)
{
	// setup timer 0 for CTC
	TCCR0A |= (1 << WGM01); // MAX counter = value OCR0A (Mode 2 / CTC)

	//TCCR0B |= 0x01; // prescaler = 1;		// TCCR0B |= (1 << CS00);
	TCCR0B |= 0x02; // prescaler = 8;		// TCCR0B |= (1 << CS01);
	//TCCR0B |= 0x03; // prescaler = 64;	// TCCR0B |= (1 << CS01) | (1 << CS00);
	//TCCR0B |= 0x04; // prescaler = 256;	// TCCR0B |= (1 << CS02);
	//TCCR0B |= 0x05; // prescaler = 1024;	// TCCR0B |= (1 << CS02) | (1 << CS00);
	
	// when OCR0A = 200 and prescaler = 8, TIMER0_COMPA_vect interrupt is triggered 7500 times/sec
	// because: 12000000 / 8 / 200 = 7500;
	OCR0A = 200; // OCR0A is 8 bit, so max 255
	
	// trigger interrupt when Timer0 == OCR0A
	TIMSK0 = 1 << OCIE0A;
}

void init_timer1(void)
{
	// setup timer 1 for CTC
	TCCR1B |= (1 << WGM12); // MAX counter = value OCR1A (Mode 4 / CTC)

	//TCCR1B |= 0x01; // prescaler = 1;		// TCCR1B |= (1 << CS10);
	TCCR1B |= 0x02; // prescaler = 8;		// TCCR1B |= (1 << CS11);
	//TCCR1B |= 0x03; // prescaler = 64;	// TCCR1B |= (1 << CS11) | (1 << CS10);
	//TCCR1B |= 0x04; // prescaler = 256;	// TCCR1B |= (1 << CS12);
	//TCCR1B |= 0x05; // prescaler = 1024;	// TCCR1B |= (1 << CS12) | (1 << CS10);
	
	// setup period
	// when OCR1A = 2400 and prescaler = 8, TIMER1_COMPA_vect interrupt is triggered 1000 times/sec
	// because: 12000000 / 8 / 2400 = 1000;
	OCR1A = 2400; // OCR1A is 16 bit, so max 65535
	
	// trigger interrupt when Timer1 == OCR1A
	TIMSK1 = 1 << OCIE1A;
}

void init_timer2(void)
{
	// setup timer 1 for CTC
	TCCR2A |= (1 << WGM21); // MAX counter = value OCR2A (Mode 2 / CTC)

	//TCCR2B |= 0x01; // prescaler = 1;		// TCCR2B |= (1 << CS20);
	//TCCR2B |= 0x02; // prescaler = 8;		// TCCR2B |= (1 << CS21);
	TCCR2B |= 0x03; // prescaler = 32;	// TCCR2B |= (1 << CS21) | (1 << CS20);
	//TCCR2B |= 0x04; // prescaler = 64;	// TCCR2B |= (1 << CS22);
	//TCCR2B |= 0x05; // prescaler = 128;	// TCCR2B |= (1 << CS22) | (1 << CS20);
	//TCCR2B |= 0x06; // prescaler = 256;	// TCCR2B |= (1 << CS22) | (1 << CS21);
	//TCCR2B |= 0x07; // prescaler = 1024;	// TCCR2B |= (1 << CS22) | (1 << CS21) | (1 << CS20);
	
	// setup period
	// when OCR2A = 250 and prescaler = 32, TIMER2_COMPA_vect interrupt is triggered 1500 times/sec
	// because: 12000000 / 32 / 250 = 1500;
	OCR2A = 250; // OCR2A is 8 bit, so max 255
	
	// trigger interrupt when Timer2 == OCR2A
	TIMSK2 = 1 << OCIE2A;
}
Now, again, run:

Code: Select all

make install
You should see 1 LED blink every 0.1 seconds (10 times per second), 1 LED blink every 0.2 seconds (5 times per second) and 1 LED blink every 0.5 seconds (2 times per second). And with 'blink', I mean 'invert' here.

As it is set up now, the function ISR(TIMER0_COMPA_vect) is being called 7500 times per second. We keep track of our own variable 'counter0', that's incremented every time the function is called. When that counter0 equals 750 (1/10th of 7500) it inverts pin D7. This way you can call any function, any x amount of time by introducing other 'interval' variables.

The same goes for the other 2 'Interrupt Service Routines'. If you need other values, play around with the prescalers in the init_timerx functions, in combination with the values in the OCRxA bits. I set up all 3 timers that are available on the ATmega328p to trigger a 'compare' ISR. As you might realise, you can do a lot with just 1 timer, so it's really overkill, but here you go. I can imagine you'll want to use other timers for things like PWM, so mix and match as you see fit.

For a full (and much better) explanation of how this all works, look here: http://www.engblaze.com/microcontroller ... nterrupts/

I hope this is useful for someone.

thsBavR10
Posts: 233
Joined: Sat Jul 21, 2012 3:11 pm

Re: Gertboard AVR without Arduino IDE (howto)

Mon Nov 12, 2012 6:32 am

I hope this is useful for someone.
Yes, it is.
I had been looking for the steps to do the tradional way to programming the AVR - and now it is available.
Your description is very helpful,
many thanks,
Thomas

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

Re: Gertboard AVR without Arduino IDE (howto)

Mon Nov 12, 2012 7:08 pm

Glad to hear that, Thomas. Thanks.
Please let me know if you run into trouble, or if things are unclear.

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

Re: Gertboard AVR without Arduino IDE (howto)

Thu Nov 15, 2012 9:40 pm

Hmmm... basic math fail in setting up Timer 1. OCR1A should be 1500, not 2400 to make it trigger 1000 times/sec. That'll teach you to double check things you read on the internet. ;)

To make it up, here's code to make the 3 LED's blink at different intervals using just Timer 0. You can delete all code related to Timer 1 and Timer 2. This probably makes it a better example anyway.

Assuming init_timer0() is unchanged:

Code: Select all

volatile int counter = 0;

// this ISR is triggered 7500 times/sec
ISR(TIMER0_COMPA_vect)
{
	counter++;
	
	if (counter%750 == 0) { // every 100ms
		PORTD ^= (1 << 7);
	}
	if (counter%1500 == 0) { // every 200ms
		PORTD ^= (1 << 6);
	}
	if (counter%3750 == 0) { // every 500ms
		PORTD ^= (1 << 5);
	}
	
	if (counter == 7500) {
		counter = 0;
	}
}
But double check that too :D

JohnCrow
Posts: 25
Joined: Fri May 25, 2012 5:28 pm
Location: Lincolnshire

Re: Gertboard AVR without Arduino IDE (howto)

Sun Nov 18, 2012 2:37 pm

I have successfully programmed the AVR on my Gertboard using an AVR ISP and Flowcode software.
(I would expect you will be able to use Atmel Studio as well, though I have not tried this)

A free basic version of Flowcode can be downloaded from here.
http://www.matrixmultimedia.com/flowcode.php

Both a simple binary indication on the LEDS from an input from an ADC potentionmeter, with no interaction from the Raspberry Pi to a Binary counter reading pulses generated on the Rpi by a simple python script.
AVR.jpg
Gertboard & AVR ISP
AVR.jpg (41.99 KiB) Viewed 23839 times
Ok, I know if you don't already have one of these, you are not likely to go buy one just for the Gertboard, think they are in the region of £40.
Mine came as part of an AVR development board which I already had.
1 in 10 people understand binary, the other one doesn't

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

Re: Gertboard AVR without Arduino IDE (howto)

Sun Nov 18, 2012 4:14 pm

@JohnCrow: Once you have a .hex-file compiled (be it with Arduino IDE, Atmel AVR Studio, Flowcode or what-have-you) either on the Raspberry Pi itself or another machine, that hex-file can be uploaded with the Raspberry Pi to the AVR on the Gertboard with Gordon's patched avrdude.

For example, when you have compiled 'blinky.hex':

Code: Select all

avrdude -p atmega328p -c gpio -v -U flash:w:blinky.hex
This way, you could use Flowcode or Atmel Studio on another PC without buying a programmer. Use the Raspberry Pi just to upload the file.

Thanks for sharing!

thsBavR10
Posts: 233
Joined: Sat Jul 21, 2012 3:11 pm

Re: Gertboard AVR without Arduino IDE (howto)

Mon Nov 19, 2012 12:53 pm

panik wrote:Hmmm... basic math fail in setting up Timer 1. OCR1A should be 1500, not 2400 to make it trigger 1000 times/sec. That'll teach you to double check things you read on the internet. ;)
...
But double check that too :D
Sorry, I've read your adjustment yesterday.
I'm a starter in programming the AVR, so this also is very helpful for me.
Simple math, but I have to understand the relationsship.

If I change

Code: Select all

   if (counter%3750 == 0) { // every 500ms
      PORTD ^= (1 << 5);
   }
   if (counter == 7500) {
      counter = 0;
to

Code: Select all

   if (counter%3750 == 0) { // every 500ms
      PORTD ^= (1 << 5);
   }
   PORTD ^= (1 << 4);
   if (counter == 7500) {
      counter = 0;
then i should get a frequency of 7500Hz?

Seems, that errors are made-up for better learning.
Thanks! ;-)

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

Re: Gertboard AVR without Arduino IDE (howto)

Mon Nov 19, 2012 6:51 pm

The 'ISR(TIMER0_COMPA_vect)' is triggered 7500 times per second (that's how it's set up in 'void init_timer0(void)'). So yes, that's 7500Hz. In your case, it inverts pin D4 every 1/7500th of a second since that always happens every time the ISR is triggered.

To be absolutely clear, the calculation mistake I made only affects Timer 1. You probably figured that out, but it doesn't hurt to correct it correctly:

Code: Select all

void init_timer1(void)
{
   [...]
   // when OCR1A = 2400 and prescaler = 8, TIMER1_COMPA_vect interrupt is triggered 1000 times/sec
   // because: 12000000 / 8 / 2400 = 1000;
   OCR1A = 2400; // OCR1A is 16 bit, so max 65535
   [...]
}
Should be:

Code: Select all

void init_timer1(void)
{
   [...]
   // when OCR1A = 1500 and prescaler = 8, TIMER1_COMPA_vect interrupt is triggered 1000 times/sec
   // because: 12000000 / 8 / 1500 = 1000;
   OCR1A = 1500; // OCR1A is 16 bit, so max 65535
   [...]
}
See how I also made a mistake in the first comment in the init_timer2() function, where I'm still talking about Timer 1. That should be Timer 2, but the code itself is correct (that is, I didn't spot any extra mistakes). As stated, you could also delete or comment out everything related to Timer 1 and Timer 2. They don't do anything useful anymore in the example.
thsBavR10 wrote:Seems, that errors are made-up for better learning.
Mine were an exemplary case of 'just being an idiot', but in general that's very true. I always learn the most when making mistakes (and fixing them).

By the way, the forums on http://www.avrfreaks.net/ are usually a good resource for code snippets and tutorials. That helps too ;)

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

Re: Gertboard AVR without Arduino IDE (howto)

Thu Dec 06, 2012 4:40 pm

There's another option: writing Arduino sketches, without using the Arduino IDE. It saves 100MB+ on the SD card, and the need to run X (no Java!). A guy named Paulo Torrens has some code on github that does this. Find that here: https://github.com/takanuva/arduino-makefile

I took his Makefile, replaced the Arduino library with the more modern 1.0.2 version, and made it behave nicely with the AVR on the Gertboard. I must say I only tested it with some blinky lights, but I don't foresee problems with other functionality.

To get it to work, follow instructions in the opening post of this topic (install Gordon's patched avrdude, and apt-get install the avr toolchain). Edit src/main.cpp (this is your 'sketch'), and run 'make upload'. Currently, it blinks pin D7.

After uploading, the gpio pins are unexported so they don't mess with the SPI pins. For this to work, you also need to install Gordon's WiringPi (it uses the 'gpio' app). I hope Gordon finds the time to add this functionality to avrdude itself. Until then, this will do. Alternatively, disconnect and reconnect the Gertboard from the Pi if these pins give you trouble.

The code for the USB functionality for newer Arduino's is removed. See attachment.
Attachments
arduino-gertboard-makefile.zip
Makefile
(61.44 KiB) Downloaded 472 times

User avatar
kulminaator
Posts: 23
Joined: Mon Aug 06, 2012 8:55 am
Location: estonia

Re: Gertboard AVR without Arduino IDE (howto)

Thu Jan 03, 2013 11:14 am

I'm wondering if i'm missing out here on something ... but assuming that i already have the atmega chip assembled to another board (and having the spi connector there), can't i just use the spi connections from the rpi's own gpio port and skip the whole gertboard ? (i don't have one and i don't really need it either (and just like the avr programmer, it costs money too ...)).

ps. great work. when i saw the open connections on rpi-s board itself i realized pretty quickly that someone will come along and do what you did with it

User avatar
kulminaator
Posts: 23
Joined: Mon Aug 06, 2012 8:55 am
Location: estonia

Re: Gertboard AVR without Arduino IDE (howto)

Thu Jan 03, 2013 1:53 pm

answering to my own question here with a link: http://blog.stevemarple.co.uk/2012/07/a ... using.html ... looks like someone has done it a long while ago already.

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

Re: Gertboard AVR without Arduino IDE (howto)

Thu Jan 03, 2013 4:02 pm

Just to confirm: Nope, you're not missing anything :) Nothing's new or magic. Gordon did all the work. Steve also has some buffering going on there. Nice, but not necessary if you're careful and power the AVR with 3V3. I did mention it in the OP, but I admit it's hard to find in that wall of text:
Since Gordon patched avrdude, we can use the Raspberry Pi as an AVR programmer. Not only to program the ATmega328p on the Gertboard, but in fact *any* AVR you fancy.

oversteer
Posts: 1
Joined: Mon Mar 25, 2013 10:53 am

Re: Gertboard AVR without Arduino IDE (howto)

Mon Mar 25, 2013 10:57 am

Just a little tip for anyone who copies in the Makefile and gets an error about "Missing separator" on line 22

Makefiles use tabs, not spaces, but probably the way the forum software presents the Makefile means spaces are used.

Just copy and paste the file into your favourite text editor, and replace the initial spaces in the 6 indented lines with tabs.

Thanks for a comprehensive guide. My Raspberry Pi uses a network share to read the files so I don't need an IDE on the Pi at all.

User avatar
gordon@drogon.net
Posts: 1979
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Gertboard AVR without Arduino IDE (howto)

Mon Mar 25, 2013 1:10 pm

Had other things going on recently, but I'm in the middle of writing some more stuff up for the Gertboard (and Arduino + Pi in general) and I do have a full "wiring" replacement for Arduino that runs from a traditional command-line environment - just need some time to publish it. It also features a little interrupt driven task scheduller, as well as all your usual digitalWrite(), pinMode() etc. calls.

Just need a bit more time... Hang in there!

-Gordon
--
Gordons projects: https://projects.drogon.net/

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

Re: Gertboard AVR without Arduino IDE (howto)

Mon Mar 25, 2013 5:02 pm

We're all looking forward to that Gordon! I'm especially curious about that scheduler. Every time I use the Arduino IDE and libraries, I find something else to dislike.

Thanks for mentioning the tab/spaces issue, oversteer. Indeed, the forum software converted the tabs.

A couple of months ago, I made a cmake project of the arduino makefile I posted as an attachment. I hesitated to post it, because it's mostly untested (only with the hardware I have, which is an Arduino Duemilanove, a GertBoard, and an 'ATmega32u4 on a breakoutboard'). Also, I'm really unsure about some of the 'cmake-isms' I used.

For the interested/adventurous:
https://github.com/panikrpi/arduino_cmake

In the top-level CMakeLists.txt on line 20, you'll have to edit 'set(BOARD_TYPE xxx)', where 'xxx' is:
standard: Arduino Duemilanove
rpi: GertBoard, or using the Raspberry Pi to program Arduino-compatible custom boards
leonardo: Arduino Leonardo (untested!)
custom: My own custom breakoutboard (using the default Atmel dfu bootloader)

I had to edit a few lines in some of the Arduino libraries to get it to compile (no luck on WiFi I believe, but it's been a while).

I'm using this whenever I want to use the Arduino library for quick and dirty prototyping, but you're probably better off waiting for Gordon's 'Wiring replacement'. At least Gordon seems to know what he's doing :D

docjim
Posts: 9
Joined: Thu Mar 13, 2014 1:29 am

Re: Gertboard AVR without Arduino IDE (howto)

Thu Mar 13, 2014 1:47 am

I'm trying to setup my Gertboard and RPi as decribed in this article but I'm having trouble getting the instruction 'make fuse' to work using the Makefile listed.
I get the diagnostic: Makefile line 22: missing separator

I've checked, using a copy of the Makefile listing directly from this article, and just can't see any difference between my code as run and that listing.

Can anyone help?

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

Re: Gertboard AVR without Arduino IDE (howto)

Thu Mar 13, 2014 3:48 pm

Make sure to replace all spaces (' ') before the lines (if there are any) with a single tab.

That is, the words 'all:', 'clean:', 'install:' and 'fuse:' should start at the beginning of a line, the commands below them with a single tab.

Forum screws with formatting. Sorry about that.
Microcontroller addon boards and software for Raspberry Pi A+/B+/Pi2:
- ARMinARM: ARM Cortex-M3 (STM32)
- AVRPi: ATmega32U4 & ATmega328 ("Arduino")
http://www.onandoffables.com

docjim
Posts: 9
Joined: Thu Mar 13, 2014 1:29 am

Re: Gertboard AVR without Arduino IDE (howto)

Fri Mar 14, 2014 3:33 pm

Doh.......!
That's the first thing I learnt about Makefiles - but now we're cooking on gas.
Thanks a million.

Now, could you do the same thing for ChipKIT Pi? ....and Embedded Pi (at graduate level, of course)?

There appear to be a lot of 'arbitrary' definitions in the c code. Presumably there are equivalents for these other chips. Where do they come from? How do I learn more?

Sorry - sudden excess of enthusiasm after weeks of struggling with embedded technology - but it does appear, at last, that it is a little more than heaps of sand soldered onto bits of plastic board!
Thanks again.

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

Re: Gertboard AVR without Arduino IDE (howto)

Fri Mar 14, 2014 4:16 pm

docjim wrote:There appear to be a lot of 'arbitrary' definitions in the c code. Presumably there are equivalents for these other chips. Where do they come from? How do I learn more?
I'm assuming with 'arbitrary definitions' you mean the names of the registers (stuff like PORTD, DDRD, but also TCCR0A and OCR0A etcetera). These are the names of the registers that you fill with certain values to make the chip behave a certain way.

For AVR chips, these names and values are found in the datasheet. For the ATmega328p on the Gertboard, the datasheet is on this page: http://www.atmel.com/devices/atmega328.aspx Most of what you need to know is in a single datasheet for that single chip. But there are some 'appnotes' that contain some useful information as well.

In comparison, the Arduino library is 'just' an abstraction layer that defines high level functions around poking these registers. It might be interesting to have a look around the source code. The core is here: https://github.com/arduino/Arduino/tree ... es/arduino The libraries here: https://github.com/arduino/Arduino/tree ... /libraries
docjim wrote:Now, could you do the same thing for ChipKIT Pi? ....and Embedded Pi (at graduate level, of course)?
For ARM cortex microcontrollers (like the cortex M3 on the Embedded Pi) the information is spread out over multiple (dozens) of datasheets and appnotes. So there it's a bit harder to find what you need. Here's a good start: http://www.st.com/web/en/catalog/mmc/FM141/SC1169

At the moment, I'm working hard to try and wrap my head around the 32 bit cortex M3 and M4 line of microcontrollers. They're really powerful (fast + large memory) and have a lot of peripherals. Really interesting, but also a different beast from the rather 'simple' (in comparison) 8 bit AVR chips.

I never worked with PIC, so there's not much I can say about that.

(Also, be sure to read the rest of this topic. I made some rookie mistakes in the code in the topic start. I can't edit the posts anymore.)

docjim
Posts: 9
Joined: Thu Mar 13, 2014 1:29 am

Re: Gertboard AVR without Arduino IDE (howto)

Sat Mar 15, 2014 10:51 am

Thanks again.
Yes, that's exactly what I wanted: a Rosetta stone to translate from gibberish to common-or-garden technospeak (rather than from complete gibberish to Englese technospeak). But it's going to take me a minute or two to get my head round this......

Sounds like I'll have to go through the pain barrier again if I want to extend into ChipKIT and Embedded Pi territory. For my intended application, however, I'm beginning to think it might be simpler just to use a second RPi rather than any of these 'embedded' cpus: equipment costs are not too dissimilar and the RPi can be kitted out with the OS of your choice (in which I can be very fluent - creative, even). And if you take into account the extended development times needed to deploy embedded technology, it seems to me there is no contest.

But best of luck with your endeavours: more strength to your ARM!

Soprano15
Posts: 1
Joined: Tue Mar 15, 2016 11:09 pm

Re: Gertboard AVR without Arduino IDE (howto)

Tue Mar 15, 2016 11:41 pm

Hi,
I need help to write a code using either Pi Terminal or other IDE to drive the GPIO of my Pi.

I have visited the web but i could not find one that give me all step. I have my Pi already configured. I wanted to upload some images but they are too big.
Once i am able to flash LED connected to the GPIO, I can drive a transistor to switch a relay then I can move on in figuring out how to do IoT.

Please help me I really need your help.

Thanks in advance

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

Re: Gertboard AVR without Arduino IDE (howto)

Wed Mar 16, 2016 7:44 pm

Hi Soprano15. Welcome to the forum!
I need help to write a code using either Pi Terminal or other IDE to drive the GPIO of my Pi.
I don't think your question has a lot to do with AVR's or the Gertboard specifically. If you post a new, separate topic in the general section there's a bigger chance that the right people will see it. The advice you'll get will be better. This topic is a bit of a dark corner in a back alley compared to the ones in the general section.

After deciding the programming language you want to use, there's probably a choice of libraries available to use the GPIO pins of the Pi. Using the terminal and/or an IDE is another decision. You have a lot of options.

I hope this helps somewhat.
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 “Gertboard classic”

Who is online

Users browsing this forum: No registered users and 1 guest