In Hidden Variables I showed what command line options you could use to see what preprocessor symbols your GNU C and C++ compilers define by default. There are a lot of them. If you write code intended to run on different AVR microcontrollers, as I am doing for my Amigo project, this is worth knowing. For example, the Ardunino Uno board uses an Atmel ATmega328P microcontroller, while the Ardunino Mega 2560 board uses an Atmel ATmega2560 microcontroller. There are significant differences, some of which the compiler knows about.
Monday, February 27, 2012
Hidden Variables: Arduino and AVR Microcontrollers
In Hidden Variables I showed what command line options you could use to see what preprocessor symbols your GNU C and C++ compilers define by default. There are a lot of them. If you write code intended to run on different AVR microcontrollers, as I am doing for my Amigo project, this is worth knowing. For example, the Ardunino Uno board uses an Atmel ATmega328P microcontroller, while the Ardunino Mega 2560 board uses an Atmel ATmega2560 microcontroller. There are significant differences, some of which the compiler knows about.
Wednesday, February 22, 2012
Advanced Embedded C++ Development with Arduino II
Monday, February 20, 2012
Advanced Embedded C++ Development with Arduino
namespace com {
namespace diag {
namespace amigo {
...
}
}
}
#ifndef _COM_DIAG_AMIGO_LC100_H_
#define _COM_DIAG_AMIGO_LC100_H_
...
#endif /* _COM_DIAG_AMIGO_LC100_H_ */
static const byte COLS = 16;
struct Display
{
...
virtual void setCursor(byte col, byte row) = 0;
...
};
enum State {
DATA = 'D',
ESCAPE = 'E',
DECIMAL = 'N',
BRACKET = 'B',
FIRST = 'F',
SECOND = 'S',
QUESTION = 'Q'
};
template <byte _COLS_, byte _ROWS_> class LC100
: public LC100Base
{
...
byte lineLength[_ROWS_];
...
};
class Mock
: public com::diag::amigo::Display
{
...
};
#if 0
/**
* Cursor control unit test.
*/
static char TEST[] = {
lc100.ESC, '[', 'H',
'0',
lc100.ESC, '[', '1', ';', '1', '6', 'H',
'1',
lc100.ESC, '[', '2', ';', '1', '6', 'H',
'2',
lc100.ESC, '[', '2', ';', '1', 'H',
'3'
};
static void test() {
for (byte ii = 0; ii < (sizeof(TEST)/sizeof(TEST[0])); ++ii) {
lc100.write(TEST[ii]);
}
}
#endif
/**
* Place the cursor at the specified position. The column and row
* coordinates are taken modulo of the actual display dimensions.
* @param col is the zero-based column number.
* @param row is the zero-based row number.
*/
void setCursor(byte col, byte row);
Monday, February 13, 2012
Power over Ethernet with Arduino
Friday, February 10, 2012
Thinking Small With Arduino
Wednesday, February 08, 2012
Arduino to Android on BeagleBoard via Zigbee
Thursday, February 02, 2012
Embedded Software Development Economics 1
This is also why I really like Linux/GNU as an embedded platform when it's possible because it opens the possibility of doing a lot of development for prototyping or even production in scripting languages in which the think-type-compile-debug cycle can be very very short. I've leveraged the hell out of the bash shell, or even the more limited BusyBox ash shell, on embedded products. Scripting may also allow you to use less expensive developers who have no idea what the sizes are of variables in memory, but don't need to know for the kind work that they do.
Java falls into this category. If you can support it on your system, and its footprint meets your resource requirements, then you would be remiss not doing as much work in it as you can, with faster development iterations and less expensive developers. Java is increasingly becoming the language of choice in which to teach software development, so more and more college graduates are being produced with Java as their core programming language competency. I'm fully aware of the irony of this since some of my buddies tell me that Java is on the wane as an application language. But I think it has a lot of merit as a high level embedded language. Case in point: Android, on its way to becoming the most popular software platform for mobile devices, which has a Java application layer sitting on top of a C/C++ run-time and Linux kernel.
Those organizations who insist on doing everything in C or even C++ when more cost effective alternatives are available are quickly going to go the way of organizations who want to do everything in assembler on gigahertz ARM processors. Which is to say: they won't exist.
Wednesday, February 01, 2012
Arduino Data Types
I think for every system I've ever worked on that had a C compiler, going all the way back to my PDP-11 days, I eventually wrote this program or its equivalent. I have had some surprises. Here it is for Arduino, as part of my Amigo project.
#include <stdint.h> #include <avr/pgmspace.h> void setup() { Serial.begin(9600); } void loop() { Serial.print("sizeof(byte)="); Serial.println(sizeof(byte)); Serial.print("sizeof(char)="); Serial.println(sizeof(char)); Serial.print("sizeof(short)="); Serial.println(sizeof(short)); Serial.print("sizeof(int)="); Serial.println(sizeof(int)); Serial.print("sizeof(long)="); Serial.println(sizeof(long)); Serial.print("sizeof(long long)="); Serial.println(sizeof(long long)); Serial.print("sizeof(bool)="); Serial.println(sizeof(bool)); Serial.print("sizeof(boolean)="); Serial.println(sizeof(boolean)); Serial.print("sizeof(float)="); Serial.println(sizeof(float)); Serial.print("sizeof(double)="); Serial.println(sizeof(double)); Serial.print("sizeof(int8_t)="); Serial.println(sizeof(int8_t)); Serial.print("sizeof(int16_t)="); Serial.println(sizeof(int16_t)); Serial.print("sizeof(int32_t)="); Serial.println(sizeof(int32_t)); Serial.print("sizeof(int64_t)="); Serial.println(sizeof(int64_t)); Serial.print("sizeof(uint8_t)="); Serial.println(sizeof(uint8_t)); Serial.print("sizeof(uint16_t)="); Serial.println(sizeof(uint16_t)); Serial.print("sizeof(uint32_t)="); Serial.println(sizeof(uint32_t)); Serial.print("sizeof(uint64_t)="); Serial.println(sizeof(uint64_t)); Serial.print("sizeof(char*)="); Serial.println(sizeof(char*)); Serial.print("sizeof(int*)="); Serial.println(sizeof(int*)); Serial.print("sizeof(long*)="); Serial.println(sizeof(long*)); Serial.print("sizeof(float*)="); Serial.println(sizeof(float*)); Serial.print("sizeof(double*)="); Serial.println(sizeof(double*)); Serial.print("sizeof(void*)="); Serial.println(sizeof(void*)); Serial.print("sizeof(prog_char)="); Serial.println(sizeof(prog_char)); Serial.print("sizeof(prog_char*)="); Serial.println(sizeof(prog_char*)); Serial.println(); delay(5000); }