Arduino
So after the Arduino workshop at BruCON 2009 (pics here), I was seduced by this little development board.
Links
boards & clones
Duemilanove (SmartProjects)
The Duemilanove automatically selects the appropriate power supply (USB or external power), eliminating the need for the power selection jumper found on previous boards. It also adds an easiest to cut trace for disabling the auto-reset, along with a solder jumper for re-enabling it.
based on the ATmega168, latest versions are based on ATmega328p
Clones:
- Roboduino
Decimilia (SmartProjects)
Version before Duemilanove, with a jumper to select the power supply (USB or external power)
based on the Atmega168, can be upgraded with a ATmega328
Clones:
- Freeduino V1.16 Board
- Freeduino MaxSerial
- HACEduino "2009"
- Fino168 USB Board
- with a DIP switch to disable auto-reset and D13 LED
- Duino168 Serial Board
- with a DIP switch to disable auto-reset and D13 LED
- Duino328 Serial Board
- with a DIP switch to disable auto-reset and D13 LED
Lilypad (SparkFun)
based on the ATmega168V on v03 (the low-power version of the ATmega168) or the ATmega328V on v04
Pro (SparkFun)
based on the ATmega168 or ATmega328. The Pro comes in both 3.3V / 8 MHz and 5V / 16 MHz versions. It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a battery power jack, a power switch, a reset button, and holes for mounting a power jack, an ICSP header, and pin headers. A six pin header can be connected to an FTDI cable or Sparkfun breakout board to provide USB power and communication to the board.
The Arduino Pro is intended for semi-permanent installation in objects or exhibitions. The board comes without pre-mounted headers, allowing the use of various types of connectors or direct soldering of wires. The pin layout is compatible with Arduino shields. The 3.3V versions of the Pro can be powered with a battery.
Pro Mini (SparkFun)
based on the ATmega168. It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, an on-board resonator, a reset button, and holes for mounting pin headers. A six pin header can be connected to an FTDI cable or Sparkfun breakout board to provide USB power and communication to the board.
The Arduino Pro Mini is intended for semi-permanent installation in objects or exhibitions. The board comes without pre-mounted headers, allowing the use of various types of connectors or direct soldering of wires. The pin layout is compatible with the Arduino Mini.
There are two version of the Pro Mini. One runs at 3.3V and 8 MHz, the other at 5V and 16 MHz.
Nano (Gravitech)
small, complete, and breadboard-friendly board based on the ATmega328 (Arduino Nano 3.0) or ATmega168 (Arduino Nano 2.x). It has more or less the same functionality of the Arduino Duemilanove, but in a different package. It lacks only a DC power jack, and works with a Mini-B USB cable instead of a standard one
Clones:
- DFRoduino Nano
- HACEduino 2009 Nano
Mini (SmartProjects)
based on the ATmega168
the smallest of the serie. It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 8 analog inputs, and a 16 MHz crystal oscillator. It can be programmed with the Mini USB adapter or other USB or RS232 to TTL serial adapter.
Mega (SmartProjects)
based on the ATmega1280
54 Digital I/O Pins (of which 14 provide PWM) / 16 Analog Input Pins
Other clones
- iDuino, a breadboardable version
- Really Bare Bones Board, minimalist, smallest one?
Officials
- Arduino official website
Documentation
Hardware
Shopping
Ethernet
LCD
- Tutorial with LiquidCrystal library, for Hitachi HD44780 compatible LCDs
Misc links to explore
Arduino and Linux
Installation
Main instructions are here
As I'm using a Debian AMD 64bit, here is what I did:
Installing java from Sun and making sure it will be called by the tools. It might be that other java suites are working but at least java-gcj is missing a GtkLookAndFeel component that Arduino GUI is using
So if you don't have it yet:
aptitude install sun-java6-jre
Then if it's not the one by default, change it: (maybe "java" is enough but let's be consistent)
update-alternatives --config java update-alternatives --config jar update-alternatives --config keytool update-alternatives --config orbd update-alternatives --config rmid update-alternatives --config rmiregistry update-alternatives --config serialver
Other dependencies:
aptitude install avr-libc gcc-avr
Arduino tools, here v0017:
wget http://arduino.googlecode.com/files/arduino-0017.tgz tar xzf arduino-0017.tgz
Arduino tools are coming only for 32bit but it contains only a few executables so let's install the 64bit version of those executables
aptitude install librxtx-java rm arduino-0017/lib/librxtxSerial.so
There is also the avrdude binary in arduino-0017 which is compiled as 32bit executable.
You can recompile it from the source or if you have the ia32-libs package, the 32bit binary provided will work out-of-the-box.
But in any ways, DON'T USE AVRDUDE FROM YOUR DISTRO! because the one provided with the Arduino tools is a patched version.
Now let's try to launch the script arduino-0017/arduino
Tools/SerialPort/"/dev/ttyUSB0" Tools/Board/"Arduino Diecimila, Duemilanove or Nanoe, w/ Atmega168"
Now trying the very first code:
See this tuto
Problem with the original avrdude
As I told in the previous section, don't use the avrdude coming with your distro. Initially this is what I did and here are the problems I faced:
aptitude install avrdude avrdude-doc cd arduino-0017/hardware/tools mv avrdude avrdude.disabled mv avrdude.conf avrdude.conf.disabled ln -s /usr/bin/avrdude ln -s /etc/avrdude.conf
DON'T USE AVRDUDE FROM YOUR DISTRO! Then when trying to upload the bin to the board (menu -> Upload to I/O board), I got the following message:
Binary sketch size: 896 bytes (of a 14336 byte maximum) avrdude: Yikes! Invalid device signature. Double check connections and try again, or use -F to override this check.
Then I tried to inject the -F option to avrdude, it flashed the chip, gave me still errors:
Wrong microcontroller found. Did you select the right board in the Tools > Board menu? avrdude: Yikes! Invalid device signature. avrdude: Expected signature for ATMEGA168 is 1E 94 06
But the code was apparently correctly uploaded to the board as I got my blinking LED...
Avrdude which is part of the arduino-0017 release is a patched version as it says:
Version 5.4-arduino
While the version in Debian Squeeze is:
Version 5.8
So apparently we need absolutely to use the special arduino version.
Brucon Blink blink
Here is a first little project.
It is using two libraries
You can download the code [{{#file: brucon.pde}} as brucon.pde]
#include <Metro.h>
#include <LED.h>
LED LED_CircleA = LED(3);
LED LED_CircleB = LED(5);
LED LED_CircleC = LED(6);
Metro METRO_Circle = Metro(100);
int State_Circle = 0;
struct Steps_Circle_t {
int CircleA,CircleB,CircleC;
};
struct Steps_Circle_t Steps_Circle[] = {{0xFF,0,0x80},{0x80,0xFF,0},{0,0x80,0xFF}};
int Steps_Circle_size = 3;
LED LED_Left = LED(0);
LED LED_Middle = LED(1);
LED LED_Right = LED(2);
Metro METRO_Box = Metro(400);
int State_Box = 0;
struct Steps_Box_t {
int Left,Middle,Right;
};
struct Steps_Box_t Steps_Box[] = {{0,0,0},{0,1,0},
{0,0,0},{1,1,1},
{0,0,0},{1,1,1},{1,1,1},{1,1,1},{1,1,1},{1,1,1},{1,1,1},
{0,0,0},{1,0,0},{1,1,0},{1,1,1},
{1,1,1},{1,1,1},
{0,0,0},{1,1,1},
{0,0,0},{1,1,1},{1,1,1},{1,1,1},{1,1,1},{1,1,1},{1,1,1},
};
int Steps_Box_size = 26;
LED LED_B = LED(8);
LED LED_R = LED(9);
LED LED_U = LED(10);
LED LED_C = LED(11);
LED LED_O = LED(12);
LED LED_N = LED(13);
Metro METRO_Brucon = Metro(400);
int State_Brucon = 0;
struct Steps_Brucon_t {
int B,R,U,C,O,N;
};
struct Steps_Brucon_t Steps_Brucon[] = {{0,0,0,0,0,0},{1,1,1,1,1,1},
{0,0,0,0,0,0},{1,1,1,1,1,1},
{0,0,0,0,0,0},{1,0,0,0,0,0},{0,1,0,0,0,0},{0,0,1,0,0,0},{0,0,0,1,0,0},{0,0,0,0,1,0},{0,0,0,0,0,1},
{0,0,0,0,0,0},{0,0,0,0,0,0},{0,0,0,0,0,0},{0,0,0,0,0,0},
{1,1,1,1,1,1},{0,0,0,0,0,0},
{0,0,0,0,0,0},{1,1,1,1,1,1},
{0,0,0,0,0,0},{1,0,0,0,0,0},{1,1,0,0,0,0},{1,1,1,0,0,0},{1,1,1,1,0,0},{1,1,1,1,1,0},{1,1,1,1,1,1},
};
int Steps_Brucon_size = 26;
void setup() {
}
void loop()
{
if (METRO_Circle.check()) {
LED_CircleA.setValue(Steps_Circle[State_Circle].CircleA);
LED_CircleB.setValue(Steps_Circle[State_Circle].CircleB);
LED_CircleC.setValue(Steps_Circle[State_Circle].CircleC);
if (++State_Circle == Steps_Circle_size)
State_Circle = 0;
}
if (METRO_Box.check()) {
LED_Left.setValue (Steps_Box[State_Box].Left * 0xFF);
LED_Middle.setValue(Steps_Box[State_Box].Middle * 0xFF);
LED_Right.setValue (Steps_Box[State_Box].Right * 0xFF);
if (++State_Box == Steps_Box_size)
State_Box = 0;
}
if (METRO_Brucon.check()) {
LED_B.setValue(Steps_Brucon[State_Brucon].B * 0xFF);
LED_R.setValue(Steps_Brucon[State_Brucon].R * 0xFF);
LED_U.setValue(Steps_Brucon[State_Brucon].U * 0xFF);
LED_C.setValue(Steps_Brucon[State_Brucon].C * 0xFF);
LED_O.setValue(Steps_Brucon[State_Brucon].O * 0xFF);
LED_N.setValue(Steps_Brucon[State_Brucon].N * 0xFF);
if (++State_Brucon == Steps_Brucon_size)
State_Brucon = 0;
}
}
VFD brightness control
LiquidCrystal is great to control a LCD but it doesn't cover this little extension allowing to control a vacuum-fluorescent display (VFD) by software.
Here is how to do:
It is using the library
You can download the code [{{#file: testVFD.pde}} as testVFD.pde]
/*
LiquidCrystal Library - demo
Extension to control brightness of a Samsung 16T202DA1J VFD
*/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// Adds definitions for VFD:
#define VFD_25pc 0x03
#define VFD_50pc 0x02
#define VFD_75pc 0x01
#define VFD_100pc 0x00
void vfd_brightness(int brightness) {
// unfortunately lcd._displayfunction is private so we've to redefine it
int _displayfunction = LCD_4BITMODE | LCD_2LINE | LCD_5x8DOTS;
lcd.command(LCD_FUNCTIONSET | _displayfunction | brightness);
}
void setup() {
// set up the LCD's number of rows and columns:
lcd.begin(2, 16);
lcd.print("hello, world!");
}
void loop() {
vfd_brightness(VFD_100pc);
delay(200);
vfd_brightness(VFD_75pc);
delay(200);
vfd_brightness(VFD_50pc);
delay(200);
vfd_brightness(VFD_25pc);
delay(200);
vfd_brightness(VFD_50pc);
delay(200);
vfd_brightness(VFD_75pc);
delay(200);
}
Yet another EMF detector
Based on Aaron's detector, here using a 2x16 LCD, actually my VFD.
Upper row gives the averaged value on 10 samples
Lower row gives the signal between the minimal and maximal values observed in the 10 samples.
It's also a good example of a smooth bargraph on a LCD, with custom "chars" if needed.
It is using the library
You can download the code [{{#file: testEMF.pde}} as testEMF.pde]
// Doegox EMF detector
// Based on Aaron ALAI EMF Detector April 22nd 2009 VERSION 1.0
#include <LiquidCrystal.h>
int inPin = 5; // analog 5
#define MAXN 10 // samples per cycle
#define FREQ 50 // cycle in Hz, 60 for US folks
#define DARKBARS true // extrapolate 2 bars between digits? smoother but we loose info
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
lcd.begin(2, 16);
lcd.clear();
}
void loop() {
int val;
int val_avg = 0; // will store and average value of analog 5
int val_min = 1024; // will store and keep min value of analog 5
int val_max = 0; // will store and keep max value of analog 5
int LCD1[16]; // will store temporarely content of 2nd LCD row
for (int n=0; n<MAXN; n++) {
delayMicroseconds(1000000/FREQ/MAXN);
val = analogRead(inPin);
val_avg += val;
val_min = min(val_min, val);
val_max = max(val_max, val);
}
val_avg/=MAXN;
val_avg = map(val_avg, 0, 1023, 1, 16*(DARKBARS ? 7 : 5));
val_min = map(val_min, 0, 1023, 1, 16*(DARKBARS ? 7 : 5));
val_max = map(val_max, 0, 1023, 1, 16*(DARKBARS ? 7 : 5));
lcd.setCursor(0,0);
for (int i=0; i<16;i++) {
if (val_avg>=5) {
lcd.print(0x14, BYTE);
val_avg-=min((DARKBARS ? 7 : 5),val_avg);
} else if (val_avg>=1) {
lcd.print(0x0F + val_avg, BYTE);
val_avg=0;
} else {
lcd.print(0x20, BYTE);
}
}
for (int i=0; i<16;i++) {
if (val_min>=6) {
LCD1[i]=0x20;
val_min-=min((DARKBARS ? 7 : 5),val_min);
val_max-=min((DARKBARS ? 7 : 5),val_max);
} else if (val_min>=1) {
if (val_max>=5) {
LCD1[i]=0x13 + val_min;
val_max-=min((DARKBARS ? 7 : 5),val_max);
} else {
// tricky part, both min & max on same digit
int mm=0;
uint8_t mmchr[8];
for (int k=4; k>=0; k--) {
if ((k + val_min <= 5) && (k + val_max >=5 ))
mm+=1<<k;
}
for (int k=0; k<7; k++)
mmchr[k]=mm;
mmchr[7]=0x00;
// here we risk to manipulate again a char being displayed
// for critical apps, better to work on an unused char
// e.g. toggle between CG-RAM 0x00 and CG-RAM 0x01
lcd.createChar(0x00, mmchr);
LCD1[i]=0x00;
val_max=0;
}
val_min=0;
} else {
if (val_max>=5) {
LCD1[i]=0x14;
val_max-=min((DARKBARS ? 7 : 5),val_max);
} else if (val_max>=1) {
LCD1[i]=0x0F + val_max;
val_max=0;
} else {
LCD1[i]=0x20;
}
}
}
lcd.setCursor(0,1);
for (int i=0; i<16;i++) {
lcd.print(LCD1[i], BYTE);
}
}