RobinGreig
Posts: 13
Joined: Sat Oct 27, 2012 2:40 am
Location: Calgary, Alberta, Canada

Programming the Gertduino with c

Wed Jan 07, 2015 4:17 am

Hello all;
I've been looking for links to help me learn how to program the Gertduino using c, rather than the Arduino IDE.
Can someone point me towards some good tutorials that would also cover how to setup the serial communication between the Gertduino and the Raspi using c as well?

Thanks!
Robin Greig
http://www.robingreig.ca
www.robingreig.ca
Arduino + Raspi + Amateur Radio enthusiast since 2012
VE6RBN Canadian Amateur Radio Callsign

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

Re: Programming the Gertduino with c

Wed Jan 07, 2015 8:47 am

The Arduino IDE is just a java wrapper for the avr gcc compiler.

There is a script ino http://inotool.org which runs from the command line but I don't know if you can get that running with the Gertduino.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

RobinGreig
Posts: 13
Joined: Sat Oct 27, 2012 2:40 am
Location: Calgary, Alberta, Canada

Re: Programming the Gertduino with c

Wed Jan 07, 2015 2:21 pm

Thanks Dougie;

That looks very interesting and I'll look into that and report back on how is works with the Gertduino.

The Arduino IDE is fine, but I do enjoy working via the command line (and usually use ssh to access my raspi's)

Robin
DougieLawson wrote:The Arduino IDE is just a java wrapper for the avr gcc compiler.

There is a script ino http://inotool.org which runs from the command line but I don't know if you can get that running with the Gertduino.
www.robingreig.ca
Arduino + Raspi + Amateur Radio enthusiast since 2012
VE6RBN Canadian Amateur Radio Callsign


rotwang
Posts: 237
Joined: Sat Dec 07, 2013 1:12 pm

Re: Programming the Gertduino with c

Wed Jan 07, 2015 3:36 pm

In the past I have used cduino project http://forum.arduino.cc/index.php?topic=59575.0

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

Re: Programming the Gertduino with c

Wed Jan 07, 2015 5:27 pm

The following code returns (echoes) whatever you typed in minicom (between brackets and adds a newline). It's interrupt based, see the ISR(USART_RX_vect) method. Most of the code is straight from the datasheet.

You could also disable the USART receive interrupt in usart_init(), and use usart_data_available() and usart_read_char() in the for-loop in main() as well.

The forum software turns tabs into spaces, so I pasted the Makefile here: http://pastebin.com/ZT9aipUn (the Makefile assumes you saved the code below as 'main.c').

Compile and upload to Gertduino with 'make flash'.

Code: Select all

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

void usart_init(int baud_rate);
uint8_t usart_data_available(void);
char usart_read_char(void);
void usart_write_char(char data);
void usart_write_string(const char* data);

int main(void)
{
	// init the USART
	usart_init(9600);
	
	// enable interrupts
	sei();
	
	for (;;) {
		; // nop
	}
	
	return 0;
}


ISR(USART_RX_vect)
{
	// UDR0 is the USART RX buffer
	uint8_t rx_data = UDR0;
	
	usart_write_string("[");
	usart_write_char(rx_data);
	usart_write_string("]\r\n");
}

void usart_init(int baud_rate)
{
	// set baud rate
	int ubrr_val = (((F_CPU / (baud_rate * 16L))) - 1);
	UBRR0H = (uint8_t)(ubrr_val>>8);
	UBRR0L = (uint8_t)(ubrr_val);

	// enable receiver and transmitter
	UCSR0B=(1<<RXEN0)|(1<<TXEN0);
	
	// set frame format
	UCSR0C |= (3<<UCSZ00); // 8 data bits
	UCSR0C &= ~(1<<USBS0); // 1 stop bit
	
	// enable USART receive interrupt
	UCSR0B |= (1 << RXCIE0);
}

uint8_t usart_data_available(void)
{
	return (UCSR0A & (1<<RXC0));
}

char usart_read_char(void)
{
   // wait until data is available
   while(!(UCSR0A & (1<<RXC0))) {
      ; // nop
   }

   // usart data available in register UDR0
   return UDR0;
}

void usart_write_char(char data)
{
	// wait until transmitter is ready
	while(!(UCSR0A & (1<<UDRE0))) {
		; // nop
	}

	// send the data
	UDR0 = data;
}

void usart_write_string(const char* data)
{
	while (*data != '\0') {
		usart_write_char(*data);
		data++;
	}
}
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
Jednorozec
Posts: 809
Joined: Sun Nov 24, 2013 2:17 pm
Location: Deposit, NY

Re: Programming the Gertduino with c

Sun Jan 11, 2015 5:36 pm

http://friendsoftheunicorn.net/content/ ... ino-serial for Gertduino serial communication.
http://friendsoftheunicorn.net/content/using-ino for using Ino with the Gertduino.
The most important leg of a three legged stool is the one that's missing.
It's called thinking. Why don't you try it sometime?

Return to “Add-ons”

Who is online

Users browsing this forum: No registered users and 7 guests