diff --git a/arduino-0018-linux/arduino b/arduino-0018-linux/arduino new file mode 100755 index 0000000..7128bac --- /dev/null +++ b/arduino-0018-linux/arduino @@ -0,0 +1,22 @@ +#!/bin/sh + +APPDIR="$(dirname -- "${0}")" + +cd $APPDIR + +for LIB in \ + java/lib/rt.jar \ + java/lib/tools.jar \ + lib/*.jar \ + ; +do + CLASSPATH="${CLASSPATH}:${APPDIR}/${LIB}" +done +export CLASSPATH + +LD_LIBRARY_PATH=`pwd`/lib:${LD_LIBRARY_PATH} +export LD_LIBRARY_PATH + +export PATH="${APPDIR}/java/bin:${PATH}" + +java -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel processing.app.Base diff --git a/arduino-0018-linux/examples/Analog/AnalogInOutSerial/AnalogInOutSerial.pde b/arduino-0018-linux/examples/Analog/AnalogInOutSerial/AnalogInOutSerial.pde new file mode 100644 index 0000000..81c8e81 --- /dev/null +++ b/arduino-0018-linux/examples/Analog/AnalogInOutSerial/AnalogInOutSerial.pde @@ -0,0 +1,50 @@ +/* + Analog input, analog output, serial output + + Reads an analog input pin, maps the result to a range from 0 to 255 + and uses the result to set the pulsewidth modulation (PWM) of an output pin. + Also prints the results to the serial monitor. + + The circuit: + * potentiometer connected to analog pin 0. + Center pin of the potentiometer goes to the analog pin. + side pins of the potentiometer go to +5V and ground + * LED connected from digital pin 9 to ground + + created 29 Dec. 2008 + by Tom Igoe + + */ + +// These constants won't change. They're used to give names +// to the pins used: +const int analogInPin = 0; // Analog input pin that the potentiometer is attached to +const int analogOutPin = 9; // Analog output pin that the LED is attached to + +int sensorValue = 0; // value read from the pot +int outputValue = 0; // value output to the PWM (analog out) + +void setup() { + // initialize serial communications at 9600 bps: + Serial.begin(9600); +} + +void loop() { + // read the analog in value: + sensorValue = analogRead(analogInPin); + // map it to the range of the analog out: + outputValue = map(sensorValue, 0, 1023, 0, 255); + // change the analog out value: + analogWrite(analogOutPin, outputValue); + + // print the results to the serial monitor: + Serial.print("sensor = " ); + Serial.print(sensorValue); + Serial.print("\t output = "); + Serial.println(outputValue); + + // wait 10 milliseconds before the next loop + // for the analog-to-digital converter to settle + // after the last reading: + delay(10); +} diff --git a/arduino-0018-linux/examples/Analog/AnalogInSerial/AnalogInSerial.pde b/arduino-0018-linux/examples/Analog/AnalogInSerial/AnalogInSerial.pde new file mode 100644 index 0000000..c8fa158 --- /dev/null +++ b/arduino-0018-linux/examples/Analog/AnalogInSerial/AnalogInSerial.pde @@ -0,0 +1,29 @@ +/* + Analog input, serial output + + Reads an analog input pin, prints the results to the serial monitor. + + The circuit: + + * potentiometer connected to analog pin 0. + Center pin of the potentiometer goes to the analog pin. + side pins of the potentiometer go to +5V and ground + + created over and over again + by Tom Igoe and everyone who's ever used Arduino + + */ + + void setup() { + Serial.begin(9600); + } + + void loop() { + // read the analog input into a variable: + int analogValue = analogRead(0); + // print the result: + Serial.println(analogValue); + // wait 10 milliseconds for the analog-to-digital converter + // to settle after the last reading: + delay(10); + } diff --git a/arduino-0018-linux/examples/Analog/AnalogInput/AnalogInput.pde b/arduino-0018-linux/examples/Analog/AnalogInput/AnalogInput.pde new file mode 100644 index 0000000..1ee8ee3 --- /dev/null +++ b/arduino-0018-linux/examples/Analog/AnalogInput/AnalogInput.pde @@ -0,0 +1,48 @@ +/* + Analog Input + Demonstrates analog input by reading an analog sensor on analog pin 0 and + turning on and off a light emitting diode(LED) connected to digital pin 13. + The amount of time the LED will be on and off depends on + the value obtained by analogRead(). + + The circuit: + * Potentiometer attached to analog input 0 + * center pin of the potentiometer to the analog pin + * one side pin (either one) to ground + * the other side pin to +5V + * LED anode (long leg) attached to digital output 13 + * LED cathode (short leg) attached to ground + + * Note: because most Arduinos have a built-in LED attached + to pin 13 on the board, the LED is optional. + + + Created by David Cuartielles + Modified 16 Jun 2009 + By Tom Igoe + + http://arduino.cc/en/Tutorial/AnalogInput + + */ + +int sensorPin = 0; // select the input pin for the potentiometer +int ledPin = 13; // select the pin for the LED +int sensorValue = 0; // variable to store the value coming from the sensor + +void setup() { + // declare the ledPin as an OUTPUT: + pinMode(ledPin, OUTPUT); +} + +void loop() { + // read the value from the sensor: + sensorValue = analogRead(sensorPin); + // turn the ledPin on + digitalWrite(ledPin, HIGH); + // stop the program for milliseconds: + delay(sensorValue); + // turn the ledPin off: + digitalWrite(ledPin, LOW); + // stop the program for for milliseconds: + delay(sensorValue); +} \ No newline at end of file diff --git a/arduino-0018-linux/examples/Analog/AnalogWriteMega/AnalogWriteMega.pde b/arduino-0018-linux/examples/Analog/AnalogWriteMega/AnalogWriteMega.pde new file mode 100644 index 0000000..3166952 --- /dev/null +++ b/arduino-0018-linux/examples/Analog/AnalogWriteMega/AnalogWriteMega.pde @@ -0,0 +1,42 @@ +/* + Mega analogWrite() test + + This sketch fades LEDs up and down one at a time on digital pins 2 through 13. + This sketch was written for the Arduino Mega, and will not work on previous boards. + + The circuit: + * LEDs attached from pins 2 through 13 to ground. + + created 8 Feb 2009 + by Tom Igoe + */ +// These constants won't change. They're used to give names +// to the pins used: +const int lowestPin = 2; +const int highestPin = 13; + + +void setup() { + // set pins 2 through 13 as outputs: + for (int thisPin =lowestPin; thisPin <= highestPin; thisPin++) { + pinMode(thisPin, OUTPUT); + } +} + +void loop() { + // iterate over the pins: + for (int thisPin =lowestPin; thisPin <= highestPin; thisPin++) { + // fade the LED on thisPin from off to brightest: + for (int brightness = 0; brightness < 255; brightness++) { + analogWrite(thisPin, brightness); + delay(2); + } + // fade the LED on thisPin from brithstest to off: + for (int brightness = 255; brightness >= 0; brightness--) { + analogWrite(thisPin, brightness); + delay(2); + } + // pause between LEDs: + delay(100); + } +} diff --git a/arduino-0018-linux/examples/Analog/Calibration/Calibration.pde b/arduino-0018-linux/examples/Analog/Calibration/Calibration.pde new file mode 100644 index 0000000..52c8d8d --- /dev/null +++ b/arduino-0018-linux/examples/Analog/Calibration/Calibration.pde @@ -0,0 +1,73 @@ +/* + Calibration + + Demonstrates one techinque for calibrating sensor input. The + sensor readings during the first five seconds of the sketch + execution define the minimum and maximum of expected values + attached to the sensor pin. + + The sensor minumum and maximum initial values may seem backwards. + Initially, you set the minimum high and listen for anything + lower, saving it as the new minumum. Likewise, you set the + maximum low and listen for anything higher as the new maximum. + + The circuit: + * Analog sensor (potentiometer will do) attached to analog input 0 + * LED attached from digital pin 9 to ground + + created 29 Oct 2008 + By David A Mellis + Modified 17 Jun 2009 + By Tom Igoe + + http://arduino.cc/en/Tutorial/Calibration + + */ + +// These constants won't change: +const int sensorPin = 2; // pin that the sensor is attached to +const int ledPin = 9; // pin that the LED is attached to + +// variables: +int sensorValue = 0; // the sensor value +int sensorMin = 1023; // minimum sensor value +int sensorMax = 0; // maximum sensor value + + +void setup() { + // turn on LED to signal the start of the calibration period: + pinMode(13, OUTPUT); + digitalWrite(13, HIGH); + + // calibrate during the first five seconds + while (millis() < 5000) { + sensorValue = analogRead(sensorPin); + + // record the maximum sensor value + if (sensorValue > sensorMax) { + sensorMax = sensorValue; + } + + // record the minimum sensor value + if (sensorValue < sensorMin) { + sensorMin = sensorValue; + } + } + + // signal the end of the calibration period + digitalWrite(13, LOW); +} + +void loop() { + // read the sensor: + sensorValue = analogRead(sensorPin); + + // apply the calibration to the sensor reading + sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255); + + // in case the sensor value is outside the range seen during calibration + sensorValue = constrain(sensorValue, 0, 255); + + // fade the LED using the calibrated value: + analogWrite(ledPin, sensorValue); +} \ No newline at end of file diff --git a/arduino-0018-linux/examples/Analog/Fading/Fading.pde b/arduino-0018-linux/examples/Analog/Fading/Fading.pde new file mode 100644 index 0000000..1205078 --- /dev/null +++ b/arduino-0018-linux/examples/Analog/Fading/Fading.pde @@ -0,0 +1,43 @@ +/* + Fading + + This example shows how to fade an LED using the analogWrite() function. + + The circuit: + * LED attached from digital pin 9 to ground. + + Created 1 Nov 2008 + By David A. Mellis + Modified 17 June 2009 + By Tom Igoe + + http://arduino.cc/en/Tutorial/Fading + + */ + + +int ledPin = 9; // LED connected to digital pin 9 + +void setup() { + // nothing happens in setup +} + +void loop() { + // fade in from min to max in increments of 5 points: + for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) { + // sets the value (range from 0 to 255): + analogWrite(ledPin, fadeValue); + // wait for 30 milliseconds to see the dimming effect + delay(30); + } + + // fade out from max to min in increments of 5 points: + for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) { + // sets the value (range from 0 to 255): + analogWrite(ledPin, fadeValue); + // wait for 30 milliseconds to see the dimming effect + delay(30); + } +} + + diff --git a/arduino-0018-linux/examples/Analog/Smoothing/Smoothing.pde b/arduino-0018-linux/examples/Analog/Smoothing/Smoothing.pde new file mode 100644 index 0000000..881bb13 --- /dev/null +++ b/arduino-0018-linux/examples/Analog/Smoothing/Smoothing.pde @@ -0,0 +1,64 @@ +/* + + Smoothing + + Reads repeatedly from an analog input, calculating a running average + and printing it to the computer. Keeps ten readings in an array and + continually averages them. + + The circuit: + * Analog sensor (potentiometer will do) attached to analog input 0 + + Created 22 April 2007 + By David A. Mellis + + http://www.arduino.cc/en/Tutorial/Smoothing + + +*/ + + +// Define the number of samples to keep track of. The higher the number, +// the more the readings will be smoothed, but the slower the output will +// respond to the input. Using a constant rather than a normal variable lets +// use this value to determine the size of the readings array. +const int numReadings = 10; + +int readings[numReadings]; // the readings from the analog input +int index = 0; // the index of the current reading +int total = 0; // the running total +int average = 0; // the average + +int inputPin = 0; + +void setup() +{ + // initialize serial communication with computer: + Serial.begin(9600); + // initialize all the readings to 0: + for (int thisReading = 0; thisReading < numReadings; thisReading++) + readings[thisReading] = 0; +} + +void loop() { + // subtract the last reading: + total= total - readings[index]; + // read from the sensor: + readings[index] = analogRead(inputPin); + // add the reading to the total: + total= total + readings[index]; + // advance to the next position in the array: + index = index + 1; + + // if we're at the end of the array... + if (index >= numReadings) + // ...wrap around to the beginning: + index = 0; + + // calculate the average: + average = total / numReadings; + // send it to the computer (as ASCII digits) + Serial.println(average, DEC); +} + + diff --git a/arduino-0018-linux/examples/ArduinoISP/ArduinoISP.pde b/arduino-0018-linux/examples/ArduinoISP/ArduinoISP.pde new file mode 100644 index 0000000..0012c69 --- /dev/null +++ b/arduino-0018-linux/examples/ArduinoISP/ArduinoISP.pde @@ -0,0 +1,480 @@ +// this sketch turns the Arduino into a AVRISP +// using the following pins: +// 10: slave reset +// 11: MOSI +// 12: MISO +// 13: SCK + +// Put an LED (with resistor) on the following pins: +// 9: Heartbeat - shows the programmer is running +// 8: Error - Lights up if something goes wrong (use red if that makes sense) +// 7: Programming - In communication with the slave +// +// October 2009 by David A. Mellis +// - Added support for the read signature command +// +// February 2009 by Randall Bohn +// - Added support for writing to EEPROM (what took so long?) +// Windows users should consider WinAVR's avrdude instead of the +// avrdude included with Arduino software. +// +// January 2008 by Randall Bohn +// - Thanks to Amplificar for helping me with the STK500 protocol +// - The AVRISP/STK500 (mk I) protocol is used in the arduino bootloader +// - The SPI functions herein were developed for the AVR910_ARD programmer +// - More information at http://code.google.com/p/mega-isp + +#define SCK 13 +#define MISO 12 +#define MOSI 11 +#define RESET 10 + +#define LED_HB 9 +#define LED_ERR 8 +#define LED_PMODE 7 + +#define HWVER 2 +#define SWMAJ 1 +#define SWMIN 18 + +// STK Definitions +#define STK_OK 0x10 +#define STK_FAILED 0x11 +#define STK_UNKNOWN 0x12 +#define STK_INSYNC 0x14 +#define STK_NOSYNC 0x15 +#define CRC_EOP 0x20 //ok it is a space... + +void pulse(int pin, int times); + +void setup() { + Serial.begin(19200); + pinMode(7, OUTPUT); + pulse(7, 2); + pinMode(8, OUTPUT); + pulse(8, 2); + pinMode(9, OUTPUT); + pulse(9, 2); +} + +int error=0; +int pmode=0; +// address for reading and writing, set by 'U' command +int here; +uint8_t buff[256]; // global block storage + +#define beget16(addr) (*addr * 256 + *(addr+1) ) +typedef struct param { + uint8_t devicecode; + uint8_t revision; + uint8_t progtype; + uint8_t parmode; + uint8_t polling; + uint8_t selftimed; + uint8_t lockbytes; + uint8_t fusebytes; + int flashpoll; + int eeprompoll; + int pagesize; + int eepromsize; + int flashsize; +} +parameter; + +parameter param; + +// this provides a heartbeat on pin 9, so you can tell the software is running. +uint8_t hbval=128; +int8_t hbdelta=8; +void heartbeat() { + if (hbval > 192) hbdelta = -hbdelta; + if (hbval < 32) hbdelta = -hbdelta; + hbval += hbdelta; + analogWrite(LED_HB, hbval); + delay(40); +} + + +void loop(void) { + // is pmode active? + if (pmode) digitalWrite(LED_PMODE, HIGH); + else digitalWrite(LED_PMODE, LOW); + // is there an error? + if (error) digitalWrite(LED_ERR, HIGH); + else digitalWrite(LED_ERR, LOW); + + // light the heartbeat LED + heartbeat(); + if (Serial.available()) { + avrisp(); + } +} + +uint8_t getch() { + while(!Serial.available()); + return Serial.read(); +} +void readbytes(int n) { + for (int x = 0; x < n; x++) { + buff[x] = Serial.read(); + } +} + +#define PTIME 30 +void pulse(int pin, int times) { + do { + digitalWrite(pin, HIGH); + delay(PTIME); + digitalWrite(pin, LOW); + delay(PTIME); + } + while (times--); +} + +void spi_init() { + uint8_t x; + SPCR = 0x53; + x=SPSR; + x=SPDR; +} + +void spi_wait() { + do { + } + while (!(SPSR & (1 << SPIF))); +} + +uint8_t spi_send(uint8_t b) { + uint8_t reply; + SPDR=b; + spi_wait(); + reply = SPDR; + return reply; +} + +uint8_t spi_transaction(uint8_t a, uint8_t b, uint8_t c, uint8_t d) { + uint8_t n; + spi_send(a); + n=spi_send(b); + //if (n != a) error = -1; + n=spi_send(c); + return spi_send(d); +} + +void empty_reply() { + if (CRC_EOP == getch()) { + Serial.print((char)STK_INSYNC); + Serial.print((char)STK_OK); + } + else { + Serial.print((char)STK_NOSYNC); + } +} + +void breply(uint8_t b) { + if (CRC_EOP == getch()) { + Serial.print((char)STK_INSYNC); + Serial.print((char)b); + Serial.print((char)STK_OK); + } + else { + Serial.print((char)STK_NOSYNC); + } +} + +void get_version(uint8_t c) { + switch(c) { + case 0x80: + breply(HWVER); + break; + case 0x81: + breply(SWMAJ); + break; + case 0x82: + breply(SWMIN); + break; + case 0x93: + breply('S'); // serial programmer + break; + default: + breply(0); + } +} + +void set_parameters() { + // call this after reading paramter packet into buff[] + param.devicecode = buff[0]; + param.revision = buff[1]; + param.progtype = buff[2]; + param.parmode = buff[3]; + param.polling = buff[4]; + param.selftimed = buff[5]; + param.lockbytes = buff[6]; + param.fusebytes = buff[7]; + param.flashpoll = buff[8]; + // ignore buff[9] (= buff[8]) + //getch(); // discard second value + + // WARNING: not sure about the byte order of the following + // following are 16 bits (big endian) + param.eeprompoll = beget16(&buff[10]); + param.pagesize = beget16(&buff[12]); + param.eepromsize = beget16(&buff[14]); + + // 32 bits flashsize (big endian) + param.flashsize = buff[16] * 0x01000000 + + buff[17] * 0x00010000 + + buff[18] * 0x00000100 + + buff[19]; + +} + +void start_pmode() { + spi_init(); + // following delays may not work on all targets... + pinMode(RESET, OUTPUT); + digitalWrite(RESET, HIGH); + pinMode(SCK, OUTPUT); + digitalWrite(SCK, LOW); + delay(50); + digitalWrite(RESET, LOW); + delay(50); + pinMode(MISO, INPUT); + pinMode(MOSI, OUTPUT); + spi_transaction(0xAC, 0x53, 0x00, 0x00); + pmode = 1; +} + +void end_pmode() { + pinMode(MISO, INPUT); + pinMode(MOSI, INPUT); + pinMode(SCK, INPUT); + pinMode(RESET, INPUT); + pmode = 0; +} + +void universal() { + int w; + uint8_t ch; + + for (w = 0; w < 4; w++) { + buff[w] = getch(); + } + ch = spi_transaction(buff[0], buff[1], buff[2], buff[3]); + breply(ch); +} + +void flash(uint8_t hilo, int addr, uint8_t data) { + spi_transaction(0x40+8*hilo, + addr>>8 & 0xFF, + addr & 0xFF, + data); +} +void commit(int addr) { + spi_transaction(0x4C, (addr >> 8) & 0xFF, addr & 0xFF, 0); +} + +//#define _current_page(x) (here & 0xFFFFE0) +int current_page(int addr) { + if (param.pagesize == 32) return here & 0xFFFFFFF0; + if (param.pagesize == 64) return here & 0xFFFFFFE0; + if (param.pagesize == 128) return here & 0xFFFFFFC0; + if (param.pagesize == 256) return here & 0xFFFFFF80; + return here; +} +uint8_t write_flash(int length) { + if (param.pagesize < 1) return STK_FAILED; + //if (param.pagesize != 64) return STK_FAILED; + int page = current_page(here); + int x = 0; + while (x < length) { + if (page != current_page(here)) { + commit(page); + page = current_page(here); + } + flash(LOW, here, buff[x++]); + flash(HIGH, here, buff[x++]); + here++; + } + + commit(page); + + return STK_OK; +} + +uint8_t write_eeprom(int length) { + // here is a word address, so we use here*2 + // this writes byte-by-byte, + // page writing may be faster (4 bytes at a time) + for (int x = 0; x < length; x++) { + spi_transaction(0xC0, 0x00, here*2+x, buff[x]); + delay(45); + } + return STK_OK; +} + +void program_page() { + char result = (char) STK_FAILED; + int length = 256 * getch() + getch(); + if (length > 256) { + Serial.print((char) STK_FAILED); + return; + } + char memtype = getch(); + for (int x = 0; x < length; x++) { + buff[x] = getch(); + } + if (CRC_EOP == getch()) { + Serial.print((char) STK_INSYNC); + if (memtype == 'F') result = (char)write_flash(length); + if (memtype == 'E') result = (char)write_eeprom(length); + Serial.print(result); + } + else { + Serial.print((char) STK_NOSYNC); + } +} +uint8_t flash_read(uint8_t hilo, int addr) { + return spi_transaction(0x20 + hilo * 8, + (addr >> 8) & 0xFF, + addr & 0xFF, + 0); +} + +char flash_read_page(int length) { + for (int x = 0; x < length; x+=2) { + uint8_t low = flash_read(LOW, here); + Serial.print((char) low); + uint8_t high = flash_read(HIGH, here); + Serial.print((char) high); + here++; + } + return STK_OK; +} + +char eeprom_read_page(int length) { + // here again we have a word address + for (int x = 0; x < length; x++) { + uint8_t ee = spi_transaction(0xA0, 0x00, here*2+x, 0xFF); + Serial.print((char) ee); + } + return STK_OK; +} + +void read_page() { + char result = (char)STK_FAILED; + int length = 256 * getch() + getch(); + char memtype = getch(); + if (CRC_EOP != getch()) { + Serial.print((char) STK_NOSYNC); + return; + } + Serial.print((char) STK_INSYNC); + if (memtype == 'F') result = flash_read_page(length); + if (memtype == 'E') result = eeprom_read_page(length); + Serial.print(result); + return; +} + +void read_signature() { + if (CRC_EOP != getch()) { + Serial.print((char) STK_NOSYNC); + return; + } + Serial.print((char) STK_INSYNC); + uint8_t high = spi_transaction(0x30, 0x00, 0x00, 0x00); + Serial.print((char) high); + uint8_t middle = spi_transaction(0x30, 0x00, 0x01, 0x00); + Serial.print((char) middle); + uint8_t low = spi_transaction(0x30, 0x00, 0x02, 0x00); + Serial.print((char) low); + Serial.print((char) STK_OK); +} +////////////////////////////////////////// +////////////////////////////////////////// + + +//////////////////////////////////// +//////////////////////////////////// +int avrisp() { + uint8_t data, low, high; + uint8_t ch = getch(); + switch (ch) { + case '0': // signon + empty_reply(); + break; + case '1': + if (getch() == CRC_EOP) { + Serial.print((char) STK_INSYNC); + Serial.print("AVR ISP"); + Serial.print((char) STK_OK); + } + break; + case 'A': + get_version(getch()); + break; + case 'B': + readbytes(20); + set_parameters(); + empty_reply(); + break; + case 'E': // extended parameters - ignore for now + readbytes(5); + empty_reply(); + break; + + case 'P': + start_pmode(); + empty_reply(); + break; + case 'U': + here = getch() + 256 * getch(); + empty_reply(); + break; + + case 0x60: //STK_PROG_FLASH + low = getch(); + high = getch(); + empty_reply(); + break; + case 0x61: //STK_PROG_DATA + data = getch(); + empty_reply(); + break; + + case 0x64: //STK_PROG_PAGE + program_page(); + break; + + case 0x74: //STK_READ_PAGE + read_page(); + break; + + case 'V': + universal(); + break; + case 'Q': + error=0; + end_pmode(); + empty_reply(); + break; + + case 0x75: //STK_READ_SIGN + read_signature(); + break; + + // expecting a command, not CRC_EOP + // this is how we can get back in sync + case CRC_EOP: + Serial.print((char) STK_NOSYNC); + break; + + // anything else we will return STK_UNKNOWN + default: + if (CRC_EOP == getch()) + Serial.print((char)STK_UNKNOWN); + else + Serial.print((char)STK_NOSYNC); + } +} + diff --git a/arduino-0018-linux/examples/Communication/ASCIITable/ASCIITable.pde b/arduino-0018-linux/examples/Communication/ASCIITable/ASCIITable.pde new file mode 100644 index 0000000..3a20603 --- /dev/null +++ b/arduino-0018-linux/examples/Communication/ASCIITable/ASCIITable.pde @@ -0,0 +1,73 @@ +/* + ASCII table + + Prints out byte values in all possible formats: + * as raw binary values + * as ASCII-encoded decimal, hex, octal, and binary values + + For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII + + The circuit: No external hardware needed. + + created 2006 + by Nicholas Zambetti + modified 18 Jan 2009 + by Tom Igoe + + + */ +void setup() +{ + Serial.begin(9600); + + // prints title with ending line break + Serial.println("ASCII Table ~ Character Map"); +} + +// first visible ASCIIcharacter '!' is number 33: +int thisByte = 33; +// you can also write ASCII characters in single quotes. +// for example. '!' is the same as 33, so you could also use this: +//int thisByte = '!'; + +void loop() +{ + // prints value unaltered, i.e. the raw binary version of the + // byte. The serial monitor interprets all bytes as + // ASCII, so 33, the first number, will show up as '!' + Serial.print(thisByte, BYTE); + + Serial.print(", dec: "); + // prints value as string as an ASCII-encoded decimal (base 10). + // Decimal is the default format for Serial.print() and Serial.println(), + // so no modifier is needed: + Serial.print(thisByte); + // But you can declare the modifier for decimal if you want to. + //this also works if you uncomment it: + + // Serial.print(thisByte, DEC); + + + Serial.print(", hex: "); + // prints value as string in hexadecimal (base 16): + Serial.print(thisByte, HEX); + + Serial.print(", oct: "); + // prints value as string in octal (base 8); + Serial.print(thisByte, OCT); + + Serial.print(", bin: "); + // prints value as string in binary (base 2) + // also prints ending line break: + Serial.println(thisByte, BIN); + + // if printed last visible character '~' or 126, stop: + if(thisByte == 126) { // you could also use if (thisByte == '~') { + // This loop loops forever and does nothing + while(true) { + continue; + } + } + // go on to the next character + thisByte++; +} diff --git a/arduino-0018-linux/examples/Communication/Dimmer/Dimmer.pde b/arduino-0018-linux/examples/Communication/Dimmer/Dimmer.pde new file mode 100644 index 0000000..0990fe5 --- /dev/null +++ b/arduino-0018-linux/examples/Communication/Dimmer/Dimmer.pde @@ -0,0 +1,360 @@ +/* + Dimmer + + Demonstrates the sending data from the computer to the Arduino board, + in this case to control the brightness of an LED. The data is sent + in individual bytes, each of which ranges from 0 to 255. Arduino + reads these bytes and uses them to set the brightness of the LED. + + The circuit: + LED attached from digital pin 9 to ground. + Serial connection to Processing, Max/MSP, or another serial application + + created 2006 + by David A. Mellis + modified 14 Apr 2009 + by Tom Igoe and Scott Fitzgerald + + http://www.arduino.cc/en/Tutorial/Dimmer + */ + +const int ledPin = 9; // the pin that the LED is attached to + +void setup() +{ + // initialize the serial communication: + Serial.begin(9600); + // initialize the ledPin as an output: + pinMode(ledPin, OUTPUT); +} + +void loop() { + byte brightness; + + // check if data has been sent from the computer: + if (Serial.available()) { + // read the most recent byte (which will be from 0 to 255): + brightness = Serial.read(); + // set the brightness of the LED: + analogWrite(ledPin, brightness); + } +} + +/* Processing code for this example + // Dimmer - sends bytes over a serial port + // by David A. Mellis + + import processing.serial.*; + Serial port; + + void setup() { + size(256, 150); + + println("Available serial ports:"); + println(Serial.list()); + + // Uses the first port in this list (number 0). Change this to + // select the port corresponding to your Arduino board. The last + // parameter (e.g. 9600) is the speed of the communication. It + // has to correspond to the value passed to Serial.begin() in your + // Arduino sketch. + port = new Serial(this, Serial.list()[0], 9600); + + // If you know the name of the port used by the Arduino board, you + // can specify it directly like this. + //port = new Serial(this, "COM1", 9600); + } + + void draw() { + // draw a gradient from black to white + for (int i = 0; i < 256; i++) { + stroke(i); + line(i, 0, i, 150); + } + + // write the current X-position of the mouse to the serial port as + // a single byte + port.write(mouseX); + } + */ + +/* Max/MSP v5 patch for this example + + { + "boxes" : [ { + "box" : { + "maxclass" : "comment", + "text" : "Dimmer\n\nThis patch sends a binary number from 0 to 255 out the serial port to an Arduino connected to the port. It dims an LED attached to the Arduino.\n\ncreated 2006\nby David A. Mellis\nmodified 14 Apr 2009\nby Scott Fitzgerald and Tom Igoe", + "linecount" : 10, + "patching_rect" : [ 209.0, 55.0, 344.0, 144.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-32", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "change the slider to alter the brightness of the LED", + "linecount" : 3, + "patching_rect" : [ 90.0, 235.0, 117.0, 48.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-7", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "number", + "patching_rect" : [ 215.0, 385.0, 50.0, 19.0 ], + "numoutlets" : 2, + "fontsize" : 10.0, + "outlettype" : [ "int", "bang" ], + "id" : "obj-6", + "fontname" : "Verdana", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "slider", + "patching_rect" : [ 215.0, 235.0, 20.0, 140.0 ], + "numoutlets" : 1, + "outlettype" : [ "" ], + "bgcolor" : [ 0.94902, 0.94902, 0.94902, 0.0 ], + "id" : "obj-1", + "size" : 256.0, + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "newobj", + "text" : "select 0 1", + "patching_rect" : [ 342.0, 305.0, 62.0, 20.0 ], + "numoutlets" : 3, + "fontsize" : 12.0, + "outlettype" : [ "bang", "bang", "" ], + "id" : "obj-30", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "click here to close the serial port", + "patching_rect" : [ 390.0, 396.0, 206.0, 20.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-26", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "click here to open the serial port", + "patching_rect" : [ 415.0, 370.0, 206.0, 20.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-27", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "message", + "text" : "close", + "patching_rect" : [ 342.0, 396.0, 39.0, 18.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "" ], + "id" : "obj-21", + "fontname" : "Arial", + "numinlets" : 2 + } + + } + , { + "box" : { + "maxclass" : "message", + "text" : "port a", + "patching_rect" : [ 364.0, 370.0, 41.0, 18.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "" ], + "id" : "obj-19", + "fontname" : "Arial", + "numinlets" : 2 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "Click here to get a list of serial ports", + "patching_rect" : [ 435.0, 344.0, 207.0, 20.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-2", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "toggle", + "patching_rect" : [ 342.0, 268.0, 15.0, 15.0 ], + "numoutlets" : 1, + "outlettype" : [ "int" ], + "id" : "obj-11", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "message", + "text" : "print", + "patching_rect" : [ 384.0, 344.0, 36.0, 18.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "" ], + "id" : "obj-13", + "fontname" : "Arial", + "numinlets" : 2 + } + + } + , { + "box" : { + "maxclass" : "newobj", + "text" : "serial a 9600", + "patching_rect" : [ 259.0, 420.0, 84.0, 20.0 ], + "numoutlets" : 2, + "fontsize" : 12.0, + "outlettype" : [ "int", "" ], + "id" : "obj-14", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "Click to start", + "patching_rect" : [ 369.0, 268.0, 117.0, 20.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-17", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "panel", + "patching_rect" : [ 215.0, 235.0, 21.0, 139.0 ], + "numoutlets" : 0, + "mode" : 1, + "grad1" : [ 1.0, 1.0, 1.0, 1.0 ], + "id" : "obj-8", + "grad2" : [ 0.509804, 0.509804, 0.509804, 1.0 ], + "numinlets" : 1, + "angle" : 270.0 + } + + } + ], + "lines" : [ { + "patchline" : { + "source" : [ "obj-11", 0 ], + "destination" : [ "obj-30", 0 ], + "hidden" : 0, + "midpoints" : [ 351.0, 296.0, 351.5, 296.0 ] + } + + } + , { + "patchline" : { + "source" : [ "obj-30", 1 ], + "destination" : [ "obj-19", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-30", 0 ], + "destination" : [ "obj-21", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-21", 0 ], + "destination" : [ "obj-14", 0 ], + "hidden" : 0, + "midpoints" : [ 351.5, 416.5, 268.5, 416.5 ] + } + + } + , { + "patchline" : { + "source" : [ "obj-19", 0 ], + "destination" : [ "obj-14", 0 ], + "hidden" : 0, + "midpoints" : [ 373.5, 393.5, 268.5, 393.5 ] + } + + } + , { + "patchline" : { + "source" : [ "obj-13", 0 ], + "destination" : [ "obj-14", 0 ], + "hidden" : 0, + "midpoints" : [ 393.5, 365.5, 268.5, 365.5 ] + } + + } + , { + "patchline" : { + "source" : [ "obj-1", 0 ], + "destination" : [ "obj-6", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-6", 0 ], + "destination" : [ "obj-14", 0 ], + "hidden" : 0, + "midpoints" : [ 224.5, 411.5, 268.5, 411.5 ] + } + + } + ] + } + */ diff --git a/arduino-0018-linux/examples/Communication/Graph/Graph.pde b/arduino-0018-linux/examples/Communication/Graph/Graph.pde new file mode 100644 index 0000000..1f2fadd --- /dev/null +++ b/arduino-0018-linux/examples/Communication/Graph/Graph.pde @@ -0,0 +1,578 @@ +/* + Graph + + A simple example of communication from the Arduino board to the computer: + the value of analog input 0 is sent out the serial port. We call this "serial" + communication because the connection appears to both the Arduino and the + computer as a serial port, even though it may actually use + a USB cable. Bytes are sent one after another (serially) from the Arduino + to the computer. + + You can use the Arduino serial monitor to view the sent data, or it can + be read by Processing, PD, Max/MSP, or any other program capable of reading + data from a serial port. The Processing code below graphs the data received + so you can see the value of the analog input changing over time. + + The circuit: + Any analog input sensor is attached to analog in pin 0. + + http://www.arduino.cc/en/Tutorial/Graph + + created 2006 + by David A. Mellis + modified 14 Apr 2009 + by Tom Igoe and Scott Fitzgerald + + http://www.arduino.cc/en/Tutorial/Graph + */ + +void setup() { + // initialize the serial communication: + Serial.begin(9600); +} + +void loop() { + // send the value of analog input 0: + Serial.println(analogRead(0)); + // wait a bit for the analog-to-digital converter + // to stabilize after the last reading: + delay(10); +} + +/* Processing code for this example + + // Graphing sketch + + + // This program takes ASCII-encoded strings + // from the serial port at 9600 baud and graphs them. It expects values in the + // range 0 to 1023, followed by a newline, or newline and carriage return + + // Created 20 Apr 2005 + // Updated 18 Jan 2008 + // by Tom Igoe + + import processing.serial.*; + + Serial myPort; // The serial port + int xPos = 1; // horizontal position of the graph + + void setup () { + // set the window size: + size(400, 300); + + // List all the available serial ports + println(Serial.list()); + // I know that the first port in the serial list on my mac + // is always my Arduino, so I open Serial.list()[0]. + // Open whatever port is the one you're using. + myPort = new Serial(this, Serial.list()[0], 9600); + // don't generate a serialEvent() unless you get a newline character: + myPort.bufferUntil('\n'); + // set inital background: + background(0); + } + void draw () { + // everything happens in the serialEvent() + } + + void serialEvent (Serial myPort) { + // get the ASCII string: + String inString = myPort.readStringUntil('\n'); + + if (inString != null) { + // trim off any whitespace: + inString = trim(inString); + // convert to an int and map to the screen height: + float inByte = float(inString); + inByte = map(inByte, 0, 1023, 0, height); + + // draw the line: + stroke(127,34,255); + line(xPos, height, xPos, height - inByte); + + // at the edge of the screen, go back to the beginning: + if (xPos >= width) { + xPos = 0; + background(0); + } + else { + // increment the horizontal position: + xPos++; + } + } + } + + */ + +/* Max/MSP v5 patch for this example + { + "boxes" : [ { + "box" : { + "maxclass" : "comment", + "text" : "Graph\n\nThis patch takes a string, containing ASCII formatted number from 0 to 1023, with a carriage return and linefeed at the end. It converts the string to an integer and graphs it.\n\ncreated 2006\nby David A. Mellis\nmodified 14 Apr 2009\nby Scott Fitzgerald and Tom Igoe", + "linecount" : 10, + "patching_rect" : [ 479.0, 6.0, 344.0, 144.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-32", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "newobj", + "text" : "select 0 1", + "patching_rect" : [ 327.0, 80.0, 62.0, 20.0 ], + "numoutlets" : 3, + "fontsize" : 12.0, + "outlettype" : [ "bang", "bang", "" ], + "id" : "obj-30", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "click here to close the serial port", + "patching_rect" : [ 412.0, 231.0, 206.0, 20.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-26", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "click here to open the serial port", + "patching_rect" : [ 412.0, 205.0, 206.0, 20.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-27", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "message", + "text" : "close", + "patching_rect" : [ 327.0, 231.0, 39.0, 18.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "" ], + "id" : "obj-21", + "fontname" : "Arial", + "numinlets" : 2 + } + + } + , { + "box" : { + "maxclass" : "message", + "text" : "port a", + "patching_rect" : [ 349.0, 205.0, 41.0, 18.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "" ], + "id" : "obj-19", + "fontname" : "Arial", + "numinlets" : 2 + } + + } + , { + "box" : { + "maxclass" : "multislider", + "candicane7" : [ 0.878431, 0.243137, 0.145098, 1.0 ], + "patching_rect" : [ 302.0, 450.0, 246.0, 167.0 ], + "contdata" : 1, + "numoutlets" : 2, + "peakcolor" : [ 0.498039, 0.498039, 0.498039, 1.0 ], + "slidercolor" : [ 0.066667, 0.058824, 0.776471, 1.0 ], + "candicane8" : [ 0.027451, 0.447059, 0.501961, 1.0 ], + "outlettype" : [ "", "" ], + "setminmax" : [ 0.0, 1023.0 ], + "settype" : 0, + "candicane6" : [ 0.733333, 0.035294, 0.788235, 1.0 ], + "setstyle" : 3, + "bgcolor" : [ 0.231373, 0.713726, 1.0, 1.0 ], + "id" : "obj-1", + "candicane4" : [ 0.439216, 0.619608, 0.070588, 1.0 ], + "candicane5" : [ 0.584314, 0.827451, 0.431373, 1.0 ], + "candicane2" : [ 0.145098, 0.203922, 0.356863, 1.0 ], + "candicane3" : [ 0.290196, 0.411765, 0.713726, 1.0 ], + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "Click here to get a list of serial ports", + "patching_rect" : [ 412.0, 179.0, 207.0, 20.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-2", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "Here's the number from Arduino's analog input", + "linecount" : 2, + "patching_rect" : [ 153.0, 409.0, 138.0, 34.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-3", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "Convert ASCII to symbol", + "patching_rect" : [ 379.0, 378.0, 147.0, 20.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-4", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "Convert integer to ASCII", + "patching_rect" : [ 379.0, 355.0, 147.0, 20.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-5", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "number", + "patching_rect" : [ 302.0, 414.0, 37.0, 20.0 ], + "numoutlets" : 2, + "fontsize" : 12.0, + "outlettype" : [ "int", "bang" ], + "bgcolor" : [ 0.866667, 0.866667, 0.866667, 1.0 ], + "id" : "obj-6", + "triscale" : 0.9, + "fontname" : "Arial", + "htextcolor" : [ 0.870588, 0.870588, 0.870588, 1.0 ], + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "newobj", + "text" : "fromsymbol", + "patching_rect" : [ 302.0, 378.0, 74.0, 20.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "" ], + "id" : "obj-7", + "fontname" : "Arial", + "color" : [ 1.0, 0.890196, 0.090196, 1.0 ], + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "newobj", + "text" : "itoa", + "patching_rect" : [ 302.0, 355.0, 46.0, 20.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "int" ], + "id" : "obj-8", + "fontname" : "Arial", + "color" : [ 1.0, 0.890196, 0.090196, 1.0 ], + "numinlets" : 3 + } + + } + , { + "box" : { + "maxclass" : "newobj", + "text" : "zl group 4", + "patching_rect" : [ 302.0, 332.0, 64.0, 20.0 ], + "numoutlets" : 2, + "fontsize" : 12.0, + "outlettype" : [ "", "" ], + "id" : "obj-9", + "fontname" : "Arial", + "numinlets" : 2 + } + + } + , { + "box" : { + "maxclass" : "newobj", + "text" : "select 10 13", + "patching_rect" : [ 244.0, 281.0, 77.0, 20.0 ], + "numoutlets" : 3, + "fontsize" : 12.0, + "outlettype" : [ "bang", "bang", "" ], + "id" : "obj-10", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "toggle", + "patching_rect" : [ 244.0, 43.0, 15.0, 15.0 ], + "numoutlets" : 1, + "outlettype" : [ "int" ], + "id" : "obj-11", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "newobj", + "text" : "qmetro 10", + "patching_rect" : [ 244.0, 80.0, 65.0, 20.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "bang" ], + "id" : "obj-12", + "fontname" : "Arial", + "numinlets" : 2 + } + + } + , { + "box" : { + "maxclass" : "message", + "text" : "print", + "patching_rect" : [ 369.0, 179.0, 36.0, 18.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "" ], + "id" : "obj-13", + "fontname" : "Arial", + "numinlets" : 2 + } + + } + , { + "box" : { + "maxclass" : "newobj", + "text" : "serial a 9600", + "patching_rect" : [ 244.0, 255.0, 84.0, 20.0 ], + "numoutlets" : 2, + "fontsize" : 12.0, + "outlettype" : [ "int", "" ], + "id" : "obj-14", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "Read serial input buffer every 10 milliseconds", + "linecount" : 2, + "patching_rect" : [ 53.0, 72.0, 185.0, 34.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-15", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "If you get newline (ASCII 10), send the list. If you get return (ASCII 13) do nothing. Any other value, add to the list", + "linecount" : 3, + "patching_rect" : [ 332.0, 269.0, 320.0, 48.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-16", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "Click to open/close serial port and start/stop patch", + "linecount" : 2, + "patching_rect" : [ 271.0, 32.0, 199.0, 34.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-17", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + ], + "lines" : [ { + "patchline" : { + "source" : [ "obj-6", 0 ], + "destination" : [ "obj-1", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-7", 0 ], + "destination" : [ "obj-6", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-8", 0 ], + "destination" : [ "obj-7", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-9", 0 ], + "destination" : [ "obj-8", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-10", 0 ], + "destination" : [ "obj-9", 0 ], + "hidden" : 0, + "midpoints" : [ 253.5, 308.0, 311.5, 308.0 ] + } + + } + , { + "patchline" : { + "source" : [ "obj-10", 2 ], + "destination" : [ "obj-9", 0 ], + "hidden" : 0, + "midpoints" : [ 311.5, 320.0, 311.5, 320.0 ] + } + + } + , { + "patchline" : { + "source" : [ "obj-14", 0 ], + "destination" : [ "obj-10", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-12", 0 ], + "destination" : [ "obj-14", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-11", 0 ], + "destination" : [ "obj-12", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-13", 0 ], + "destination" : [ "obj-14", 0 ], + "hidden" : 0, + "midpoints" : [ 378.5, 200.5, 253.5, 200.5 ] + } + + } + , { + "patchline" : { + "source" : [ "obj-19", 0 ], + "destination" : [ "obj-14", 0 ], + "hidden" : 0, + "midpoints" : [ 358.5, 228.5, 253.5, 228.5 ] + } + + } + , { + "patchline" : { + "source" : [ "obj-21", 0 ], + "destination" : [ "obj-14", 0 ], + "hidden" : 0, + "midpoints" : [ 336.5, 251.5, 253.5, 251.5 ] + } + + } + , { + "patchline" : { + "source" : [ "obj-30", 0 ], + "destination" : [ "obj-21", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-30", 1 ], + "destination" : [ "obj-19", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-11", 0 ], + "destination" : [ "obj-30", 0 ], + "hidden" : 0, + "midpoints" : [ 253.0, 71.0, 336.5, 71.0 ] + } + + } + ] + } + + */ diff --git a/arduino-0018-linux/examples/Communication/MIDI/Midi.pde b/arduino-0018-linux/examples/Communication/MIDI/Midi.pde new file mode 100644 index 0000000..feb3e82 --- /dev/null +++ b/arduino-0018-linux/examples/Communication/MIDI/Midi.pde @@ -0,0 +1,47 @@ +/* + MIDI note player + + This sketch shows how to use the serial transmit pin (pin 1) to send MIDI note data. + If this circuit is connected to a MIDI synth, it will play + the notes F#-0 (0x1E) to F#-5 (0x5A) in sequence. + + + The circuit: + * digital in 1 connected to MIDI jack pin 5 + * MIDI jack pin 2 connected to ground + * MIDI jack pin 4 connected to +5V through 220-ohm resistor + Attach a MIDI cable to the jack, then to a MIDI synth, and play music. + + created 13 Jun 2006 + modified 2 Jul 2009 + by Tom Igoe + + http://www.arduino.cc/en/Tutorial/MIDI + + */ + +void setup() { + // Set MIDI baud rate: + Serial.begin(31250); +} + +void loop() { + // play notes from F#-0 (0x1E) to F#-5 (0x5A): + for (intnote = 0x1E; note < 0x5A; note ++) { + //Note on channel 1 (0x90), some note value (note), middle velocity (0x45): + noteOn(0x90, note, 0x45); + delay(100); + //Note on channel 1 (0x90), some note value (note), silent velocity (0x00): + noteOn(0x90, note, 0x00); + delay(100); + } +} + +// plays a MIDI note. Doesn't check to see that +// cmd is greater than 127, or that data values are less than 127: +void noteOn(int cmd, int pitch, int velocity) { + Serial.print(cmd, BYTE); + Serial.print(pitch, BYTE); + Serial.print(velocity, BYTE); +} + diff --git a/arduino-0018-linux/examples/Communication/MultiSerialMega/MultiSerialMega.pde b/arduino-0018-linux/examples/Communication/MultiSerialMega/MultiSerialMega.pde new file mode 100644 index 0000000..f587c63 --- /dev/null +++ b/arduino-0018-linux/examples/Communication/MultiSerialMega/MultiSerialMega.pde @@ -0,0 +1,31 @@ +/* + Mega multple serial test + + Receives from the main serial port, sends to the others. + Receives from serial port 1, sends to the main serial (Serial 0). + + This example works only on the Arduino Mega + + The circuit: + * Any serial device attached to Serial port 1 + * Serial monitor open on Serial port 0: + + created 30 Dec. 2008 + by Tom Igoe + + */ + + +void setup() { + // initialize both serial ports: + Serial.begin(9600); + Serial1.begin(9600); +} + +void loop() { + // read from port 1, send to port 0: + if (Serial1.available()) { + int inByte = Serial1.read(); + Serial.print(inByte, BYTE); + } +} diff --git a/arduino-0018-linux/examples/Communication/PhysicalPixel/PhysicalPixel.pde b/arduino-0018-linux/examples/Communication/PhysicalPixel/PhysicalPixel.pde new file mode 100644 index 0000000..b5006ec --- /dev/null +++ b/arduino-0018-linux/examples/Communication/PhysicalPixel/PhysicalPixel.pde @@ -0,0 +1,707 @@ +/* + Physical Pixel + + An example of using the Arduino board to receive data from the + computer. In this case, the Arduino boards turns on an LED when + it receives the character 'H', and turns off the LED when it + receives the character 'L'. + + The data can be sent from the Arduino serial monitor, or another + program like Processing (see code below), Flash (via a serial-net + proxy), PD, or Max/MSP. + + The circuit: + * LED connected from digital pin 13 to ground + + created 2006 + by David A. Mellis + modified 14 Apr 2009 + by Tom Igoe and Scott Fitzgerald + + http://www.arduino.cc/en/Tutorial/PhysicalPixel + */ + +const int ledPin = 13; // the pin that the LED is attached to +int incomingByte; // a variable to read incoming serial data into + +void setup() { + // initialize serial communication: + Serial.begin(9600); + // initialize the LED pin as an output: + pinMode(ledPin, OUTPUT); +} + +void loop() { + // see if there's incoming serial data: + if (Serial.available() > 0) { + // read the oldest byte in the serial buffer: + incomingByte = Serial.read(); + // if it's a capital H (ASCII 72), turn on the LED: + if (incomingByte == 'H') { + digitalWrite(ledPin, HIGH); + } + // if it's an L (ASCII 76) turn off the LED: + if (incomingByte == 'L') { + digitalWrite(ledPin, LOW); + } + } +} + +/* Processing code for this example + + // mouseover serial + + // Demonstrates how to send data to the Arduino I/O board, in order to + // turn ON a light if the mouse is over a square and turn it off + // if the mouse is not. + + // created 2003-4 + // based on examples by Casey Reas and Hernando Barragan + // modified 18 Jan 2009 + // by Tom Igoe + + + import processing.serial.*; + + float boxX; + float boxY; + int boxSize = 20; + boolean mouseOverBox = false; + + Serial port; + + void setup() { + size(200, 200); + boxX = width/2.0; + boxY = height/2.0; + rectMode(RADIUS); + + // List all the available serial ports in the output pane. + // You will need to choose the port that the Arduino board is + // connected to from this list. The first port in the list is + // port #0 and the third port in the list is port #2. + println(Serial.list()); + + // Open the port that the Arduino board is connected to (in this case #0) + // Make sure to open the port at the same speed Arduino is using (9600bps) + port = new Serial(this, Serial.list()[0], 9600); + + } + + void draw() + { + background(0); + + // Test if the cursor is over the box + if (mouseX > boxX-boxSize && mouseX < boxX+boxSize && + mouseY > boxY-boxSize && mouseY < boxY+boxSize) { + mouseOverBox = true; + // draw a line around the box and change its color: + stroke(255); + fill(153); + // send an 'H' to indicate mouse is over square: + port.write('H'); + } + else { + // return the box to it's inactive state: + stroke(153); + fill(153); + // send an 'L' to turn the LED off: + port.write('L'); + mouseOverBox = false; + } + + // Draw the box + rect(boxX, boxY, boxSize, boxSize); + } + + + */ + +/* +{ + "boxes" : [ { + "box" : { + "maxclass" : "comment", + "text" : "Physical Pixel\n\nThis patch sends an ASCII H or an ASCII L out the serial port to turn on an LED attached to an Arduino board. It can also send alternating H and L characters once every second to make the LED blink.\n\ncreated 2006\nby David A. Mellis\nmodified 14 Apr 2009\nby Scott Fitzgerald and Tom Igoe", + "linecount" : 11, + "patching_rect" : [ 14.0, 35.0, 354.0, 158.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-1", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "Click to blink every second", + "patching_rect" : [ 99.0, 251.0, 161.0, 20.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-38", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "toggle", + "patching_rect" : [ 74.0, 251.0, 21.0, 21.0 ], + "numoutlets" : 1, + "outlettype" : [ "int" ], + "id" : "obj-39", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "newobj", + "text" : "p blink", + "patching_rect" : [ 74.0, 286.0, 45.0, 20.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "int" ], + "id" : "obj-37", + "fontname" : "Arial", + "numinlets" : 2, + "patcher" : { + "fileversion" : 1, + "rect" : [ 54.0, 94.0, 640.0, 480.0 ], + "bglocked" : 0, + "defrect" : [ 54.0, 94.0, 640.0, 480.0 ], + "openrect" : [ 0.0, 0.0, 0.0, 0.0 ], + "openinpresentation" : 0, + "default_fontsize" : 10.0, + "default_fontface" : 0, + "default_fontname" : "Verdana", + "gridonopen" : 0, + "gridsize" : [ 25.0, 25.0 ], + "gridsnaponopen" : 0, + "toolbarvisible" : 1, + "boxanimatetime" : 200, + "imprint" : 0, + "boxes" : [ { + "box" : { + "maxclass" : "newobj", + "text" : "* 1000", + "patching_rect" : [ 200.0, 150.0, 46.0, 19.0 ], + "numoutlets" : 1, + "fontsize" : 10.0, + "outlettype" : [ "int" ], + "id" : "obj-12", + "fontname" : "Verdana", + "numinlets" : 2 + } + + } + , { + "box" : { + "maxclass" : "inlet", + "patching_rect" : [ 200.0, 75.0, 25.0, 25.0 ], + "numoutlets" : 1, + "outlettype" : [ "" ], + "id" : "obj-11", + "numinlets" : 0, + "comment" : "" + } + + } + , { + "box" : { + "maxclass" : "toggle", + "patching_rect" : [ 125.0, 250.0, 20.0, 20.0 ], + "numoutlets" : 1, + "outlettype" : [ "int" ], + "id" : "obj-10", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "newobj", + "text" : "metro 1000", + "patching_rect" : [ 115.0, 190.0, 69.0, 19.0 ], + "numoutlets" : 1, + "fontsize" : 10.0, + "outlettype" : [ "bang" ], + "id" : "obj-3", + "fontname" : "Verdana", + "numinlets" : 2 + } + + } + , { + "box" : { + "maxclass" : "outlet", + "patching_rect" : [ 125.0, 400.0, 25.0, 25.0 ], + "numoutlets" : 0, + "id" : "obj-2", + "numinlets" : 1, + "comment" : "" + } + + } + , { + "box" : { + "maxclass" : "inlet", + "patching_rect" : [ 100.0, 25.0, 25.0, 25.0 ], + "numoutlets" : 1, + "outlettype" : [ "int" ], + "id" : "obj-1", + "numinlets" : 0, + "comment" : "" + } + + } + ], + "lines" : [ { + "patchline" : { + "source" : [ "obj-12", 0 ], + "destination" : [ "obj-3", 1 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-11", 0 ], + "destination" : [ "obj-12", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-1", 0 ], + "destination" : [ "obj-3", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-10", 0 ], + "destination" : [ "obj-2", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-3", 0 ], + "destination" : [ "obj-10", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + ] + } + , + "saved_object_attributes" : { + "fontface" : 0, + "fontsize" : 10.0, + "default_fontface" : 0, + "default_fontname" : "Verdana", + "default_fontsize" : 10.0, + "fontname" : "Verdana", + "globalpatchername" : "" + } + + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "convert to int", + "patching_rect" : [ 154.0, 386.0, 104.0, 20.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-36", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "send L if 0, H if 1", + "patching_rect" : [ 154.0, 361.0, 104.0, 20.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-35", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "is it on or off?", + "patching_rect" : [ 179.0, 336.0, 95.0, 20.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-34", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "newobj", + "text" : "atoi", + "patching_rect" : [ 279.0, 386.0, 46.0, 20.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "list" ], + "id" : "obj-33", + "fontname" : "Arial", + "numinlets" : 3 + } + + } + , { + "box" : { + "maxclass" : "message", + "text" : "H", + "patching_rect" : [ 329.0, 361.0, 32.5, 17.0 ], + "numoutlets" : 1, + "fontsize" : 10.0, + "outlettype" : [ "" ], + "id" : "obj-32", + "fontname" : "Verdana", + "numinlets" : 2 + } + + } + , { + "box" : { + "maxclass" : "message", + "text" : "L", + "patching_rect" : [ 279.0, 361.0, 32.5, 17.0 ], + "numoutlets" : 1, + "fontsize" : 10.0, + "outlettype" : [ "" ], + "id" : "obj-31", + "fontname" : "Verdana", + "numinlets" : 2 + } + + } + , { + "box" : { + "maxclass" : "newobj", + "text" : "select 0 1", + "patching_rect" : [ 279.0, 336.0, 62.0, 20.0 ], + "numoutlets" : 3, + "fontsize" : 12.0, + "outlettype" : [ "bang", "bang", "" ], + "id" : "obj-25", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "Click to turn the LED on and off", + "linecount" : 2, + "patching_rect" : [ 130.0, 205.0, 143.0, 34.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-24", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "toggle", + "patching_rect" : [ 279.0, 211.0, 24.0, 24.0 ], + "numoutlets" : 1, + "outlettype" : [ "int" ], + "id" : "obj-23", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "newobj", + "text" : "select 0 1", + "patching_rect" : [ 381.0, 331.0, 62.0, 20.0 ], + "numoutlets" : 3, + "fontsize" : 12.0, + "outlettype" : [ "bang", "bang", "" ], + "id" : "obj-30", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "click here to close the serial port", + "patching_rect" : [ 429.0, 422.0, 206.0, 20.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-26", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "click here to open the serial port", + "patching_rect" : [ 454.0, 396.0, 206.0, 20.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-27", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "message", + "text" : "close", + "patching_rect" : [ 381.0, 422.0, 39.0, 18.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "" ], + "id" : "obj-21", + "fontname" : "Arial", + "numinlets" : 2 + } + + } + , { + "box" : { + "maxclass" : "message", + "text" : "port a", + "patching_rect" : [ 403.0, 396.0, 41.0, 18.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "" ], + "id" : "obj-19", + "fontname" : "Arial", + "numinlets" : 2 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "Click here to get a list of serial ports", + "patching_rect" : [ 474.0, 370.0, 207.0, 20.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-2", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "toggle", + "patching_rect" : [ 381.0, 181.0, 21.0, 21.0 ], + "numoutlets" : 1, + "outlettype" : [ "int" ], + "id" : "obj-11", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "message", + "text" : "print", + "patching_rect" : [ 423.0, 370.0, 36.0, 18.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "" ], + "id" : "obj-13", + "fontname" : "Arial", + "numinlets" : 2 + } + + } + , { + "box" : { + "maxclass" : "newobj", + "text" : "serial a 9600", + "patching_rect" : [ 279.0, 461.0, 84.0, 20.0 ], + "numoutlets" : 2, + "fontsize" : 12.0, + "outlettype" : [ "int", "" ], + "id" : "obj-14", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "Click to start", + "patching_rect" : [ 408.0, 181.0, 117.0, 20.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-17", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + ], + "lines" : [ { + "patchline" : { + "source" : [ "obj-39", 0 ], + "destination" : [ "obj-37", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-37", 0 ], + "destination" : [ "obj-25", 0 ], + "hidden" : 0, + "midpoints" : [ 83.5, 320.5, 288.5, 320.5 ] + } + + } + , { + "patchline" : { + "source" : [ "obj-33", 0 ], + "destination" : [ "obj-14", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-32", 0 ], + "destination" : [ "obj-33", 0 ], + "hidden" : 0, + "midpoints" : [ 338.5, 381.5, 288.5, 381.5 ] + } + + } + , { + "patchline" : { + "source" : [ "obj-31", 0 ], + "destination" : [ "obj-33", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-25", 0 ], + "destination" : [ "obj-31", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-25", 1 ], + "destination" : [ "obj-32", 0 ], + "hidden" : 0, + "midpoints" : [ 310.0, 358.0, 338.5, 358.0 ] + } + + } + , { + "patchline" : { + "source" : [ "obj-23", 0 ], + "destination" : [ "obj-25", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-13", 0 ], + "destination" : [ "obj-14", 0 ], + "hidden" : 0, + "midpoints" : [ 432.5, 389.0, 367.0, 389.0, 367.0, 411.0, 288.5, 411.0 ] + } + + } + , { + "patchline" : { + "source" : [ "obj-19", 0 ], + "destination" : [ "obj-14", 0 ], + "hidden" : 0, + "midpoints" : [ 412.5, 417.0, 288.5, 417.0 ] + } + + } + , { + "patchline" : { + "source" : [ "obj-21", 0 ], + "destination" : [ "obj-14", 0 ], + "hidden" : 0, + "midpoints" : [ 390.5, 450.0, 288.5, 450.0 ] + } + + } + , { + "patchline" : { + "source" : [ "obj-30", 0 ], + "destination" : [ "obj-21", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-30", 1 ], + "destination" : [ "obj-19", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-11", 0 ], + "destination" : [ "obj-30", 0 ], + "hidden" : 0, + "midpoints" : [ 390.5, 322.0, 390.5, 322.0 ] + } + + } + ] + } + + */ diff --git a/arduino-0018-linux/examples/Communication/SerialCallResponse/SerialCallResponse.pde b/arduino-0018-linux/examples/Communication/SerialCallResponse/SerialCallResponse.pde new file mode 100644 index 0000000..809bbf8 --- /dev/null +++ b/arduino-0018-linux/examples/Communication/SerialCallResponse/SerialCallResponse.pde @@ -0,0 +1,1193 @@ +/* + Serial Call and Response + Language: Wiring/Arduino + + This program sends an ASCII A (byte of value 65) on startup + and repeats that until it gets some data in. + Then it waits for a byte in the serial port, and + sends three sensor values whenever it gets a byte in. + + Thanks to Greg Shakar and Scott Fitzgerald for the improvements + + The circuit: + * potentiometers attached to analog inputs 0 and 1 + * pushbutton attached to digital I/O 2 + + + http://www.arduino.cc/en/Tutorial/SerialCallResponse + + Created 26 Sept. 2005 + by Tom Igoe + Modified 14 April 2009 + by Tom Igoe and Scott Fitzgerald + */ + +int firstSensor = 0; // first analog sensor +int secondSensor = 0; // second analog sensor +int thirdSensor = 0; // digital sensor +int inByte = 0; // incoming serial byte + +void setup() +{ + // start serial port at 9600 bps: + Serial.begin(9600); + pinMode(2, INPUT); // digital sensor is on digital pin 2 + establishContact(); // send a byte to establish contact until receiver responds +} + +void loop() +{ + // if we get a valid byte, read analog ins: + if (Serial.available() > 0) { + // get incoming byte: + inByte = Serial.read(); + // read first analog input, divide by 4 to make the range 0-255: + firstSensor = analogRead(0)/4; + // delay 10ms to let the ADC recover: + delay(10); + // read second analog input, divide by 4 to make the range 0-255: + secondSensor = analogRead(1)/4; + // read switch, map it to 0 or 255L + thirdSensor = map(digitalRead(2), 0, 1, 0, 255); + // send sensor values: + Serial.print(firstSensor, BYTE); + Serial.print(secondSensor, BYTE); + Serial.print(thirdSensor, BYTE); + } +} + +void establishContact() { + while (Serial.available() <= 0) { + Serial.print('A', BYTE); // send a capital A + delay(300); + } +} + +/* +Processing sketch to run with this example: + +import processing.serial.*; + +int bgcolor; // Background color +int fgcolor; // Fill color +Serial myPort; // The serial port +int[] serialInArray = new int[3]; // Where we'll put what we receive +int serialCount = 0; // A count of how many bytes we receive +int xpos, ypos; // Starting position of the ball +boolean firstContact = false; // Whether we've heard from the microcontroller + +void setup() { + size(256, 256); // Stage size + noStroke(); // No border on the next thing drawn + + // Set the starting position of the ball (middle of the stage) + xpos = width/2; + ypos = height/2; + + // Print a list of the serial ports, for debugging purposes: + println(Serial.list()); + + // I know that the first port in the serial list on my mac + // is always my FTDI adaptor, so I open Serial.list()[0]. + // On Windows machines, this generally opens COM1. + // Open whatever port is the one you're using. + String portName = Serial.list()[0]; + myPort = new Serial(this, portName, 9600); +} + +void draw() { + background(bgcolor); + fill(fgcolor); + // Draw the shape + ellipse(xpos, ypos, 20, 20); +} + +void serialEvent(Serial myPort) { + // read a byte from the serial port: + int inByte = myPort.read(); + // if this is the first byte received, and it's an A, + // clear the serial buffer and note that you've + // had first contact from the microcontroller. + // Otherwise, add the incoming byte to the array: + if (firstContact == false) { + if (inByte == 'A') { + myPort.clear(); // clear the serial port buffer + firstContact = true; // you've had first contact from the microcontroller + myPort.write('A'); // ask for more + } + } + else { + // Add the latest byte from the serial port to array: + serialInArray[serialCount] = inByte; + serialCount++; + + // If we have 3 bytes: + if (serialCount > 2 ) { + xpos = serialInArray[0]; + ypos = serialInArray[1]; + fgcolor = serialInArray[2]; + + // print the values (for debugging purposes only): + println(xpos + "\t" + ypos + "\t" + fgcolor); + + // Send a capital A to request new sensor readings: + myPort.write('A'); + // Reset serialCount: + serialCount = 0; + } + } +} +*/ + +/* +Max/MSP version 5 patch to run with this example: + +{ + "boxes" : [ { + "box" : { + "maxclass" : "message", + "text" : "65", + "patching_rect" : [ 339.0, 466.0, 32.5, 18.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "" ], + "id" : "obj-9", + "fontname" : "Arial", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "sel 1", + "patching_rect" : [ 339.0, 437.0, 36.0, 20.0 ], + "numoutlets" : 2, + "fontsize" : 12.0, + "outlettype" : [ "bang", "" ], + "id" : "obj-6", + "fontname" : "Arial", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "comment", + "text" : "Serial Call-Response \n\nSends a byte out the serial port, and reads 3 bytes in. Sets foregound color, xpos, and ypos of a circle using the values returned from the serial port. \n\nNote: This patch assumes that the device on the other end of the serial port is going to send a single byte of value 65 (ASCII A) on startup. The sketch waits for that byte, then sends an ASCII A whenever it wants more data. \n\ncreated 14 Apr 2009\nby Scott Fitzgerald and Tom Igoe", + "linecount" : 11, + "patching_rect" : [ 404.0, 52.0, 464.0, 158.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-5", + "fontname" : "Arial", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "comment", + "text" : "trigger (or [t]) forces right-left conventions. All the drawing and processing will happen before Max requests new values. When this trigger fires, it sends an ASCII A to ask Arduino for new values.", + "linecount" : 3, + "patching_rect" : [ 239.0, 505.0, 425.0, 48.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-65", + "fontname" : "Arial", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "comment", + "text" : "reinitializes the gates when turned on and off", + "linecount" : 2, + "patching_rect" : [ 170.0, 370.0, 135.0, 34.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-64", + "fontname" : "Arial", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "comment", + "text" : "checks for the ascii value of \"A\" to begin cominucation. After initial communication is made, this block shuts down.", + "linecount" : 3, + "patching_rect" : [ 460.0, 355.0, 233.0, 48.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-63", + "fontname" : "Arial", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "p \"draw the circle\"", + "patching_rect" : [ 217.0, 645.0, 269.0, 19.0 ], + "numoutlets" : 1, + "fontsize" : 10.0, + "outlettype" : [ "" ], + "id" : "obj-62", + "fontname" : "Verdana", + "numinlets" : 3, + "patcher" : { + "fileversion" : 1, + "rect" : [ 54.0, 94.0, 640.0, 480.0 ], + "bglocked" : 0, + "defrect" : [ 54.0, 94.0, 640.0, 480.0 ], + "openrect" : [ 0.0, 0.0, 0.0, 0.0 ], + "openinpresentation" : 0, + "default_fontsize" : 10.0, + "default_fontface" : 0, + "default_fontname" : "Verdana", + "gridonopen" : 0, + "gridsize" : [ 25.0, 25.0 ], + "gridsnaponopen" : 0, + "toolbarvisible" : 1, + "boxanimatetime" : 200, + "imprint" : 0, + "boxes" : [ { + "box" : { + "maxclass" : "message", + "text" : "frgb 255 255 255", + "patching_rect" : [ 375.0, 150.0, 98.0, 18.0 ], + "numoutlets" : 1, + "fontsize" : 11.595187, + "outlettype" : [ "" ], + "id" : "obj-47", + "fontname" : "Arial", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "message", + "text" : "frgb 0 0 0", + "patching_rect" : [ 275.0, 125.0, 59.0, 18.0 ], + "numoutlets" : 1, + "fontsize" : 11.595187, + "outlettype" : [ "" ], + "id" : "obj-46", + "fontname" : "Arial", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "sel 255 0", + "patching_rect" : [ 300.0, 100.0, 66.0, 21.0 ], + "numoutlets" : 3, + "fontsize" : 12.0, + "outlettype" : [ "bang", "bang", "" ], + "id" : "obj-45", + "fontname" : "Verdana", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "pack 0 0 0 0", + "patching_rect" : [ 50.0, 125.0, 180.0, 21.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "" ], + "id" : "obj-43", + "fontname" : "Verdana", + "numinlets" : 4 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "+ 10", + "patching_rect" : [ 200.0, 100.0, 40.0, 21.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "int" ], + "id" : "obj-42", + "fontname" : "Verdana", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "+ 10", + "patching_rect" : [ 75.0, 100.0, 40.0, 21.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "int" ], + "id" : "obj-41", + "fontname" : "Verdana", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "message", + "text" : "clear, paintoval $1 $2 $3 $4", + "patching_rect" : [ 50.0, 150.0, 152.0, 18.0 ], + "numoutlets" : 1, + "fontsize" : 11.595187, + "outlettype" : [ "" ], + "id" : "obj-40", + "fontname" : "Arial", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "inlet", + "patching_rect" : [ 57.5, 40.0, 25.0, 25.0 ], + "numoutlets" : 1, + "outlettype" : [ "int" ], + "id" : "obj-58", + "numinlets" : 0, + "comment" : "" + } + + } +, { + "box" : { + "maxclass" : "inlet", + "patching_rect" : [ 120.0, 40.0, 25.0, 25.0 ], + "numoutlets" : 1, + "outlettype" : [ "int" ], + "id" : "obj-59", + "numinlets" : 0, + "comment" : "" + } + + } +, { + "box" : { + "maxclass" : "inlet", + "patching_rect" : [ 300.0, 40.0, 25.0, 25.0 ], + "numoutlets" : 1, + "outlettype" : [ "int" ], + "id" : "obj-60", + "numinlets" : 0, + "comment" : "" + } + + } +, { + "box" : { + "maxclass" : "outlet", + "patching_rect" : [ 228.333344, 228.0, 25.0, 25.0 ], + "numoutlets" : 0, + "id" : "obj-61", + "numinlets" : 1, + "comment" : "" + } + + } + ], + "lines" : [ { + "patchline" : { + "source" : [ "obj-47", 0 ], + "destination" : [ "obj-61", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-46", 0 ], + "destination" : [ "obj-61", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-40", 0 ], + "destination" : [ "obj-61", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-60", 0 ], + "destination" : [ "obj-45", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-59", 0 ], + "destination" : [ "obj-42", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-59", 0 ], + "destination" : [ "obj-43", 1 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-58", 0 ], + "destination" : [ "obj-41", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-58", 0 ], + "destination" : [ "obj-43", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-42", 0 ], + "destination" : [ "obj-43", 3 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-41", 0 ], + "destination" : [ "obj-43", 2 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-45", 1 ], + "destination" : [ "obj-47", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-45", 0 ], + "destination" : [ "obj-46", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-43", 0 ], + "destination" : [ "obj-40", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + ] + } +, + "saved_object_attributes" : { + "fontface" : 0, + "fontsize" : 10.0, + "default_fontface" : 0, + "default_fontname" : "Verdana", + "default_fontsize" : 10.0, + "fontname" : "Verdana", + "globalpatchername" : "" + } + + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "0", + "patching_rect" : [ 310.0, 378.0, 32.5, 20.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "int" ], + "id" : "obj-57", + "fontname" : "Arial", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "!- 1", + "patching_rect" : [ 385.0, 436.0, 32.5, 20.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "int" ], + "id" : "obj-55", + "fontname" : "Arial", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "gate 1 1", + "patching_rect" : [ 385.0, 355.0, 54.0, 20.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "" ], + "id" : "obj-54", + "fontname" : "Arial", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "toggle", + "patching_rect" : [ 385.0, 405.0, 20.0, 20.0 ], + "numoutlets" : 1, + "outlettype" : [ "int" ], + "id" : "obj-53", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "gate 1 0", + "patching_rect" : [ 194.0, 455.0, 54.0, 20.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "" ], + "id" : "obj-50", + "fontname" : "Arial", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "sel 65", + "patching_rect" : [ 385.0, 380.0, 43.0, 20.0 ], + "numoutlets" : 2, + "fontsize" : 12.0, + "outlettype" : [ "bang", "" ], + "id" : "obj-48", + "fontname" : "Arial", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "lcd", + "patching_rect" : [ 217.0, 695.0, 256.0, 256.0 ], + "numoutlets" : 4, + "outlettype" : [ "list", "list", "int", "" ], + "id" : "obj-39", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "t 65 l", + "patching_rect" : [ 194.0, 504.0, 42.0, 21.0 ], + "numoutlets" : 2, + "fontsize" : 12.0, + "outlettype" : [ "int", "" ], + "id" : "obj-35", + "fontname" : "Verdana", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "comment", + "text" : "val3", + "patching_rect" : [ 535.0, 604.0, 37.0, 21.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-1", + "fontname" : "Verdana", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "number", + "patching_rect" : [ 467.0, 604.0, 56.0, 21.0 ], + "numoutlets" : 2, + "fontsize" : 12.0, + "outlettype" : [ "int", "bang" ], + "id" : "obj-3", + "fontname" : "Verdana", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "comment", + "text" : "val2", + "patching_rect" : [ 410.0, 605.0, 37.0, 21.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-18", + "fontname" : "Verdana", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "comment", + "text" : "val1", + "patching_rect" : [ 282.0, 605.0, 37.0, 21.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-20", + "fontname" : "Verdana", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "number", + "patching_rect" : [ 342.0, 605.0, 56.0, 21.0 ], + "numoutlets" : 2, + "fontsize" : 12.0, + "outlettype" : [ "int", "bang" ], + "id" : "obj-22", + "fontname" : "Verdana", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "number", + "patching_rect" : [ 217.0, 605.0, 55.0, 21.0 ], + "numoutlets" : 2, + "fontsize" : 12.0, + "outlettype" : [ "int", "bang" ], + "id" : "obj-23", + "fontname" : "Verdana", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "unpack 0 0 0", + "patching_rect" : [ 217.0, 570.0, 269.0, 21.0 ], + "numoutlets" : 3, + "fontsize" : 12.0, + "outlettype" : [ "int", "int", "int" ], + "id" : "obj-29", + "fontname" : "Verdana", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "zl group 3", + "patching_rect" : [ 194.0, 480.0, 71.0, 21.0 ], + "numoutlets" : 2, + "fontsize" : 12.0, + "outlettype" : [ "", "" ], + "id" : "obj-31", + "fontname" : "Verdana", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "select 0 1", + "patching_rect" : [ 312.0, 200.0, 62.0, 20.0 ], + "numoutlets" : 3, + "fontsize" : 12.0, + "outlettype" : [ "bang", "bang", "" ], + "id" : "obj-30", + "fontname" : "Arial", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "comment", + "text" : "click here to close the serial port", + "patching_rect" : [ 360.0, 291.0, 206.0, 20.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-26", + "fontname" : "Arial", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "comment", + "text" : "click here to open the serial port", + "patching_rect" : [ 385.0, 265.0, 206.0, 20.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-27", + "fontname" : "Arial", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "message", + "text" : "close", + "patching_rect" : [ 312.0, 291.0, 39.0, 18.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "" ], + "id" : "obj-21", + "fontname" : "Arial", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "message", + "text" : "port a", + "patching_rect" : [ 334.0, 265.0, 41.0, 18.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "" ], + "id" : "obj-19", + "fontname" : "Arial", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "comment", + "text" : "Click here to get a list of serial ports", + "patching_rect" : [ 405.0, 239.0, 207.0, 20.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-2", + "fontname" : "Arial", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "toggle", + "patching_rect" : [ 229.0, 155.0, 22.0, 22.0 ], + "numoutlets" : 1, + "outlettype" : [ "int" ], + "id" : "obj-11", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "qmetro 10", + "patching_rect" : [ 229.0, 200.0, 65.0, 20.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "bang" ], + "id" : "obj-12", + "fontname" : "Arial", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "message", + "text" : "print", + "patching_rect" : [ 354.0, 239.0, 36.0, 18.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "" ], + "id" : "obj-13", + "fontname" : "Arial", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "serial a 9600", + "patching_rect" : [ 229.0, 315.0, 84.0, 20.0 ], + "numoutlets" : 2, + "fontsize" : 12.0, + "outlettype" : [ "int", "" ], + "id" : "obj-14", + "fontname" : "Arial", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "comment", + "text" : "Read serial input buffer every 10 milliseconds", + "linecount" : 2, + "patching_rect" : [ 13.0, 192.0, 210.0, 34.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-15", + "fontname" : "Arial", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "comment", + "text" : "Click to start", + "patching_rect" : [ 256.0, 163.0, 117.0, 20.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-17", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + ], + "lines" : [ { + "patchline" : { + "source" : [ "obj-12", 0 ], + "destination" : [ "obj-14", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-11", 0 ], + "destination" : [ "obj-12", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-13", 0 ], + "destination" : [ "obj-14", 0 ], + "hidden" : 0, + "midpoints" : [ 363.5, 260.5, 238.5, 260.5 ] + } + + } +, { + "patchline" : { + "source" : [ "obj-19", 0 ], + "destination" : [ "obj-14", 0 ], + "hidden" : 0, + "midpoints" : [ 343.5, 288.5, 238.5, 288.5 ] + } + + } +, { + "patchline" : { + "source" : [ "obj-21", 0 ], + "destination" : [ "obj-14", 0 ], + "hidden" : 0, + "midpoints" : [ 321.5, 311.5, 238.5, 311.5 ] + } + + } +, { + "patchline" : { + "source" : [ "obj-30", 0 ], + "destination" : [ "obj-21", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-30", 1 ], + "destination" : [ "obj-19", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-11", 0 ], + "destination" : [ "obj-30", 0 ], + "hidden" : 0, + "midpoints" : [ 238.5, 191.0, 321.5, 191.0 ] + } + + } +, { + "patchline" : { + "source" : [ "obj-29", 2 ], + "destination" : [ "obj-3", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-29", 0 ], + "destination" : [ "obj-23", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-29", 1 ], + "destination" : [ "obj-22", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-14", 0 ], + "destination" : [ "obj-50", 1 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-50", 0 ], + "destination" : [ "obj-31", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-48", 0 ], + "destination" : [ "obj-53", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-53", 0 ], + "destination" : [ "obj-50", 0 ], + "hidden" : 0, + "midpoints" : [ 394.5, 426.0, 203.5, 426.0 ] + } + + } +, { + "patchline" : { + "source" : [ "obj-14", 0 ], + "destination" : [ "obj-54", 1 ], + "hidden" : 0, + "midpoints" : [ 238.5, 342.0, 429.5, 342.0 ] + } + + } +, { + "patchline" : { + "source" : [ "obj-54", 0 ], + "destination" : [ "obj-48", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-62", 0 ], + "destination" : [ "obj-39", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-3", 0 ], + "destination" : [ "obj-62", 2 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-22", 0 ], + "destination" : [ "obj-62", 1 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-23", 0 ], + "destination" : [ "obj-62", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-53", 0 ], + "destination" : [ "obj-55", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-55", 0 ], + "destination" : [ "obj-54", 0 ], + "hidden" : 0, + "midpoints" : [ 394.5, 459.0, 453.0, 459.0, 453.0, 351.0, 394.5, 351.0 ] + } + + } +, { + "patchline" : { + "source" : [ "obj-30", 0 ], + "destination" : [ "obj-57", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-57", 0 ], + "destination" : [ "obj-53", 0 ], + "hidden" : 0, + "midpoints" : [ 319.5, 401.0, 394.5, 401.0 ] + } + + } +, { + "patchline" : { + "source" : [ "obj-35", 0 ], + "destination" : [ "obj-14", 0 ], + "hidden" : 0, + "midpoints" : [ 203.5, 542.0, 167.0, 542.0, 167.0, 300.0, 238.5, 300.0 ] + } + + } +, { + "patchline" : { + "source" : [ "obj-35", 1 ], + "destination" : [ "obj-29", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-31", 0 ], + "destination" : [ "obj-35", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-6", 0 ], + "destination" : [ "obj-9", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-53", 0 ], + "destination" : [ "obj-6", 0 ], + "hidden" : 0, + "midpoints" : [ 394.5, 431.5, 348.5, 431.5 ] + } + + } +, { + "patchline" : { + "source" : [ "obj-9", 0 ], + "destination" : [ "obj-14", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + ] +} + + +*/ diff --git a/arduino-0018-linux/examples/Communication/SerialCallResponseASCII/SerialCallResponseASCII.pde b/arduino-0018-linux/examples/Communication/SerialCallResponseASCII/SerialCallResponseASCII.pde new file mode 100644 index 0000000..7c2528d --- /dev/null +++ b/arduino-0018-linux/examples/Communication/SerialCallResponseASCII/SerialCallResponseASCII.pde @@ -0,0 +1,1267 @@ +/* + Serial Call and Response in ASCII + Language: Wiring/Arduino + + This program sends an ASCII A (byte of value 65) on startup + and repeats that until it gets some data in. + Then it waits for a byte in the serial port, and + sends three ASCII-encoded, comma-separated sensor values, + truncated by a linefeed and carriage return, + whenever it gets a byte in. + + Thanks to Greg Shakar and Scott Fitzgerald for the improvements + + The circuit: + * potentiometers attached to analog inputs 0 and 1 + * pushbutton attached to digital I/O 2 + + + http://www.arduino.cc/en/Tutorial/SerialCallResponseASCII + + Created 26 Sept. 2005 + by Tom Igoe + Modified 14 April 2009 + by Tom Igoe and Scott Fitzgerald + */ + +int firstSensor = 0; // first analog sensor +int secondSensor = 0; // second analog sensor +int thirdSensor = 0; // digital sensor +int inByte = 0; // incoming serial byte + +void setup() +{ + // start serial port at 9600 bps: + Serial.begin(9600); + pinMode(2, INPUT); // digital sensor is on digital pin 2 + establishContact(); // send a byte to establish contact until receiver responds +} + +void loop() +{ + // if we get a valid byte, read analog ins: + if (Serial.available() > 0) { + // get incoming byte: + inByte = Serial.read(); + // read first analog input, divide by 4 to make the range 0-255: + firstSensor = analogRead(0)/4; + // delay 10ms to let the ADC recover: + delay(10); + // read second analog input, divide by 4 to make the range 0-255: + secondSensor = analogRead(1)/4; + // read switch, map it to 0 or 255L + thirdSensor = map(digitalRead(2), 0, 1, 0, 255); + // send sensor values: + Serial.print(firstSensor, DEC); + Serial.print(","); + Serial.print(secondSensor, DEC); + Serial.print(","); + Serial.println(thirdSensor, DEC); + } +} + +void establishContact() { + while (Serial.available() <= 0) { + Serial.println("0,0,0"); // send an initial string + delay(300); + } +} + + +/* +Processing code to run with this example: + + +import processing.serial.*; // import the Processing serial library +Serial myPort; // The serial port + +float bgcolor; // Background color +float fgcolor; // Fill color +float xpos, ypos; // Starting position of the ball + +void setup() { + size(640,480); + + // List all the available serial ports + println(Serial.list()); + + // I know that the first port in the serial list on my mac + // is always my Arduino module, so I open Serial.list()[0]. + // Change the 0 to the appropriate number of the serial port + // that your microcontroller is attached to. + myPort = new Serial(this, Serial.list()[0], 9600); + + // read bytes into a buffer until you get a linefeed (ASCII 10): + myPort.bufferUntil('\n'); + + // draw with smooth edges: + smooth(); +} + +void draw() { + background(bgcolor); + fill(fgcolor); + // Draw the shape + ellipse(xpos, ypos, 20, 20); +} + +// serialEvent method is run automatically by the Processing applet +// whenever the buffer reaches the byte value set in the bufferUntil() +// method in the setup(): + +void serialEvent(Serial myPort) { + // read the serial buffer: + String myString = myPort.readStringUntil('\n'); + // if you got any bytes other than the linefeed: + myString = trim(myString); + + // split the string at the commas + // and convert the sections into integers: + int sensors[] = int(split(myString, ',')); + + // print out the values you got: + for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) { + print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t"); + } + // add a linefeed after all the sensor values are printed: + println(); + if (sensors.length > 1) { + xpos = map(sensors[0], 0,1023,0,width); + ypos = map(sensors[1], 0,1023,0,height); + fgcolor = sensors[2]; + } + // send a byte to ask for more data: + myPort.write("A"); + } + +*/ + +/* +{ + "boxes" : [ { + "box" : { + "maxclass" : "newobj", + "text" : "fromsymbol", + "patching_rect" : [ 265.0, 585.0, 74.0, 20.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "" ], + "id" : "obj-7", + "fontname" : "Arial", + "color" : [ 1.0, 0.890196, 0.090196, 1.0 ], + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "itoa", + "patching_rect" : [ 265.0, 562.0, 46.0, 20.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "int" ], + "id" : "obj-8", + "fontname" : "Arial", + "color" : [ 1.0, 0.890196, 0.090196, 1.0 ], + "numinlets" : 3 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "zl group", + "patching_rect" : [ 265.0, 539.0, 53.0, 20.0 ], + "numoutlets" : 2, + "fontsize" : 12.0, + "outlettype" : [ "", "" ], + "id" : "obj-4", + "fontname" : "Arial", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "select 10 13", + "patching_rect" : [ 209.0, 501.0, 75.0, 20.0 ], + "numoutlets" : 3, + "fontsize" : 12.0, + "outlettype" : [ "bang", "bang", "" ], + "id" : "obj-10", + "fontname" : "Arial", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "message", + "text" : "65", + "patching_rect" : [ 354.0, 481.0, 32.5, 18.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "" ], + "id" : "obj-9", + "fontname" : "Arial", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "sel 1", + "patching_rect" : [ 354.0, 452.0, 36.0, 20.0 ], + "numoutlets" : 2, + "fontsize" : 12.0, + "outlettype" : [ "bang", "" ], + "id" : "obj-6", + "fontname" : "Arial", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "comment", + "text" : "Serial Call-Response ASCII \n\nSends a byte out the serial port, and reads 3 ASCII enoded, comma separated in, truncated by a linefeed. It then sets foregound color, xpos, and ypos of a circle using the values returned from the serial port. \n\nNote: This patch assumes that the device on the other end of the serial port is going to send a single byte of value 65 (ASCII A) on startup. The sketch waits for that byte, then sends an ASCII A whenever it wants more data. \n\ncreated 14 Apr 2009\nby Scott Fitzgerald and Tom Igoe", + "linecount" : 12, + "patching_rect" : [ 401.0, 67.0, 540.0, 172.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-5", + "fontname" : "Arial", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "comment", + "text" : "trigger (or [t]) forces right-left conventions. All the drawing and processing will happen before Max requests new values. When this trigger fires, it sends an ASCII A to ask Arduino for new values.", + "linecount" : 3, + "patching_rect" : [ 254.0, 625.0, 425.0, 48.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-65", + "fontname" : "Arial", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "comment", + "text" : "reinitializes the gates when turned on and off", + "linecount" : 2, + "patching_rect" : [ 185.0, 385.0, 135.0, 34.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-64", + "fontname" : "Arial", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "comment", + "text" : "checks for the ascii value of newline to begin communication. After initial communication is made, this block shuts down.", + "linecount" : 3, + "patching_rect" : [ 475.0, 370.0, 252.0, 48.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-63", + "fontname" : "Arial", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "p \"draw the circle\"", + "patching_rect" : [ 232.0, 765.0, 269.0, 19.0 ], + "numoutlets" : 1, + "fontsize" : 10.0, + "outlettype" : [ "" ], + "id" : "obj-62", + "fontname" : "Verdana", + "numinlets" : 3, + "patcher" : { + "fileversion" : 1, + "rect" : [ 54.0, 94.0, 640.0, 480.0 ], + "bglocked" : 0, + "defrect" : [ 54.0, 94.0, 640.0, 480.0 ], + "openrect" : [ 0.0, 0.0, 0.0, 0.0 ], + "openinpresentation" : 0, + "default_fontsize" : 10.0, + "default_fontface" : 0, + "default_fontname" : "Verdana", + "gridonopen" : 0, + "gridsize" : [ 25.0, 25.0 ], + "gridsnaponopen" : 0, + "toolbarvisible" : 1, + "boxanimatetime" : 200, + "imprint" : 0, + "boxes" : [ { + "box" : { + "maxclass" : "message", + "text" : "frgb 255 255 255", + "patching_rect" : [ 375.0, 150.0, 98.0, 18.0 ], + "numoutlets" : 1, + "fontsize" : 11.595187, + "outlettype" : [ "" ], + "id" : "obj-47", + "fontname" : "Arial", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "message", + "text" : "frgb 0 0 0", + "patching_rect" : [ 275.0, 125.0, 59.0, 18.0 ], + "numoutlets" : 1, + "fontsize" : 11.595187, + "outlettype" : [ "" ], + "id" : "obj-46", + "fontname" : "Arial", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "sel 255 0", + "patching_rect" : [ 300.0, 100.0, 66.0, 21.0 ], + "numoutlets" : 3, + "fontsize" : 12.0, + "outlettype" : [ "bang", "bang", "" ], + "id" : "obj-45", + "fontname" : "Verdana", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "pack 0 0 0 0", + "patching_rect" : [ 50.0, 125.0, 180.0, 21.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "" ], + "id" : "obj-43", + "fontname" : "Verdana", + "numinlets" : 4 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "+ 10", + "patching_rect" : [ 200.0, 100.0, 40.0, 21.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "int" ], + "id" : "obj-42", + "fontname" : "Verdana", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "+ 10", + "patching_rect" : [ 75.0, 100.0, 40.0, 21.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "int" ], + "id" : "obj-41", + "fontname" : "Verdana", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "message", + "text" : "clear, paintoval $1 $2 $3 $4", + "patching_rect" : [ 50.0, 150.0, 152.0, 18.0 ], + "numoutlets" : 1, + "fontsize" : 11.595187, + "outlettype" : [ "" ], + "id" : "obj-40", + "fontname" : "Arial", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "inlet", + "patching_rect" : [ 57.5, 40.0, 25.0, 25.0 ], + "numoutlets" : 1, + "outlettype" : [ "int" ], + "id" : "obj-58", + "numinlets" : 0, + "comment" : "" + } + + } +, { + "box" : { + "maxclass" : "inlet", + "patching_rect" : [ 120.0, 40.0, 25.0, 25.0 ], + "numoutlets" : 1, + "outlettype" : [ "int" ], + "id" : "obj-59", + "numinlets" : 0, + "comment" : "" + } + + } +, { + "box" : { + "maxclass" : "inlet", + "patching_rect" : [ 300.0, 40.0, 25.0, 25.0 ], + "numoutlets" : 1, + "outlettype" : [ "int" ], + "id" : "obj-60", + "numinlets" : 0, + "comment" : "" + } + + } +, { + "box" : { + "maxclass" : "outlet", + "patching_rect" : [ 228.333344, 228.0, 25.0, 25.0 ], + "numoutlets" : 0, + "id" : "obj-61", + "numinlets" : 1, + "comment" : "" + } + + } + ], + "lines" : [ { + "patchline" : { + "source" : [ "obj-43", 0 ], + "destination" : [ "obj-40", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-45", 0 ], + "destination" : [ "obj-46", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-45", 1 ], + "destination" : [ "obj-47", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-41", 0 ], + "destination" : [ "obj-43", 2 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-42", 0 ], + "destination" : [ "obj-43", 3 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-58", 0 ], + "destination" : [ "obj-43", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-58", 0 ], + "destination" : [ "obj-41", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-59", 0 ], + "destination" : [ "obj-43", 1 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-59", 0 ], + "destination" : [ "obj-42", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-60", 0 ], + "destination" : [ "obj-45", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-40", 0 ], + "destination" : [ "obj-61", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-46", 0 ], + "destination" : [ "obj-61", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-47", 0 ], + "destination" : [ "obj-61", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + ] + } +, + "saved_object_attributes" : { + "fontface" : 0, + "fontsize" : 10.0, + "default_fontface" : 0, + "default_fontname" : "Verdana", + "default_fontsize" : 10.0, + "fontname" : "Verdana", + "globalpatchername" : "" + } + + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "0", + "patching_rect" : [ 325.0, 393.0, 32.5, 20.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "int" ], + "id" : "obj-57", + "fontname" : "Arial", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "!- 1", + "patching_rect" : [ 400.0, 451.0, 32.5, 20.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "int" ], + "id" : "obj-55", + "fontname" : "Arial", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "gate 1 1", + "patching_rect" : [ 400.0, 370.0, 54.0, 20.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "" ], + "id" : "obj-54", + "fontname" : "Arial", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "toggle", + "patching_rect" : [ 400.0, 420.0, 20.0, 20.0 ], + "numoutlets" : 1, + "outlettype" : [ "int" ], + "id" : "obj-53", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "gate 1 0", + "patching_rect" : [ 209.0, 470.0, 54.0, 20.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "" ], + "id" : "obj-50", + "fontname" : "Arial", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "sel 10", + "patching_rect" : [ 400.0, 393.0, 43.0, 20.0 ], + "numoutlets" : 2, + "fontsize" : 12.0, + "outlettype" : [ "bang", "" ], + "id" : "obj-48", + "fontname" : "Arial", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "lcd", + "patching_rect" : [ 232.0, 815.0, 256.0, 256.0 ], + "numoutlets" : 4, + "outlettype" : [ "list", "list", "int", "" ], + "id" : "obj-39", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "t 65 l", + "patching_rect" : [ 209.0, 624.0, 42.0, 21.0 ], + "numoutlets" : 2, + "fontsize" : 12.0, + "outlettype" : [ "int", "" ], + "id" : "obj-35", + "fontname" : "Verdana", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "comment", + "text" : "val3", + "patching_rect" : [ 553.0, 725.0, 37.0, 21.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-1", + "fontname" : "Verdana", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "number", + "patching_rect" : [ 482.0, 725.0, 56.0, 21.0 ], + "numoutlets" : 2, + "fontsize" : 12.0, + "outlettype" : [ "int", "bang" ], + "id" : "obj-3", + "fontname" : "Verdana", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "comment", + "text" : "val2", + "patching_rect" : [ 425.0, 725.0, 37.0, 21.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-18", + "fontname" : "Verdana", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "comment", + "text" : "val1", + "patching_rect" : [ 297.0, 725.0, 37.0, 21.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-20", + "fontname" : "Verdana", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "number", + "patching_rect" : [ 357.0, 725.0, 56.0, 21.0 ], + "numoutlets" : 2, + "fontsize" : 12.0, + "outlettype" : [ "int", "bang" ], + "id" : "obj-22", + "fontname" : "Verdana", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "number", + "patching_rect" : [ 232.0, 725.0, 55.0, 21.0 ], + "numoutlets" : 2, + "fontsize" : 12.0, + "outlettype" : [ "int", "bang" ], + "id" : "obj-23", + "fontname" : "Verdana", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "unpack 0 0 0 0 0", + "patching_rect" : [ 232.0, 690.0, 269.0, 21.0 ], + "numoutlets" : 5, + "fontsize" : 12.0, + "outlettype" : [ "int", "int", "int", "int", "int" ], + "id" : "obj-29", + "fontname" : "Verdana", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "select 0 1", + "patching_rect" : [ 327.0, 215.0, 62.0, 20.0 ], + "numoutlets" : 3, + "fontsize" : 12.0, + "outlettype" : [ "bang", "bang", "" ], + "id" : "obj-30", + "fontname" : "Arial", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "comment", + "text" : "click here to close the serial port", + "patching_rect" : [ 375.0, 306.0, 206.0, 20.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-26", + "fontname" : "Arial", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "comment", + "text" : "click here to open the serial port", + "patching_rect" : [ 400.0, 280.0, 206.0, 20.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-27", + "fontname" : "Arial", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "message", + "text" : "close", + "patching_rect" : [ 327.0, 306.0, 39.0, 18.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "" ], + "id" : "obj-21", + "fontname" : "Arial", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "message", + "text" : "port a", + "patching_rect" : [ 349.0, 280.0, 41.0, 18.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "" ], + "id" : "obj-19", + "fontname" : "Arial", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "comment", + "text" : "Click here to get a list of serial ports", + "patching_rect" : [ 420.0, 254.0, 207.0, 20.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-2", + "fontname" : "Arial", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "toggle", + "patching_rect" : [ 244.0, 170.0, 22.0, 22.0 ], + "numoutlets" : 1, + "outlettype" : [ "int" ], + "id" : "obj-11", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "qmetro 10", + "patching_rect" : [ 244.0, 215.0, 65.0, 20.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "bang" ], + "id" : "obj-12", + "fontname" : "Arial", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "message", + "text" : "print", + "patching_rect" : [ 369.0, 254.0, 36.0, 18.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "" ], + "id" : "obj-13", + "fontname" : "Arial", + "numinlets" : 2 + } + + } +, { + "box" : { + "maxclass" : "newobj", + "text" : "serial a 9600", + "patching_rect" : [ 244.0, 330.0, 84.0, 20.0 ], + "numoutlets" : 2, + "fontsize" : 12.0, + "outlettype" : [ "int", "" ], + "id" : "obj-14", + "fontname" : "Arial", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "comment", + "text" : "Read serial input buffer every 10 milliseconds", + "linecount" : 2, + "patching_rect" : [ 28.0, 207.0, 210.0, 34.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-15", + "fontname" : "Arial", + "numinlets" : 1 + } + + } +, { + "box" : { + "maxclass" : "comment", + "text" : "Click to start", + "patching_rect" : [ 271.0, 178.0, 117.0, 20.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-17", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + ], + "lines" : [ { + "patchline" : { + "source" : [ "obj-54", 0 ], + "destination" : [ "obj-48", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-48", 0 ], + "destination" : [ "obj-53", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-9", 0 ], + "destination" : [ "obj-14", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-53", 0 ], + "destination" : [ "obj-6", 0 ], + "hidden" : 0, + "midpoints" : [ 409.5, 446.5, 363.5, 446.5 ] + } + + } +, { + "patchline" : { + "source" : [ "obj-6", 0 ], + "destination" : [ "obj-9", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-35", 0 ], + "destination" : [ "obj-14", 0 ], + "hidden" : 0, + "midpoints" : [ 218.5, 656.0, 182.0, 656.0, 182.0, 315.0, 253.5, 315.0 ] + } + + } +, { + "patchline" : { + "source" : [ "obj-57", 0 ], + "destination" : [ "obj-53", 0 ], + "hidden" : 0, + "midpoints" : [ 334.5, 416.0, 409.5, 416.0 ] + } + + } +, { + "patchline" : { + "source" : [ "obj-30", 0 ], + "destination" : [ "obj-57", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-55", 0 ], + "destination" : [ "obj-54", 0 ], + "hidden" : 0, + "midpoints" : [ 409.5, 474.0, 468.0, 474.0, 468.0, 366.0, 409.5, 366.0 ] + } + + } +, { + "patchline" : { + "source" : [ "obj-53", 0 ], + "destination" : [ "obj-55", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-23", 0 ], + "destination" : [ "obj-62", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-22", 0 ], + "destination" : [ "obj-62", 1 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-3", 0 ], + "destination" : [ "obj-62", 2 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-62", 0 ], + "destination" : [ "obj-39", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-14", 0 ], + "destination" : [ "obj-54", 1 ], + "hidden" : 0, + "midpoints" : [ 253.5, 357.0, 444.5, 357.0 ] + } + + } +, { + "patchline" : { + "source" : [ "obj-53", 0 ], + "destination" : [ "obj-50", 0 ], + "hidden" : 0, + "midpoints" : [ 409.5, 441.0, 218.5, 441.0 ] + } + + } +, { + "patchline" : { + "source" : [ "obj-14", 0 ], + "destination" : [ "obj-50", 1 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-11", 0 ], + "destination" : [ "obj-30", 0 ], + "hidden" : 0, + "midpoints" : [ 253.5, 206.0, 336.5, 206.0 ] + } + + } +, { + "patchline" : { + "source" : [ "obj-30", 1 ], + "destination" : [ "obj-19", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-30", 0 ], + "destination" : [ "obj-21", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-21", 0 ], + "destination" : [ "obj-14", 0 ], + "hidden" : 0, + "midpoints" : [ 336.5, 326.5, 253.5, 326.5 ] + } + + } +, { + "patchline" : { + "source" : [ "obj-19", 0 ], + "destination" : [ "obj-14", 0 ], + "hidden" : 0, + "midpoints" : [ 358.5, 303.5, 253.5, 303.5 ] + } + + } +, { + "patchline" : { + "source" : [ "obj-13", 0 ], + "destination" : [ "obj-14", 0 ], + "hidden" : 0, + "midpoints" : [ 378.5, 275.5, 253.5, 275.5 ] + } + + } +, { + "patchline" : { + "source" : [ "obj-11", 0 ], + "destination" : [ "obj-12", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-12", 0 ], + "destination" : [ "obj-14", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-10", 2 ], + "destination" : [ "obj-4", 0 ], + "hidden" : 0, + "midpoints" : [ 274.5, 542.0, 274.5, 542.0 ] + } + + } +, { + "patchline" : { + "source" : [ "obj-10", 0 ], + "destination" : [ "obj-4", 0 ], + "hidden" : 0, + "midpoints" : [ 218.5, 529.5, 274.5, 529.5 ] + } + + } +, { + "patchline" : { + "source" : [ "obj-4", 0 ], + "destination" : [ "obj-8", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-8", 0 ], + "destination" : [ "obj-7", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-7", 0 ], + "destination" : [ "obj-35", 0 ], + "hidden" : 0, + "midpoints" : [ 274.5, 614.0, 218.5, 614.0 ] + } + + } +, { + "patchline" : { + "source" : [ "obj-50", 0 ], + "destination" : [ "obj-10", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-29", 0 ], + "destination" : [ "obj-23", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-35", 1 ], + "destination" : [ "obj-29", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-29", 4 ], + "destination" : [ "obj-3", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } +, { + "patchline" : { + "source" : [ "obj-29", 2 ], + "destination" : [ "obj-22", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + ] +} + +*/ diff --git a/arduino-0018-linux/examples/Communication/VirtualColorMixer/VirtualColorMixer.pde b/arduino-0018-linux/examples/Communication/VirtualColorMixer/VirtualColorMixer.pde new file mode 100644 index 0000000..f23f147 --- /dev/null +++ b/arduino-0018-linux/examples/Communication/VirtualColorMixer/VirtualColorMixer.pde @@ -0,0 +1,697 @@ +/* + This example reads three analog sensors (potentiometers are easiest) + and sends their values serially. The Processing and Max/MSP programs at the bottom + take those three values and use them to change the background color of the screen. + + The circuit: + * potentiometers attached to analog inputs 0, 1, and 2 + + http://www.arduino.cc/en/Tutorial/VirtualColorMixer + + created 2 Dec 2006 + by David A. Mellis + modified 14 Apr 2009 + by Tom Igoe and Scott Fitzgerald + + */ + +const int redPin = 0; // sensor to control red color +const int greenPin = 1; // sensor to control green color +const int bluePin = 2; // sensor to control blue color + +void setup() +{ + Serial.begin(9600); +} + +void loop() +{ + Serial.print(analogRead(redPin)); + Serial.print(","); + Serial.print(analogRead(greenPin)); + Serial.print(","); + Serial.println(analogRead(bluePin)); +} + +/* Processing code for this example + + + import processing.serial.*; + + float redValue = 0; // red value + float greenValue = 0; // green value + float blueValue = 0; // blue value + + Serial myPort; + + void setup() { + size(200, 200); + + // List all the available serial ports + println(Serial.list()); + // I know that the first port in the serial list on my mac + // is always my Arduino, so I open Serial.list()[0]. + // Open whatever port is the one you're using. + myPort = new Serial(this, Serial.list()[0], 9600); + // don't generate a serialEvent() unless you get a newline character: + myPort.bufferUntil('\n'); + } + + void draw() { + // set the background color with the color values: + background(redValue, greenValue, blueValue); + } + + void serialEvent(Serial myPort) { + // get the ASCII string: + String inString = myPort.readStringUntil('\n'); + + if (inString != null) { + // trim off any whitespace: + inString = trim(inString); + // split the string on the commas and convert the + // resulting substrings into an integer array: + float[] colors = float(split(inString, ",")); + // if the array has at least three elements, you know + // you got the whole thing. Put the numbers in the + // color variables: + if (colors.length >=3) { + // map them to the range 0-255: + redValue = map(colors[0], 0, 1023, 0, 255); + greenValue = map(colors[1], 0, 1023, 0, 255); + blueValue = map(colors[2], 0, 1023, 0, 255); + } + } + } + */ + +/* Max/MSP patch for this example + { + "boxes" : [ { + "box" : { + "maxclass" : "newobj", + "text" : "/ 4", + "patching_rect" : [ 448.0, 502.0, 32.5, 20.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "int" ], + "id" : "obj-25", + "fontname" : "Arial", + "numinlets" : 2 + } + + } + , { + "box" : { + "maxclass" : "newobj", + "text" : "/ 4", + "patching_rect" : [ 398.0, 502.0, 32.5, 20.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "int" ], + "id" : "obj-24", + "fontname" : "Arial", + "numinlets" : 2 + } + + } + , { + "box" : { + "maxclass" : "newobj", + "text" : "/ 4", + "patching_rect" : [ 348.0, 502.0, 32.5, 20.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "int" ], + "id" : "obj-23", + "fontname" : "Arial", + "numinlets" : 2 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "Virtual color mixer\n\nThis patch takes a string, containing three comma-separated ASCII formatted numbers from 0 to 1023, with a carriage return and linefeed at the end. It converts the string to three integers and uses them to set the background color.\n\n created 2 Dec 2006\n by David A. Mellis\nmodified 14 Apr 2009\nby Scott Fitzgerald and Tom Igoe", + "linecount" : 11, + "patching_rect" : [ 524.0, 51.0, 398.0, 158.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-32", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "newobj", + "text" : "select 0 1", + "patching_rect" : [ 372.0, 125.0, 62.0, 20.0 ], + "numoutlets" : 3, + "fontsize" : 12.0, + "outlettype" : [ "bang", "bang", "" ], + "id" : "obj-30", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "click here to close the serial port", + "patching_rect" : [ 457.0, 276.0, 206.0, 20.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-26", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "click here to open the serial port", + "patching_rect" : [ 457.0, 250.0, 206.0, 20.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-27", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "message", + "text" : "close", + "patching_rect" : [ 372.0, 276.0, 39.0, 18.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "" ], + "id" : "obj-21", + "fontname" : "Arial", + "numinlets" : 2 + } + + } + , { + "box" : { + "maxclass" : "message", + "text" : "port a", + "patching_rect" : [ 394.0, 250.0, 41.0, 18.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "" ], + "id" : "obj-19", + "fontname" : "Arial", + "numinlets" : 2 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "Click here to get a list of serial ports", + "patching_rect" : [ 457.0, 224.0, 207.0, 20.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-2", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "Convert ASCII to symbol", + "patching_rect" : [ 424.0, 423.0, 147.0, 20.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-4", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "Convert integer to ASCII", + "patching_rect" : [ 424.0, 400.0, 147.0, 20.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-5", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "newobj", + "text" : "fromsymbol", + "patching_rect" : [ 347.0, 423.0, 74.0, 20.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "" ], + "id" : "obj-7", + "fontname" : "Arial", + "color" : [ 1.0, 0.890196, 0.090196, 1.0 ], + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "newobj", + "text" : "itoa", + "patching_rect" : [ 347.0, 400.0, 46.0, 20.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "int" ], + "id" : "obj-8", + "fontname" : "Arial", + "color" : [ 1.0, 0.890196, 0.090196, 1.0 ], + "numinlets" : 3 + } + + } + , { + "box" : { + "maxclass" : "newobj", + "text" : "zl group", + "patching_rect" : [ 347.0, 377.0, 53.0, 20.0 ], + "numoutlets" : 2, + "fontsize" : 12.0, + "outlettype" : [ "", "" ], + "id" : "obj-9", + "fontname" : "Arial", + "numinlets" : 2 + } + + } + , { + "box" : { + "maxclass" : "newobj", + "text" : "select 10 13", + "patching_rect" : [ 289.0, 326.0, 77.0, 20.0 ], + "numoutlets" : 3, + "fontsize" : 12.0, + "outlettype" : [ "bang", "bang", "" ], + "id" : "obj-10", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "toggle", + "patching_rect" : [ 289.0, 88.0, 15.0, 15.0 ], + "numoutlets" : 1, + "outlettype" : [ "int" ], + "id" : "obj-11", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "newobj", + "text" : "qmetro 10", + "patching_rect" : [ 289.0, 125.0, 65.0, 20.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "bang" ], + "id" : "obj-12", + "fontname" : "Arial", + "numinlets" : 2 + } + + } + , { + "box" : { + "maxclass" : "message", + "text" : "print", + "patching_rect" : [ 414.0, 224.0, 36.0, 18.0 ], + "numoutlets" : 1, + "fontsize" : 12.0, + "outlettype" : [ "" ], + "id" : "obj-13", + "fontname" : "Arial", + "numinlets" : 2 + } + + } + , { + "box" : { + "maxclass" : "newobj", + "text" : "serial a 9600", + "patching_rect" : [ 289.0, 300.0, 84.0, 20.0 ], + "numoutlets" : 2, + "fontsize" : 12.0, + "outlettype" : [ "int", "" ], + "id" : "obj-14", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "Read serial input buffer every 10 milliseconds", + "linecount" : 2, + "patching_rect" : [ 98.0, 117.0, 185.0, 34.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-15", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "If you get newline (ASCII 10), send the list. If you get return (ASCII 13) do nothing. Any other value, add to the list", + "linecount" : 3, + "patching_rect" : [ 377.0, 314.0, 320.0, 48.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-16", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "Click to open/close serial port and start/stop patch", + "linecount" : 2, + "patching_rect" : [ 316.0, 77.0, 199.0, 34.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-17", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "newobj", + "text" : "bgcolor 0 0 0", + "patching_rect" : [ 348.0, 585.0, 169.0, 19.0 ], + "numoutlets" : 0, + "fontsize" : 10.0, + "id" : "obj-6", + "fontname" : "Verdana", + "numinlets" : 4 + } + + } + , { + "box" : { + "maxclass" : "newobj", + "text" : "unpack 0 0 0 0 0", + "patching_rect" : [ 347.0, 470.0, 119.0, 19.0 ], + "numoutlets" : 5, + "fontsize" : 10.0, + "outlettype" : [ "int", "int", "int", "int", "int" ], + "id" : "obj-20", + "fontname" : "Verdana", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "number", + "patching_rect" : [ 448.0, 535.0, 50.0, 19.0 ], + "numoutlets" : 2, + "fontsize" : 10.0, + "outlettype" : [ "int", "bang" ], + "id" : "obj-18", + "fontname" : "Verdana", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "number", + "patching_rect" : [ 398.0, 535.0, 50.0, 19.0 ], + "numoutlets" : 2, + "fontsize" : 10.0, + "outlettype" : [ "int", "bang" ], + "id" : "obj-1", + "fontname" : "Verdana", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "number", + "patching_rect" : [ 348.0, 535.0, 50.0, 19.0 ], + "numoutlets" : 2, + "fontsize" : 10.0, + "outlettype" : [ "int", "bang" ], + "id" : "obj-22", + "fontname" : "Verdana", + "numinlets" : 1 + } + + } + , { + "box" : { + "maxclass" : "comment", + "text" : "Here's the numbers from Arduino's analog input", + "linecount" : 3, + "patching_rect" : [ 198.0, 484.0, 138.0, 48.0 ], + "numoutlets" : 0, + "fontsize" : 12.0, + "id" : "obj-3", + "fontname" : "Arial", + "numinlets" : 1 + } + + } + ], + "lines" : [ { + "patchline" : { + "source" : [ "obj-18", 0 ], + "destination" : [ "obj-6", 2 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-1", 0 ], + "destination" : [ "obj-6", 1 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-22", 0 ], + "destination" : [ "obj-6", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-25", 0 ], + "destination" : [ "obj-18", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-20", 4 ], + "destination" : [ "obj-25", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-20", 2 ], + "destination" : [ "obj-24", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-24", 0 ], + "destination" : [ "obj-1", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-23", 0 ], + "destination" : [ "obj-22", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-20", 0 ], + "destination" : [ "obj-23", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-8", 0 ], + "destination" : [ "obj-7", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-14", 0 ], + "destination" : [ "obj-10", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-12", 0 ], + "destination" : [ "obj-14", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-11", 0 ], + "destination" : [ "obj-12", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-13", 0 ], + "destination" : [ "obj-14", 0 ], + "hidden" : 0, + "midpoints" : [ 423.5, 245.5, 298.5, 245.5 ] + } + + } + , { + "patchline" : { + "source" : [ "obj-19", 0 ], + "destination" : [ "obj-14", 0 ], + "hidden" : 0, + "midpoints" : [ 403.5, 273.5, 298.5, 273.5 ] + } + + } + , { + "patchline" : { + "source" : [ "obj-21", 0 ], + "destination" : [ "obj-14", 0 ], + "hidden" : 0, + "midpoints" : [ 381.5, 296.5, 298.5, 296.5 ] + } + + } + , { + "patchline" : { + "source" : [ "obj-30", 0 ], + "destination" : [ "obj-21", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-30", 1 ], + "destination" : [ "obj-19", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-11", 0 ], + "destination" : [ "obj-30", 0 ], + "hidden" : 0, + "midpoints" : [ 298.0, 116.0, 381.5, 116.0 ] + } + + } + , { + "patchline" : { + "source" : [ "obj-7", 0 ], + "destination" : [ "obj-20", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-9", 0 ], + "destination" : [ "obj-8", 0 ], + "hidden" : 0, + "midpoints" : [ ] + } + + } + , { + "patchline" : { + "source" : [ "obj-10", 0 ], + "destination" : [ "obj-9", 0 ], + "hidden" : 0, + "midpoints" : [ 298.5, 353.0, 356.5, 353.0 ] + } + + } + , { + "patchline" : { + "source" : [ "obj-10", 2 ], + "destination" : [ "obj-9", 0 ], + "hidden" : 0, + "midpoints" : [ 356.5, 365.0, 356.5, 365.0 ] + } + + } + ] + } + + */ diff --git a/arduino-0018-linux/examples/Control/Arrays/Arrays.pde b/arduino-0018-linux/examples/Control/Arrays/Arrays.pde new file mode 100644 index 0000000..d9d9837 --- /dev/null +++ b/arduino-0018-linux/examples/Control/Arrays/Arrays.pde @@ -0,0 +1,55 @@ +/* + Arrays + + Demonstrates the use of an array to hold pin numbers + in order to iterate over the pins in a sequence. + Lights multiple LEDs in sequence, then in reverse. + + Unlike the For Loop tutorial, where the pins have to be + contiguous, here the pins can be in any random order. + + The circuit: + * LEDs from pins 2 through 7 to ground + + created 2006 + by David A. Mellis + modified 5 Jul 2009 + by Tom Igoe + + http://www.arduino.cc/en/Tutorial/Array + */ + +int timer = 100; // The higher the number, the slower the timing. +int ledPins[] = { + 2, 7, 4, 6, 5, 3 }; // an array of pin numbers to which LEDs are attached +int pinCount = 6; // the number of pins (i.e. the length of the array) + +void setup() { + int thisPin; + // the array elements are numbered from 0 to (pinCount - 1). + // use a for loop to initialize each pin as an output: + for (int thisPin = 0; thisPin < pinCount; thisPin++) { + pinMode(ledPins[thisPin], OUTPUT); + } +} + +void loop() { + // loop from the lowest pin to the highest: + for (int thisPin = 0; thisPin < pinCount; thisPin++) { + // turn the pin on: + digitalWrite(ledPins[thisPin], HIGH); + delay(timer); + // turn the pin off: + digitalWrite(ledPins[thisPin], LOW); + + } + + // loop from the highest pin to the lowest: + for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) { + // turn the pin on: + digitalWrite(ledPins[thisPin], HIGH); + delay(timer); + // turn the pin off: + digitalWrite(ledPins[thisPin], LOW); + } +} diff --git a/arduino-0018-linux/examples/Control/ForLoopIteration/ForLoopIteration.pde b/arduino-0018-linux/examples/Control/ForLoopIteration/ForLoopIteration.pde new file mode 100644 index 0000000..4fd745d --- /dev/null +++ b/arduino-0018-linux/examples/Control/ForLoopIteration/ForLoopIteration.pde @@ -0,0 +1,45 @@ +/* + For Loop Iteration + + Demonstrates the use of a for() loop. + Lights multiple LEDs in sequence, then in reverse. + + The circuit: + * LEDs from pins 2 through 7 to ground + + created 2006 + by David A. Mellis + modified 5 Jul 2009 + by Tom Igoe + + http://www.arduino.cc/en/Tutorial/ForLoop + */ + +int timer = 100; // The higher the number, the slower the timing. + +void setup() { + // use a for loop to initialize each pin as an output: + for (int thisPin = 2; thisPin < 8; thisPin++) { + pinMode(thisPin, OUTPUT); + } +} + +void loop() { + // loop from the lowest pin to the highest: + for (int thisPin = 2; thisPin < 8; thisPin++) { + // turn the pin on: + digitalWrite(thisPin, HIGH); + delay(timer); + // turn the pin off: + digitalWrite(thisPin, LOW); + } + + // loop from the highest pin to the lowest: + for (int thisPin = 7; thisPin >= 2; thisPin--) { + // turn the pin on: + digitalWrite(thisPin, HIGH); + delay(timer); + // turn the pin off: + digitalWrite(thisPin, LOW); + } +} diff --git a/arduino-0018-linux/examples/Control/IfStatementConditional/IfStatementConditional.pde b/arduino-0018-linux/examples/Control/IfStatementConditional/IfStatementConditional.pde new file mode 100644 index 0000000..a763ae5 --- /dev/null +++ b/arduino-0018-linux/examples/Control/IfStatementConditional/IfStatementConditional.pde @@ -0,0 +1,53 @@ +/* + Conditionals - If statement + + This example demonstrates the use of if() statements. + It reads the state of a potentiometer (an analog input) and turns on an LED + only if the LED goes above a certain threshold level. It prints the analog value + regardless of the level. + + The circuit: + * potentiometer connected to analog pin 0. + Center pin of the potentiometer goes to the analog pin. + side pins of the potentiometer go to +5V and ground + * LED connected from digital pin 13 to ground + + * Note: On most Arduino boards, there is already an LED on the board + connected to pin 13, so you don't need any extra components for this example. + + created 17 Jan 2009 + by Tom Igoe + + http://arduino.cc/en/Tutorial/ + + */ + +// These constants won't change: +const int analogPin = 0; // pin that the sensor is attached to +const int ledPin = 13; // pin that the LED is attached to +const int threshold = 400; // an arbitrary threshold level that's in the range of the analog input + +void setup() { + // initialize the LED pin as an output: + pinMode(ledPin, OUTPUT); + // initialize serial communications: + Serial.begin(9600); +} + +void loop() { + // read the value of the potentiometer: + int analogValue = analogRead(analogPin); + + // if the analog value is high enough, turn on the LED: + if (analogValue > threshold) { + digitalWrite(ledPin, HIGH); + } + else { + digitalWrite(ledPin,LOW); + } + + // print the analog value: + Serial.println(analogValue, DEC); + +} + diff --git a/arduino-0018-linux/examples/Control/WhileStatementConditional/WhileStatementConditional.pde b/arduino-0018-linux/examples/Control/WhileStatementConditional/WhileStatementConditional.pde new file mode 100644 index 0000000..0500479 --- /dev/null +++ b/arduino-0018-linux/examples/Control/WhileStatementConditional/WhileStatementConditional.pde @@ -0,0 +1,86 @@ +/* + Conditionals - while statement + + This example demonstrates the use of while() statements. + + While the pushbutton is pressed, the sketch runs the calibration routine. + The sensor readings during the while loop define the minimum and maximum + of expected values from the photo resistor. + + This is a variation on the calibrate example. + + The circuit: + * photo resistor connected from +5V to analog in pin 0 + * 10K resistor connected from ground to analog in pin 0 + * LED connected from digital pin 9 to ground through 220 ohm resistor + * pushbutton attached from pin 2 to +5V + * 10K resistor attached from pin 2 to ground + + created 17 Jan 2009 + modified 25 Jun 2009 + by Tom Igoe + + http://arduino.cc/en/Tutorial/WhileLoop + + */ + + +// These constants won't change: +const int sensorPin = 2; // pin that the sensor is attached to +const int ledPin = 9; // pin that the LED is attached to +const int indicatorLedPin = 13; // pin that the built-in LED is attached to +const int buttonPin = 2; // pin that the button is attached to + + +// These variables will change: +int sensorMin = 1023; // minimum sensor value +int sensorMax = 0; // maximum sensor value +int sensorValue = 0; // the sensor value + + +void setup() { + // set the LED pins as outputs and the switch pin as input: + pinMode(indicatorLedPin, OUTPUT); + pinMode (ledPin, OUTPUT); + pinMode (buttonPin, INPUT); +} + +void loop() { + // while the button is pressed, take calibration readings: + while (digitalRead(buttonPin) == HIGH) { + calibrate(); + } + // signal the end of the calibration period + digitalWrite(indicatorLedPin, LOW); + + // read the sensor: + sensorValue = analogRead(sensorPin); + + // apply the calibration to the sensor reading + sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255); + + // in case the sensor value is outside the range seen during calibration + sensorValue = constrain(sensorValue, 0, 255); + + // fade the LED using the calibrated value: + analogWrite(ledPin, sensorValue); +} + +void calibrate() { + // turn on the indicator LED to indicate that calibration is happening: + digitalWrite(indicatorLedPin, HIGH); + // read the sensor: + sensorValue = analogRead(sensorPin); + + // record the maximum sensor value + if (sensorValue > sensorMax) { + sensorMax = sensorValue; + } + + // record the minimum sensor value + if (sensorValue < sensorMin) { + sensorMin = sensorValue; + } +} + + diff --git a/arduino-0018-linux/examples/Control/switchCase/switchCase.pde b/arduino-0018-linux/examples/Control/switchCase/switchCase.pde new file mode 100644 index 0000000..10a2be1 --- /dev/null +++ b/arduino-0018-linux/examples/Control/switchCase/switchCase.pde @@ -0,0 +1,59 @@ +/* + Switch statement + + Demonstrates the use of a switch statement. The switch + statement allows you to choose from among a set of discrete values + of a variable. It's like a series of if statements. + + To see this sketch in action, but the board and sensor in a well-lit + room, open the serial monitor, and and move your hand gradually + down over the sensor. + + The circuit: + * photoresistor from analog in 0 to +5V + * 10K resistor from analog in 0 to ground + + created 1 Jul 2009 + by Tom Igoe + + http://www.arduino.cc/en/Tutorial/SwitchCase + */ + +// these constants won't change: +const int sensorMin = 0; // sensor minimum, discovered through experiment +const int sensorMax = 600; // sensor maximum, discovered through experiment + +void setup() { + // initialize serial communication: + Serial.begin(9600); +} + +void loop() { + // read the sensor: + int sensorReading = analogRead(0); + // map the sensor range to a range of four options: + int range = map(sensorReading, sensorMin, sensorMax, 0, 3); + + // do something different depending on the + // range value: + switch (range) { + case 0: // your hand is on the sensor + Serial.println("dark"); + break; + case 1: // your hand is close to the sensor + Serial.println("dim"); + break; + case 2: // your hand is a few inches from the sensor + Serial.println("medium"); + break; + case 3: // your hand is nowhere near the sensor + Serial.println("bright"); + break; + } + +} + + + + + diff --git a/arduino-0018-linux/examples/Control/switchCase2/switchCase2.pde b/arduino-0018-linux/examples/Control/switchCase2/switchCase2.pde new file mode 100644 index 0000000..94a1b6c --- /dev/null +++ b/arduino-0018-linux/examples/Control/switchCase2/switchCase2.pde @@ -0,0 +1,64 @@ +/* + Switch statement with serial input + + Demonstrates the use of a switch statement. The switch + statement allows you to choose from among a set of discrete values + of a variable. It's like a series of if statements. + + To see this sketch in action, open the Serial monitor and send any character. + The characters a, b, c, d, and e, will turn on LEDs. Any other character will turn + the LEDs off. + + The circuit: + * 5 LEDs attached to digital pins 2 through 6 through 220-ohm resistors + + created 1 Jul 2009 + by Tom Igoe + + http://www.arduino.cc/en/Tutorial/SwitchCase2 + */ + +void setup() { + // initialize serial communication: + Serial.begin(9600); + // initialize the LED pins: + for (int thisPin = 2; thisPin < 7; thisPin++) { + pinMode(thisPin, OUTPUT); + } +} + +void loop() { + // read the sensor: + if (Serial.available() > 0) { + int inByte = Serial.read(); + // do something different depending on the character received. + // The switch statement expects single number values for each case; + // in this exmaple, though, you're using single quotes to tell + // the controller to get the ASCII value for the character. For + // example 'a' = 97, 'b' = 98, and so forth: + + switch (inByte) { + case 'a': + digitalWrite(2, HIGH); + break; + case 'b': + digitalWrite(3, HIGH); + break; + case 'c': + digitalWrite(4, HIGH); + break; + case 'd': + digitalWrite(5, HIGH); + break; + case 'e': + digitalWrite(6, HIGH); + break; + default: + // turn all the LEDs off: + for (int thisPin = 2; thisPin < 7; thisPin++) { + digitalWrite(thisPin, LOW); + } + } + } +} + diff --git a/arduino-0018-linux/examples/Digital/Blink/Blink.pde b/arduino-0018-linux/examples/Digital/Blink/Blink.pde new file mode 100644 index 0000000..5d27483 --- /dev/null +++ b/arduino-0018-linux/examples/Digital/Blink/Blink.pde @@ -0,0 +1,40 @@ +/* + Blink + + Turns on an LED on for one second, then off for one second, repeatedly. + + The circuit: + * LED connected from digital pin 13 to ground. + + * Note: On most Arduino boards, there is already an LED on the board + connected to pin 13, so you don't need any extra components for this example. + + + Created 1 June 2005 + By David Cuartielles + + http://arduino.cc/en/Tutorial/Blink + + based on an orginal by H. Barragan for the Wiring i/o board + + */ + +int ledPin = 13; // LED connected to digital pin 13 + +// The setup() method runs once, when the sketch starts + +void setup() { + // initialize the digital pin as an output: + pinMode(ledPin, OUTPUT); +} + +// the loop() method runs over and over again, +// as long as the Arduino has power + +void loop() +{ + digitalWrite(ledPin, HIGH); // set the LED on + delay(1000); // wait for a second + digitalWrite(ledPin, LOW); // set the LED off + delay(1000); // wait for a second +} diff --git a/arduino-0018-linux/examples/Digital/BlinkWithoutDelay/BlinkWithoutDelay.pde b/arduino-0018-linux/examples/Digital/BlinkWithoutDelay/BlinkWithoutDelay.pde new file mode 100644 index 0000000..f1d6984 --- /dev/null +++ b/arduino-0018-linux/examples/Digital/BlinkWithoutDelay/BlinkWithoutDelay.pde @@ -0,0 +1,58 @@ +/* Blink without Delay + + Turns on and off a light emitting diode(LED) connected to a digital + pin, without using the delay() function. This means that other code + can run at the same time without being interrupted by the LED code. + + The circuit: + * LED attached from pin 13 to ground. + * Note: on most Arduinos, there is already an LED on the board + that's attached to pin 13, so no hardware is needed for this example. + + + created 2005 + by David A. Mellis + modified 17 Jun 2009 + by Tom Igoe + + http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay + */ + +// constants won't change. Used here to +// set pin numbers: +const int ledPin = 13; // the number of the LED pin + +// Variables will change: +int ledState = LOW; // ledState used to set the LED +long previousMillis = 0; // will store last time LED was updated + +// the follow variables is a long because the time, measured in miliseconds, +// will quickly become a bigger number than can be stored in an int. +long interval = 1000; // interval at which to blink (milliseconds) + +void setup() { + // set the digital pin as output: + pinMode(ledPin, OUTPUT); +} + +void loop() +{ + // here is where you'd put code that needs to be running all the time. + + // check to see if it's time to blink the LED; that is, is the difference + // between the current time and last time we blinked the LED bigger than + // the interval at which we want to blink the LED. + if (millis() - previousMillis > interval) { + // save the last time you blinked the LED + previousMillis = millis(); + + // if the LED is off turn it on and vice-versa: + if (ledState == LOW) + ledState = HIGH; + else + ledState = LOW; + + // set the LED with the ledState of the variable: + digitalWrite(ledPin, ledState); + } +} \ No newline at end of file diff --git a/arduino-0018-linux/examples/Digital/Button/Button.pde b/arduino-0018-linux/examples/Digital/Button/Button.pde new file mode 100644 index 0000000..8df98ec --- /dev/null +++ b/arduino-0018-linux/examples/Digital/Button/Button.pde @@ -0,0 +1,54 @@ +/* + Button + + Turns on and off a light emitting diode(LED) connected to digital + pin 13, when pressing a pushbutton attached to pin 7. + + + The circuit: + * LED attached from pin 13 to ground + * pushbutton attached to pin 2 from +5V + * 10K resistor attached to pin 2 from ground + + * Note: on most Arduinos there is already an LED on the board + attached to pin 13. + + + created 2005 + by DojoDave + modified 17 Jun 2009 + by Tom Igoe + + http://www.arduino.cc/en/Tutorial/Button + */ + +// constants won't change. They're used here to +// set pin numbers: +const int buttonPin = 2; // the number of the pushbutton pin +const int ledPin = 13; // the number of the LED pin + +// variables will change: +int buttonState = 0; // variable for reading the pushbutton status + +void setup() { + // initialize the LED pin as an output: + pinMode(ledPin, OUTPUT); + // initialize the pushbutton pin as an input: + pinMode(buttonPin, INPUT); +} + +void loop(){ + // read the state of the pushbutton value: + buttonState = digitalRead(buttonPin); + + // check if the pushbutton is pressed. + // if it is, the buttonState is HIGH: + if (buttonState == HIGH) { + // turn LED on: + digitalWrite(ledPin, HIGH); + } + else { + // turn LED off: + digitalWrite(ledPin, LOW); + } +} \ No newline at end of file diff --git a/arduino-0018-linux/examples/Digital/Debounce/Debounce.pde b/arduino-0018-linux/examples/Digital/Debounce/Debounce.pde new file mode 100644 index 0000000..568100f --- /dev/null +++ b/arduino-0018-linux/examples/Digital/Debounce/Debounce.pde @@ -0,0 +1,74 @@ +/* + Debounce + + Each time the input pin goes from LOW to HIGH (e.g. because of a push-button + press), the output pin is toggled from LOW to HIGH or HIGH to LOW. There's + a minimum delay between toggles to debounce the circuit (i.e. to ignore + noise). + + The circuit: + * LED attached from pin 13 to ground + * pushbutton attached from pin 2 to +5V + * 10K resistor attached from pin 2 to ground + + * Note: On most Arduino boards, there is already an LED on the board + connected to pin 13, so you don't need any extra components for this example. + + + created 21 November 2006 + by David A. Mellis + modified 3 Jul 2009 + by Limor Fried + + + http://www.arduino.cc/en/Tutorial/Debounce + */ + +// constants won't change. They're used here to +// set pin numbers: +const int buttonPin = 2; // the number of the pushbutton pin +const int ledPin = 13; // the number of the LED pin + +// Variables will change: +int ledState = HIGH; // the current state of the output pin +int buttonState; // the current reading from the input pin +int lastButtonState = LOW; // the previous reading from the input pin + +// the following variables are long's because the time, measured in miliseconds, +// will quickly become a bigger number than can be stored in an int. +long lastDebounceTime = 0; // the last time the output pin was toggled +long debounceDelay = 50; // the debounce time; increase if the output flickers + +void setup() { + pinMode(buttonPin, INPUT); + pinMode(ledPin, OUTPUT); +} + +void loop() { + // read the state of the switch into a local variable: + int reading = digitalRead(buttonPin); + + // check to see if you just pressed the button + // (i.e. the input went from LOW to HIGH), and you've waited + // long enough since the last press to ignore any noise: + + // If the switch changed, due to noise or pressing: + if (reading != lastButtonState) { + // reset the debouncing timer + lastDebounceTime = millis(); + } + + if ((millis() - lastDebounceTime) > debounceDelay) { + // whatever the reading is at, it's been there for longer + // than the debounce delay, so take it as the actual current state: + buttonState = reading; + } + + // set the LED using the state of the button: + digitalWrite(ledPin, buttonState); + + // save the reading. Next time through the loop, + // it'll be the lastButtonState: + lastButtonState = reading; +} + diff --git a/arduino-0018-linux/examples/Digital/StateChangeDetection/StateChangeDetection.pde b/arduino-0018-linux/examples/Digital/StateChangeDetection/StateChangeDetection.pde new file mode 100644 index 0000000..607dfc9 --- /dev/null +++ b/arduino-0018-linux/examples/Digital/StateChangeDetection/StateChangeDetection.pde @@ -0,0 +1,90 @@ +/* + State change detection (edge detection) + + Often, you don't need to know the state of a digital input all the time, + but you just need to know when the input changes from one state to another. + For example, you want to know when a button goes from OFF to ON. This is called + state change detection, or edge detection. + + This example shows how to detect when a button or button changes from off to on + and on to off. + + The circuit: + * pushbutton attached to pin 2 from +5V + * 10K resistor attached to pin 2 from ground + * LED attached from pin 13 to ground (or use the built-in LED on + most Arduino boards) + + created 27 Sep 2005 + modified 30 Dec 2009 + by Tom Igoe + + http://arduino.cc/en/Tutorial/ButtonStateChange + + */ + +// this constant won't change: +const int buttonPin = 2; // the pin that the pushbutton is attached to +const int ledPin = 13; // the pin that the LED is attached to + +// Variables will change: +int buttonPushCounter = 0; // counter for the number of button presses +int buttonState = 0; // current state of the button +int lastButtonState = 0; // previous state of the button + +void setup() { + // initialize the button pin as a input: + pinMode(buttonPin, INPUT); + // initialize the LED as an output: + pinMode(ledPin, OUTPUT); + // initialize serial communication: + Serial.begin(9600); +} + + +void loop() { + // read the pushbutton input pin: + buttonState = digitalRead(buttonPin); + + // compare the buttonState to its previous state + if (buttonState != lastButtonState) { + // if the state has changed, increment the counter + if (buttonState == HIGH) { + // if the current state is HIGH then the button + // wend from off to on: + buttonPushCounter++; + Serial.println("on"); + Serial.print("number of button pushes: "); + Serial.println(buttonPushCounter, DEC); + } + else { + // if the current state is LOW then the button + // wend from on to off: + Serial.println("off"); + } + + // save the current state as the last state, + //for next time through the loop + lastButtonState = buttonState; + } + + // turns on the LED every four button pushes by + // checking the modulo of the button push counter. + // the modulo function gives you the remainder of + // the division of two numbers: + if (buttonPushCounter % 4 == 0) { + digitalWrite(ledPin, HIGH); + } else { + digitalWrite(ledPin, LOW); + } + +} + + + + + + + + + diff --git a/arduino-0018-linux/examples/Digital/toneKeyboard/pitches.h b/arduino-0018-linux/examples/Digital/toneKeyboard/pitches.h new file mode 100644 index 0000000..55c7d54 --- /dev/null +++ b/arduino-0018-linux/examples/Digital/toneKeyboard/pitches.h @@ -0,0 +1,95 @@ +/************************************************* + * Public Constants + *************************************************/ + +#define NOTE_B0 31 +#define NOTE_C1 33 +#define NOTE_CS1 35 +#define NOTE_D1 37 +#define NOTE_DS1 39 +#define NOTE_E1 41 +#define NOTE_F1 44 +#define NOTE_FS1 46 +#define NOTE_G1 49 +#define NOTE_GS1 52 +#define NOTE_A1 55 +#define NOTE_AS1 58 +#define NOTE_B1 62 +#define NOTE_C2 65 +#define NOTE_CS2 69 +#define NOTE_D2 73 +#define NOTE_DS2 78 +#define NOTE_E2 82 +#define NOTE_F2 87 +#define NOTE_FS2 93 +#define NOTE_G2 98 +#define NOTE_GS2 104 +#define NOTE_A2 110 +#define NOTE_AS2 117 +#define NOTE_B2 123 +#define NOTE_C3 131 +#define NOTE_CS3 139 +#define NOTE_D3 147 +#define NOTE_DS3 156 +#define NOTE_E3 165 +#define NOTE_F3 175 +#define NOTE_FS3 185 +#define NOTE_G3 196 +#define NOTE_GS3 208 +#define NOTE_A3 220 +#define NOTE_AS3 233 +#define NOTE_B3 247 +#define NOTE_C4 262 +#define NOTE_CS4 277 +#define NOTE_D4 294 +#define NOTE_DS4 311 +#define NOTE_E4 330 +#define NOTE_F4 349 +#define NOTE_FS4 370 +#define NOTE_G4 392 +#define NOTE_GS4 415 +#define NOTE_A4 440 +#define NOTE_AS4 466 +#define NOTE_B4 494 +#define NOTE_C5 523 +#define NOTE_CS5 554 +#define NOTE_D5 587 +#define NOTE_DS5 622 +#define NOTE_E5 659 +#define NOTE_F5 698 +#define NOTE_FS5 740 +#define NOTE_G5 784 +#define NOTE_GS5 831 +#define NOTE_A5 880 +#define NOTE_AS5 932 +#define NOTE_B5 988 +#define NOTE_C6 1047 +#define NOTE_CS6 1109 +#define NOTE_D6 1175 +#define NOTE_DS6 1245 +#define NOTE_E6 1319 +#define NOTE_F6 1397 +#define NOTE_FS6 1480 +#define NOTE_G6 1568 +#define NOTE_GS6 1661 +#define NOTE_A6 1760 +#define NOTE_AS6 1865 +#define NOTE_B6 1976 +#define NOTE_C7 2093 +#define NOTE_CS7 2217 +#define NOTE_D7 2349 +#define NOTE_DS7 2489 +#define NOTE_E7 2637 +#define NOTE_F7 2794 +#define NOTE_FS7 2960 +#define NOTE_G7 3136 +#define NOTE_GS7 3322 +#define NOTE_A7 3520 +#define NOTE_AS7 3729 +#define NOTE_B7 3951 +#define NOTE_C8 4186 +#define NOTE_CS8 4435 +#define NOTE_D8 4699 +#define NOTE_DS8 4978 + + diff --git a/arduino-0018-linux/examples/Digital/toneKeyboard/toneKeyboard.pde b/arduino-0018-linux/examples/Digital/toneKeyboard/toneKeyboard.pde new file mode 100644 index 0000000..57279ef --- /dev/null +++ b/arduino-0018-linux/examples/Digital/toneKeyboard/toneKeyboard.pde @@ -0,0 +1,49 @@ +/* + keyboard + + Plays a pitch that changes based on a changing analog input + + circuit: + * 3 force-sensing resistors from +5V to analog in 0 through 5 + * 3 10K resistors from analog in 0 through 5 to ground + * 8-ohm speaker on digital pin 8 + + created 21 Jan 2010 + by Tom Igoe + + http://arduino.cc/en/Tutorial/Tone3 + + */ + +#include "pitches.h" + +const int threshold = 10; // minimum reading of the sensors that generates a note + +// notes to play, corresponding to the 3 sensors: +int notes[] = { + NOTE_A4, NOTE_B4,NOTE_C3 }; + +void setup() { + +} + +void loop() { + for (int thisSensor = 0; thisSensor < 3; thisSensor++) { + // get a sensor reading: + int sensorReading = analogRead(thisSensor); + + // if the sensor is pressed hard enough: + if (sensorReading > threshold) { + // play the note corresponding to this sensor: + tone(8, notes[thisSensor], 20); + } + } + Serial.println(); +} + + + + + + + diff --git a/arduino-0018-linux/examples/Digital/toneMelody/pitches.h b/arduino-0018-linux/examples/Digital/toneMelody/pitches.h new file mode 100644 index 0000000..55c7d54 --- /dev/null +++ b/arduino-0018-linux/examples/Digital/toneMelody/pitches.h @@ -0,0 +1,95 @@ +/************************************************* + * Public Constants + *************************************************/ + +#define NOTE_B0 31 +#define NOTE_C1 33 +#define NOTE_CS1 35 +#define NOTE_D1 37 +#define NOTE_DS1 39 +#define NOTE_E1 41 +#define NOTE_F1 44 +#define NOTE_FS1 46 +#define NOTE_G1 49 +#define NOTE_GS1 52 +#define NOTE_A1 55 +#define NOTE_AS1 58 +#define NOTE_B1 62 +#define NOTE_C2 65 +#define NOTE_CS2 69 +#define NOTE_D2 73 +#define NOTE_DS2 78 +#define NOTE_E2 82 +#define NOTE_F2 87 +#define NOTE_FS2 93 +#define NOTE_G2 98 +#define NOTE_GS2 104 +#define NOTE_A2 110 +#define NOTE_AS2 117 +#define NOTE_B2 123 +#define NOTE_C3 131 +#define NOTE_CS3 139 +#define NOTE_D3 147 +#define NOTE_DS3 156 +#define NOTE_E3 165 +#define NOTE_F3 175 +#define NOTE_FS3 185 +#define NOTE_G3 196 +#define NOTE_GS3 208 +#define NOTE_A3 220 +#define NOTE_AS3 233 +#define NOTE_B3 247 +#define NOTE_C4 262 +#define NOTE_CS4 277 +#define NOTE_D4 294 +#define NOTE_DS4 311 +#define NOTE_E4 330 +#define NOTE_F4 349 +#define NOTE_FS4 370 +#define NOTE_G4 392 +#define NOTE_GS4 415 +#define NOTE_A4 440 +#define NOTE_AS4 466 +#define NOTE_B4 494 +#define NOTE_C5 523 +#define NOTE_CS5 554 +#define NOTE_D5 587 +#define NOTE_DS5 622 +#define NOTE_E5 659 +#define NOTE_F5 698 +#define NOTE_FS5 740 +#define NOTE_G5 784 +#define NOTE_GS5 831 +#define NOTE_A5 880 +#define NOTE_AS5 932 +#define NOTE_B5 988 +#define NOTE_C6 1047 +#define NOTE_CS6 1109 +#define NOTE_D6 1175 +#define NOTE_DS6 1245 +#define NOTE_E6 1319 +#define NOTE_F6 1397 +#define NOTE_FS6 1480 +#define NOTE_G6 1568 +#define NOTE_GS6 1661 +#define NOTE_A6 1760 +#define NOTE_AS6 1865 +#define NOTE_B6 1976 +#define NOTE_C7 2093 +#define NOTE_CS7 2217 +#define NOTE_D7 2349 +#define NOTE_DS7 2489 +#define NOTE_E7 2637 +#define NOTE_F7 2794 +#define NOTE_FS7 2960 +#define NOTE_G7 3136 +#define NOTE_GS7 3322 +#define NOTE_A7 3520 +#define NOTE_AS7 3729 +#define NOTE_B7 3951 +#define NOTE_C8 4186 +#define NOTE_CS8 4435 +#define NOTE_D8 4699 +#define NOTE_DS8 4978 + + diff --git a/arduino-0018-linux/examples/Digital/toneMelody/toneMelody.pde b/arduino-0018-linux/examples/Digital/toneMelody/toneMelody.pde new file mode 100644 index 0000000..b6e88d0 --- /dev/null +++ b/arduino-0018-linux/examples/Digital/toneMelody/toneMelody.pde @@ -0,0 +1,48 @@ +/* + Melody + + Plays a melody + + circuit: + * 8-ohm speaker on digital pin 8 + + created 21 Jan 2010 + by Tom Igoe + + http://arduino.cc/en/Tutorial/Tone + + */ + #include "pitches.h" + +// notes in the melody: +int melody[] = { + NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4}; + +// note durations: 4 = quarter note, 8 = eighth note, etc.: +int noteDurations[] = { + 4, 8, 8, 4,4,4,4,4 }; + +void setup() { + // iterate over the notes of the melody: + for (int thisNote = 0; thisNote < 8; thisNote++) { + + // to calculate the note duration, take one second + // divided by the note type. + //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. + int noteDuration = 1000/noteDurations[thisNote]; + tone(8, melody[thisNote],noteDuration); + + // to distinguish the notes, set a minimum time between them. + // the note's duration + 30% seems to work well: + int pauseBetweenNotes = noteDuration * 1.30; + delay(pauseBetweenNotes); + } +} + +void loop() { + // no need to repeat the melody. +} + + + + diff --git a/arduino-0018-linux/examples/Digital/tonePitchFollower/tonePitchFollower.pde b/arduino-0018-linux/examples/Digital/tonePitchFollower/tonePitchFollower.pde new file mode 100644 index 0000000..403b2c1 --- /dev/null +++ b/arduino-0018-linux/examples/Digital/tonePitchFollower/tonePitchFollower.pde @@ -0,0 +1,43 @@ +/* + Pitch follower + + Plays a pitch that changes based on a changing analog input + + circuit: + * 8-ohm speaker on digital pin 8 + * photoresistor on analog 0 to 5V + * 4.7K resistor on analog 0 to ground + + created 21 Jan 2010 + by Tom Igoe + + http://arduino.cc/en/Tutorial/Tone2 + + */ + + +void setup() { + // initialize serial communications (for debugging only): + Serial.begin(9600); +} + +void loop() { + // read the sensor: + int sensorReading = analogRead(0); + // print the sensor reading so you know its range + Serial.println(sensorReading); + // map the pitch to the range of the analog input. + // change the minimum and maximum input numbers below + // depending on the range your sensor's giving: + int thisPitch = map(sensorReading, 400, 1000, 100, 1000); + + // play the pitch: + tone(8, thisPitch, 10); + +} + + + + + + diff --git a/arduino-0018-linux/examples/Display/RowColumnScanning/RowColumnScanning.pde b/arduino-0018-linux/examples/Display/RowColumnScanning/RowColumnScanning.pde new file mode 100644 index 0000000..49f6ab7 --- /dev/null +++ b/arduino-0018-linux/examples/Display/RowColumnScanning/RowColumnScanning.pde @@ -0,0 +1,112 @@ +/* + Row-Column Scanning an 8x8 LED matrix with X-Y input + + This example controls an 8x8 LED matrix using two analog inputs + + created 27 May 2009 + modified 29 Jun 2009 + by Tom Igoe + + This example works for the Lumex LDM-24488NI Matrix. See + http://sigma.octopart.com/140413/datasheet/Lumex-LDM-24488NI.pdf + for the pin connections + + For other LED cathode column matrixes, you should only need to change + the pin numbers in the row[] and column[] arrays + + rows are the anodes + cols are the cathodes + --------- + + Pin numbers: + Matrix: + * Digital pins 2 through 13, + * analog pins 2 through 5 used as digital 16 through 19 + Potentiometers: + * center pins are attached to analog pins 0 and 1, respectively + * side pins attached to +5V and ground, respectively. + + http://www.arduino.cc/en/Tutorial/RowColumnScanning + + see also http://www.tigoe.net/pcomp/code/category/arduinowiring/514 for more + */ + + +// 2-dimensional array of row pin numbers: +const int row[8] = { + 2,7,19,5,13,18,12,16 }; + +// 2-dimensional array of column pin numbers: +const int col[8] = { + 6,11,10,3,17,4,8,9 }; + +// 2-dimensional array of pixels: +int pixels[8][8]; + +// cursor position: +int x = 5; +int y = 5; + +void setup() { + Serial.begin(9600); + // initialize the I/O pins as outputs: + + // iterate over the pins: + for (int thisPin = 0; thisPin < 8; thisPin++) { + // initialize the output pins: + pinMode(col[thisPin], OUTPUT); + pinMode(row[thisPin], OUTPUT); + // take the col pins (i.e. the cathodes) high to ensure that + // the LEDS are off: + digitalWrite(col[thisPin], HIGH); + } + + // initialize the pixel matrix: + for (int x = 0; x < 8; x++) { + for (int y = 0; y < 8; y++) { + pixels[x][y] = HIGH; + } + } +} + +void loop() { + // read input: + readSensors(); + + // draw the screen: + refreshScreen(); +} + +void readSensors() { + // turn off the last position: + pixels[x][y] = HIGH; + // read the sensors for X and Y values: + x = 7 - map(analogRead(0), 0, 1023, 0, 7); + y = map(analogRead(1), 0, 1023, 0, 7); + // set the new pixel position low so that the LED will turn on + // in the next screen refresh: + pixels[x][y] = LOW; + +} + +void refreshScreen() { + // iterate over the rows (anodes): + for (int thisRow = 0; thisRow < 8; thisRow++) { + // take the row pin (anode) high: + digitalWrite(row[thisRow], HIGH); + // iterate over the cols (cathodes): + for (int thisCol = 0; thisCol < 8; thisCol++) { + // get the state of the current pixel; + int thisPixel = pixels[thisRow][thisCol]; + // when the row is HIGH and the col is LOW, + // the LED where they meet turns on: + digitalWrite(col[thisCol], thisPixel); + // turn the pixel off: + if (thisPixel == LOW) { + digitalWrite(col[thisCol], HIGH); + } + } + // take the row pin low to turn off the whole row: + digitalWrite(row[thisRow], LOW); + } +} diff --git a/arduino-0018-linux/examples/Display/barGraph/barGraph.pde b/arduino-0018-linux/examples/Display/barGraph/barGraph.pde new file mode 100644 index 0000000..3e6664a --- /dev/null +++ b/arduino-0018-linux/examples/Display/barGraph/barGraph.pde @@ -0,0 +1,58 @@ +/* + LED bar graph + + Turns on a series of LEDs based on the value of an analog sensor. + This is a simple way to make a bar graph display. Though this graph + uses 10 LEDs, you can use any number by changing the LED count + and the pins in the array. + + This method can be used to control any series of digital outputs that + depends on an analog input. + + The circuit: + * LEDs from pins 2 through 11 to ground + + created 26 Jun 2009 + by Tom Igoe + + http://www.arduino.cc/en/Tutorial/BarGraph + */ + + +// these constants won't change: +const int analogPin = 0; // the pin that the potentiometer is attached to +const int ledCount = 10; // the number of LEDs in the bar graph + +int ledPins[] = { + 2, 3, 4, 5, 6, 7,8,9,10,11 }; // an array of pin numbers to which LEDs are attached + + +void setup() { + // loop over the pin array and set them all to output: + for (int thisLed = 0; thisLed < ledCount; thisLed++) { + pinMode(ledPins[thisLed], OUTPUT); + } +} + +void loop() { + // read the potentiometer: + int sensorReading = analogRead(analogPin); + // map the result to a range from 0 to the number of LEDs: + int ledLevel = map(sensorReading, 0, 1023, 0, ledCount); + + // loop over the LED array: + for (int thisLed = 0; thisLed < ledCount; thisLed++) { + // if the array element's index is less than ledLevel, + // turn the pin for this element on: + if (thisLed < ledLevel) { + digitalWrite(ledPins[thisLed], HIGH); + } + // turn off all pins higher than the ledLevel: + else { + digitalWrite(ledPins[thisLed], LOW); + } + } +} + + + diff --git a/arduino-0018-linux/examples/Sensors/ADXL3xx/ADXL3xx.pde b/arduino-0018-linux/examples/Sensors/ADXL3xx/ADXL3xx.pde new file mode 100644 index 0000000..5609c42 --- /dev/null +++ b/arduino-0018-linux/examples/Sensors/ADXL3xx/ADXL3xx.pde @@ -0,0 +1,62 @@ + +/* + ADXL3xx + + Reads an Analog Devices ADXL3xx accelerometer and communicates the + acceleration to the computer. The pins used are designed to be easily + compatible with the breakout boards from Sparkfun, available from: + http://www.sparkfun.com/commerce/categories.php?c=80 + + http://www.arduino.cc/en/Tutorial/ADXL3xx + + The circuit: + analog 0: accelerometer self test + analog 1: z-axis + analog 2: y-axis + analog 3: x-axis + analog 4: ground + analog 5: vcc + + created 2 Jul 2008 + by David A. Mellis + modified 26 Jun 2009 + by Tom Igoe + +*/ + +// these constants describe the pins. They won't change: +const int groundpin = 18; // analog input pin 4 -- ground +const int powerpin = 19; // analog input pin 5 -- voltage +const int xpin = 3; // x-axis of the accelerometer +const int ypin = 2; // y-axis +const int zpin = 1; // z-axis (only on 3-axis models) + +void setup() +{ + // initialize the serial communications: + Serial.begin(9600); + + // Provide ground and power by using the analog inputs as normal + // digital pins. This makes it possible to directly connect the + // breakout board to the Arduino. If you use the normal 5V and + // GND pins on the Arduino, you can remove these lines. + pinMode(groundpin, OUTPUT); + pinMode(powerpin, OUTPUT); + digitalWrite(groundpin, LOW); + digitalWrite(powerpin, HIGH); +} + +void loop() +{ + // print the sensor values: + Serial.print(analogRead(xpin)); + // print a tab between values: + Serial.print("\t"); + Serial.print(analogRead(ypin)); + // print a tab between values: + Serial.print("\t"); + Serial.print(analogRead(zpin)); + Serial.println(); + // delay before next reading: + delay(100); +} diff --git a/arduino-0018-linux/examples/Sensors/Knock/Knock.pde b/arduino-0018-linux/examples/Sensors/Knock/Knock.pde new file mode 100644 index 0000000..05e4632 --- /dev/null +++ b/arduino-0018-linux/examples/Sensors/Knock/Knock.pde @@ -0,0 +1,53 @@ +/* Knock Sensor + + This sketch reads a piezo element to detect a knocking sound. + It reads an analog pin and compares the result to a set threshold. + If the result is greater than the threshold, it writes + "knock" to the serial port, and toggles the LED on pin 13. + + The circuit: + * + connection of the piezo attached to analog in 0 + * - connection of the piezo attached to ground + * 1-megohm resistor attached from analog in 0 to ground + + http://www.arduino.cc/en/Tutorial/Knock + + created 25 Mar 2007 + by David Cuartielles + modified 30 Jun 2009 + by Tom Igoe + + */ + + +// these constants won't change: +const int ledPin = 13; // led connected to digital pin 13 +const int knockSensor = 0; // the piezo is connected to analog pin 0 +const int threshold = 100; // threshold value to decide when the detected sound is a knock or not + + +// these variables will change: +int sensorReading = 0; // variable to store the value read from the sensor pin +int ledState = LOW; // variable used to store the last LED status, to toggle the light + +void setup() { + pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT + Serial.begin(9600); // use the serial port +} + +void loop() { + // read the sensor and store it in the variable sensorReading: + sensorReading = analogRead(knockSensor); + + // if the sensor reading is greater than the threshold: + if (sensorReading >= threshold) { + // toggle the status of the ledPin: + ledState = !ledState; + // update the LED pin itself: + digitalWrite(ledPin, ledState); + // send the string "Knock!" back to the computer, followed by newline + Serial.println("Knock!"); + } + delay(100); // delay to avoid overloading the serial port buffer +} + diff --git a/arduino-0018-linux/examples/Sensors/Memsic2125/Memsic2125.pde b/arduino-0018-linux/examples/Sensors/Memsic2125/Memsic2125.pde new file mode 100644 index 0000000..a69e31d --- /dev/null +++ b/arduino-0018-linux/examples/Sensors/Memsic2125/Memsic2125.pde @@ -0,0 +1,61 @@ +/* + Memsic2125 + + Read the Memsic 2125 two-axis accelerometer. Converts the + pulses output by the 2125 into milli-g's (1/1000 of earth's + gravity) and prints them over the serial connection to the + computer. + + The circuit: + * X output of accelerometer to digital pin 2 + * Y output of accelerometer to digital pin 3 + * +V of accelerometer to +5V + * GND of accelerometer to ground + + http://www.arduino.cc/en/Tutorial/Memsic2125 + + created 6 Nov 2008 + by David A. Mellis + modified 30 Jun 2009 + by Tom Igoe + + */ + +// these constants won't change: +const int xPin = 2; // X output of the accelerometer +const int yPin = 3; // Y output of the accelerometer + +void setup() { + // initialize serial communications: + Serial.begin(9600); + // initialize the pins connected to the accelerometer + // as inputs: + pinMode(xPin, INPUT); + pinMode(yPin, INPUT); +} + +void loop() { + // variables to read the pulse widths: + int pulseX, pulseY; + // variables to contain the resulting accelerations + int accelerationX, accelerationY; + + // read pulse from x- and y-axes: + pulseX = pulseIn(xPin,HIGH); + pulseY = pulseIn(yPin,HIGH); + + // convert the pulse width into acceleration + // accelerationX and accelerationY are in milli-g's: + // earth's gravity is 1000 milli-g's, or 1g. + accelerationX = ((pulseX / 10) - 500) * 8; + accelerationY = ((pulseY / 10) - 500) * 8; + + // print the acceleration + Serial.print(accelerationX); + // print a tab character: + Serial.print("\t"); + Serial.print(accelerationY); + Serial.println(); + + delay(100); +} diff --git a/arduino-0018-linux/examples/Sensors/Ping/Ping.pde b/arduino-0018-linux/examples/Sensors/Ping/Ping.pde new file mode 100644 index 0000000..3e89744 --- /dev/null +++ b/arduino-0018-linux/examples/Sensors/Ping/Ping.pde @@ -0,0 +1,82 @@ +/* Ping))) Sensor + + This sketch reads a PING))) ultrasonic rangefinder and returns the + distance to the closest object in range. To do this, it sends a pulse + to the sensor to initiate a reading, then listens for a pulse + to return. The length of the returning pulse is proportional to + the distance of the object from the sensor. + + The circuit: + * +V connection of the PING))) attached to +5V + * GND connection of the PING))) attached to ground + * SIG connection of the PING))) attached to digital pin 7 + + http://www.arduino.cc/en/Tutorial/Ping + + created 3 Nov 2008 + by David A. Mellis + modified 30 Jun 2009 + by Tom Igoe + + */ + +// this constant won't change. It's the pin number +// of the sensor's output: +const int pingPin = 7; + +void setup() { + // initialize serial communication: + Serial.begin(9600); +} + +void loop() +{ + // establish variables for duration of the ping, + // and the distance result in inches and centimeters: + long duration, inches, cm; + + // The PING))) is triggered by a HIGH pulse of 2 or more microseconds. + // Give a short LOW pulse beforehand to ensure a clean HIGH pulse: + pinMode(pingPin, OUTPUT); + digitalWrite(pingPin, LOW); + delayMicroseconds(2); + digitalWrite(pingPin, HIGH); + delayMicroseconds(5); + digitalWrite(pingPin, LOW); + + // The same pin is used to read the signal from the PING))): a HIGH + // pulse whose duration is the time (in microseconds) from the sending + // of the ping to the reception of its echo off of an object. + pinMode(pingPin, INPUT); + duration = pulseIn(pingPin, HIGH); + + // convert the time into a distance + inches = microsecondsToInches(duration); + cm = microsecondsToCentimeters(duration); + + Serial.print(inches); + Serial.print("in, "); + Serial.print(cm); + Serial.print("cm"); + Serial.println(); + + delay(100); +} + +long microsecondsToInches(long microseconds) +{ + // According to Parallax's datasheet for the PING))), there are + // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per + // second). This gives the distance travelled by the ping, outbound + // and return, so we divide by 2 to get the distance of the obstacle. + // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf + return microseconds / 74 / 2; +} + +long microsecondsToCentimeters(long microseconds) +{ + // The speed of sound is 340 m/s or 29 microseconds per centimeter. + // The ping travels out and back, so to find the distance of the + // object we take half of the distance travelled. + return microseconds / 29 / 2; +} diff --git a/arduino-0018-linux/examples/Stubs/AnalogReadSerial/AnalogReadSerial.pde b/arduino-0018-linux/examples/Stubs/AnalogReadSerial/AnalogReadSerial.pde new file mode 100644 index 0000000..f0ce8f4 --- /dev/null +++ b/arduino-0018-linux/examples/Stubs/AnalogReadSerial/AnalogReadSerial.pde @@ -0,0 +1,12 @@ + +void setup() { + Serial.begin(9600); +} + +void loop() { + int sensorValue = analogRead(0); + Serial.println(sensorValue, DEC); +} + + + diff --git a/arduino-0018-linux/examples/Stubs/AnalogReadWrite/AnalogReadWrite.pde b/arduino-0018-linux/examples/Stubs/AnalogReadWrite/AnalogReadWrite.pde new file mode 100644 index 0000000..3dc8052 --- /dev/null +++ b/arduino-0018-linux/examples/Stubs/AnalogReadWrite/AnalogReadWrite.pde @@ -0,0 +1,13 @@ + +void setup() { + pinMode(6, OUTPUT); +} + +void loop() { + int sensorValue = analogRead(2); + int ledFadeValue = map(sensorValue, 0, 1023, 0, 255); + analogWrite(6, ledFadeValue); +} + + + diff --git a/arduino-0018-linux/examples/Stubs/BareMinumum/BareMinumum.pde b/arduino-0018-linux/examples/Stubs/BareMinumum/BareMinumum.pde new file mode 100644 index 0000000..b1a29e5 --- /dev/null +++ b/arduino-0018-linux/examples/Stubs/BareMinumum/BareMinumum.pde @@ -0,0 +1,9 @@ +void setup() { + +} + +void loop() { + +} + + diff --git a/arduino-0018-linux/examples/Stubs/DigitalReadSerial/DigitalReadSerial.pde b/arduino-0018-linux/examples/Stubs/DigitalReadSerial/DigitalReadSerial.pde new file mode 100644 index 0000000..369b9a4 --- /dev/null +++ b/arduino-0018-linux/examples/Stubs/DigitalReadSerial/DigitalReadSerial.pde @@ -0,0 +1,13 @@ + +void setup() { + Serial.begin(9600); + pinMode(2, INPUT); +} + +void loop() { + int sensorValue = digitalRead(2); + Serial.println(sensorValue, DEC); +} + + + diff --git a/arduino-0018-linux/examples/Stubs/DigitalReadWrite/DigitalReadWrite.pde b/arduino-0018-linux/examples/Stubs/DigitalReadWrite/DigitalReadWrite.pde new file mode 100644 index 0000000..f4ca3c5 --- /dev/null +++ b/arduino-0018-linux/examples/Stubs/DigitalReadWrite/DigitalReadWrite.pde @@ -0,0 +1,12 @@ + +void setup() { + pinMode(13, OUTPUT); +} + +void loop() { + int switchValue = digitalRead(2); + digitalWrite(13, switchValue); +} + + + diff --git a/arduino-0018-linux/examples/Stubs/HelloWorld/HelloWorld.pde b/arduino-0018-linux/examples/Stubs/HelloWorld/HelloWorld.pde new file mode 100644 index 0000000..628a9f3 --- /dev/null +++ b/arduino-0018-linux/examples/Stubs/HelloWorld/HelloWorld.pde @@ -0,0 +1,9 @@ +void setup() { + Serial.begin(9600); +} + +void loop() { + Serial.println("Hello World!"); +} + + diff --git a/arduino-0018-linux/hardware/arduino/boards.txt b/arduino-0018-linux/hardware/arduino/boards.txt new file mode 100644 index 0000000..4ae4ac9 --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/boards.txt @@ -0,0 +1,220 @@ +############################################################## + +atmega328.name=Arduino Duemilanove or Nano w/ ATmega328 + +atmega328.upload.protocol=stk500 +atmega328.upload.maximum_size=30720 +atmega328.upload.speed=57600 + +atmega328.bootloader.low_fuses=0xFF +atmega328.bootloader.high_fuses=0xDA +atmega328.bootloader.extended_fuses=0x05 +atmega328.bootloader.path=atmega +atmega328.bootloader.file=ATmegaBOOT_168_atmega328.hex +atmega328.bootloader.unlock_bits=0x3F +atmega328.bootloader.lock_bits=0x0F + +atmega328.build.mcu=atmega328p +atmega328.build.f_cpu=16000000L +atmega328.build.core=arduino + +############################################################## + +diecimila.name=Arduino Diecimila, Duemilanove, or Nano w/ ATmega168 + +diecimila.upload.protocol=stk500 +diecimila.upload.maximum_size=14336 +diecimila.upload.speed=19200 + +diecimila.bootloader.low_fuses=0xff +diecimila.bootloader.high_fuses=0xdd +diecimila.bootloader.extended_fuses=0x00 +diecimila.bootloader.path=atmega +diecimila.bootloader.file=ATmegaBOOT_168_diecimila.hex +diecimila.bootloader.unlock_bits=0x3F +diecimila.bootloader.lock_bits=0x0F + +diecimila.build.mcu=atmega168 +diecimila.build.f_cpu=16000000L +diecimila.build.core=arduino + +############################################################## + +mega.name=Arduino Mega + +mega.upload.protocol=stk500 +mega.upload.maximum_size=126976 +mega.upload.speed=57600 + +mega.bootloader.low_fuses=0xFF +mega.bootloader.high_fuses=0xDA +mega.bootloader.extended_fuses=0xF5 +mega.bootloader.path=atmega +mega.bootloader.file=ATmegaBOOT_168_atmega1280.hex +mega.bootloader.unlock_bits=0x3F +mega.bootloader.lock_bits=0x0F + +mega.build.mcu=atmega1280 +mega.build.f_cpu=16000000L +mega.build.core=arduino + +############################################################## + +mini.name=Arduino Mini + +mini.upload.protocol=stk500 +mini.upload.maximum_size=14336 +mini.upload.speed=19200 + +mini.bootloader.low_fuses=0xff +mini.bootloader.high_fuses=0xdd +mini.bootloader.extended_fuses=0x00 +mini.bootloader.path=atmega +mini.bootloader.file=ATmegaBOOT_168_ng.hex +mini.bootloader.unlock_bits=0x3F +mini.bootloader.lock_bits=0x0F + +mini.build.mcu=atmega168 +mini.build.f_cpu=16000000L +mini.build.core=arduino + +############################################################## + +bt.name=Arduino BT + +bt.upload.protocol=stk500 +bt.upload.maximum_size=14336 +bt.upload.speed=19200 +bt.upload.disable_flushing=true + +bt.bootloader.low_fuses=0xff +bt.bootloader.high_fuses=0xdd +bt.bootloader.extended_fuses=0x00 +bt.bootloader.path=bt +bt.bootloader.file=ATmegaBOOT_168.hex +bt.bootloader.unlock_bits=0x3F +bt.bootloader.lock_bits=0x0F + +bt.build.mcu=atmega168 +bt.build.f_cpu=16000000L +bt.build.core=arduino + +############################################################## + +lilypad328.name=LilyPad Arduino w/ ATmega328 + +lilypad328.upload.protocol=stk500 +lilypad328.upload.maximum_size=30720 +lilypad328.upload.speed=57600 + +lilypad328.bootloader.low_fuses=0xFF +lilypad328.bootloader.high_fuses=0xDA +lilypad328.bootloader.extended_fuses=0x05 +lilypad328.bootloader.path=atmega +lilypad328.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex +lilypad328.bootloader.unlock_bits=0x3F +lilypad328.bootloader.lock_bits=0x0F + +lilypad328.build.mcu=atmega328p +lilypad328.build.f_cpu=8000000L +lilypad328.build.core=arduino + +############################################################## + +lilypad.name=LilyPad Arduino w/ ATmega168 + +lilypad.upload.protocol=stk500 +lilypad.upload.maximum_size=14336 +lilypad.upload.speed=19200 + +lilypad.bootloader.low_fuses=0xe2 +lilypad.bootloader.high_fuses=0xdd +lilypad.bootloader.extended_fuses=0x00 +lilypad.bootloader.path=lilypad +lilypad.bootloader.file=LilyPadBOOT_168.hex +lilypad.bootloader.unlock_bits=0x3F +lilypad.bootloader.lock_bits=0x0F + +lilypad.build.mcu=atmega168 +lilypad.build.f_cpu=8000000L +lilypad.build.core=arduino + +############################################################## + +pro328.name=Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328 + +pro328.upload.protocol=stk500 +pro328.upload.maximum_size=30720 +pro328.upload.speed=57600 + +pro328.bootloader.low_fuses=0xFF +pro328.bootloader.high_fuses=0xDA +pro328.bootloader.extended_fuses=0x05 +pro328.bootloader.path=atmega +pro328.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex +pro328.bootloader.unlock_bits=0x3F +pro328.bootloader.lock_bits=0x0F + +pro328.build.mcu=atmega328p +pro328.build.f_cpu=8000000L +pro328.build.core=arduino + +############################################################## + +pro.name=Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega168 + +pro.upload.protocol=stk500 +pro.upload.maximum_size=14336 +pro.upload.speed=19200 + +pro.bootloader.low_fuses=0xc6 +pro.bootloader.high_fuses=0xdd +pro.bootloader.extended_fuses=0x00 +pro.bootloader.path=atmega +pro.bootloader.file=ATmegaBOOT_168_pro_8MHz.hex +pro.bootloader.unlock_bits=0x3F +pro.bootloader.lock_bits=0x0F + +pro.build.mcu=atmega168 +pro.build.f_cpu=8000000L +pro.build.core=arduino + +############################################################## + +atmega168.name=Arduino NG or older w/ ATmega168 + +atmega168.upload.protocol=stk500 +atmega168.upload.maximum_size=14336 +atmega168.upload.speed=19200 + +atmega168.bootloader.low_fuses=0xff +atmega168.bootloader.high_fuses=0xdd +atmega168.bootloader.extended_fuses=0x00 +atmega168.bootloader.path=atmega +atmega168.bootloader.file=ATmegaBOOT_168_ng.hex +atmega168.bootloader.unlock_bits=0x3F +atmega168.bootloader.lock_bits=0x0F + +atmega168.build.mcu=atmega168 +atmega168.build.f_cpu=16000000L +atmega168.build.core=arduino + +############################################################## + +atmega8.name=Arduino NG or older w/ ATmega8 + +atmega8.upload.protocol=stk500 +atmega8.upload.maximum_size=7168 +atmega8.upload.speed=19200 + +atmega8.bootloader.low_fuses=0xdf +atmega8.bootloader.high_fuses=0xca +atmega8.bootloader.path=atmega8 +atmega8.bootloader.file=ATmegaBOOT.hex +atmega8.bootloader.unlock_bits=0x3F +atmega8.bootloader.lock_bits=0x0F + +atmega8.build.mcu=atmega8 +atmega8.build.f_cpu=16000000L +atmega8.build.core=arduino + diff --git a/arduino-0018-linux/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168.c b/arduino-0018-linux/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168.c new file mode 100755 index 0000000..2b9fefa --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168.c @@ -0,0 +1,1054 @@ +/**********************************************************/ +/* Serial Bootloader for Atmel megaAVR Controllers */ +/* */ +/* tested with ATmega8, ATmega128 and ATmega168 */ +/* should work with other mega's, see code for details */ +/* */ +/* ATmegaBOOT.c */ +/* */ +/* */ +/* 20090308: integrated Mega changes into main bootloader */ +/* source by D. Mellis */ +/* 20080930: hacked for Arduino Mega (with the 1280 */ +/* processor, backwards compatible) */ +/* by D. Cuartielles */ +/* 20070626: hacked for Arduino Diecimila (which auto- */ +/* resets when a USB connection is made to it) */ +/* by D. Mellis */ +/* 20060802: hacked for Arduino by D. Cuartielles */ +/* based on a previous hack by D. Mellis */ +/* and D. Cuartielles */ +/* */ +/* Monitor and debug functions were added to the original */ +/* code by Dr. Erik Lins, chip45.com. (See below) */ +/* */ +/* Thanks to Karl Pitrich for fixing a bootloader pin */ +/* problem and more informative LED blinking! */ +/* */ +/* For the latest version see: */ +/* http://www.chip45.com/ */ +/* */ +/* ------------------------------------------------------ */ +/* */ +/* based on stk500boot.c */ +/* Copyright (c) 2003, Jason P. Kyle */ +/* All rights reserved. */ +/* see avr1.org for original file and information */ +/* */ +/* This program is free software; you can redistribute it */ +/* and/or modify it under the terms of the GNU General */ +/* Public License as published by the Free Software */ +/* Foundation; either version 2 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* This program is distributed in the hope that it will */ +/* be useful, but WITHOUT ANY WARRANTY; without even the */ +/* implied warranty of MERCHANTABILITY or FITNESS FOR A */ +/* PARTICULAR PURPOSE. See the GNU General Public */ +/* License for more details. */ +/* */ +/* You should have received a copy of the GNU General */ +/* Public License along with this program; if not, write */ +/* to the Free Software Foundation, Inc., */ +/* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/* */ +/* Licence can be viewed at */ +/* http://www.fsf.org/licenses/gpl.txt */ +/* */ +/* Target = Atmel AVR m128,m64,m32,m16,m8,m162,m163,m169, */ +/* m8515,m8535. ATmega161 has a very small boot block so */ +/* isn't supported. */ +/* */ +/* Tested with m168 */ +/**********************************************************/ + +/* $Id$ */ + + +/* some includes */ +#include +#include +#include +#include +#include +#include + +/* the current avr-libc eeprom functions do not support the ATmega168 */ +/* own eeprom write/read functions are used instead */ +#if !defined(__AVR_ATmega168__) || !defined(__AVR_ATmega328P__) +#include +#endif + +/* Use the F_CPU defined in Makefile */ + +/* 20060803: hacked by DojoCorp */ +/* 20070626: hacked by David A. Mellis to decrease waiting time for auto-reset */ +/* set the waiting time for the bootloader */ +/* get this from the Makefile instead */ +/* #define MAX_TIME_COUNT (F_CPU>>4) */ + +/* 20070707: hacked by David A. Mellis - after this many errors give up and launch application */ +#define MAX_ERROR_COUNT 5 + +/* set the UART baud rate */ +/* 20060803: hacked by DojoCorp */ +//#define BAUD_RATE 115200 +#ifndef BAUD_RATE +#define BAUD_RATE 19200 +#endif + + +/* SW_MAJOR and MINOR needs to be updated from time to time to avoid warning message from AVR Studio */ +/* never allow AVR Studio to do an update !!!! */ +#define HW_VER 0x02 +#define SW_MAJOR 0x01 +#define SW_MINOR 0x10 + + +/* Adjust to suit whatever pin your hardware uses to enter the bootloader */ +/* ATmega128 has two UARTS so two pins are used to enter bootloader and select UART */ +/* ATmega1280 has four UARTS, but for Arduino Mega, we will only use RXD0 to get code */ +/* BL0... means UART0, BL1... means UART1 */ +#ifdef __AVR_ATmega128__ +#define BL_DDR DDRF +#define BL_PORT PORTF +#define BL_PIN PINF +#define BL0 PINF7 +#define BL1 PINF6 +#elif defined __AVR_ATmega1280__ +/* we just don't do anything for the MEGA and enter bootloader on reset anyway*/ +#else +/* other ATmegas have only one UART, so only one pin is defined to enter bootloader */ +#define BL_DDR DDRD +#define BL_PORT PORTD +#define BL_PIN PIND +#define BL PIND6 +#endif + + +/* onboard LED is used to indicate, that the bootloader was entered (3x flashing) */ +/* if monitor functions are included, LED goes on after monitor was entered */ +#if defined __AVR_ATmega128__ || defined __AVR_ATmega1280__ +/* Onboard LED is connected to pin PB7 (e.g. Crumb128, PROBOmega128, Savvy128, Arduino Mega) */ +#define LED_DDR DDRB +#define LED_PORT PORTB +#define LED_PIN PINB +#define LED PINB7 +#else +/* Onboard LED is connected to pin PB5 in Arduino NG, Diecimila, and Duomilanuove */ +/* other boards like e.g. Crumb8, Crumb168 are using PB2 */ +#define LED_DDR DDRB +#define LED_PORT PORTB +#define LED_PIN PINB +#define LED PINB5 +#endif + + +/* monitor functions will only be compiled when using ATmega128, due to bootblock size constraints */ +#if defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__) +#define MONITOR 1 +#endif + + +/* define various device id's */ +/* manufacturer byte is always the same */ +#define SIG1 0x1E // Yep, Atmel is the only manufacturer of AVR micros. Single source :( + +#if defined __AVR_ATmega1280__ +#define SIG2 0x97 +#define SIG3 0x03 +#define PAGE_SIZE 0x80U //128 words + +#elif defined __AVR_ATmega1281__ +#define SIG2 0x97 +#define SIG3 0x04 +#define PAGE_SIZE 0x80U //128 words + +#elif defined __AVR_ATmega128__ +#define SIG2 0x97 +#define SIG3 0x02 +#define PAGE_SIZE 0x80U //128 words + +#elif defined __AVR_ATmega64__ +#define SIG2 0x96 +#define SIG3 0x02 +#define PAGE_SIZE 0x80U //128 words + +#elif defined __AVR_ATmega32__ +#define SIG2 0x95 +#define SIG3 0x02 +#define PAGE_SIZE 0x40U //64 words + +#elif defined __AVR_ATmega16__ +#define SIG2 0x94 +#define SIG3 0x03 +#define PAGE_SIZE 0x40U //64 words + +#elif defined __AVR_ATmega8__ +#define SIG2 0x93 +#define SIG3 0x07 +#define PAGE_SIZE 0x20U //32 words + +#elif defined __AVR_ATmega88__ +#define SIG2 0x93 +#define SIG3 0x0a +#define PAGE_SIZE 0x20U //32 words + +#elif defined __AVR_ATmega168__ +#define SIG2 0x94 +#define SIG3 0x06 +#define PAGE_SIZE 0x40U //64 words + +#elif defined __AVR_ATmega328P__ +#define SIG2 0x95 +#define SIG3 0x0F +#define PAGE_SIZE 0x40U //64 words + +#elif defined __AVR_ATmega162__ +#define SIG2 0x94 +#define SIG3 0x04 +#define PAGE_SIZE 0x40U //64 words + +#elif defined __AVR_ATmega163__ +#define SIG2 0x94 +#define SIG3 0x02 +#define PAGE_SIZE 0x40U //64 words + +#elif defined __AVR_ATmega169__ +#define SIG2 0x94 +#define SIG3 0x05 +#define PAGE_SIZE 0x40U //64 words + +#elif defined __AVR_ATmega8515__ +#define SIG2 0x93 +#define SIG3 0x06 +#define PAGE_SIZE 0x20U //32 words + +#elif defined __AVR_ATmega8535__ +#define SIG2 0x93 +#define SIG3 0x08 +#define PAGE_SIZE 0x20U //32 words +#endif + + +/* function prototypes */ +void putch(char); +char getch(void); +void getNch(uint8_t); +void byte_response(uint8_t); +void nothing_response(void); +char gethex(void); +void puthex(char); +void flash_led(uint8_t); + +/* some variables */ +union address_union { + uint16_t word; + uint8_t byte[2]; +} address; + +union length_union { + uint16_t word; + uint8_t byte[2]; +} length; + +struct flags_struct { + unsigned eeprom : 1; + unsigned rampz : 1; +} flags; + +uint8_t buff[256]; +uint8_t address_high; + +uint8_t pagesz=0x80; + +uint8_t i; +uint8_t bootuart = 0; + +uint8_t error_count = 0; + +void (*app_start)(void) = 0x0000; + + +/* main program starts here */ +int main(void) +{ + uint8_t ch,ch2; + uint16_t w; + +#ifdef WATCHDOG_MODS + ch = MCUSR; + MCUSR = 0; + + WDTCSR |= _BV(WDCE) | _BV(WDE); + WDTCSR = 0; + + // Check if the WDT was used to reset, in which case we dont bootload and skip straight to the code. woot. + if (! (ch & _BV(EXTRF))) // if its a not an external reset... + app_start(); // skip bootloader +#else + asm volatile("nop\n\t"); +#endif + + /* set pin direction for bootloader pin and enable pullup */ + /* for ATmega128, two pins need to be initialized */ +#ifdef __AVR_ATmega128__ + BL_DDR &= ~_BV(BL0); + BL_DDR &= ~_BV(BL1); + BL_PORT |= _BV(BL0); + BL_PORT |= _BV(BL1); +#else + /* We run the bootloader regardless of the state of this pin. Thus, don't + put it in a different state than the other pins. --DAM, 070709 + This also applies to Arduino Mega -- DC, 080930 + BL_DDR &= ~_BV(BL); + BL_PORT |= _BV(BL); + */ +#endif + + +#ifdef __AVR_ATmega128__ + /* check which UART should be used for booting */ + if(bit_is_clear(BL_PIN, BL0)) { + bootuart = 1; + } + else if(bit_is_clear(BL_PIN, BL1)) { + bootuart = 2; + } +#endif + +#if defined __AVR_ATmega1280__ + /* the mega1280 chip has four serial ports ... we could eventually use any of them, or not? */ + /* however, we don't wanna confuse people, to avoid making a mess, we will stick to RXD0, TXD0 */ + bootuart = 1; +#endif + + /* check if flash is programmed already, if not start bootloader anyway */ + if(pgm_read_byte_near(0x0000) != 0xFF) { + +#ifdef __AVR_ATmega128__ + /* no UART was selected, start application */ + if(!bootuart) { + app_start(); + } +#else + /* check if bootloader pin is set low */ + /* we don't start this part neither for the m8, nor m168 */ + //if(bit_is_set(BL_PIN, BL)) { + // app_start(); + // } +#endif + } + +#ifdef __AVR_ATmega128__ + /* no bootuart was selected, default to uart 0 */ + if(!bootuart) { + bootuart = 1; + } +#endif + + + /* initialize UART(s) depending on CPU defined */ +#if defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__) + if(bootuart == 1) { + UBRR0L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1); + UBRR0H = (F_CPU/(BAUD_RATE*16L)-1) >> 8; + UCSR0A = 0x00; + UCSR0C = 0x06; + UCSR0B = _BV(TXEN0)|_BV(RXEN0); + } + if(bootuart == 2) { + UBRR1L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1); + UBRR1H = (F_CPU/(BAUD_RATE*16L)-1) >> 8; + UCSR1A = 0x00; + UCSR1C = 0x06; + UCSR1B = _BV(TXEN1)|_BV(RXEN1); + } +#elif defined __AVR_ATmega163__ + UBRR = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1); + UBRRHI = (F_CPU/(BAUD_RATE*16L)-1) >> 8; + UCSRA = 0x00; + UCSRB = _BV(TXEN)|_BV(RXEN); +#elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) + +#ifdef DOUBLE_SPEED + UCSR0A = (1<> 8; +#else + UBRR0L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1); + UBRR0H = (F_CPU/(BAUD_RATE*16L)-1) >> 8; +#endif + + UCSR0B = (1<>8; // set baud rate + UBRRL = (((F_CPU/BAUD_RATE)/16)-1); + UCSRB = (1<> 8; + UCSRA = 0x00; + UCSRC = 0x06; + UCSRB = _BV(TXEN)|_BV(RXEN); +#endif + +#if defined __AVR_ATmega1280__ + /* Enable internal pull-up resistor on pin D0 (RX), in order + to supress line noise that prevents the bootloader from + timing out (DAM: 20070509) */ + /* feature added to the Arduino Mega --DC: 080930 */ + DDRE &= ~_BV(PINE0); + PORTE |= _BV(PINE0); +#endif + + + /* set LED pin as output */ + LED_DDR |= _BV(LED); + + + /* flash onboard LED to signal entering of bootloader */ +#if defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__) + // 4x for UART0, 5x for UART1 + flash_led(NUM_LED_FLASHES + bootuart); +#else + flash_led(NUM_LED_FLASHES); +#endif + + /* 20050803: by DojoCorp, this is one of the parts provoking the + system to stop listening, cancelled from the original */ + //putch('\0'); + + /* forever loop */ + for (;;) { + + /* get character from UART */ + ch = getch(); + + /* A bunch of if...else if... gives smaller code than switch...case ! */ + + /* Hello is anyone home ? */ + if(ch=='0') { + nothing_response(); + } + + + /* Request programmer ID */ + /* Not using PROGMEM string due to boot block in m128 being beyond 64kB boundry */ + /* Would need to selectively manipulate RAMPZ, and it's only 9 characters anyway so who cares. */ + else if(ch=='1') { + if (getch() == ' ') { + putch(0x14); + putch('A'); + putch('V'); + putch('R'); + putch(' '); + putch('I'); + putch('S'); + putch('P'); + putch(0x10); + } else { + if (++error_count == MAX_ERROR_COUNT) + app_start(); + } + } + + + /* AVR ISP/STK500 board commands DON'T CARE so default nothing_response */ + else if(ch=='@') { + ch2 = getch(); + if (ch2>0x85) getch(); + nothing_response(); + } + + + /* AVR ISP/STK500 board requests */ + else if(ch=='A') { + ch2 = getch(); + if(ch2==0x80) byte_response(HW_VER); // Hardware version + else if(ch2==0x81) byte_response(SW_MAJOR); // Software major version + else if(ch2==0x82) byte_response(SW_MINOR); // Software minor version + else if(ch2==0x98) byte_response(0x03); // Unknown but seems to be required by avr studio 3.56 + else byte_response(0x00); // Covers various unnecessary responses we don't care about + } + + + /* Device Parameters DON'T CARE, DEVICE IS FIXED */ + else if(ch=='B') { + getNch(20); + nothing_response(); + } + + + /* Parallel programming stuff DON'T CARE */ + else if(ch=='E') { + getNch(5); + nothing_response(); + } + + + /* P: Enter programming mode */ + /* R: Erase device, don't care as we will erase one page at a time anyway. */ + else if(ch=='P' || ch=='R') { + nothing_response(); + } + + + /* Leave programming mode */ + else if(ch=='Q') { + nothing_response(); +#ifdef WATCHDOG_MODS + // autoreset via watchdog (sneaky!) + WDTCSR = _BV(WDE); + while (1); // 16 ms +#endif + } + + + /* Set address, little endian. EEPROM in bytes, FLASH in words */ + /* Perhaps extra address bytes may be added in future to support > 128kB FLASH. */ + /* This might explain why little endian was used here, big endian used everywhere else. */ + else if(ch=='U') { + address.byte[0] = getch(); + address.byte[1] = getch(); + nothing_response(); + } + + + /* Universal SPI programming command, disabled. Would be used for fuses and lock bits. */ + else if(ch=='V') { + if (getch() == 0x30) { + getch(); + ch = getch(); + getch(); + if (ch == 0) { + byte_response(SIG1); + } else if (ch == 1) { + byte_response(SIG2); + } else { + byte_response(SIG3); + } + } else { + getNch(3); + byte_response(0x00); + } + } + + + /* Write memory, length is big endian and is in bytes */ + else if(ch=='d') { + length.byte[1] = getch(); + length.byte[0] = getch(); + flags.eeprom = 0; + if (getch() == 'E') flags.eeprom = 1; + for (w=0;w127) address_high = 0x01; //Only possible with m128, m256 will need 3rd address byte. FIXME + else address_high = 0x00; +#if defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) + RAMPZ = address_high; +#endif + address.word = address.word << 1; //address * 2 -> byte location + /* if ((length.byte[0] & 0x01) == 0x01) length.word++; //Even up an odd number of bytes */ + if ((length.byte[0] & 0x01)) length.word++; //Even up an odd number of bytes + cli(); //Disable interrupts, just to be sure +#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__) + while(bit_is_set(EECR,EEPE)); //Wait for previous EEPROM writes to complete +#else + while(bit_is_set(EECR,EEWE)); //Wait for previous EEPROM writes to complete +#endif + asm volatile( + "clr r17 \n\t" //page_word_count + "lds r30,address \n\t" //Address of FLASH location (in bytes) + "lds r31,address+1 \n\t" + "ldi r28,lo8(buff) \n\t" //Start of buffer array in RAM + "ldi r29,hi8(buff) \n\t" + "lds r24,length \n\t" //Length of data to be written (in bytes) + "lds r25,length+1 \n\t" + "length_loop: \n\t" //Main loop, repeat for number of words in block + "cpi r17,0x00 \n\t" //If page_word_count=0 then erase page + "brne no_page_erase \n\t" + "wait_spm1: \n\t" + "lds r16,%0 \n\t" //Wait for previous spm to complete + "andi r16,1 \n\t" + "cpi r16,1 \n\t" + "breq wait_spm1 \n\t" + "ldi r16,0x03 \n\t" //Erase page pointed to by Z + "sts %0,r16 \n\t" + "spm \n\t" +#ifdef __AVR_ATmega163__ + ".word 0xFFFF \n\t" + "nop \n\t" +#endif + "wait_spm2: \n\t" + "lds r16,%0 \n\t" //Wait for previous spm to complete + "andi r16,1 \n\t" + "cpi r16,1 \n\t" + "breq wait_spm2 \n\t" + + "ldi r16,0x11 \n\t" //Re-enable RWW section + "sts %0,r16 \n\t" + "spm \n\t" +#ifdef __AVR_ATmega163__ + ".word 0xFFFF \n\t" + "nop \n\t" +#endif + "no_page_erase: \n\t" + "ld r0,Y+ \n\t" //Write 2 bytes into page buffer + "ld r1,Y+ \n\t" + + "wait_spm3: \n\t" + "lds r16,%0 \n\t" //Wait for previous spm to complete + "andi r16,1 \n\t" + "cpi r16,1 \n\t" + "breq wait_spm3 \n\t" + "ldi r16,0x01 \n\t" //Load r0,r1 into FLASH page buffer + "sts %0,r16 \n\t" + "spm \n\t" + + "inc r17 \n\t" //page_word_count++ + "cpi r17,%1 \n\t" + "brlo same_page \n\t" //Still same page in FLASH + "write_page: \n\t" + "clr r17 \n\t" //New page, write current one first + "wait_spm4: \n\t" + "lds r16,%0 \n\t" //Wait for previous spm to complete + "andi r16,1 \n\t" + "cpi r16,1 \n\t" + "breq wait_spm4 \n\t" +#ifdef __AVR_ATmega163__ + "andi r30,0x80 \n\t" // m163 requires Z6:Z1 to be zero during page write +#endif + "ldi r16,0x05 \n\t" //Write page pointed to by Z + "sts %0,r16 \n\t" + "spm \n\t" +#ifdef __AVR_ATmega163__ + ".word 0xFFFF \n\t" + "nop \n\t" + "ori r30,0x7E \n\t" // recover Z6:Z1 state after page write (had to be zero during write) +#endif + "wait_spm5: \n\t" + "lds r16,%0 \n\t" //Wait for previous spm to complete + "andi r16,1 \n\t" + "cpi r16,1 \n\t" + "breq wait_spm5 \n\t" + "ldi r16,0x11 \n\t" //Re-enable RWW section + "sts %0,r16 \n\t" + "spm \n\t" +#ifdef __AVR_ATmega163__ + ".word 0xFFFF \n\t" + "nop \n\t" +#endif + "same_page: \n\t" + "adiw r30,2 \n\t" //Next word in FLASH + "sbiw r24,2 \n\t" //length-2 + "breq final_write \n\t" //Finished + "rjmp length_loop \n\t" + "final_write: \n\t" + "cpi r17,0 \n\t" + "breq block_done \n\t" + "adiw r24,2 \n\t" //length+2, fool above check on length after short page write + "rjmp write_page \n\t" + "block_done: \n\t" + "clr __zero_reg__ \n\t" //restore zero register +#if defined __AVR_ATmega168__ || __AVR_ATmega328P__ || __AVR_ATmega128__ || __AVR_ATmega1280__ || __AVR_ATmega1281__ + : "=m" (SPMCSR) : "M" (PAGE_SIZE) : "r0","r16","r17","r24","r25","r28","r29","r30","r31" +#else + : "=m" (SPMCR) : "M" (PAGE_SIZE) : "r0","r16","r17","r24","r25","r28","r29","r30","r31" +#endif + ); + /* Should really add a wait for RWW section to be enabled, don't actually need it since we never */ + /* exit the bootloader without a power cycle anyhow */ + } + putch(0x14); + putch(0x10); + } else { + if (++error_count == MAX_ERROR_COUNT) + app_start(); + } + } + + + /* Read memory block mode, length is big endian. */ + else if(ch=='t') { + length.byte[1] = getch(); + length.byte[0] = getch(); +#if defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__) + if (address.word>0x7FFF) flags.rampz = 1; // No go with m256, FIXME + else flags.rampz = 0; +#endif + address.word = address.word << 1; // address * 2 -> byte location + if (getch() == 'E') flags.eeprom = 1; + else flags.eeprom = 0; + if (getch() == ' ') { // Command terminator + putch(0x14); + for (w=0;w < length.word;w++) { // Can handle odd and even lengths okay + if (flags.eeprom) { // Byte access EEPROM read +#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) + while(EECR & (1<= 'a') { + return (a - 'a' + 0x0a); + } else if(a >= '0') { + return(a - '0'); + } + return a; +} + + +char gethex(void) { + return (gethexnib() << 4) + gethexnib(); +} + + +void puthex(char ch) { + char ah; + + ah = ch >> 4; + if(ah >= 0x0a) { + ah = ah - 0x0a + 'a'; + } else { + ah += '0'; + } + + ch &= 0x0f; + if(ch >= 0x0a) { + ch = ch - 0x0a + 'a'; + } else { + ch += '0'; + } + + putch(ah); + putch(ch); +} + + +void putch(char ch) +{ +#if defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__) + if(bootuart == 1) { + while (!(UCSR0A & _BV(UDRE0))); + UDR0 = ch; + } + else if (bootuart == 2) { + while (!(UCSR1A & _BV(UDRE1))); + UDR1 = ch; + } +#elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) + while (!(UCSR0A & _BV(UDRE0))); + UDR0 = ch; +#else + /* m8,16,32,169,8515,8535,163 */ + while (!(UCSRA & _BV(UDRE))); + UDR = ch; +#endif +} + + +char getch(void) +{ +#if defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__) + uint32_t count = 0; + if(bootuart == 1) { + while(!(UCSR0A & _BV(RXC0))) { + /* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/ + /* HACKME:: here is a good place to count times*/ + count++; + if (count > MAX_TIME_COUNT) + app_start(); + } + + return UDR0; + } + else if(bootuart == 2) { + while(!(UCSR1A & _BV(RXC1))) { + /* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/ + /* HACKME:: here is a good place to count times*/ + count++; + if (count > MAX_TIME_COUNT) + app_start(); + } + + return UDR1; + } + return 0; +#elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) + uint32_t count = 0; + while(!(UCSR0A & _BV(RXC0))){ + /* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/ + /* HACKME:: here is a good place to count times*/ + count++; + if (count > MAX_TIME_COUNT) + app_start(); + } + return UDR0; +#else + /* m8,16,32,169,8515,8535,163 */ + uint32_t count = 0; + while(!(UCSRA & _BV(RXC))){ + /* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/ + /* HACKME:: here is a good place to count times*/ + count++; + if (count > MAX_TIME_COUNT) + app_start(); + } + return UDR; +#endif +} + + +void getNch(uint8_t count) +{ + while(count--) { +#if defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__) + if(bootuart == 1) { + while(!(UCSR0A & _BV(RXC0))); + UDR0; + } + else if(bootuart == 2) { + while(!(UCSR1A & _BV(RXC1))); + UDR1; + } +#elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) + getch(); +#else + /* m8,16,32,169,8515,8535,163 */ + /* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/ + //while(!(UCSRA & _BV(RXC))); + //UDR; + getch(); // need to handle time out +#endif + } +} + + +void byte_response(uint8_t val) +{ + if (getch() == ' ') { + putch(0x14); + putch(val); + putch(0x10); + } else { + if (++error_count == MAX_ERROR_COUNT) + app_start(); + } +} + + +void nothing_response(void) +{ + if (getch() == ' ') { + putch(0x14); + putch(0x10); + } else { + if (++error_count == MAX_ERROR_COUNT) + app_start(); + } +} + +void flash_led(uint8_t count) +{ + while (count--) { + LED_PORT |= _BV(LED); + _delay_ms(100); + LED_PORT &= ~_BV(LED); + _delay_ms(100); + } +} + + +/* end of file ATmegaBOOT.c */ diff --git a/arduino-0018-linux/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_atmega1280.hex b/arduino-0018-linux/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_atmega1280.hex new file mode 100644 index 0000000..f16e877 --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_atmega1280.hex @@ -0,0 +1,245 @@ +:020000021000EC +:10F000000C9472F80C9492F80C9492F80C9492F878 +:10F010000C9492F80C9492F80C9492F80C9492F848 +:10F020000C9492F80C9492F80C9492F80C9492F838 +:10F030000C9492F80C9492F80C9492F80C9492F828 +:10F040000C9492F80C9492F80C9492F80C9492F818 +:10F050000C9492F80C9492F80C9492F80C9492F808 +:10F060000C9492F80C9492F80C9492F80C9492F8F8 +:10F070000C9492F80C9492F80C9492F80C9492F8E8 +:10F080000C9492F80C9492F80C9492F80C9492F8D8 +:10F090000C9492F80C9492F80C9492F80C9492F8C8 +:10F0A0000C9492F80C9492F80C9492F80C9492F8B8 +:10F0B0000C9492F80C9492F80C9492F80C9492F8A8 +:10F0C0000C9492F80C9492F80C9492F80C9492F898 +:10F0D0000C9492F80C9492F80C9492F80C9492F888 +:10F0E0000C9492F811241FBECFEFD1E2DEBFCDBF4A +:10F0F00012E0A0E0B2E0EEEDFEEF01E00BBF02C0D7 +:10F1000007900D92A833B107D9F71BBE13E0A8E30F +:10F11000B2E001C01D92A334B107E1F70E9412FAD8 +:10F120000C946DFF0C9400F8982F959595959595F6 +:10F130009595905D8F708A301CF1282F295A809107 +:10F140003802813019F0823071F008958091C0004A +:10F1500085FFFCCF9093C6008091C00085FFFCCF57 +:10F160002093C60008958091C80085FFFCCF90933E +:10F17000CE008091C80085FFFCCF2093CE0008957B +:10F18000282F205DDCCF982F80913802813019F034 +:10F19000823041F008958091C00085FFFCCF9093AC +:10F1A000C60008958091C80085FFFCCF9093CE00E3 +:10F1B0000895EF92FF920F931F9380913802813050 +:10F1C00069F1823031F080E01F910F91FF90EF9054 +:10F1D0000895EE24FF2487018091C80087FD17C0A1 +:10F1E0000894E11CF11C011D111D81E4E81682E464 +:10F1F000F8068FE0080780E0180770F3E0913A0204 +:10F20000F0913B0209958091C80087FFE9CF80917A +:10F21000CE001F910F91FF90EF900895EE24FF24F0 +:10F2200087018091C00087FD17C00894E11CF11C84 +:10F23000011D111D81E4E81682E4F8068FE008073D +:10F2400080E0180770F3E0913A02F0913B020995D3 +:10F250008091C00087FFE9CF8091C6001F910F9178 +:10F26000FF90EF9008950E94D9F8982F809138026E +:10F27000813049F0823091F091366CF490330CF08B +:10F280009053892F08958091C00085FFFCCF909303 +:10F29000C60091369CF39755892F08958091C80038 +:10F2A00085FFFCCF9093CE00E7CF1F930E9433F9E8 +:10F2B000182F0E9433F91295107F810F1F91089526 +:10F2C000982F20913802992339F0213031F02230E3 +:10F2D00061F091509923C9F708958091C00087FF8C +:10F2E000FCCF8091C6009150F5CF8091C80087FF78 +:10F2F000FCCF8091CE009150EDCF1F93182F0E942C +:10F30000D9F8803249F0809139028F5F80933902B9 +:10F31000853091F11F910895809138028130B9F0C4 +:10F320008230C1F78091C80085FFFCCF84E18093D3 +:10F33000CE008091C80085FFFCCF1093CE00809155 +:10F34000C80085FFFCCF80E18093CE00E3CF8091A1 +:10F35000C00085FFFCCF84E18093C6008091C0008F +:10F3600085FFFCCF1093C6008091C00085FFFCCFC5 +:10F3700080E18093C600CECFE0913A02F0913B024B +:10F3800009951F9108950E94D9F8803241F080912B +:10F3900039028F5F80933902853029F10895809179 +:10F3A0003802813089F08230C9F78091C80085FF2A +:10F3B000FCCF84E18093CE008091C80085FFFCCF14 +:10F3C00080E18093CE0008958091C00085FFFCCF3E +:10F3D00084E18093C6008091C00085FFFCCF80E16E +:10F3E0008093C6000895E0913A02F0913B0209959E +:10F3F000089540E951E08823A1F02F9A28EE33E0E8 +:10F40000FA013197F1F721503040D1F72F9828EECB +:10F4100033E0FA013197F1F721503040D1F78150B4 +:10F4200061F708952F923F924F925F926F927F9271 +:10F430008F929F92AF92BF92CF92DF92EF92FF9204 +:10F440000F931F93CF93DF93000081E080933802E6 +:10F4500080E18093C4001092C5001092C00086E045 +:10F460008093C20088E18093C1006898709A279ABF +:10F4700081E00E94F9F9E4E1EE2E7EE1D72E67E902 +:10F48000C62E53E0B52E40E1A42E9924939431E486 +:10F49000832E26E5722E92E5692E80E2582E09E42D +:10F4A000402E13E5312EB0E52B2E0E94D9F8803383 +:10F4B000C9F1813309F452C0803409F4C8C08134E1 +:10F4C00009F4EAC0823489F1853409F4CAC0803570 +:10F4D00049F1823539F1813529F1853509F4ECC0DE +:10F4E000863509F409C1843609F428C1843709F442 +:10F4F000ABC1853709F473C2863709F4D9C08132AC +:10F5000009F4B7C2809139028F5F80933902853048 +:10F5100061F6E0913A02F0913B0209950E94D9F818 +:10F52000803339F60E94C3F9C0CF2091380293E1AD +:10F5300005C0223061F09923A9F391502130C9F719 +:10F540008091C00087FFFCCF8091C600F4CF8091EE +:10F55000C80087FFFCCF8091CE00EDCF0E94D9F884 +:10F56000803281F6809138028130D1F1823009F009 +:10F570009CCF8091C80085FFFCCFE092CE008091A7 +:10F58000C80085FFFCCF8092CE008091C80085FF27 +:10F59000FCCF7092CE008091C80085FFFCCF6092B6 +:10F5A000CE008091C80085FFFCCF5092CE008091A4 +:10F5B000C80085FFFCCF4092CE008091C80085FF37 +:10F5C000FCCF3092CE008091C80085FFFCCF209206 +:10F5D000CE008091C80085FFFCCFA092CE0065CF01 +:10F5E0008091C00085FFFCCFE092C6008091C000F2 +:10F5F00085FFFCCF8092C6008091C00085FFFCCFC4 +:10F600007092C6008091C00085FFFCCF6092C6005A +:10F610008091C00085FFFCCF5092C6008091C00051 +:10F6200085FFFCCF4092C6008091C00085FFFCCFD3 +:10F630003092C6008091C00085FFFCCF2092C600AA +:10F640008091C00085FFFCCFA092C6002ECF0E9403 +:10F65000D9F8863808F466CF0E94D9F80E94C3F919 +:10F6600024CF2091380294E0213041F0223069F01B +:10F67000992309F457CF91502130C1F78091C000F0 +:10F6800087FFFCCF8091C600F3CF8091C80087FF31 +:10F69000FCCF8091CE00ECCF0E94D9F8803841F1A8 +:10F6A000813809F447C0823809F4CAC08839E1F0CA +:10F6B00080E00E947DF9F9CE0E94D9F880933C0247 +:10F6C0000E94D9F880933D020E94C3F9EECE0E94B9 +:10F6D000D9F80E94D9F8182F0E94D9F8112309F4FB +:10F6E0007EC2113009F40AC283E00E947DF9DDCEAA +:10F6F00082E00E947DF9D9CE0E94D9F8803339F397 +:10F700002091380292E0213039F0223061F09923C3 +:10F7100079F291502130C9F78091C00087FFFCCF6A +:10F720008091C600F4CF8091C80087FFFCCF809104 +:10F73000CE00EDCF81E00E947DF9B7CE0E94D9F8CE +:10F7400080933F030E94D9F880933E038091420347 +:10F750008E7F809342030E94D9F8853409F4B3C1A7 +:10F7600080913E0390913F03892B89F000E010E0E7 +:10F770000E94D9F8F801E25CFD4F80830F5F1F4FB4 +:10F7800080913E0390913F030817190788F30E9468 +:10F79000D9F8803209F0B6CE8091420380FFB2C121 +:10F7A00040913C0250913D02440F551F50933D0241 +:10F7B00040933C0260913E0370913F0361157105D7 +:10F7C000F1F080E090E09A01280F391FFC01E25C23 +:10F7D000FD4FE081F999FECF1FBA32BD21BDE0BDDA +:10F7E0000FB6F894FA9AF99A0FBE01968617970702 +:10F7F00050F3460F571F50933D0240933C028091B7 +:10F800003802813081F0823009F04FCE8091C800FB +:10F8100085FFFCCFE092CE008091C80085FFFCCF31 +:10F82000A092CE0042CE8091C00085FFFCCFE09236 +:10F83000C6008091C00085FFFCCFA092C60035CEE7 +:10F8400080E10E947DF931CE0E94D9F880933F0378 +:10F850000E94D9F880933E0320913C0230913D02F2 +:10F8600037FD46C1809142038D7F80934203220F72 +:10F87000331F30933D0220933C020E94D9F8853417 +:10F8800009F430C1809142038E7F809342030E942D +:10F89000D9F8803209F009CE60913802613009F45C +:10F8A0006FC0623009F473C000913E0310913F03B2 +:10F8B0000115110509F440C080914203782F717041 +:10F8C000F82EF69481E0F82240913C0250913D02DE +:10F8D00020E030E013C0FF2009F060C0FA019491ED +:10F8E000613009F43BC0623009F441C0CA0101969D +:10F8F0002F5F3F4FAC0120173107D0F4772359F326 +:10F90000F999FECF52BD41BDF89A90B56130F9F03A +:10F91000623061F78091C80085FFFCCF9093CE00E4 +:10F92000CA0101962F5F3F4FAC012017310730F31A +:10F9300090933D0280933C02613009F4CAC062306A +:10F9400009F0B3CD8091C80085FFFCCF46CE8091F1 +:10F95000C00085FFFCCF9093C600C8CF8091C00047 +:10F9600085FDF9CF8091C00085FFF8CFF4CF80915D +:10F97000C80085FDD3CF8091C80085FFF8CFCECFDA +:10F980008091C00085FFFCCFE092C6008DCF8091B2 +:10F99000C80085FFFCCFE092CE0086CFCA01A0E070 +:10F9A000B0E080509040AF4FBF4FABBFFC0197918C +:10F9B000613061F0623009F099CF8091C80085FD17 +:10F9C000ADCF8091C80085FFF8CFA8CF8091C0004F +:10F9D00085FDC1CF8091C00085FFF8CFBCCF0E94CC +:10F9E000D9F8803209F08ECD80913802813011F142 +:10F9F000823009F05ACD8091C80085FFFCCFE0929B +:10FA0000CE008091C80085FFFCCFD092CE008091BF +:10FA1000C80085FFFCCFC092CE008091C80085FF52 +:10FA2000FCCFB092CE008091C80085FFFCCFA092A1 +:10FA3000CE003BCD8091C00085FFFCCFE092C60098 +:10FA40008091C00085FFFCCFD092C6008091C0009D +:10FA500085FFFCCFC092C6008091C00085FFFCCF1F +:10FA6000B092C6008091C00085FFFCCFA092C60076 +:10FA70001CCD0E94D9F8813209F017CD0E94D9F827 +:10FA8000813209F012CD279A2F98109240032091CD +:10FA90003802E1E491E00EC0223009F4A4C0909352 +:10FAA0004003E92FF0E0E050FE4FE0819F5FEE233E +:10FAB00009F4A0C0213081F78091C00085FFFCCF00 +:10FAC000E093C600ECCF80914203816080934203B3 +:10FAD00047CE8091C00085FDB7CD8091C00085FFE5 +:10FAE000F8CFB2CD80914203816080934203CFCEA4 +:10FAF00080914203826080934203B9CE87E90E94DD +:10FB00007DF9D3CC80913D028823880F880B892111 +:10FB1000809341038BBF80913C0290913D02880FFE +:10FB2000991F90933D0280933C0280913E0380FF99 +:10FB300009C080913E0390913F03019690933F034B +:10FB400080933E03F894F999FECF1127E0913C028F +:10FB5000F0913D02CEE3D2E080913E0390913F03CD +:10FB6000103091F40091570001700130D9F303E097 +:10FB700000935700E8950091570001700130D9F3C8 +:10FB800001E100935700E895099019900091570002 +:10FB900001700130D9F301E000935700E895139507 +:10FBA000103898F011270091570001700130D9F3F7 +:10FBB00005E000935700E89500915700017001306F +:10FBC000D9F301E100935700E8953296029709F0C6 +:10FBD000C7CF103011F00296E5CF112410CE8EE180 +:10FBE0000E947DF962CC8091C80085FFFCCFE09334 +:10FBF000CE0055CF7AE0B72E6DE0A62E5AE3952EB3 +:10FC000040E2842E3DE3732E90E3692E81E3582E6B +:10FC1000213009F442C0223009F45FC00E94D9F8B3 +:10FC2000982F20913802213089F1223009F44EC0FA +:10FC3000943709F46BC0923709F405C1973709F47A +:10FC40007BC0953799F0923609F4BDC09A3601F71A +:10FC5000E0913A02F0913B02099520913802D8CF09 +:10FC60008091C00085FFFCCF9093C6000E94D9F818 +:10FC7000982F80913802813099F38230B9F78091C2 +:10FC8000C80085FFFCCF9093CE00F0CF8091C000DC +:10FC900085FFFCCF9093C600CBCF8091C00085FF3D +:10FCA000FCCFB092C6008091C00085FFFCCFA0922F +:10FCB000C6008091C00085FFFCCF9092C600809165 +:10FCC000C00085FFFCCF8092C600A8CF8091C800FD +:10FCD00085FFFCCF9093CE00ABCF8091C80085FF0D +:10FCE000FCCFB092CE008091C80085FFFCCFA092DF +:10FCF000CE008091C80085FFFCCF9092CE0080910D +:10FD0000C80085FFFCCF8092CE0088CF1F9947C0E6 +:10FD10002F9A213051F0223009F07ACF8091C8001B +:10FD200085FFFCCF6092CE0073CF8091C00085FF2D +:10FD3000FCCF6092C6006CCF0E94D9F8982F8091BA +:10FD400038028130F1F0823009F4ABC00E9455F9DD +:10FD5000082F0E9455F9182F0E94D9F8982F8091EA +:10FD600038028130A9F0823009F4A2C00E9455F90E +:10FD7000D02ECC24F601E10FF11D808320913802B2 +:10FD800047CF8091C00085FFFCCF9093C600DECFA7 +:10FD90008091C00085FFFCCF9093C600E7CF2F98DD +:10FDA000213051F0223009F033CF8091C80085FF17 +:10FDB000FCCF5092CE002CCF8091C00085FFFCCFAD +:10FDC0005092C60025CF213041F1223081F080E8E9 +:10FDD00085BF109274001092750080E091E1FC01E3 +:10FDE000819180E091E13097D1F3CF01F8CF8091FC +:10FDF000C80085FFFCCF82E68093CE008091C800CA +:10FE000085FFFCCF85E78093CE008091C80085FFF9 +:10FE1000FCCF83E78093CE00DACF8091C00085FFCE +:10FE2000FCCF82E68093C6008091C00085FFFCCFA6 +:10FE300085E78093C6008091C00085FFFCCF83E7F3 +:10FE40008093C600C4CF0E94D9F8982F80913802C1 +:10FE50008130C9F08230D1F10E9455F9182F0E94EB +:10FE600055F9982F809138028130A1F0823039F114 +:10FE7000F12EEE24F701E90FF11D80810E9494F824 +:10FE800020913802C5CE8091C00085FFFCCF9093B1 +:10FE9000C600E2CF8091C00085FFFCCF7092C60003 +:10FEA000E7CF8091C80085FFFCCF9093CE004ECF66 +:10FEB0008091C80085FFFCCF9093CE0057CF8091F2 +:10FEC000C80085FFFCCF7092CE00D2CF8091C800D1 +:0EFED00085FFFCCF9093CE00BFCFF894FFCFFC +:10FEDE0041546D656761424F4F54202F204172642B +:10FEEE0075696E6F204D656761202D20284329208E +:10FEFE0041726475696E6F204C4C43202D20303951 +:08FF0E00303933300A0D008088 +:040000031000F000F9 +:00000001FF diff --git a/arduino-0018-linux/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_atmega328.hex b/arduino-0018-linux/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_atmega328.hex new file mode 100644 index 0000000..43a8b30 --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_atmega328.hex @@ -0,0 +1,125 @@ +:107800000C94343C0C94513C0C94513C0C94513CE1 +:107810000C94513C0C94513C0C94513C0C94513CB4 +:107820000C94513C0C94513C0C94513C0C94513CA4 +:107830000C94513C0C94513C0C94513C0C94513C94 +:107840000C94513C0C94513C0C94513C0C94513C84 +:107850000C94513C0C94513C0C94513C0C94513C74 +:107860000C94513C0C94513C11241FBECFEFD8E036 +:10787000DEBFCDBF11E0A0E0B1E0ECE9FFE702C060 +:1078800005900D92A230B107D9F712E0A2E0B1E065 +:1078900001C01D92AD30B107E1F70E942D3D0C945F +:1078A000CC3F0C94003C982F959595959595959582 +:1078B000905D8F708A307CF0282F295A8091C0000B +:1078C00085FFFCCF9093C6008091C00085FFFCCF60 +:1078D0002093C6000895282F205DF0CF982F809127 +:1078E000C00085FFFCCF9093C6000895EF92FF92F1 +:1078F0000F931F93EE24FF2487018091C00087FD22 +:1079000017C00894E11CF11C011D111D81E4E8164B +:1079100082E4F8068FE0080780E0180770F3E09132 +:107920000401F091050109958091C00087FFE9CF1E +:107930008091C6001F910F91FF90EF9008950E94D3 +:10794000763C982F8091C00085FFFCCF9093C600B5 +:1079500091362CF490330CF09053892F089597555D +:10796000892F08951F930E949F3C182F0E949F3CCF +:107970001295107F810F1F9108951F93182F882350 +:1079800021F00E94763C1150E1F71F9108951F935A +:10799000182F0E94763C803249F0809103018F5F5E +:1079A000809303018530C1F01F9108958091C0003C +:1079B00085FFFCCF84E18093C6008091C00085FFE5 +:1079C000FCCF1093C6008091C00085FFFCCF80E102 +:1079D0008093C6001F910895E0910401F091050184 +:1079E00009951F9108950E94763C803241F0809164 +:1079F00003018F5F80930301853081F008958091AA +:107A0000C00085FFFCCF84E18093C6008091C00058 +:107A100085FFFCCF80E18093C6000895E0910401CA +:107A2000F09105010995089540E951E08823A1F0FE +:107A30002D9A28EE33E0FA013197F1F721503040CA +:107A4000D1F72D9828EE33E0FA013197F1F7215064 +:107A50003040D1F7815061F708953F924F925F9285 +:107A60006F927F928F929F92AF92BF92CF92DF924E +:107A7000EF92FF920F931F93CF93DF93000080E16B +:107A80008093C4001092C50088E18093C10086E015 +:107A90008093C2005098589A259A81E00E94143D24 +:107AA00024E1F22E9EE1E92E85E9D82E0FE0C02ECA +:107AB00010E1B12EAA24A394B1E49B2EA6E58A2E50 +:107AC000F2E57F2EE0E26E2E79E4572E63E5462E36 +:107AD00050E5352E0E94763C8033B1F18133B9F107 +:107AE000803409F46FC0813409F476C0823409F41B +:107AF00085C0853409F488C0803531F1823521F1A3 +:107B0000813511F1853509F485C0863509F48DC0BC +:107B1000843609F496C0843709F403C1853709F423 +:107B200072C1863709F466C0809103018F5F80932C +:107B30000301853079F6E0910401F0910501099582 +:107B40000E94763C803351F60E94F33CC3CF0E94E2 +:107B5000763C803249F78091C00085FFFCCFF092DF +:107B6000C6008091C00085FFFCCF9092C600809136 +:107B7000C00085FFFCCF8092C6008091C00085FFC9 +:107B8000FCCF7092C6008091C00085FFFCCF609250 +:107B9000C6008091C00085FFFCCF5092C600809146 +:107BA000C00085FFFCCF4092C6008091C00085FFD9 +:107BB000FCCF3092C6008091C00085FFFCCFB09210 +:107BC000C60088CF0E94763C863808F4BDCF0E945C +:107BD000763C0E94F33C7ECF0E94763C803809F4CC +:107BE0009CC0813809F40BC1823809F43CC1883942 +:107BF00009F48FC080E00E94C73C6CCF84E10E94F2 +:107C0000BD3C0E94F33C66CF85E00E94BD3C0E94D3 +:107C1000F33C60CF0E94763C809306010E94763C44 +:107C2000809307010E94F33C55CF0E94763C80333D +:107C300009F41DC183E00E94BD3C80E00E94C73C66 +:107C400049CF0E94763C809309020E94763C809343 +:107C5000080280910C028E7F80930C020E94763C79 +:107C6000853409F415C18091080290910902892B8D +:107C700089F000E010E00E94763CF801E85FFE4FDA +:107C800080830F5F1F4F80910802909109020817AF +:107C9000190788F30E94763C803209F045CF809125 +:107CA0000C0280FF01C16091060170910701660F0F +:107CB000771F7093070160930601A0910802B091AD +:107CC00009021097C9F0E8E0F1E09B01AD014E0F09 +:107CD0005F1FF999FECF32BD21BD819180BDFA9A17 +:107CE000F99A2F5F3F4FE417F50799F76A0F7B1F4B +:107CF00070930701609306018091C00085FFFCCF5F +:107D0000F092C6008091C00085FFFCCFB092C60003 +:107D1000E1CE83E00E94C73CDDCE82E00E94C73CFA +:107D2000D9CE0E94763C809309020E94763C8093D3 +:107D300008028091060190910701880F991F909386 +:107D40000701809306010E94763C853409F4A6C0A1 +:107D500080910C028E7F80930C020E94763C8032D0 +:107D600009F0B8CE8091C00085FFFCCFF092C6002C +:107D7000609108027091090261157105B9F140E046 +:107D800050E080910C02A82FA170B82FB27011C0E2 +:107D9000BB2309F45CC0E0910601F0910701319624 +:107DA000F0930701E09306014F5F5F4F46175707B7 +:107DB000E8F4AA2369F3F999FECF209106013091E6 +:107DC000070132BD21BDF89A90B58091C00085FFB2 +:107DD000FCCF9093C6002F5F3F4F30930701209355 +:107DE00006014F5F5F4F4617570718F38091C00099 +:107DF00085FDE5CE8091C00085FFF8CFE0CE81E023 +:107E00000E94C73C67CE0E94763C803209F08CCE3F +:107E10008091C00085FFFCCFF092C6008091C00029 +:107E200085FFFCCFE092C6008091C00085FFFCCFAB +:107E3000D092C6008091C00085FFFCCFC092C600E2 +:107E40008091C00085FFFCCFB092C60043CEE09188 +:107E50000601F091070194918091C00085FFFCCF4D +:107E60009093C6009CCF80E10E94C73C33CE0E9415 +:107E7000763C0E94763C182F0E94763C112309F430 +:107E800083C0113009F484C08FE00E94C73C22CE29 +:107E900080910C02816080930C02E5CE80910C02EF +:107EA000816080930C0259CF809107018823880F4D +:107EB000880B8A2180930B02809106019091070123 +:107EC000880F991F90930701809306018091080203 +:107ED00080FF09C080910802909109020196909359 +:107EE000090280930802F894F999FECF1127E091D6 +:107EF0000601F0910701C8E0D1E08091080290915D +:107F00000902103091F40091570001700130D9F34B +:107F100003E000935700E89500915700017001308D +:107F2000D9F301E100935700E89509901990009169 +:107F3000570001700130D9F301E000935700E89534 +:107F40001395103498F011270091570001700130FB +:107F5000D9F305E000935700E895009157000170B0 +:107F60000130D9F301E100935700E895329602976A +:107F700009F0C7CF103011F00296E5CF112480919F +:107F8000C00085FFB9CEBCCE8EE10E94C73CA2CD19 +:0C7F900085E90E94C73C9ECDF894FFCF0D +:027F9C00800063 +:040000030000780081 +:00000001FF diff --git a/arduino-0018-linux/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex b/arduino-0018-linux/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex new file mode 100644 index 0000000..9753e2e --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex @@ -0,0 +1,124 @@ +:107800000C94343C0C94513C0C94513C0C94513CE1 +:107810000C94513C0C94513C0C94513C0C94513CB4 +:107820000C94513C0C94513C0C94513C0C94513CA4 +:107830000C94513C0C94513C0C94513C0C94513C94 +:107840000C94513C0C94513C0C94513C0C94513C84 +:107850000C94513C0C94513C0C94513C0C94513C74 +:107860000C94513C0C94513C11241FBECFEFD8E036 +:10787000DEBFCDBF11E0A0E0B1E0EAE8FFE702C063 +:1078800005900D92A230B107D9F712E0A2E0B1E065 +:1078900001C01D92AD30B107E1F70E942D3D0C945F +:1078A000C33F0C94003C982F95959595959595958B +:1078B000905D8F708A307CF0282F295A8091C0000B +:1078C00085FFFCCF9093C6008091C00085FFFCCF60 +:1078D0002093C6000895282F205DF0CF982F809127 +:1078E000C00085FFFCCF9093C6000895EF92FF92F1 +:1078F0000F931F93EE24FF2487018091C00087FD22 +:1079000017C00894E11CF11C011D111D81E2E8164D +:1079100081EAF80687E0080780E0180770F3E09135 +:107920000401F091050109958091C00087FFE9CF1E +:107930008091C6001F910F91FF90EF9008950E94D3 +:10794000763C982F8091C00085FFFCCF9093C600B5 +:1079500091362CF490330CF09053892F089597555D +:10796000892F08951F930E949F3C182F0E949F3CCF +:107970001295107F810F1F9108951F93182F882350 +:1079800021F00E94763C1150E1F71F9108951F935A +:10799000182F0E94763C803249F0809103018F5F5E +:1079A000809303018530C1F01F9108958091C0003C +:1079B00085FFFCCF84E18093C6008091C00085FFE5 +:1079C000FCCF1093C6008091C00085FFFCCF80E102 +:1079D0008093C6001F910895E0910401F091050184 +:1079E00009951F9108950E94763C803241F0809164 +:1079F00003018F5F80930301853081F008958091AA +:107A0000C00085FFFCCF84E18093C6008091C00058 +:107A100085FFFCCF80E18093C6000895E0910401CA +:107A2000F09105010995089548EC50E08823A1F0F4 +:107A30002D9A28EE33E0FA013197F1F721503040CA +:107A4000D1F72D9828EE33E0FA013197F1F7215064 +:107A50003040D1F7815061F708953F924F925F9285 +:107A60006F927F928F929F92AF92BF92CF92DF924E +:107A7000EF92FF920F931F93CF93DF93000082E06A +:107A80008093C00080E18093C4001092C50088E11B +:107A90008093C10086E08093C2005098589A259A3E +:107AA00081E00E94143D24E1F22E9EE1E92E85E959 +:107AB000D82E0FE0C02E10E1B12EAA24A394B1E479 +:107AC0009B2EA6E58A2EF2E57F2EE0E26E2E79E46B +:107AD000572E63E5462E50E5352E0E94763C8033C6 +:107AE000B1F18133B9F1803409F46FC0813409F404 +:107AF00076C0823409F485C0853409F488C08035A5 +:107B000031F1823521F1813511F1853509F485C0D6 +:107B1000863509F48DC0843609F496C0843709F49B +:107B200003C1853709F472C1863709F466C08091B4 +:107B300003018F5F80930301853079F6E0910401A2 +:107B4000F091050109950E94763C803351F60E9420 +:107B5000F33CC3CF0E94763C803249F78091C0004D +:107B600085FFFCCFF092C6008091C00085FFFCCF5E +:107B70009092C6008091C00085FFFCCF8092C60025 +:107B80008091C00085FFFCCF7092C6008091C0003C +:107B900085FFFCCF6092C6008091C00085FFFCCFBE +:107BA0005092C6008091C00085FFFCCF4092C60075 +:107BB0008091C00085FFFCCF3092C6008091C0004C +:107BC00085FFFCCFB092C60088CF0E94763C8638F5 +:107BD00008F4BDCF0E94763C0E94F33C7ECF0E9409 +:107BE000763C803809F49CC0813809F40BC1823896 +:107BF00009F430C1883909F48FC080E00E94C73C85 +:107C00006CCF84E10E94BD3C0E94F33C66CF85E0CE +:107C10000E94BD3C0E94F33C60CF0E94763C809362 +:107C200006010E94763C809307010E94F33C55CFE9 +:107C30000E94763C803309F411C183E00E94BD3C70 +:107C400080E00E94C73C49CF0E94763C80930902A5 +:107C50000E94763C8093080280910C028E7F809374 +:107C60000C020E94763C853409F409C18091080217 +:107C700090910902892B89F000E010E00E94763C87 +:107C8000F801E85FFE4F80830F5F1F4F809108026D +:107C9000909109020817190788F30E94763C8032F8 +:107CA00009F045CF80910C0280FFF5C0609106017C +:107CB00070910701660F771F7093070160930601AB +:107CC000A0910802B09109021097C9F0E8E0F1E034 +:107CD0009B01AD014E0F5F1FF999FECF32BD21BD53 +:107CE000819180BDFA9AF99A2F5F3F4FE417F5070B +:107CF00099F76A0F7B1F70930701609306018091CB +:107D0000C00085FFFCCFF092C6008091C00085FFC7 +:107D1000FCCFB092C600E1CE83E00E94C73CDDCE2E +:107D200082E00E94C73CD9CE0E94763C8093090233 +:107D30000E94763C80930802809106019091070191 +:107D4000880F991F90930701809306010E94763C4B +:107D5000853409F49AC080910C028E7F80930C02C6 +:107D60000E94763C803209F0B8CE8091C00085FF39 +:107D7000FCCFF092C600A0910802B09109021097C2 +:107D8000C1F180910C02082F0170182F1695117007 +:107D9000E0910601F0910701AF014F5F5F4FBA011B +:107DA00020E030E00023B1F4112339F49491809164 +:107DB000C00085FFFCCF9093C6002F5F3F4FCB01E3 +:107DC0000196FA012A173B0780F4BC014F5F5F4F11 +:107DD000002351F3F999FECFF2BDE1BDF89A90B5B9 +:107DE0008091C00085FFFCCFE6CF709307016093C0 +:107DF00006018091C00085FDE5CE8091C00085FF21 +:107E0000F8CFE0CE81E00E94C73C67CE0E94763C6E +:107E1000803209F08CCE8091C00085FFFCCFF092BB +:107E2000C6008091C00085FFFCCFE092C600809123 +:107E3000C00085FFFCCFD092C6008091C00085FFB6 +:107E4000FCCFC092C6008091C00085FFFCCFB092ED +:107E5000C60043CE80E10E94C73C3FCE0E94763CE4 +:107E60000E94763C182F0E94763C112309F483C0AF +:107E7000113009F484C08FE00E94C73C2ECE80915F +:107E80000C02816080930C02F1CE80910C02816023 +:107E900080930C0265CF809107018823880F880B9F +:107EA0008A2180930B028091060190910701880F2F +:107EB000991F90930701809306018091080280FF2B +:107EC00009C08091080290910902019690930902DD +:107ED00080930802F894F999FECF1127E0910601EA +:107EE000F0910701C8E0D1E0809108029091090269 +:107EF000103091F40091570001700130D9F303E084 +:107F000000935700E8950091570001700130D9F3B4 +:107F100001E100935700E8950990199000915700EE +:107F200001700130D9F301E000935700E8951395F3 +:107F3000103498F011270091570001700130D9F3E7 +:107F400005E000935700E89500915700017001305B +:107F5000D9F301E100935700E8953296029709F0B2 +:107F6000C7CF103011F00296E5CF11248091C000E8 +:107F700085FFC5CEC8CE8EE10E94C73CAECD85E957 +:0A7F80000E94C73CAACDF894FFCF81 +:027F8A00800075 +:040000030000780081 +:00000001FF diff --git a/arduino-0018-linux/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_diecimila.hex b/arduino-0018-linux/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_diecimila.hex new file mode 100644 index 0000000..feac9d2 --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_diecimila.hex @@ -0,0 +1,126 @@ +:103800000C94341C0C94511C0C94511C0C94511CA1 +:103810000C94511C0C94511C0C94511C0C94511C74 +:103820000C94511C0C94511C0C94511C0C94511C64 +:103830000C94511C0C94511C0C94511C0C94511C54 +:103840000C94511C0C94511C0C94511C0C94511C44 +:103850000C94511C0C94511C0C94511C0C94511C34 +:103860000C94511C0C94511C11241FBECFEFD4E0BA +:10387000DEBFCDBF11E0A0E0B1E0E4EAFFE302C0AB +:1038800005900D92A230B107D9F712E0A2E0B1E0A5 +:1038900001C01D92AD30B107E1F70E94361D0C94B6 +:1038A000D01F0C94001C982F9595959595959595FE +:1038B000905D8F708A307CF0282F295A8091C0004B +:1038C00085FFFCCF9093C6008091C00085FFFCCFA0 +:1038D0002093C6000895282F205DF0CF982F809167 +:1038E000C00085FFFCCF9093C6000895EF92FF9231 +:1038F0000F931F93EE24FF2487018091C00087FD62 +:1039000017C00894E11CF11C011D111D81E4E8168B +:1039100082E4F8068FE0080780E0180770F3E09172 +:103920000401F091050109958091C00087FFE9CF5E +:103930008091C6001F910F91FF90EF9008950E9413 +:10394000761C982F8091C00085FFFCCF9093C60015 +:1039500091362CF490330CF09053892F089597559D +:10396000892F08951F930E949F1C182F0E949F1C4F +:103970001295107F810F1F910895882351F0982F81 +:1039800091508091C00087FFFCCF8091C6009923A1 +:10399000B9F708951F93182F0E94761C803249F0C2 +:1039A000809103018F5F809303018530C1F01F91E7 +:1039B00008958091C00085FFFCCF84E18093C6000C +:1039C0008091C00085FFFCCF1093C6008091C0009D +:1039D00085FFFCCF80E18093C6001F910895E091A0 +:1039E0000401F091050109951F9108950E94761C2C +:1039F000803241F0809103018F5F80930301853015 +:103A000081F008958091C00085FFFCCF84E1809310 +:103A1000C6008091C00085FFFCCF80E18093C60086 +:103A20000895E0910401F09105010995089510921F +:103A30000A028823D1F090E040E951E02D9A28EE67 +:103A400033E0FA013197F1F721503040D1F72D984A +:103A500028EE33E0FA013197F1F721503040D1F7E9 +:103A60009F5F981758F380930A0208953F924F92F0 +:103A70005F926F927F928F929F92AF92BF92CF92FE +:103A8000DF92EF92FF920F931F93CF93DF9300008B +:103A900083E38093C4001092C50088E18093C10045 +:103AA00086E08093C2005098589A259A81E00E943F +:103AB000171D44E1F42E3EE1E32E24E9D22E96E0D8 +:103AC000C92E80E1B82EAA24A39401E4902E16E515 +:103AD000812EB2E57B2EA0E26A2EF9E45F2EE3E5AB +:103AE0004E2E70E5372E0E94761C8033B1F1813363 +:103AF00009F441C0803409F479C0813409F48CC0E0 +:103B0000823471F1853409F47BC0803531F182351E +:103B100021F1813511F1853509F48DC0863509F41F +:103B20009DC0843609F4AEC0843709F41BC18537C3 +:103B300009F485C1863709F47AC0809103018F5F4B +:103B400080930301853079F6E0910401F09105013D +:103B500009950E94761C803351F60E94F61CC3CF53 +:103B600093E18091C00087FFFCCF8091C60099232C +:103B7000A1F39150F6CF0E94761C8032F1F680912D +:103B8000C00085FFFCCFF092C6008091C00085FF89 +:103B9000FCCF9092C6008091C00085FFFCCF809240 +:103BA000C6008091C00085FFFCCF7092C600809156 +:103BB000C00085FFFCCF6092C6008091C00085FFE9 +:103BC000FCCF5092C6008091C00085FFFCCF409290 +:103BD000C6008091C00085FFFCCF3092C600809166 +:103BE000C00085FFFCCFB092C6007DCF0E94761C3E +:103BF000863808F4B2CF0E94761C0E94F61C73CF60 +:103C000094E08091C00087FFFCCF8091C60099238B +:103C100009F4A3CF9150F5CF0E94761C8038D1F0E3 +:103C2000813861F1823809F499C0883979F080E0EF +:103C30000E94CA1C58CF0E94761C809306010E94E5 +:103C4000761C809307010E94F61C4DCF83E00E94F2 +:103C5000CA1C49CF82E00E94CA1C45CF0E94761C34 +:103C6000803309F486C192E08091C00087FFFCCFC9 +:103C70008091C6009923D9F29150F6CF81E00E943D +:103C8000CA1C31CF0E94761C809309020E94761CC8 +:103C90008093080280910C028E7F80930C020E9418 +:103CA000761C853429F480910C02816080930C028B +:103CB0008091080290910902892B89F000E010E0C0 +:103CC0000E94761CF801E85FFE4F80830F5F1F4F54 +:103CD00080910802909109020817190788F30E9441 +:103CE000761C803209F029CF80910C0280FFD1C070 +:103CF0004091060150910701440F551F5093070151 +:103D000040930601A0910802B09109021097C9F0F2 +:103D1000E8E0F1E09A01BD016E0F7F1FF999FECF37 +:103D200032BD21BD819180BDFA9AF99A2F5F3F4F34 +:103D3000E617F70799F74A0F5B1F50930701409367 +:103D400006018091C00085FFFCCFF092C6008091F3 +:103D5000C00085FFFCCFB092C600C5CE80E10E94B6 +:103D6000CA1CC1CE0E94761C809309020E94761C58 +:103D7000809308028091060190910701880F991F96 +:103D800090930701809306010E94761C853409F404 +:103D90007AC080910C028E7F80930C020E94761C68 +:103DA000803209F0A0CE8091C00085FFFCCFF09258 +:103DB000C600A0910802B09109021097B9F1809154 +:103DC0000C02182F1170082F0270E0910601F0917B +:103DD00007019F012F5F3F4FB90140E050E01123E1 +:103DE000B1F4002339F494918091C00085FFFCCF99 +:103DF0009093C6004F5F5F4FCB010196F9014A17C0 +:103E00005B0780F4BC012F5F3F4F112351F3F999F9 +:103E1000FECFF2BDE1BDF89A90B58091C00085FF5C +:103E2000FCCFE6CF70930701609306018091C0003C +:103E300085FDD9CE8091C00085FFF8CFD4CE0E94F9 +:103E4000761C803209F079CE8091C00085FFFCCFCE +:103E5000F092C6008091C00085FFFCCFE092C600C2 +:103E60008091C00085FFFCCFD092C6008091C00039 +:103E700085FFFCCFC092C6008091C00085FFFCCFBB +:103E8000B092C60030CE80910C02816080930C020B +:103E900085CF809107018823880F880B8A21809322 +:103EA0000B028091060190910701880F991F909352 +:103EB0000701809306018091080280FF09C080916C +:103EC00008029091090201969093090280930802DA +:103ED000F894F999FECF1127E0910601F0910701BE +:103EE000C8E0D1E08091080290910902103091F46D +:103EF0000091570001700130D9F303E0009357009F +:103F0000E8950091570001700130D9F301E1009369 +:103F10005700E89509901990009157000170013001 +:103F2000D9F301E000935700E8951395103498F009 +:103F300011270091570001700130D9F305E000937B +:103F40005700E8950091570001700130D9F301E165 +:103F500000935700E8953296029709F0C7CF1030CA +:103F600011F00296E5CF11248091C00085FFE9CEC3 +:103F7000ECCE0E94761C0E94761C182F0E94761CA4 +:103F8000112351F0113021F086E00E94CA1CABCD04 +:103F900084E90E94CA1CA7CD8EE10E94CA1CA3CD51 +:043FA000F894FFCFC3 +:023FA40080009B +:0400000300003800C1 +:00000001FF diff --git a/arduino-0018-linux/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_ng.hex b/arduino-0018-linux/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_ng.hex new file mode 100644 index 0000000..387091e --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_ng.hex @@ -0,0 +1,110 @@ +:103800000C94341C0C94511C0C94511C0C94511CA1 +:103810000C94511C0C94511C0C94511C0C94511C74 +:103820000C94511C0C94511C0C94511C0C94511C64 +:103830000C94511C0C94511C0C94511C0C94511C54 +:103840000C94511C0C94511C0C94511C0C94511C44 +:103850000C94511C0C94511C0C94511C0C94511C34 +:103860000C94511C0C94511C11241FBECFEFD4E0BA +:10387000DEBFCDBF11E0A0E0B1E0E4EAFEE302C0AC +:1038800005900D92A230B107D9F712E0A2E0B1E0A5 +:1038900001C01D92AD30B107E1F70E94ED1C0C9400 +:1038A000511F0C94001C482F10920A0280E08417CC +:1038B000E0F4582F2D9A28EE33E080E991E001974B +:1038C000F1F721503040C9F72D9828EE33E080E918 +:1038D00091E00197F1F721503040C9F7852F8F5FB4 +:1038E000582F841738F380930A020895EF92FF92BD +:1038F0000F931F93EE24FF2487018091C00087FD62 +:1039000017C00894E11CF11C011D111D81E0E8168F +:1039100082E1F8068AE7080780E0180770F3E09173 +:103920000201F091030109958091C00087FFE9CF62 +:103930008091C600992787FD90951F910F91FF9068 +:10394000EF900895982F8091C00085FFFCCF909351 +:10395000C60008950E94761C803271F080910401A7 +:103960008F5F80930401853009F00895E091020192 +:10397000F09103010995089584E10E94A21C80E161 +:103980000E94A21C0895CF93C82F0E94761C8032FB +:1039900041F0809104018F5F80930401853081F4B0 +:1039A0000AC084E10E94A21C8C2F0E94A21C80E10C +:1039B0000E94A21C05C0E0910201F091030109954B +:1039C000CF910895CF93C82FC150CF3F21F00E94CF +:1039D000761CC150E0F7CF910895CFEFD4E0DEBF61 +:1039E000CDBF000083E38093C4001092C50088E13E +:1039F0008093C10086E08093C2005098589A259A1F +:103A000083E00E94531C0E94761C8033B1F1813305 +:103A1000B9F1803409F455C0813409F45BC08234B3 +:103A200009F46DC0853409F470C0803531F18235F8 +:103A300021F1813511F1853509F46BC0863509F422 +:103A400073C0843609F47AC0843709F4CEC0853750 +:103A500009F429C1863709F44AC0809104018F5FB7 +:103A600080930401853079F6E0910201F091030121 +:103A700009950E94761C803351F60E94AA1CC3CF80 +:103A80000E94761CC82F803241F784E10E94A21C5C +:103A900081E40E94A21C86E50E94A21C82E50E948D +:103AA000A21C8C2F0E94A21C89E40E94A21C83E508 +:103AB0000E94A21C80E50E94A21C80E10E94A21C20 +:103AC000A2CF0E94761C8638C0F20E94761C0E940B +:103AD000AA1C99CF0E94761C803809F486C18138CF +:103AE00009F487C1823809F488C1883921F080E05F +:103AF0000E94C31C88CF83E00E94C31C84CF84E152 +:103B00000E94E21C0E94AA1C7ECF85E00E94E21C5B +:103B1000F9CF0E94761C809306010E94761C809348 +:103B200007010E94AA1C6FCF0E94761C803309F403 +:103B3000CAC083E00E94E21C80E0DACF0E94761CBB +:103B4000809309020E94761C8093080280910C02E7 +:103B50008E7F80930C020E94761C853409F4C4C0C9 +:103B600000E010E0809108029091090218161906F1 +:103B700070F4C8E0D1E00E94761C89930F5F1F4F5C +:103B8000809108029091090208171907A0F30E947A +:103B9000761C803209F061CF80910C0280FFAEC0AC +:103BA000E0910601F0910701EE0FFF1F00E010E029 +:103BB00020910802309109021216130680F4A8E041 +:103BC000B1E0F999FECFF2BDE1BD8D9180BDFA9AC9 +:103BD000F99A31960F5F1F4F0217130790F3F09376 +:103BE0000701E093060184E166CF0E94761C809372 +:103BF00009020E94761C8093080280910601909130 +:103C00000701880F991F90930701809306010E9476 +:103C1000761C853409F46EC080910C028E7F8093EF +:103C20000C020E94761C803209F0EDCE84E10E94E5 +:103C3000A21C00E010E02091080230910902121647 +:103C4000130608F03ACFE0910601F0910701809148 +:103C50000C0280FF1FC0F999FECFF2BDE1BDF89ABA +:103C600080B50E94A21CE0910601F09107013196F7 +:103C7000F0930701E09306012091080230910902B8 +:103C80000F5F1F4F0217130708F017CF80910C0228 +:103C900080FDE1CF869580FFB4C03196F093070197 +:103CA000E0930601EDCF0E94761C803209F0D5CE5C +:103CB00084E10E94A21C8EE10E94A21C84E90E9461 +:103CC000A21C86E0F8CE0E94761C0E94761CC82FAB +:103CD0000E94761CCC2309F47CC0C13009F47DC05D +:103CE00086E00E94C31C8FCE80910C02816080937D +:103CF0000C0236CF80910C02816091CF8091070138 +:103D000087FD6FC010920B02809106019091070110 +:103D1000880F991F909307018093060180910802F4 +:103D200080FF09C08091080290910902019690934A +:103D3000090280930802F894F999FECF1127E091C7 +:103D40000601F0910701C8E0D1E08091080290914E +:103D50000902103091F40091570001700130D9F33D +:103D600003E000935700E89500915700017001307F +:103D7000D9F301E100935700E8950990199000915B +:103D8000570001700130D9F301E000935700E89526 +:103D90001395103498F011270091570001700130ED +:103DA000D9F305E000935700E895009157000170A2 +:103DB0000130D9F301E100935700E895329602975C +:103DC00009F0C7CF103011F00296E5CF112484E13D +:103DD00072CE8EE10E94C31C16CE84E90E94C31CE1 +:103DE00012CE81E080930B028FCF82E00E94C31C31 +:103DF0000ACE81E00E94C31C06CE80E10E94C31C53 +:103E000002CE84910E94A21C2091080230910902E6 +:103E1000E0910601F091070140CFCF930E94761CFC +:103E2000C82F0E94A21CC13614F0C75503C0C0336E +:103E30000CF0C0538C2F992787FD9095CF91089552 +:103E40000F931F930E940D1F082F112707FD109538 +:103E500002951295107F1027007F10270E940D1FDA +:103E6000800F992787FD90951F910F910895CF930B +:103E7000C82F85958595859585958A3034F0895A22 +:103E8000CF70CA3034F0C95A05C0805DCF70CA30D7 +:103E9000D4F7C05D0E94A21C8C2F0E94A21CCF915F +:043EA0000895FFCFB3 +:023EA40080009C +:0400000300003800C1 +:00000001FF diff --git a/arduino-0018-linux/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_pro_8MHz.hex b/arduino-0018-linux/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_pro_8MHz.hex new file mode 100644 index 0000000..994e478 --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_pro_8MHz.hex @@ -0,0 +1,126 @@ +:103800000C94341C0C94511C0C94511C0C94511CA1 +:103810000C94511C0C94511C0C94511C0C94511C74 +:103820000C94511C0C94511C0C94511C0C94511C64 +:103830000C94511C0C94511C0C94511C0C94511C54 +:103840000C94511C0C94511C0C94511C0C94511C44 +:103850000C94511C0C94511C0C94511C0C94511C34 +:103860000C94511C0C94511C11241FBECFEFD4E0BA +:10387000DEBFCDBF11E0A0E0B1E0EEEAFFE302C0A1 +:1038800005900D92A230B107D9F712E0A2E0B1E0A5 +:1038900001C01D92AD30B107E1F70E94331D0C94B9 +:1038A000D51F0C94001C982F9595959595959595F9 +:1038B000905D8F708A307CF0282F295A8091C0004B +:1038C00085FFFCCF9093C6008091C00085FFFCCFA0 +:1038D0002093C6000895282F205DF0CF982F809167 +:1038E000C00085FFFCCF9093C6000895EF92FF9231 +:1038F0000F931F93EE24FF2487018091C00087FD62 +:1039000017C00894E11CF11C011D111D81E2E8168D +:1039100081EAF80687E0080780E0180770F3E09175 +:103920000401F091050109958091C00087FFE9CF5E +:103930008091C6001F910F91FF90EF9008950E9413 +:10394000761C982F8091C00085FFFCCF9093C60015 +:1039500091362CF490330CF09053892F089597559D +:10396000892F08951F930E949F1C182F0E949F1C4F +:103970001295107F810F1F9108951F93182F882390 +:1039800021F00E94761C1150E1F71F9108951F93BA +:10399000182F0E94761C803249F0809103018F5FBE +:1039A000809303018530C1F01F9108958091C0007C +:1039B00085FFFCCF84E18093C6008091C00085FF25 +:1039C000FCCF1093C6008091C00085FFFCCF80E142 +:1039D0008093C6001F910895E0910401F0910501C4 +:1039E00009951F9108950E94761C803241F08091C4 +:1039F00003018F5F80930301853081F008958091EA +:103A0000C00085FFFCCF84E18093C6008091C00098 +:103A100085FFFCCF80E18093C6000895E09104010A +:103A2000F09105010995089510920A028823D1F0BA +:103A300090E048EC50E02D9A28EE33E0FA013197FF +:103A4000F1F721503040D1F72D9828EE33E0FA01FC +:103A50003197F1F721503040D1F79F5F981758F315 +:103A600080930A0208953F924F925F926F927F92E5 +:103A70008F929F92AF92BF92CF92DF92EF92FF927E +:103A80000F931F93CF93DF9394B714BE8091600080 +:103A90008861809360001092600091FF0CC289E100 +:103AA0008093C4001092C50088E18093C10086E035 +:103AB0008093C2005098589A259A81E00E94141D64 +:103AC00044E1F42E3EE1E32E24E9D22E96E0C92E05 +:103AD00080E1B82EAA24A39401E4902E16E5812E4D +:103AE000B2E57B2EA0E26A2EF9E45F2EE3E54E2ECE +:103AF00070E5372E0E94761C8033B9F18133C1F115 +:103B0000803409F470C0813409F477C0823409F438 +:103B100086C0853409F489C0803539F1823529F1B0 +:103B2000813509F4AFC1853509F485C0863509F4BE +:103B30008DC0843609F435C1843709F4C1C0853796 +:103B400009F490C0863709F466C0809103018F5F45 +:103B500080930301853071F6E0910401F091050135 +:103B600009950E94761C803349F60E94F31CC2CF4F +:103B70000E94761C803249F78091C00085FFFCCFFF +:103B8000F092C6008091C00085FFFCCF9092C600E5 +:103B90008091C00085FFFCCF8092C6008091C0005C +:103BA00085FFFCCF7092C6008091C00085FFFCCFDE +:103BB0006092C6008091C00085FFFCCF5092C60085 +:103BC0008091C00085FFFCCF4092C6008091C0006C +:103BD00085FFFCCF3092C6008091C00085FFFCCFEE +:103BE000B092C60087CF0E94761C863808F4BDCFFD +:103BF0000E94761C0E94F31C7DCF0E94761C8038A8 +:103C000009F45AC0813809F453C0823809F440C11C +:103C1000883909F449C080E00E94C71C6BCF84E159 +:103C20000E94BD1C0E94F31C65CF85E00E94BD1C54 +:103C30000E94F31C5FCF0E94761C809306010E94B5 +:103C4000761C809307010E94F31C54CF0E94761CBF +:103C5000803309F421C183E00E94BD1C80E00E94F2 +:103C6000C71C48CF0E94761C803209F06ECF80912D +:103C7000C00085FFFCCFF092C6008091C00085FF98 +:103C8000FCCFE092C6008091C00085FFFCCFD092AF +:103C9000C6008091C00085FFFCCFC092C600809115 +:103CA000C00085FFFCCF9CCF83E00E94C71C22CFC1 +:103CB00081E00E94C71C1ECF82E00E94C71C1ACF61 +:103CC0000E94761C809309020E94761C8093080251 +:103CD0008091060190910701880F991F9093070129 +:103CE000809306010E94761C853409F4C5C080913A +:103CF0000C028E7F80930C020E94761C803209F0A9 +:103D0000F9CE8091C00085FFFCCFF092C600609193 +:103D10000802709109026115710591F140E050E0CF +:103D200080910C02A82FA170B82FB27010C0BB23D5 +:103D300061F1E0910601F09107013196F0930701DE +:103D4000E09306014F5F5F4F46175707C8F4AA2359 +:103D500071F3F999FECF209106013091070132BD30 +:103D600021BDF89A90B58091C00085FFFCCF90935B +:103D7000C6002F5F3F4F3093070120930601E2CF2B +:103D80008091C00085FFFCCF2BCFE0910601F09120 +:103D9000070194918091C00085FFFCCF9093C600ED +:103DA000CCCF0E94761C809309020E94761C8093DF +:103DB000080280910C028E7F80930C020E94761C78 +:103DC000853429F480910C02816080930C028091EB +:103DD000080290910902892B89F000E010E00E940E +:103DE000761CF801E85FFE4F80830F5F1F4F8091C4 +:103DF0000802909109020817190788F30E94761C9F +:103E0000803209F0A2CE80910C0280FF62C0409106 +:103E1000060150910701440F551F5093070140932D +:103E20000601609108027091090261157105C9F0DF +:103E3000E8E0F1E09A01DB01AE0FBF1FF999FECF78 +:103E400032BD21BD819180BDFA9AF99A2F5F3F4F13 +:103E5000EA17FB0799F7460F571F50930701409346 +:103E600006018091C00085FFFCCFF092C6008091D2 +:103E7000C00085FFFCCFB4CE80910C02816080939E +:103E80000C023ACF0E94F31C88E080936000FFCFC1 +:103E900080E10E94C71C2ECE0E94761C0E94761CD8 +:103EA000182F0E94761C112381F0113051F086E00A +:103EB0000E94C71C1FCEE0910401F09105010995F5 +:103EC000EECD84E90E94C71C15CE8EE10E94C71C6E +:103ED00011CE809107018823880F880B8A21809357 +:103EE0000B028091060190910701880F991F909312 +:103EF0000701809306018091080280FF09C080912C +:103F00000802909109020196909309028093080299 +:103F1000F894F999FECF1127E0910601F09107017D +:103F2000C8E0D1E08091080290910902103091F42C +:103F30000091570001700130D9F303E0009357005E +:103F4000E8950091570001700130D9F301E1009329 +:103F50005700E895099019900091570001700130C1 +:103F6000D9F301E000935700E8951395103498F0C9 +:103F700011270091570001700130D9F305E000933B +:103F80005700E8950091570001700130D9F301E125 +:103F900000935700E8953296029709F0C7CF10308A +:0E3FA00011F00296E5CF11245CCFF894FFCF0C +:023FAE00800091 +:0400000300003800C1 +:00000001FF diff --git a/arduino-0018-linux/hardware/arduino/bootloaders/atmega/Makefile b/arduino-0018-linux/hardware/arduino/bootloaders/atmega/Makefile new file mode 100755 index 0000000..0fd54db --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/bootloaders/atmega/Makefile @@ -0,0 +1,224 @@ +# Makefile for ATmegaBOOT +# E.Lins, 18.7.2005 +# $Id$ +# +# Instructions +# +# To make bootloader .hex file: +# make diecimila +# make lilypad +# make ng +# etc... +# +# To burn bootloader .hex file: +# make diecimila_isp +# make lilypad_isp +# make ng_isp +# etc... + +# program name should not be changed... +PROGRAM = ATmegaBOOT_168 + +# enter the parameters for the avrdude isp tool +ISPTOOL = stk500v2 +ISPPORT = usb +ISPSPEED = -b 115200 + +MCU_TARGET = atmega168 +LDSECTION = --section-start=.text=0x3800 + +# the efuse should really be 0xf8; since, however, only the lower +# three bits of that byte are used on the atmega168, avrdude gets +# confused if you specify 1's for the higher bits, see: +# http://tinker.it/now/2007/02/24/the-tale-of-avrdude-atmega168-and-extended-bits-fuses/ +# +# similarly, the lock bits should be 0xff instead of 0x3f (to +# unlock the bootloader section) and 0xcf instead of 0x0f (to +# lock it), but since the high two bits of the lock byte are +# unused, avrdude would get confused. + +ISPFUSES = avrdude -c $(ISPTOOL) -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \ +-e -u -U lock:w:0x3f:m -U efuse:w:0x$(EFUSE):m -U hfuse:w:0x$(HFUSE):m -U lfuse:w:0x$(LFUSE):m +ISPFLASH = avrdude -c $(ISPTOOL) -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \ +-U flash:w:$(PROGRAM)_$(TARGET).hex -U lock:w:0x0f:m + +STK500 = "C:\Program Files\Atmel\AVR Tools\STK500\Stk500.exe" +STK500-1 = $(STK500) -e -d$(MCU_TARGET) -pf -vf -if$(PROGRAM)_$(TARGET).hex \ +-lFF -LFF -f$(HFUSE)$(LFUSE) -EF8 -ms -q -cUSB -I200kHz -s -wt +STK500-2 = $(STK500) -d$(MCU_TARGET) -ms -q -lCF -LCF -cUSB -I200kHz -s -wt + + +OBJ = $(PROGRAM).o +OPTIMIZE = -O2 + +DEFS = +LIBS = + +CC = avr-gcc + +# Override is only needed by avr-lib build system. + +override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) -DF_CPU=$(AVR_FREQ) $(DEFS) +override LDFLAGS = -Wl,$(LDSECTION) +#override LDFLAGS = -Wl,-Map,$(PROGRAM).map,$(LDSECTION) + +OBJCOPY = avr-objcopy +OBJDUMP = avr-objdump + +all: + +lilypad: TARGET = lilypad +lilypad: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>1' '-DNUM_LED_FLASHES=3' +lilypad: AVR_FREQ = 8000000L +lilypad: $(PROGRAM)_lilypad.hex + +lilypad_isp: lilypad +lilypad_isp: TARGET = lilypad +lilypad_isp: HFUSE = DD +lilypad_isp: LFUSE = E2 +lilypad_isp: EFUSE = 00 +lilypad_isp: isp + +lilypad_resonator: TARGET = lilypad_resonator +lilypad_resonator: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=3' +lilypad_resonator: AVR_FREQ = 8000000L +lilypad_resonator: $(PROGRAM)_lilypad_resonator.hex + +lilypad_resonator_isp: lilypad_resonator +lilypad_resonator_isp: TARGET = lilypad_resonator +lilypad_resonator_isp: HFUSE = DD +lilypad_resonator_isp: LFUSE = C6 +lilypad_resonator_isp: EFUSE = 00 +lilypad_resonator_isp: isp + +pro8: TARGET = pro_8MHz +pro8: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' '-DWATCHDOG_MODS' +pro8: AVR_FREQ = 8000000L +pro8: $(PROGRAM)_pro_8MHz.hex + +pro8_isp: pro8 +pro8_isp: TARGET = pro_8MHz +pro8_isp: HFUSE = DD +pro8_isp: LFUSE = C6 +pro8_isp: EFUSE = 00 +pro8_isp: isp + +pro16: TARGET = pro_16MHz +pro16: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' '-DWATCHDOG_MODS' +pro16: AVR_FREQ = 16000000L +pro16: $(PROGRAM)_pro_16MHz.hex + +pro16_isp: pro16 +pro16_isp: TARGET = pro_16MHz +pro16_isp: HFUSE = DD +pro16_isp: LFUSE = C6 +pro16_isp: EFUSE = 00 +pro16_isp: isp + +pro20: TARGET = pro_20mhz +pro20: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' '-DWATCHDOG_MODS' +pro20: AVR_FREQ = 20000000L +pro20: $(PROGRAM)_pro_20mhz.hex + +pro20_isp: pro20 +pro20_isp: TARGET = pro_20mhz +pro20_isp: HFUSE = DD +pro20_isp: LFUSE = C6 +pro20_isp: EFUSE = 00 +pro20_isp: isp + +diecimila: TARGET = diecimila +diecimila: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' +diecimila: AVR_FREQ = 16000000L +diecimila: $(PROGRAM)_diecimila.hex + +diecimila_isp: diecimila +diecimila_isp: TARGET = diecimila +diecimila_isp: HFUSE = DD +diecimila_isp: LFUSE = FF +diecimila_isp: EFUSE = 00 +diecimila_isp: isp + +ng: TARGET = ng +ng: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>1' '-DNUM_LED_FLASHES=3' +ng: AVR_FREQ = 16000000L +ng: $(PROGRAM)_ng.hex + +ng_isp: ng +ng_isp: TARGET = ng +ng_isp: HFUSE = DD +ng_isp: LFUSE = FF +ng_isp: EFUSE = 00 +ng_isp: isp + +atmega328: TARGET = atmega328 +atmega328: MCU_TARGET = atmega328p +atmega328: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' -DBAUD_RATE=57600 +atmega328: AVR_FREQ = 16000000L +atmega328: LDSECTION = --section-start=.text=0x7800 +atmega328: $(PROGRAM)_atmega328.hex + +atmega328_isp: atmega328 +atmega328_isp: TARGET = atmega328 +atmega328_isp: MCU_TARGET = atmega328p +atmega328_isp: HFUSE = DA +atmega328_isp: LFUSE = FF +atmega328_isp: EFUSE = 05 +atmega328_isp: isp + +atmega328_pro8: TARGET = atmega328_pro_8MHz +atmega328_pro8: MCU_TARGET = atmega328p +atmega328_pro8: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' -DBAUD_RATE=57600 -DDOUBLE_SPEED +atmega328_pro8: AVR_FREQ = 8000000L +atmega328_pro8: LDSECTION = --section-start=.text=0x7800 +atmega328_pro8: $(PROGRAM)_atmega328_pro_8MHz.hex + +atmega328_pro8_isp: atmega328_pro8 +atmega328_pro8_isp: TARGET = atmega328_pro_8MHz +atmega328_pro8_isp: MCU_TARGET = atmega328p +atmega328_pro8_isp: HFUSE = DA +atmega328_pro8_isp: LFUSE = FF +atmega328_pro8_isp: EFUSE = 05 +atmega328_pro8_isp: isp + +mega: TARGET = atmega1280 +mega: MCU_TARGET = atmega1280 +mega: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=0' -DBAUD_RATE=57600 +mega: AVR_FREQ = 16000000L +mega: LDSECTION = --section-start=.text=0x1F000 +mega: $(PROGRAM)_atmega1280.hex + +mega_isp: mega +mega_isp: TARGET = atmega1280 +mega_isp: MCU_TARGET = atmega1280 +mega_isp: HFUSE = DA +mega_isp: LFUSE = FF +mega_isp: EFUSE = F5 +mega_isp: isp + +isp: $(TARGET) + $(ISPFUSES) + $(ISPFLASH) + +isp-stk500: $(PROGRAM)_$(TARGET).hex + $(STK500-1) + $(STK500-2) + +%.elf: $(OBJ) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) + +clean: + rm -rf *.o *.elf *.lst *.map *.sym *.lss *.eep *.srec *.bin *.hex + +%.lst: %.elf + $(OBJDUMP) -h -S $< > $@ + +%.hex: %.elf + $(OBJCOPY) -j .text -j .data -O ihex $< $@ + +%.srec: %.elf + $(OBJCOPY) -j .text -j .data -O srec $< $@ + +%.bin: %.elf + $(OBJCOPY) -j .text -j .data -O binary $< $@ + diff --git a/arduino-0018-linux/hardware/arduino/bootloaders/atmega8/ATmegaBOOT.c b/arduino-0018-linux/hardware/arduino/bootloaders/atmega8/ATmegaBOOT.c new file mode 100755 index 0000000..17977e6 --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/bootloaders/atmega8/ATmegaBOOT.c @@ -0,0 +1,507 @@ +/**********************************************************/ +/* Serial Bootloader for Atmel mega8 AVR Controller */ +/* */ +/* ATmegaBOOT.c */ +/* */ +/* Copyright (c) 2003, Jason P. Kyle */ +/* */ +/* Hacked by DojoCorp - ZGZ - MMX - IVR */ +/* Hacked by David A. Mellis */ +/* */ +/* This program is free software; you can redistribute it */ +/* and/or modify it under the terms of the GNU General */ +/* Public License as published by the Free Software */ +/* Foundation; either version 2 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* This program is distributed in the hope that it will */ +/* be useful, but WITHOUT ANY WARRANTY; without even the */ +/* implied warranty of MERCHANTABILITY or FITNESS FOR A */ +/* PARTICULAR PURPOSE. See the GNU General Public */ +/* License for more details. */ +/* */ +/* You should have received a copy of the GNU General */ +/* Public License along with this program; if not, write */ +/* to the Free Software Foundation, Inc., */ +/* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/* */ +/* Licence can be viewed at */ +/* http://www.fsf.org/licenses/gpl.txt */ +/* */ +/* Target = Atmel AVR m8 */ +/**********************************************************/ + +#include +#include +#include +#include +#include +#include + +//#define F_CPU 16000000 + +/* We, Malmoitians, like slow interaction + * therefore the slow baud rate ;-) + */ +//#define BAUD_RATE 9600 + +/* 6.000.000 is more or less 8 seconds at the + * speed configured here + */ +//#define MAX_TIME_COUNT 6000000 +#define MAX_TIME_COUNT (F_CPU>>1) +///#define MAX_TIME_COUNT_MORATORY 1600000 + +/* SW_MAJOR and MINOR needs to be updated from time to time to avoid warning message from AVR Studio */ +#define HW_VER 0x02 +#define SW_MAJOR 0x01 +#define SW_MINOR 0x12 + +// AVR-GCC compiler compatibility +// avr-gcc compiler v3.1.x and older doesn't support outb() and inb() +// if necessary, convert outb and inb to outp and inp +#ifndef outb + #define outb(sfr,val) (_SFR_BYTE(sfr) = (val)) +#endif +#ifndef inb + #define inb(sfr) _SFR_BYTE(sfr) +#endif + +/* defines for future compatibility */ +#ifndef cbi + #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) +#endif +#ifndef sbi + #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) +#endif + +/* Adjust to suit whatever pin your hardware uses to enter the bootloader */ +#define eeprom_rb(addr) eeprom_read_byte ((uint8_t *)(addr)) +#define eeprom_rw(addr) eeprom_read_word ((uint16_t *)(addr)) +#define eeprom_wb(addr, val) eeprom_write_byte ((uint8_t *)(addr), (uint8_t)(val)) + +/* Onboard LED is connected to pin PB5 */ +#define LED_DDR DDRB +#define LED_PORT PORTB +#define LED_PIN PINB +#define LED PINB5 + + +#define SIG1 0x1E // Yep, Atmel is the only manufacturer of AVR micros. Single source :( +#define SIG2 0x93 +#define SIG3 0x07 +#define PAGE_SIZE 0x20U //32 words + + +void putch(char); +char getch(void); +void getNch(uint8_t); +void byte_response(uint8_t); +void nothing_response(void); + +union address_union { + uint16_t word; + uint8_t byte[2]; +} address; + +union length_union { + uint16_t word; + uint8_t byte[2]; +} length; + +struct flags_struct { + unsigned eeprom : 1; + unsigned rampz : 1; +} flags; + +uint8_t buff[256]; +//uint8_t address_high; + +uint8_t pagesz=0x80; + +uint8_t i; +//uint8_t bootuart0=0,bootuart1=0; + + +void (*app_start)(void) = 0x0000; + +int main(void) +{ + uint8_t ch,ch2; + uint16_t w; + + //cbi(BL_DDR,BL); + //sbi(BL_PORT,BL); + + asm volatile("nop\n\t"); + + /* check if flash is programmed already, if not start bootloader anyway */ + //if(pgm_read_byte_near(0x0000) != 0xFF) { + + /* check if bootloader pin is set low */ + //if(bit_is_set(BL_PIN,BL)) app_start(); + //} + + /* initialize UART(s) depending on CPU defined */ + /* m8 */ + UBRRH = (((F_CPU/BAUD_RATE)/16)-1)>>8; // set baud rate + UBRRL = (((F_CPU/BAUD_RATE)/16)-1); + UCSRB = (1<> 8; + //UCSRA = 0x00; + //UCSRC = 0x86; + //UCSRB = _BV(TXEN)|_BV(RXEN); + + + /* this was giving uisp problems, so I removed it; without it, the boot + works on with uisp and avrdude on the mac (at least). */ + //putch('\0'); + + //uint32_t l; + //uint32_t time_count; + //time_count=0; + + /* set LED pin as output */ + sbi(LED_DDR,LED); + for (i = 0; i < 16; i++) { + outb(LED_PORT, inb(LED_PORT) ^ _BV(LED)); + _delay_loop_2(0); + } + + //for (l=0; l<40000000; l++) + //outb(LED_PORT, inb(LED_PORT) ^= _BV(LED)); + + /* flash onboard LED three times to signal entering of bootloader */ + //for(i=0; i<3; ++i) { + //for(l=0; l<40000000; ++l); + //sbi(LED_PORT,LED); + //for(l=0; l<40000000; ++l); + //cbi(LED_PORT,LED); + //} + + /* see comment at previous call to putch() */ + //putch('\0'); // this line is needed for the synchronization of the programmer + + /* forever */ + for (;;) { + //if((inb(UCSRA) & _BV(RXC))){ + /* get character from UART */ + ch = getch(); + + /* A bunch of if...else if... gives smaller code than switch...case ! */ + + /* Hello is anyone home ? */ + if(ch=='0') { + nothing_response(); + } + + /* Request programmer ID */ + /* Not using PROGMEM string due to boot block in m128 being beyond 64kB boundry */ + /* Would need to selectively manipulate RAMPZ, and it's only 9 characters anyway so who cares. */ + else if(ch=='1') { + if (getch() == ' ') { + putch(0x14); + putch('A'); + putch('V'); + putch('R'); + putch(' '); + putch('I'); + putch('S'); + putch('P'); + putch(0x10); + } + } + + /* AVR ISP/STK500 board commands DON'T CARE so default nothing_response */ + else if(ch=='@') { + ch2 = getch(); + if (ch2>0x85) getch(); + nothing_response(); + } + + /* AVR ISP/STK500 board requests */ + else if(ch=='A') { + ch2 = getch(); + if(ch2==0x80) byte_response(HW_VER); // Hardware version + else if(ch2==0x81) byte_response(SW_MAJOR); // Software major version + else if(ch2==0x82) byte_response(SW_MINOR); // Software minor version + //else if(ch2==0x98) byte_response(0x03); // Unknown but seems to be required by avr studio 3.56 + else byte_response(0x00); // Covers various unnecessary responses we don't care about + } + + /* Device Parameters DON'T CARE, DEVICE IS FIXED */ + else if(ch=='B') { + getNch(20); + nothing_response(); + } + + /* Parallel programming stuff DON'T CARE */ + else if(ch=='E') { + getNch(5); + nothing_response(); + } + + /* Enter programming mode */ + else if(ch=='P') { + nothing_response(); + // FIXME: modified only here by DojoCorp, Mumbai, India, 20050626 + //time_count=0; // exted the delay once entered prog.mode + } + + /* Leave programming mode */ + else if(ch=='Q') { + nothing_response(); + //time_count=MAX_TIME_COUNT_MORATORY; // once the programming is done, + // we should start the application + // but uisp has problems with this, + // therefore we just change the times + // and give the programmer 1 sec to react + } + + /* Erase device, don't care as we will erase one page at a time anyway. */ + else if(ch=='R') { + nothing_response(); + } + + /* Set address, little endian. EEPROM in bytes, FLASH in words */ + /* Perhaps extra address bytes may be added in future to support > 128kB FLASH. */ + /* This might explain why little endian was used here, big endian used everywhere else. */ + else if(ch=='U') { + address.byte[0] = getch(); + address.byte[1] = getch(); + nothing_response(); + } + + /* Universal SPI programming command, disabled. Would be used for fuses and lock bits. */ + else if(ch=='V') { + getNch(4); + byte_response(0x00); + } + + /* Write memory, length is big endian and is in bytes */ + else if(ch=='d') { + length.byte[1] = getch(); + length.byte[0] = getch(); + flags.eeprom = 0; + if (getch() == 'E') flags.eeprom = 1; + for (w=0;w127) address_high = 0x01; //Only possible with m128, m256 will need 3rd address byte. FIXME + //else address_high = 0x00; + + //address.word = address.word << 1; //address * 2 -> byte location + //if ((length.byte[0] & 0x01)) length.word++; //Even up an odd number of bytes + cli(); //Disable interrupts, just to be sure + while(bit_is_set(EECR,EEWE)); //Wait for previous EEPROM writes to complete + asm volatile( + "clr r17 \n\t" //page_word_count + "lds r30,address \n\t" //Address of FLASH location (in words) + "lds r31,address+1 \n\t" + "lsl r30 \n\t" //address * 2 -> byte location + "rol r31 \n\t" + "ldi r28,lo8(buff) \n\t" //Start of buffer array in RAM + "ldi r29,hi8(buff) \n\t" + "lds r24,length \n\t" //Length of data to be written (in bytes) + "lds r25,length+1 \n\t" + "sbrs r24,0 \n\t" //Even up an odd number of bytes + "rjmp length_loop \n\t" + "adiw r24,1 \n\t" + "length_loop: \n\t" //Main loop, repeat for number of words in block + "cpi r17,0x00 \n\t" //If page_word_count=0 then erase page + "brne no_page_erase \n\t" + "rcall wait_spm \n\t" +// "wait_spm1: \n\t" +// "lds r16,%0 \n\t" //Wait for previous spm to complete +// "andi r16,1 \n\t" +// "cpi r16,1 \n\t" +// "breq wait_spm1 \n\t" + "ldi r16,0x03 \n\t" //Erase page pointed to by Z + "sts %0,r16 \n\t" + "spm \n\t" + "rcall wait_spm \n\t" +// "wait_spm2: \n\t" +// "lds r16,%0 \n\t" //Wait for previous spm to complete +// "andi r16,1 \n\t" +// "cpi r16,1 \n\t" +// "breq wait_spm2 \n\t" + "ldi r16,0x11 \n\t" //Re-enable RWW section + "sts %0,r16 \n\t" + "spm \n\t" + "no_page_erase: \n\t" + "ld r0,Y+ \n\t" //Write 2 bytes into page buffer + "ld r1,Y+ \n\t" + + "rcall wait_spm \n\t" +// "wait_spm3: \n\t" +// "lds r16,%0 \n\t" //Wait for previous spm to complete +// "andi r16,1 \n\t" +// "cpi r16,1 \n\t" +// "breq wait_spm3 \n\t" + "ldi r16,0x01 \n\t" //Load r0,r1 into FLASH page buffer + "sts %0,r16 \n\t" + "spm \n\t" + + "inc r17 \n\t" //page_word_count++ + "cpi r17,%1 \n\t" + "brlo same_page \n\t" //Still same page in FLASH + "write_page: \n\t" + "clr r17 \n\t" //New page, write current one first + "rcall wait_spm \n\t" +// "wait_spm4: \n\t" +// "lds r16,%0 \n\t" //Wait for previous spm to complete +// "andi r16,1 \n\t" +// "cpi r16,1 \n\t" +// "breq wait_spm4 \n\t" + "ldi r16,0x05 \n\t" //Write page pointed to by Z + "sts %0,r16 \n\t" + "spm \n\t" + "rcall wait_spm \n\t" +// "wait_spm5: \n\t" +// "lds r16,%0 \n\t" //Wait for previous spm to complete +// "andi r16,1 \n\t" +// "cpi r16,1 \n\t" +// "breq wait_spm5 \n\t" + "ldi r16,0x11 \n\t" //Re-enable RWW section + "sts %0,r16 \n\t" + "spm \n\t" + "same_page: \n\t" + "adiw r30,2 \n\t" //Next word in FLASH + "sbiw r24,2 \n\t" //length-2 + "breq final_write \n\t" //Finished + "rjmp length_loop \n\t" + + "wait_spm: \n\t" + "lds r16,%0 \n\t" //Wait for previous spm to complete + "andi r16,1 \n\t" + "cpi r16,1 \n\t" + "breq wait_spm \n\t" + "ret \n\t" + + "final_write: \n\t" + "cpi r17,0 \n\t" + "breq block_done \n\t" + "adiw r24,2 \n\t" //length+2, fool above check on length after short page write + "rjmp write_page \n\t" + "block_done: \n\t" + "clr __zero_reg__ \n\t" //restore zero register + : "=m" (SPMCR) : "M" (PAGE_SIZE) : "r0","r16","r17","r24","r25","r28","r29","r30","r31"); + + /* Should really add a wait for RWW section to be enabled, don't actually need it since we never */ + /* exit the bootloader without a power cycle anyhow */ + } + putch(0x14); + putch(0x10); + } + } + + /* Read memory block mode, length is big endian. */ + else if(ch=='t') { + length.byte[1] = getch(); + length.byte[0] = getch(); + if (getch() == 'E') flags.eeprom = 1; + else { + flags.eeprom = 0; + address.word = address.word << 1; // address * 2 -> byte location + } + if (getch() == ' ') { // Command terminator + putch(0x14); + for (w=0;w < length.word;w++) { // Can handle odd and even lengths okay + if (flags.eeprom) { // Byte access EEPROM read + putch(eeprom_rb(address.word)); + address.word++; + } else { + if (!flags.rampz) putch(pgm_read_byte_near(address.word)); + address.word++; + } + } + putch(0x10); + } + } + + /* Get device signature bytes */ + else if(ch=='u') { + if (getch() == ' ') { + putch(0x14); + putch(SIG1); + putch(SIG2); + putch(SIG3); + putch(0x10); + } + } + + /* Read oscillator calibration byte */ + else if(ch=='v') { + byte_response(0x00); + } +// } else { +// time_count++; +// if (time_count>=MAX_TIME_COUNT) { +// app_start(); +// } +// } + } /* end of forever loop */ +} + +void putch(char ch) +{ + /* m8 */ + while (!(inb(UCSRA) & _BV(UDRE))); + outb(UDR,ch); +} + +char getch(void) +{ + /* m8 */ + uint32_t count = 0; + while(!(inb(UCSRA) & _BV(RXC))) { + /* HACKME:: here is a good place to count times*/ + count++; + if (count > MAX_TIME_COUNT) + app_start(); + } + return (inb(UDR)); +} + +void getNch(uint8_t count) +{ + uint8_t i; + for(i=0;i $@ + +size: $(PROGRAM).hex + $(SIZE) $^ + +# Rules for building the .text rom images + +text: hex bin srec + +hex: $(PROGRAM).hex +bin: $(PROGRAM).bin +srec: $(PROGRAM).srec + +%.hex: %.elf + $(OBJCOPY) -j .text -j .data -O ihex $< $@ + +%.srec: %.elf + $(OBJCOPY) -j .text -j .data -O srec $< $@ + +%.bin: %.elf + $(OBJCOPY) -j .text -j .data -O binary $< $@ diff --git a/arduino-0018-linux/hardware/arduino/bootloaders/bt/ATmegaBOOT_168.c b/arduino-0018-linux/hardware/arduino/bootloaders/bt/ATmegaBOOT_168.c new file mode 100644 index 0000000..a85dc9a --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/bootloaders/bt/ATmegaBOOT_168.c @@ -0,0 +1,1032 @@ +/**********************************************************/ +/* Serial Bootloader for Atmel megaAVR Controllers */ +/* */ +/* tested with ATmega8, ATmega128 and ATmega168 */ +/* should work with other mega's, see code for details */ +/* */ +/* ATmegaBOOT.c */ +/* */ +/* build: 050815 */ +/* date : 15.08.2005 */ +/* */ +/* 20060802: hacked for Arduino by D. Cuartielles */ +/* based on a previous hack by D. Mellis */ +/* and D. Cuartielles */ +/* */ +/* Monitor and debug functions were added to the original */ +/* code by Dr. Erik Lins, chip45.com. (See below) */ +/* */ +/* Thanks to Karl Pitrich for fixing a bootloader pin */ +/* problem and more informative LED blinking! */ +/* */ +/* For the latest version see: */ +/* http://www.chip45.com/ */ +/* */ +/* ------------------------------------------------------ */ +/* */ +/* based on stk500boot.c */ +/* Copyright (c) 2003, Jason P. Kyle */ +/* All rights reserved. */ +/* see avr1.org for original file and information */ +/* */ +/* This program is free software; you can redistribute it */ +/* and/or modify it under the terms of the GNU General */ +/* Public License as published by the Free Software */ +/* Foundation; either version 2 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* This program is distributed in the hope that it will */ +/* be useful, but WITHOUT ANY WARRANTY; without even the */ +/* implied warranty of MERCHANTABILITY or FITNESS FOR A */ +/* PARTICULAR PURPOSE. See the GNU General Public */ +/* License for more details. */ +/* */ +/* You should have received a copy of the GNU General */ +/* Public License along with this program; if not, write */ +/* to the Free Software Foundation, Inc., */ +/* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/* */ +/* Licence can be viewed at */ +/* http://www.fsf.org/licenses/gpl.txt */ +/* */ +/* Target = Atmel AVR m128,m64,m32,m16,m8,m162,m163,m169, */ +/* m8515,m8535. ATmega161 has a very small boot block so */ +/* isn't supported. */ +/* */ +/* Tested with m128,m8,m163 - feel free to let me know */ +/* how/if it works for you. */ +/* */ +/**********************************************************/ + + +/* some includes */ +#include +#include +#include +#include +#include + + +#define set_output(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) +#define set_input(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) + + +#define high(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) +#define low(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) + + + + +/* the current avr-libc eeprom functions do not support the ATmega168 */ +/* own eeprom write/read functions are used instead */ +#ifndef __AVR_ATmega168__ +#include +#endif + +/* define F_CPU according to AVR_FREQ set in Makefile */ +/* Is there a better way to pass such a parameter from Makefile to source code ? */ + +#define F_CPU 16000000L + +#include + + +/* 20060803: hacked by DojoCorp */ +/* set the waiting time for the bootloader */ +#define MAX_TIME_COUNT (F_CPU>>1) + +/* set the UART baud rate */ +/* 20060803: hacked by DojoCorp */ +#define BAUD_RATE 115200 + + +/* SW_MAJOR and MINOR needs to be updated from time to time to avoid warning message from AVR Studio */ +/* never allow AVR Studio to do an update !!!! */ +#define HW_VER 0x02 +#define SW_MAJOR 0x01 +#define SW_MINOR 0x0f + + +/* Adjust to suit whatever pin your hardware uses to enter the bootloader */ +/* ATmega128 has two UARTS so two pins are used to enter bootloader and select UART */ +/* BL0... means UART0, BL1... means UART1 */ +#ifdef __AVR_ATmega128__ +#define BL_DDR DDRF +#define BL_PORT PORTF +#define BL_PIN PINF +#define BL0 PINF7 +#define BL1 PINF6 +#else +/* other ATmegas have only one UART, so only one pin is defined to enter bootloader */ +#define BL_DDR DDRD +#define BL_PORT PORTD +#define BL_PIN PIND +#define BL PIND6 +#endif + + +/* onboard LED is used to indicate, that the bootloader was entered (3x flashing) */ +/* if monitor functions are included, LED goes on after monitor was entered */ +#ifdef __AVR_ATmega128__ +/* Onboard LED is connected to pin PB7 (e.g. Crumb128, PROBOmega128, Savvy128) */ +#define LED_DDR DDRB +#define LED_PORT PORTB +#define LED_PIN PINB +#define LED PINB7 +#else +/* Onboard LED is connected to pin PB2 (e.g. Crumb8, Crumb168) */ +#define LED_DDR DDRB +#define LED_PORT PORTB +#define LED_PIN PINB +/* 20060803: hacked by DojoCorp, LED pin is B5 in Arduino */ +/* #define LED PINB2 */ +#define LED PINB5 +#endif + + +/* monitor functions will only be compiled when using ATmega128, due to bootblock size constraints */ +#ifdef __AVR_ATmega128__ +#define MONITOR +#endif + + +/* define various device id's */ +/* manufacturer byte is always the same */ +#define SIG1 0x1E // Yep, Atmel is the only manufacturer of AVR micros. Single source :( + +#if defined __AVR_ATmega128__ +#define SIG2 0x97 +#define SIG3 0x02 +#define PAGE_SIZE 0x80U //128 words + +#elif defined __AVR_ATmega64__ +#define SIG2 0x96 +#define SIG3 0x02 +#define PAGE_SIZE 0x80U //128 words + +#elif defined __AVR_ATmega32__ +#define SIG2 0x95 +#define SIG3 0x02 +#define PAGE_SIZE 0x40U //64 words + +#elif defined __AVR_ATmega16__ +#define SIG2 0x94 +#define SIG3 0x03 +#define PAGE_SIZE 0x40U //64 words + +#elif defined __AVR_ATmega8__ +#define SIG2 0x93 +#define SIG3 0x07 +#define PAGE_SIZE 0x20U //32 words + +#elif defined __AVR_ATmega88__ +#define SIG2 0x93 +#define SIG3 0x0a +#define PAGE_SIZE 0x20U //32 words + +#elif defined __AVR_ATmega168__ +#define SIG2 0x94 +#define SIG3 0x06 +#define PAGE_SIZE 0x40U //64 words + +#elif defined __AVR_ATmega162__ +#define SIG2 0x94 +#define SIG3 0x04 +#define PAGE_SIZE 0x40U //64 words + +#elif defined __AVR_ATmega163__ +#define SIG2 0x94 +#define SIG3 0x02 +#define PAGE_SIZE 0x40U //64 words + +#elif defined __AVR_ATmega169__ +#define SIG2 0x94 +#define SIG3 0x05 +#define PAGE_SIZE 0x40U //64 words + +#elif defined __AVR_ATmega8515__ +#define SIG2 0x93 +#define SIG3 0x06 +#define PAGE_SIZE 0x20U //32 words + +#elif defined __AVR_ATmega8535__ +#define SIG2 0x93 +#define SIG3 0x08 +#define PAGE_SIZE 0x20U //32 words +#endif + + +/* function prototypes */ +void putch(char); +char getch(void); +void getNch(uint8_t); +void byte_response(uint8_t); +void nothing_response(void); +char gethex(void); +void puthex(char); +void flash_led(uint8_t); + +/* some variables */ +union address_union { + uint16_t word; + uint8_t byte[2]; +} address; + +union length_union { + uint16_t word; + uint8_t byte[2]; +} length; + +struct flags_struct { + unsigned eeprom : 1; + unsigned rampz : 1; +} flags; + +uint8_t buff[256]; +uint8_t address_high; + +uint8_t pagesz=0x80; + +uint8_t i; +uint8_t bootuart = 0; + +void (*app_start)(void) = 0x0000; + + +/* main program starts here */ +int main(void) +{ + uint8_t ch,ch2; + uint16_t w; + + asm volatile("nop\n\t"); + + /* set pin direction for bootloader pin and enable pullup */ + /* for ATmega128, two pins need to be initialized */ +#ifdef __AVR_ATmega128__ + BL_DDR &= ~_BV(BL0); + BL_DDR &= ~_BV(BL1); + BL_PORT |= _BV(BL0); + BL_PORT |= _BV(BL1); +#else + BL_DDR &= ~_BV(BL); + BL_PORT |= _BV(BL); +#endif + + +#ifdef __AVR_ATmega128__ + /* check which UART should be used for booting */ + if(bit_is_clear(BL_PIN, BL0)) { + bootuart = 1; + } + else if(bit_is_clear(BL_PIN, BL1)) { + bootuart = 2; + } +#endif + + /* check if flash is programmed already, if not start bootloader anyway */ + if(pgm_read_byte_near(0x0000) != 0xFF) { + +#ifdef __AVR_ATmega128__ + /* no UART was selected, start application */ + if(!bootuart) { + app_start(); + } +#else + /* check if bootloader pin is set low */ + /* we don't start this part neither for the m8, nor m168 */ + //if(bit_is_set(BL_PIN, BL)) { + // app_start(); + // } +#endif + } + +#ifdef __AVR_ATmega128__ + /* no bootuart was selected, default to uart 0 */ + if(!bootuart) { + bootuart = 1; + } +#endif + + + /* initialize UART(s) depending on CPU defined */ +#ifdef __AVR_ATmega128__ + if(bootuart == 1) { + UBRR0L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1); + UBRR0H = (F_CPU/(BAUD_RATE*16L)-1) >> 8; + UCSR0A = 0x00; + UCSR0C = 0x06; + UCSR0B = _BV(TXEN0)|_BV(RXEN0); + } + if(bootuart == 2) { + UBRR1L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1); + UBRR1H = (F_CPU/(BAUD_RATE*16L)-1) >> 8; + UCSR1A = 0x00; + UCSR1C = 0x06; + UCSR1B = _BV(TXEN1)|_BV(RXEN1); + } +#elif defined __AVR_ATmega163__ + UBRR = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1); + UBRRHI = (F_CPU/(BAUD_RATE*16L)-1) >> 8; + UCSRA = 0x00; + UCSRB = _BV(TXEN)|_BV(RXEN); +#elif defined __AVR_ATmega168__ + UBRR0H = ((F_CPU / 16 + BAUD_RATE / 2) / BAUD_RATE - 1) >> 8; + UBRR0L = ((F_CPU / 16 + BAUD_RATE / 2) / BAUD_RATE - 1); + + + //UBRR0L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1); + //UBRR0H = (F_CPU/(BAUD_RATE*16L)-1) >> 8; + UCSR0B = (1<>8; // set baud rate + UBRRL = (((F_CPU/BAUD_RATE)/16)-1); + UCSRB = (1<> 8; + UCSRA = 0x00; + UCSRC = 0x06; + UCSRB = _BV(TXEN)|_BV(RXEN); +#endif + + /* set LED pin as output */ + LED_DDR |= _BV(LED); + + + + set_output(DDRD,PIND7); + high(PORTD,PD7); + for (i = 0; i < 16; i++) { + + _delay_loop_2(0); + } + + + low(PORTD,PD7); + + + /* flash onboard LED to signal entering of bootloader */ +#ifdef __AVR_ATmega128__ + // 4x for UART0, 5x for UART1 + flash_led(3 + bootuart); +#else + flash_led(3); +#endif + + /* 20050803: by DojoCorp, this is one of the parts provoking the + system to stop listening, cancelled from the original */ + //putch('\0'); + + + //message("SET BT PAGEMODE 3 2000 1"); +putch('S'); +putch('E'); +putch('T'); +putch(' '); +putch('B'); +putch('T'); +putch(' '); +putch('P'); +putch('A'); +putch('G'); +putch('E'); +putch('M'); +putch('O'); +putch('D'); +putch('E'); +putch(' '); +putch('3'); +putch(' '); +putch('2'); +putch('0'); +putch('0'); +putch('0'); +putch(' '); +putch('1'); +putch(0x0D); + + + //put_s("SET BT ROLE 0 f 7d00"); + putch('S'); + putch('E'); + putch('T'); + putch(' '); + putch('B'); + putch('T'); + putch(' '); + putch('R'); + putch('O'); + putch('L'); + putch('E'); + putch(' '); + putch('0'); + putch(' '); + putch('f'); + putch(' '); + putch('7'); + putch('d'); + putch('0'); + putch('0'); + putch(0x0D); + + + + + + + /* forever loop */ + for (;;) { + + /* get character from UART */ + ch = getch(); + + /* A bunch of if...else if... gives smaller code than switch...case ! */ + + /* Hello is anyone home ? */ + if(ch=='0') { + nothing_response(); + } + + + /* Request programmer ID */ + /* Not using PROGMEM string due to boot block in m128 being beyond 64kB boundry */ + /* Would need to selectively manipulate RAMPZ, and it's only 9 characters anyway so who cares. */ + else if(ch=='1') { + if (getch() == ' ') { + putch(0x14); + putch('A'); + putch('V'); + putch('R'); + putch(' '); + putch('I'); + putch('S'); + putch('P'); + putch(0x10); + } + } + + + /* AVR ISP/STK500 board commands DON'T CARE so default nothing_response */ + else if(ch=='@') { + ch2 = getch(); + if (ch2>0x85) getch(); + nothing_response(); + } + + + /* AVR ISP/STK500 board requests */ + else if(ch=='A') { + ch2 = getch(); + if(ch2==0x80) byte_response(HW_VER); // Hardware version + else if(ch2==0x81) byte_response(SW_MAJOR); // Software major version + else if(ch2==0x82) byte_response(SW_MINOR); // Software minor version + else if(ch2==0x98) byte_response(0x03); // Unknown but seems to be required by avr studio 3.56 + else byte_response(0x00); // Covers various unnecessary responses we don't care about + } + + + /* Device Parameters DON'T CARE, DEVICE IS FIXED */ + else if(ch=='B') { + getNch(20); + nothing_response(); + } + + + /* Parallel programming stuff DON'T CARE */ + else if(ch=='E') { + getNch(5); + nothing_response(); + } + + + /* Enter programming mode */ + else if(ch=='P') { + nothing_response(); + } + + + /* Leave programming mode */ + else if(ch=='Q') { + nothing_response(); + } + + + /* Erase device, don't care as we will erase one page at a time anyway. */ + else if(ch=='R') { + nothing_response(); + } + + + /* Set address, little endian. EEPROM in bytes, FLASH in words */ + /* Perhaps extra address bytes may be added in future to support > 128kB FLASH. */ + /* This might explain why little endian was used here, big endian used everywhere else. */ + else if(ch=='U') { + address.byte[0] = getch(); + address.byte[1] = getch(); + nothing_response(); + } + + + /* Universal SPI programming command, disabled. Would be used for fuses and lock bits. */ + else if(ch=='V') { + getNch(4); + byte_response(0x00); + } + + + /* Write memory, length is big endian and is in bytes */ + else if(ch=='d') { + length.byte[1] = getch(); + length.byte[0] = getch(); + flags.eeprom = 0; + if (getch() == 'E') flags.eeprom = 1; + for (w=0;w127) address_high = 0x01; //Only possible with m128, m256 will need 3rd address byte. FIXME + else address_high = 0x00; +#ifdef __AVR_ATmega128__ + RAMPZ = address_high; +#endif + address.word = address.word << 1; //address * 2 -> byte location + /* if ((length.byte[0] & 0x01) == 0x01) length.word++; //Even up an odd number of bytes */ + if ((length.byte[0] & 0x01)) length.word++; //Even up an odd number of bytes + cli(); //Disable interrupts, just to be sure + // HACKME: EEPE used to be EEWE + while(bit_is_set(EECR,EEPE)); //Wait for previous EEPROM writes to complete + asm volatile( + "clr r17 \n\t" //page_word_count + "lds r30,address \n\t" //Address of FLASH location (in bytes) + "lds r31,address+1 \n\t" + "ldi r28,lo8(buff) \n\t" //Start of buffer array in RAM + "ldi r29,hi8(buff) \n\t" + "lds r24,length \n\t" //Length of data to be written (in bytes) + "lds r25,length+1 \n\t" + "length_loop: \n\t" //Main loop, repeat for number of words in block + "cpi r17,0x00 \n\t" //If page_word_count=0 then erase page + "brne no_page_erase \n\t" + "wait_spm1: \n\t" + "lds r16,%0 \n\t" //Wait for previous spm to complete + "andi r16,1 \n\t" + "cpi r16,1 \n\t" + "breq wait_spm1 \n\t" + "ldi r16,0x03 \n\t" //Erase page pointed to by Z + "sts %0,r16 \n\t" + "spm \n\t" +#ifdef __AVR_ATmega163__ + ".word 0xFFFF \n\t" + "nop \n\t" +#endif + "wait_spm2: \n\t" + "lds r16,%0 \n\t" //Wait for previous spm to complete + "andi r16,1 \n\t" + "cpi r16,1 \n\t" + "breq wait_spm2 \n\t" + + "ldi r16,0x11 \n\t" //Re-enable RWW section + "sts %0,r16 \n\t" + "spm \n\t" +#ifdef __AVR_ATmega163__ + ".word 0xFFFF \n\t" + "nop \n\t" +#endif + "no_page_erase: \n\t" + "ld r0,Y+ \n\t" //Write 2 bytes into page buffer + "ld r1,Y+ \n\t" + + "wait_spm3: \n\t" + "lds r16,%0 \n\t" //Wait for previous spm to complete + "andi r16,1 \n\t" + "cpi r16,1 \n\t" + "breq wait_spm3 \n\t" + "ldi r16,0x01 \n\t" //Load r0,r1 into FLASH page buffer + "sts %0,r16 \n\t" + "spm \n\t" + + "inc r17 \n\t" //page_word_count++ + "cpi r17,%1 \n\t" + "brlo same_page \n\t" //Still same page in FLASH + "write_page: \n\t" + "clr r17 \n\t" //New page, write current one first + "wait_spm4: \n\t" + "lds r16,%0 \n\t" //Wait for previous spm to complete + "andi r16,1 \n\t" + "cpi r16,1 \n\t" + "breq wait_spm4 \n\t" +#ifdef __AVR_ATmega163__ + "andi r30,0x80 \n\t" // m163 requires Z6:Z1 to be zero during page write +#endif + "ldi r16,0x05 \n\t" //Write page pointed to by Z + "sts %0,r16 \n\t" + "spm \n\t" +#ifdef __AVR_ATmega163__ + ".word 0xFFFF \n\t" + "nop \n\t" + "ori r30,0x7E \n\t" // recover Z6:Z1 state after page write (had to be zero during write) +#endif + "wait_spm5: \n\t" + "lds r16,%0 \n\t" //Wait for previous spm to complete + "andi r16,1 \n\t" + "cpi r16,1 \n\t" + "breq wait_spm5 \n\t" + "ldi r16,0x11 \n\t" //Re-enable RWW section + "sts %0,r16 \n\t" + "spm \n\t" +#ifdef __AVR_ATmega163__ + ".word 0xFFFF \n\t" + "nop \n\t" +#endif + "same_page: \n\t" + "adiw r30,2 \n\t" //Next word in FLASH + "sbiw r24,2 \n\t" //length-2 + "breq final_write \n\t" //Finished + "rjmp length_loop \n\t" + "final_write: \n\t" + "cpi r17,0 \n\t" + "breq block_done \n\t" + "adiw r24,2 \n\t" //length+2, fool above check on length after short page write + "rjmp write_page \n\t" + "block_done: \n\t" + "clr __zero_reg__ \n\t" //restore zero register +#if defined __AVR_ATmega168__ + : "=m" (SPMCSR) : "M" (PAGE_SIZE) : "r0","r16","r17","r24","r25","r28","r29","r30","r31" +#else + : "=m" (SPMCR) : "M" (PAGE_SIZE) : "r0","r16","r17","r24","r25","r28","r29","r30","r31" +#endif + ); + /* Should really add a wait for RWW section to be enabled, don't actually need it since we never */ + /* exit the bootloader without a power cycle anyhow */ + } + putch(0x14); + putch(0x10); + } + } + + + /* Read memory block mode, length is big endian. */ + else if(ch=='t') { + length.byte[1] = getch(); + length.byte[0] = getch(); +#if defined __AVR_ATmega128__ + if (address.word>0x7FFF) flags.rampz = 1; // No go with m256, FIXME + else flags.rampz = 0; +#endif + if (getch() == 'E') flags.eeprom = 1; + else { + flags.eeprom = 0; + address.word = address.word << 1; // address * 2 -> byte location + } + if (getch() == ' ') { // Command terminator + putch(0x14); + for (w=0;w < length.word;w++) { // Can handle odd and even lengths okay + if (flags.eeprom) { // Byte access EEPROM read +#ifdef __AVR_ATmega168__ + while(EECR & (1<= 'a') { + ah = ah - 'a' + 0x0a; + } else if(ah >= '0') { + ah -= '0'; + } + if(al >= 'a') { + al = al - 'a' + 0x0a; + } else if(al >= '0') { + al -= '0'; + } + return (ah << 4) + al; +} + + +void puthex(char ch) { + char ah,al; + + ah = (ch & 0xf0) >> 4; + if(ah >= 0x0a) { + ah = ah - 0x0a + 'a'; + } else { + ah += '0'; + } + al = (ch & 0x0f); + if(al >= 0x0a) { + al = al - 0x0a + 'a'; + } else { + al += '0'; + } + putch(ah); + putch(al); +} + + +void putch(char ch) +{ +#ifdef __AVR_ATmega128__ + if(bootuart == 1) { + while (!(UCSR0A & _BV(UDRE0))); + UDR0 = ch; + } + else if (bootuart == 2) { + while (!(UCSR1A & _BV(UDRE1))); + UDR1 = ch; + } +#elif defined __AVR_ATmega168__ + while (!(UCSR0A & _BV(UDRE0))); + UDR0 = ch; +#else + /* m8,16,32,169,8515,8535,163 */ + while (!(UCSRA & _BV(UDRE))); + UDR = ch; +#endif +} + + +char getch(void) +{ +#ifdef __AVR_ATmega128__ + if(bootuart == 1) { + while(!(UCSR0A & _BV(RXC0))); + return UDR0; + } + else if(bootuart == 2) { + while(!(UCSR1A & _BV(RXC1))); + return UDR1; + } + return 0; +#elif defined __AVR_ATmega168__ + uint32_t count = 0; + while(!(UCSR0A & _BV(RXC0))){ + /* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/ + /* HACKME:: here is a good place to count times*/ + count++; + if (count > MAX_TIME_COUNT) + app_start(); + } + return UDR0; +#else + /* m8,16,32,169,8515,8535,163 */ + uint32_t count = 0; + while(!(UCSRA & _BV(RXC))){ + /* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/ + /* HACKME:: here is a good place to count times*/ + count++; + if (count > MAX_TIME_COUNT) + app_start(); + } + return UDR; +#endif +} + + +void getNch(uint8_t count) +{ + uint8_t i; + for(i=0;i +#include +#include +#include +#include + + +/* the current avr-libc eeprom functions do not support the ATmega168 */ +/* own eeprom write/read functions are used instead */ +#ifndef __AVR_ATmega168__ +#include +#endif + +/* Use the F_CPU defined in Makefile */ + +/* 20060803: hacked by DojoCorp */ +/* 20070626: hacked by David A. Mellis to decrease waiting time for auto-reset */ +/* set the waiting time for the bootloader */ +/* get this from the Makefile instead */ +/* #define MAX_TIME_COUNT (F_CPU>>4) */ + +/* 20070707: hacked by David A. Mellis - after this many errors give up and launch application */ +#define MAX_ERROR_COUNT 5 + +/* set the UART baud rate */ +/* 20060803: hacked by DojoCorp */ +//#define BAUD_RATE 115200 +#define BAUD_RATE 19200 + + +/* SW_MAJOR and MINOR needs to be updated from time to time to avoid warning message from AVR Studio */ +/* never allow AVR Studio to do an update !!!! */ +#define HW_VER 0x02 +#define SW_MAJOR 0x01 +#define SW_MINOR 0x10 + + +/* Adjust to suit whatever pin your hardware uses to enter the bootloader */ +/* ATmega128 has two UARTS so two pins are used to enter bootloader and select UART */ +/* BL0... means UART0, BL1... means UART1 */ +#ifdef __AVR_ATmega128__ +#define BL_DDR DDRF +#define BL_PORT PORTF +#define BL_PIN PINF +#define BL0 PINF7 +#define BL1 PINF6 +#else +/* other ATmegas have only one UART, so only one pin is defined to enter bootloader */ +#define BL_DDR DDRD +#define BL_PORT PORTD +#define BL_PIN PIND +#define BL PIND6 +#endif + + +/* onboard LED is used to indicate, that the bootloader was entered (3x flashing) */ +/* if monitor functions are included, LED goes on after monitor was entered */ +#ifdef __AVR_ATmega128__ +/* Onboard LED is connected to pin PB7 (e.g. Crumb128, PROBOmega128, Savvy128) */ +#define LED_DDR DDRB +#define LED_PORT PORTB +#define LED_PIN PINB +#define LED PINB7 +#else +/* Onboard LED is connected to pin PB2 (e.g. Crumb8, Crumb168) */ +#define LED_DDR DDRB +#define LED_PORT PORTB +#define LED_PIN PINB +/* 20060803: hacked by DojoCorp, LED pin is B5 in Arduino */ +/* #define LED PINB2 */ +#define LED PINB5 +#endif + + +/* monitor functions will only be compiled when using ATmega128, due to bootblock size constraints */ +#ifdef __AVR_ATmega128__ +#define MONITOR +#endif + + +/* define various device id's */ +/* manufacturer byte is always the same */ +#define SIG1 0x1E // Yep, Atmel is the only manufacturer of AVR micros. Single source :( + +#if defined __AVR_ATmega128__ +#define SIG2 0x97 +#define SIG3 0x02 +#define PAGE_SIZE 0x80U //128 words + +#elif defined __AVR_ATmega64__ +#define SIG2 0x96 +#define SIG3 0x02 +#define PAGE_SIZE 0x80U //128 words + +#elif defined __AVR_ATmega32__ +#define SIG2 0x95 +#define SIG3 0x02 +#define PAGE_SIZE 0x40U //64 words + +#elif defined __AVR_ATmega16__ +#define SIG2 0x94 +#define SIG3 0x03 +#define PAGE_SIZE 0x40U //64 words + +#elif defined __AVR_ATmega8__ +#define SIG2 0x93 +#define SIG3 0x07 +#define PAGE_SIZE 0x20U //32 words + +#elif defined __AVR_ATmega88__ +#define SIG2 0x93 +#define SIG3 0x0a +#define PAGE_SIZE 0x20U //32 words + +#elif defined __AVR_ATmega168__ +#define SIG2 0x94 +#define SIG3 0x06 +#define PAGE_SIZE 0x40U //64 words + +#elif defined __AVR_ATmega162__ +#define SIG2 0x94 +#define SIG3 0x04 +#define PAGE_SIZE 0x40U //64 words + +#elif defined __AVR_ATmega163__ +#define SIG2 0x94 +#define SIG3 0x02 +#define PAGE_SIZE 0x40U //64 words + +#elif defined __AVR_ATmega169__ +#define SIG2 0x94 +#define SIG3 0x05 +#define PAGE_SIZE 0x40U //64 words + +#elif defined __AVR_ATmega8515__ +#define SIG2 0x93 +#define SIG3 0x06 +#define PAGE_SIZE 0x20U //32 words + +#elif defined __AVR_ATmega8535__ +#define SIG2 0x93 +#define SIG3 0x08 +#define PAGE_SIZE 0x20U //32 words +#endif + + +/* function prototypes */ +void putch(char); +char getch(void); +void getNch(uint8_t); +void byte_response(uint8_t); +void nothing_response(void); +char gethex(void); +void puthex(char); +void flash_led(uint8_t); + +/* some variables */ +union address_union { + uint16_t word; + uint8_t byte[2]; +} address; + +union length_union { + uint16_t word; + uint8_t byte[2]; +} length; + +struct flags_struct { + unsigned eeprom : 1; + unsigned rampz : 1; +} flags; + +uint8_t buff[256]; +uint8_t address_high; + +uint8_t pagesz=0x80; + +uint8_t i; +uint8_t bootuart = 0; + +uint8_t error_count = 0; + +void (*app_start)(void) = 0x0000; + + +/* main program starts here */ +int main(void) +{ + uint8_t ch,ch2; + uint16_t w; + + asm volatile("nop\n\t"); + + /* set pin direction for bootloader pin and enable pullup */ + /* for ATmega128, two pins need to be initialized */ +#ifdef __AVR_ATmega128__ + BL_DDR &= ~_BV(BL0); + BL_DDR &= ~_BV(BL1); + BL_PORT |= _BV(BL0); + BL_PORT |= _BV(BL1); +#else + /* We run the bootloader regardless of the state of this pin. Thus, don't + put it in a different state than the other pins. --DAM, 070709 + BL_DDR &= ~_BV(BL); + BL_PORT |= _BV(BL); + */ +#endif + + +#ifdef __AVR_ATmega128__ + /* check which UART should be used for booting */ + if(bit_is_clear(BL_PIN, BL0)) { + bootuart = 1; + } + else if(bit_is_clear(BL_PIN, BL1)) { + bootuart = 2; + } +#endif + + /* check if flash is programmed already, if not start bootloader anyway */ + if(pgm_read_byte_near(0x0000) != 0xFF) { + +#ifdef __AVR_ATmega128__ + /* no UART was selected, start application */ + if(!bootuart) { + app_start(); + } +#else + /* check if bootloader pin is set low */ + /* we don't start this part neither for the m8, nor m168 */ + //if(bit_is_set(BL_PIN, BL)) { + // app_start(); + // } +#endif + } + +#ifdef __AVR_ATmega128__ + /* no bootuart was selected, default to uart 0 */ + if(!bootuart) { + bootuart = 1; + } +#endif + + + /* initialize UART(s) depending on CPU defined */ +#ifdef __AVR_ATmega128__ + if(bootuart == 1) { + UBRR0L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1); + UBRR0H = (F_CPU/(BAUD_RATE*16L)-1) >> 8; + UCSR0A = 0x00; + UCSR0C = 0x06; + UCSR0B = _BV(TXEN0)|_BV(RXEN0); + } + if(bootuart == 2) { + UBRR1L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1); + UBRR1H = (F_CPU/(BAUD_RATE*16L)-1) >> 8; + UCSR1A = 0x00; + UCSR1C = 0x06; + UCSR1B = _BV(TXEN1)|_BV(RXEN1); + } +#elif defined __AVR_ATmega163__ + UBRR = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1); + UBRRHI = (F_CPU/(BAUD_RATE*16L)-1) >> 8; + UCSRA = 0x00; + UCSRB = _BV(TXEN)|_BV(RXEN); +#elif defined __AVR_ATmega168__ + UBRR0L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1); + UBRR0H = (F_CPU/(BAUD_RATE*16L)-1) >> 8; + UCSR0B = (1<>8; // set baud rate + UBRRL = (((F_CPU/BAUD_RATE)/16)-1); + UCSRB = (1<> 8; + UCSRA = 0x00; + UCSRC = 0x06; + UCSRB = _BV(TXEN)|_BV(RXEN); +#endif + + /* set LED pin as output */ + LED_DDR |= _BV(LED); + + + /* flash onboard LED to signal entering of bootloader */ +#ifdef __AVR_ATmega128__ + // 4x for UART0, 5x for UART1 + flash_led(NUM_LED_FLASHES + bootuart); +#else + flash_led(NUM_LED_FLASHES); +#endif + + /* 20050803: by DojoCorp, this is one of the parts provoking the + system to stop listening, cancelled from the original */ + //putch('\0'); + + + /* forever loop */ + for (;;) { + + /* get character from UART */ + ch = getch(); + + /* A bunch of if...else if... gives smaller code than switch...case ! */ + + /* Hello is anyone home ? */ + if(ch=='0') { + nothing_response(); + } + + + /* Request programmer ID */ + /* Not using PROGMEM string due to boot block in m128 being beyond 64kB boundry */ + /* Would need to selectively manipulate RAMPZ, and it's only 9 characters anyway so who cares. */ + else if(ch=='1') { + if (getch() == ' ') { + putch(0x14); + putch('A'); + putch('V'); + putch('R'); + putch(' '); + putch('I'); + putch('S'); + putch('P'); + putch(0x10); + } else { + if (++error_count == MAX_ERROR_COUNT) + app_start(); + } + } + + + /* AVR ISP/STK500 board commands DON'T CARE so default nothing_response */ + else if(ch=='@') { + ch2 = getch(); + if (ch2>0x85) getch(); + nothing_response(); + } + + + /* AVR ISP/STK500 board requests */ + else if(ch=='A') { + ch2 = getch(); + if(ch2==0x80) byte_response(HW_VER); // Hardware version + else if(ch2==0x81) byte_response(SW_MAJOR); // Software major version + else if(ch2==0x82) byte_response(SW_MINOR); // Software minor version + else if(ch2==0x98) byte_response(0x03); // Unknown but seems to be required by avr studio 3.56 + else byte_response(0x00); // Covers various unnecessary responses we don't care about + } + + + /* Device Parameters DON'T CARE, DEVICE IS FIXED */ + else if(ch=='B') { + getNch(20); + nothing_response(); + } + + + /* Parallel programming stuff DON'T CARE */ + else if(ch=='E') { + getNch(5); + nothing_response(); + } + + + /* Enter programming mode */ + else if(ch=='P') { + nothing_response(); + } + + + /* Leave programming mode */ + else if(ch=='Q') { + nothing_response(); + } + + + /* Erase device, don't care as we will erase one page at a time anyway. */ + else if(ch=='R') { + nothing_response(); + } + + + /* Set address, little endian. EEPROM in bytes, FLASH in words */ + /* Perhaps extra address bytes may be added in future to support > 128kB FLASH. */ + /* This might explain why little endian was used here, big endian used everywhere else. */ + else if(ch=='U') { + address.byte[0] = getch(); + address.byte[1] = getch(); + nothing_response(); + } + + + /* Universal SPI programming command, disabled. Would be used for fuses and lock bits. */ + else if(ch=='V') { + getNch(4); + byte_response(0x00); + } + + + /* Write memory, length is big endian and is in bytes */ + else if(ch=='d') { + length.byte[1] = getch(); + length.byte[0] = getch(); + flags.eeprom = 0; + if (getch() == 'E') flags.eeprom = 1; + for (w=0;w127) address_high = 0x01; //Only possible with m128, m256 will need 3rd address byte. FIXME + else address_high = 0x00; +#ifdef __AVR_ATmega128__ + RAMPZ = address_high; +#endif + address.word = address.word << 1; //address * 2 -> byte location + /* if ((length.byte[0] & 0x01) == 0x01) length.word++; //Even up an odd number of bytes */ + if ((length.byte[0] & 0x01)) length.word++; //Even up an odd number of bytes + cli(); //Disable interrupts, just to be sure + // HACKME: EEPE used to be EEWE + while(bit_is_set(EECR,EEPE)); //Wait for previous EEPROM writes to complete + asm volatile( + "clr r17 \n\t" //page_word_count + "lds r30,address \n\t" //Address of FLASH location (in bytes) + "lds r31,address+1 \n\t" + "ldi r28,lo8(buff) \n\t" //Start of buffer array in RAM + "ldi r29,hi8(buff) \n\t" + "lds r24,length \n\t" //Length of data to be written (in bytes) + "lds r25,length+1 \n\t" + "length_loop: \n\t" //Main loop, repeat for number of words in block + "cpi r17,0x00 \n\t" //If page_word_count=0 then erase page + "brne no_page_erase \n\t" + "wait_spm1: \n\t" + "lds r16,%0 \n\t" //Wait for previous spm to complete + "andi r16,1 \n\t" + "cpi r16,1 \n\t" + "breq wait_spm1 \n\t" + "ldi r16,0x03 \n\t" //Erase page pointed to by Z + "sts %0,r16 \n\t" + "spm \n\t" +#ifdef __AVR_ATmega163__ + ".word 0xFFFF \n\t" + "nop \n\t" +#endif + "wait_spm2: \n\t" + "lds r16,%0 \n\t" //Wait for previous spm to complete + "andi r16,1 \n\t" + "cpi r16,1 \n\t" + "breq wait_spm2 \n\t" + + "ldi r16,0x11 \n\t" //Re-enable RWW section + "sts %0,r16 \n\t" + "spm \n\t" +#ifdef __AVR_ATmega163__ + ".word 0xFFFF \n\t" + "nop \n\t" +#endif + "no_page_erase: \n\t" + "ld r0,Y+ \n\t" //Write 2 bytes into page buffer + "ld r1,Y+ \n\t" + + "wait_spm3: \n\t" + "lds r16,%0 \n\t" //Wait for previous spm to complete + "andi r16,1 \n\t" + "cpi r16,1 \n\t" + "breq wait_spm3 \n\t" + "ldi r16,0x01 \n\t" //Load r0,r1 into FLASH page buffer + "sts %0,r16 \n\t" + "spm \n\t" + + "inc r17 \n\t" //page_word_count++ + "cpi r17,%1 \n\t" + "brlo same_page \n\t" //Still same page in FLASH + "write_page: \n\t" + "clr r17 \n\t" //New page, write current one first + "wait_spm4: \n\t" + "lds r16,%0 \n\t" //Wait for previous spm to complete + "andi r16,1 \n\t" + "cpi r16,1 \n\t" + "breq wait_spm4 \n\t" +#ifdef __AVR_ATmega163__ + "andi r30,0x80 \n\t" // m163 requires Z6:Z1 to be zero during page write +#endif + "ldi r16,0x05 \n\t" //Write page pointed to by Z + "sts %0,r16 \n\t" + "spm \n\t" +#ifdef __AVR_ATmega163__ + ".word 0xFFFF \n\t" + "nop \n\t" + "ori r30,0x7E \n\t" // recover Z6:Z1 state after page write (had to be zero during write) +#endif + "wait_spm5: \n\t" + "lds r16,%0 \n\t" //Wait for previous spm to complete + "andi r16,1 \n\t" + "cpi r16,1 \n\t" + "breq wait_spm5 \n\t" + "ldi r16,0x11 \n\t" //Re-enable RWW section + "sts %0,r16 \n\t" + "spm \n\t" +#ifdef __AVR_ATmega163__ + ".word 0xFFFF \n\t" + "nop \n\t" +#endif + "same_page: \n\t" + "adiw r30,2 \n\t" //Next word in FLASH + "sbiw r24,2 \n\t" //length-2 + "breq final_write \n\t" //Finished + "rjmp length_loop \n\t" + "final_write: \n\t" + "cpi r17,0 \n\t" + "breq block_done \n\t" + "adiw r24,2 \n\t" //length+2, fool above check on length after short page write + "rjmp write_page \n\t" + "block_done: \n\t" + "clr __zero_reg__ \n\t" //restore zero register +#if defined __AVR_ATmega168__ + : "=m" (SPMCSR) : "M" (PAGE_SIZE) : "r0","r16","r17","r24","r25","r28","r29","r30","r31" +#else + : "=m" (SPMCR) : "M" (PAGE_SIZE) : "r0","r16","r17","r24","r25","r28","r29","r30","r31" +#endif + ); + /* Should really add a wait for RWW section to be enabled, don't actually need it since we never */ + /* exit the bootloader without a power cycle anyhow */ + } + putch(0x14); + putch(0x10); + } else { + if (++error_count == MAX_ERROR_COUNT) + app_start(); + } + } + + + /* Read memory block mode, length is big endian. */ + else if(ch=='t') { + length.byte[1] = getch(); + length.byte[0] = getch(); +#if defined __AVR_ATmega128__ + if (address.word>0x7FFF) flags.rampz = 1; // No go with m256, FIXME + else flags.rampz = 0; +#endif + if (getch() == 'E') flags.eeprom = 1; + else { + flags.eeprom = 0; + address.word = address.word << 1; // address * 2 -> byte location + } + if (getch() == ' ') { // Command terminator + putch(0x14); + for (w=0;w < length.word;w++) { // Can handle odd and even lengths okay + if (flags.eeprom) { // Byte access EEPROM read +#ifdef __AVR_ATmega168__ + while(EECR & (1<= 'a') { + ah = ah - 'a' + 0x0a; + } else if(ah >= '0') { + ah -= '0'; + } + if(al >= 'a') { + al = al - 'a' + 0x0a; + } else if(al >= '0') { + al -= '0'; + } + return (ah << 4) + al; +} + + +void puthex(char ch) { + char ah,al; + + ah = (ch & 0xf0) >> 4; + if(ah >= 0x0a) { + ah = ah - 0x0a + 'a'; + } else { + ah += '0'; + } + al = (ch & 0x0f); + if(al >= 0x0a) { + al = al - 0x0a + 'a'; + } else { + al += '0'; + } + putch(ah); + putch(al); +} + + +void putch(char ch) +{ +#ifdef __AVR_ATmega128__ + if(bootuart == 1) { + while (!(UCSR0A & _BV(UDRE0))); + UDR0 = ch; + } + else if (bootuart == 2) { + while (!(UCSR1A & _BV(UDRE1))); + UDR1 = ch; + } +#elif defined __AVR_ATmega168__ + while (!(UCSR0A & _BV(UDRE0))); + UDR0 = ch; +#else + /* m8,16,32,169,8515,8535,163 */ + while (!(UCSRA & _BV(UDRE))); + UDR = ch; +#endif +} + + +char getch(void) +{ +#ifdef __AVR_ATmega128__ + if(bootuart == 1) { + while(!(UCSR0A & _BV(RXC0))); + return UDR0; + } + else if(bootuart == 2) { + while(!(UCSR1A & _BV(RXC1))); + return UDR1; + } + return 0; +#elif defined __AVR_ATmega168__ + uint32_t count = 0; + while(!(UCSR0A & _BV(RXC0))){ + /* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/ + /* HACKME:: here is a good place to count times*/ + count++; + if (count > MAX_TIME_COUNT) + app_start(); + } + return UDR0; +#else + /* m8,16,32,169,8515,8535,163 */ + uint32_t count = 0; + while(!(UCSRA & _BV(RXC))){ + /* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/ + /* HACKME:: here is a good place to count times*/ + count++; + if (count > MAX_TIME_COUNT) + app_start(); + } + return UDR; +#endif +} + + +void getNch(uint8_t count) +{ + uint8_t i; + for(i=0;i $@ + +%.srec: %.elf + $(OBJCOPY) -j .text -j .data -O srec $< $@ + +%.bin: %.elf + $(OBJCOPY) -j .text -j .data -O binary $< $@ + +clean: + rm -rf *.o *.elf *.lst *.map *.sym *.lss *.eep *.srec *.bin *.hex + +install: + avrdude -p m168 -c stk500v2 -P /dev/cu.USA19H1b1P1.1 -e -u -U lock:w:0x3f:m -U efuse:w:0x00:m -U hfuse:w:0xdd:m -U lfuse:w:0xe2:m + avrdude -p m168 -c stk500v2 -P /dev/cu.USA19H1b1P1.1 -e -u -U flash:w:ATmegaBOOT_168.hex -U lock:w:0x0f:m diff --git a/arduino-0018-linux/hardware/arduino/cores/arduino/HardwareSerial.cpp b/arduino-0018-linux/hardware/arduino/cores/arduino/HardwareSerial.cpp new file mode 100755 index 0000000..712a4c7 --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/cores/arduino/HardwareSerial.cpp @@ -0,0 +1,226 @@ +/* + HardwareSerial.cpp - Hardware serial library for Wiring + Copyright (c) 2006 Nicholas Zambetti. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Modified 23 November 2006 by David A. Mellis +*/ + +#include +#include +#include +#include "wiring.h" +#include "wiring_private.h" + +#include "HardwareSerial.h" + +// Define constants and variables for buffering incoming serial data. We're +// using a ring buffer (I think), in which rx_buffer_head is the index of the +// location to which to write the next incoming character and rx_buffer_tail +// is the index of the location from which to read. +#define RX_BUFFER_SIZE 128 + +struct ring_buffer { + unsigned char buffer[RX_BUFFER_SIZE]; + int head; + int tail; +}; + +ring_buffer rx_buffer = { { 0 }, 0, 0 }; + +#if defined(__AVR_ATmega1280__) +ring_buffer rx_buffer1 = { { 0 }, 0, 0 }; +ring_buffer rx_buffer2 = { { 0 }, 0, 0 }; +ring_buffer rx_buffer3 = { { 0 }, 0, 0 }; +#endif + +inline void store_char(unsigned char c, ring_buffer *rx_buffer) +{ + int i = (rx_buffer->head + 1) % RX_BUFFER_SIZE; + + // if we should be storing the received character into the location + // just before the tail (meaning that the head would advance to the + // current location of the tail), we're about to overflow the buffer + // and so we don't write the character or advance the head. + if (i != rx_buffer->tail) { + rx_buffer->buffer[rx_buffer->head] = c; + rx_buffer->head = i; + } +} + +#if defined(__AVR_ATmega1280__) + +SIGNAL(SIG_USART0_RECV) +{ + unsigned char c = UDR0; + store_char(c, &rx_buffer); +} + +SIGNAL(SIG_USART1_RECV) +{ + unsigned char c = UDR1; + store_char(c, &rx_buffer1); +} + +SIGNAL(SIG_USART2_RECV) +{ + unsigned char c = UDR2; + store_char(c, &rx_buffer2); +} + +SIGNAL(SIG_USART3_RECV) +{ + unsigned char c = UDR3; + store_char(c, &rx_buffer3); +} + +#else + +#if defined(__AVR_ATmega8__) +SIGNAL(SIG_UART_RECV) +#else +SIGNAL(USART_RX_vect) +#endif +{ +#if defined(__AVR_ATmega8__) + unsigned char c = UDR; +#else + unsigned char c = UDR0; +#endif + store_char(c, &rx_buffer); +} + +#endif + +// Constructors //////////////////////////////////////////////////////////////// + +HardwareSerial::HardwareSerial(ring_buffer *rx_buffer, + volatile uint8_t *ubrrh, volatile uint8_t *ubrrl, + volatile uint8_t *ucsra, volatile uint8_t *ucsrb, + volatile uint8_t *udr, + uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x) +{ + _rx_buffer = rx_buffer; + _ubrrh = ubrrh; + _ubrrl = ubrrl; + _ucsra = ucsra; + _ucsrb = ucsrb; + _udr = udr; + _rxen = rxen; + _txen = txen; + _rxcie = rxcie; + _udre = udre; + _u2x = u2x; +} + +// Public Methods ////////////////////////////////////////////////////////////// + +void HardwareSerial::begin(long baud) +{ + uint16_t baud_setting; + bool use_u2x; + + // U2X mode is needed for baud rates higher than (CPU Hz / 16) + if (baud > F_CPU / 16) { + use_u2x = true; + } else { + // figure out if U2X mode would allow for a better connection + + // calculate the percent difference between the baud-rate specified and + // the real baud rate for both U2X and non-U2X mode (0-255 error percent) + uint8_t nonu2x_baud_error = abs((int)(255-((F_CPU/(16*(((F_CPU/8/baud-1)/2)+1))*255)/baud))); + uint8_t u2x_baud_error = abs((int)(255-((F_CPU/(8*(((F_CPU/4/baud-1)/2)+1))*255)/baud))); + + // prefer non-U2X mode because it handles clock skew better + use_u2x = (nonu2x_baud_error > u2x_baud_error); + } + + if (use_u2x) { + *_ucsra = 1 << _u2x; + baud_setting = (F_CPU / 4 / baud - 1) / 2; + } else { + *_ucsra = 0; + baud_setting = (F_CPU / 8 / baud - 1) / 2; + } + + // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register) + *_ubrrh = baud_setting >> 8; + *_ubrrl = baud_setting; + + sbi(*_ucsrb, _rxen); + sbi(*_ucsrb, _txen); + sbi(*_ucsrb, _rxcie); +} + +void HardwareSerial::end() +{ + cbi(*_ucsrb, _rxen); + cbi(*_ucsrb, _txen); + cbi(*_ucsrb, _rxcie); +} + +uint8_t HardwareSerial::available(void) +{ + return (RX_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) % RX_BUFFER_SIZE; +} + +int HardwareSerial::read(void) +{ + // if the head isn't ahead of the tail, we don't have any characters + if (_rx_buffer->head == _rx_buffer->tail) { + return -1; + } else { + unsigned char c = _rx_buffer->buffer[_rx_buffer->tail]; + _rx_buffer->tail = (_rx_buffer->tail + 1) % RX_BUFFER_SIZE; + return c; + } +} + +void HardwareSerial::flush() +{ + // don't reverse this or there may be problems if the RX interrupt + // occurs after reading the value of rx_buffer_head but before writing + // the value to rx_buffer_tail; the previous value of rx_buffer_head + // may be written to rx_buffer_tail, making it appear as if the buffer + // don't reverse this or there may be problems if the RX interrupt + // occurs after reading the value of rx_buffer_head but before writing + // the value to rx_buffer_tail; the previous value of rx_buffer_head + // may be written to rx_buffer_tail, making it appear as if the buffer + // were full, not empty. + _rx_buffer->head = _rx_buffer->tail; +} + +void HardwareSerial::write(uint8_t c) +{ + while (!((*_ucsra) & (1 << _udre))) + ; + + *_udr = c; +} + +// Preinstantiate Objects ////////////////////////////////////////////////////// + +#if defined(__AVR_ATmega8__) +HardwareSerial Serial(&rx_buffer, &UBRRH, &UBRRL, &UCSRA, &UCSRB, &UDR, RXEN, TXEN, RXCIE, UDRE, U2X); +#else +HardwareSerial Serial(&rx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRE0, U2X0); +#endif + +#if defined(__AVR_ATmega1280__) +HardwareSerial Serial1(&rx_buffer1, &UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UDR1, RXEN1, TXEN1, RXCIE1, UDRE1, U2X1); +HardwareSerial Serial2(&rx_buffer2, &UBRR2H, &UBRR2L, &UCSR2A, &UCSR2B, &UDR2, RXEN2, TXEN2, RXCIE2, UDRE2, U2X2); +HardwareSerial Serial3(&rx_buffer3, &UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UDR3, RXEN3, TXEN3, RXCIE3, UDRE3, U2X3); +#endif diff --git a/arduino-0018-linux/hardware/arduino/cores/arduino/HardwareSerial.h b/arduino-0018-linux/hardware/arduino/cores/arduino/HardwareSerial.h new file mode 100755 index 0000000..6b620ed --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/cores/arduino/HardwareSerial.h @@ -0,0 +1,66 @@ +/* + HardwareSerial.h - Hardware serial library for Wiring + Copyright (c) 2006 Nicholas Zambetti. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef HardwareSerial_h +#define HardwareSerial_h + +#include + +#include "Print.h" + +struct ring_buffer; + +class HardwareSerial : public Print +{ + private: + ring_buffer *_rx_buffer; + volatile uint8_t *_ubrrh; + volatile uint8_t *_ubrrl; + volatile uint8_t *_ucsra; + volatile uint8_t *_ucsrb; + volatile uint8_t *_udr; + uint8_t _rxen; + uint8_t _txen; + uint8_t _rxcie; + uint8_t _udre; + uint8_t _u2x; + public: + HardwareSerial(ring_buffer *rx_buffer, + volatile uint8_t *ubrrh, volatile uint8_t *ubrrl, + volatile uint8_t *ucsra, volatile uint8_t *ucsrb, + volatile uint8_t *udr, + uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x); + void begin(long); + void end(); + uint8_t available(void); + int read(void); + void flush(void); + virtual void write(uint8_t); + using Print::write; // pull in write(str) and write(buf, size) from Print +}; + +extern HardwareSerial Serial; + +#if defined(__AVR_ATmega1280__) +extern HardwareSerial Serial1; +extern HardwareSerial Serial2; +extern HardwareSerial Serial3; +#endif + +#endif diff --git a/arduino-0018-linux/hardware/arduino/cores/arduino/Print.cpp b/arduino-0018-linux/hardware/arduino/cores/arduino/Print.cpp new file mode 100755 index 0000000..fb5afc1 --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/cores/arduino/Print.cpp @@ -0,0 +1,206 @@ +/* + Print.cpp - Base class that provides print() and println() + Copyright (c) 2008 David A. Mellis. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Modified 23 November 2006 by David A. Mellis + */ + +#include +#include +#include +#include "wiring.h" + +#include "Print.h" + +// Public Methods ////////////////////////////////////////////////////////////// + +/* default implementation: may be overridden */ +void Print::write(const char *str) +{ + while (*str) + write(*str++); +} + +/* default implementation: may be overridden */ +void Print::write(const uint8_t *buffer, size_t size) +{ + while (size--) + write(*buffer++); +} + +void Print::print(const char str[]) +{ + write(str); +} + +void Print::print(char c, int base) +{ + print((long) c, base); +} + +void Print::print(unsigned char b, int base) +{ + print((unsigned long) b, base); +} + +void Print::print(int n, int base) +{ + print((long) n, base); +} + +void Print::print(unsigned int n, int base) +{ + print((unsigned long) n, base); +} + +void Print::print(long n, int base) +{ + if (base == 0) { + write(n); + } else if (base == 10) { + if (n < 0) { + print('-'); + n = -n; + } + printNumber(n, 10); + } else { + printNumber(n, base); + } +} + +void Print::print(unsigned long n, int base) +{ + if (base == 0) write(n); + else printNumber(n, base); +} + +void Print::print(double n, int digits) +{ + printFloat(n, digits); +} + +void Print::println(void) +{ + print('\r'); + print('\n'); +} + +void Print::println(const char c[]) +{ + print(c); + println(); +} + +void Print::println(char c, int base) +{ + print(c, base); + println(); +} + +void Print::println(unsigned char b, int base) +{ + print(b, base); + println(); +} + +void Print::println(int n, int base) +{ + print(n, base); + println(); +} + +void Print::println(unsigned int n, int base) +{ + print(n, base); + println(); +} + +void Print::println(long n, int base) +{ + print(n, base); + println(); +} + +void Print::println(unsigned long n, int base) +{ + print(n, base); + println(); +} + +void Print::println(double n, int digits) +{ + print(n, digits); + println(); +} + +// Private Methods ///////////////////////////////////////////////////////////// + +void Print::printNumber(unsigned long n, uint8_t base) +{ + unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars. + unsigned long i = 0; + + if (n == 0) { + print('0'); + return; + } + + while (n > 0) { + buf[i++] = n % base; + n /= base; + } + + for (; i > 0; i--) + print((char) (buf[i - 1] < 10 ? + '0' + buf[i - 1] : + 'A' + buf[i - 1] - 10)); +} + +void Print::printFloat(double number, uint8_t digits) +{ + // Handle negative numbers + if (number < 0.0) + { + print('-'); + number = -number; + } + + // Round correctly so that print(1.999, 2) prints as "2.00" + double rounding = 0.5; + for (uint8_t i=0; i 0) + print("."); + + // Extract digits from the remainder one at a time + while (digits-- > 0) + { + remainder *= 10.0; + int toPrint = int(remainder); + print(toPrint); + remainder -= toPrint; + } +} diff --git a/arduino-0018-linux/hardware/arduino/cores/arduino/Print.h b/arduino-0018-linux/hardware/arduino/cores/arduino/Print.h new file mode 100755 index 0000000..8a1e2b8 --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/cores/arduino/Print.h @@ -0,0 +1,62 @@ +/* + Print.h - Base class that provides print() and println() + Copyright (c) 2008 David A. Mellis. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef Print_h +#define Print_h + +#include +#include // for size_t + +#define DEC 10 +#define HEX 16 +#define OCT 8 +#define BIN 2 +#define BYTE 0 + +class Print +{ + private: + void printNumber(unsigned long, uint8_t); + void printFloat(double, uint8_t); + public: + virtual void write(uint8_t) = 0; + virtual void write(const char *str); + virtual void write(const uint8_t *buffer, size_t size); + + void print(const char[]); + void print(char, int = BYTE); + void print(unsigned char, int = BYTE); + void print(int, int = DEC); + void print(unsigned int, int = DEC); + void print(long, int = DEC); + void print(unsigned long, int = DEC); + void print(double, int = 2); + + void println(const char[]); + void println(char, int = BYTE); + void println(unsigned char, int = BYTE); + void println(int, int = DEC); + void println(unsigned int, int = DEC); + void println(long, int = DEC); + void println(unsigned long, int = DEC); + void println(double, int = 2); + void println(void); +}; + +#endif diff --git a/arduino-0018-linux/hardware/arduino/cores/arduino/Tone.cpp b/arduino-0018-linux/hardware/arduino/cores/arduino/Tone.cpp new file mode 100755 index 0000000..827fe49 --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/cores/arduino/Tone.cpp @@ -0,0 +1,515 @@ +/* Tone.cpp + + A Tone Generator Library + + Written by Brett Hagman + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Version Modified By Date Comments +------- ----------- -------- -------- +0001 B Hagman 09/08/02 Initial coding +0002 B Hagman 09/08/18 Multiple pins +0003 B Hagman 09/08/18 Moved initialization from constructor to begin() +0004 B Hagman 09/09/26 Fixed problems with ATmega8 +0005 B Hagman 09/11/23 Scanned prescalars for best fit on 8 bit timers + 09/11/25 Changed pin toggle method to XOR + 09/11/25 Fixed timer0 from being excluded +0006 D Mellis 09/12/29 Replaced objects with functions + +*************************************************/ + +#include +#include +#include +#include + +#if defined(__AVR_ATmega8__) +#define TCCR2A TCCR2 +#define TCCR2B TCCR2 +#define COM2A1 COM21 +#define COM2A0 COM20 +#define OCR2A OCR2 +#define TIMSK2 TIMSK +#define OCIE2A OCIE2 +#define TIMER2_COMPA_vect TIMER2_COMP_vect +#define TIMSK1 TIMSK +#endif + +// timerx_toggle_count: +// > 0 - duration specified +// = 0 - stopped +// < 0 - infinitely (until stop() method called, or new play() called) + +#if !defined(__AVR_ATmega8__) +volatile long timer0_toggle_count; +volatile uint8_t *timer0_pin_port; +volatile uint8_t timer0_pin_mask; +#endif + +volatile long timer1_toggle_count; +volatile uint8_t *timer1_pin_port; +volatile uint8_t timer1_pin_mask; +volatile long timer2_toggle_count; +volatile uint8_t *timer2_pin_port; +volatile uint8_t timer2_pin_mask; + +#if defined(__AVR_ATmega1280__) +volatile long timer3_toggle_count; +volatile uint8_t *timer3_pin_port; +volatile uint8_t timer3_pin_mask; +volatile long timer4_toggle_count; +volatile uint8_t *timer4_pin_port; +volatile uint8_t timer4_pin_mask; +volatile long timer5_toggle_count; +volatile uint8_t *timer5_pin_port; +volatile uint8_t timer5_pin_mask; +#endif + + +#if defined(__AVR_ATmega1280__) + +#define AVAILABLE_TONE_PINS 1 + +const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 3, 4, 5, 1, 0 */ }; +static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255, 255, 255, 255, 255 */ }; + +#elif defined(__AVR_ATmega8__) + +#define AVAILABLE_TONE_PINS 1 + +const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 1 */ }; +static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255 */ }; + +#else + +#define AVAILABLE_TONE_PINS 1 + +// Leave timer 0 to last. +const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 1, 0 */ }; +static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255, 255 */ }; + +#endif + + + +static int8_t toneBegin(uint8_t _pin) +{ + int8_t _timer = -1; + + // if we're already using the pin, the timer should be configured. + for (int i = 0; i < AVAILABLE_TONE_PINS; i++) { + if (tone_pins[i] == _pin) { + return pgm_read_byte(tone_pin_to_timer_PGM + i); + } + } + + // search for an unused timer. + for (int i = 0; i < AVAILABLE_TONE_PINS; i++) { + if (tone_pins[i] == 255) { + tone_pins[i] = _pin; + _timer = pgm_read_byte(tone_pin_to_timer_PGM + i); + break; + } + } + + if (_timer != -1) + { + // Set timer specific stuff + // All timers in CTC mode + // 8 bit timers will require changing prescalar values, + // whereas 16 bit timers are set to either ck/1 or ck/64 prescalar + switch (_timer) + { +#if !defined(__AVR_ATmega8__) + case 0: + // 8 bit timer + TCCR0A = 0; + TCCR0B = 0; + bitWrite(TCCR0A, WGM01, 1); + bitWrite(TCCR0B, CS00, 1); + timer0_pin_port = portOutputRegister(digitalPinToPort(_pin)); + timer0_pin_mask = digitalPinToBitMask(_pin); + break; +#endif + + case 1: + // 16 bit timer + TCCR1A = 0; + TCCR1B = 0; + bitWrite(TCCR1B, WGM12, 1); + bitWrite(TCCR1B, CS10, 1); + timer1_pin_port = portOutputRegister(digitalPinToPort(_pin)); + timer1_pin_mask = digitalPinToBitMask(_pin); + break; + case 2: + // 8 bit timer + TCCR2A = 0; + TCCR2B = 0; + bitWrite(TCCR2A, WGM21, 1); + bitWrite(TCCR2B, CS20, 1); + timer2_pin_port = portOutputRegister(digitalPinToPort(_pin)); + timer2_pin_mask = digitalPinToBitMask(_pin); + break; + +#if defined(__AVR_ATmega1280__) + case 3: + // 16 bit timer + TCCR3A = 0; + TCCR3B = 0; + bitWrite(TCCR3B, WGM32, 1); + bitWrite(TCCR3B, CS30, 1); + timer3_pin_port = portOutputRegister(digitalPinToPort(_pin)); + timer3_pin_mask = digitalPinToBitMask(_pin); + break; + case 4: + // 16 bit timer + TCCR4A = 0; + TCCR4B = 0; + bitWrite(TCCR4B, WGM42, 1); + bitWrite(TCCR4B, CS40, 1); + timer4_pin_port = portOutputRegister(digitalPinToPort(_pin)); + timer4_pin_mask = digitalPinToBitMask(_pin); + break; + case 5: + // 16 bit timer + TCCR5A = 0; + TCCR5B = 0; + bitWrite(TCCR5B, WGM52, 1); + bitWrite(TCCR5B, CS50, 1); + timer5_pin_port = portOutputRegister(digitalPinToPort(_pin)); + timer5_pin_mask = digitalPinToBitMask(_pin); + break; +#endif + } + } + + return _timer; +} + + + +// frequency (in hertz) and duration (in milliseconds). + +void tone(uint8_t _pin, unsigned int frequency, unsigned long duration) +{ + uint8_t prescalarbits = 0b001; + long toggle_count = 0; + uint32_t ocr = 0; + int8_t _timer; + + _timer = toneBegin(_pin); + + if (_timer >= 0) + { + // Set the pinMode as OUTPUT + pinMode(_pin, OUTPUT); + + // if we are using an 8 bit timer, scan through prescalars to find the best fit + if (_timer == 0 || _timer == 2) + { + ocr = F_CPU / frequency / 2 - 1; + prescalarbits = 0b001; // ck/1: same for both timers + if (ocr > 255) + { + ocr = F_CPU / frequency / 2 / 8 - 1; + prescalarbits = 0b010; // ck/8: same for both timers + + if (_timer == 2 && ocr > 255) + { + ocr = F_CPU / frequency / 2 / 32 - 1; + prescalarbits = 0b011; + } + + if (ocr > 255) + { + ocr = F_CPU / frequency / 2 / 64 - 1; + prescalarbits = _timer == 0 ? 0b011 : 0b100; + + if (_timer == 2 && ocr > 255) + { + ocr = F_CPU / frequency / 2 / 128 - 1; + prescalarbits = 0b101; + } + + if (ocr > 255) + { + ocr = F_CPU / frequency / 2 / 256 - 1; + prescalarbits = _timer == 0 ? 0b100 : 0b110; + if (ocr > 255) + { + // can't do any better than /1024 + ocr = F_CPU / frequency / 2 / 1024 - 1; + prescalarbits = _timer == 0 ? 0b101 : 0b111; + } + } + } + } + +#if !defined(__AVR_ATmega8__) + if (_timer == 0) + TCCR0B = prescalarbits; + else +#endif + TCCR2B = prescalarbits; + } + else + { + // two choices for the 16 bit timers: ck/1 or ck/64 + ocr = F_CPU / frequency / 2 - 1; + + prescalarbits = 0b001; + if (ocr > 0xffff) + { + ocr = F_CPU / frequency / 2 / 64 - 1; + prescalarbits = 0b011; + } + + if (_timer == 1) + TCCR1B = (TCCR1B & 0b11111000) | prescalarbits; +#if defined(__AVR_ATmega1280__) + else if (_timer == 3) + TCCR3B = (TCCR3B & 0b11111000) | prescalarbits; + else if (_timer == 4) + TCCR4B = (TCCR4B & 0b11111000) | prescalarbits; + else if (_timer == 5) + TCCR5B = (TCCR5B & 0b11111000) | prescalarbits; +#endif + + } + + + // Calculate the toggle count + if (duration > 0) + { + toggle_count = 2 * frequency * duration / 1000; + } + else + { + toggle_count = -1; + } + + // Set the OCR for the given timer, + // set the toggle count, + // then turn on the interrupts + switch (_timer) + { + +#if !defined(__AVR_ATmega8__) + case 0: + OCR0A = ocr; + timer0_toggle_count = toggle_count; + bitWrite(TIMSK0, OCIE0A, 1); + break; +#endif + + case 1: + OCR1A = ocr; + timer1_toggle_count = toggle_count; + bitWrite(TIMSK1, OCIE1A, 1); + break; + case 2: + OCR2A = ocr; + timer2_toggle_count = toggle_count; + bitWrite(TIMSK2, OCIE2A, 1); + break; + +#if defined(__AVR_ATmega1280__) + case 3: + OCR3A = ocr; + timer3_toggle_count = toggle_count; + bitWrite(TIMSK3, OCIE3A, 1); + break; + case 4: + OCR4A = ocr; + timer4_toggle_count = toggle_count; + bitWrite(TIMSK4, OCIE4A, 1); + break; + case 5: + OCR5A = ocr; + timer5_toggle_count = toggle_count; + bitWrite(TIMSK5, OCIE5A, 1); + break; +#endif + + } + } +} + + +void noTone(uint8_t _pin) +{ + int8_t _timer = -1; + + for (int i = 0; i < AVAILABLE_TONE_PINS; i++) { + if (tone_pins[i] == _pin) { + _timer = pgm_read_byte(tone_pin_to_timer_PGM + i); + tone_pins[i] = 255; + } + } + + switch (_timer) + { +#if defined(__AVR_ATmega8__) + case 1: + bitWrite(TIMSK1, OCIE1A, 0); + break; + case 2: + bitWrite(TIMSK2, OCIE2A, 0); + break; + +#else + case 0: + TIMSK0 = 0; + break; + case 1: + TIMSK1 = 0; + break; + case 2: + TIMSK2 = 0; + break; +#endif + +#if defined(__AVR_ATmega1280__) + case 3: + TIMSK3 = 0; + break; + case 4: + TIMSK4 = 0; + break; + case 5: + TIMSK5 = 0; + break; +#endif + } + + digitalWrite(_pin, 0); +} + +#if 0 +#if !defined(__AVR_ATmega8__) +ISR(TIMER0_COMPA_vect) +{ + if (timer0_toggle_count != 0) + { + // toggle the pin + *timer0_pin_port ^= timer0_pin_mask; + + if (timer0_toggle_count > 0) + timer0_toggle_count--; + } + else + { + TIMSK0 = 0; // disable the interrupt + *timer0_pin_port &= ~(timer0_pin_mask); // keep pin low after stop + } +} +#endif + + +ISR(TIMER1_COMPA_vect) +{ + if (timer1_toggle_count != 0) + { + // toggle the pin + *timer1_pin_port ^= timer1_pin_mask; + + if (timer1_toggle_count > 0) + timer1_toggle_count--; + } + else + { + TIMSK1 = 0; // disable the interrupt + *timer1_pin_port &= ~(timer1_pin_mask); // keep pin low after stop + } +} +#endif + + +ISR(TIMER2_COMPA_vect) +{ + + if (timer2_toggle_count != 0) + { + // toggle the pin + *timer2_pin_port ^= timer2_pin_mask; + + if (timer2_toggle_count > 0) + timer2_toggle_count--; + } + else + { + TIMSK2 = 0; // disable the interrupt + *timer2_pin_port &= ~(timer2_pin_mask); // keep pin low after stop + } +} + + + +//#if defined(__AVR_ATmega1280__) +#if 0 + +ISR(TIMER3_COMPA_vect) +{ + if (timer3_toggle_count != 0) + { + // toggle the pin + *timer3_pin_port ^= timer3_pin_mask; + + if (timer3_toggle_count > 0) + timer3_toggle_count--; + } + else + { + TIMSK3 = 0; // disable the interrupt + *timer3_pin_port &= ~(timer3_pin_mask); // keep pin low after stop + } +} + +ISR(TIMER4_COMPA_vect) +{ + if (timer4_toggle_count != 0) + { + // toggle the pin + *timer4_pin_port ^= timer4_pin_mask; + + if (timer4_toggle_count > 0) + timer4_toggle_count--; + } + else + { + TIMSK4 = 0; // disable the interrupt + *timer4_pin_port &= ~(timer4_pin_mask); // keep pin low after stop + } +} + +ISR(TIMER5_COMPA_vect) +{ + if (timer5_toggle_count != 0) + { + // toggle the pin + *timer5_pin_port ^= timer5_pin_mask; + + if (timer5_toggle_count > 0) + timer5_toggle_count--; + } + else + { + TIMSK5 = 0; // disable the interrupt + *timer5_pin_port &= ~(timer5_pin_mask); // keep pin low after stop + } +} + +#endif diff --git a/arduino-0018-linux/hardware/arduino/cores/arduino/WConstants.h b/arduino-0018-linux/hardware/arduino/cores/arduino/WConstants.h new file mode 100644 index 0000000..3e19ac4 --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/cores/arduino/WConstants.h @@ -0,0 +1 @@ +#include "wiring.h" diff --git a/arduino-0018-linux/hardware/arduino/cores/arduino/WInterrupts.c b/arduino-0018-linux/hardware/arduino/cores/arduino/WInterrupts.c new file mode 100755 index 0000000..69a78b0 --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/cores/arduino/WInterrupts.c @@ -0,0 +1,215 @@ +/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + Part of the Wiring project - http://wiring.uniandes.edu.co + + Copyright (c) 2004-05 Hernando Barragan + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General + Public License along with this library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, + Boston, MA 02111-1307 USA + + Modified 24 November 2006 by David A. Mellis +*/ + +#include +#include +#include +#include +#include + +#include "WConstants.h" +#include "wiring_private.h" + +volatile static voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS]; +// volatile static voidFuncPtr twiIntFunc; + +#if defined(__AVR_ATmega8__) +#define EICRA MCUCR +#define EIMSK GICR +#endif + +void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) { + if(interruptNum < EXTERNAL_NUM_INTERRUPTS) { + intFunc[interruptNum] = userFunc; + + // Configure the interrupt mode (trigger on low input, any change, rising + // edge, or falling edge). The mode constants were chosen to correspond + // to the configuration bits in the hardware register, so we simply shift + // the mode into place. + + // Enable the interrupt. + + switch (interruptNum) { +#if defined(__AVR_ATmega1280__) + case 2: + EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00); + EIMSK |= (1 << INT0); + break; + case 3: + EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10); + EIMSK |= (1 << INT1); + break; + case 4: + EICRA = (EICRA & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20); + EIMSK |= (1 << INT2); + break; + case 5: + EICRA = (EICRA & ~((1 << ISC30) | (1 << ISC31))) | (mode << ISC30); + EIMSK |= (1 << INT3); + break; + case 0: + EICRB = (EICRB & ~((1 << ISC40) | (1 << ISC41))) | (mode << ISC40); + EIMSK |= (1 << INT4); + break; + case 1: + EICRB = (EICRB & ~((1 << ISC50) | (1 << ISC51))) | (mode << ISC50); + EIMSK |= (1 << INT5); + break; + case 6: + EICRB = (EICRB & ~((1 << ISC60) | (1 << ISC61))) | (mode << ISC60); + EIMSK |= (1 << INT6); + break; + case 7: + EICRB = (EICRB & ~((1 << ISC70) | (1 << ISC71))) | (mode << ISC70); + EIMSK |= (1 << INT7); + break; +#else + case 0: + EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00); + EIMSK |= (1 << INT0); + break; + case 1: + EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10); + EIMSK |= (1 << INT1); + break; +#endif + } + } +} + +void detachInterrupt(uint8_t interruptNum) { + if(interruptNum < EXTERNAL_NUM_INTERRUPTS) { + // Disable the interrupt. (We can't assume that interruptNum is equal + // to the number of the EIMSK bit to clear, as this isn't true on the + // ATmega8. There, INT0 is 6 and INT1 is 7.) + switch (interruptNum) { +#if defined(__AVR_ATmega1280__) + case 2: + EIMSK &= ~(1 << INT0); + break; + case 3: + EIMSK &= ~(1 << INT1); + break; + case 4: + EIMSK &= ~(1 << INT2); + break; + case 5: + EIMSK &= ~(1 << INT3); + break; + case 0: + EIMSK &= ~(1 << INT4); + break; + case 1: + EIMSK &= ~(1 << INT5); + break; + case 6: + EIMSK &= ~(1 << INT6); + break; + case 7: + EIMSK &= ~(1 << INT7); + break; +#else + case 0: + EIMSK &= ~(1 << INT0); + break; + case 1: + EIMSK &= ~(1 << INT1); + break; +#endif + } + + intFunc[interruptNum] = 0; + } +} + +/* +void attachInterruptTwi(void (*userFunc)(void) ) { + twiIntFunc = userFunc; +} +*/ + +#if defined(__AVR_ATmega1280__) + +SIGNAL(INT0_vect) { + if(intFunc[EXTERNAL_INT_2]) + intFunc[EXTERNAL_INT_2](); +} + +SIGNAL(INT1_vect) { + if(intFunc[EXTERNAL_INT_3]) + intFunc[EXTERNAL_INT_3](); +} + +SIGNAL(INT2_vect) { + if(intFunc[EXTERNAL_INT_4]) + intFunc[EXTERNAL_INT_4](); +} + +SIGNAL(INT3_vect) { + if(intFunc[EXTERNAL_INT_5]) + intFunc[EXTERNAL_INT_5](); +} + +SIGNAL(INT4_vect) { + if(intFunc[EXTERNAL_INT_0]) + intFunc[EXTERNAL_INT_0](); +} + +SIGNAL(INT5_vect) { + if(intFunc[EXTERNAL_INT_1]) + intFunc[EXTERNAL_INT_1](); +} + +SIGNAL(INT6_vect) { + if(intFunc[EXTERNAL_INT_6]) + intFunc[EXTERNAL_INT_6](); +} + +SIGNAL(INT7_vect) { + if(intFunc[EXTERNAL_INT_7]) + intFunc[EXTERNAL_INT_7](); +} + +#else + +SIGNAL(INT0_vect) { + if(intFunc[EXTERNAL_INT_0]) + intFunc[EXTERNAL_INT_0](); +} + +SIGNAL(INT1_vect) { + if(intFunc[EXTERNAL_INT_1]) + intFunc[EXTERNAL_INT_1](); +} + +#endif + +/* +SIGNAL(SIG_2WIRE_SERIAL) { + if(twiIntFunc) + twiIntFunc(); +} +*/ + diff --git a/arduino-0018-linux/hardware/arduino/cores/arduino/WMath.cpp b/arduino-0018-linux/hardware/arduino/cores/arduino/WMath.cpp new file mode 100644 index 0000000..2120c4c --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/cores/arduino/WMath.cpp @@ -0,0 +1,60 @@ +/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + Part of the Wiring project - http://wiring.org.co + Copyright (c) 2004-06 Hernando Barragan + Modified 13 August 2006, David A. Mellis for Arduino - http://www.arduino.cc/ + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General + Public License along with this library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, + Boston, MA 02111-1307 USA + + $Id$ +*/ + +extern "C" { + #include "stdlib.h" +} + +void randomSeed(unsigned int seed) +{ + if (seed != 0) { + srandom(seed); + } +} + +long random(long howbig) +{ + if (howbig == 0) { + return 0; + } + return random() % howbig; +} + +long random(long howsmall, long howbig) +{ + if (howsmall >= howbig) { + return howsmall; + } + long diff = howbig - howsmall; + return random(diff) + howsmall; +} + +long map(long x, long in_min, long in_max, long out_min, long out_max) +{ + return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; +} + +unsigned int makeWord(unsigned int w) { return w; } +unsigned int makeWord(unsigned char h, unsigned char l) { return (h << 8) | l; } \ No newline at end of file diff --git a/arduino-0018-linux/hardware/arduino/cores/arduino/WProgram.h b/arduino-0018-linux/hardware/arduino/cores/arduino/WProgram.h new file mode 100755 index 0000000..f5d3e29 --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/cores/arduino/WProgram.h @@ -0,0 +1,32 @@ +#ifndef WProgram_h +#define WProgram_h + +#include +#include +#include + +#include + +#include "wiring.h" + +#ifdef __cplusplus +#include "HardwareSerial.h" + +uint16_t makeWord(uint16_t w); +uint16_t makeWord(byte h, byte l); + +#define word(...) makeWord(__VA_ARGS__) + +unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); + +void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0); +void noTone(uint8_t _pin); + +// WMath prototypes +long random(long); +long random(long, long); +void randomSeed(unsigned int); +long map(long, long, long, long, long); +#endif + +#endif \ No newline at end of file diff --git a/arduino-0018-linux/hardware/arduino/cores/arduino/binary.h b/arduino-0018-linux/hardware/arduino/cores/arduino/binary.h new file mode 100644 index 0000000..af14980 --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/cores/arduino/binary.h @@ -0,0 +1,515 @@ +#ifndef Binary_h +#define Binary_h + +#define B0 0 +#define B00 0 +#define B000 0 +#define B0000 0 +#define B00000 0 +#define B000000 0 +#define B0000000 0 +#define B00000000 0 +#define B1 1 +#define B01 1 +#define B001 1 +#define B0001 1 +#define B00001 1 +#define B000001 1 +#define B0000001 1 +#define B00000001 1 +#define B10 2 +#define B010 2 +#define B0010 2 +#define B00010 2 +#define B000010 2 +#define B0000010 2 +#define B00000010 2 +#define B11 3 +#define B011 3 +#define B0011 3 +#define B00011 3 +#define B000011 3 +#define B0000011 3 +#define B00000011 3 +#define B100 4 +#define B0100 4 +#define B00100 4 +#define B000100 4 +#define B0000100 4 +#define B00000100 4 +#define B101 5 +#define B0101 5 +#define B00101 5 +#define B000101 5 +#define B0000101 5 +#define B00000101 5 +#define B110 6 +#define B0110 6 +#define B00110 6 +#define B000110 6 +#define B0000110 6 +#define B00000110 6 +#define B111 7 +#define B0111 7 +#define B00111 7 +#define B000111 7 +#define B0000111 7 +#define B00000111 7 +#define B1000 8 +#define B01000 8 +#define B001000 8 +#define B0001000 8 +#define B00001000 8 +#define B1001 9 +#define B01001 9 +#define B001001 9 +#define B0001001 9 +#define B00001001 9 +#define B1010 10 +#define B01010 10 +#define B001010 10 +#define B0001010 10 +#define B00001010 10 +#define B1011 11 +#define B01011 11 +#define B001011 11 +#define B0001011 11 +#define B00001011 11 +#define B1100 12 +#define B01100 12 +#define B001100 12 +#define B0001100 12 +#define B00001100 12 +#define B1101 13 +#define B01101 13 +#define B001101 13 +#define B0001101 13 +#define B00001101 13 +#define B1110 14 +#define B01110 14 +#define B001110 14 +#define B0001110 14 +#define B00001110 14 +#define B1111 15 +#define B01111 15 +#define B001111 15 +#define B0001111 15 +#define B00001111 15 +#define B10000 16 +#define B010000 16 +#define B0010000 16 +#define B00010000 16 +#define B10001 17 +#define B010001 17 +#define B0010001 17 +#define B00010001 17 +#define B10010 18 +#define B010010 18 +#define B0010010 18 +#define B00010010 18 +#define B10011 19 +#define B010011 19 +#define B0010011 19 +#define B00010011 19 +#define B10100 20 +#define B010100 20 +#define B0010100 20 +#define B00010100 20 +#define B10101 21 +#define B010101 21 +#define B0010101 21 +#define B00010101 21 +#define B10110 22 +#define B010110 22 +#define B0010110 22 +#define B00010110 22 +#define B10111 23 +#define B010111 23 +#define B0010111 23 +#define B00010111 23 +#define B11000 24 +#define B011000 24 +#define B0011000 24 +#define B00011000 24 +#define B11001 25 +#define B011001 25 +#define B0011001 25 +#define B00011001 25 +#define B11010 26 +#define B011010 26 +#define B0011010 26 +#define B00011010 26 +#define B11011 27 +#define B011011 27 +#define B0011011 27 +#define B00011011 27 +#define B11100 28 +#define B011100 28 +#define B0011100 28 +#define B00011100 28 +#define B11101 29 +#define B011101 29 +#define B0011101 29 +#define B00011101 29 +#define B11110 30 +#define B011110 30 +#define B0011110 30 +#define B00011110 30 +#define B11111 31 +#define B011111 31 +#define B0011111 31 +#define B00011111 31 +#define B100000 32 +#define B0100000 32 +#define B00100000 32 +#define B100001 33 +#define B0100001 33 +#define B00100001 33 +#define B100010 34 +#define B0100010 34 +#define B00100010 34 +#define B100011 35 +#define B0100011 35 +#define B00100011 35 +#define B100100 36 +#define B0100100 36 +#define B00100100 36 +#define B100101 37 +#define B0100101 37 +#define B00100101 37 +#define B100110 38 +#define B0100110 38 +#define B00100110 38 +#define B100111 39 +#define B0100111 39 +#define B00100111 39 +#define B101000 40 +#define B0101000 40 +#define B00101000 40 +#define B101001 41 +#define B0101001 41 +#define B00101001 41 +#define B101010 42 +#define B0101010 42 +#define B00101010 42 +#define B101011 43 +#define B0101011 43 +#define B00101011 43 +#define B101100 44 +#define B0101100 44 +#define B00101100 44 +#define B101101 45 +#define B0101101 45 +#define B00101101 45 +#define B101110 46 +#define B0101110 46 +#define B00101110 46 +#define B101111 47 +#define B0101111 47 +#define B00101111 47 +#define B110000 48 +#define B0110000 48 +#define B00110000 48 +#define B110001 49 +#define B0110001 49 +#define B00110001 49 +#define B110010 50 +#define B0110010 50 +#define B00110010 50 +#define B110011 51 +#define B0110011 51 +#define B00110011 51 +#define B110100 52 +#define B0110100 52 +#define B00110100 52 +#define B110101 53 +#define B0110101 53 +#define B00110101 53 +#define B110110 54 +#define B0110110 54 +#define B00110110 54 +#define B110111 55 +#define B0110111 55 +#define B00110111 55 +#define B111000 56 +#define B0111000 56 +#define B00111000 56 +#define B111001 57 +#define B0111001 57 +#define B00111001 57 +#define B111010 58 +#define B0111010 58 +#define B00111010 58 +#define B111011 59 +#define B0111011 59 +#define B00111011 59 +#define B111100 60 +#define B0111100 60 +#define B00111100 60 +#define B111101 61 +#define B0111101 61 +#define B00111101 61 +#define B111110 62 +#define B0111110 62 +#define B00111110 62 +#define B111111 63 +#define B0111111 63 +#define B00111111 63 +#define B1000000 64 +#define B01000000 64 +#define B1000001 65 +#define B01000001 65 +#define B1000010 66 +#define B01000010 66 +#define B1000011 67 +#define B01000011 67 +#define B1000100 68 +#define B01000100 68 +#define B1000101 69 +#define B01000101 69 +#define B1000110 70 +#define B01000110 70 +#define B1000111 71 +#define B01000111 71 +#define B1001000 72 +#define B01001000 72 +#define B1001001 73 +#define B01001001 73 +#define B1001010 74 +#define B01001010 74 +#define B1001011 75 +#define B01001011 75 +#define B1001100 76 +#define B01001100 76 +#define B1001101 77 +#define B01001101 77 +#define B1001110 78 +#define B01001110 78 +#define B1001111 79 +#define B01001111 79 +#define B1010000 80 +#define B01010000 80 +#define B1010001 81 +#define B01010001 81 +#define B1010010 82 +#define B01010010 82 +#define B1010011 83 +#define B01010011 83 +#define B1010100 84 +#define B01010100 84 +#define B1010101 85 +#define B01010101 85 +#define B1010110 86 +#define B01010110 86 +#define B1010111 87 +#define B01010111 87 +#define B1011000 88 +#define B01011000 88 +#define B1011001 89 +#define B01011001 89 +#define B1011010 90 +#define B01011010 90 +#define B1011011 91 +#define B01011011 91 +#define B1011100 92 +#define B01011100 92 +#define B1011101 93 +#define B01011101 93 +#define B1011110 94 +#define B01011110 94 +#define B1011111 95 +#define B01011111 95 +#define B1100000 96 +#define B01100000 96 +#define B1100001 97 +#define B01100001 97 +#define B1100010 98 +#define B01100010 98 +#define B1100011 99 +#define B01100011 99 +#define B1100100 100 +#define B01100100 100 +#define B1100101 101 +#define B01100101 101 +#define B1100110 102 +#define B01100110 102 +#define B1100111 103 +#define B01100111 103 +#define B1101000 104 +#define B01101000 104 +#define B1101001 105 +#define B01101001 105 +#define B1101010 106 +#define B01101010 106 +#define B1101011 107 +#define B01101011 107 +#define B1101100 108 +#define B01101100 108 +#define B1101101 109 +#define B01101101 109 +#define B1101110 110 +#define B01101110 110 +#define B1101111 111 +#define B01101111 111 +#define B1110000 112 +#define B01110000 112 +#define B1110001 113 +#define B01110001 113 +#define B1110010 114 +#define B01110010 114 +#define B1110011 115 +#define B01110011 115 +#define B1110100 116 +#define B01110100 116 +#define B1110101 117 +#define B01110101 117 +#define B1110110 118 +#define B01110110 118 +#define B1110111 119 +#define B01110111 119 +#define B1111000 120 +#define B01111000 120 +#define B1111001 121 +#define B01111001 121 +#define B1111010 122 +#define B01111010 122 +#define B1111011 123 +#define B01111011 123 +#define B1111100 124 +#define B01111100 124 +#define B1111101 125 +#define B01111101 125 +#define B1111110 126 +#define B01111110 126 +#define B1111111 127 +#define B01111111 127 +#define B10000000 128 +#define B10000001 129 +#define B10000010 130 +#define B10000011 131 +#define B10000100 132 +#define B10000101 133 +#define B10000110 134 +#define B10000111 135 +#define B10001000 136 +#define B10001001 137 +#define B10001010 138 +#define B10001011 139 +#define B10001100 140 +#define B10001101 141 +#define B10001110 142 +#define B10001111 143 +#define B10010000 144 +#define B10010001 145 +#define B10010010 146 +#define B10010011 147 +#define B10010100 148 +#define B10010101 149 +#define B10010110 150 +#define B10010111 151 +#define B10011000 152 +#define B10011001 153 +#define B10011010 154 +#define B10011011 155 +#define B10011100 156 +#define B10011101 157 +#define B10011110 158 +#define B10011111 159 +#define B10100000 160 +#define B10100001 161 +#define B10100010 162 +#define B10100011 163 +#define B10100100 164 +#define B10100101 165 +#define B10100110 166 +#define B10100111 167 +#define B10101000 168 +#define B10101001 169 +#define B10101010 170 +#define B10101011 171 +#define B10101100 172 +#define B10101101 173 +#define B10101110 174 +#define B10101111 175 +#define B10110000 176 +#define B10110001 177 +#define B10110010 178 +#define B10110011 179 +#define B10110100 180 +#define B10110101 181 +#define B10110110 182 +#define B10110111 183 +#define B10111000 184 +#define B10111001 185 +#define B10111010 186 +#define B10111011 187 +#define B10111100 188 +#define B10111101 189 +#define B10111110 190 +#define B10111111 191 +#define B11000000 192 +#define B11000001 193 +#define B11000010 194 +#define B11000011 195 +#define B11000100 196 +#define B11000101 197 +#define B11000110 198 +#define B11000111 199 +#define B11001000 200 +#define B11001001 201 +#define B11001010 202 +#define B11001011 203 +#define B11001100 204 +#define B11001101 205 +#define B11001110 206 +#define B11001111 207 +#define B11010000 208 +#define B11010001 209 +#define B11010010 210 +#define B11010011 211 +#define B11010100 212 +#define B11010101 213 +#define B11010110 214 +#define B11010111 215 +#define B11011000 216 +#define B11011001 217 +#define B11011010 218 +#define B11011011 219 +#define B11011100 220 +#define B11011101 221 +#define B11011110 222 +#define B11011111 223 +#define B11100000 224 +#define B11100001 225 +#define B11100010 226 +#define B11100011 227 +#define B11100100 228 +#define B11100101 229 +#define B11100110 230 +#define B11100111 231 +#define B11101000 232 +#define B11101001 233 +#define B11101010 234 +#define B11101011 235 +#define B11101100 236 +#define B11101101 237 +#define B11101110 238 +#define B11101111 239 +#define B11110000 240 +#define B11110001 241 +#define B11110010 242 +#define B11110011 243 +#define B11110100 244 +#define B11110101 245 +#define B11110110 246 +#define B11110111 247 +#define B11111000 248 +#define B11111001 249 +#define B11111010 250 +#define B11111011 251 +#define B11111100 252 +#define B11111101 253 +#define B11111110 254 +#define B11111111 255 + +#endif diff --git a/arduino-0018-linux/hardware/arduino/cores/arduino/main.cpp b/arduino-0018-linux/hardware/arduino/cores/arduino/main.cpp new file mode 100755 index 0000000..cc6e81d --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/cores/arduino/main.cpp @@ -0,0 +1,14 @@ +#include + +int main(void) +{ + init(); + + setup(); + + for (;;) + loop(); + + return 0; +} + diff --git a/arduino-0018-linux/hardware/arduino/cores/arduino/pins_arduino.c b/arduino-0018-linux/hardware/arduino/cores/arduino/pins_arduino.c new file mode 100755 index 0000000..d7b076d --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/cores/arduino/pins_arduino.c @@ -0,0 +1,469 @@ +/* + pins_arduino.c - pin definitions for the Arduino board + Part of Arduino / Wiring Lite + + Copyright (c) 2005 David A. Mellis + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General + Public License along with this library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, + Boston, MA 02111-1307 USA + + $Id: pins_arduino.c 804 2009-12-18 16:05:52Z dmellis $ +*/ + +#include +#include "wiring_private.h" +#include "pins_arduino.h" + +// On the Arduino board, digital pins are also used +// for the analog output (software PWM). Analog input +// pins are a separate set. + +// ATMEL ATMEGA8 & 168 / ARDUINO +// +// +-\/-+ +// PC6 1| |28 PC5 (AI 5) +// (D 0) PD0 2| |27 PC4 (AI 4) +// (D 1) PD1 3| |26 PC3 (AI 3) +// (D 2) PD2 4| |25 PC2 (AI 2) +// PWM+ (D 3) PD3 5| |24 PC1 (AI 1) +// (D 4) PD4 6| |23 PC0 (AI 0) +// VCC 7| |22 GND +// GND 8| |21 AREF +// PB6 9| |20 AVCC +// PB7 10| |19 PB5 (D 13) +// PWM+ (D 5) PD5 11| |18 PB4 (D 12) +// PWM+ (D 6) PD6 12| |17 PB3 (D 11) PWM +// (D 7) PD7 13| |16 PB2 (D 10) PWM +// (D 8) PB0 14| |15 PB1 (D 9) PWM +// +----+ +// +// (PWM+ indicates the additional PWM pins on the ATmega168.) + +// ATMEL ATMEGA1280 / ARDUINO +// +// 0-7 PE0-PE7 works +// 8-13 PB0-PB5 works +// 14-21 PA0-PA7 works +// 22-29 PH0-PH7 works +// 30-35 PG5-PG0 works +// 36-43 PC7-PC0 works +// 44-51 PJ7-PJ0 works +// 52-59 PL7-PL0 works +// 60-67 PD7-PD0 works +// A0-A7 PF0-PF7 +// A8-A15 PK0-PK7 + +#define PA 1 +#define PB 2 +#define PC 3 +#define PD 4 +#define PE 5 +#define PF 6 +#define PG 7 +#define PH 8 +#define PJ 10 +#define PK 11 +#define PL 12 + +#define REPEAT8(x) x, x, x, x, x, x, x, x +#define BV0TO7 _BV(0), _BV(1), _BV(2), _BV(3), _BV(4), _BV(5), _BV(6), _BV(7) +#define BV7TO0 _BV(7), _BV(6), _BV(5), _BV(4), _BV(3), _BV(2), _BV(1), _BV(0) + + +#if defined(__AVR_ATmega1280__) +const uint16_t PROGMEM port_to_mode_PGM[] = { + NOT_A_PORT, + &DDRA, + &DDRB, + &DDRC, + &DDRD, + &DDRE, + &DDRF, + &DDRG, + &DDRH, + NOT_A_PORT, + &DDRJ, + &DDRK, + &DDRL, +}; + +const uint16_t PROGMEM port_to_output_PGM[] = { + NOT_A_PORT, + &PORTA, + &PORTB, + &PORTC, + &PORTD, + &PORTE, + &PORTF, + &PORTG, + &PORTH, + NOT_A_PORT, + &PORTJ, + &PORTK, + &PORTL, +}; + +const uint16_t PROGMEM port_to_input_PGM[] = { + NOT_A_PIN, + &PINA, + &PINB, + &PINC, + &PIND, + &PINE, + &PINF, + &PING, + &PINH, + NOT_A_PIN, + &PINJ, + &PINK, + &PINL, +}; + +const uint8_t PROGMEM digital_pin_to_port_PGM[] = { + // PORTLIST + // ------------------------------------------- + PE , // PE 0 ** 0 ** USART0_RX + PE , // PE 1 ** 1 ** USART0_TX + PE , // PE 4 ** 2 ** PWM2 + PE , // PE 5 ** 3 ** PWM3 + PG , // PG 5 ** 4 ** PWM4 + PE , // PE 3 ** 5 ** PWM5 + PH , // PH 3 ** 6 ** PWM6 + PH , // PH 4 ** 7 ** PWM7 + PH , // PH 5 ** 8 ** PWM8 + PH , // PH 6 ** 9 ** PWM9 + PB , // PB 4 ** 10 ** PWM10 + PB , // PB 5 ** 11 ** PWM11 + PB , // PB 6 ** 12 ** PWM12 + PB , // PB 7 ** 13 ** PWM13 + PJ , // PJ 1 ** 14 ** USART3_TX + PJ , // PJ 0 ** 15 ** USART3_RX + PH , // PH 1 ** 16 ** USART2_TX + PH , // PH 0 ** 17 ** USART2_RX + PD , // PD 3 ** 18 ** USART1_TX + PD , // PD 2 ** 19 ** USART1_RX + PD , // PD 1 ** 20 ** I2C_SDA + PD , // PD 0 ** 21 ** I2C_SCL + PA , // PA 0 ** 22 ** D22 + PA , // PA 1 ** 23 ** D23 + PA , // PA 2 ** 24 ** D24 + PA , // PA 3 ** 25 ** D25 + PA , // PA 4 ** 26 ** D26 + PA , // PA 5 ** 27 ** D27 + PA , // PA 6 ** 28 ** D28 + PA , // PA 7 ** 29 ** D29 + PC , // PC 7 ** 30 ** D30 + PC , // PC 6 ** 31 ** D31 + PC , // PC 5 ** 32 ** D32 + PC , // PC 4 ** 33 ** D33 + PC , // PC 3 ** 34 ** D34 + PC , // PC 2 ** 35 ** D35 + PC , // PC 1 ** 36 ** D36 + PC , // PC 0 ** 37 ** D37 + PD , // PD 7 ** 38 ** D38 + PG , // PG 2 ** 39 ** D39 + PG , // PG 1 ** 40 ** D40 + PG , // PG 0 ** 41 ** D41 + PL , // PL 7 ** 42 ** D42 + PL , // PL 6 ** 43 ** D43 + PL , // PL 5 ** 44 ** D44 + PL , // PL 4 ** 45 ** D45 + PL , // PL 3 ** 46 ** D46 + PL , // PL 2 ** 47 ** D47 + PL , // PL 1 ** 48 ** D48 + PL , // PL 0 ** 49 ** D49 + PB , // PB 3 ** 50 ** SPI_MISO + PB , // PB 2 ** 51 ** SPI_MOSI + PB , // PB 1 ** 52 ** SPI_SCK + PB , // PB 0 ** 53 ** SPI_SS + PF , // PF 0 ** 54 ** A0 + PF , // PF 1 ** 55 ** A1 + PF , // PF 2 ** 56 ** A2 + PF , // PF 3 ** 57 ** A3 + PF , // PF 4 ** 58 ** A4 + PF , // PF 5 ** 59 ** A5 + PF , // PF 6 ** 60 ** A6 + PF , // PF 7 ** 61 ** A7 + PK , // PK 0 ** 62 ** A8 + PK , // PK 1 ** 63 ** A9 + PK , // PK 2 ** 64 ** A10 + PK , // PK 3 ** 65 ** A11 + PK , // PK 4 ** 66 ** A12 + PK , // PK 5 ** 67 ** A13 + PK , // PK 6 ** 68 ** A14 + PK , // PK 7 ** 69 ** A15 +}; + +const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = { + // PIN IN PORT + // ------------------------------------------- + _BV( 0 ) , // PE 0 ** 0 ** USART0_RX + _BV( 1 ) , // PE 1 ** 1 ** USART0_TX + _BV( 4 ) , // PE 4 ** 2 ** PWM2 + _BV( 5 ) , // PE 5 ** 3 ** PWM3 + _BV( 5 ) , // PG 5 ** 4 ** PWM4 + _BV( 3 ) , // PE 3 ** 5 ** PWM5 + _BV( 3 ) , // PH 3 ** 6 ** PWM6 + _BV( 4 ) , // PH 4 ** 7 ** PWM7 + _BV( 5 ) , // PH 5 ** 8 ** PWM8 + _BV( 6 ) , // PH 6 ** 9 ** PWM9 + _BV( 4 ) , // PB 4 ** 10 ** PWM10 + _BV( 5 ) , // PB 5 ** 11 ** PWM11 + _BV( 6 ) , // PB 6 ** 12 ** PWM12 + _BV( 7 ) , // PB 7 ** 13 ** PWM13 + _BV( 1 ) , // PJ 1 ** 14 ** USART3_TX + _BV( 0 ) , // PJ 0 ** 15 ** USART3_RX + _BV( 1 ) , // PH 1 ** 16 ** USART2_TX + _BV( 0 ) , // PH 0 ** 17 ** USART2_RX + _BV( 3 ) , // PD 3 ** 18 ** USART1_TX + _BV( 2 ) , // PD 2 ** 19 ** USART1_RX + _BV( 1 ) , // PD 1 ** 20 ** I2C_SDA + _BV( 0 ) , // PD 0 ** 21 ** I2C_SCL + _BV( 0 ) , // PA 0 ** 22 ** D22 + _BV( 1 ) , // PA 1 ** 23 ** D23 + _BV( 2 ) , // PA 2 ** 24 ** D24 + _BV( 3 ) , // PA 3 ** 25 ** D25 + _BV( 4 ) , // PA 4 ** 26 ** D26 + _BV( 5 ) , // PA 5 ** 27 ** D27 + _BV( 6 ) , // PA 6 ** 28 ** D28 + _BV( 7 ) , // PA 7 ** 29 ** D29 + _BV( 7 ) , // PC 7 ** 30 ** D30 + _BV( 6 ) , // PC 6 ** 31 ** D31 + _BV( 5 ) , // PC 5 ** 32 ** D32 + _BV( 4 ) , // PC 4 ** 33 ** D33 + _BV( 3 ) , // PC 3 ** 34 ** D34 + _BV( 2 ) , // PC 2 ** 35 ** D35 + _BV( 1 ) , // PC 1 ** 36 ** D36 + _BV( 0 ) , // PC 0 ** 37 ** D37 + _BV( 7 ) , // PD 7 ** 38 ** D38 + _BV( 2 ) , // PG 2 ** 39 ** D39 + _BV( 1 ) , // PG 1 ** 40 ** D40 + _BV( 0 ) , // PG 0 ** 41 ** D41 + _BV( 7 ) , // PL 7 ** 42 ** D42 + _BV( 6 ) , // PL 6 ** 43 ** D43 + _BV( 5 ) , // PL 5 ** 44 ** D44 + _BV( 4 ) , // PL 4 ** 45 ** D45 + _BV( 3 ) , // PL 3 ** 46 ** D46 + _BV( 2 ) , // PL 2 ** 47 ** D47 + _BV( 1 ) , // PL 1 ** 48 ** D48 + _BV( 0 ) , // PL 0 ** 49 ** D49 + _BV( 3 ) , // PB 3 ** 50 ** SPI_MISO + _BV( 2 ) , // PB 2 ** 51 ** SPI_MOSI + _BV( 1 ) , // PB 1 ** 52 ** SPI_SCK + _BV( 0 ) , // PB 0 ** 53 ** SPI_SS + _BV( 0 ) , // PF 0 ** 54 ** A0 + _BV( 1 ) , // PF 1 ** 55 ** A1 + _BV( 2 ) , // PF 2 ** 56 ** A2 + _BV( 3 ) , // PF 3 ** 57 ** A3 + _BV( 4 ) , // PF 4 ** 58 ** A4 + _BV( 5 ) , // PF 5 ** 59 ** A5 + _BV( 6 ) , // PF 6 ** 60 ** A6 + _BV( 7 ) , // PF 7 ** 61 ** A7 + _BV( 0 ) , // PK 0 ** 62 ** A8 + _BV( 1 ) , // PK 1 ** 63 ** A9 + _BV( 2 ) , // PK 2 ** 64 ** A10 + _BV( 3 ) , // PK 3 ** 65 ** A11 + _BV( 4 ) , // PK 4 ** 66 ** A12 + _BV( 5 ) , // PK 5 ** 67 ** A13 + _BV( 6 ) , // PK 6 ** 68 ** A14 + _BV( 7 ) , // PK 7 ** 69 ** A15 +}; + +const uint8_t PROGMEM digital_pin_to_timer_PGM[] = { + // TIMERS + // ------------------------------------------- + NOT_ON_TIMER , // PE 0 ** 0 ** USART0_RX + NOT_ON_TIMER , // PE 1 ** 1 ** USART0_TX + TIMER3B , // PE 4 ** 2 ** PWM2 + TIMER3C , // PE 5 ** 3 ** PWM3 + TIMER0B , // PG 5 ** 4 ** PWM4 + TIMER3A , // PE 3 ** 5 ** PWM5 + TIMER4A , // PH 3 ** 6 ** PWM6 + TIMER4B , // PH 4 ** 7 ** PWM7 + TIMER4C , // PH 5 ** 8 ** PWM8 + TIMER2B , // PH 6 ** 9 ** PWM9 + TIMER2A , // PB 4 ** 10 ** PWM10 + TIMER1A , // PB 5 ** 11 ** PWM11 + TIMER1B , // PB 6 ** 12 ** PWM12 + TIMER0A , // PB 7 ** 13 ** PWM13 + NOT_ON_TIMER , // PJ 1 ** 14 ** USART3_TX + NOT_ON_TIMER , // PJ 0 ** 15 ** USART3_RX + NOT_ON_TIMER , // PH 1 ** 16 ** USART2_TX + NOT_ON_TIMER , // PH 0 ** 17 ** USART2_RX + NOT_ON_TIMER , // PD 3 ** 18 ** USART1_TX + NOT_ON_TIMER , // PD 2 ** 19 ** USART1_RX + NOT_ON_TIMER , // PD 1 ** 20 ** I2C_SDA + NOT_ON_TIMER , // PD 0 ** 21 ** I2C_SCL + NOT_ON_TIMER , // PA 0 ** 22 ** D22 + NOT_ON_TIMER , // PA 1 ** 23 ** D23 + NOT_ON_TIMER , // PA 2 ** 24 ** D24 + NOT_ON_TIMER , // PA 3 ** 25 ** D25 + NOT_ON_TIMER , // PA 4 ** 26 ** D26 + NOT_ON_TIMER , // PA 5 ** 27 ** D27 + NOT_ON_TIMER , // PA 6 ** 28 ** D28 + NOT_ON_TIMER , // PA 7 ** 29 ** D29 + NOT_ON_TIMER , // PC 7 ** 30 ** D30 + NOT_ON_TIMER , // PC 6 ** 31 ** D31 + NOT_ON_TIMER , // PC 5 ** 32 ** D32 + NOT_ON_TIMER , // PC 4 ** 33 ** D33 + NOT_ON_TIMER , // PC 3 ** 34 ** D34 + NOT_ON_TIMER , // PC 2 ** 35 ** D35 + NOT_ON_TIMER , // PC 1 ** 36 ** D36 + NOT_ON_TIMER , // PC 0 ** 37 ** D37 + NOT_ON_TIMER , // PD 7 ** 38 ** D38 + NOT_ON_TIMER , // PG 2 ** 39 ** D39 + NOT_ON_TIMER , // PG 1 ** 40 ** D40 + NOT_ON_TIMER , // PG 0 ** 41 ** D41 + NOT_ON_TIMER , // PL 7 ** 42 ** D42 + NOT_ON_TIMER , // PL 6 ** 43 ** D43 + TIMER5C , // PL 5 ** 44 ** D44 + TIMER5B , // PL 4 ** 45 ** D45 + TIMER5A , // PL 3 ** 46 ** D46 + NOT_ON_TIMER , // PL 2 ** 47 ** D47 + NOT_ON_TIMER , // PL 1 ** 48 ** D48 + NOT_ON_TIMER , // PL 0 ** 49 ** D49 + NOT_ON_TIMER , // PB 3 ** 50 ** SPI_MISO + NOT_ON_TIMER , // PB 2 ** 51 ** SPI_MOSI + NOT_ON_TIMER , // PB 1 ** 52 ** SPI_SCK + NOT_ON_TIMER , // PB 0 ** 53 ** SPI_SS + NOT_ON_TIMER , // PF 0 ** 54 ** A0 + NOT_ON_TIMER , // PF 1 ** 55 ** A1 + NOT_ON_TIMER , // PF 2 ** 56 ** A2 + NOT_ON_TIMER , // PF 3 ** 57 ** A3 + NOT_ON_TIMER , // PF 4 ** 58 ** A4 + NOT_ON_TIMER , // PF 5 ** 59 ** A5 + NOT_ON_TIMER , // PF 6 ** 60 ** A6 + NOT_ON_TIMER , // PF 7 ** 61 ** A7 + NOT_ON_TIMER , // PK 0 ** 62 ** A8 + NOT_ON_TIMER , // PK 1 ** 63 ** A9 + NOT_ON_TIMER , // PK 2 ** 64 ** A10 + NOT_ON_TIMER , // PK 3 ** 65 ** A11 + NOT_ON_TIMER , // PK 4 ** 66 ** A12 + NOT_ON_TIMER , // PK 5 ** 67 ** A13 + NOT_ON_TIMER , // PK 6 ** 68 ** A14 + NOT_ON_TIMER , // PK 7 ** 69 ** A15 +}; +#else +// these arrays map port names (e.g. port B) to the +// appropriate addresses for various functions (e.g. reading +// and writing) +const uint16_t PROGMEM port_to_mode_PGM[] = { + NOT_A_PORT, + NOT_A_PORT, + &DDRB, + &DDRC, + &DDRD, +}; + +const uint16_t PROGMEM port_to_output_PGM[] = { + NOT_A_PORT, + NOT_A_PORT, + &PORTB, + &PORTC, + &PORTD, +}; + +const uint16_t PROGMEM port_to_input_PGM[] = { + NOT_A_PORT, + NOT_A_PORT, + &PINB, + &PINC, + &PIND, +}; + +const uint8_t PROGMEM digital_pin_to_port_PGM[] = { + PD, /* 0 */ + PD, + PD, + PD, + PD, + PD, + PD, + PD, + PB, /* 8 */ + PB, + PB, + PB, + PB, + PB, + PC, /* 14 */ + PC, + PC, + PC, + PC, + PC, +}; + +const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = { + _BV(0), /* 0, port D */ + _BV(1), + _BV(2), + _BV(3), + _BV(4), + _BV(5), + _BV(6), + _BV(7), + _BV(0), /* 8, port B */ + _BV(1), + _BV(2), + _BV(3), + _BV(4), + _BV(5), + _BV(0), /* 14, port C */ + _BV(1), + _BV(2), + _BV(3), + _BV(4), + _BV(5), +}; + +const uint8_t PROGMEM digital_pin_to_timer_PGM[] = { + NOT_ON_TIMER, /* 0 - port D */ + NOT_ON_TIMER, + NOT_ON_TIMER, + // on the ATmega168, digital pin 3 has hardware pwm +#if defined(__AVR_ATmega8__) + NOT_ON_TIMER, +#else + TIMER2B, +#endif + NOT_ON_TIMER, + // on the ATmega168, digital pins 5 and 6 have hardware pwm +#if defined(__AVR_ATmega8__) + NOT_ON_TIMER, + NOT_ON_TIMER, +#else + TIMER0B, + TIMER0A, +#endif + NOT_ON_TIMER, + NOT_ON_TIMER, /* 8 - port B */ + TIMER1A, + TIMER1B, +#if defined(__AVR_ATmega8__) + TIMER2, +#else + TIMER2A, +#endif + NOT_ON_TIMER, + NOT_ON_TIMER, + NOT_ON_TIMER, + NOT_ON_TIMER, /* 14 - port C */ + NOT_ON_TIMER, + NOT_ON_TIMER, + NOT_ON_TIMER, + NOT_ON_TIMER, +}; +#endif diff --git a/arduino-0018-linux/hardware/arduino/cores/arduino/pins_arduino.h b/arduino-0018-linux/hardware/arduino/cores/arduino/pins_arduino.h new file mode 100644 index 0000000..c7e40fd --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/cores/arduino/pins_arduino.h @@ -0,0 +1,76 @@ +/* + pins_arduino.h - Pin definition functions for Arduino + Part of Arduino - http://www.arduino.cc/ + + Copyright (c) 2007 David A. Mellis + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General + Public License along with this library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, + Boston, MA 02111-1307 USA + + $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $ +*/ + +#ifndef Pins_Arduino_h +#define Pins_Arduino_h + +#include + +#define NOT_A_PIN 0 +#define NOT_A_PORT 0 + +#define NOT_ON_TIMER 0 +#define TIMER0A 1 +#define TIMER0B 2 +#define TIMER1A 3 +#define TIMER1B 4 +#define TIMER2 5 +#define TIMER2A 6 +#define TIMER2B 7 + +#define TIMER3A 8 +#define TIMER3B 9 +#define TIMER3C 10 +#define TIMER4A 11 +#define TIMER4B 12 +#define TIMER4C 13 +#define TIMER5A 14 +#define TIMER5B 15 +#define TIMER5C 16 + +// 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))) ) + +#endif diff --git a/arduino-0018-linux/hardware/arduino/cores/arduino/wiring.c b/arduino-0018-linux/hardware/arduino/cores/arduino/wiring.c new file mode 100755 index 0000000..d857e8a --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/cores/arduino/wiring.c @@ -0,0 +1,238 @@ +/* + wiring.c - Partial implementation of the Wiring API for the ATmega8. + Part of Arduino - http://www.arduino.cc/ + + Copyright (c) 2005-2006 David A. Mellis + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General + Public License along with this library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, + Boston, MA 02111-1307 USA + + $Id: wiring.c 808 2009-12-18 17:44:08Z dmellis $ +*/ + +#include "wiring_private.h" + +// the prescaler is set so that timer0 ticks every 64 clock cycles, and the +// the overflow handler is called every 256 ticks. +#define MICROSECONDS_PER_TIMER0_OVERFLOW (clockCyclesToMicroseconds(64 * 256)) + +// the whole number of milliseconds per timer0 overflow +#define MILLIS_INC (MICROSECONDS_PER_TIMER0_OVERFLOW / 1000) + +// the fractional number of milliseconds per timer0 overflow. we shift right +// by three to fit these numbers into a byte. (for the clock speeds we care +// about - 8 and 16 MHz - this doesn't lose precision.) +#define FRACT_INC ((MICROSECONDS_PER_TIMER0_OVERFLOW % 1000) >> 3) +#define FRACT_MAX (1000 >> 3) + +volatile unsigned long timer0_overflow_count = 0; +volatile unsigned long timer0_millis = 0; +static unsigned char timer0_fract = 0; + +SIGNAL(TIMER0_OVF_vect) +{ + // copy these to local variables so they can be stored in registers + // (volatile variables must be read from memory on every access) + unsigned long m = timer0_millis; + unsigned char f = timer0_fract; + + m += MILLIS_INC; + f += FRACT_INC; + if (f >= FRACT_MAX) { + f -= FRACT_MAX; + m += 1; + } + + timer0_fract = f; + timer0_millis = m; + timer0_overflow_count++; +} + +unsigned long millis() +{ + unsigned long m; + uint8_t oldSREG = SREG; + + // disable interrupts while we read timer0_millis or we might get an + // inconsistent value (e.g. in the middle of a write to timer0_millis) + cli(); + m = timer0_millis; + SREG = oldSREG; + + return m; +} + +unsigned long micros() { + unsigned long m; + uint8_t oldSREG = SREG, t; + + cli(); + m = timer0_overflow_count; + t = TCNT0; + +#ifdef TIFR0 + if ((TIFR0 & _BV(TOV0)) && (t < 255)) + m++; +#else + if ((TIFR & _BV(TOV0)) && (t < 255)) + m++; +#endif + + SREG = oldSREG; + + return ((m << 8) + t) * (64 / clockCyclesPerMicrosecond()); +} + +void delay(unsigned long ms) +{ + unsigned long start = millis(); + + while (millis() - start <= ms) + ; +} + +/* Delay for the given number of microseconds. Assumes a 8 or 16 MHz clock. */ +void delayMicroseconds(unsigned int us) +{ + // calling avrlib's delay_us() function with low values (e.g. 1 or + // 2 microseconds) gives delays longer than desired. + //delay_us(us); + +#if F_CPU >= 16000000L + // for the 16 MHz clock on most Arduino boards + + // for a one-microsecond delay, simply return. the overhead + // of the function call yields a delay of approximately 1 1/8 us. + if (--us == 0) + return; + + // the following loop takes a quarter of a microsecond (4 cycles) + // per iteration, so execute it four times for each microsecond of + // delay requested. + us <<= 2; + + // account for the time taken in the preceeding commands. + us -= 2; +#else + // for the 8 MHz internal clock on the ATmega168 + + // for a one- or two-microsecond delay, simply return. the overhead of + // the function calls takes more than two microseconds. can't just + // subtract two, since us is unsigned; we'd overflow. + if (--us == 0) + return; + if (--us == 0) + return; + + // the following loop takes half of a microsecond (4 cycles) + // per iteration, so execute it twice for each microsecond of + // delay requested. + us <<= 1; + + // partially compensate for the time taken by the preceeding commands. + // we can't subtract any more than this or we'd overflow w/ small delays. + us--; +#endif + + // busy wait + __asm__ __volatile__ ( + "1: sbiw %0,1" "\n\t" // 2 cycles + "brne 1b" : "=w" (us) : "0" (us) // 2 cycles + ); +} + +void init() +{ + // this needs to be called before setup() or some functions won't + // work there + sei(); + + // on the ATmega168, timer 0 is also used for fast hardware pwm + // (using phase-correct PWM would mean that timer 0 overflowed half as often + // resulting in different millis() behavior on the ATmega8 and ATmega168) +#if !defined(__AVR_ATmega8__) + sbi(TCCR0A, WGM01); + sbi(TCCR0A, WGM00); +#endif + // set timer 0 prescale factor to 64 +#if defined(__AVR_ATmega8__) + sbi(TCCR0, CS01); + sbi(TCCR0, CS00); +#else + sbi(TCCR0B, CS01); + sbi(TCCR0B, CS00); +#endif + // enable timer 0 overflow interrupt +#if defined(__AVR_ATmega8__) + sbi(TIMSK, TOIE0); +#else + sbi(TIMSK0, TOIE0); +#endif + + // timers 1 and 2 are used for phase-correct hardware pwm + // this is better for motors as it ensures an even waveform + // note, however, that fast pwm mode can achieve a frequency of up + // 8 MHz (with a 16 MHz clock) at 50% duty cycle + + // set timer 1 prescale factor to 64 + sbi(TCCR1B, CS11); + sbi(TCCR1B, CS10); + // put timer 1 in 8-bit phase correct pwm mode + sbi(TCCR1A, WGM10); + + // set timer 2 prescale factor to 64 +#if defined(__AVR_ATmega8__) + sbi(TCCR2, CS22); +#else + sbi(TCCR2B, CS22); +#endif + // configure timer 2 for phase correct pwm (8-bit) +#if defined(__AVR_ATmega8__) + sbi(TCCR2, WGM20); +#else + sbi(TCCR2A, WGM20); +#endif + +#if defined(__AVR_ATmega1280__) + // set timer 3, 4, 5 prescale factor to 64 + sbi(TCCR3B, CS31); sbi(TCCR3B, CS30); + sbi(TCCR4B, CS41); sbi(TCCR4B, CS40); + sbi(TCCR5B, CS51); sbi(TCCR5B, CS50); + // put timer 3, 4, 5 in 8-bit phase correct pwm mode + sbi(TCCR3A, WGM30); + sbi(TCCR4A, WGM40); + sbi(TCCR5A, WGM50); +#endif + + // set a2d prescale factor to 128 + // 16 MHz / 128 = 125 KHz, inside the desired 50-200 KHz range. + // XXX: this will not work properly for other clock speeds, and + // this code should use F_CPU to determine the prescale factor. + sbi(ADCSRA, ADPS2); + sbi(ADCSRA, ADPS1); + sbi(ADCSRA, ADPS0); + + // enable a2d conversions + sbi(ADCSRA, ADEN); + + // the bootloader connects pins 0 and 1 to the USART; disconnect them + // here so they can be used as normal digital i/o; they will be + // reconnected in Serial.begin() +#if defined(__AVR_ATmega8__) + UCSRB = 0; +#else + UCSR0B = 0; +#endif +} \ No newline at end of file diff --git a/arduino-0018-linux/hardware/arduino/cores/arduino/wiring.h b/arduino-0018-linux/hardware/arduino/cores/arduino/wiring.h new file mode 100755 index 0000000..8b42629 --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/cores/arduino/wiring.h @@ -0,0 +1,133 @@ +/* + wiring.h - Partial implementation of the Wiring API for the ATmega8. + Part of Arduino - http://www.arduino.cc/ + + Copyright (c) 2005-2006 David A. Mellis + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General + Public License along with this library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, + Boston, MA 02111-1307 USA + + $Id: wiring.h 804 2009-12-18 16:05:52Z dmellis $ +*/ + +#ifndef Wiring_h +#define Wiring_h + +#include +#include "binary.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +#define HIGH 0x1 +#define LOW 0x0 + +#define INPUT 0x0 +#define OUTPUT 0x1 + +#define true 0x1 +#define false 0x0 + +#define PI 3.1415926535897932384626433832795 +#define HALF_PI 1.5707963267948966192313216916398 +#define TWO_PI 6.283185307179586476925286766559 +#define DEG_TO_RAD 0.017453292519943295769236907684886 +#define RAD_TO_DEG 57.295779513082320876798154814105 + +#define SERIAL 0x0 +#define DISPLAY 0x1 + +#define LSBFIRST 0 +#define MSBFIRST 1 + +#define CHANGE 1 +#define FALLING 2 +#define RISING 3 + +#define INTERNAL 3 +#define DEFAULT 1 +#define EXTERNAL 0 + +// undefine stdlib's abs if encountered +#ifdef abs +#undef abs +#endif + +#define min(a,b) ((a)<(b)?(a):(b)) +#define max(a,b) ((a)>(b)?(a):(b)) +#define abs(x) ((x)>0?(x):-(x)) +#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) +#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) +#define radians(deg) ((deg)*DEG_TO_RAD) +#define degrees(rad) ((rad)*RAD_TO_DEG) +#define sq(x) ((x)*(x)) + +#define interrupts() sei() +#define noInterrupts() cli() + +#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L ) +#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() ) +#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() ) + +#define lowByte(w) ((uint8_t) ((w) & 0xff)) +#define highByte(w) ((uint8_t) ((w) >> 8)) + +#define bitRead(value, bit) (((value) >> (bit)) & 0x01) +#define bitSet(value, bit) ((value) |= (1UL << (bit))) +#define bitClear(value, bit) ((value) &= ~(1UL << (bit))) +#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) + +typedef unsigned int word; + +#define bit(b) (1UL << (b)) + +typedef uint8_t boolean; +typedef uint8_t byte; + +void init(void); + +void pinMode(uint8_t, uint8_t); +void digitalWrite(uint8_t, uint8_t); +int digitalRead(uint8_t); +int analogRead(uint8_t); +void analogReference(uint8_t mode); +void analogWrite(uint8_t, int); + +void beginSerial(long); +void serialWrite(unsigned char); +int serialAvailable(void); +int serialRead(void); +void serialFlush(void); + +unsigned long millis(void); +unsigned long micros(void); +void delay(unsigned long); +void delayMicroseconds(unsigned int us); +unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout); + +void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, byte val); + +void attachInterrupt(uint8_t, void (*)(void), int mode); +void detachInterrupt(uint8_t); + +void setup(void); +void loop(void); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif diff --git a/arduino-0018-linux/hardware/arduino/cores/arduino/wiring_analog.c b/arduino-0018-linux/hardware/arduino/cores/arduino/wiring_analog.c new file mode 100755 index 0000000..529ad52 --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/cores/arduino/wiring_analog.c @@ -0,0 +1,179 @@ +/* + wiring_analog.c - analog input and output + Part of Arduino - http://www.arduino.cc/ + + Copyright (c) 2005-2006 David A. Mellis + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General + Public License along with this library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, + Boston, MA 02111-1307 USA + + $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $ +*/ + +#include "wiring_private.h" +#include "pins_arduino.h" + +uint8_t analog_reference = DEFAULT; + +void analogReference(uint8_t mode) +{ + // can't actually set the register here because the default setting + // will connect AVCC and the AREF pin, which would cause a short if + // there's something connected to AREF. + analog_reference = mode; +} + +int analogRead(uint8_t pin) +{ + uint8_t low, high; + + // set the analog reference (high two bits of ADMUX) and select the + // channel (low 4 bits). this also sets ADLAR (left-adjust result) + // to 0 (the default). + ADMUX = (analog_reference << 6) | (pin & 0x07); + +#if defined(__AVR_ATmega1280__) + // the MUX5 bit of ADCSRB selects whether we're reading from channels + // 0 to 7 (MUX5 low) or 8 to 15 (MUX5 high). + ADCSRB = (ADCSRB & ~(1 << MUX5)) | (((pin >> 3) & 0x01) << MUX5); +#endif + + // without a delay, we seem to read from the wrong channel + //delay(1); + + // start the conversion + sbi(ADCSRA, ADSC); + + // ADSC is cleared when the conversion finishes + while (bit_is_set(ADCSRA, ADSC)); + + // we have to read ADCL first; doing so locks both ADCL + // and ADCH until ADCH is read. reading ADCL second would + // cause the results of each conversion to be discarded, + // as ADCL and ADCH would be locked when it completed. + low = ADCL; + high = ADCH; + + // combine the two bytes + return (high << 8) | low; +} + +// Right now, PWM output only works on the pins with +// hardware support. These are defined in the appropriate +// pins_*.c file. For the rest of the pins, we default +// to digital output. +void analogWrite(uint8_t pin, int val) +{ + // We need to make sure the PWM output is enabled for those pins + // that support it, as we turn it off when digitally reading or + // writing with them. Also, make sure the pin is in output mode + // for consistenty with Wiring, which doesn't require a pinMode + // call for the analog output pins. + pinMode(pin, OUTPUT); + + if (digitalPinToTimer(pin) == TIMER1A) { + // connect pwm to pin on timer 1, channel A + sbi(TCCR1A, COM1A1); + // set pwm duty + OCR1A = val; + } else if (digitalPinToTimer(pin) == TIMER1B) { + // connect pwm to pin on timer 1, channel B + sbi(TCCR1A, COM1B1); + // set pwm duty + OCR1B = val; +#if defined(__AVR_ATmega8__) + } else if (digitalPinToTimer(pin) == TIMER2) { + // connect pwm to pin on timer 2, channel B + sbi(TCCR2, COM21); + // set pwm duty + OCR2 = val; +#else + } else if (digitalPinToTimer(pin) == TIMER0A) { + if (val == 0) { + digitalWrite(pin, LOW); + } else { + // connect pwm to pin on timer 0, channel A + sbi(TCCR0A, COM0A1); + // set pwm duty + OCR0A = val; + } + } else if (digitalPinToTimer(pin) == TIMER0B) { + if (val == 0) { + digitalWrite(pin, LOW); + } else { + // connect pwm to pin on timer 0, channel B + sbi(TCCR0A, COM0B1); + // set pwm duty + OCR0B = val; + } + } else if (digitalPinToTimer(pin) == TIMER2A) { + // connect pwm to pin on timer 2, channel A + sbi(TCCR2A, COM2A1); + // set pwm duty + OCR2A = val; + } else if (digitalPinToTimer(pin) == TIMER2B) { + // connect pwm to pin on timer 2, channel B + sbi(TCCR2A, COM2B1); + // set pwm duty + OCR2B = val; +#endif +#if defined(__AVR_ATmega1280__) + // XXX: need to handle other timers here + } else if (digitalPinToTimer(pin) == TIMER3A) { + // connect pwm to pin on timer 3, channel A + sbi(TCCR3A, COM3A1); + // set pwm duty + OCR3A = val; + } else if (digitalPinToTimer(pin) == TIMER3B) { + // connect pwm to pin on timer 3, channel B + sbi(TCCR3A, COM3B1); + // set pwm duty + OCR3B = val; + } else if (digitalPinToTimer(pin) == TIMER3C) { + // connect pwm to pin on timer 3, channel C + sbi(TCCR3A, COM3C1); + // set pwm duty + OCR3C = val; + } else if (digitalPinToTimer(pin) == TIMER4A) { + // connect pwm to pin on timer 4, channel A + sbi(TCCR4A, COM4A1); + // set pwm duty + OCR4A = val; + } else if (digitalPinToTimer(pin) == TIMER4B) { + // connect pwm to pin on timer 4, channel B + sbi(TCCR4A, COM4B1); + // set pwm duty + OCR4B = val; + } else if (digitalPinToTimer(pin) == TIMER4C) { + // connect pwm to pin on timer 4, channel C + sbi(TCCR4A, COM4C1); + // set pwm duty + OCR4C = val; + } else if (digitalPinToTimer(pin) == TIMER5A) { + // connect pwm to pin on timer 5, channel A + sbi(TCCR5A, COM5A1); + // set pwm duty + OCR5A = val; + } else if (digitalPinToTimer(pin) == TIMER5B) { + // connect pwm to pin on timer 5, channel B + sbi(TCCR5A, COM5B1); + // set pwm duty + OCR5B = val; +#endif + } else if (val < 128) + digitalWrite(pin, LOW); + else + digitalWrite(pin, HIGH); +} diff --git a/arduino-0018-linux/hardware/arduino/cores/arduino/wiring_digital.c b/arduino-0018-linux/hardware/arduino/cores/arduino/wiring_digital.c new file mode 100755 index 0000000..1cdbf6c --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/cores/arduino/wiring_digital.c @@ -0,0 +1,111 @@ +/* + wiring_digital.c - digital input and output functions + Part of Arduino - http://www.arduino.cc/ + + Copyright (c) 2005-2006 David A. Mellis + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General + Public License along with this library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, + Boston, MA 02111-1307 USA + + $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $ +*/ + +#include "wiring_private.h" +#include "pins_arduino.h" + +void pinMode(uint8_t pin, uint8_t mode) +{ + uint8_t bit = digitalPinToBitMask(pin); + uint8_t port = digitalPinToPort(pin); + volatile uint8_t *reg; + + if (port == NOT_A_PIN) return; + + // JWS: can I let the optimizer do this? + reg = portModeRegister(port); + + if (mode == INPUT) *reg &= ~bit; + else *reg |= bit; +} + +// Forcing this inline keeps the callers from having to push their own stuff +// on the stack. It is a good performance win and only takes 1 more byte per +// user than calling. (It will take more bytes on the 168.) +// +// But shouldn't this be moved into pinMode? Seems silly to check and do on +// each digitalread or write. +// +static inline void turnOffPWM(uint8_t timer) __attribute__ ((always_inline)); +static inline void turnOffPWM(uint8_t timer) +{ + if (timer == TIMER1A) cbi(TCCR1A, COM1A1); + if (timer == TIMER1B) cbi(TCCR1A, COM1B1); + +#if defined(__AVR_ATmega8__) + if (timer == TIMER2) cbi(TCCR2, COM21); +#else + if (timer == TIMER0A) cbi(TCCR0A, COM0A1); + if (timer == TIMER0B) cbi(TCCR0A, COM0B1); + if (timer == TIMER2A) cbi(TCCR2A, COM2A1); + if (timer == TIMER2B) cbi(TCCR2A, COM2B1); +#endif + +#if defined(__AVR_ATmega1280__) + if (timer == TIMER3A) cbi(TCCR3A, COM3A1); + if (timer == TIMER3B) cbi(TCCR3A, COM3B1); + if (timer == TIMER3C) cbi(TCCR3A, COM3C1); + if (timer == TIMER4A) cbi(TCCR4A, COM4A1); + if (timer == TIMER4B) cbi(TCCR4A, COM4B1); + if (timer == TIMER4C) cbi(TCCR4A, COM4C1); + if (timer == TIMER5A) cbi(TCCR5A, COM5A1); + if (timer == TIMER5B) cbi(TCCR5A, COM5B1); + if (timer == TIMER5C) cbi(TCCR5A, COM5C1); +#endif +} + +void digitalWrite(uint8_t pin, uint8_t val) +{ + uint8_t timer = digitalPinToTimer(pin); + uint8_t bit = digitalPinToBitMask(pin); + uint8_t port = digitalPinToPort(pin); + volatile uint8_t *out; + + if (port == NOT_A_PIN) return; + + // If the pin that support PWM output, we need to turn it off + // before doing a digital write. + if (timer != NOT_ON_TIMER) turnOffPWM(timer); + + out = portOutputRegister(port); + + if (val == LOW) *out &= ~bit; + else *out |= bit; +} + +int digitalRead(uint8_t pin) +{ + uint8_t timer = digitalPinToTimer(pin); + uint8_t bit = digitalPinToBitMask(pin); + uint8_t port = digitalPinToPort(pin); + + if (port == NOT_A_PIN) return LOW; + + // If the pin that support PWM output, we need to turn it off + // before getting a digital reading. + if (timer != NOT_ON_TIMER) turnOffPWM(timer); + + if (*portInputRegister(port) & bit) return HIGH; + return LOW; +} diff --git a/arduino-0018-linux/hardware/arduino/cores/arduino/wiring_private.h b/arduino-0018-linux/hardware/arduino/cores/arduino/wiring_private.h new file mode 100755 index 0000000..2dfe552 --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/cores/arduino/wiring_private.h @@ -0,0 +1,68 @@ +/* + wiring_private.h - Internal header file. + Part of Arduino - http://www.arduino.cc/ + + Copyright (c) 2005-2006 David A. Mellis + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General + Public License along with this library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, + Boston, MA 02111-1307 USA + + $Id: wiring.h 239 2007-01-12 17:58:39Z mellis $ +*/ + +#ifndef WiringPrivate_h +#define WiringPrivate_h + +#include +#include +#include +#include +#include + +#include "wiring.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +#ifndef cbi +#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) +#endif +#ifndef sbi +#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) +#endif + +#define EXTERNAL_INT_0 0 +#define EXTERNAL_INT_1 1 +#define EXTERNAL_INT_2 2 +#define EXTERNAL_INT_3 3 +#define EXTERNAL_INT_4 4 +#define EXTERNAL_INT_5 5 +#define EXTERNAL_INT_6 6 +#define EXTERNAL_INT_7 7 + +#if defined(__AVR_ATmega1280__) +#define EXTERNAL_NUM_INTERRUPTS 8 +#else +#define EXTERNAL_NUM_INTERRUPTS 2 +#endif + +typedef void (*voidFuncPtr)(void); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif diff --git a/arduino-0018-linux/hardware/arduino/cores/arduino/wiring_pulse.c b/arduino-0018-linux/hardware/arduino/cores/arduino/wiring_pulse.c new file mode 100755 index 0000000..8f232f1 --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/cores/arduino/wiring_pulse.c @@ -0,0 +1,66 @@ +/* + wiring_pulse.c - pulseIn() function + Part of Arduino - http://www.arduino.cc/ + + Copyright (c) 2005-2006 David A. Mellis + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General + Public License along with this library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, + Boston, MA 02111-1307 USA + + $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $ +*/ + +#include "wiring_private.h" +#include "pins_arduino.h" + +/* Measures the length (in microseconds) of a pulse on the pin; state is HIGH + * or LOW, the type of pulse to measure. Works on pulses from 2-3 microseconds + * to 3 minutes in length, but must be called at least a few dozen microseconds + * before the start of the pulse. */ +unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout) +{ + // cache the port and bit of the pin in order to speed up the + // pulse width measuring loop and achieve finer resolution. calling + // digitalRead() instead yields much coarser resolution. + uint8_t bit = digitalPinToBitMask(pin); + uint8_t port = digitalPinToPort(pin); + uint8_t stateMask = (state ? bit : 0); + unsigned long width = 0; // keep initialization out of time critical area + + // convert the timeout from microseconds to a number of times through + // the initial loop; it takes 16 clock cycles per iteration. + unsigned long numloops = 0; + unsigned long maxloops = microsecondsToClockCycles(timeout) / 16; + + // wait for any previous pulse to end + while ((*portInputRegister(port) & bit) == stateMask) + if (numloops++ == maxloops) + return 0; + + // wait for the pulse to start + while ((*portInputRegister(port) & bit) != stateMask) + if (numloops++ == maxloops) + return 0; + + // wait for the pulse to stop + while ((*portInputRegister(port) & bit) == stateMask) + width++; + + // convert the reading to microseconds. The loop has been determined + // to be 10 clock cycles long and have about 16 clocks between the edge + // and the start of the loop. There will be some error introduced by + // the interrupt handlers. + return clockCyclesToMicroseconds(width * 10 + 16); +} diff --git a/arduino-0018-linux/hardware/arduino/cores/arduino/wiring_shift.c b/arduino-0018-linux/hardware/arduino/cores/arduino/wiring_shift.c new file mode 100755 index 0000000..956f864 --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/cores/arduino/wiring_shift.c @@ -0,0 +1,40 @@ +/* + wiring_shift.c - shiftOut() function + Part of Arduino - http://www.arduino.cc/ + + Copyright (c) 2005-2006 David A. Mellis + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General + Public License along with this library; if not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, + Boston, MA 02111-1307 USA + + $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $ +*/ + +#include "wiring_private.h" + +void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, byte val) +{ + int i; + + for (i = 0; i < 8; i++) { + if (bitOrder == LSBFIRST) + digitalWrite(dataPin, !!(val & (1 << i))); + else + digitalWrite(dataPin, !!(val & (1 << (7 - i)))); + + digitalWrite(clockPin, HIGH); + digitalWrite(clockPin, LOW); + } +} diff --git a/arduino-0018-linux/hardware/arduino/programmers.txt b/arduino-0018-linux/hardware/arduino/programmers.txt new file mode 100644 index 0000000..466f602 --- /dev/null +++ b/arduino-0018-linux/hardware/arduino/programmers.txt @@ -0,0 +1,20 @@ +avrisp.name=AVR ISP +avrisp.communication=serial +avrisp.protocol=stk500v1 + +avrispmkii.name=AVRISP mkII +avrispmkii.communication=usb +avrispmkii.protocol=stk500v2 + +usbtinyisp.name=USBtinyISP +usbtinyisp.protocol=usbtiny + +parallel.name=Parallel Programmer +parallel.protocol=dapa +parallel.force=true +# parallel.delay=200 + +arduinoisp.name=Arduino as ISP +arduinoisp.communication=serial +arduinoisp.protocol=stk500v1 +arduinoisp.speed=19200 diff --git a/arduino-0018-linux/hardware/tools/avrdude b/arduino-0018-linux/hardware/tools/avrdude new file mode 100755 index 0000000..96f489c Binary files /dev/null and b/arduino-0018-linux/hardware/tools/avrdude differ diff --git a/arduino-0018-linux/hardware/tools/avrdude.conf b/arduino-0018-linux/hardware/tools/avrdude.conf new file mode 100644 index 0000000..221cf2a --- /dev/null +++ b/arduino-0018-linux/hardware/tools/avrdude.conf @@ -0,0 +1,11914 @@ +# $Id: avrdude.conf.in,v 1.122 2007/05/16 21:29:36 joerg_wunsch Exp $ +# +# AVRDUDE Configuration File +# +# This file contains configuration data used by AVRDUDE which describes +# the programming hardware pinouts and also provides part definitions. +# AVRDUDE's "-C" command line option specifies the location of the +# configuration file. The "-c" option names the programmer configuration +# which must match one of the entry's "id" parameter. The "-p" option +# identifies which part AVRDUDE is going to be programming and must match +# one of the parts' "id" parameter. +# +# Possible entry formats are: +# +# programmer +# id = [, [, ] ...] ; # are quoted strings +# desc = ; # quoted string +# type = par | stk500 | stk500v2 | stk500pp | stk500hvsp | stk500generic | +# avr910 | butterfly | usbasp | +# jtagmki | jtagmkii | jtagmkii_isp | jtagmkii_dw | +# dragon_dw | dragon_jtag | dragon_isp | dragon_pp | +# dragon_hvsp; # programmer type +# baudrate = ; # baudrate for avr910-programmer +# vcc = [, ... ] ; # pin number(s) +# reset = ; # pin number +# sck = ; # pin number +# mosi = ; # pin number +# miso = ; # pin number +# errled = ; # pin number +# rdyled = ; # pin number +# pgmled = ; # pin number +# vfyled = ; # pin number +# ; +# +# part +# id = ; # quoted string +# desc = ; # quoted string +# has_jtag = ; # part has JTAG i/f +# has_debugwire = ; # part has debugWire i/f +# devicecode = ; # deprecated, use stk500_devcode +# stk500_devcode = ; # numeric +# avr910_devcode = ; # numeric +# signature = ; # signature bytes +# chip_erase_delay = ; # micro-seconds +# reset = dedicated | io; +# retry_pulse = reset | sck; +# pgm_enable = ; +# chip_erase = ; +# chip_erase_delay = ; # chip erase delay (us) +# # STK500 parameters (parallel programming IO lines) +# pagel = ; # pin name in hex, i.e., 0xD7 +# bs2 = ; # pin name in hex, i.e., 0xA0 +# serial = ; # can use serial downloading +# parallel = ; # can use par. programming +# # STK500v2 parameters, to be taken from Atmel's XML files +# timeout = ; +# stabdelay = ; +# cmdexedelay = ; +# synchloops = ; +# bytedelay = ; +# pollvalue = ; +# pollindex = ; +# predelay = ; +# postdelay = ; +# pollmethod = ; +# mode = ; +# delay = ; +# blocksize = ; +# readsize = ; +# hvspcmdexedelay = ; +# # STK500v2 HV programming parameters, from XML +# pp_controlstack = , , ...; # PP only +# hvsp_controlstack = , , ...; # HVSP only +# hventerstabdelay = ; +# progmodedelay = ; # PP only +# latchcycles = ; +# togglevtg = ; +# poweroffdelay = ; +# resetdelayms = ; +# resetdelayus = ; +# hvleavestabdelay = ; +# resetdelay = ; +# synchcycles = ; # HVSP only +# chiperasepulsewidth = ; # PP only +# chiperasepolltimeout = ; +# chiperasetime = ; # HVSP only +# programfusepulsewidth = ; # PP only +# programfusepolltimeout = ; +# programlockpulsewidth = ; # PP only +# programlockpolltimeout = ; +# # JTAG ICE mkII parameters, also from XML files +# allowfullpagebitstream = ; +# enablepageprogramming = ; +# idr = ; # IO addr of IDR (OCD) reg. +# rampz = ; # IO addr of RAMPZ reg. +# spmcr = ; # mem addr of SPMC[S]R reg. +# eecr = ; # mem addr of EECR reg. +# # (only when != 0x3c) +# +# memory +# paged = ; # yes / no +# size = ; # bytes +# page_size = ; # bytes +# num_pages = ; # numeric +# min_write_delay = ; # micro-seconds +# max_write_delay = ; # micro-seconds +# readback_p1 = ; # byte value +# readback_p2 = ; # byte value +# pwroff_after_write = ; # yes / no +# read = ; +# write = ; +# read_lo = ; +# read_hi = ; +# write_lo = ; +# write_hi = ; +# loadpage_lo = ; +# loadpage_hi = ; +# writepage = ; +# ; +# ; +# +# If any of the above parameters are not specified, the default value +# of 0 is used for numerics or the empty string ("") for string +# values. If a required parameter is left empty, AVRDUDE will +# complain. +# +# NOTES: +# * 'devicecode' is the device code used by the STK500 (see codes +# listed below) +# * Not all memory types will implement all instructions. +# * AVR Fuse bits and Lock bits are implemented as a type of memory. +# * Example memory types are: +# "flash", "eeprom", "fuse", "lfuse" (low fuse), "hfuse" (high +# fuse), "signature", "calibration", "lock" +# * The memory type specified on the avrdude command line must match +# one of the memory types defined for the specified chip. +# * The pwroff_after_write flag causes avrdude to attempt to +# power the device off and back on after an unsuccessful write to +# the affected memory area if VCC programmer pins are defined. If +# VCC pins are not defined for the programmer, a message +# indicating that the device needs a power-cycle is printed out. +# This flag was added to work around a problem with the +# at90s4433/2333's; see the at90s4433 errata at: +# +# http://www.atmel.com/atmel/acrobat/doc1280.pdf +# +# INSTRUCTION FORMATS +# +# Instruction formats are specified as a comma seperated list of +# string values containing information (bit specifiers) about each +# of the 32 bits of the instruction. Bit specifiers may be one of +# the following formats: +# +# '1' = the bit is always set on input as well as output +# +# '0' = the bit is always clear on input as well as output +# +# 'x' = the bit is ignored on input and output +# +# 'a' = the bit is an address bit, the bit-number matches this bit +# specifier's position within the current instruction byte +# +# 'aN' = the bit is the Nth address bit, bit-number = N, i.e., a12 +# is address bit 12 on input, a0 is address bit 0. +# +# 'i' = the bit is an input data bit +# +# 'o' = the bit is an output data bit +# +# Each instruction must be composed of 32 bit specifiers. The +# instruction specification closely follows the instruction data +# provided in Atmel's data sheets for their parts. +# +# See below for some examples. +# +# +# The following are STK500 part device codes to use for the +# "devicecode" field of the part. These came from Atmel's software +# section avr061.zip which accompanies the application note +# AVR061 available from: +# +# http://www.atmel.com/atmel/acrobat/doc2525.pdf +# + +#define ATTINY10 0x10 +#define ATTINY11 0x11 +#define ATTINY12 0x12 +#define ATTINY15 0x13 +#define ATTINY13 0x14 + +#define ATTINY22 0x20 +#define ATTINY26 0x21 +#define ATTINY28 0x22 +#define ATTINY2313 0x23 + +#define AT90S1200 0x33 + +#define AT90S2313 0x40 +#define AT90S2323 0x41 +#define AT90S2333 0x42 +#define AT90S2343 0x43 + +#define AT90S4414 0x50 +#define AT90S4433 0x51 +#define AT90S4434 0x52 +#define ATMEGA48 0x59 + +#define AT90S8515 0x60 +#define AT90S8535 0x61 +#define AT90C8534 0x62 +#define ATMEGA8515 0x63 +#define ATMEGA8535 0x64 + +#define ATMEGA8 0x70 +#define ATMEGA88 0x73 +#define ATMEGA168 0x86 + +#define ATMEGA161 0x80 +#define ATMEGA163 0x81 +#define ATMEGA16 0x82 +#define ATMEGA162 0x83 +#define ATMEGA169 0x84 + +#define ATMEGA323 0x90 +#define ATMEGA32 0x91 + +#define ATMEGA64 0xA0 + +#define ATMEGA103 0xB1 +#define ATMEGA128 0xB2 +#define AT90CAN128 0xB3 + +#define AT86RF401 0xD0 + +#define AT89START 0xE0 +#define AT89S51 0xE0 +#define AT89S52 0xE1 + +# The following table lists the devices in the original AVR910 +# appnote: +# |Device |Signature | Code | +# +-------+----------+------+ +# |tiny12 | 1E 90 05 | 0x55 | +# |tiny15 | 1E 90 06 | 0x56 | +# | | | | +# | S1200 | 1E 90 01 | 0x13 | +# | | | | +# | S2313 | 1E 91 01 | 0x20 | +# | S2323 | 1E 91 02 | 0x48 | +# | S2333 | 1E 91 05 | 0x34 | +# | S2343 | 1E 91 03 | 0x4C | +# | | | | +# | S4414 | 1E 92 01 | 0x28 | +# | S4433 | 1E 92 03 | 0x30 | +# | S4434 | 1E 92 02 | 0x6C | +# | | | | +# | S8515 | 1E 93 01 | 0x38 | +# | S8535 | 1E 93 03 | 0x68 | +# | | | | +# |mega32 | 1E 95 01 | 0x72 | +# |mega83 | 1E 93 05 | 0x65 | +# |mega103| 1E 97 01 | 0x41 | +# |mega161| 1E 94 01 | 0x60 | +# |mega163| 1E 94 02 | 0x64 | + +# Appnote AVR109 also has a table of AVR910 device codes, which +# lists: +# dev avr910 signature +# ATmega8 0x77 0x1E 0x93 0x07 +# ATmega8515 0x3B 0x1E 0x93 0x06 +# ATmega8535 0x6A 0x1E 0x93 0x08 +# ATmega16 0x75 0x1E 0x94 0x03 +# ATmega162 0x63 0x1E 0x94 0x04 +# ATmega163 0x66 0x1E 0x94 0x02 +# ATmega169 0x79 0x1E 0x94 0x05 +# ATmega32 0x7F 0x1E 0x95 0x02 +# ATmega323 0x73 0x1E 0x95 0x01 +# ATmega64 0x46 0x1E 0x96 0x02 +# ATmega128 0x44 0x1E 0x97 0x02 +# +# These codes refer to "BOOT" device codes which are apparently +# different than standard device codes, for whatever reasons +# (often one above the standard code). + +# There are several extended versions of AVR910 implementations around +# in the Internet. These add the following codes (only devices that +# actually exist are listed): + +# ATmega8515 0x3A +# ATmega128 0x43 +# ATmega64 0x45 +# ATtiny26 0x5E +# ATmega8535 0x69 +# ATmega32 0x72 +# ATmega16 0x74 +# ATmega8 0x76 +# ATmega169 0x78 + +# +# Overall avrdude defaults +# +default_parallel = "/dev/parport0"; +default_serial = "/dev/ttyS0"; + + +# +# PROGRAMMER DEFINITIONS +# + +programmer + id = "avrisp"; + desc = "Atmel AVR ISP"; + type = stk500; +; + +programmer + id = "avrispv2"; + desc = "Atmel AVR ISP V2"; + type = stk500v2; +; + +programmer + id = "avrispmkII"; + desc = "Atmel AVR ISP mkII"; + type = stk500v2; +; + +programmer + id = "avrisp2"; + desc = "Atmel AVR ISP mkII"; + type = stk500v2; +; + +# This is supposed to be the "default" STK500 entry. +# Attempts to select the correct firmware version +# by probing for it. Better use one of the entries +# below instead. +programmer + id = "stk500"; + desc = "Atmel STK500"; + type = stk500generic; +; + +programmer + id = "stk500v1"; + desc = "Atmel STK500 Version 1.x firmware"; + type = stk500; +; + +programmer + id = "stk500v2"; + desc = "Atmel STK500 Version 2.x firmware"; + type = stk500v2; +; + +programmer + id = "stk500pp"; + desc = "Atmel STK500 V2 in parallel programming mode"; + type = stk500pp; +; + +programmer + id = "stk500hvsp"; + desc = "Atmel STK500 V2 in high-voltage serial programming mode"; + type = stk500hvsp; +; + +programmer + id = "avr910"; + desc = "Atmel Low Cost Serial Programmer"; + type = avr910; +; + +programmer + id = "usbasp"; + desc = "USBasp, http://www.fischl.de/usbasp/"; + type = usbasp; +; + +programmer + id = "usbtiny"; + desc = "USBtiny simple USB programmer"; + type = usbtiny; +; + +programmer + id = "butterfly"; + desc = "Atmel Butterfly Development Board"; + type = butterfly; +; + +programmer + id = "avr109"; + desc = "Atmel AppNote AVR109 Boot Loader"; + type = butterfly; +; + +programmer + id = "avr911"; + desc = "Atmel AppNote AVR911 AVROSP"; + type = butterfly; +; + +programmer + id = "jtagmkI"; + desc = "Atmel JTAG ICE (mkI)"; + baudrate = 115200; # default is 115200 + type = jtagmki; +; + +# easier to type +programmer + id = "jtag1"; + desc = "Atmel JTAG ICE (mkI)"; + baudrate = 115200; # default is 115200 + type = jtagmki; +; + +# easier to type +programmer + id = "jtag1slow"; + desc = "Atmel JTAG ICE (mkI)"; + baudrate = 19200; + type = jtagmki; +; + +programmer + id = "jtagmkII"; + desc = "Atmel JTAG ICE mkII"; + baudrate = 19200; # default is 19200 + type = jtagmkii; +; + +# easier to type +programmer + id = "jtag2slow"; + desc = "Atmel JTAG ICE mkII"; + baudrate = 19200; # default is 19200 + type = jtagmkii; +; + +# JTAG ICE mkII @ 115200 Bd +programmer + id = "jtag2fast"; + desc = "Atmel JTAG ICE mkII"; + baudrate = 115200; + type = jtagmkii; +; + +# make the fast one the default, people will love that +programmer + id = "jtag2"; + desc = "Atmel JTAG ICE mkII"; + baudrate = 115200; + type = jtagmkii; +; + +# JTAG ICE mkII in ISP mode +programmer + id = "jtag2isp"; + desc = "Atmel JTAG ICE mkII in ISP mode"; + baudrate = 115200; + type = jtagmkii_isp; +; + +# JTAG ICE mkII in debugWire mode +programmer + id = "jtag2dw"; + desc = "Atmel JTAG ICE mkII in debugWire mode"; + baudrate = 115200; + type = jtagmkii_dw; +; + +# AVR Dragon in JTAG mode +programmer + id = "dragon_jtag"; + desc = "Atmel AVR Dragon in JTAG mode"; + baudrate = 115200; + type = dragon_jtag; +; + +# AVR Dragon in ISP mode +programmer + id = "dragon_isp"; + desc = "Atmel AVR Dragon in ISP mode"; + baudrate = 115200; + type = dragon_isp; +; + +# AVR Dragon in PP mode +programmer + id = "dragon_pp"; + desc = "Atmel AVR Dragon in PP mode"; + baudrate = 115200; + type = dragon_pp; +; + +# AVR Dragon in HVSP mode +programmer + id = "dragon_hvsp"; + desc = "Atmel AVR Dragon in HVSP mode"; + baudrate = 115200; + type = dragon_hvsp; +; + +# AVR Dragon in debugWire mode +programmer + id = "dragon_dw"; + desc = "Atmel AVR Dragon in debugWire mode"; + baudrate = 115200; + type = dragon_dw; +; + +programmer + id = "pavr"; + desc = "Jason Kyle's pAVR Serial Programmer"; + type = avr910; +; + +# Parallel port programmers. + +programmer + id = "bsd"; + desc = "Brian Dean's Programmer, http://www.bsdhome.com/avrdude/"; + type = par; + vcc = 2, 3, 4, 5; + reset = 7; + sck = 8; + mosi = 9; + miso = 10; +; + +programmer + id = "stk200"; + desc = "STK200"; + type = par; + buff = 4, 5; + sck = 6; + mosi = 7; + reset = 9; + miso = 10; +; + +# The programming dongle used by the popular Ponyprog +# utility. It is almost similar to the STK200 one, +# except that there is a LED indicating that the +# programming is currently in progress. + +programmer + id = "pony-stk200"; + desc = "Pony Prog STK200"; + type = par; + buff = 4, 5; + sck = 6; + mosi = 7; + reset = 9; + miso = 10; + pgmled = 8; +; + +programmer + id = "dt006"; + desc = "Dontronics DT006"; + type = par; + reset = 4; + sck = 5; + mosi = 2; + miso = 11; +; + +programmer + id = "bascom"; + desc = "Bascom SAMPLE programming cable"; + type = par; + reset = 4; + sck = 5; + mosi = 2; + miso = 11; +; + +programmer + id = "alf"; + desc = "Nightshade ALF-PgmAVR, http://nightshade.homeip.net/"; + type = par; + vcc = 2, 3, 4, 5; + buff = 6; + reset = 7; + sck = 8; + mosi = 9; + miso = 10; + errled = 1; + rdyled = 14; + pgmled = 16; + vfyled = 17; +; + +programmer + id = "sp12"; + desc = "Steve Bolt's Programmer"; + type = par; + vcc = 4,5,6,7,8; + reset = 3; + sck = 2; + mosi = 9; + miso = 11; +; + +programmer + id = "picoweb"; + desc = "Picoweb Programming Cable, http://www.picoweb.net/"; + type = par; + reset = 2; + sck = 3; + mosi = 4; + miso = 13; +; + +programmer + id = "abcmini"; + desc = "ABCmini Board, aka Dick Smith HOTCHIP"; + type = par; + reset = 4; + sck = 3; + mosi = 2; + miso = 10; +; + +programmer + id = "futurlec"; + desc = "Futurlec.com programming cable."; + type = par; + reset = 3; + sck = 2; + mosi = 1; + miso = 10; +; + + +# From the contributor of the "xil" jtag cable: +# The "vcc" definition isn't really vcc (the cable gets its power from +# the programming circuit) but is necessary to switch one of the +# buffer lines (trying to add it to the "buff" lines doesn't work). +# With this, TMS connects to RESET, TDI to MOSI, TDO to MISO and TCK +# to SCK (plus vcc/gnd of course) +programmer + id = "xil"; + desc = "Xilinx JTAG cable"; + type = par; + mosi = 2; + sck = 3; + reset = 4; + buff = 5; + miso = 13; + vcc = 6; +; + + +programmer + id = "dapa"; + desc = "Direct AVR Parallel Access cable"; + type = par; + vcc = 3; + reset = 16; + sck = 1; + mosi = 2; + miso = 11; +; + +programmer + id = "atisp"; + desc = "AT-ISP V1.1 programming cable for AVR-SDK1 from micro-research.co.th"; + type = par; + reset = ~6; + sck = ~8; + mosi = ~7; + miso = ~10; +; + +programmer + id = "ere-isp-avr"; + desc = "ERE ISP-AVR "; + type = par; + reset = ~4; + sck = 3; + mosi = 2; + miso = 10; +; + +programmer + id = "blaster"; + desc = "Altera ByteBlaster"; + type = par; + sck = 2; + miso = 11; + reset = 3; + mosi = 8; + buff = 14; +; + +# It is almost same as pony-stk200, except vcc on pin 5 to auto +# disconnect port (download on http://electropol.free.fr) +programmer + id = "frank-stk200"; + desc = "Frank STK200"; + type = par; + vcc = 5; + sck = 6; + mosi = 7; + reset = 9; + miso = 10; + pgmled = 8; +; + + +# +# some ultra cheap programmers use bitbanging on the +# serialport. +# +# PC - DB9 - Pins for RS232: +# +# GND 5 -- |O +# | O| <- 9 RI +# DTR 4 <- |O | +# | O| <- 8 CTS +# TXD 3 <- |O | +# | O| -> 7 RTS +# RXD 2 -> |O | +# | O| <- 6 DSR +# DCD 1 -> |O +# +# Using RXD is currently not supported. +# Using RI is not supported under Win32 but is supported under Posix. + +# serial ponyprog design (dasa2 in uisp) +# reset=!txd sck=rts mosi=dtr miso=cts + +programmer + id = "ponyser"; + desc = "design ponyprog serial, reset=!txd sck=rts mosi=dtr miso=cts"; + type = serbb; + reset = ~3; + sck = 7; + mosi = 4; + miso = 8; +; + +# Same as above, different name +# reset=!txd sck=rts mosi=dtr miso=cts + +programmer + id = "siprog"; + desc = "Lancos SI-Prog "; + type = serbb; + reset = ~3; + sck = 7; + mosi = 4; + miso = 8; +; + +# unknown (dasa in uisp) +# reset=rts sck=dtr mosi=txd miso=cts + +programmer + id = "dasa"; + desc = "serial port banging, reset=rts sck=dtr mosi=txd miso=cts"; + type = serbb; + reset = 7; + sck = 4; + mosi = 3; + miso = 8; +; + +# unknown (dasa3 in uisp) +# reset=!dtr sck=rts mosi=txd miso=cts + +programmer + id = "dasa3"; + desc = "serial port banging, reset=!dtr sck=rts mosi=txd miso=cts"; + type = serbb; + reset = ~4; + sck = 7; + mosi = 3; + miso = 8; +; + +# +# PART DEFINITIONS +# + +#------------------------------------------------------------ +# ATtiny11 +#------------------------------------------------------------ + +# This is an HVSP-only device. + +part + id = "t11"; + desc = "ATtiny11"; + stk500_devcode = 0x11; + signature = 0x1e 0x90 0x04; + chip_erase_delay = 20000; + + timeout = 200; + hvsp_controlstack = + 0x4C, 0x0C, 0x1C, 0x2C, 0x3C, 0x64, 0x74, 0x00, + 0x68, 0x78, 0x68, 0x68, 0x00, 0x00, 0x68, 0x78, + 0x78, 0x00, 0x6D, 0x0C, 0x80, 0x40, 0x20, 0x10, + 0x11, 0x08, 0x04, 0x02, 0x03, 0x08, 0x04, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + hvspcmdexedelay = 0; + synchcycles = 6; + latchcycles = 1; + togglevtg = 1; + poweroffdelay = 25; + resetdelayms = 0; + resetdelayus = 50; + hvleavestabdelay = 100; + resetdelay = 25; + chiperasepolltimeout = 40; + chiperasetime = 0; + programfusepolltimeout = 25; + programlockpolltimeout = 25; + + memory "eeprom" + size = 64; + blocksize = 64; + readsize = 256; + delay = 5; + ; + + memory "flash" + size = 1024; + blocksize = 128; + readsize = 256; + delay = 3; + ; + + memory "signature" + size = 3; + ; + + memory "lock" + size = 1; + ; + + memory "calibration" + size = 1; + ; + + memory "fuse" + size = 1; + ; +; + +#------------------------------------------------------------ +# ATtiny12 +#------------------------------------------------------------ + +part + id = "t12"; + desc = "ATtiny12"; + stk500_devcode = 0x12; + avr910_devcode = 0x55; + signature = 0x1e 0x90 0x05; + chip_erase_delay = 20000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 0; + + hvsp_controlstack = + 0x4C, 0x0C, 0x1C, 0x2C, 0x3C, 0x64, 0x74, 0x00, + 0x68, 0x78, 0x68, 0x68, 0x00, 0x00, 0x68, 0x78, + 0x78, 0x00, 0x6D, 0x0C, 0x80, 0x40, 0x20, 0x10, + 0x11, 0x08, 0x04, 0x02, 0x03, 0x08, 0x04, 0x00; + hventerstabdelay = 100; + hvspcmdexedelay = 0; + synchcycles = 6; + latchcycles = 1; + togglevtg = 1; + poweroffdelay = 25; + resetdelayms = 0; + resetdelayus = 50; + hvleavestabdelay = 100; + resetdelay = 25; + chiperasepolltimeout = 40; + chiperasetime = 0; + programfusepolltimeout = 25; + programlockpolltimeout = 25; + + memory "eeprom" + size = 64; + min_write_delay = 9000; + max_write_delay = 20000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = "1 0 1 0 0 0 0 0 x x x x x x x x", + "x x a5 a4 a3 a2 a1 a0 o o o o o o o o"; + + write = "1 1 0 0 0 0 0 0 x x x x x x x x", + "x x a5 a4 a3 a2 a1 a0 i i i i i i i i"; + + mode = 0x04; + delay = 8; + blocksize = 64; + readsize = 256; + ; + + memory "flash" + size = 1024; + min_write_delay = 4500; + max_write_delay = 20000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " x x x x x x x a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " x x x x x x x a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write_lo = " 0 1 0 0 0 0 0 0", + " x x x x x x x a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + write_hi = " 0 1 0 0 1 0 0 0", + " x x x x x x x a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + mode = 0x04; + delay = 5; + blocksize = 128; + readsize = 256; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "0 0 0 0 0 0 a1 a0 o o o o o o o o"; + ; + + memory "lock" + size = 1; + read = "0 1 0 1 1 0 0 0 x x x x x x x x", + "x x x x x x x x x x x x x o o x"; + + write = "1 0 1 0 1 1 0 0 1 1 1 1 1 i i 1", + "x x x x x x x x x x x x x x x x"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 x x x x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + + memory "fuse" + size = 1; + read = "0 1 0 1 0 0 0 0 x x x x x x x x", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 x x x x x", + "x x x x x x x x i i i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; +; + +#------------------------------------------------------------ +# ATtiny13 +#------------------------------------------------------------ + +part + id = "t13"; + desc = "ATtiny13"; + has_debugwire = yes; + flash_instr = 0xB4, 0x0E, 0x1E; + eeprom_instr = 0xBB, 0xFE, 0xBB, 0xEE, 0xBB, 0xCC, 0xB2, 0x0D, + 0xBC, 0x0E, 0xB4, 0x0E, 0xBA, 0x0D, 0xBB, 0xBC, + 0x99, 0xE1, 0xBB, 0xAC; + stk500_devcode = 0x14; + signature = 0x1e 0x90 0x07; + chip_erase_delay = 4000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + hvsp_controlstack = + 0x4C, 0x0C, 0x1C, 0x2C, 0x3C, 0x64, 0x74, 0x66, + 0x68, 0x78, 0x68, 0x68, 0x7A, 0x6A, 0x68, 0x78, + 0x78, 0x7D, 0x6D, 0x0C, 0x80, 0x40, 0x20, 0x10, + 0x11, 0x08, 0x04, 0x02, 0x03, 0x08, 0x04, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + hvspcmdexedelay = 0; + synchcycles = 6; + latchcycles = 1; + togglevtg = 1; + poweroffdelay = 25; + resetdelayms = 0; + resetdelayus = 90; + hvleavestabdelay = 100; + resetdelay = 25; + chiperasepolltimeout = 40; + chiperasetime = 0; + programfusepolltimeout = 25; + programlockpolltimeout = 25; + + memory "eeprom" + size = 64; + page_size = 4; + min_write_delay = 4000; + max_write_delay = 4000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = "1 0 1 0 0 0 0 0 0 0 0 x x x x x", + "x x a5 a4 a3 a2 a1 a0 o o o o o o o o"; + + write = "1 1 0 0 0 0 0 0 0 0 0 x x x x x", + "x x a5 a4 a3 a2 a1 a0 i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x x x x", + " x x a5 a4 a3 a2 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 5; + blocksize = 4; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 1024; + page_size = 32; + num_pages = 32; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " 0 0 0 0 0 0 0 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 0 0 0 0 0 0 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 0 x x x x x", + " x x x x a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 0 x x x x x", + " x x x x a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " 0 0 0 0 0 0 0 a8", + " a7 a6 a5 a4 x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 32; + readsize = 256; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 0 0 0 x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + + memory "lock" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + ; + + memory "calibration" + size = 2; + read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x", + "0 0 0 0 0 0 0 a0 o o o o o o o o"; + ; + + memory "lfuse" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + ; + + memory "hfuse" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + ; + +; + + +#------------------------------------------------------------ +# ATtiny15 +#------------------------------------------------------------ + +part + id = "t15"; + desc = "ATtiny15"; + stk500_devcode = 0x13; + avr910_devcode = 0x56; + signature = 0x1e 0x90 0x06; + chip_erase_delay = 8200; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 0; + + hvsp_controlstack = + 0x4C, 0x0C, 0x1C, 0x2C, 0x3C, 0x64, 0x74, 0x00, + 0x68, 0x78, 0x68, 0x68, 0x00, 0x00, 0x68, 0x78, + 0x78, 0x00, 0x6D, 0x0C, 0x80, 0x40, 0x20, 0x10, + 0x11, 0x08, 0x04, 0x02, 0x03, 0x08, 0x04, 0x00; + hventerstabdelay = 100; + hvspcmdexedelay = 5; + synchcycles = 6; + latchcycles = 16; + togglevtg = 1; + poweroffdelay = 25; + resetdelayms = 0; + resetdelayus = 50; + hvleavestabdelay = 100; + resetdelay = 25; + chiperasepolltimeout = 40; + chiperasetime = 0; + programfusepolltimeout = 25; + programlockpolltimeout = 25; + + memory "eeprom" + size = 64; + min_write_delay = 8200; + max_write_delay = 8200; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = "1 0 1 0 0 0 0 0 x x x x x x x x", + "x x a5 a4 a3 a2 a1 a0 o o o o o o o o"; + + write = "1 1 0 0 0 0 0 0 x x x x x x x x", + "x x a5 a4 a3 a2 a1 a0 i i i i i i i i"; + + mode = 0x04; + delay = 10; + blocksize = 64; + readsize = 256; + ; + + memory "flash" + size = 1024; + min_write_delay = 4100; + max_write_delay = 4100; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " x x x x x x x a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " x x x x x x x a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write_lo = " 0 1 0 0 0 0 0 0", + " x x x x x x x a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + write_hi = " 0 1 0 0 1 0 0 0", + " x x x x x x x a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + mode = 0x04; + delay = 5; + blocksize = 128; + readsize = 256; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "0 0 0 0 0 0 a1 a0 o o o o o o o o"; + ; + + memory "lock" + size = 1; + read = "0 1 0 1 1 0 0 0 x x x x x x x x", + "x x x x x x x x x x x x x o o x"; + + write = "1 0 1 0 1 1 0 0 1 1 1 1 1 i i 1", + "x x x x x x x x x x x x x x x x"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 x x x x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + + memory "fuse" + size = 1; + read = "0 1 0 1 0 0 0 0 x x x x x x x x", + "x x x x x x x x o o o o x x o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 x x x x x", + "x x x x x x x x i i i i 1 1 i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; +; + +#------------------------------------------------------------ +# AT90s1200 +#------------------------------------------------------------ + +part + id = "1200"; + desc = "AT90S1200"; + stk500_devcode = 0x33; + avr910_devcode = 0x13; + signature = 0x1e 0x90 0x01; + pagel = 0xd7; + bs2 = 0xa0; + chip_erase_delay = 20000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 1; + bytedelay = 0; + pollindex = 0; + pollvalue = 0xFF; + predelay = 1; + postdelay = 1; + pollmethod = 0; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 0; + togglevtg = 0; + poweroffdelay = 0; + resetdelayms = 0; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 15; + chiperasepolltimeout = 0; + programfusepulsewidth = 2; + programfusepolltimeout = 0; + programlockpulsewidth = 0; + programlockpolltimeout = 1; + + memory "eeprom" + size = 64; + min_write_delay = 4000; + max_write_delay = 9000; + readback_p1 = 0x00; + readback_p2 = 0xff; + read = "1 0 1 0 0 0 0 0 x x x x x x x x", + "x x a5 a4 a3 a2 a1 a0 o o o o o o o o"; + + write = "1 1 0 0 0 0 0 0 x x x x x x x x", + "x x a5 a4 a3 a2 a1 a0 i i i i i i i i"; + + mode = 0x04; + delay = 20; + blocksize = 32; + readsize = 256; + ; + memory "flash" + size = 1024; + min_write_delay = 4000; + max_write_delay = 9000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " x x x x x x x a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " x x x x x x x a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write_lo = " 0 1 0 0 0 0 0 0", + " x x x x x x x a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + write_hi = " 0 1 0 0 1 0 0 0", + " x x x x x x x a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + mode = 0x02; + delay = 15; + blocksize = 128; + readsize = 256; + ; + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + memory "fuse" + size = 1; + ; + memory "lock" + size = 1; + min_write_delay = 9000; + max_write_delay = 20000; + write = "1 0 1 0 1 1 0 0 1 1 1 1 1 i i 1", + "x x x x x x x x x x x x x x x x"; + ; + ; + +#------------------------------------------------------------ +# AT90s4414 +#------------------------------------------------------------ + +part + id = "4414"; + desc = "AT90S4414"; + stk500_devcode = 0x50; + avr910_devcode = 0x28; + signature = 0x1e 0x92 0x01; + chip_erase_delay = 20000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 0; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 0; + togglevtg = 0; + poweroffdelay = 0; + resetdelayms = 0; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 15; + chiperasepolltimeout = 0; + programfusepulsewidth = 2; + programfusepolltimeout = 0; + programlockpulsewidth = 0; + programlockpolltimeout = 1; + + memory "eeprom" + size = 256; + min_write_delay = 9000; + max_write_delay = 20000; + readback_p1 = 0x80; + readback_p2 = 0x7f; + read = " 1 0 1 0 0 0 0 0 x x x x x x x a8", + "a7 a6 a5 a4 a3 a2 a1 a0 o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0 x x x x x x x a8", + "a7 a6 a5 a4 a3 a2 a1 a0 i i i i i i i i"; + + mode = 0x04; + delay = 12; + blocksize = 64; + readsize = 256; + ; + memory "flash" + size = 4096; + min_write_delay = 9000; + max_write_delay = 20000; + readback_p1 = 0x7f; + readback_p2 = 0x7f; + read_lo = " 0 0 1 0 0 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write_lo = " 0 1 0 0 0 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + write_hi = " 0 1 0 0 1 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + mode = 0x04; + delay = 12; + blocksize = 64; + readsize = 256; + ; + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + memory "fuse" + size = 1; + ; + memory "lock" + size = 1; + write = "1 0 1 0 1 1 0 0 1 1 1 1 1 i i 1", + "x x x x x x x x x x x x x x x x"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + ; + +#------------------------------------------------------------ +# AT90s2313 +#------------------------------------------------------------ + +part + id = "2313"; + desc = "AT90S2313"; + stk500_devcode = 0x40; + avr910_devcode = 0x20; + signature = 0x1e 0x91 0x01; + chip_erase_delay = 20000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 0; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 0; + togglevtg = 0; + poweroffdelay = 0; + resetdelayms = 0; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 15; + chiperasepolltimeout = 0; + programfusepulsewidth = 2; + programfusepolltimeout = 0; + programlockpulsewidth = 0; + programlockpolltimeout = 1; + + memory "eeprom" + size = 128; + min_write_delay = 4000; + max_write_delay = 9000; + readback_p1 = 0x80; + readback_p2 = 0x7f; + read = "1 0 1 0 0 0 0 0 x x x x x x x x", + "x a6 a5 a4 a3 a2 a1 a0 o o o o o o o o"; + + write = "1 1 0 0 0 0 0 0 x x x x x x x x", + "x a6 a5 a4 a3 a2 a1 a0 i i i i i i i i"; + + mode = 0x04; + delay = 12; + blocksize = 64; + readsize = 256; + ; + memory "flash" + size = 2048; + min_write_delay = 4000; + max_write_delay = 9000; + readback_p1 = 0x7f; + readback_p2 = 0x7f; + read_lo = " 0 0 1 0 0 0 0 0", + " x x x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " x x x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write_lo = " 0 1 0 0 0 0 0 0", + " x x x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + write_hi = " 0 1 0 0 1 0 0 0", + " x x x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + mode = 0x04; + delay = 12; + blocksize = 128; + readsize = 256; + ; + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + memory "fuse" + size = 1; + ; + memory "lock" + size = 1; + write = "1 0 1 0 1 1 0 0 1 1 1 x x i i x", + "x x x x x x x x x x x x x x x x"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + ; + +#------------------------------------------------------------ +# AT90s2333 +#------------------------------------------------------------ + +part + id = "2333"; +##### WARNING: No XML file for device 'AT90S2333'! ##### + desc = "AT90S2333"; + stk500_devcode = 0x42; + avr910_devcode = 0x34; + signature = 0x1e 0x91 0x05; + chip_erase_delay = 20000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0", + "x x x x x x x x x x x x x x x x"; + + memory "eeprom" + size = 128; + min_write_delay = 9000; + max_write_delay = 20000; + readback_p1 = 0x00; + readback_p2 = 0xff; + read = "1 0 1 0 0 0 0 0 x x x x x x x x", + "x a6 a5 a4 a3 a2 a1 a0 o o o o o o o o"; + + write = "1 1 0 0 0 0 0 0 x x x x x x x x", + "x a6 a5 a4 a3 a2 a1 a0 i i i i i i i i"; + ; + memory "flash" + size = 2048; + min_write_delay = 9000; + max_write_delay = 20000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " x x x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " x x x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write_lo = " 0 1 0 0 0 0 0 0", + " x x x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + write_hi = " 0 1 0 0 1 0 0 0", + " x x x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + ; + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + memory "fuse" + size = 1; + min_write_delay = 9000; + max_write_delay = 20000; + pwroff_after_write = yes; + read = "0 1 0 1 0 0 0 0 x x x x x x x x", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 i i i i i", + "x x x x x x x x x x x x x x x x"; + ; + memory "lock" + size = 1; + min_write_delay = 9000; + max_write_delay = 20000; + read = "0 1 0 1 1 0 0 0 x x x x x x x x", + "x x x x x x x x x x x x x o o x"; + + write = "1 0 1 0 1 1 0 0 1 1 1 1 1 i i 1", + "x x x x x x x x x x x x x x x x"; + ; + ; + + +#------------------------------------------------------------ +# AT90s2343 (also AT90s2323 and ATtiny22) +#------------------------------------------------------------ + +part + id = "2343"; + desc = "AT90S2343"; + stk500_devcode = 0x43; + avr910_devcode = 0x4c; + signature = 0x1e 0x91 0x03; + chip_erase_delay = 18000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 0; + + hvsp_controlstack = + 0x4C, 0x0C, 0x1C, 0x2C, 0x3C, 0x64, 0x74, 0x00, + 0x68, 0x78, 0x68, 0x68, 0x00, 0x00, 0x68, 0x78, + 0x78, 0x00, 0x6D, 0x0C, 0x80, 0x40, 0x20, 0x10, + 0x11, 0x08, 0x04, 0x02, 0x03, 0x08, 0x04, 0x00; + hventerstabdelay = 100; + hvspcmdexedelay = 0; + synchcycles = 6; + latchcycles = 1; + togglevtg = 0; + poweroffdelay = 25; + resetdelayms = 0; + resetdelayus = 50; + hvleavestabdelay = 100; + resetdelay = 25; + chiperasepolltimeout = 40; + chiperasetime = 0; + programfusepolltimeout = 25; + programlockpolltimeout = 25; + + memory "eeprom" + size = 128; + min_write_delay = 9000; + max_write_delay = 20000; + readback_p1 = 0x00; + readback_p2 = 0xff; + read = "1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0", + "x a6 a5 a4 a3 a2 a1 a0 o o o o o o o o"; + + write = "1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0", + "x a6 a5 a4 a3 a2 a1 a0 i i i i i i i i"; + + mode = 0x04; + delay = 12; + blocksize = 64; + readsize = 256; + ; + memory "flash" + size = 2048; + min_write_delay = 9000; + max_write_delay = 20000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " x x x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " x x x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write_lo = " 0 1 0 0 0 0 0 0", + " x x x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + write_hi = " 0 1 0 0 1 0 0 0", + " x x x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + mode = 0x04; + delay = 12; + blocksize = 128; + readsize = 128; + ; + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + memory "fuse" + size = 1; + min_write_delay = 9000; + max_write_delay = 20000; + read = "0 1 0 1 1 0 0 0 x x x x x x x x", + "x x x x x x x x o o o x x x x o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 1 1 1 1 i", + "x x x x x x x x x x x x x x x x"; + ; + memory "lock" + size = 1; + min_write_delay = 9000; + max_write_delay = 20000; + read = "0 1 0 1 1 0 0 0 x x x x x x x x", + "x x x x x x x x o o o x x x x o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 1 1 i i 1", + "x x x x x x x x x x x x x x x x"; + ; + ; + + +#------------------------------------------------------------ +# AT90s4433 +#------------------------------------------------------------ + +part + id = "4433"; + desc = "AT90S4433"; + stk500_devcode = 0x51; + avr910_devcode = 0x30; + signature = 0x1e 0x92 0x03; + chip_erase_delay = 20000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 0; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 0; + togglevtg = 0; + poweroffdelay = 0; + resetdelayms = 0; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 15; + chiperasepolltimeout = 0; + programfusepulsewidth = 2; + programfusepolltimeout = 0; + programlockpulsewidth = 0; + programlockpolltimeout = 1; + + memory "eeprom" + size = 256; + min_write_delay = 9000; + max_write_delay = 20000; + readback_p1 = 0x00; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0 x x x x x x x x", + "a7 a6 a5 a4 a3 a2 a1 a0 o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0 x x x x x x x x", + "a7 a6 a5 a4 a3 a2 a1 a0 i i i i i i i i"; + + mode = 0x04; + delay = 12; + blocksize = 128; + readsize = 256; + ; + memory "flash" + size = 4096; + min_write_delay = 9000; + max_write_delay = 20000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " x x x x x a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " x x x x x a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write_lo = " 0 1 0 0 0 0 0 0", + " x x x x x a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + write_hi = " 0 1 0 0 1 0 0 0", + " x x x x x a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + mode = 0x04; + delay = 12; + blocksize = 128; + readsize = 256; + ; + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + memory "fuse" + size = 1; + min_write_delay = 9000; + max_write_delay = 20000; + pwroff_after_write = yes; + read = "0 1 0 1 0 0 0 0 x x x x x x x x", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 i i i i i", + "x x x x x x x x x x x x x x x x"; + ; + memory "lock" + size = 1; + min_write_delay = 9000; + max_write_delay = 20000; + read = "0 1 0 1 1 0 0 0 x x x x x x x x", + "x x x x x x x x x x x x x o o x"; + + write = "1 0 1 0 1 1 0 0 1 1 1 1 1 i i 1", + "x x x x x x x x x x x x x x x x"; + ; + ; + +#------------------------------------------------------------ +# AT90s4434 +#------------------------------------------------------------ + +part + id = "4434"; +##### WARNING: No XML file for device 'AT90S4434'! ##### + desc = "AT90S4434"; + stk500_devcode = 0x52; + avr910_devcode = 0x6c; + signature = 0x1e 0x92 0x02; + chip_erase_delay = 20000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0", + "x x x x x x x x x x x x x x x x"; + + memory "eeprom" + size = 256; + min_write_delay = 9000; + max_write_delay = 20000; + readback_p1 = 0x00; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0 x x x x x x x x", + "a7 a6 a5 a4 a3 a2 a1 a0 o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0 x x x x x x x x", + "a7 a6 a5 a4 a3 a2 a1 a0 i i i i i i i i"; + ; + memory "flash" + size = 4096; + min_write_delay = 9000; + max_write_delay = 20000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " x x x x x a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " x x x x x a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write_lo = " 0 1 0 0 0 0 0 0", + " x x x x x a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + write_hi = " 0 1 0 0 1 0 0 0", + " x x x x x a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + ; + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + memory "fuse" + size = 1; + min_write_delay = 9000; + max_write_delay = 20000; + read = "0 1 0 1 0 0 0 0 x x x x x x x x", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 i i i i i", + "x x x x x x x x x x x x x x x x"; + ; + memory "lock" + size = 1; + min_write_delay = 9000; + max_write_delay = 20000; + read = "0 1 0 1 1 0 0 0 x x x x x x x x", + "x x x x x x x x x x x x x o o x"; + + write = "1 0 1 0 1 1 0 0 1 1 1 1 1 i i 1", + "x x x x x x x x x x x x x x x x"; + ; + ; + +#------------------------------------------------------------ +# AT90s8515 +#------------------------------------------------------------ + +part + id = "8515"; + desc = "AT90S8515"; + stk500_devcode = 0x60; + avr910_devcode = 0x38; + signature = 0x1e 0x93 0x01; + chip_erase_delay = 20000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 0; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 0; + togglevtg = 0; + poweroffdelay = 0; + resetdelayms = 0; + resetdelayus = 0; + hvleavestabdelay = 15; + resetdelay = 15; + chiperasepulsewidth = 15; + chiperasepolltimeout = 0; + programfusepulsewidth = 2; + programfusepolltimeout = 0; + programlockpulsewidth = 0; + programlockpolltimeout = 1; + + memory "eeprom" + size = 512; + min_write_delay = 4000; + max_write_delay = 9000; + readback_p1 = 0x80; + readback_p2 = 0x7f; + read = " 1 0 1 0 0 0 0 0 x x x x x x x a8", + "a7 a6 a5 a4 a3 a2 a1 a0 o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0 x x x x x x x a8", + "a7 a6 a5 a4 a3 a2 a1 a0 i i i i i i i i"; + + mode = 0x04; + delay = 12; + blocksize = 128; + readsize = 256; + ; + memory "flash" + size = 8192; + min_write_delay = 4000; + max_write_delay = 9000; + readback_p1 = 0x7f; + readback_p2 = 0x7f; + read_lo = " 0 0 1 0 0 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write_lo = " 0 1 0 0 0 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + write_hi = " 0 1 0 0 1 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + mode = 0x04; + delay = 12; + blocksize = 128; + readsize = 256; + ; + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + memory "fuse" + size = 1; + ; + memory "lock" + size = 1; + write = "1 0 1 0 1 1 0 0 1 1 1 1 1 i i 1", + "x x x x x x x x x x x x x x x x"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + ; + +#------------------------------------------------------------ +# AT90s8535 +#------------------------------------------------------------ + +part + id = "8535"; + desc = "AT90S8535"; + stk500_devcode = 0x61; + avr910_devcode = 0x68; + signature = 0x1e 0x93 0x03; + chip_erase_delay = 20000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 0; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 0; + togglevtg = 0; + poweroffdelay = 0; + resetdelayms = 0; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 15; + chiperasepolltimeout = 0; + programfusepulsewidth = 2; + programfusepolltimeout = 0; + programlockpulsewidth = 0; + programlockpolltimeout = 1; + + memory "eeprom" + size = 512; + min_write_delay = 9000; + max_write_delay = 20000; + readback_p1 = 0x00; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0 x x x x x x x a8", + "a7 a6 a5 a4 a3 a2 a1 a0 o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0 x x x x x x x a8", + "a7 a6 a5 a4 a3 a2 a1 a0 i i i i i i i i"; + + mode = 0x04; + delay = 12; + blocksize = 128; + readsize = 256; + ; + memory "flash" + size = 8192; + min_write_delay = 9000; + max_write_delay = 20000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write_lo = " 0 1 0 0 0 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + write_hi = " 0 1 0 0 1 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + mode = 0x04; + delay = 12; + blocksize = 128; + readsize = 256; + ; + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + memory "fuse" + size = 1; + read = "0 1 0 1 1 0 0 0 x x x x x x x x", + "x x x x x x x x x x x x x x x o"; + write = "1 0 1 0 1 1 0 0 1 0 1 1 1 1 1 i", + "x x x x x x x x x x x x x x x x"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + memory "lock" + size = 1; + read = "0 1 0 1 1 0 0 0 x x x x x x x x", + "x x x x x x x x o o x x x x x x"; + write = "1 0 1 0 1 1 0 0 1 1 1 1 1 i i 1", + "x x x x x x x x x x x x x x x x"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + ; + +#------------------------------------------------------------ +# ATmega103 +#------------------------------------------------------------ + +part + id = "m103"; + desc = "ATMEGA103"; + stk500_devcode = 0xB1; + avr910_devcode = 0x41; + signature = 0x1e 0x97 0x01; + chip_erase_delay = 112000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 0; + + pp_controlstack = + 0x0E, 0x1E, 0x8E, 0x9E, 0x2E, 0x3E, 0xAE, 0xBE, + 0x4E, 0x5E, 0xCE, 0xDE, 0x6E, 0x7E, 0xEE, 0xDE, + 0x66, 0x76, 0xE6, 0xF6, 0x6A, 0x7A, 0xEA, 0x7A, + 0x7F, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 0; + togglevtg = 0; + poweroffdelay = 0; + resetdelayms = 0; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 15; + chiperasepolltimeout = 0; + programfusepulsewidth = 2; + programfusepolltimeout = 0; + programlockpulsewidth = 0; + programlockpolltimeout = 10; + + memory "eeprom" + size = 4096; + min_write_delay = 4000; + max_write_delay = 9000; + readback_p1 = 0x80; + readback_p2 = 0x7f; + read = " 1 0 1 0 0 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + mode = 0x04; + delay = 12; + blocksize = 64; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 131072; + page_size = 256; + num_pages = 512; + min_write_delay = 22000; + max_write_delay = 56000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " x x x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " x x x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 x x x x x x x", + " x x x x x x x x"; + + mode = 0x11; + delay = 70; + blocksize = 256; + readsize = 256; + ; + + memory "fuse" + size = 1; + read = "0 1 0 1 0 0 0 0 x x x x x x x x", + "x x x x x x x x x x o x o 1 o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 1 i 1 i i", + "x x x x x x x x x x x x x x x x"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lock" + size = 1; + read = "0 1 0 1 1 0 0 0 x x x x x x x x", + "x x x x x x x x x x x x x o o x"; + + write = "1 0 1 0 1 1 0 0 1 1 1 1 1 i i 1", + "x x x x x x x x x x x x x x x x"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + ; + + +#------------------------------------------------------------ +# ATmega64 +#------------------------------------------------------------ + +part + id = "m64"; + desc = "ATMEGA64"; + has_jtag = yes; + stk500_devcode = 0xA0; + avr910_devcode = 0x45; + signature = 0x1e 0x96 0x02; + chip_erase_delay = 9000; + pagel = 0xD7; + bs2 = 0xA0; + reset = dedicated; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 0; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 6; + togglevtg = 0; + poweroffdelay = 0; + resetdelayms = 0; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + idr = 0x22; + spmcr = 0x68; + allowfullpagebitstream = yes; + + memory "eeprom" + paged = no; /* leave this "no" */ + page_size = 8; /* for parallel programming */ + size = 2048; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + mode = 0x04; + delay = 20; + blocksize = 64; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 65536; + page_size = 256; + num_pages = 256; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " x a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " x a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " x x x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " x x x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " x a14 a13 a12 a11 a10 a9 a8", + " a7 x x x x x x x", + " x x x x x x x x"; + + mode = 0x21; + delay = 6; + blocksize = 128; + readsize = 256; + ; + + memory "lfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x x x i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lock" + size = 1; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "calibration" + size = 4; + read = "0 0 1 1 1 0 0 0 x x x x x x x x", + "0 0 0 0 0 0 a1 a0 o o o o o o o o"; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + ; + + + + +#------------------------------------------------------------ +# ATmega128 +#------------------------------------------------------------ + +part + id = "m128"; + desc = "ATMEGA128"; + has_jtag = yes; + stk500_devcode = 0xB2; + avr910_devcode = 0x43; + signature = 0x1e 0x97 0x02; + chip_erase_delay = 9000; + pagel = 0xD7; + bs2 = 0xA0; + reset = dedicated; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 0; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 6; + togglevtg = 0; + poweroffdelay = 0; + resetdelayms = 0; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + idr = 0x22; + spmcr = 0x68; + rampz = 0x3b; + allowfullpagebitstream = yes; + + memory "eeprom" + paged = no; /* leave this "no" */ + page_size = 8; /* for parallel programming */ + size = 4096; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + mode = 0x04; + delay = 12; + blocksize = 64; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 131072; + page_size = 256; + num_pages = 512; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " x x x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " x x x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 x x x x x x x", + " x x x x x x x x"; + + mode = 0x21; + delay = 6; + blocksize = 128; + readsize = 256; + ; + + memory "lfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x x x i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lock" + size = 1; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "calibration" + size = 4; + read = "0 0 1 1 1 0 0 0 x x x x x x x x", + "0 0 0 0 0 0 a1 a0 o o o o o o o o"; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# AT90CAN128 +#------------------------------------------------------------ + +part + id = "c128"; + desc = "AT90CAN128"; + has_jtag = yes; + stk500_devcode = 0xB3; +# avr910_devcode = 0x43; + signature = 0x1e 0x97 0x81; + chip_erase_delay = 9000; + pagel = 0xD7; + bs2 = 0xA0; + reset = dedicated; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 6; + togglevtg = 0; + poweroffdelay = 0; + resetdelayms = 0; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + idr = 0x31; + spmcr = 0x57; + rampz = 0x3b; + eecr = 0x3f; + allowfullpagebitstream = no; + + memory "eeprom" + paged = no; /* leave this "no" */ + page_size = 8; /* for parallel programming */ + size = 4096; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0", + " 0 0 0 x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " 0 0 0 x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 0 0 0", + " x x x x x x x x"; + + + mode = 0x41; + delay = 20; + blocksize = 8; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 131072; + page_size = 256; + num_pages = 512; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 0 x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 0 x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 x x x x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 256; + readsize = 256; + ; + + memory "lfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lock" + size = 1; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + ; + + +#------------------------------------------------------------ +# ATmega16 +#------------------------------------------------------------ + +part + id = "m16"; + desc = "ATMEGA16"; + has_jtag = yes; + stk500_devcode = 0x82; + avr910_devcode = 0x74; + signature = 0x1e 0x94 0x03; + pagel = 0xd7; + bs2 = 0xa0; + chip_erase_delay = 9000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 0; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 100; + latchcycles = 6; + togglevtg = 0; + poweroffdelay = 0; + resetdelayms = 0; + resetdelayus = 0; + hvleavestabdelay = 15; + resetdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + idr = 0x31; + spmcr = 0x57; + allowfullpagebitstream = yes; + + memory "eeprom" + paged = no; /* leave this "no" */ + page_size = 4; /* for parallel programming */ + size = 512; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0", + " 0 0 x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " 0 0 x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 0 0", + " x x x x x x x x"; + + mode = 0x04; + delay = 10; + blocksize = 128; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 16384; + page_size = 128; + num_pages = 128; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " 0 0 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 0 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 x x x x x x", + " x x a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 x x x x x x", + " x x a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " 0 0 a13 a12 a11 a10 a9 a8", + " a7 a6 x x x x x x", + " x x x x x x x x"; + + mode = 0x21; + delay = 6; + blocksize = 128; + readsize = 256; + ; + + memory "lock" + size = 1; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lfuse" + size = 1; + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + memory "calibration" + size = 4; + + read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x", + "0 0 0 0 0 0 a1 a0 o o o o o o o o"; + ; + ; + + +#------------------------------------------------------------ +# ATmega164P +#------------------------------------------------------------ + +# close to ATmega16 + +part + id = "m164p"; + desc = "ATMEGA164P"; + has_jtag = yes; +# stk500_devcode = 0x82; # no STK500v1 support +# avr910_devcode = 0x?; # try the ATmega16 one:^ + avr910_devcode = 0x74; + signature = 0x1e 0x94 0x0a; + pagel = 0xd7; + bs2 = 0xa0; + chip_erase_delay = 9000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 0; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + idr = 0x31; + spmcr = 0x57; + allowfullpagebitstream = no; + + memory "eeprom" + paged = no; /* leave this "no" */ + page_size = 4; /* for parallel programming */ + size = 512; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0", + " 0 0 x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " 0 0 x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 10; + blocksize = 128; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 16384; + page_size = 128; + num_pages = 128; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " 0 0 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 0 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 x x x x x x", + " x x a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 x x x x x x", + " x x a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " 0 0 a13 a12 a11 a10 a9 a8", + " a7 a6 x x x x x x", + " x x x x x x x x"; + + mode = 0x21; + delay = 6; + blocksize = 128; + readsize = 256; + ; + + memory "lock" + size = 1; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lfuse" + size = 1; + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x 1 1 1 1 1 i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + + memory "calibration" + size = 1; + + read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + ; + + +#------------------------------------------------------------ +# ATmega324P +#------------------------------------------------------------ + +# similar to ATmega164P + +part + id = "m324p"; + desc = "ATMEGA324P"; + has_jtag = yes; +# stk500_devcode = 0x82; # no STK500v1 support +# avr910_devcode = 0x?; # try the ATmega16 one:^ + avr910_devcode = 0x74; + signature = 0x1e 0x95 0x08; + pagel = 0xd7; + bs2 = 0xa0; + chip_erase_delay = 9000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 0; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + idr = 0x31; + spmcr = 0x57; + allowfullpagebitstream = no; + + memory "eeprom" + paged = no; /* leave this "no" */ + page_size = 4; /* for parallel programming */ + size = 1024; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0", + " 0 0 x x x a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " 0 0 x x x a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x a10 a9 a8", + " a7 a6 a5 a4 a3 a2 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 10; + blocksize = 128; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 32768; + page_size = 128; + num_pages = 256; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " 0 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 x x x x x x", + " x x a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 x x x x x x", + " x x a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " 0 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 x x x x x x", + " x x x x x x x x"; + + mode = 0x21; + delay = 6; + blocksize = 256; + readsize = 256; + ; + + memory "lock" + size = 1; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lfuse" + size = 1; + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x 1 1 1 1 1 i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + + memory "calibration" + size = 1; + + read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + ; + + +#------------------------------------------------------------ +# ATmega644 +#------------------------------------------------------------ + +# similar to ATmega164 + +part + id = "m644"; + desc = "ATMEGA644"; + has_jtag = yes; +# stk500_devcode = 0x82; # no STK500v1 support +# avr910_devcode = 0x?; # try the ATmega16 one:^ + avr910_devcode = 0x74; + signature = 0x1e 0x96 0x09; + pagel = 0xd7; + bs2 = 0xa0; + chip_erase_delay = 9000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 0; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 6; + togglevtg = 0; + poweroffdelay = 0; + resetdelayms = 0; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + idr = 0x31; + spmcr = 0x57; + allowfullpagebitstream = no; + + memory "eeprom" + paged = no; /* leave this "no" */ + page_size = 8; /* for parallel programming */ + size = 2048; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0", + " 0 0 x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " 0 0 x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 0 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 10; + blocksize = 128; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 65536; + page_size = 256; + num_pages = 256; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 x x x x x x x", + " x x x x x x x x"; + + mode = 0x21; + delay = 6; + blocksize = 256; + readsize = 256; + ; + + memory "lock" + size = 1; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lfuse" + size = 1; + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x 1 1 1 1 1 i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + + memory "calibration" + size = 1; + + read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# ATmega644P +#------------------------------------------------------------ + +# similar to ATmega164p + +part + id = "m644p"; + desc = "ATMEGA644P"; + has_jtag = yes; +# stk500_devcode = 0x82; # no STK500v1 support +# avr910_devcode = 0x?; # try the ATmega16 one:^ + avr910_devcode = 0x74; + signature = 0x1e 0x96 0x0a; + pagel = 0xd7; + bs2 = 0xa0; + chip_erase_delay = 9000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 0; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 6; + togglevtg = 0; + poweroffdelay = 0; + resetdelayms = 0; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + idr = 0x31; + spmcr = 0x57; + allowfullpagebitstream = no; + + memory "eeprom" + paged = no; /* leave this "no" */ + page_size = 8; /* for parallel programming */ + size = 2048; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0", + " 0 0 x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " 0 0 x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 0 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 10; + blocksize = 128; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 65536; + page_size = 256; + num_pages = 256; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 x x x x x x x", + " x x x x x x x x"; + + mode = 0x21; + delay = 6; + blocksize = 256; + readsize = 256; + ; + + memory "lock" + size = 1; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lfuse" + size = 1; + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x 1 1 1 1 1 i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + + memory "calibration" + size = 1; + + read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + ; + + + +#------------------------------------------------------------ +# ATmega162 +#------------------------------------------------------------ + +part + id = "m162"; + desc = "ATMEGA162"; + has_jtag = yes; + stk500_devcode = 0x83; + avr910_devcode = 0x63; + signature = 0x1e 0x94 0x04; + chip_erase_delay = 9000; + pagel = 0xd7; + bs2 = 0xa0; + + idr = 0x04; + spmcr = 0x57; + allowfullpagebitstream = yes; + + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + memory "flash" + paged = yes; + size = 16384; + page_size = 128; + num_pages = 128; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + + read_lo = " 0 0 1 0 0 0 0 0", + " 0 0 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 0 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 x x x x x x", + " x x a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 x x x x x x", + " x x a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " 0 0 a13 a12 a11 a10 a9 a8", + " a7 a6 x x x x x x", + " x x x x x x x x"; + mode = 0x41; + delay = 10; + blocksize = 128; + readsize = 256; + + ; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 0; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 6; + togglevtg = 0; + poweroffdelay = 0; + resetdelayms = 0; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + memory "eeprom" + paged = no; /* leave this "no" */ + page_size = 4; /* for parallel programming */ + size = 512; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0xff; + readback_p2 = 0xff; + + read = " 1 0 1 0 0 0 0 0", + " 0 0 x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " 0 0 x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 20; + blocksize = 4; + readsize = 256; + ; + + memory "lfuse" + size = 1; + min_write_delay = 16000; + max_write_delay = 16000; + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + ; + + memory "hfuse" + size = 1; + min_write_delay = 16000; + max_write_delay = 16000; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + ; + + memory "efuse" + size = 1; + min_write_delay = 16000; + max_write_delay = 16000; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x 1 1 1 1 1 i i i"; + ; + + memory "lock" + size = 1; + min_write_delay = 16000; + max_write_delay = 16000; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + ; + + memory "signature" + size = 3; + + read = "0 0 1 1 0 0 0 0 0 0 x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + + memory "calibration" + size = 1; + + read = "0 0 1 1 1 0 0 0 0 0 x x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; +; + + + +#------------------------------------------------------------ +# ATmega163 +#------------------------------------------------------------ + +part + id = "m163"; + desc = "ATMEGA163"; + stk500_devcode = 0x81; + avr910_devcode = 0x64; + signature = 0x1e 0x94 0x02; + chip_erase_delay = 32000; + pagel = 0xd7; + bs2 = 0xa0; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0", + "x x x x x x x x x x x x x x x x"; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 0; + togglevtg = 0; + poweroffdelay = 0; + resetdelayms = 0; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 30; + programfusepulsewidth = 0; + programfusepolltimeout = 2; + programlockpulsewidth = 0; + programlockpolltimeout = 2; + + + memory "eeprom" + size = 512; + min_write_delay = 4000; + max_write_delay = 4000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0", + " x x x x x x x a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " x x x x x x x a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + ; + + memory "flash" + paged = yes; + size = 16384; + page_size = 128; + num_pages = 128; + min_write_delay = 16000; + max_write_delay = 16000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " x x x a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " x x x a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " x x x x x x x x", + " x x a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " x x x x x x x x", + " x x a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " x x x a12 a11 a10 a9 a8", + " a7 a6 x x x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 128; + readsize = 256; + ; + + memory "lfuse" + size = 1; + min_write_delay = 2000; + max_write_delay = 2000; + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o x x o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i 1 1 i i i i"; + ; + + memory "hfuse" + size = 1; + min_write_delay = 2000; + max_write_delay = 2000; + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x x x x x 1 o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x 1 1 1 1 1 i i i"; + ; + + memory "lock" + size = 1; + min_write_delay = 2000; + max_write_delay = 2000; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x 0 x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 x x x x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# ATmega169 +#------------------------------------------------------------ + +part + id = "m169"; + desc = "ATMEGA169"; + has_jtag = yes; + stk500_devcode = 0x85; + avr910_devcode = 0x78; + signature = 0x1e 0x94 0x05; + chip_erase_delay = 9000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0", + "x x x x x x x x x x x x x x x x"; + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + idr = 0x31; + spmcr = 0x57; + + memory "eeprom" + paged = no; /* leave this "no" */ + page_size = 4; /* for parallel programming */ + size = 512; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0", + " x x x x x x x a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " x x x x x x x a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x x x a8", + " a7 a6 a5 a4 a3 a2 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 20; + blocksize = 4; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 16384; + page_size = 128; + num_pages = 128; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " x x x a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " x x x a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " x x x x x x x x", + " x x a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " x x x x x x x x", + " x x a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " x x x a12 a11 a10 a9 a8", + " a7 a6 x x x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 128; + readsize = 256; + ; + + memory "lfuse" + size = 1; + min_write_delay = 2000; + max_write_delay = 2000; + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + ; + + memory "hfuse" + size = 1; + min_write_delay = 2000; + max_write_delay = 2000; + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + ; + + memory "efuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + ; + + memory "lock" + size = 1; + min_write_delay = 2000; + max_write_delay = 2000; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 0 0 0 x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# ATmega329 +#------------------------------------------------------------ + +part + id = "m329"; + desc = "ATMEGA329"; + has_jtag = yes; +# stk500_devcode = 0x85; # no STK500 support, only STK500v2 +# avr910_devcode = 0x?; # try the ATmega169 one: + avr910_devcode = 0x75; + signature = 0x1e 0x95 0x03; + chip_erase_delay = 9000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0", + "x x x x x x x x x x x x x x x x"; + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + idr = 0x31; + spmcr = 0x57; + + memory "eeprom" + paged = no; /* leave this "no" */ + page_size = 4; /* for parallel programming */ + size = 1024; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0", + " x x x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " x x x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 20; + blocksize = 8; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 32768; + page_size = 128; + num_pages = 256; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " x a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " x a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " x x x x x x x x", + " x x a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " x x x x x x x x", + " x x a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " x x x a12 a11 a10 a9 a8", + " a7 a6 x x x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 256; + readsize = 256; + ; + + memory "lfuse" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + ; + + memory "hfuse" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + ; + + memory "efuse" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x x i i i"; + ; + + memory "lock" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 0 0 0 x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# ATmega3290 +#------------------------------------------------------------ + +# identical to ATmega329 + +part + id = "m3290"; + desc = "ATMEGA3290"; + has_jtag = yes; +# stk500_devcode = 0x85; # no STK500 support, only STK500v2 +# avr910_devcode = 0x?; # try the ATmega169 one: + avr910_devcode = 0x75; + signature = 0x1e 0x95 0x04; + chip_erase_delay = 9000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0", + "x x x x x x x x x x x x x x x x"; + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + idr = 0x31; + spmcr = 0x57; + + memory "eeprom" + paged = no; /* leave this "no" */ + page_size = 4; /* for parallel programming */ + size = 1024; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0", + " x x x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " x x x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x x a9 a8", + " a7 a6 a5 a4 a3 a3 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 20; + blocksize = 8; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 32768; + page_size = 128; + num_pages = 256; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " x a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " x a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " x x x x x x x x", + " x x a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " x x x x x x x x", + " x x a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " x x x a12 a11 a10 a9 a8", + " a7 a6 x x x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 256; + readsize = 256; + ; + + memory "lfuse" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + ; + + memory "hfuse" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + ; + + memory "efuse" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x x i i i"; + ; + + memory "lock" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 0 0 0 x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# ATmega649 +#------------------------------------------------------------ + +part + id = "m649"; + desc = "ATMEGA649"; + has_jtag = yes; +# stk500_devcode = 0x85; # no STK500 support, only STK500v2 +# avr910_devcode = 0x?; # try the ATmega169 one: + avr910_devcode = 0x75; + signature = 0x1e 0x96 0x03; + chip_erase_delay = 9000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0", + "x x x x x x x x x x x x x x x x"; + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + idr = 0x31; + spmcr = 0x57; + + memory "eeprom" + paged = no; /* leave this "no" */ + page_size = 8; /* for parallel programming */ + size = 2048; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0", + " x x x x x a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " x x x x x a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x a10 a9 a8", + " a7 a6 a5 a4 a3 0 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 20; + blocksize = 8; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 65536; + page_size = 256; + num_pages = 256; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " x x x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " x x x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " x x x a12 a11 a10 a9 a8", + " a7 x x x x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 256; + readsize = 256; + ; + + memory "lfuse" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + ; + + memory "hfuse" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + ; + + memory "efuse" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x x i i i"; + ; + + memory "lock" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 0 0 0 x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# ATmega6490 +#------------------------------------------------------------ + +# identical to ATmega649 + +part + id = "m6490"; + desc = "ATMEGA6490"; + has_jtag = yes; +# stk500_devcode = 0x85; # no STK500 support, only STK500v2 +# avr910_devcode = 0x?; # try the ATmega169 one: + avr910_devcode = 0x75; + signature = 0x1e 0x96 0x04; + chip_erase_delay = 9000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0", + "x x x x x x x x x x x x x x x x"; + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + idr = 0x31; + spmcr = 0x57; + + memory "eeprom" + paged = no; /* leave this "no" */ + page_size = 8; /* for parallel programming */ + size = 2048; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0", + " x x x x x a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " x x x x x a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x x x a8", + " a7 a6 a5 a4 a3 0 0 0", + " x x x x x x x x"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x a10 a9 a8", + " a7 a6 a5 a4 a3 0 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 20; + blocksize = 8; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 65536; + page_size = 256; + num_pages = 256; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " x x x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " x x x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " x x x a12 a11 a10 a9 a8", + " a7 x x x x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 256; + readsize = 256; + ; + + memory "lfuse" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + ; + + memory "hfuse" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + ; + + memory "efuse" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x x i i i"; + ; + + memory "lock" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 0 0 0 x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# ATmega32 +#------------------------------------------------------------ + +part + id = "m32"; + desc = "ATMEGA32"; + has_jtag = yes; + stk500_devcode = 0x91; + avr910_devcode = 0x72; + signature = 0x1e 0x95 0x02; + chip_erase_delay = 9000; + pagel = 0xd7; + bs2 = 0xa0; + reset = dedicated; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0", + "x x x x x x x x x x x x x x x x"; + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 0; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 6; + togglevtg = 0; + poweroffdelay = 0; + resetdelayms = 0; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + idr = 0x31; + spmcr = 0x57; + allowfullpagebitstream = yes; + + memory "eeprom" + paged = no; /* leave this "no" */ + page_size = 4; /* for parallel programming */ + size = 1024; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0", + " 0 0 x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " 0 0 x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 0 0", + " x x x x x x x x"; + + mode = 0x04; + delay = 10; + blocksize = 64; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 32768; + page_size = 128; + num_pages = 256; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " 0 0 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 0 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 x x x x x x", + " x x a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 x x x x x x", + " x x a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " 0 0 a13 a12 a11 a10 a9 a8", + " a7 a6 x x x x x x", + " x x x x x x x x"; + + mode = 0x21; + delay = 6; + blocksize = 64; + readsize = 256; + ; + + memory "lfuse" + size = 1; + min_write_delay = 2000; + max_write_delay = 2000; + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + ; + + memory "hfuse" + size = 1; + min_write_delay = 2000; + max_write_delay = 2000; + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + ; + + memory "lock" + size = 1; + min_write_delay = 2000; + max_write_delay = 2000; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + + memory "calibration" + size = 4; + read = "0 0 1 1 1 0 0 0 0 0 x x x x x x", + "0 0 0 0 0 0 a1 a0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# ATmega161 +#------------------------------------------------------------ + +part + id = "m161"; + desc = "ATMEGA161"; + stk500_devcode = 0x80; + avr910_devcode = 0x60; + signature = 0x1e 0x94 0x01; + chip_erase_delay = 28000; + pagel = 0xd7; + bs2 = 0xa0; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0", + "x x x x x x x x x x x x x x x x"; + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 0; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 0; + togglevtg = 0; + poweroffdelay = 0; + resetdelayms = 0; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 30; + programfusepulsewidth = 0; + programfusepolltimeout = 2; + programlockpulsewidth = 0; + programlockpolltimeout = 2; + + memory "eeprom" + size = 512; + min_write_delay = 3400; + max_write_delay = 3400; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0", + " x x x x x x x a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " x x x x x x x a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + mode = 0x04; + delay = 5; + blocksize = 128; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 16384; + page_size = 128; + num_pages = 128; + min_write_delay = 14000; + max_write_delay = 14000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " x x x a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " x x x a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " x x x x x x x x", + " x x a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " x x x x x x x x", + " x x a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " x x x a12 a11 a10 a9 a8", + " a7 a6 x x x x x x", + " x x x x x x x x"; + + mode = 0x21; + delay = 16; + blocksize = 128; + readsize = 256; + ; + + memory "fuse" + size = 1; + min_write_delay = 2000; + max_write_delay = 2000; + read = "0 1 0 1 0 0 0 0 x x x x x x x x", + "x x x x x x x x x o x o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 x x x x x", + "x x x x x x x x 1 i 1 i i i i i"; + ; + + memory "lock" + size = 1; + min_write_delay = 2000; + max_write_delay = 2000; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + ; + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + ; + + +#------------------------------------------------------------ +# ATmega8 +#------------------------------------------------------------ + +part + id = "m8"; + desc = "ATMEGA8"; + stk500_devcode = 0x70; + avr910_devcode = 0x76; + signature = 0x1e 0x93 0x07; + pagel = 0xd7; + bs2 = 0xc2; + chip_erase_delay = 10000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 0; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 2; + resetdelayus = 0; + hvleavestabdelay = 15; + resetdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + memory "eeprom" + size = 512; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0", + " 0 0 x x x x x a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " 0 0 x x x x x a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + mode = 0x04; + delay = 20; + blocksize = 128; + readsize = 256; + ; + memory "flash" + paged = yes; + size = 8192; + page_size = 64; + num_pages = 128; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0x00; + read_lo = " 0 0 1 0 0 0 0 0", + " 0 0 0 0 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 0 0 0 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 0 0 x x x x", + " x x x a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 0 0 x x x x", + " x x x a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " 0 0 0 0 a11 a10 a9 a8", + " a7 a6 a5 x x x x x", + " x x x x x x x x"; + + mode = 0x21; + delay = 10; + blocksize = 64; + readsize = 256; + ; + + memory "lfuse" + size = 1; + min_write_delay = 2000; + max_write_delay = 2000; + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + ; + + memory "hfuse" + size = 1; + min_write_delay = 2000; + max_write_delay = 2000; + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + ; + + memory "lock" + size = 1; + min_write_delay = 2000; + max_write_delay = 2000; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + ; + + memory "calibration" + size = 4; + read = "0 0 1 1 1 0 0 0 0 0 x x x x x x", + "0 0 0 0 0 0 a1 a0 o o o o o o o o"; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + ; + + + +#------------------------------------------------------------ +# ATmega8515 +#------------------------------------------------------------ + +part + id = "m8515"; + desc = "ATMEGA8515"; + stk500_devcode = 0x63; + avr910_devcode = 0x3A; + signature = 0x1e 0x93 0x06; + chip_erase_delay = 9000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 0; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 6; + togglevtg = 0; + poweroffdelay = 0; + resetdelayms = 0; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + memory "eeprom" + size = 512; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0", + " 0 0 x x x x x a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " 0 0 x x x x x a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + mode = 0x04; + delay = 10; + blocksize = 128; + readsize = 256; + ; + memory "flash" + paged = yes; + size = 8192; + page_size = 64; + num_pages = 128; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " 0 0 0 0 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 0 0 0 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 0 0 x x x x", + " x x x a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 0 0 x x x x", + " x x x a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " 0 0 0 0 a11 a10 a9 a8", + " a7 a6 a5 x x x x x", + " x x x x x x x x"; + + mode = 0x21; + delay = 6; + blocksize = 64; + readsize = 256; + ; + + memory "lfuse" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + ; + + memory "hfuse" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + ; + + memory "lock" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + ; + + memory "calibration" + size = 4; + read = "0 0 1 1 1 0 0 0 0 0 x x x x x x", + "0 0 0 0 0 0 a1 a0 o o o o o o o o"; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + ; + + + + +#------------------------------------------------------------ +# ATmega8535 +#------------------------------------------------------------ + +part + id = "m8535"; + desc = "ATMEGA8535"; + stk500_devcode = 0x64; + avr910_devcode = 0x69; + signature = 0x1e 0x93 0x08; + pagel = 0xd7; + bs2 = 0xa0; + chip_erase_delay = 9000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 0; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 6; + togglevtg = 0; + poweroffdelay = 0; + resetdelayms = 0; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + memory "eeprom" + size = 512; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0", + " 0 0 x x x x x a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " 0 0 x x x x x a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + mode = 0x04; + delay = 10; + blocksize = 128; + readsize = 256; + ; + memory "flash" + paged = yes; + size = 8192; + page_size = 64; + num_pages = 128; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " 0 0 0 0 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 0 0 0 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 0 0 x x x x", + " x x x a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 0 0 x x x x", + " x x x a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " 0 0 0 0 a11 a10 a9 a8", + " a7 a6 a5 x x x x x", + " x x x x x x x x"; + + mode = 0x21; + delay = 6; + blocksize = 64; + readsize = 256; + ; + + memory "lfuse" + size = 1; + min_write_delay = 2000; + max_write_delay = 2000; + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + ; + + memory "hfuse" + size = 1; + min_write_delay = 2000; + max_write_delay = 2000; + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + ; + + memory "lock" + size = 1; + min_write_delay = 2000; + max_write_delay = 2000; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + ; + + memory "calibration" + size = 4; + read = "0 0 1 1 1 0 0 0 0 0 x x x x x x", + "0 0 0 0 0 0 a1 a0 o o o o o o o o"; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + ; + + +#------------------------------------------------------------ +# ATtiny26 +#------------------------------------------------------------ + +part + id = "t26"; + desc = "ATTINY26"; + stk500_devcode = 0x21; + avr910_devcode = 0x5e; + signature = 0x1e 0x91 0x09; + pagel = 0xb3; + bs2 = 0xb2; + chip_erase_delay = 9000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 0; + + pp_controlstack = + 0xC4, 0xE4, 0xC4, 0xE4, 0xCC, 0xEC, 0xCC, 0xEC, + 0xD4, 0xF4, 0xD4, 0xF4, 0xDC, 0xFC, 0xDC, 0xFC, + 0xC8, 0xE8, 0xD8, 0xF8, 0x4C, 0x6C, 0x5C, 0x7C, + 0xEC, 0xBC, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 2; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + memory "eeprom" + size = 128; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = "1 0 1 0 0 0 0 0 x x x x x x x x", + "x a6 a5 a4 a3 a2 a1 a0 o o o o o o o o"; + + write = "1 1 0 0 0 0 0 0 x x x x x x x x", + "x a6 a5 a4 a3 a2 a1 a0 i i i i i i i i"; + + mode = 0x04; + delay = 10; + blocksize = 64; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 2048; + page_size = 32; + num_pages = 64; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " x x x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " x x x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " x x x x x x x x", + " x x x x a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " x x x x x x x x", + " x x x x a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " x x x x x x a9 a8", + " a7 a6 a5 a4 x x x x", + " x x x x x x x x"; + + mode = 0x21; + delay = 6; + blocksize = 16; + readsize = 256; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "0 0 0 0 0 0 a1 a0 o o o o o o o o"; + ; + + memory "lock" + size = 1; + read = "0 1 0 1 1 0 0 0 x x x x x x x x", + "x x x x x x x x x x x x x x o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 1 1 1 i i", + "x x x x x x x x x x x x x x x x"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x x x x i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x x x x o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "calibration" + size = 4; + read = "0 0 1 1 1 0 0 0 x x x x x x x x", + "0 0 0 0 0 0 a1 a0 o o o o o o o o"; + ; + +; + + +#------------------------------------------------------------ +# ATtiny261 +#------------------------------------------------------------ +# Close to ATtiny26 + +part + id = "t261"; + desc = "ATTINY261"; + has_debugwire = yes; + flash_instr = 0xB4, 0x00, 0x10; + eeprom_instr = 0xBB, 0xFF, 0xBB, 0xEE, 0xBB, 0xCC, 0xB2, 0x0D, + 0xBC, 0x00, 0xB4, 0x00, 0xBA, 0x0D, 0xBB, 0xBC, + 0x99, 0xE1, 0xBB, 0xAC; +# stk500_devcode = 0x21; +# avr910_devcode = 0x5e; + signature = 0x1e 0x91 0x0c; + pagel = 0xb3; + bs2 = 0xb2; + chip_erase_delay = 4000; + + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 0; + + pp_controlstack = + 0xC4, 0xE4, 0xC4, 0xE4, 0xCC, 0xEC, 0xCC, 0xEC, + 0xD4, 0xF4, 0xD4, 0xF4, 0xDC, 0xFC, 0xDC, 0xFC, + 0xC8, 0xE8, 0xD8, 0xF8, 0x4C, 0x6C, 0x5C, 0x7C, + 0xEC, 0xBC, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 2; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + memory "eeprom" + paged = no; + size = 128; + page_size = 4; + num_pages = 32; + min_write_delay = 4000; + max_write_delay = 4000; + readback_p1 = 0xff; + readback_p2 = 0xff; + + read = "1 0 1 0 0 0 0 0 x x x x x x x x", + "x a6 a5 a4 a3 a2 a1 a0 o o o o o o o o"; + + write = "1 1 0 0 0 0 0 0 x x x x x x x x", + "x a6 a5 a4 a3 a2 a1 a0 i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x x x x", + " x a6 a5 a4 a3 a2 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 10; + blocksize = 4; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 2048; + page_size = 32; + num_pages = 64; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + + read_lo = " 0 0 1 0 0 0 0 0", + " x x x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " x x x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " x x x x x x x x", + " x x x x a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " x x x x x x x x", + " x x x x a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " x x x x x x a9 a8", + " a7 a6 a5 a4 x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 32; + readsize = 256; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "0 0 0 0 0 0 a1 a0 o o o o o o o o"; + ; + + memory "lock" + size = 1; + read = "0 1 0 1 1 0 0 0 x x x x x x x x", + "x x x x x x x x x x x x x x o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 1 1 1 i i", + "x x x x x x x x x x x x x x x x"; + min_write_delay = 4500; + max_write_delay = 4500; + ; + + memory "lfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 4500; + max_write_delay = 4500; + ; + + memory "hfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 4500; + max_write_delay = 4500; + ; + + memory "efuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x x x x i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x x x x x x x x o"; + min_write_delay = 4500; + max_write_delay = 4500; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 x x x x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + +; + + +#------------------------------------------------------------ +# ATtiny461 +#------------------------------------------------------------ +# Close to ATtiny261 + +part + id = "t461"; + desc = "ATTINY461"; + has_debugwire = yes; + flash_instr = 0xB4, 0x00, 0x10; + eeprom_instr = 0xBB, 0xFF, 0xBB, 0xEE, 0xBB, 0xCC, 0xB2, 0x0D, + 0xBC, 0x00, 0xB4, 0x00, 0xBA, 0x0D, 0xBB, 0xBC, + 0x99, 0xE1, 0xBB, 0xAC; +# stk500_devcode = 0x21; +# avr910_devcode = 0x5e; + signature = 0x1e 0x92 0x08; + pagel = 0xb3; + bs2 = 0xb2; + chip_erase_delay = 4000; + + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 0; + + pp_controlstack = + 0xC4, 0xE4, 0xC4, 0xE4, 0xCC, 0xEC, 0xCC, 0xEC, + 0xD4, 0xF4, 0xD4, 0xF4, 0xDC, 0xFC, 0xDC, 0xFC, + 0xC8, 0xE8, 0xD8, 0xF8, 0x4C, 0x6C, 0x5C, 0x7C, + 0xEC, 0xBC, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 2; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + memory "eeprom" + paged = no; + size = 256; + page_size = 4; + num_pages = 64; + min_write_delay = 4000; + max_write_delay = 4000; + readback_p1 = 0xff; + readback_p2 = 0xff; + + read = " 1 0 1 0 0 0 0 0 x x x x x x x x", + "a7 a6 a5 a4 a3 a2 a1 a0 o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0 x x x x x x x x", + "a7 a6 a5 a4 a3 a2 a1 a0 i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x x x x", + " a7 a6 a5 a4 a3 a2 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 10; + blocksize = 4; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 4096; + page_size = 64; + num_pages = 64; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + + read_lo = " 0 0 1 0 0 0 0 0", + " x x x x x a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " x x x x x a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " x x x x x x x x", + " x x x a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " x x x x x x x x", + " x x x a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " x x x x x a10 a9 a8", + " a7 a6 a5 x x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 64; + readsize = 256; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "0 0 0 0 0 0 a1 a0 o o o o o o o o"; + ; + + memory "lock" + size = 1; + read = "0 1 0 1 1 0 0 0 x x x x x x x x", + "x x x x x x x x x x x x x x o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 1 1 1 i i", + "x x x x x x x x x x x x x x x x"; + min_write_delay = 4500; + max_write_delay = 4500; + ; + + memory "lfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 4500; + max_write_delay = 4500; + ; + + memory "hfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 4500; + max_write_delay = 4500; + ; + + memory "efuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x x x x i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x x x x x x x x o"; + min_write_delay = 4500; + max_write_delay = 4500; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 x x x x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + +; + + +#------------------------------------------------------------ +# ATtiny861 +#------------------------------------------------------------ +# Close to ATtiny461 + +part + id = "t861"; + desc = "ATTINY861"; + has_debugwire = yes; + flash_instr = 0xB4, 0x00, 0x10; + eeprom_instr = 0xBB, 0xFF, 0xBB, 0xEE, 0xBB, 0xCC, 0xB2, 0x0D, + 0xBC, 0x00, 0xB4, 0x00, 0xBA, 0x0D, 0xBB, 0xBC, + 0x99, 0xE1, 0xBB, 0xAC; +# stk500_devcode = 0x21; +# avr910_devcode = 0x5e; + signature = 0x1e 0x93 0x0d; + pagel = 0xb3; + bs2 = 0xb2; + chip_erase_delay = 4000; + + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 0; + + pp_controlstack = + 0xC4, 0xE4, 0xC4, 0xE4, 0xCC, 0xEC, 0xCC, 0xEC, + 0xD4, 0xF4, 0xD4, 0xF4, 0xDC, 0xFC, 0xDC, 0xFC, + 0xC8, 0xE8, 0xD8, 0xF8, 0x4C, 0x6C, 0x5C, 0x7C, + 0xEC, 0xBC, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 2; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + memory "eeprom" + paged = no; + size = 512; + num_pages = 128; + page_size = 4; + min_write_delay = 4000; + max_write_delay = 4000; + readback_p1 = 0xff; + readback_p2 = 0xff; + + read = " 1 0 1 0 0 0 0 0 x x x x x x x a8", + "a7 a6 a5 a4 a3 a2 a1 a0 o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0 x x x x x x x a8", + "a7 a6 a5 a4 a3 a2 a1 a0 i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x x x a8", + " a7 a6 a5 a4 a3 a2 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 10; + blocksize = 4; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 8192; + page_size = 64; + num_pages = 128; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + + read_lo = " 0 0 1 0 0 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " x x x x x x x x", + " x x x a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " x x x x x x x x", + " x x x a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 x x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 64; + readsize = 256; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "0 0 0 0 0 0 a1 a0 o o o o o o o o"; + ; + + memory "lock" + size = 1; + read = "0 1 0 1 1 0 0 0 x x x x x x x x", + "x x x x x x x x x x x x x x o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 1 1 1 i i", + "x x x x x x x x x x x x x x x x"; + min_write_delay = 4500; + max_write_delay = 4500; + ; + + memory "lfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 4500; + max_write_delay = 4500; + ; + + memory "hfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 4500; + max_write_delay = 4500; + ; + + memory "efuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x x x x i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x x x x x x x x o"; + min_write_delay = 4500; + max_write_delay = 4500; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 x x x x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + +; + + +#------------------------------------------------------------ +# ATmega48 +#------------------------------------------------------------ + +part + id = "m48"; + desc = "ATMEGA48"; + has_debugwire = yes; + flash_instr = 0xB6, 0x01, 0x11; + eeprom_instr = 0xBD, 0xF2, 0xBD, 0xE1, 0xBB, 0xCF, 0xB4, 0x00, + 0xBE, 0x01, 0xB6, 0x01, 0xBC, 0x00, 0xBB, 0xBF, + 0x99, 0xF9, 0xBB, 0xAF; + stk500_devcode = 0x59; +# avr910_devcode = 0x; + signature = 0x1e 0x92 0x05; + pagel = 0xd7; + bs2 = 0xc2; + chip_erase_delay = 45000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 15; + resetdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + memory "eeprom" + paged = no; + page_size = 4; + size = 256; + min_write_delay = 3600; + max_write_delay = 3600; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0", + " 0 0 0 x x x x x", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " 0 0 0 x x x x x", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x x x x", + " a7 a6 a5 a4 a3 a2 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 5; + blocksize = 4; + readsize = 256; + ; + memory "flash" + paged = yes; + size = 4096; + page_size = 64; + num_pages = 64; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0x00; + readback_p2 = 0x00; + read_lo = " 0 0 1 0 0 0 0 0", + " 0 0 0 0 0 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 0 0 0 0 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 0 x x x x x", + " x x x a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 0 x x x x x", + " x x x a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " 0 0 0 0 0 a10 a9 a8", + " a7 a6 a5 x x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 64; + readsize = 256; + ; + + memory "lfuse" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + ; + + memory "hfuse" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + ; + + memory "efuse" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x x x x x x x x o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x x x x i"; + ; + + memory "lock" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 0 0 0 x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + ; + + +#------------------------------------------------------------ +# ATmega88 +#------------------------------------------------------------ + +part + id = "m88"; + desc = "ATMEGA88"; + has_debugwire = yes; + flash_instr = 0xB6, 0x01, 0x11; + eeprom_instr = 0xBD, 0xF2, 0xBD, 0xE1, 0xBB, 0xCF, 0xB4, 0x00, + 0xBE, 0x01, 0xB6, 0x01, 0xBC, 0x00, 0xBB, 0xBF, + 0x99, 0xF9, 0xBB, 0xAF; + stk500_devcode = 0x73; +# avr910_devcode = 0x; + signature = 0x1e 0x93 0x0a; + pagel = 0xd7; + bs2 = 0xc2; + chip_erase_delay = 9000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 15; + resetdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + memory "eeprom" + paged = no; + page_size = 4; + size = 512; + min_write_delay = 3600; + max_write_delay = 3600; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0", + " 0 0 0 x x x x a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " 0 0 0 x x x x a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x x x a8", + " a7 a6 a5 a4 a3 a2 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 5; + blocksize = 4; + readsize = 256; + ; + memory "flash" + paged = yes; + size = 8192; + page_size = 64; + num_pages = 128; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " 0 0 0 0 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 0 0 0 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 0 x x x x x", + " x x x a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 0 x x x x x", + " x x x a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " 0 0 0 0 a11 a10 a9 a8", + " a7 a6 a5 x x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 64; + readsize = 256; + ; + + memory "lfuse" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + ; + + memory "hfuse" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + ; + + memory "efuse" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x x x x x x o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x x i i i"; + ; + + memory "lock" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 0 0 0 x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# ATmega168 +#------------------------------------------------------------ + +part + id = "m168"; + desc = "ATMEGA168"; + has_debugwire = yes; + flash_instr = 0xB6, 0x01, 0x11; + eeprom_instr = 0xBD, 0xF2, 0xBD, 0xE1, 0xBB, 0xCF, 0xB4, 0x00, + 0xBE, 0x01, 0xB6, 0x01, 0xBC, 0x00, 0xBB, 0xBF, + 0x99, 0xF9, 0xBB, 0xAF; + stk500_devcode = 0x86; + # avr910_devcode = 0x; + signature = 0x1e 0x94 0x06; + pagel = 0xd7; + bs2 = 0xc2; + chip_erase_delay = 9000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 15; + resetdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + memory "eeprom" + paged = no; + page_size = 4; + size = 512; + min_write_delay = 3600; + max_write_delay = 3600; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0", + " 0 0 0 x x x x a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " 0 0 0 x x x x a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x x x a8", + " a7 a6 a5 a4 a3 a2 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 5; + blocksize = 4; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 16384; + page_size = 128; + num_pages = 128; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " 0 0 0 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 0 0 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 0 x x x x x", + " x x a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 0 x x x x x", + " x x a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " 0 0 0 a12 a11 a10 a9 a8", + " a7 a6 x x x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 128; + readsize = 256; + + ; + + memory "lfuse" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + ; + + memory "hfuse" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + ; + + memory "efuse" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x x x x x x o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x x i i i"; + ; + + memory "lock" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 0 0 0 x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; +; + +#------------------------------------------------------------ +# ATmega328 +#------------------------------------------------------------ + +part + id = "m328p"; + desc = "ATMEGA328P"; + has_debugwire = yes; + flash_instr = 0xB6, 0x01, 0x11; + eeprom_instr = 0xBD, 0xF2, 0xBD, 0xE1, 0xBB, 0xCF, 0xB4, 0x00, + 0xBE, 0x01, 0xB6, 0x01, 0xBC, 0x00, 0xBB, 0xBF, + 0x99, 0xF9, 0xBB, 0xAF; + stk500_devcode = 0x86; + # avr910_devcode = 0x; + signature = 0x1e 0x95 0x0F; + pagel = 0xd7; + bs2 = 0xc2; + chip_erase_delay = 9000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 15; + resetdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + memory "eeprom" + paged = no; + page_size = 4; + size = 1024; + min_write_delay = 3600; + max_write_delay = 3600; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0", + " 0 0 0 x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " 0 0 0 x x x a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x x a9 a8", + " a7 a6 a5 a4 a3 a2 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 5; + blocksize = 4; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 32768; + page_size = 128; + num_pages = 256; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " 0 0 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 0 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 0 x x x x x", + " x x a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 0 x x x x x", + " x x a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " 0 0 a13 a12 a11 a10 a9 a8", + " a7 a6 x x x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 128; + readsize = 256; + + ; + + memory "lfuse" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + ; + + memory "hfuse" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + ; + + memory "efuse" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x x x x x x o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x x i i i"; + ; + + memory "lock" + size = 1; + min_write_delay = 4500; + max_write_delay = 4500; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 0 0 0 x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; +; + #------------------------------------------------------------ +# ATtiny2313 +#------------------------------------------------------------ + +part + id = "t2313"; + desc = "ATtiny2313"; + has_debugwire = yes; + flash_instr = 0xB2, 0x0F, 0x1F; + eeprom_instr = 0xBB, 0xFE, 0xBB, 0xEE, 0xBB, 0xCC, 0xB2, 0x0D, + 0xBA, 0x0F, 0xB2, 0x0F, 0xBA, 0x0D, 0xBB, 0xBC, + 0x99, 0xE1, 0xBB, 0xAC; + stk500_devcode = 0x23; +## Use the ATtiny26 devcode: + avr910_devcode = 0x5e; + signature = 0x1e 0x91 0x0a; + pagel = 0xD4; + bs2 = 0xD6; + reset = io; + chip_erase_delay = 9000; + + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + pp_controlstack = + 0x0E, 0x1E, 0x0E, 0x1E, 0x2E, 0x3E, 0x2E, 0x3E, + 0x4E, 0x5E, 0x4E, 0x5E, 0x6E, 0x7E, 0x6E, 0x7E, + 0x26, 0x36, 0x66, 0x76, 0x2A, 0x3A, 0x6A, 0x7A, + 0x2E, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + memory "eeprom" + size = 128; + paged = no; + page_size = 4; + min_write_delay = 4000; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = "1 0 1 0 0 0 0 0 0 0 0 x x x x x", + "x a6 a5 a4 a3 a2 a1 a0 o o o o o o o o"; + + write = "1 1 0 0 0 0 0 0 0 0 0 x x x x x", + "x a6 a5 a4 a3 a2 a1 a0 i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x x x x", + " x a6 a5 a4 a3 a2 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 4; + readsize = 256; + ; + memory "flash" + paged = yes; + size = 2048; + page_size = 32; + num_pages = 64; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " 0 0 0 0 0 0 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 0 0 0 0 0 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + +# The information in the data sheet of April/2004 is wrong, this works: + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 0 x x x x x", + " x x x x a3 a2 a1 a0", + " i i i i i i i i"; + +# The information in the data sheet of April/2004 is wrong, this works: + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 0 x x x x x", + " x x x x a3 a2 a1 a0", + " i i i i i i i i"; + +# The information in the data sheet of April/2004 is wrong, this works: + writepage = " 0 1 0 0 1 1 0 0", + " 0 0 0 0 0 0 a9 a8", + " a7 a6 a5 a4 x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 32; + readsize = 256; + ; +# ATtiny2313 has Signature Bytes: 0x1E 0x91 0x0A. + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 0 0 0 x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + memory "lock" + size = 1; + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x x x x i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; +# The Tiny2313 has calibration data for both 4 MHz and 8 MHz. +# The information in the data sheet of April/2004 is wrong, this works: + + memory "calibration" + size = 2; + read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x", + "0 0 0 0 0 0 0 a0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# AT90PWM2 +#------------------------------------------------------------ + +part + id = "pwm2"; + desc = "AT90PWM2"; + has_debugwire = yes; + flash_instr = 0xB6, 0x01, 0x11; + eeprom_instr = 0xBD, 0xF2, 0xBD, 0xE1, 0xBB, 0xCF, 0xB4, 0x00, + 0xBE, 0x01, 0xB6, 0x01, 0xBC, 0x00, 0xBB, 0xBF, + 0x99, 0xF9, 0xBB, 0xAF; + stk500_devcode = 0x65; +## avr910_devcode = ?; + signature = 0x1e 0x93 0x81; + pagel = 0xD8; + bs2 = 0xE2; + reset = io; + chip_erase_delay = 9000; + + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + memory "eeprom" + size = 512; + paged = no; + page_size = 4; + min_write_delay = 4000; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = "1 0 1 0 0 0 0 0 0 0 0 x x x x a8", + "a7 a6 a5 a4 a3 a2 a1 a0 o o o o o o o o"; + + write = "1 1 0 0 0 0 0 0 0 0 0 x x x x a8", + "a7 a6 a5 a4 a3 a2 a1 a0 i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x x x x", + " a7 a6 a5 a4 a3 a2 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 4; + readsize = 256; + ; + memory "flash" + paged = yes; + size = 8192; + page_size = 64; + num_pages = 128; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " 0 0 0 0 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 0 0 0 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 0 x x x x x", + " x x x a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 0 x x x x x", + " x x x a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " 0 0 0 0 a11 a10 a9 a8", + " a7 a6 a5 x x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 64; + readsize = 256; + ; +# AT90PWM2 has Signature Bytes: 0x1E 0x93 0x81. + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 0 0 x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + memory "lock" + size = 1; + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x x x x i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# AT90PWM3 +#------------------------------------------------------------ + +# Completely identical to AT90PWM2 (including the signature!) + +part + id = "pwm3"; + desc = "AT90PWM3"; + has_debugwire = yes; + flash_instr = 0xB6, 0x01, 0x11; + eeprom_instr = 0xBD, 0xF2, 0xBD, 0xE1, 0xBB, 0xCF, 0xB4, 0x00, + 0xBE, 0x01, 0xB6, 0x01, 0xBC, 0x00, 0xBB, 0xBF, + 0x99, 0xF9, 0xBB, 0xAF; + stk500_devcode = 0x65; +## avr910_devcode = ?; + signature = 0x1e 0x93 0x81; + pagel = 0xD8; + bs2 = 0xE2; + reset = io; + chip_erase_delay = 9000; + + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + memory "eeprom" + size = 512; + paged = no; + page_size = 4; + min_write_delay = 4000; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = "1 0 1 0 0 0 0 0 0 0 0 x x x x a8", + "a7 a6 a5 a4 a3 a2 a1 a0 o o o o o o o o"; + + write = "1 1 0 0 0 0 0 0 0 0 0 x x x x a8", + "a7 a6 a5 a4 a3 a2 a1 a0 i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x x x x", + " a7 a6 a5 a4 a3 a2 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 4; + readsize = 256; + ; + memory "flash" + paged = yes; + size = 8192; + page_size = 64; + num_pages = 128; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " 0 0 0 0 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 0 0 0 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 0 x x x x x", + " x x x a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 0 x x x x x", + " x x x a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " 0 0 0 0 a11 a10 a9 a8", + " a7 a6 a5 x x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 64; + readsize = 256; + ; +# AT90PWM2 has Signature Bytes: 0x1E 0x93 0x81. + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 0 0 x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + memory "lock" + size = 1; + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x x x x i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# AT90PWM2B +#------------------------------------------------------------ +# Same as AT90PWM2 but different signature. + +part + id = "pwm2b"; + desc = "AT90PWM2B"; + has_debugwire = yes; + flash_instr = 0xB6, 0x01, 0x11; + eeprom_instr = 0xBD, 0xF2, 0xBD, 0xE1, 0xBB, 0xCF, 0xB4, 0x00, + 0xBE, 0x01, 0xB6, 0x01, 0xBC, 0x00, 0xBB, 0xBF, + 0x99, 0xF9, 0xBB, 0xAF; + stk500_devcode = 0x65; +## avr910_devcode = ?; + signature = 0x1e 0x93 0x83; + pagel = 0xD8; + bs2 = 0xE2; + reset = io; + chip_erase_delay = 9000; + + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + memory "eeprom" + size = 512; + paged = no; + page_size = 4; + min_write_delay = 4000; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = "1 0 1 0 0 0 0 0 0 0 0 x x x x a8", + "a7 a6 a5 a4 a3 a2 a1 a0 o o o o o o o o"; + + write = "1 1 0 0 0 0 0 0 0 0 0 x x x x a8", + "a7 a6 a5 a4 a3 a2 a1 a0 i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x x x x", + " a7 a6 a5 a4 a3 a2 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 4; + readsize = 256; + ; + memory "flash" + paged = yes; + size = 8192; + page_size = 64; + num_pages = 128; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " 0 0 0 0 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 0 0 0 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 0 x x x x x", + " x x x a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 0 x x x x x", + " x x x a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " 0 0 0 0 a11 a10 a9 a8", + " a7 a6 a5 x x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 64; + readsize = 256; + ; + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 0 0 x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + memory "lock" + size = 1; + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x x x x i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# AT90PWM3B +#------------------------------------------------------------ + +# Completely identical to AT90PWM2B (including the signature!) + +part + id = "pwm3b"; + desc = "AT90PWM3B"; + has_debugwire = yes; + flash_instr = 0xB6, 0x01, 0x11; + eeprom_instr = 0xBD, 0xF2, 0xBD, 0xE1, 0xBB, 0xCF, 0xB4, 0x00, + 0xBE, 0x01, 0xB6, 0x01, 0xBC, 0x00, 0xBB, 0xBF, + 0x99, 0xF9, 0xBB, 0xAF; + stk500_devcode = 0x65; +## avr910_devcode = ?; + signature = 0x1e 0x93 0x83; + pagel = 0xD8; + bs2 = 0xE2; + reset = io; + chip_erase_delay = 9000; + + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + memory "eeprom" + size = 512; + paged = no; + page_size = 4; + min_write_delay = 4000; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = "1 0 1 0 0 0 0 0 0 0 0 x x x x a8", + "a7 a6 a5 a4 a3 a2 a1 a0 o o o o o o o o"; + + write = "1 1 0 0 0 0 0 0 0 0 0 x x x x a8", + "a7 a6 a5 a4 a3 a2 a1 a0 i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x x x x", + " a7 a6 a5 a4 a3 a2 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 4; + readsize = 256; + ; + memory "flash" + paged = yes; + size = 8192; + page_size = 64; + num_pages = 128; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " 0 0 0 0 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 0 0 0 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 0 x x x x x", + " x x x a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 0 x x x x x", + " x x x a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " 0 0 0 0 a11 a10 a9 a8", + " a7 a6 a5 x x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 64; + readsize = 256; + ; + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 0 0 x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + memory "lock" + size = 1; + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x x x x i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# ATtiny25 +#------------------------------------------------------------ + +part + id = "t25"; + desc = "ATtiny25"; + has_debugwire = yes; + flash_instr = 0xB4, 0x02, 0x12; + eeprom_instr = 0xBB, 0xFF, 0xBB, 0xEE, 0xBB, 0xCC, 0xB2, 0x0D, + 0xBC, 0x02, 0xB4, 0x02, 0xBA, 0x0D, 0xBB, 0xBC, + 0x99, 0xE1, 0xBB, 0xAC; +## no STK500 devcode in XML file, use the ATtiny45 one + stk500_devcode = 0x14; +## avr910_devcode = ?; +## Try the AT90S2313 devcode: + avr910_devcode = 0x20; + signature = 0x1e 0x91 0x08; + reset = io; + chip_erase_delay = 4500; + + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + hvsp_controlstack = + 0x4C, 0x0C, 0x1C, 0x2C, 0x3C, 0x64, 0x74, 0x66, + 0x68, 0x78, 0x68, 0x68, 0x7A, 0x6A, 0x68, 0x78, + 0x78, 0x7D, 0x6D, 0x0C, 0x80, 0x40, 0x20, 0x10, + 0x11, 0x08, 0x04, 0x02, 0x03, 0x08, 0x04, 0x00; + hventerstabdelay = 100; + hvspcmdexedelay = 0; + synchcycles = 6; + latchcycles = 1; + togglevtg = 1; + poweroffdelay = 25; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 100; + resetdelay = 25; + chiperasepolltimeout = 40; + chiperasetime = 0; + programfusepolltimeout = 25; + programlockpolltimeout = 25; + + memory "eeprom" + size = 128; + paged = no; + page_size = 4; + min_write_delay = 4000; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = "1 0 1 0 0 0 0 0 0 0 0 x x x x x", + "x a6 a5 a4 a3 a2 a1 a0 o o o o o o o o"; + + write = "1 1 0 0 0 0 0 0 0 0 0 x x x x x", + "x a6 a5 a4 a3 a2 a1 a0 i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x x x x", + " x a6 a5 a4 a3 a2 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 4; + readsize = 256; + ; + memory "flash" + paged = yes; + size = 2048; + page_size = 32; + num_pages = 64; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " 0 0 0 0 0 0 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 0 0 0 0 0 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 0 x x x x x", + " x x x x a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 0 x x x x x", + " x x x x a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " 0 0 0 0 0 0 a9 a8", + " a7 a6 a5 a4 x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 32; + readsize = 256; + ; +# ATtiny25 has Signature Bytes: 0x1E 0x91 0x08. + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 0 0 0 x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + memory "lock" + size = 1; + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x x x x i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "calibration" + size = 2; + read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x", + "0 0 0 0 0 0 0 a0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# ATtiny45 +#------------------------------------------------------------ + +part + id = "t45"; + desc = "ATtiny45"; + has_debugwire = yes; + flash_instr = 0xB4, 0x02, 0x12; + eeprom_instr = 0xBB, 0xFF, 0xBB, 0xEE, 0xBB, 0xCC, 0xB2, 0x0D, + 0xBC, 0x02, 0xB4, 0x02, 0xBA, 0x0D, 0xBB, 0xBC, + 0x99, 0xE1, 0xBB, 0xAC; + stk500_devcode = 0x14; +## avr910_devcode = ?; +## Try the AT90S2313 devcode: + avr910_devcode = 0x20; + signature = 0x1e 0x92 0x06; + reset = io; + chip_erase_delay = 4500; + + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + hvsp_controlstack = + 0x4C, 0x0C, 0x1C, 0x2C, 0x3C, 0x64, 0x74, 0x66, + 0x68, 0x78, 0x68, 0x68, 0x7A, 0x6A, 0x68, 0x78, + 0x78, 0x7D, 0x6D, 0x0C, 0x80, 0x40, 0x20, 0x10, + 0x11, 0x08, 0x04, 0x02, 0x03, 0x08, 0x04, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + hvspcmdexedelay = 0; + synchcycles = 6; + latchcycles = 1; + togglevtg = 1; + poweroffdelay = 25; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 100; + resetdelay = 25; + chiperasepolltimeout = 40; + chiperasetime = 0; + programfusepolltimeout = 25; + programlockpolltimeout = 25; + + memory "eeprom" + size = 256; + page_size = 4; + min_write_delay = 4000; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = "1 0 1 0 0 0 0 0 0 0 0 x x x x x", + "a7 a6 a5 a4 a3 a2 a1 a0 o o o o o o o o"; + + write = "1 1 0 0 0 0 0 0 0 0 0 x x x x x", + "a7 a6 a5 a4 a3 a2 a1 a0 i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x x x x", + " a7 a6 a5 a4 a3 a2 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 4; + readsize = 256; + ; + memory "flash" + paged = yes; + size = 4096; + page_size = 64; + num_pages = 64; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " 0 0 0 0 0 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 0 0 0 0 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 0 x x x x x", + " x x x a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 0 x x x x x", + " x x x a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " 0 0 0 0 0 a10 a9 a8", + " a7 a6 a5 x x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 32; + readsize = 256; + ; +# ATtiny45 has Signature Bytes: 0x1E 0x92 0x08. (Data sheet 2586C-AVR-06/05 (doc2586.pdf) indicates otherwise!) + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 0 0 0 x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + memory "lock" + size = 1; + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x x x x i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "calibration" + size = 2; + read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x", + "0 0 0 0 0 0 0 a0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# ATtiny85 +#------------------------------------------------------------ + +part + id = "t85"; + desc = "ATtiny85"; + has_debugwire = yes; + flash_instr = 0xB4, 0x02, 0x12; + eeprom_instr = 0xBB, 0xFF, 0xBB, 0xEE, 0xBB, 0xCC, 0xB2, 0x0D, + 0xBC, 0x02, 0xB4, 0x02, 0xBA, 0x0D, 0xBB, 0xBC, + 0x99, 0xE1, 0xBB, 0xAC; +## no STK500 devcode in XML file, use the ATtiny45 one + stk500_devcode = 0x14; +## avr910_devcode = ?; +## Try the AT90S2313 devcode: + avr910_devcode = 0x20; + signature = 0x1e 0x93 0x0b; + reset = io; + chip_erase_delay = 4500; + + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + hvsp_controlstack = + 0x4C, 0x0C, 0x1C, 0x2C, 0x3C, 0x64, 0x74, 0x66, + 0x68, 0x78, 0x68, 0x68, 0x7A, 0x6A, 0x68, 0x78, + 0x78, 0x7D, 0x6D, 0x0C, 0x80, 0x40, 0x20, 0x10, + 0x11, 0x08, 0x04, 0x02, 0x03, 0x08, 0x04, 0x00; + hventerstabdelay = 100; + hvspcmdexedelay = 0; + synchcycles = 6; + latchcycles = 1; + togglevtg = 1; + poweroffdelay = 25; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 100; + resetdelay = 25; + chiperasepolltimeout = 40; + chiperasetime = 0; + programfusepolltimeout = 25; + programlockpolltimeout = 25; + + memory "eeprom" + size = 512; + paged = no; + page_size = 4; + min_write_delay = 4000; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = "1 0 1 0 0 0 0 0 0 0 0 x x x x a8", + "a7 a6 a5 a4 a3 a2 a1 a0 o o o o o o o o"; + + write = "1 1 0 0 0 0 0 0 0 0 0 x x x x a8", + "a8 a6 a5 a4 a3 a2 a1 a0 i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x x x a8", + " a7 a6 a5 a4 a3 a2 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 4; + readsize = 256; + ; + memory "flash" + paged = yes; + size = 8192; + page_size = 64; + num_pages = 128; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " 0 0 0 0 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 0 0 0 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 0 x x x x x", + " x x x a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 0 x x x x x", + " x x x a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " 0 0 0 0 a11 a10 a9 a8", + " a7 a6 a5 x x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 32; + readsize = 256; + ; +# ATtiny85 has Signature Bytes: 0x1E 0x93 0x08. + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 0 0 0 x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + memory "lock" + size = 1; + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x x x x i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "calibration" + size = 2; + read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x", + "0 0 0 0 0 0 0 a0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# ATmega640 +#------------------------------------------------------------ +# Almost same as ATmega1280, except for different memory sizes + +part + id = "m640"; + desc = "ATMEGA640"; + signature = 0x1e 0x96 0x08; + has_jtag = yes; +# stk500_devcode = 0xB2; +# avr910_devcode = 0x43; + chip_erase_delay = 9000; + pagel = 0xD7; + bs2 = 0xA0; + reset = dedicated; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + idr = 0x31; + spmcr = 0x57; + rampz = 0x3b; + allowfullpagebitstream = no; + + memory "eeprom" + paged = no; /* leave this "no" */ + page_size = 8; /* for parallel programming */ + size = 4096; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0x00; + readback_p2 = 0x00; + read = " 1 0 1 0 0 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 0 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 10; + blocksize = 8; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 65536; + page_size = 256; + num_pages = 256; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0x00; + readback_p2 = 0x00; + read_lo = " 0 0 1 0 0 0 0 0", + " 0 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " x x x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " x x x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " 0 a14 a13 a12 a11 a10 a9 a8", + " a7 x x x x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 10; + blocksize = 256; + readsize = 256; + ; + + memory "lfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x x i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lock" + size = 1; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 x x x x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# ATmega1280 +#------------------------------------------------------------ + +part + id = "m1280"; + desc = "ATMEGA1280"; + signature = 0x1e 0x97 0x03; + has_jtag = yes; +# stk500_devcode = 0xB2; +# avr910_devcode = 0x43; + chip_erase_delay = 9000; + pagel = 0xD7; + bs2 = 0xA0; + reset = dedicated; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + idr = 0x31; + spmcr = 0x57; + rampz = 0x3b; + allowfullpagebitstream = no; + + memory "eeprom" + paged = no; /* leave this "no" */ + page_size = 8; /* for parallel programming */ + size = 4096; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0x00; + readback_p2 = 0x00; + read = " 1 0 1 0 0 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 0 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 10; + blocksize = 8; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 131072; + page_size = 256; + num_pages = 512; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0x00; + readback_p2 = 0x00; + read_lo = " 0 0 1 0 0 0 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " x x x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " x x x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 x x x x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 10; + blocksize = 256; + readsize = 256; + ; + + memory "lfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x x i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lock" + size = 1; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 x x x x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# ATmega1281 +#------------------------------------------------------------ +# Identical to ATmega1280 + +part + id = "m1281"; + desc = "ATMEGA1281"; + signature = 0x1e 0x97 0x04; + has_jtag = yes; +# stk500_devcode = 0xB2; +# avr910_devcode = 0x43; + chip_erase_delay = 9000; + pagel = 0xD7; + bs2 = 0xA0; + reset = dedicated; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + idr = 0x31; + spmcr = 0x57; + rampz = 0x3b; + allowfullpagebitstream = no; + + memory "eeprom" + paged = no; /* leave this "no" */ + page_size = 8; /* for parallel programming */ + size = 4096; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0x00; + readback_p2 = 0x00; + read = " 1 0 1 0 0 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 0 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 10; + blocksize = 8; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 131072; + page_size = 256; + num_pages = 512; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0x00; + readback_p2 = 0x00; + read_lo = " 0 0 1 0 0 0 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " x x x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " x x x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 x x x x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 10; + blocksize = 256; + readsize = 256; + ; + + memory "lfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x x i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lock" + size = 1; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 x x x x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# ATmega2560 +#------------------------------------------------------------ + +part + id = "m2560"; + desc = "ATMEGA2560"; + signature = 0x1e 0x98 0x01; + has_jtag = yes; +# stk500_devcode = 0xB2; +# avr910_devcode = 0x43; + chip_erase_delay = 9000; + pagel = 0xD7; + bs2 = 0xA0; + reset = dedicated; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + idr = 0x31; + spmcr = 0x57; + rampz = 0x3b; + allowfullpagebitstream = no; + + memory "eeprom" + paged = no; /* leave this "no" */ + page_size = 8; /* for parallel programming */ + size = 4096; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0x00; + readback_p2 = 0x00; + read = " 1 0 1 0 0 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 0 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 10; + blocksize = 8; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 262144; + page_size = 256; + num_pages = 1024; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0x00; + readback_p2 = 0x00; + read_lo = " 0 0 1 0 0 0 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " x x x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " x x x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 x x x x x x x", + " x x x x x x x x"; + + load_ext_addr = " 0 1 0 0 1 1 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 0 a16", + " 0 0 0 0 0 0 0 0"; + + mode = 0x41; + delay = 10; + blocksize = 256; + readsize = 256; + ; + + memory "lfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x x i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lock" + size = 1; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 x x x x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# ATmega2561 +#------------------------------------------------------------ + +part + id = "m2561"; + desc = "ATMEGA2561"; + signature = 0x1e 0x98 0x02; + has_jtag = yes; +# stk500_devcode = 0xB2; +# avr910_devcode = 0x43; + chip_erase_delay = 9000; + pagel = 0xD7; + bs2 = 0xA0; + reset = dedicated; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + idr = 0x31; + spmcr = 0x57; + rampz = 0x3b; + allowfullpagebitstream = no; + + memory "eeprom" + paged = no; /* leave this "no" */ + page_size = 8; /* for parallel programming */ + size = 4096; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0x00; + readback_p2 = 0x00; + read = " 1 0 1 0 0 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 0 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 10; + blocksize = 8; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 262144; + page_size = 256; + num_pages = 1024; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0x00; + readback_p2 = 0x00; + read_lo = " 0 0 1 0 0 0 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " x x x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " x x x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 x x x x x x x", + " x x x x x x x x"; + + load_ext_addr = " 0 1 0 0 1 1 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 0 a16", + " 0 0 0 0 0 0 0 0"; + + mode = 0x41; + delay = 10; + blocksize = 256; + readsize = 256; + ; + + memory "lfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x x i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lock" + size = 1; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 x x x x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# ATtiny24 +#------------------------------------------------------------ + +part + id = "t24"; + desc = "ATtiny24"; + has_debugwire = yes; + flash_instr = 0xB4, 0x07, 0x17; + eeprom_instr = 0xBB, 0xFF, 0xBB, 0xEE, 0xBB, 0xCC, 0xB2, 0x0D, + 0xBC, 0x07, 0xB4, 0x07, 0xBA, 0x0D, 0xBB, 0xBC, + 0x99, 0xE1, 0xBB, 0xAC; +## no STK500 devcode in XML file, use the ATtiny45 one + stk500_devcode = 0x14; +## avr910_devcode = ?; +## Try the AT90S2313 devcode: + avr910_devcode = 0x20; + signature = 0x1e 0x91 0x0b; + reset = io; + chip_erase_delay = 4500; + + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + hvsp_controlstack = + 0x4C, 0x0C, 0x1C, 0x2C, 0x3C, 0x64, 0x74, 0x66, + 0x68, 0x78, 0x68, 0x68, 0x7A, 0x6A, 0x68, 0x78, + 0x78, 0x7D, 0x6D, 0x0C, 0x80, 0x40, 0x20, 0x10, + 0x11, 0x08, 0x04, 0x02, 0x03, 0x08, 0x04, 0x0F; + hventerstabdelay = 100; + hvspcmdexedelay = 0; + synchcycles = 6; + latchcycles = 1; + togglevtg = 1; + poweroffdelay = 25; + resetdelayms = 0; + resetdelayus = 70; + hvleavestabdelay = 100; + resetdelay = 25; + chiperasepolltimeout = 40; + chiperasetime = 0; + programfusepolltimeout = 25; + programlockpolltimeout = 25; + + memory "eeprom" + size = 128; + paged = no; + page_size = 4; + min_write_delay = 4000; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = "1 0 1 0 0 0 0 0 0 0 0 x x x x x", + "x a6 a5 a4 a3 a2 a1 a0 o o o o o o o o"; + + write = "1 1 0 0 0 0 0 0 0 0 0 x x x x x", + "x a6 a5 a4 a3 a2 a1 a0 i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x x x x", + " x a6 a5 a4 a3 a2 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 4; + readsize = 256; + ; + memory "flash" + paged = yes; + size = 2048; + page_size = 32; + num_pages = 64; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " 0 0 0 0 0 0 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 0 0 0 0 0 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 0 x x x x x", + " x x x x a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 0 x x x x x", + " x x x x a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " 0 0 0 0 0 0 a9 a8", + " a7 a6 a5 a4 x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 32; + readsize = 256; + ; +# ATtiny24 has Signature Bytes: 0x1E 0x91 0x0B. + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 0 0 0 x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + memory "lock" + size = 1; + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x x x x x x x i i"; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x x x x i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x", + "0 0 0 0 0 0 0 a0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# ATtiny44 +#------------------------------------------------------------ + +part + id = "t44"; + desc = "ATtiny44"; + has_debugwire = yes; + flash_instr = 0xB4, 0x07, 0x17; + eeprom_instr = 0xBB, 0xFF, 0xBB, 0xEE, 0xBB, 0xCC, 0xB2, 0x0D, + 0xBC, 0x07, 0xB4, 0x07, 0xBA, 0x0D, 0xBB, 0xBC, + 0x99, 0xE1, 0xBB, 0xAC; +## no STK500 devcode in XML file, use the ATtiny45 one + stk500_devcode = 0x14; +## avr910_devcode = ?; +## Try the AT90S2313 devcode: + avr910_devcode = 0x20; + signature = 0x1e 0x92 0x07; + reset = io; + chip_erase_delay = 4500; + + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + hvsp_controlstack = + 0x4C, 0x0C, 0x1C, 0x2C, 0x3C, 0x64, 0x74, 0x66, + 0x68, 0x78, 0x68, 0x68, 0x7A, 0x6A, 0x68, 0x78, + 0x78, 0x7D, 0x6D, 0x0C, 0x80, 0x40, 0x20, 0x10, + 0x11, 0x08, 0x04, 0x02, 0x03, 0x08, 0x04, 0x0F; + hventerstabdelay = 100; + hvspcmdexedelay = 0; + synchcycles = 6; + latchcycles = 1; + togglevtg = 1; + poweroffdelay = 25; + resetdelayms = 0; + resetdelayus = 70; + hvleavestabdelay = 100; + resetdelay = 25; + chiperasepolltimeout = 40; + chiperasetime = 0; + programfusepolltimeout = 25; + programlockpolltimeout = 25; + + memory "eeprom" + size = 256; + paged = no; + page_size = 4; + min_write_delay = 4000; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = "1 0 1 0 0 0 0 0 0 0 0 x x x x x", + "a7 a6 a5 a4 a3 a2 a1 a0 o o o o o o o o"; + + write = "1 1 0 0 0 0 0 0 0 0 0 x x x x x", + "a7 a6 a5 a4 a3 a2 a1 a0 i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x x x x", + " x a6 a5 a4 a3 a2 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 4; + readsize = 256; + ; + memory "flash" + paged = yes; + size = 4096; + page_size = 64; + num_pages = 64; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " 0 0 0 0 0 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 0 0 0 0 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 0 x x x x x", + " x x x a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 0 x x x x x", + " x x x a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " 0 0 0 0 0 a10 a9 a8", + " a7 a6 a5 x x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 32; + readsize = 256; + ; +# ATtiny44 has Signature Bytes: 0x1E 0x92 0x07. + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 0 0 0 x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + memory "lock" + size = 1; + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x x x x x x x i i"; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x x x x i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x", + "0 0 0 0 0 0 0 a0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# ATtiny84 +#------------------------------------------------------------ + +part + id = "t84"; + desc = "ATtiny84"; + has_debugwire = yes; + flash_instr = 0xB4, 0x07, 0x17; + eeprom_instr = 0xBB, 0xFF, 0xBB, 0xEE, 0xBB, 0xCC, 0xB2, 0x0D, + 0xBC, 0x07, 0xB4, 0x07, 0xBA, 0x0D, 0xBB, 0xBC, + 0x99, 0xE1, 0xBB, 0xAC; +## no STK500 devcode in XML file, use the ATtiny45 one + stk500_devcode = 0x14; +## avr910_devcode = ?; +## Try the AT90S2313 devcode: + avr910_devcode = 0x20; + signature = 0x1e 0x93 0x0c; + reset = io; + chip_erase_delay = 4500; + + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + hvsp_controlstack = + 0x4C, 0x0C, 0x1C, 0x2C, 0x3C, 0x64, 0x74, 0x66, + 0x68, 0x78, 0x68, 0x68, 0x7A, 0x6A, 0x68, 0x78, + 0x78, 0x7D, 0x6D, 0x0C, 0x80, 0x40, 0x20, 0x10, + 0x11, 0x08, 0x04, 0x02, 0x03, 0x08, 0x04, 0x0F; + hventerstabdelay = 100; + hvspcmdexedelay = 0; + synchcycles = 6; + latchcycles = 1; + togglevtg = 1; + poweroffdelay = 25; + resetdelayms = 0; + resetdelayus = 70; + hvleavestabdelay = 100; + resetdelay = 25; + chiperasepolltimeout = 40; + chiperasetime = 0; + programfusepolltimeout = 25; + programlockpolltimeout = 25; + + memory "eeprom" + size = 512; + paged = no; + page_size = 4; + min_write_delay = 4000; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = "1 0 1 0 0 0 0 0 0 0 0 x x x x a8", + "a7 a6 a5 a4 a3 a2 a1 a0 o o o o o o o o"; + + write = "1 1 0 0 0 0 0 0 0 0 0 x x x x a8", + "a8 a6 a5 a4 a3 a2 a1 a0 i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x x x x", + " x a6 a5 a4 a3 a2 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 4; + readsize = 256; + ; + memory "flash" + paged = yes; + size = 8192; + page_size = 64; + num_pages = 128; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " 0 0 0 0 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 0 0 0 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 0 x x x x x", + " x x x a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 0 x x x x x", + " x x x a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " 0 0 0 0 a11 a10 a9 a8", + " a7 a6 a5 x x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 32; + readsize = 256; + ; +# ATtiny84 has Signature Bytes: 0x1E 0x93 0x0C. + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 0 0 0 x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + + memory "lock" + size = 1; + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x x x x x x x i i"; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x x x x i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x", + "0 0 0 0 0 0 0 a0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# AT90USB646 +#------------------------------------------------------------ + +part + id = "usb646"; + desc = "AT90USB646"; +# signature = 0x1e 0x96 0x82; ? + signature = 0x1e 0x97 0x82; + has_jtag = yes; +# stk500_devcode = 0xB2; +# avr910_devcode = 0x43; + chip_erase_delay = 9000; + pagel = 0xD7; + bs2 = 0xA0; + reset = dedicated; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + idr = 0x31; + spmcr = 0x57; + rampz = 0x3b; + allowfullpagebitstream = no; + + memory "eeprom" + paged = no; /* leave this "no" */ + page_size = 8; /* for parallel programming */ + size = 2048; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0x00; + readback_p2 = 0x00; + read = " 1 0 1 0 0 0 0 0", + " x x x x x a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " x x x x x a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x a10 a9 a8", + " a7 a6 a5 a4 a3 0 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 10; + blocksize = 8; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 65536; + page_size = 256; + num_pages = 256; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0x00; + readback_p2 = 0x00; + read_lo = " 0 0 1 0 0 0 0 0", + " 0 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " x x x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " x x x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " 0 a14 a13 a12 a11 a10 a9 a8", + " a7 x x x x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 256; + readsize = 256; + ; + + memory "lfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lock" + size = 1; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 x x x x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# AT90USB647 +#------------------------------------------------------------ +# identical to AT90USB646 + +part + id = "usb647"; + desc = "AT90USB647"; +# signature = 0x1e 0x96 0x82; ? + signature = 0x1e 0x97 0x82; + has_jtag = yes; +# stk500_devcode = 0xB2; +# avr910_devcode = 0x43; + chip_erase_delay = 9000; + pagel = 0xD7; + bs2 = 0xA0; + reset = dedicated; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + idr = 0x31; + spmcr = 0x57; + rampz = 0x3b; + allowfullpagebitstream = no; + + memory "eeprom" + paged = no; /* leave this "no" */ + page_size = 8; /* for parallel programming */ + size = 2048; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0x00; + readback_p2 = 0x00; + read = " 1 0 1 0 0 0 0 0", + " x x x x x a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " x x x x x a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x a10 a9 a8", + " a7 a6 a5 a4 a3 0 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 10; + blocksize = 8; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 65536; + page_size = 256; + num_pages = 256; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0x00; + readback_p2 = 0x00; + read_lo = " 0 0 1 0 0 0 0 0", + " 0 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " x x x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " x x x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " 0 a14 a13 a12 a11 a10 a9 a8", + " a7 x x x x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 256; + readsize = 256; + ; + + memory "lfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lock" + size = 1; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 x x x x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# AT90USB1286 +#------------------------------------------------------------ + +part + id = "usb1286"; + desc = "AT90USB1286"; + signature = 0x1e 0x97 0x82; + has_jtag = yes; +# stk500_devcode = 0xB2; +# avr910_devcode = 0x43; + chip_erase_delay = 9000; + pagel = 0xD7; + bs2 = 0xA0; + reset = dedicated; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + idr = 0x31; + spmcr = 0x57; + rampz = 0x3b; + allowfullpagebitstream = no; + + memory "eeprom" + paged = no; /* leave this "no" */ + page_size = 8; /* for parallel programming */ + size = 4096; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0x00; + readback_p2 = 0x00; + read = " 1 0 1 0 0 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x a10 a9 a8", + " a7 a6 a5 a4 a3 0 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 10; + blocksize = 8; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 131072; + page_size = 256; + num_pages = 512; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0x00; + readback_p2 = 0x00; + read_lo = " 0 0 1 0 0 0 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " x x x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " x x x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 x x x x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 256; + readsize = 256; + ; + + memory "lfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lock" + size = 1; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 x x x x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# AT90USB1287 +#------------------------------------------------------------ +# identical to AT90USB1286 + +part + id = "usb1287"; + desc = "AT90USB1287"; + signature = 0x1e 0x97 0x82; + has_jtag = yes; +# stk500_devcode = 0xB2; +# avr910_devcode = 0x43; + chip_erase_delay = 9000; + pagel = 0xD7; + bs2 = 0xA0; + reset = dedicated; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "x x x x x x x x x x x x x x x x"; + + chip_erase = "1 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0", + "x x x x x x x x x x x x x x x x"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + idr = 0x31; + spmcr = 0x57; + rampz = 0x3b; + allowfullpagebitstream = no; + + memory "eeprom" + paged = no; /* leave this "no" */ + page_size = 8; /* for parallel programming */ + size = 4096; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0x00; + readback_p2 = 0x00; + read = " 1 0 1 0 0 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " x x x x a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 x x x a10 a9 a8", + " a7 a6 a5 a4 a3 0 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 10; + blocksize = 8; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 131072; + page_size = 256; + num_pages = 512; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0x00; + readback_p2 = 0x00; + read_lo = " 0 0 1 0 0 0 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " x x x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " x x x x x x x x", + " x a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + "a15 a14 a13 a12 a11 a10 a9 a8", + " a7 x x x x x x x", + " x x x x x x x x"; + + mode = 0x41; + delay = 6; + blocksize = 256; + readsize = 256; + ; + + memory "lfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "x x x x x x x x i i i i i i i i"; + + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "x x x x x x x x x x x x i i i i"; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "x x x x x x x x o o o o o o o o"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lock" + size = 1; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x", + "x x x x x x x x 1 1 i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "calibration" + size = 1; + read = "0 0 1 1 1 0 0 0 x x x x x x x x", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 x x x x x x x x", + "x x x x x x a1 a0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# ATmega325 +#------------------------------------------------------------ + +part + id = "m325"; + desc = "ATMEGA325"; + signature = 0x1e 0x95 0x05; + has_jtag = yes; +# stk500_devcode = 0x??; # No STK500v1 support? +# avr910_devcode = 0x??; # Try the ATmega16 one + avr910_devcode = 0x74; + pagel = 0xd7; + bs2 = 0xa0; + chip_erase_delay = 9000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"; + + chip_erase = "1 0 1 0 1 1 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"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + idr = 0x31; + spmcr = 0x57; + allowfullpagebitstream = no; + + memory "eeprom" + paged = no; /* leave this "no" */ + page_size = 4; /* for parallel programming */ + size = 1024; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0", + " 0 0 0 0 0 0 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " 0 0 0 0 0 0 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 0 0 0 0 a9 a8", + " a7 a6 a5 a4 a3 a2 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 10; + blocksize = 4; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 32768; + page_size = 128; + num_pages = 256; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " 0 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 0 0 0 0 0 0", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 0 0 0 0 0 0", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " 0 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " x x x x x x x x"; + + mode = 0x41; + delay = 10; + blocksize = 128; + readsize = 256; + ; + + memory "lock" + size = 1; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 0 0 0 0 0", + "0 0 0 0 0 0 0 0 1 1 i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lfuse" + size = 1; + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "0 0 0 0 0 0 0 0 i i i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "0 0 0 0 0 0 0 0 i i i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "0 0 0 0 0 0 0 0 1 1 1 1 1 i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0", + "0 0 0 0 0 0 a1 a0 o o o o o o o o"; + ; + + memory "calibration" + size = 1; + + read = "0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# ATmega645 +#------------------------------------------------------------ + +part + id = "m645"; + desc = "ATMEGA645"; + signature = 0x1E 0x96 0x05; + has_jtag = yes; +# stk500_devcode = 0x??; # No STK500v1 support? +# avr910_devcode = 0x??; # Try the ATmega16 one + avr910_devcode = 0x74; + pagel = 0xd7; + bs2 = 0xa0; + chip_erase_delay = 9000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"; + + chip_erase = "1 0 1 0 1 1 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"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + idr = 0x31; + spmcr = 0x57; + allowfullpagebitstream = no; + + memory "eeprom" + paged = no; /* leave this "no" */ + page_size = 8; /* for parallel programming */ + size = 2048; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0", + " 0 0 0 0 0 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " 0 0 0 0 0 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 0 0 0 a10 a9 a8", + " a7 a6 a5 a4 a3 0 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 10; + blocksize = 8; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 65536; + page_size = 256; + num_pages = 256; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 0 0 0 0 0 0", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 0 0 0 0 0 0", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " 0 0 0 0 0 0 0 0"; + + mode = 0x41; + delay = 10; + blocksize = 128; + readsize = 256; + ; + + memory "lock" + size = 1; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 0 0 0 0 0", + "0 0 0 0 0 0 0 0 1 1 i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lfuse" + size = 1; + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "0 0 0 0 0 0 0 0 i i i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "0 0 0 0 0 0 0 0 i i i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "0 0 0 0 0 0 0 0 1 1 1 1 1 i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0", + "0 0 0 0 0 0 a1 a0 o o o o o o o o"; + ; + + memory "calibration" + size = 1; + + read = "0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# ATmega3250 +#------------------------------------------------------------ + +part + id = "m3250"; + desc = "ATMEGA3250"; + signature = 0x1E 0x95 0x06; + has_jtag = yes; +# stk500_devcode = 0x??; # No STK500v1 support? +# avr910_devcode = 0x??; # Try the ATmega16 one + avr910_devcode = 0x74; + pagel = 0xd7; + bs2 = 0xa0; + chip_erase_delay = 9000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"; + + chip_erase = "1 0 1 0 1 1 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"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + idr = 0x31; + spmcr = 0x57; + allowfullpagebitstream = no; + + memory "eeprom" + paged = no; /* leave this "no" */ + page_size = 4; /* for parallel programming */ + size = 1024; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0", + " 0 0 0 0 0 0 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " 0 0 0 0 0 0 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 0 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 0 0 0 0 a9 a8", + " a7 a6 a5 a4 a3 a2 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 10; + blocksize = 4; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 32768; + page_size = 128; + num_pages = 256; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " 0 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " 0 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 0 0 0 0 0 0", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 0 0 0 0 0 0", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " 0 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " x x x x x x x x"; + + mode = 0x41; + delay = 10; + blocksize = 128; + readsize = 256; + ; + + memory "lock" + size = 1; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 0 0 0 0 0", + "0 0 0 0 0 0 0 0 1 1 i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lfuse" + size = 1; + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "0 0 0 0 0 0 0 0 i i i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "0 0 0 0 0 0 0 0 i i i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "0 0 0 0 0 0 0 0 1 1 1 1 1 i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0", + "0 0 0 0 0 0 a1 a0 o o o o o o o o"; + ; + + memory "calibration" + size = 1; + + read = "0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + ; + +#------------------------------------------------------------ +# ATmega6450 +#------------------------------------------------------------ + +part + id = "m6450"; + desc = "ATMEGA6450"; + signature = 0x1E 0x96 0x06; + has_jtag = yes; +# stk500_devcode = 0x??; # No STK500v1 support? +# avr910_devcode = 0x??; # Try the ATmega16 one + avr910_devcode = 0x74; + pagel = 0xd7; + bs2 = 0xa0; + chip_erase_delay = 9000; + pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1", + "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"; + + chip_erase = "1 0 1 0 1 1 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"; + + timeout = 200; + stabdelay = 100; + cmdexedelay = 25; + synchloops = 32; + bytedelay = 0; + pollindex = 3; + pollvalue = 0x53; + predelay = 1; + postdelay = 1; + pollmethod = 1; + + pp_controlstack = + 0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F, + 0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F, + 0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B, + 0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00; + hventerstabdelay = 100; + progmodedelay = 0; + latchcycles = 5; + togglevtg = 1; + poweroffdelay = 15; + resetdelayms = 1; + resetdelayus = 0; + hvleavestabdelay = 15; + chiperasepulsewidth = 0; + chiperasepolltimeout = 10; + programfusepulsewidth = 0; + programfusepolltimeout = 5; + programlockpulsewidth = 0; + programlockpolltimeout = 5; + + idr = 0x31; + spmcr = 0x57; + allowfullpagebitstream = no; + + memory "eeprom" + paged = no; /* leave this "no" */ + page_size = 8; /* for parallel programming */ + size = 2048; + min_write_delay = 9000; + max_write_delay = 9000; + readback_p1 = 0xff; + readback_p2 = 0xff; + read = " 1 0 1 0 0 0 0 0", + " 0 0 0 0 0 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + write = " 1 1 0 0 0 0 0 0", + " 0 0 0 0 0 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_lo = " 1 1 0 0 0 0 0 1", + " 0 0 0 0 0 0 0 0", + " 0 0 0 0 0 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 1 1 0 0 0 0 1 0", + " 0 0 0 0 0 a10 a9 a8", + " a7 a6 a5 a4 a3 0 0 0", + " x x x x x x x x"; + + mode = 0x41; + delay = 10; + blocksize = 4; + readsize = 256; + ; + + memory "flash" + paged = yes; + size = 65536; + page_size = 256; + num_pages = 256; + min_write_delay = 4500; + max_write_delay = 4500; + readback_p1 = 0xff; + readback_p2 = 0xff; + read_lo = " 0 0 1 0 0 0 0 0", + " a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + read_hi = " 0 0 1 0 1 0 0 0", + " a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " o o o o o o o o"; + + loadpage_lo = " 0 1 0 0 0 0 0 0", + " 0 0 0 0 0 0 0 0", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + loadpage_hi = " 0 1 0 0 1 0 0 0", + " 0 0 0 0 0 0 0 0", + " a7 a6 a5 a4 a3 a2 a1 a0", + " i i i i i i i i"; + + writepage = " 0 1 0 0 1 1 0 0", + " a15 a14 a13 a12 a11 a10 a9 a8", + " a7 a6 a5 a4 a3 a2 a1 a0", + " 0 0 0 0 0 0 0 0"; + + mode = 0x41; + delay = 10; + blocksize = 128; + readsize = 256; + ; + + memory "lock" + size = 1; + read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0", + "x x x x x x x x x x o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 1 1 0 0 0 0 0", + "0 0 0 0 0 0 0 0 1 1 i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "lfuse" + size = 1; + read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0", + "0 0 0 0 0 0 0 0 i i i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "hfuse" + size = 1; + read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0", + "0 0 0 0 0 0 0 0 i i i i i i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "efuse" + size = 1; + + read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + + write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0", + "0 0 0 0 0 0 0 0 1 1 1 1 1 i i i"; + min_write_delay = 9000; + max_write_delay = 9000; + ; + + memory "signature" + size = 3; + read = "0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0", + "0 0 0 0 0 0 a1 a0 o o o o o o o o"; + ; + + memory "calibration" + size = 1; + + read = "0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0", + "0 0 0 0 0 0 0 0 o o o o o o o o"; + ; + ; diff --git a/arduino-0018-linux/lib/RXTXcomm.jar b/arduino-0018-linux/lib/RXTXcomm.jar new file mode 100644 index 0000000..84e5f01 Binary files /dev/null and b/arduino-0018-linux/lib/RXTXcomm.jar differ diff --git a/arduino-0018-linux/lib/about.jpg b/arduino-0018-linux/lib/about.jpg new file mode 100755 index 0000000..90afdb0 Binary files /dev/null and b/arduino-0018-linux/lib/about.jpg differ diff --git a/arduino-0018-linux/lib/antlr.jar b/arduino-0018-linux/lib/antlr.jar new file mode 100644 index 0000000..42f25e5 Binary files /dev/null and b/arduino-0018-linux/lib/antlr.jar differ diff --git a/arduino-0018-linux/lib/core.jar b/arduino-0018-linux/lib/core.jar new file mode 100644 index 0000000..db10153 Binary files /dev/null and b/arduino-0018-linux/lib/core.jar differ diff --git a/arduino-0018-linux/lib/ecj.jar b/arduino-0018-linux/lib/ecj.jar new file mode 100644 index 0000000..878a32c Binary files /dev/null and b/arduino-0018-linux/lib/ecj.jar differ diff --git a/arduino-0018-linux/lib/jna.jar b/arduino-0018-linux/lib/jna.jar new file mode 100644 index 0000000..5c669af Binary files /dev/null and b/arduino-0018-linux/lib/jna.jar differ diff --git a/arduino-0018-linux/lib/keywords.txt b/arduino-0018-linux/lib/keywords.txt new file mode 100644 index 0000000..fbf8f39 --- /dev/null +++ b/arduino-0018-linux/lib/keywords.txt @@ -0,0 +1,173 @@ +# LITERAL1 specifies constants + +HIGH LITERAL1 Constants +LOW LITERAL1 Constants +INPUT LITERAL1 Constants +OUTPUT LITERAL1 Constants +DEC LITERAL1 Serial_Print +BIN LITERAL1 Serial_Print +HEX LITERAL1 Serial_Print +OCT LITERAL1 Serial_Print +BYTE LITERAL1 Serial_Print +PI LITERAL1 +HALF_PI LITERAL1 +TWO_PI LITERAL1 +LSBFIRST LITERAL1 ShiftOut +MSBFIRST LITERAL1 ShiftOut +CHANGE LITERAL1 AttachInterrupt +FALLING LITERAL1 AttachInterrupt +RISING LITERAL1 AttachInterrupt +DEFAULT LITERAL1 AnalogReference +EXTERNAL LITERAL1 AnalogReference +INTERAL LITERAL1 AnalogReference + +# KEYWORD1 specifies datatypes and C/C++ keywords + +boolean KEYWORD1 BooleanVariables +break KEYWORD1 Break +byte KEYWORD1 Byte +case KEYWORD1 SwitchCase +char KEYWORD1 Char +class KEYWORD1 +continue KEYWORD1 Continue +default KEYWORD1 SwitchCase +do KEYWORD1 DoWhile +double KEYWORD1 Double +else KEYWORD1 Else +false KEYWORD1 Constants +float KEYWORD1 Float +for KEYWORD1 For +if KEYWORD1 If +int KEYWORD1 Int +long KEYWORD1 Long +new KEYWORD1 +null KEYWORD1 +private KEYWORD1 +protected KEYWORD1 +public KEYWORD1 +return KEYWORD1 Return +short KEYWORD1 +signed KEYWORD1 +static KEYWORD1 Static +switch KEYWORD1 SwitchCase +this KEYWORD1 +throw KEYWORD1 +try KEYWORD1 +true KEYWORD1 +unsigned KEYWORD1 +void KEYWORD1 Void +while KEYWORD1 While +word KEYWORD1 Word + +# operators aren't highlighted, but may have documentation + ++= IncrementCompound ++ Arithmetic +[] arrayaccess += assign +& BitwiseAnd +| BitwiseAnd +, +// Comments +?: +{} Braces +-- Increment +/ Arithmetic +/* Comments +. dot +== +< greaterthan +<= greaterthanorequalto +++ Increment +!= inequality +<< Bitshift +< lessthan +<= lessthanorequalto +&& Boolean +! Boolean +|| Boolean +- Arithmetic +% Modulo +* Arithmetic +() parentheses +>> Bitshift +; SemiColon +-= IncrementCompound + +# these are datatypes, but we've also defined functions to cast to them + +boolean KEYWORD2 boolean_ +byte KEYWORD2 byte_ +char KEYWORD2 char_ +float KEYWORD2 float_ +int KEYWORD2 int_ +long KEYWORD2 long_ +word KEYWORD2 word_ + +# KEYWORD2 specifies methods and functions + +abs KEYWORD2 Abs +acos KEYWORD2 ACos +asin KEYWORD2 ASin +atan KEYWORD2 ATan +atan2 KEYWORD2 ATan2 +ceil KEYWORD2 Ceil +constrain KEYWORD2 Constrain +cos KEYWORD2 Cos +degrees KEYWORD2 +exp KEYWORD2 Exp +floor KEYWORD2 Floor +log KEYWORD2 Log +map KEYWORD2 Map +max KEYWORD2 Max +min KEYWORD2 Min +radians KEYWORD2 +random KEYWORD2 Random +randomSeed KEYWORD2 RandomSeed +round KEYWORD2 +sin KEYWORD2 Sin +sq KEYWORD2 Sq +sqrt KEYWORD2 Sqrt +tan KEYWORD2 Tan + +bitRead KEYWORD2 BitRead +bitWrite KEYWORD2 BitWrite +bitSet KEYWORD2 BitSet +bitClear KEYWORD2 BitClear +bit KEYWORD2 Bit +highByte KEYWORD2 HighByte +lowByte KEYWORD2 LowByte + +analogReference KEYWORD2 AnalogReference +analogRead KEYWORD2 AnalogRead +analogWrite KEYWORD2 AnalogWrite +attachInterrupt KEYWORD2 AttachInterrupt +detachInterrupt KEYWORD2 DetachInterrupt +delay KEYWORD2 Delay +delayMicroseconds KEYWORD2 DelayMicroseconds +digitalWrite KEYWORD2 DigitalWrite +digitalRead KEYWORD2 DigitalRead +interrupts KEYWORD2 +millis KEYWORD2 Millis +micros KEYWORD2 Micros +noInterrupts KEYWORD2 NoInterrupts +noTone KEYWORD2 NoTone +pinMode KEYWORD2 PinMode +pulseIn KEYWORD2 PulseIn +shiftOut KEYWORD2 ShiftOut +tone KEYWORD2 Tone + +Serial KEYWORD3 Serial +Serial1 KEYWORD3 Serial +Serial2 KEYWORD3 Serial +Serial3 KEYWORD3 Serial +begin KEYWORD2 Serial_Begin +end KEYWORD2 Serial_End +read KEYWORD2 Serial_Read +print KEYWORD2 Serial_Print +println KEYWORD2 Serial_Println +available KEYWORD2 Serial_Available +flush KEYWORD2 Serial_Flush + +setup KEYWORD3 Setup +loop KEYWORD3 Loop diff --git a/arduino-0018-linux/lib/librxtxSerial.so b/arduino-0018-linux/lib/librxtxSerial.so new file mode 100755 index 0000000..d340dcb Binary files /dev/null and b/arduino-0018-linux/lib/librxtxSerial.so differ diff --git a/arduino-0018-linux/lib/oro.jar b/arduino-0018-linux/lib/oro.jar new file mode 100644 index 0000000..667e86c Binary files /dev/null and b/arduino-0018-linux/lib/oro.jar differ diff --git a/arduino-0018-linux/lib/pde.jar b/arduino-0018-linux/lib/pde.jar new file mode 100644 index 0000000..87c0e9a Binary files /dev/null and b/arduino-0018-linux/lib/pde.jar differ diff --git a/arduino-0018-linux/lib/preferences.txt b/arduino-0018-linux/lib/preferences.txt new file mode 100755 index 0000000..0dc7963 --- /dev/null +++ b/arduino-0018-linux/lib/preferences.txt @@ -0,0 +1,227 @@ +# !!!!!!!! UNLIKE PREVIOUS VERSIONS OF PROCESSING !!!!!!!!!! +# DO NOT MODIFY THIS FILE, OR DELETE SETTINGS FROM THIS FILE + +# These are the default preferences. If you want to modify +# them directly, use the per-user local version of the file: + +# Documents and Settings -> [username] -> Application Data -> +# Processing -> preferences.txt (on Windows XP) + +# Users -> [username] -> AppData -> Roaming -> +# Processing -> preferences.txt (on Windows Vista) + +# ~/Library -> Processing -> preferences.txt (on Mac OS X) + +# ~/.processing -> preferences.txt (on Linux) + +# The exact location of your preferences file can be found at +# the bottom of the Preferences window inside Processing. + +# Because AppData and Application Data may be considered +# hidden or system folders on Windows, you'll have to ensure +# that they're visible in order to get at preferences.txt + +# You'll have problems running Processing if you incorrectly +# modify lines in this file. + + +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + +# DEFAULT PATHS FOR SKETCHBOOK AND SETTINGS + +# relative paths will be relative to processing.exe or procesing.app. +# absolute paths may also be used. + +# note that this path should use forward slashes (like unix) +# instead of \ on windows or : on macos or whatever else + +# If you don't want users to have their sketchbook default to +# "My Documents/Processing" on Windows and "Documents/Processing" on OS X, +# set this to another path that will be used by default. +# Note that this path must exist already otherwise it won't see +# the sketchbook folder, and will instead assume the sketchbook +# has gone missing, and that it should instead use the default. +#sketchbook.path= + +# if you don't want settings to go into "application data" on windows +# and "library" on macosx, set this to the alternate location. +#settings.path=data + +# temporary build path, normally this goes into the default +# "temp" folder for that platform (as defined by java) +# but this can be used to set a specific file in case of problems +#build.path=build + +# By default, no sketches currently open +last.sketch.count=0 + + +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + +# by default, check the processing server for any updates +# (please avoid disabling, this also helps us know basic numbers +# on how many people are using Processing) +update.check = true + +# on windows, automatically associate .pde files with processing.exe +platform.auto_file_type_associations = true + +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + +# default size for the main window +default.window.width = 500 +default.window.height = 600 + +# font size for editor +editor.font=Monospaced,plain,12 +# Monaco is nicer on Mac OS X, so use that explicitly +editor.font.macosx = Monaco,plain,10 + +# anti-aliased text, turned off by default +editor.antialias=false + +# color to be used for background when 'external editor' enabled +editor.external=false + +# caret blinking +editor.caret.blink=true + +# area that's not in use by the text (replaced with tildes) +editor.invalid=false + +console = true +console.output.file = stdout.txt +console.error.file = stderr.txt +console.lines = 4 + +# set to false to disable automatically clearing the console +# each time 'run' is hit +console.auto_clear = true + +# set the maximum number of lines remembered by the console +# the default is 500, lengthen at your own peril +console.length = 500 + +# convert tabs to spaces? how many spaces? +editor.tabs.expand = true +editor.tabs.size = 2 + +# automatically indent each line +editor.indent = true + +# size of divider between editing area and the console +editor.divider.size = 0 +# the larger divider on windows is ugly with the little arrows +# this makes it large enough to see (mouse changes) and use, +# but keeps it from being annoyingly obtrusive +editor.divider.size.windows = 2 + +# any additional java options when running externally +# (for applets that are run external to the environment... +# those with a code folder, or using any libraries) +# if you hose this and can't run things, it's your own durn fault +run.options = + +# settings for the -XmsNNNm and -XmxNNNm command line option +run.options.memory = false +run.options.memory.initial = 64 +run.options.memory.maximum = 256 + +# example of increasing the memory size for applets run externally +#run.options = -Xms128m -Xmx1024m + +# index of the default display to use for present mode +# (this setting not yet completely implemented) +run.display = 1 + +# set internally +#run.window.bgcolor= + +# set to false to open a new untitled window when closing the last window +# (otherwise, the environment will quit) +# default to the relative norm for the different platforms, +# but the setting can be changed in the prefs dialog anyway +#sketchbook.closing_last_window_quits = true +#sketchbook.closing_last_window_quits.macosx = false + + +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + +#history.recording = true + +# for advanced users, enable option to export a library +#export.library = false + +# which platforms to export by default +export.application.platform.windows = true +export.application.platform.macosx = true +export.application.platform.linux = true + +# whether or not to export as full screen (present) mode +export.application.fullscreen = false + +# whether to show the stop button when exporting to application +export.application.stop = true + +# false will place all exported files into a single .jar +export.applet.separate_jar_files = false + +# set to false to no longer delete applet or application folders before export +export.delete_target_folder = true + +# may be useful when attempting to debug the preprocessor +preproc.save_build_files=false + +# allows various preprocessor features to be toggled +# in case they are causing problems + +# preprocessor: pde.g +preproc.color_datatype = true +preproc.web_colors = true +preproc.enhanced_casting = true + +# preprocessor: PdeEmitter.java +preproc.substitute_floats = true +#preproc.substitute_image = false +#preproc.substitute_font = false + +# auto-convert non-ascii chars to unicode escape sequences +preproc.substitute_unicode = true + +# PdePreproc.java +# writes out the parse tree as parseTree.xml, which can be usefully +# viewed in (at least) Mozilla or IE. useful when debugging the preprocessor. +preproc.output_parse_tree = false + +# imports to use by default (changed for 0149, some imports removed) +preproc.imports = java.applet,java.awt,java.awt.image,java.awt.event,java.io,java.net,java.text,java.util,java.util.zip,java.util.regex + +# set the browser to be used on linux +browser.linux = mozilla + +# set to the program to be used for launching apps on linux +#launcher.linux = gnome-open + +# FULL SCREEN (PRESENT MODE) +run.present.bgcolor = #666666 +run.present.stop.color = #cccccc +# starting in release 0159, don't use full screen exclusive anymore +run.present.exclusive = false +# use this by default to hide the menu bar and dock on osx +run.present.exclusive.macosx = true + +# ARDUINO PREFERENCES +board = atmega328 +target = arduino + +upload.using = bootloader + +serial.port=COM1 +serial.databits=8 +serial.stopbits=1 +serial.parity=N +serial.debug_rate=9600 diff --git a/arduino-0018-linux/lib/theme/buttons.gif b/arduino-0018-linux/lib/theme/buttons.gif new file mode 100644 index 0000000..7cc33ce Binary files /dev/null and b/arduino-0018-linux/lib/theme/buttons.gif differ diff --git a/arduino-0018-linux/lib/theme/resize.gif b/arduino-0018-linux/lib/theme/resize.gif new file mode 100644 index 0000000..59d21d9 Binary files /dev/null and b/arduino-0018-linux/lib/theme/resize.gif differ diff --git a/arduino-0018-linux/lib/theme/tab-sel-left.gif b/arduino-0018-linux/lib/theme/tab-sel-left.gif new file mode 100644 index 0000000..1fbefec Binary files /dev/null and b/arduino-0018-linux/lib/theme/tab-sel-left.gif differ diff --git a/arduino-0018-linux/lib/theme/tab-sel-menu.gif b/arduino-0018-linux/lib/theme/tab-sel-menu.gif new file mode 100644 index 0000000..eabde56 Binary files /dev/null and b/arduino-0018-linux/lib/theme/tab-sel-menu.gif differ diff --git a/arduino-0018-linux/lib/theme/tab-sel-mid.gif b/arduino-0018-linux/lib/theme/tab-sel-mid.gif new file mode 100644 index 0000000..e6df088 Binary files /dev/null and b/arduino-0018-linux/lib/theme/tab-sel-mid.gif differ diff --git a/arduino-0018-linux/lib/theme/tab-sel-right.gif b/arduino-0018-linux/lib/theme/tab-sel-right.gif new file mode 100644 index 0000000..be24960 Binary files /dev/null and b/arduino-0018-linux/lib/theme/tab-sel-right.gif differ diff --git a/arduino-0018-linux/lib/theme/tab-unsel-left.gif b/arduino-0018-linux/lib/theme/tab-unsel-left.gif new file mode 100644 index 0000000..6ed8391 Binary files /dev/null and b/arduino-0018-linux/lib/theme/tab-unsel-left.gif differ diff --git a/arduino-0018-linux/lib/theme/tab-unsel-menu.gif b/arduino-0018-linux/lib/theme/tab-unsel-menu.gif new file mode 100644 index 0000000..1587067 Binary files /dev/null and b/arduino-0018-linux/lib/theme/tab-unsel-menu.gif differ diff --git a/arduino-0018-linux/lib/theme/tab-unsel-mid.gif b/arduino-0018-linux/lib/theme/tab-unsel-mid.gif new file mode 100644 index 0000000..f1adaa6 Binary files /dev/null and b/arduino-0018-linux/lib/theme/tab-unsel-mid.gif differ diff --git a/arduino-0018-linux/lib/theme/tab-unsel-right.gif b/arduino-0018-linux/lib/theme/tab-unsel-right.gif new file mode 100644 index 0000000..1086fb3 Binary files /dev/null and b/arduino-0018-linux/lib/theme/tab-unsel-right.gif differ diff --git a/arduino-0018-linux/lib/theme/theme.txt b/arduino-0018-linux/lib/theme/theme.txt new file mode 100644 index 0000000..d340417 --- /dev/null +++ b/arduino-0018-linux/lib/theme/theme.txt @@ -0,0 +1,101 @@ +# GUI - STATUS +status.notice.fgcolor = #000000 +status.notice.bgcolor = #54919e +status.error.fgcolor = #ffffff +status.error.bgcolor = #662000 +status.edit.fgcolor = #000000 +status.edit.bgcolor = #cc9900 +status.font = SansSerif,plain,12 + +# GUI - TABS +# settings for the tabs at the top +# (tab images are stored in the lib/theme folder) +header.bgcolor = #216886 +header.text.selected.color = #1a1a00 +header.text.unselected.color = #ffffff +header.text.font = SansSerif,plain,12 + +# GUI - CONSOLE +console.font = Monospaced,plain,11 +console.font.macosx = Monaco,plain,10 +console.color = #000000 +console.output.color = #cccccc +console.error.color = #ff3000 + +# GUI - BUTTONS +buttons.bgcolor = #044f6f +buttons.status.font = SansSerif,plain,12 +buttons.status.color = #ffffff + +# GUI - LINESTATUS +linestatus.color = #ffffff +linestatus.bgcolor = #044f6f + +# EDITOR - DETAILS + +# foreground and background colors +editor.fgcolor = #000000 +editor.bgcolor = #ffffff + +# highlight for the current line +editor.linehighlight.color=#e2e2e2 +# highlight for the current line +editor.linehighlight=true + +# caret blinking and caret color +editor.caret.color = #333300 + +# color to be used for background when 'external editor' enabled +editor.external.bgcolor = #c8d2dc + +# selection color +editor.selection.color = #ffcc00 + +# area that's not in use by the text (replaced with tildes) +editor.invalid.style = #7e7e7e,bold + +# little pooties at the end of lines that show where they finish +editor.eolmarkers = false +editor.eolmarkers.color = #999999 + +# bracket/brace highlighting +editor.brackethighlight = true +editor.brackethighlight.color = #006699 + + +# TEXT - KEYWORDS + +# e.g abstract, final, private +editor.keyword1.style = #cc6600,plain + +# e.g. beginShape, point, line +editor.keyword2.style = #cc6600,plain + +# e.g. byte, char, short, color +editor.keyword3.style = #cc6600,bold + + +# TEXT - LITERALS + +# constants: e.g. null, true, this, RGB, TWO_PI +editor.literal1.style = #006699,plain + +# p5 built in variables: e.g. mouseX, width, pixels +editor.literal2.style = #006699,plain + +# e.g. + - = / +editor.operator.style = #000000,plain + +# ?? maybe this is for words followed by a colon +# like in case statements or goto +editor.label.style = #7e7e7e,bold + + +# TEXT - COMMENTS +editor.comment1.style = #7e7e7e,plain +editor.comment2.style = #7e7e7e,plain + + +# LINE STATUS - editor line number status bar at the bottom of the screen +linestatus.font = SansSerif,plain,10 +linestatus.height = 20 diff --git a/arduino-0018-linux/libraries/EEPROM/EEPROM.cpp b/arduino-0018-linux/libraries/EEPROM/EEPROM.cpp new file mode 100755 index 0000000..3a361e7 --- /dev/null +++ b/arduino-0018-linux/libraries/EEPROM/EEPROM.cpp @@ -0,0 +1,50 @@ +/* + EEPROM.cpp - EEPROM library + Copyright (c) 2006 David A. Mellis. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +/****************************************************************************** + * Includes + ******************************************************************************/ + +#include +#include "WConstants.h" +#include "EEPROM.h" + +/****************************************************************************** + * Definitions + ******************************************************************************/ + +/****************************************************************************** + * Constructors + ******************************************************************************/ + +/****************************************************************************** + * User API + ******************************************************************************/ + +uint8_t EEPROMClass::read(int address) +{ + return eeprom_read_byte((unsigned char *) address); +} + +void EEPROMClass::write(int address, uint8_t value) +{ + eeprom_write_byte((unsigned char *) address, value); +} + +EEPROMClass EEPROM; diff --git a/arduino-0018-linux/libraries/EEPROM/EEPROM.h b/arduino-0018-linux/libraries/EEPROM/EEPROM.h new file mode 100755 index 0000000..aa2b577 --- /dev/null +++ b/arduino-0018-linux/libraries/EEPROM/EEPROM.h @@ -0,0 +1,35 @@ +/* + EEPROM.h - EEPROM library + Copyright (c) 2006 David A. Mellis. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef EEPROM_h +#define EEPROM_h + +#include + +class EEPROMClass +{ + public: + uint8_t read(int); + void write(int, uint8_t); +}; + +extern EEPROMClass EEPROM; + +#endif + diff --git a/arduino-0018-linux/libraries/EEPROM/examples/eeprom_clear/eeprom_clear.pde b/arduino-0018-linux/libraries/EEPROM/examples/eeprom_clear/eeprom_clear.pde new file mode 100644 index 0000000..36af68e --- /dev/null +++ b/arduino-0018-linux/libraries/EEPROM/examples/eeprom_clear/eeprom_clear.pde @@ -0,0 +1,21 @@ +/* + * EEPROM Clear + * + * Sets all of the bytes of the EEPROM to 0. + */ + +#include + +void setup() +{ + // write a 0 to all 512 bytes of the EEPROM + for (int i = 0; i < 512; i++) + EEPROM.write(i, 0); + + // turn the LED on when we're done + digitalWrite(13, HIGH); +} + +void loop() +{ +} diff --git a/arduino-0018-linux/libraries/EEPROM/examples/eeprom_read/eeprom_read.pde b/arduino-0018-linux/libraries/EEPROM/examples/eeprom_read/eeprom_read.pde new file mode 100644 index 0000000..2e30708 --- /dev/null +++ b/arduino-0018-linux/libraries/EEPROM/examples/eeprom_read/eeprom_read.pde @@ -0,0 +1,38 @@ +/* + * EEPROM Read + * + * Reads the value of each byte of the EEPROM and prints it + * to the computer. + */ + +#include + +// start reading from the first byte (address 0) of the EEPROM +int address = 0; +byte value; + +void setup() +{ + Serial.begin(9600); +} + +void loop() +{ + // read a byte from the current address of the EEPROM + value = EEPROM.read(address); + + Serial.print(address); + Serial.print("\t"); + Serial.print(value, DEC); + Serial.println(); + + // advance to the next address of the EEPROM + address = address + 1; + + // there are only 512 bytes of EEPROM, from 0 to 511, so if we're + // on address 512, wrap around to address 0 + if (address == 512) + address = 0; + + delay(500); +} diff --git a/arduino-0018-linux/libraries/EEPROM/examples/eeprom_write/eeprom_write.pde b/arduino-0018-linux/libraries/EEPROM/examples/eeprom_write/eeprom_write.pde new file mode 100644 index 0000000..ae7c57e --- /dev/null +++ b/arduino-0018-linux/libraries/EEPROM/examples/eeprom_write/eeprom_write.pde @@ -0,0 +1,38 @@ +/* + * EEPROM Write + * + * Stores values read from analog input 0 into the EEPROM. + * These values will stay in the EEPROM when the board is + * turned off and may be retrieved later by another sketch. + */ + +#include + +// the current address in the EEPROM (i.e. which byte +// we're going to write to next) +int addr = 0; + +void setup() +{ +} + +void loop() +{ + // need to divide by 4 because analog inputs range from + // 0 to 1023 and each byte of the EEPROM can only hold a + // value from 0 to 255. + int val = analogRead(0) / 4; + + // write the value to the appropriate byte of the EEPROM. + // these values will remain there when the board is + // turned off. + EEPROM.write(addr, val); + + // advance to the next address. there are 512 bytes in + // the EEPROM, so go back to 0 when we hit 512. + addr = addr + 1; + if (addr == 512) + addr = 0; + + delay(100); +} diff --git a/arduino-0018-linux/libraries/EEPROM/keywords.txt b/arduino-0018-linux/libraries/EEPROM/keywords.txt new file mode 100644 index 0000000..d3218fe --- /dev/null +++ b/arduino-0018-linux/libraries/EEPROM/keywords.txt @@ -0,0 +1,18 @@ +####################################### +# Syntax Coloring Map For Ultrasound +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +EEPROM KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +####################################### +# Constants (LITERAL1) +####################################### + diff --git a/arduino-0018-linux/libraries/Ethernet/Client.cpp b/arduino-0018-linux/libraries/Ethernet/Client.cpp new file mode 100644 index 0000000..0511c7b --- /dev/null +++ b/arduino-0018-linux/libraries/Ethernet/Client.cpp @@ -0,0 +1,148 @@ +extern "C" { + #include "types.h" + #include "w5100.h" + #include "socket.h" + #include "string.h" +} + +#include "WProgram.h" + +#include "Ethernet.h" +#include "Client.h" +#include "Server.h" + +uint16_t Client::_srcport = 0; + +Client::Client(uint8_t sock) { + _sock = sock; +} + +Client::Client(uint8_t *ip, uint16_t port) { + _ip = ip; + _port = port; + _sock = 255; +} + +uint8_t Client::connect() { + if (_sock != 255) + return 0; + + for (int i = 0; i < MAX_SOCK_NUM; i++) { + uint8_t s = getSn_SR(i); + if (s == SOCK_CLOSED || s == SOCK_FIN_WAIT) { + _sock = i; + break; + } + } + + if (_sock == 255) + return 0; + + _srcport++; + if (_srcport + 1024 == 0) _srcport = 0; + socket(_sock, Sn_MR_TCP, _srcport + 1024, 0); + + if (!::connect(_sock, _ip, _port)) { + _sock = 255; + return 0; + } + + while (status() != SOCK_ESTABLISHED) { + delay(1); + if (status() == SOCK_CLOSED) { + _sock = 255; + return 0; + } + } + + return 1; +} + +void Client::write(uint8_t b) { + if (_sock != 255) + send(_sock, &b, 1); +} + +void Client::write(const char *str) { + if (_sock != 255) + send(_sock, (const uint8_t *)str, strlen(str)); +} + +void Client::write(const uint8_t *buf, size_t size) { + if (_sock != 255) + send(_sock, buf, size); +} + +int Client::available() { + if (_sock != 255) + return getSn_RX_RSR(_sock); + return 0; +} + +int Client::read() { + uint8_t b; + if (!available()) + return -1; + recv(_sock, &b, 1); + return b; +} + +void Client::flush() { + while (available()) + read(); +} + +void Client::stop() { + if (_sock == 255) + return; + + // attempt to close the connection gracefully (send a FIN to other side) + disconnect(_sock); + unsigned long start = millis(); + + // wait a second for the connection to close + while (status() != SOCK_CLOSED && millis() - start < 1000) + delay(1); + + // if it hasn't closed, close it forcefully + if (status() != SOCK_CLOSED) + close(_sock); + + EthernetClass::_server_port[_sock] = 0; + _sock = 255; +} + +uint8_t Client::connected() { + if (_sock == 255) { + return 0; + } else { + uint8_t s = status(); + return !(s == SOCK_LISTEN || s == SOCK_CLOSED || s == SOCK_FIN_WAIT || + (s == SOCK_CLOSE_WAIT && !available())); + } +} + +uint8_t Client::status() { + if (_sock == 255) { + return SOCK_CLOSED; + } else { + return getSn_SR(_sock); + } +} + +// the next three functions are a hack so we can compare the client returned +// by Server::available() to null, or use it as the condition in an +// if-statement. this lets us stay compatible with the Processing network +// library. + +uint8_t Client::operator==(int p) { + return _sock == 255; +} + +uint8_t Client::operator!=(int p) { + return _sock != 255; +} + +Client::operator bool() { + return _sock != 255; +} diff --git a/arduino-0018-linux/libraries/Ethernet/Client.h b/arduino-0018-linux/libraries/Ethernet/Client.h new file mode 100644 index 0000000..7c0ccdf --- /dev/null +++ b/arduino-0018-linux/libraries/Ethernet/Client.h @@ -0,0 +1,31 @@ +#ifndef Client_h +#define Client_h + +#include "Print.h" + +class Client : public Print { +private: + static uint16_t _srcport; + uint8_t _sock; + uint8_t *_ip; + uint16_t _port; +public: + Client(uint8_t); + Client(uint8_t *, uint16_t); + uint8_t status(); + uint8_t connect(); + virtual void write(uint8_t); + virtual void write(const char *str); + virtual void write(const uint8_t *buf, size_t size); + int available(); + int read(); + void flush(); + void stop(); + uint8_t connected(); + uint8_t operator==(int); + uint8_t operator!=(int); + operator bool(); + friend class Server; +}; + +#endif diff --git a/arduino-0018-linux/libraries/Ethernet/Ethernet.cpp b/arduino-0018-linux/libraries/Ethernet/Ethernet.cpp new file mode 100644 index 0000000..cb74876 --- /dev/null +++ b/arduino-0018-linux/libraries/Ethernet/Ethernet.cpp @@ -0,0 +1,38 @@ +extern "C" { + #include "types.h" + #include "w5100.h" +} + +#include "Ethernet.h" + +// XXX: don't make assumptions about the value of MAX_SOCK_NUM. +uint8_t EthernetClass::_state[MAX_SOCK_NUM] = { 0, 0, 0, 0 }; +uint16_t EthernetClass::_server_port[MAX_SOCK_NUM] = { 0, 0, 0, 0 }; + +void EthernetClass::begin(uint8_t *mac, uint8_t *ip) +{ + uint8_t gateway[4]; + gateway[0] = ip[0]; + gateway[1] = ip[1]; + gateway[2] = ip[2]; + gateway[3] = 1; + begin(mac, ip, gateway); +} + +void EthernetClass::begin(uint8_t *mac, uint8_t *ip, uint8_t *gateway) +{ + uint8_t subnet[] = { 255, 255, 255, 0 }; + begin(mac, ip, gateway, subnet); +} + +void EthernetClass::begin(uint8_t *mac, uint8_t *ip, uint8_t *gateway, uint8_t *subnet) +{ + iinchip_init(); + sysinit(0x55, 0x55); + setSHAR(mac); + setSIPR(ip); + setGAR(gateway); + setSUBR(subnet); +} + +EthernetClass Ethernet; diff --git a/arduino-0018-linux/libraries/Ethernet/Ethernet.h b/arduino-0018-linux/libraries/Ethernet/Ethernet.h new file mode 100644 index 0000000..bdfc4dd --- /dev/null +++ b/arduino-0018-linux/libraries/Ethernet/Ethernet.h @@ -0,0 +1,22 @@ +#ifndef Ethernet_h +#define Ethernet_h + +#include +#include "Client.h" +#include "Server.h" + +class EthernetClass { +private: +public: + static uint8_t _state[MAX_SOCK_NUM]; + static uint16_t _server_port[MAX_SOCK_NUM]; + void begin(uint8_t *, uint8_t *); + void begin(uint8_t *, uint8_t *, uint8_t *); + void begin(uint8_t *, uint8_t *, uint8_t *, uint8_t *); + friend class Client; + friend class Server; +}; + +extern EthernetClass Ethernet; + +#endif diff --git a/arduino-0018-linux/libraries/Ethernet/Server.cpp b/arduino-0018-linux/libraries/Ethernet/Server.cpp new file mode 100644 index 0000000..d17a5d3 --- /dev/null +++ b/arduino-0018-linux/libraries/Ethernet/Server.cpp @@ -0,0 +1,91 @@ +extern "C" { + #include "types.h" + #include "w5100.h" + #include "socket.h" + #include "string.h" +} + +#include "Ethernet.h" +#include "Client.h" +#include "Server.h" + +Server::Server(uint16_t port) +{ + _port = port; +} + +void Server::begin() +{ + for (int sock = 0; sock < MAX_SOCK_NUM; sock++) { + Client client(sock); + if (client.status() == SOCK_CLOSED) { + socket(sock, Sn_MR_TCP, _port, 0); + listen(sock); + EthernetClass::_server_port[sock] = _port; + break; + } + } +} + +void Server::accept() +{ + int listening = 0; + + for (int sock = 0; sock < MAX_SOCK_NUM; sock++) { + Client client(sock); + + if (EthernetClass::_server_port[sock] == _port) { + if (client.status() == SOCK_LISTEN) { + listening = 1; + } else if (client.status() == SOCK_CLOSE_WAIT && !client.available()) { + client.stop(); + } + } + } + + if (!listening) { + begin(); + } +} + +Client Server::available() +{ + accept(); + + for (int sock = 0; sock < MAX_SOCK_NUM; sock++) { + Client client(sock); + if (EthernetClass::_server_port[sock] == _port && + client.status() == SOCK_ESTABLISHED) { + if (client.available()) { + // XXX: don't always pick the lowest numbered socket. + return client; + } + } + } + + return Client(255); +} + +void Server::write(uint8_t b) +{ + write(&b, 1); +} + +void Server::write(const char *str) +{ + write((const uint8_t *)str, strlen(str)); +} + +void Server::write(const uint8_t *buffer, size_t size) +{ + accept(); + + for (int sock = 0; sock < MAX_SOCK_NUM; sock++) { + Client client(sock); + + if (EthernetClass::_server_port[sock] == _port && + client.status() == SOCK_ESTABLISHED) { + client.write(buffer, size); + } + } +} diff --git a/arduino-0018-linux/libraries/Ethernet/Server.h b/arduino-0018-linux/libraries/Ethernet/Server.h new file mode 100644 index 0000000..73d6a5e --- /dev/null +++ b/arduino-0018-linux/libraries/Ethernet/Server.h @@ -0,0 +1,25 @@ +#ifndef Server_h +#define Server_h + +extern "C" { + #include "utility/types.h" +} + +#include "Print.h" + +class Client; + +class Server : public Print { +private: + uint16_t _port; + void accept(); +public: + Server(uint16_t); + Client available(); + void begin(); + virtual void write(uint8_t); + virtual void write(const char *str); + virtual void write(const uint8_t *buf, size_t size); +}; + +#endif diff --git a/arduino-0018-linux/libraries/Ethernet/examples/ChatServer/ChatServer.pde b/arduino-0018-linux/libraries/Ethernet/examples/ChatServer/ChatServer.pde new file mode 100644 index 0000000..825d2f8 --- /dev/null +++ b/arduino-0018-linux/libraries/Ethernet/examples/ChatServer/ChatServer.pde @@ -0,0 +1,34 @@ +/* + * Chat Server + * + * A simple server that distributes any incoming messages to all + * connected clients. To use telnet to 10.0.0.177 and type! + */ + +#include + +// network configuration. gateway and subnet are optional. +byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; +byte ip[] = { 10, 0, 0, 177 }; +byte gateway[] = { 10, 0, 0, 1 }; +byte subnet[] = { 255, 255, 0, 0 }; + +// telnet defaults to port 23 +Server server(23); + +void setup() +{ + // initialize the ethernet device + Ethernet.begin(mac, ip, gateway, subnet); + + // start listening for clients + server.begin(); +} + +void loop() +{ + Client client = server.available(); + if (client) { + server.write(client.read()); + } +} diff --git a/arduino-0018-linux/libraries/Ethernet/examples/WebClient/WebClient.pde b/arduino-0018-linux/libraries/Ethernet/examples/WebClient/WebClient.pde new file mode 100644 index 0000000..74a6094 --- /dev/null +++ b/arduino-0018-linux/libraries/Ethernet/examples/WebClient/WebClient.pde @@ -0,0 +1,41 @@ +#include + +byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; +byte ip[] = { 10, 0, 0, 177 }; +byte server[] = { 64, 233, 187, 99 }; // Google + +Client client(server, 80); + +void setup() +{ + Ethernet.begin(mac, ip); + Serial.begin(9600); + + delay(1000); + + Serial.println("connecting..."); + + if (client.connect()) { + Serial.println("connected"); + client.println("GET /search?q=arduino HTTP/1.0"); + client.println(); + } else { + Serial.println("connection failed"); + } +} + +void loop() +{ + if (client.available()) { + char c = client.read(); + Serial.print(c); + } + + if (!client.connected()) { + Serial.println(); + Serial.println("disconnecting."); + client.stop(); + for(;;) + ; + } +} diff --git a/arduino-0018-linux/libraries/Ethernet/examples/WebServer/WebServer.pde b/arduino-0018-linux/libraries/Ethernet/examples/WebServer/WebServer.pde new file mode 100644 index 0000000..b337a8e --- /dev/null +++ b/arduino-0018-linux/libraries/Ethernet/examples/WebServer/WebServer.pde @@ -0,0 +1,61 @@ +/* + * Web Server + * + * A simple web server that shows the value of the analog input pins. + */ + +#include + +byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; +byte ip[] = { 10, 0, 0, 177 }; + +Server server(80); + +void setup() +{ + Ethernet.begin(mac, ip); + server.begin(); +} + +void loop() +{ + Client client = server.available(); + if (client) { + // an http request ends with a blank line + boolean current_line_is_blank = true; + while (client.connected()) { + if (client.available()) { + char c = client.read(); + // if we've gotten to the end of the line (received a newline + // character) and the line is blank, the http request has ended, + // so we can send a reply + if (c == '\n' && current_line_is_blank) { + // send a standard http response header + client.println("HTTP/1.1 200 OK"); + client.println("Content-Type: text/html"); + client.println(); + + // output the value of each analog input pin + for (int i = 0; i < 6; i++) { + client.print("analog input "); + client.print(i); + client.print(" is "); + client.print(analogRead(i)); + client.println("
"); + } + break; + } + if (c == '\n') { + // we're starting a new line + current_line_is_blank = true; + } else if (c != '\r') { + // we've gotten a character on the current line + current_line_is_blank = false; + } + } + } + // give the web browser time to receive the data + delay(1); + client.stop(); + } +} diff --git a/arduino-0018-linux/libraries/Ethernet/keywords.txt b/arduino-0018-linux/libraries/Ethernet/keywords.txt new file mode 100644 index 0000000..ebc5793 --- /dev/null +++ b/arduino-0018-linux/libraries/Ethernet/keywords.txt @@ -0,0 +1,30 @@ +####################################### +# Syntax Coloring Map For Ethernet +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +Ethernet KEYWORD1 +Client KEYWORD1 +Server KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +status KEYWORD2 +connect KEYWORD2 +write KEYWORD2 +available KEYWORD2 +read KEYWORD2 +flush KEYWORD2 +stop KEYWORD2 +connected KEYWORD2 +begin KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### + diff --git a/arduino-0018-linux/libraries/Ethernet/utility/socket.c b/arduino-0018-linux/libraries/Ethernet/utility/socket.c new file mode 100755 index 0000000..88c81a8 --- /dev/null +++ b/arduino-0018-linux/libraries/Ethernet/utility/socket.c @@ -0,0 +1,558 @@ +/* +* +@file socket.c +@brief setting chip register for socket + last update : 2008. Jan +* +*/ + +#include "types.h" +#include "w5100.h" +#include "socket.h" + +static uint16 local_port; + + +/** +@brief This Socket function initialize the channel in perticular mode, and set the port and wait for W5100 done it. +@return 1 for sucess else 0. +*/ +uint8 socket( + SOCKET s, /**< for socket number */ + uint8 protocol, /**< for socket protocol */ + uint16 port, /**< the source port for the socket */ + uint8 flag /**< the option for the socket */ + ) +{ + uint8 ret; +#ifdef __DEF_IINCHIP_DBG__ + printf("socket()\r\n"); +#endif + if ((protocol == Sn_MR_TCP) || (protocol == Sn_MR_UDP) || (protocol == Sn_MR_IPRAW) || (protocol == Sn_MR_MACRAW) || (protocol == Sn_MR_PPPOE)) + { + close(s); + IINCHIP_WRITE(Sn_MR(s),protocol | flag); + if (port != 0) { + IINCHIP_WRITE(Sn_PORT0(s),(uint8)((port & 0xff00) >> 8)); + IINCHIP_WRITE((Sn_PORT0(s) + 1),(uint8)(port & 0x00ff)); + } else { + local_port++; // if don't set the source port, set local_port number. + IINCHIP_WRITE(Sn_PORT0(s),(uint8)((local_port & 0xff00) >> 8)); + IINCHIP_WRITE((Sn_PORT0(s) + 1),(uint8)(local_port & 0x00ff)); + } + IINCHIP_WRITE(Sn_CR(s),Sn_CR_OPEN); // run sockinit Sn_CR + + /* +20071122[chungs]:wait to process the command... */ + while( IINCHIP_READ(Sn_CR(s)) ) + ; + /* ------- */ + ret = 1; + } + else + { + ret = 0; + } +#ifdef __DEF_IINCHIP_DBG__ + printf("Sn_SR = %.2x , Protocol = %.2x\r\n", IINCHIP_READ(Sn_SR(s)), IINCHIP_READ(Sn_MR(s))); +#endif + return ret; +} + + +/** +@brief This function close the socket and parameter is "s" which represent the socket number +*/ +void close(SOCKET s) +{ +#ifdef __DEF_IINCHIP_DBG__ + printf("close()\r\n"); +#endif + + IINCHIP_WRITE(Sn_CR(s),Sn_CR_CLOSE); + + /* +20071122[chungs]:wait to process the command... */ + while( IINCHIP_READ(Sn_CR(s)) ) + ; + /* ------- */ + + /* +2008.01 [hwkim]: clear interrupt */ + #ifdef __DEF_IINCHIP_INT__ + /* m2008.01 [bj] : all clear */ + putISR(s, 0x00); + #else + /* m2008.01 [bj] : all clear */ + IINCHIP_WRITE(Sn_IR(s), 0xFF); + #endif +} + + +/** +@brief This function established the connection for the channel in passive (server) mode. This function waits for the request from the peer. +@return 1 for success else 0. +*/ +uint8 listen( + SOCKET s /**< the socket number */ + ) +{ + uint8 ret; +#ifdef __DEF_IINCHIP_DBG__ + printf("listen()\r\n"); +#endif + if (IINCHIP_READ(Sn_SR(s)) == SOCK_INIT) + { + IINCHIP_WRITE(Sn_CR(s),Sn_CR_LISTEN); + /* +20071122[chungs]:wait to process the command... */ + while( IINCHIP_READ(Sn_CR(s)) ) + ; + /* ------- */ + ret = 1; + } + else + { + ret = 0; +#ifdef __DEF_IINCHIP_DBG__ + printf("Fail[invalid ip,port]\r\n"); +#endif + } + return ret; +} + + +/** +@brief This function established the connection for the channel in Active (client) mode. + This function waits for the untill the connection is established. + +@return 1 for success else 0. +*/ +uint8 connect(SOCKET s, uint8 * addr, uint16 port) +{ + uint8 ret; +#ifdef __DEF_IINCHIP_DBG__ + printf("connect()\r\n"); +#endif + if + ( + ((addr[0] == 0xFF) && (addr[1] == 0xFF) && (addr[2] == 0xFF) && (addr[3] == 0xFF)) || + ((addr[0] == 0x00) && (addr[1] == 0x00) && (addr[2] == 0x00) && (addr[3] == 0x00)) || + (port == 0x00) + ) + { + ret = 0; +#ifdef __DEF_IINCHIP_DBG__ + printf("Fail[invalid ip,port]\r\n"); +#endif + } + else + { + ret = 1; + // set destination IP + IINCHIP_WRITE(Sn_DIPR0(s),addr[0]); + IINCHIP_WRITE((Sn_DIPR0(s) + 1),addr[1]); + IINCHIP_WRITE((Sn_DIPR0(s) + 2),addr[2]); + IINCHIP_WRITE((Sn_DIPR0(s) + 3),addr[3]); + IINCHIP_WRITE(Sn_DPORT0(s),(uint8)((port & 0xff00) >> 8)); + IINCHIP_WRITE((Sn_DPORT0(s) + 1),(uint8)(port & 0x00ff)); + IINCHIP_WRITE(Sn_CR(s),Sn_CR_CONNECT); + /* m2008.01 [bj] : wait for completion */ + while ( IINCHIP_READ(Sn_CR(s)) ) ; + + } + + return ret; +} + + + +/** +@brief This function used for disconnect the socket and parameter is "s" which represent the socket number +@return 1 for success else 0. +*/ +void disconnect(SOCKET s) +{ +#ifdef __DEF_IINCHIP_DBG__ + printf("disconnect()\r\n"); +#endif + IINCHIP_WRITE(Sn_CR(s),Sn_CR_DISCON); + + /* +20071122[chungs]:wait to process the command... */ + while( IINCHIP_READ(Sn_CR(s)) ) + ; + /* ------- */ +} + + +/** +@brief This function used to send the data in TCP mode +@return 1 for success else 0. +*/ +uint16 send( + SOCKET s, /**< the socket index */ + const uint8 * buf, /**< a pointer to data */ + uint16 len /**< the data size to be send */ + ) +{ + uint8 status=0; + uint16 ret=0; + uint16 freesize=0; +#ifdef __DEF_IINCHIP_DBG__ + printf("send()\r\n"); +#endif + + if (len > getIINCHIP_TxMAX(s)) ret = getIINCHIP_TxMAX(s); // check size not to exceed MAX size. + else ret = len; + + // if freebuf is available, start. + do + { + freesize = getSn_TX_FSR(s); + status = IINCHIP_READ(Sn_SR(s)); + if ((status != SOCK_ESTABLISHED) && (status != SOCK_CLOSE_WAIT)) + { + ret = 0; + break; + } +#ifdef __DEF_IINCHIP_DBG__ + printf("socket %d freesize(%d) empty or error\r\n", s, freesize); +#endif + } while (freesize < ret); + + // copy data + send_data_processing(s, (uint8 *)buf, ret); + IINCHIP_WRITE(Sn_CR(s),Sn_CR_SEND); + + /* +20071122[chungs]:wait to process the command... */ + while( IINCHIP_READ(Sn_CR(s)) ) + ; + /* ------- */ + +/* +2008.01 bj */ +#ifdef __DEF_IINCHIP_INT__ + while ( (getISR(s) & Sn_IR_SEND_OK) != Sn_IR_SEND_OK ) +#else + while ( (IINCHIP_READ(Sn_IR(s)) & Sn_IR_SEND_OK) != Sn_IR_SEND_OK ) +#endif + { + /* m2008.01 [bj] : reduce code */ + if ( IINCHIP_READ(Sn_SR(s)) == SOCK_CLOSED ) + { +#ifdef __DEF_IINCHIP_DBG__ + printf("SOCK_CLOSED.\r\n"); +#endif + close(s); + return 0; + } + } +/* +2008.01 bj */ +#ifdef __DEF_IINCHIP_INT__ + putISR(s, getISR(s) & (~Sn_IR_SEND_OK)); +#else + IINCHIP_WRITE(Sn_IR(s), Sn_IR_SEND_OK); +#endif + return ret; +} + + +/** +@brief This function is an application I/F function which is used to receive the data in TCP mode. + It continues to wait for data as much as the application wants to receive. + +@return received data size for success else -1. +*/ +uint16 recv( + SOCKET s, /**< socket index */ + uint8 * buf, /**< a pointer to copy the data to be received */ + uint16 len /**< the data size to be read */ + ) +{ + uint16 ret=0; +#ifdef __DEF_IINCHIP_DBG__ + printf("recv()\r\n"); +#endif + + + if ( len > 0 ) + { + recv_data_processing(s, buf, len); + IINCHIP_WRITE(Sn_CR(s),Sn_CR_RECV); + + /* +20071122[chungs]:wait to process the command... */ + while( IINCHIP_READ(Sn_CR(s)) ) + ; + /* ------- */ + ret = len; + } + return ret; +} + + +/** +@brief This function is an application I/F function which is used to send the data for other then TCP mode. + Unlike TCP transmission, The peer's destination address and the port is needed. + +@return This function return send data size for success else -1. +*/ +uint16 sendto( + SOCKET s, /**< socket index */ + const uint8 * buf, /**< a pointer to the data */ + uint16 len, /**< the data size to send */ + uint8 * addr, /**< the peer's Destination IP address */ + uint16 port /**< the peer's destination port number */ + ) +{ +// uint8 status=0; +// uint8 isr=0; + uint16 ret=0; + +#ifdef __DEF_IINCHIP_DBG__ + printf("sendto()\r\n"); +#endif + if (len > getIINCHIP_TxMAX(s)) ret = getIINCHIP_TxMAX(s); // check size not to exceed MAX size. + else ret = len; + + if + ( + ((addr[0] == 0x00) && (addr[1] == 0x00) && (addr[2] == 0x00) && (addr[3] == 0x00)) || + ((port == 0x00)) ||(ret == 0) + ) + { + /* +2008.01 [bj] : added return value */ + ret = 0; +#ifdef __DEF_IINCHIP_DBG__ + printf("%d Fail[%.2x.%.2x.%.2x.%.2x, %.d, %d]\r\n",s, addr[0], addr[1], addr[2], addr[3] , port, len); + printf("Fail[invalid ip,port]\r\n"); +#endif + } + else + { + IINCHIP_WRITE(Sn_DIPR0(s),addr[0]); + IINCHIP_WRITE((Sn_DIPR0(s) + 1),addr[1]); + IINCHIP_WRITE((Sn_DIPR0(s) + 2),addr[2]); + IINCHIP_WRITE((Sn_DIPR0(s) + 3),addr[3]); + IINCHIP_WRITE(Sn_DPORT0(s),(uint8)((port & 0xff00) >> 8)); + IINCHIP_WRITE((Sn_DPORT0(s) + 1),(uint8)(port & 0x00ff)); + + // copy data + send_data_processing(s, (uint8 *)buf, ret); + IINCHIP_WRITE(Sn_CR(s),Sn_CR_SEND); + + /* +20071122[chungs]:wait to process the command... */ + while( IINCHIP_READ(Sn_CR(s)) ) + ; + /* ------- */ + +/* +2008.01 bj */ +#ifdef __DEF_IINCHIP_INT__ + while ( (getISR(s) & Sn_IR_SEND_OK) != Sn_IR_SEND_OK ) +#else + while ( (IINCHIP_READ(Sn_IR(s)) & Sn_IR_SEND_OK) != Sn_IR_SEND_OK ) +#endif + { +#ifdef __DEF_IINCHIP_INT__ + if (getISR(s) & Sn_IR_TIMEOUT) +#else + if (IINCHIP_READ(Sn_IR(s)) & Sn_IR_TIMEOUT) +#endif + { +#ifdef __DEF_IINCHIP_DBG__ + printf("send fail.\r\n"); +#endif +/* +2008.01 [bj]: clear interrupt */ +#ifdef __DEF_IINCHIP_INT__ + putISR(s, getISR(s) & ~(Sn_IR_SEND_OK | Sn_IR_TIMEOUT)); /* clear SEND_OK & TIMEOUT */ +#else + IINCHIP_WRITE(Sn_IR(s), (Sn_IR_SEND_OK | Sn_IR_TIMEOUT)); /* clear SEND_OK & TIMEOUT */ +#endif + return 0; + } + } + +/* +2008.01 bj */ +#ifdef __DEF_IINCHIP_INT__ + putISR(s, getISR(s) & (~Sn_IR_SEND_OK)); +#else + IINCHIP_WRITE(Sn_IR(s), Sn_IR_SEND_OK); +#endif + + } + return ret; +} + + +/** +@brief This function is an application I/F function which is used to receive the data in other then + TCP mode. This function is used to receive UDP, IP_RAW and MAC_RAW mode, and handle the header as well. + +@return This function return received data size for success else -1. +*/ +uint16 recvfrom( + SOCKET s, /**< the socket number */ + uint8 * buf, /**< a pointer to copy the data to be received */ + uint16 len, /**< the data size to read */ + uint8 * addr, /**< a pointer to store the peer's IP address */ + uint16 *port /**< a pointer to store the peer's port number. */ + ) +{ + uint8 head[8]; + uint16 data_len=0; + uint16 ptr=0; +#ifdef __DEF_IINCHIP_DBG__ + printf("recvfrom()\r\n"); +#endif + + if ( len > 0 ) + { + ptr = IINCHIP_READ(Sn_RX_RD0(s)); + ptr = ((ptr & 0x00ff) << 8) + IINCHIP_READ(Sn_RX_RD0(s) + 1); +#ifdef __DEF_IINCHIP_DBG__ + printf("ISR_RX: rd_ptr : %.4x\r\n", ptr); +#endif + switch (IINCHIP_READ(Sn_MR(s)) & 0x07) + { + case Sn_MR_UDP : + read_data(s, (uint8 *)ptr, head, 0x08); + ptr += 8; + // read peer's IP address, port number. + addr[0] = head[0]; + addr[1] = head[1]; + addr[2] = head[2]; + addr[3] = head[3]; + *port = head[4]; + *port = (*port << 8) + head[5]; + data_len = head[6]; + data_len = (data_len << 8) + head[7]; + +#ifdef __DEF_IINCHIP_DBG__ + printf("UDP msg arrived\r\n"); + printf("source Port : %d\r\n", *port); + printf("source IP : %d.%d.%d.%d\r\n", addr[0], addr[1], addr[2], addr[3]); +#endif + + read_data(s, (uint8 *)ptr, buf, data_len); // data copy. + ptr += data_len; + + IINCHIP_WRITE(Sn_RX_RD0(s),(uint8)((ptr & 0xff00) >> 8)); + IINCHIP_WRITE((Sn_RX_RD0(s) + 1),(uint8)(ptr & 0x00ff)); + break; + + case Sn_MR_IPRAW : + read_data(s, (uint8 *)ptr, head, 0x06); + ptr += 6; + + addr[0] = head[0]; + addr[1] = head[1]; + addr[2] = head[2]; + addr[3] = head[3]; + data_len = head[4]; + data_len = (data_len << 8) + head[5]; + +#ifdef __DEF_IINCHIP_DBG__ + printf("IP RAW msg arrived\r\n"); + printf("source IP : %d.%d.%d.%d\r\n", addr[0], addr[1], addr[2], addr[3]); +#endif + read_data(s, (uint8 *)ptr, buf, data_len); // data copy. + ptr += data_len; + + IINCHIP_WRITE(Sn_RX_RD0(s),(uint8)((ptr & 0xff00) >> 8)); + IINCHIP_WRITE((Sn_RX_RD0(s) + 1),(uint8)(ptr & 0x00ff)); + break; + case Sn_MR_MACRAW : + read_data(s,(uint8*)ptr,head,2); + ptr+=2; + data_len = head[0]; + data_len = (data_len<<8) + head[1] - 2; + + read_data(s,(uint8*) ptr,buf,data_len); + ptr += data_len; + IINCHIP_WRITE(Sn_RX_RD0(s),(uint8)((ptr & 0xff00) >> 8)); + IINCHIP_WRITE((Sn_RX_RD0(s) + 1),(uint8)(ptr & 0x00ff)); + +#ifdef __DEF_IINCHIP_DGB__ + printf("MAC RAW msg arrived\r\n"); + printf("dest mac=%.2X.%.2X.%.2X.%.2X.%.2X.%.2X\r\n",buf[0],buf[1],buf[2],buf[3],buf[4],buf[5]); + printf("src mac=%.2X.%.2X.%.2X.%.2X.%.2X.%.2X\r\n",buf[6],buf[7],buf[8],buf[9],buf[10],buf[11]); + printf("type =%.2X%.2X\r\n",buf[12],buf[13]); +#endif + break; + + default : + break; + } + IINCHIP_WRITE(Sn_CR(s),Sn_CR_RECV); + + /* +20071122[chungs]:wait to process the command... */ + while( IINCHIP_READ(Sn_CR(s)) ) + ; + /* ------- */ + } +#ifdef __DEF_IINCHIP_DBG__ + printf("recvfrom() end ..\r\n"); +#endif + return data_len; +} + + +uint16 igmpsend(SOCKET s, const uint8 * buf, uint16 len) +{ + uint8 status=0; +// uint8 isr=0; + uint16 ret=0; + +#ifdef __DEF_IINCHIP_DBG__ + printf("igmpsend()\r\n"); +#endif + if (len > getIINCHIP_TxMAX(s)) ret = getIINCHIP_TxMAX(s); // check size not to exceed MAX size. + else ret = len; + + if (ret == 0) + { + ; +#ifdef __DEF_IINCHIP_DBG__ + printf("%d Fail[%d]\r\n",len); +#endif + } + else + { + // copy data + send_data_processing(s, (uint8 *)buf, ret); + IINCHIP_WRITE(Sn_CR(s),Sn_CR_SEND); +/* +2008.01 bj */ + while( IINCHIP_READ(Sn_CR(s)) ) + ; +/* ------- */ + +/* +2008.01 bj */ +#ifdef __DEF_IINCHIP_INT__ + while ( (getISR(s) & Sn_IR_SEND_OK) != Sn_IR_SEND_OK ) +#else + while ( (IINCHIP_READ(Sn_IR(s)) & Sn_IR_SEND_OK) != Sn_IR_SEND_OK ) +#endif + { + status = IINCHIP_READ(Sn_SR(s)); +#ifdef __DEF_IINCHIP_INT__ + if (getISR(s) & Sn_IR_TIMEOUT) +#else + if (IINCHIP_READ(Sn_IR(s)) & Sn_IR_TIMEOUT) +#endif + { +#ifdef __DEF_IINCHIP_DBG__ + printf("igmpsend fail.\r\n"); +#endif + /* in case of igmp, if send fails, then socket closed */ + /* if you want change, remove this code. */ + close(s); + /* ----- */ + + return 0; + } + } + +/* +2008.01 bj */ +#ifdef __DEF_IINCHIP_INT__ + putISR(s, getISR(s) & (~Sn_IR_SEND_OK)); +#else + IINCHIP_WRITE(Sn_IR(s), Sn_IR_SEND_OK); +#endif + } + return ret; +} + diff --git a/arduino-0018-linux/libraries/Ethernet/utility/socket.h b/arduino-0018-linux/libraries/Ethernet/utility/socket.h new file mode 100755 index 0000000..a5cce42 --- /dev/null +++ b/arduino-0018-linux/libraries/Ethernet/utility/socket.h @@ -0,0 +1,23 @@ +/* +* +@file socket.h +@brief define function of socket API +* +*/ + +#ifndef _SOCKET_H_ +#define _SOCKET_H_ + +extern uint8 socket(SOCKET s, uint8 protocol, uint16 port, uint8 flag); // Opens a socket(TCP or UDP or IP_RAW mode) +extern void close(SOCKET s); // Close socket +extern uint8 connect(SOCKET s, uint8 * addr, uint16 port); // Establish TCP connection (Active connection) +extern void disconnect(SOCKET s); // disconnect the connection +extern uint8 listen(SOCKET s); // Establish TCP connection (Passive connection) +extern uint16 send(SOCKET s, const uint8 * buf, uint16 len); // Send data (TCP) +extern uint16 recv(SOCKET s, uint8 * buf, uint16 len); // Receive data (TCP) +extern uint16 sendto(SOCKET s, const uint8 * buf, uint16 len, uint8 * addr, uint16 port); // Send data (UDP/IP RAW) +extern uint16 recvfrom(SOCKET s, uint8 * buf, uint16 len, uint8 * addr, uint16 *port); // Receive data (UDP/IP RAW) + +extern uint16 igmpsend(SOCKET s, const uint8 * buf, uint16 len); +#endif +/* _SOCKET_H_ */ diff --git a/arduino-0018-linux/libraries/Ethernet/utility/spi.h b/arduino-0018-linux/libraries/Ethernet/utility/spi.h new file mode 100755 index 0000000..000705d --- /dev/null +++ b/arduino-0018-linux/libraries/Ethernet/utility/spi.h @@ -0,0 +1,58 @@ +//----------------------------------------------------------------------------- +//AVR Mega168 SPI HAL +#define BIT0 0x01 +#define BIT1 0x02 +#define BIT2 0x04 +#define BIT3 0x08 +#define BIT4 0x10 +#define BIT5 0x20 +#define BIT6 0x40 +#define BIT7 0x80 + +#define SPI0_SS_BIT BIT2 +#define SPI0_SS_DDR DDRB +#define SPI0_SS_PORT PORTB + +#define SPI0_SCLK_BIT BIT5 +#define SPI0_SCLK_DDR DDRB +#define SPI0_SCLK_PORT PORTB + +#define SPI0_MOSI_BIT BIT3 +#define SPI0_MOSI_DDR DDRB +#define SPI0_MOSI_PORT PORTB + +#define SPI0_MISO_BIT BIT4 +#define SPI0_MISO_DDR DDRB +#define SPI0_MISO_PORT PORTB + + +#define SPI0_WaitForReceive() +#define SPI0_RxData() (SPDR) + +#define SPI0_TxData(Data) (SPDR = Data) +#define SPI0_WaitForSend() while( (SPSR & 0x80)==0x00 ) + +#define SPI0_SendByte(Data) SPI0_TxData(Data);SPI0_WaitForSend() +#define SPI0_RecvBute() SPI0_RxData() + +// PB4(MISO), PB3(MOSI), PB5(SCK), PB2(/SS) // CS=1, waiting for SPI start // SPI mode 0, 4MHz +#define SPI0_Init() DDRB |= SPI0_SS_BIT|SPI0_SCLK_BIT|SPI0_MOSI_BIT;\ + PORTB |= SPI0_SS_BIT; PORTB &= ~(SPI0_SCLK_BIT|SPI0_MOSI_BIT);\ + SPCR = 0x50 +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +//IInChip SPI HAL +#define IINCHIP_SpiInit SPI0_Init +#define IINCHIP_SpiSendData SPI0_SendByte +#define IINCHIP_SpiRecvData SPI0_RxData + + +#define IINCHIP_CS_BIT BIT2 +#define IINCHIP_CS_DDR DDRB +#define IINCHIP_CS_PORT PORTB + +#define IINCHIP_CSInit() (IINCHIP_CS_DDR |= IINCHIP_CS_BIT) +#define IINCHIP_CSon() (IINCHIP_CS_PORT |= IINCHIP_CS_BIT) +#define IINCHIP_CSoff() (IINCHIP_CS_PORT &= ~IINCHIP_CS_BIT) +//----------------------------------------------------------------------------- diff --git a/arduino-0018-linux/libraries/Ethernet/utility/types.h b/arduino-0018-linux/libraries/Ethernet/utility/types.h new file mode 100755 index 0000000..6c350da --- /dev/null +++ b/arduino-0018-linux/libraries/Ethernet/utility/types.h @@ -0,0 +1,165 @@ +/* +* +@file type.h +* +*/ + +#ifndef _TYPE_H_ +#define _TYPE_H_ + + +/*************************************************** + * attribute for mcu ( types, ... ) + ***************************************************/ +//#include "mcu_define.h" +#define __MCU_AVR__ 1 +#define __MCU_TYPE__ __MCU_AVR__ + +//---- Refer "Rom File Maker Manual Vx.x.pdf" +#include + +#define _ENDIAN_LITTLE_ 0 /**< This must be defined if system is little-endian alignment */ +#define _ENDIAN_BIG_ 1 +#define SYSTEM_ENDIAN _ENDIAN_LITTLE_ + +#define MAX_SOCK_NUM 4 /**< Maxmium number of socket */ +#define CLK_CPU F_CPU /**< 8Mhz(for serial) */ + +/* ## __DEF_IINCHIP_xxx__ : define option for iinchip driver *****************/ +//#define __DEF_IINCHIP_DBG__ /* involve debug code in driver (socket.c) */ +//#define __DEF_IINCHIP_INT__ /**< involve interrupt service routine (socket.c) */ +//#define __DEF_IINCHIP_PPP__ /* involve pppoe routine (socket.c) */ + /* If it is defined, the source files(md5.h,md5.c) must be included in your project. + Otherwize, the source files must be removed in your project. */ + +#define __DEF_IINCHIP_DIRECT_MODE__ 1 +#define __DEF_IINCHIP_INDIRECT_MODE__ 2 +#define __DEF_IINCHIP_SPI_MODE__ 3 + +//#define __DEF_IINCHIP_BUS__ __DEF_IINCHIP_DIRECT_MODE__ +//#define __DEF_IINCHIP_BUS__ __DEF_IINCHIP_INDIRECT_MODE__ +#define __DEF_IINCHIP_BUS__ __DEF_IINCHIP_SPI_MODE__ /*Enable SPI_mode*/ + + +/** +@brief __DEF_IINCHIP_MAP_xxx__ : define memory map for iinchip +*/ +#define __DEF_IINCHIP_MAP_BASE__ 0x8000 +#if (__DEF_IINCHIP_BUS__ == __DEF_IINCHIP_DIRECT_MODE__) + #define COMMON_BASE __DEF_IINCHIP_MAP_BASE__ +#else + #define COMMON_BASE 0x0000 +#endif +#define __DEF_IINCHIP_MAP_TXBUF__ (COMMON_BASE + 0x4000) /* Internal Tx buffer address of the iinchip */ +#define __DEF_IINCHIP_MAP_RXBUF__ (COMMON_BASE + 0x6000) /* Internal Rx buffer address of the iinchip */ + + +#if (__MCU_TYPE__ == __MCU_AVR__) + #ifdef __DEF_IINCHIP_INT__ + // iinchip use external interrupt 4 + #define IINCHIP_ISR_DISABLE() (EIMSK &= ~(0x10)) + #define IINCHIP_ISR_ENABLE() (EIMSK |= 0x10) + #define IINCHIP_ISR_GET(X) (X = EIMSK) + #define IINCHIP_ISR_SET(X) (EIMSK = X) + #else + #define IINCHIP_ISR_DISABLE() + #define IINCHIP_ISR_ENABLE() + #define IINCHIP_ISR_GET(X) + #define IINCHIP_ISR_SET(X) + #endif +#else +#error "unknown MCU type" +#endif + +#ifndef NULL +#define NULL ((void *) 0) +#endif + +//typedef enum { false, true } bool; + +#ifndef _SIZE_T +#define _SIZE_T +typedef unsigned int size_t; +#endif + +/** + * The 8-bit signed data type. + */ +typedef char int8; +/** + * The volatile 8-bit signed data type. + */ +typedef volatile char vint8; +/** + * The 8-bit unsigned data type. + */ +typedef unsigned char uint8; +/** + * The volatile 8-bit unsigned data type. + */ +typedef volatile unsigned char vuint8; + +/** + * The 16-bit signed data type. + */ +typedef int int16; +/** + * The volatile 16-bit signed data type. + */ +typedef volatile int vint16; +/** + * The 16-bit unsigned data type. + */ +typedef unsigned int uint16; +/** + * The volatile 16-bit unsigned data type. + */ +typedef volatile unsigned int vuint16; +/** + * The 32-bit signed data type. + */ +typedef long int32; +/** + * The volatile 32-bit signed data type. + */ +typedef volatile long vint32; +/** + * The 32-bit unsigned data type. + */ +typedef unsigned long uint32; +/** + * The volatile 32-bit unsigned data type. + */ +typedef volatile unsigned long vuint32; + +/* bsd */ +typedef uint8 u_char; /**< 8-bit value */ +typedef uint8 SOCKET; +typedef uint16 u_short; /**< 16-bit value */ +typedef uint16 u_int; /**< 16-bit value */ +typedef uint32 u_long; /**< 32-bit value */ + +typedef union _un_l2cval { + u_long lVal; + u_char cVal[4]; +}un_l2cval; + +typedef union _un_i2cval { + u_int iVal; + u_char cVal[2]; +}un_i2cval; + + +/** global define */ +#define FW_VERSION 0x01010000 /* System F/W Version : 1.1.0.0 */ +#define HW_VERSION 0x01000000 + + +#define TX_RX_MAX_BUF_SIZE 2048 +#define TX_BUF 0x1100 +#define RX_BUF (TX_BUF+TX_RX_MAX_BUF_SIZE) + +#define UART_DEVICE_CNT 1 /**< UART device number */ +/* #define SUPPORT_UART_ONE */ + +#endif /* _TYPE_H_ */ diff --git a/arduino-0018-linux/libraries/Ethernet/utility/w5100.c b/arduino-0018-linux/libraries/Ethernet/utility/w5100.c new file mode 100755 index 0000000..7d0f55a --- /dev/null +++ b/arduino-0018-linux/libraries/Ethernet/utility/w5100.c @@ -0,0 +1,1302 @@ +/* + * (c)COPYRIGHT + * ALL RIGHT RESERVED + * + * FileName : w5100.c + * Revision History : + * ---------- ------- ------------------------------------------------ + * Date version Description + * ---------- ------- ------------------------------------------------ + * 01/25/2007 1.1 Bug is Fixed in the Indirect Mode + * : Memory mapping error + * ---------- ------- ------------------------------------------------ + * 01/08/2008 1.2 Modification of Socket Command Part + * : Check if the appropriately performed after writing Sn_CR + * + * Modification of SPI Part + * : SPI code changed by adding 'spi.h'. + * : Change control type for SPI port from byte to bit. + * ---------- ------- ------------------------------------------------ + * 01/15/2008 1.3 Bug is Fixed in the pppinit() fuction. + * : do not clear interrupt value, so fixed. + * + * Modification of ISR + * : Do not exit ISR, if there is interrupt. + * ---------- ------- ------------------------------------------------ + * 03/21/2008 1.4 Modification of SetMR() function + * : Use IINCHIP_WRITE() function in Direct or SPI mode. + * ---------- ------- ------------------------------------------------ + */ +#include +#include + +#include +// #include + +#include "types.h" +#include "socket.h" +#include "w5100.h" + + + +#ifdef __DEF_IINCHIP_PPP__ + #include "md5.h" +#endif + + +#if (__DEF_IINCHIP_BUS__ == __DEF_IINCHIP_SPI_MODE__) +#include "spi.h" //+2007113[jhpark] +#endif + +static uint8 I_STATUS[MAX_SOCK_NUM]; +static uint16 SMASK[MAX_SOCK_NUM]; /**< Variable for Tx buffer MASK in each channel */ +static uint16 RMASK[MAX_SOCK_NUM]; /**< Variable for Rx buffer MASK in each channel */ +static uint16 SSIZE[MAX_SOCK_NUM]; /**< Max Tx buffer size by each channel */ +static uint16 RSIZE[MAX_SOCK_NUM]; /**< Max Rx buffer size by each channel */ +static uint16 SBUFBASEADDRESS[MAX_SOCK_NUM]; /**< Tx buffer base address by each channel */ +static uint16 RBUFBASEADDRESS[MAX_SOCK_NUM]; /**< Rx buffer base address by each channel */ + +uint8 getISR(uint8 s) +{ + return I_STATUS[s]; +} + +void putISR(uint8 s, uint8 val) +{ + I_STATUS[s] = val; +} + +uint16 getIINCHIP_RxMAX(uint8 s) +{ + return RSIZE[s]; +} +uint16 getIINCHIP_TxMAX(uint8 s) +{ + return SSIZE[s]; +} +uint16 getIINCHIP_RxMASK(uint8 s) +{ + return RMASK[s]; +} +uint16 getIINCHIP_TxMASK(uint8 s) +{ + return SMASK[s]; +} +uint16 getIINCHIP_RxBASE(uint8 s) +{ + return RBUFBASEADDRESS[s]; +} +uint16 getIINCHIP_TxBASE(uint8 s) +{ + return SBUFBASEADDRESS[s]; +} + + /** +@brief This function writes the data into W5100 registers. +*/ +uint8 IINCHIP_WRITE(uint16 addr,uint8 data) +{ +// DIRECT MODE I/F +#if (__DEF_IINCHIP_BUS__ == __DEF_IINCHIP_DIRECT_MODE__) + IINCHIP_ISR_DISABLE(); + *((vuint8*)(addr)) = data; + IINCHIP_ISR_ENABLE(); +#elif(__DEF_IINCHIP_BUS__ == __DEF_IINCHIP_INDIRECT_MODE__) /* INDIRECT MODE I/F */ + IINCHIP_ISR_DISABLE(); + *((vuint8*)IDM_AR0) = (uint8)((addr & 0xFF00) >> 8); + *((vuint8*)IDM_AR1) = (uint8)(addr & 0x00FF); + *((vuint8*)IDM_DR) = data; + IINCHIP_ISR_ENABLE(); +#elif (__DEF_IINCHIP_BUS__ == __DEF_IINCHIP_SPI_MODE__) + IINCHIP_ISR_DISABLE(); + IINCHIP_SpiInit(); + + //SPI MODE I/F + IINCHIP_CSoff(); // CS=0, SPI start + + IINCHIP_SpiSendData(0xF0); + IINCHIP_SpiSendData((addr & 0xFF00) >> 8); + IINCHIP_SpiSendData(addr & 0x00FF); + IINCHIP_SpiSendData(data); + + IINCHIP_CSon(); + + IINCHIP_ISR_ENABLE(); +#else + #error "unknown bus type" +#endif + return 1; +} + + +/** +@brief This function reads the value from W5100 registers. +*/ +uint8 IINCHIP_READ(uint16 addr) +{ + uint8 data; + +// DIRECT MODE I/F + +#if (__DEF_IINCHIP_BUS__ == __DEF_IINCHIP_DIRECT_MODE__) + IINCHIP_ISR_DISABLE(); + data = *((vuint8*)(addr)); + IINCHIP_ISR_ENABLE(); +#elif(__DEF_IINCHIP_BUS__ == __DEF_IINCHIP_INDIRECT_MODE__) + IINCHIP_ISR_DISABLE(); + *((vuint8*)IDM_AR0) = (uint8)((addr & 0xFF00) >> 8); + *((vuint8*)IDM_AR1) = (uint8)(addr & 0x00FF); + data = *((vuint8*)IDM_DR); + IINCHIP_ISR_ENABLE(); + +#elif (__DEF_IINCHIP_BUS__ == __DEF_IINCHIP_SPI_MODE__) + IINCHIP_ISR_DISABLE(); + IINCHIP_SpiInit(); + IINCHIP_CSoff(); // CS=0, SPI start + + IINCHIP_SpiSendData(0x0F); + IINCHIP_SpiSendData((addr & 0xFF00) >> 8); + IINCHIP_SpiSendData(addr & 0x00FF); + + + IINCHIP_SpiSendData(0); + data = IINCHIP_SpiRecvData(); + + IINCHIP_CSon(); // SPI end + IINCHIP_ISR_ENABLE(); +#else + #error "unknown bus type" +#endif + return data; +} + + +/** +@brief This function writes into W5100 memory(Buffer) +*/ +uint16 wiz_write_buf(uint16 addr,uint8* buf,uint16 len) +{ +#if (__DEF_IINCHIP_BUS__ == __DEF_IINCHIP_DIRECT_MODE__) + IINCHIP_ISR_DISABLE(); + memcpy((uint8 *)addr, buf, len); + IINCHIP_ISR_ENABLE(); +#elif (__DEF_IINCHIP_BUS__ == __DEF_IINCHIP_INDIRECT_MODE__) + uint16 idx = 0; + IINCHIP_ISR_DISABLE(); + *((vuint8*)IDM_AR0) = (uint8)((addr & 0xFF00) >> 8); + *((vuint8*)IDM_AR1) = (uint8)(addr & 0x00FF); + for (idx = 0; idx < len ; idx++) *((vuint8*)IDM_DR) = buf[idx]; + IINCHIP_ISR_ENABLE(); +#elif (__DEF_IINCHIP_BUS__ == __DEF_IINCHIP_SPI_MODE__) + uint16 idx = 0; + + IINCHIP_ISR_DISABLE(); + IINCHIP_SpiInit(); + + //SPI MODE I/F + for(idx=0;idx> 8); + IINCHIP_SpiSendData((addr+idx) & 0x00FF); + IINCHIP_SpiSendData(buf[idx]); + + IINCHIP_CSon(); // CS=0, SPI end + } + + IINCHIP_ISR_ENABLE(); +#else + #error "unknown bus type" +#endif + return len; +} + + +/** +@brief This function reads into W5100 memory(Buffer) +*/ +uint16 wiz_read_buf(uint16 addr, uint8* buf,uint16 len) +{ +#if (__DEF_IINCHIP_BUS__ == __DEF_IINCHIP_DIRECT_MODE__) + IINCHIP_ISR_DISABLE(); + memcpy(buf, (uint8 *)addr, len); + IINCHIP_ISR_ENABLE(); +#elif(__DEF_IINCHIP_BUS__ == __DEF_IINCHIP_INDIRECT_MODE__) + uint16 idx = 0; + IINCHIP_ISR_DISABLE(); + *((vuint8*)IDM_AR0) = (uint8)((addr & 0xFF00) >> 8); + *((vuint8*)IDM_AR1) = (uint8)(addr & 0x00FF); + for (idx = 0; idx < len ; idx++) buf[idx] = *((vuint8*)IDM_DR); + IINCHIP_ISR_ENABLE(); +#elif (__DEF_IINCHIP_BUS__ == __DEF_IINCHIP_SPI_MODE__) + uint16 idx = 0; + IINCHIP_ISR_DISABLE(); + + IINCHIP_SpiInit(); + + for (idx=0; idx> 8); + IINCHIP_SpiSendData((addr+idx) & 0x00FF); + + + IINCHIP_SpiSendData(0); + buf[idx] = IINCHIP_SpiRecvData(); + + IINCHIP_CSon(); // CS=0, SPI end + } + + IINCHIP_ISR_ENABLE(); +#else + #error "unknown bus type" +#endif + return len; +} + + +/** +@brief Socket interrupt routine +*/ +#ifdef __DEF_IINCHIP_INT__ +ISR(INT4_vect) +{ + uint8 int_val; + IINCHIP_ISR_DISABLE(); + int_val = IINCHIP_READ(IR); + + /* +200801[bj] process all of interupt */ + do { + /*---*/ + + if (int_val & IR_CONFLICT) + { + printf("IP conflict : %.2x\r\n", int_val); + } + if (int_val & IR_UNREACH) + { + printf("INT Port Unreachable : %.2x\r\n", int_val); + printf("UIPR0 : %d.%d.%d.%d\r\n", IINCHIP_READ(UIPR0), IINCHIP_READ(UIPR0+1), IINCHIP_READ(UIPR0+2), IINCHIP_READ(UIPR0+3)); + printf("UPORT0 : %.2x %.2x\r\n", IINCHIP_READ(UPORT0), IINCHIP_READ(UPORT0+1)); + } + + /* +200801[bj] interrupt clear */ + IINCHIP_WRITE(IR, 0xf0); + /*---*/ + + if (int_val & IR_SOCK(0)) + { + /* +-200801[bj] save interrupt value*/ + I_STATUS[0] |= IINCHIP_READ(Sn_IR(0)); // can be come to over two times. + IINCHIP_WRITE(Sn_IR(0), I_STATUS[0]); + /*---*/ + } + if (int_val & IR_SOCK(1)) + { + /* +-200801[bj] save interrupt value*/ + I_STATUS[1] |= IINCHIP_READ(Sn_IR(1)); + IINCHIP_WRITE(Sn_IR(1), I_STATUS[1]); + /*---*/ + } + if (int_val & IR_SOCK(2)) + { + /* +-200801[bj] save interrupt value*/ + I_STATUS[2] |= IINCHIP_READ(Sn_IR(2)); + IINCHIP_WRITE(Sn_IR(2), I_STATUS[2]); + /*---*/ + } + if (int_val & IR_SOCK(3)) + { + /* +-200801[bj] save interrupt value*/ + I_STATUS[3] |= IINCHIP_READ(Sn_IR(3)); + IINCHIP_WRITE(Sn_IR(3), I_STATUS[3]); + /*---*/ + } + + /* +-200801[bj] re-read interrupt value*/ + int_val = IINCHIP_READ(IR); + + /* +200801[bj] if exist, contiue to process */ + } while (int_val != 0x00); + /*---*/ + + IINCHIP_ISR_ENABLE(); +} +#endif + +/** +@brief This function is for resetting of the iinchip. Initializes the iinchip to work in whether DIRECT or INDIRECT mode +*/ +void iinchip_init(void) +{ + setMR( MR_RST ); +#if (__DEF_IINCHIP_BUS__ == __DEF_IINCHIP_INDIRECT_MODE__) + setMR( MR_IND | MR_AI ); +#ifdef __DEF_IINCHIP_DBG__ + printf("MR value is %d \r\n",IINCHIP_READ(MR)); +#endif +#endif +} + + +/** +@brief This function set the transmit & receive buffer size as per the channels is used + +Note for TMSR and RMSR bits are as follows\n +bit 1-0 : memory size of channel #0 \n +bit 3-2 : memory size of channel #1 \n +bit 5-4 : memory size of channel #2 \n +bit 7-6 : memory size of channel #3 \n\n +Maximum memory size for Tx, Rx in the W5100 is 8K Bytes,\n +In the range of 8KBytes, the memory size could be allocated dynamically by each channel.\n +Be attentive to sum of memory size shouldn't exceed 8Kbytes\n +and to data transmission and receiption from non-allocated channel may cause some problems.\n +If the 8KBytes memory is already assigned to centain channel, \n +other 3 channels couldn't be used, for there's no available memory.\n +If two 4KBytes memory are assigned to two each channels, \n +other 2 channels couldn't be used, for there's no available memory.\n +*/ +void sysinit( + uint8 tx_size, /**< tx_size Tx memory size (00 - 1KByte, 01- 2KBtye, 10 - 4KByte, 11 - 8KByte) */ + uint8 rx_size /**< rx_size Rx memory size (00 - 1KByte, 01- 2KBtye, 10 - 4KByte, 11 - 8KByte) */ + ) +{ + int16 i; + int16 ssum,rsum; + +#ifdef __DEF_IINCHIP_DBG__ + printf("sysinit()\r\n"); +#endif + + ssum = 0; + rsum = 0; + + IINCHIP_WRITE(TMSR,tx_size); /* Set Tx memory size for each channel */ + IINCHIP_WRITE(RMSR,rx_size); /* Set Rx memory size for each channel */ + + SBUFBASEADDRESS[0] = (uint16)(__DEF_IINCHIP_MAP_TXBUF__); /* Set base address of Tx memory for channel #0 */ + RBUFBASEADDRESS[0] = (uint16)(__DEF_IINCHIP_MAP_RXBUF__); /* Set base address of Rx memory for channel #0 */ + +#ifdef __DEF_IINCHIP_DBG__ + printf("Channel : SEND MEM SIZE : RECV MEM SIZE\r\n"); +#endif + + for (i = 0 ; i < MAX_SOCK_NUM; i++) // Set the size, masking and base address of Tx & Rx memory by each channel + { + SSIZE[i] = (int16)(0); + RSIZE[i] = (int16)(0); + if (ssum < 8192) + { + switch((tx_size >> i*2) & 0x03) // Set Tx memory size + { + case 0: + SSIZE[i] = (int16)(1024); + SMASK[i] = (uint16)(0x03FF); + break; + case 1: + SSIZE[i] = (int16)(2048); + SMASK[i] = (uint16)(0x07FF); + break; + case 2: + SSIZE[i] = (int16)(4096); + SMASK[i] = (uint16)(0x0FFF); + break; + case 3: + SSIZE[i] = (int16)(8192); + SMASK[i] = (uint16)(0x1FFF); + break; + } + } + if (rsum < 8192) + { + switch((rx_size >> i*2) & 0x03) // Set Rx memory size + { + case 0: + RSIZE[i] = (int16)(1024); + RMASK[i] = (uint16)(0x03FF); + break; + case 1: + RSIZE[i] = (int16)(2048); + RMASK[i] = (uint16)(0x07FF); + break; + case 2: + RSIZE[i] = (int16)(4096); + RMASK[i] = (uint16)(0x0FFF); + break; + case 3: + RSIZE[i] = (int16)(8192); + RMASK[i] = (uint16)(0x1FFF); + break; + } + } + ssum += SSIZE[i]; + rsum += RSIZE[i]; + + if (i != 0) // Sets base address of Tx and Rx memory for channel #1,#2,#3 + { + SBUFBASEADDRESS[i] = SBUFBASEADDRESS[i-1] + SSIZE[i-1]; + RBUFBASEADDRESS[i] = RBUFBASEADDRESS[i-1] + RSIZE[i-1]; + } +#ifdef __DEF_IINCHIP_DBG__ + printf("%d : %.4x : %.4x : %.4x : %.4x\r\n", i, (uint16)SBUFBASEADDRESS[i], (uint16)RBUFBASEADDRESS[i], SSIZE[i], RSIZE[i]); +#endif + } +} + + +void setMR(uint8 val) +{ + +#if (__DEF_IINCHIP_BUS__ == __DEF_IINCHIP_INDIRECT_MODE__) + *((volatile uint8*)(MR)) = val; +#else + /* DIRECT ACCESS */ + IINCHIP_WRITE(MR,val); +#endif +} + + +/** +@brief This function sets up gateway IP address. +*/ +void setGAR( + uint8 * addr /**< a pointer to a 4 -byte array responsible to set the Gateway IP address. */ + ) +{ + IINCHIP_WRITE((GAR0 + 0),addr[0]); + IINCHIP_WRITE((GAR0 + 1),addr[1]); + IINCHIP_WRITE((GAR0 + 2),addr[2]); + IINCHIP_WRITE((GAR0 + 3),addr[3]); +} +void getGWIP(uint8 * addr) +{ + addr[0] = IINCHIP_READ((GAR0 + 0)); + addr[1] = IINCHIP_READ((GAR0 + 1)); + addr[2] = IINCHIP_READ((GAR0 + 2)); + addr[3] = IINCHIP_READ((GAR0 + 3)); +} + + +/** +@brief It sets up SubnetMask address +*/ +void setSUBR( + uint8 * addr /**< a pointer to a 4 -byte array responsible to set the SubnetMask address */ + ) +{ + IINCHIP_WRITE((SUBR0 + 0),addr[0]); + IINCHIP_WRITE((SUBR0 + 1),addr[1]); + IINCHIP_WRITE((SUBR0 + 2),addr[2]); + IINCHIP_WRITE((SUBR0 + 3),addr[3]); +} + + +/** +@brief This function sets up MAC address. +*/ +void setSHAR( + uint8 * addr /**< a pointer to a 6 -byte array responsible to set the MAC address. */ + ) +{ + IINCHIP_WRITE((SHAR0 + 0),addr[0]); + IINCHIP_WRITE((SHAR0 + 1),addr[1]); + IINCHIP_WRITE((SHAR0 + 2),addr[2]); + IINCHIP_WRITE((SHAR0 + 3),addr[3]); + IINCHIP_WRITE((SHAR0 + 4),addr[4]); + IINCHIP_WRITE((SHAR0 + 5),addr[5]); +} + + +/** +@brief This function sets up Source IP address. +*/ +void setSIPR( + uint8 * addr /**< a pointer to a 4 -byte array responsible to set the Source IP address. */ + ) +{ + IINCHIP_WRITE((SIPR0 + 0),addr[0]); + IINCHIP_WRITE((SIPR0 + 1),addr[1]); + IINCHIP_WRITE((SIPR0 + 2),addr[2]); + IINCHIP_WRITE((SIPR0 + 3),addr[3]); +} + + +/** +@brief This function gets Interrupt register in common register. + */ +uint8 getIR( void ) +{ + return IINCHIP_READ(IR); +} + + + +/** +@brief This function sets up Retransmission time. + +If there is no response from the peer or delay in response then retransmission +will be there as per RTR (Retry Time-value Register)setting +*/ +void setRTR(uint16 timeout) +{ + IINCHIP_WRITE(RTR0,(uint8)((timeout & 0xff00) >> 8)); + IINCHIP_WRITE((RTR0 + 1),(uint8)(timeout & 0x00ff)); +} + + +/** +@brief This function set the number of Retransmission. + +If there is no response from the peer or delay in response then recorded time +as per RTR & RCR register seeting then time out will occur. +*/ +void setRCR(uint8 retry) +{ + IINCHIP_WRITE(RCR,retry); +} + + +/** +@brief This function set the interrupt mask Enable/Disable appropriate Interrupt. ('1' : interrupt enable) + +If any bit in IMR is set as '0' then there is not interrupt signal though the bit is +set in IR register. +*/ +void setIMR(uint8 mask) +{ + IINCHIP_WRITE(IMR,mask); // must be setted 0x10. +} + + +/** +@brief These below functions are used to get the Gateway, SubnetMask + and Source Hardware Address (MAC Address) and Source IP address +*/ +void getGAR(uint8 * addr) +{ + addr[0] = IINCHIP_READ(GAR0); + addr[1] = IINCHIP_READ(GAR0+1); + addr[2] = IINCHIP_READ(GAR0+2); + addr[3] = IINCHIP_READ(GAR0+3); +} +void getSUBR(uint8 * addr) +{ + addr[0] = IINCHIP_READ(SUBR0); + addr[1] = IINCHIP_READ(SUBR0+1); + addr[2] = IINCHIP_READ(SUBR0+2); + addr[3] = IINCHIP_READ(SUBR0+3); +} +void getSHAR(uint8 * addr) +{ + addr[0] = IINCHIP_READ(SHAR0); + addr[1] = IINCHIP_READ(SHAR0+1); + addr[2] = IINCHIP_READ(SHAR0+2); + addr[3] = IINCHIP_READ(SHAR0+3); + addr[4] = IINCHIP_READ(SHAR0+4); + addr[5] = IINCHIP_READ(SHAR0+5); +} +void getSIPR(uint8 * addr) +{ + addr[0] = IINCHIP_READ(SIPR0); + addr[1] = IINCHIP_READ(SIPR0+1); + addr[2] = IINCHIP_READ(SIPR0+2); + addr[3] = IINCHIP_READ(SIPR0+3); +} + + +/** +@brief These below functions are used to get the Destination Hardware Address (MAC Address), Destination IP address and Destination Port. +*/ +void getSn_DHAR(SOCKET s, uint8 * addr) +{ + addr[0] = IINCHIP_READ(Sn_DHAR0(s)); + addr[1] = IINCHIP_READ(Sn_DHAR0(s)+1); + addr[2] = IINCHIP_READ(Sn_DHAR0(s)+2); + addr[3] = IINCHIP_READ(Sn_DHAR0(s)+3); + addr[4] = IINCHIP_READ(Sn_DHAR0(s)+4); + addr[5] = IINCHIP_READ(Sn_DHAR0(s)+5); +} +void setSn_DHAR(SOCKET s, uint8 * addr) +{ + IINCHIP_WRITE((Sn_DHAR0(s) + 0),addr[0]); + IINCHIP_WRITE((Sn_DHAR0(s) + 1),addr[1]); + IINCHIP_WRITE((Sn_DHAR0(s) + 2),addr[2]); + IINCHIP_WRITE((Sn_DHAR0(s) + 3),addr[3]); + IINCHIP_WRITE((Sn_DHAR0(s) + 4),addr[4]); + IINCHIP_WRITE((Sn_DHAR0(s) + 5),addr[5]); +} +void getSn_DIPR(SOCKET s, uint8 * addr) +{ + addr[0] = IINCHIP_READ(Sn_DIPR0(s)); + addr[1] = IINCHIP_READ(Sn_DIPR0(s)+1); + addr[2] = IINCHIP_READ(Sn_DIPR0(s)+2); + addr[3] = IINCHIP_READ(Sn_DIPR0(s)+3); +} +void setSn_DIPR(SOCKET s, uint8 * addr) +{ + IINCHIP_WRITE((Sn_DIPR0(s) + 0),addr[0]); + IINCHIP_WRITE((Sn_DIPR0(s) + 1),addr[1]); + IINCHIP_WRITE((Sn_DIPR0(s) + 2),addr[2]); + IINCHIP_WRITE((Sn_DIPR0(s) + 3),addr[3]); +} +void getSn_DPORT(SOCKET s, uint8 * addr) +{ + addr[0] = IINCHIP_READ(Sn_DPORT0(s)); + addr[1] = IINCHIP_READ(Sn_DPORT0(s)+1); +} +void setSn_DPORT(SOCKET s, uint8 * addr) +{ + IINCHIP_WRITE((Sn_DPORT0(s) + 0),addr[0]); + IINCHIP_WRITE((Sn_DPORT0(s) + 1),addr[1]); +} + + +/** +@brief This sets the maximum segment size of TCP in Active Mode), while in Passive Mode this is set by peer +*/ +void setSn_MSS(SOCKET s, uint16 Sn_MSSR0) +{ + IINCHIP_WRITE(Sn_MSSR0(s),(uint8)((Sn_MSSR0 & 0xff00) >> 8)); + IINCHIP_WRITE((Sn_MSSR0(s) + 1),(uint8)(Sn_MSSR0 & 0x00ff)); +} + +void setSn_TTL(SOCKET s, uint8 ttl) +{ + IINCHIP_WRITE(Sn_TTL(s), ttl); +} + + +/** +@brief These below function is used to setup the Protocol Field of IP Header when + executing the IP Layer RAW mode. +*/ +void setSn_PROTO(SOCKET s, uint8 proto) +{ + IINCHIP_WRITE(Sn_PROTO(s),proto); +} + + +/** +@brief get socket interrupt status + +These below functions are used to read the Interrupt & Soket Status register +*/ +uint8 getSn_IR(SOCKET s) +{ + return IINCHIP_READ(Sn_IR(s)); +} + + +/** +@brief get socket status +*/ +uint8 getSn_SR(SOCKET s) +{ + return IINCHIP_READ(Sn_SR(s)); +} + + +/** +@brief get socket TX free buf size + +This gives free buffer size of transmit buffer. This is the data size that user can transmit. +User shuold check this value first and control the size of transmitting data +*/ +uint16 getSn_TX_FSR(SOCKET s) +{ + uint16 val=0,val1=0; + do + { + val1 = IINCHIP_READ(Sn_TX_FSR0(s)); + val1 = (val1 << 8) + IINCHIP_READ(Sn_TX_FSR0(s) + 1); + if (val1 != 0) + { + val = IINCHIP_READ(Sn_TX_FSR0(s)); + val = (val << 8) + IINCHIP_READ(Sn_TX_FSR0(s) + 1); + } + } while (val != val1); + return val; +} + + +/** +@brief get socket RX recv buf size + +This gives size of received data in receive buffer. +*/ +uint16 getSn_RX_RSR(SOCKET s) +{ + uint16 val=0,val1=0; + do + { + val1 = IINCHIP_READ(Sn_RX_RSR0(s)); + val1 = (val1 << 8) + IINCHIP_READ(Sn_RX_RSR0(s) + 1); + if(val1 != 0) + { + val = IINCHIP_READ(Sn_RX_RSR0(s)); + val = (val << 8) + IINCHIP_READ(Sn_RX_RSR0(s) + 1); + } + } while (val != val1); + return val; +} + + +/** +@brief This function is being called by send() and sendto() function also. + +This function read the Tx write pointer register and after copy the data in buffer update the Tx write pointer +register. User should read upper byte first and lower byte later to get proper value. +*/ +void send_data_processing(SOCKET s, uint8 *data, uint16 len) +{ + uint16 ptr; + ptr = IINCHIP_READ(Sn_TX_WR0(s)); + ptr = ((ptr & 0x00ff) << 8) + IINCHIP_READ(Sn_TX_WR0(s) + 1); + write_data(s, data, (uint8 *)(ptr), len); + ptr += len; + IINCHIP_WRITE(Sn_TX_WR0(s),(uint8)((ptr & 0xff00) >> 8)); + IINCHIP_WRITE((Sn_TX_WR0(s) + 1),(uint8)(ptr & 0x00ff)); +} + + +/** +@brief This function is being called by recv() also. + +This function read the Rx read pointer register +and after copy the data from receive buffer update the Rx write pointer register. +User should read upper byte first and lower byte later to get proper value. +*/ +void recv_data_processing(SOCKET s, uint8 *data, uint16 len) +{ + uint16 ptr; + ptr = IINCHIP_READ(Sn_RX_RD0(s)); + ptr = ((ptr & 0x00ff) << 8) + IINCHIP_READ(Sn_RX_RD0(s) + 1); +#ifdef __DEF_IINCHIP_DBG__ + printf("ISR_RX: rd_ptr : %.4x\r\n", ptr); +#endif + read_data(s, (uint8 *)ptr, data, len); // read data + ptr += len; + IINCHIP_WRITE(Sn_RX_RD0(s),(uint8)((ptr & 0xff00) >> 8)); + IINCHIP_WRITE((Sn_RX_RD0(s) + 1),(uint8)(ptr & 0x00ff)); +} + + +/** +@brief for copy the data form application buffer to Transmite buffer of the chip. + +This function is being used for copy the data form application buffer to Transmite +buffer of the chip. It calculate the actual physical address where one has to write +the data in transmite buffer. Here also take care of the condition while it exceed +the Tx memory uper-bound of socket. +*/ +void write_data(SOCKET s, vuint8 * src, vuint8 * dst, uint16 len) +{ + uint16 size; + uint16 dst_mask; + uint8 * dst_ptr; + + dst_mask = (uint16)dst & getIINCHIP_TxMASK(s); + dst_ptr = (uint8 *)(getIINCHIP_TxBASE(s) + dst_mask); + + if (dst_mask + len > getIINCHIP_TxMAX(s)) + { + size = getIINCHIP_TxMAX(s) - dst_mask; + wiz_write_buf((uint16)dst_ptr, (uint8*)src, size); + src += size; + size = len - size; + dst_ptr = (uint8 *)(getIINCHIP_TxBASE(s)); + wiz_write_buf((uint16)dst_ptr, (uint8*)src, size); + } + else + { + wiz_write_buf((uint16)dst_ptr, (uint8*)src, len); + } +} + + +/** +@brief This function is being used for copy the data form Receive buffer of the chip to application buffer. + +It calculate the actual physical address where one has to read +the data from Receive buffer. Here also take care of the condition while it exceed +the Rx memory uper-bound of socket. +*/ +void read_data(SOCKET s, vuint8 * src, vuint8 * dst, uint16 len) +{ + uint16 size; + uint16 src_mask; + uint8 * src_ptr; + + src_mask = (uint16)src & getIINCHIP_RxMASK(s); + src_ptr = (uint8 *)(getIINCHIP_RxBASE(s) + src_mask); + + if( (src_mask + len) > getIINCHIP_RxMAX(s) ) + { + size = getIINCHIP_RxMAX(s) - src_mask; + wiz_read_buf((uint16)src_ptr, (uint8*)dst,size); + dst += size; + size = len - size; + src_ptr = (uint8 *)(getIINCHIP_RxBASE(s)); + wiz_read_buf((uint16)src_ptr, (uint8*) dst,size); + } + else + { + wiz_read_buf((uint16)src_ptr, (uint8*) dst,len); + } +} + + +#ifdef __DEF_IINCHIP_PPP__ +#define PPP_OPTION_BUF_LEN 64 + +uint8 pppinit_in(uint8 * id, uint8 idlen, uint8 * passwd, uint8 passwdlen); + + +/** +@brief make PPPoE connection +@return 1 => success to connect, 2 => Auth fail, 3 => timeout, 4 => Auth type not support + +*/ +uint8 pppinit(uint8 * id, uint8 idlen, uint8 * passwd, uint8 passwdlen) +{ + uint8 ret; + uint8 isr; + + // PHASE0. W5100 PPPoE(ADSL) setup + // enable pppoe mode + printf("-- PHASE 0. W5100 PPPoE(ADSL) setup process --\r\n"); + printf("\r\n"); + IINCHIP_WRITE(MR,IINCHIP_READ(MR) | MR_PPPOE); + + // open socket in pppoe mode + isr = IINCHIP_READ(Sn_IR(0));// first clear isr(0), W5100 at present time + IINCHIP_WRITE(Sn_IR(0),isr); + + IINCHIP_WRITE(PTIMER,200); // 5sec timeout + IINCHIP_WRITE(PMAGIC,0x01); // magic number + IINCHIP_WRITE(Sn_MR(0),Sn_MR_PPPOE); + IINCHIP_WRITE(Sn_CR(0),Sn_CR_OPEN); + + /* +20071122[chungs]:wait to process the command... */ + while( IINCHIP_READ(Sn_CR(0)) ) + ; + /* ------- */ + + ret = pppinit_in(id, idlen, passwd, passwdlen); + + // close ppp connection socket + /* +200801 (hwkim) */ + close(0); + /* ------- */ + + return ret; +} + + +uint8 pppinit_in(uint8 * id, uint8 idlen, uint8 * passwd, uint8 passwdlen) +{ + uint8 loop_idx = 0; + uint8 isr = 0; + uint8 buf[PPP_OPTION_BUF_LEN]; + uint16 len; + uint8 str[PPP_OPTION_BUF_LEN]; + uint8 str_idx,dst_idx; + + // PHASE1. PPPoE Discovery + // start to connect pppoe connection + printf("-- PHASE 1. PPPoE Discovery process --"); + printf(" ok\r\n"); + printf("\r\n"); + IINCHIP_WRITE(Sn_CR(0),Sn_CR_PCON); + /* +20071122[chungs]:wait to process the command... */ + while( IINCHIP_READ(Sn_CR(0)) ) + ; + /* ------- */ + + wait_10ms(100); + + loop_idx = 0; + //check whether PPPoE discovery end or not + while (!(IINCHIP_READ(Sn_IR(0)) & Sn_IR_PNEXT)) + { + printf("."); + if (loop_idx++ == 10) // timeout + { + printf("timeout before LCP\r\n"); + return 3; + } + wait_10ms(100); + } + + /* +200801[bj] clear interrupt value*/ + IINCHIP_WRITE(Sn_IR(0), 0xff); + /*---*/ + + // PHASE2. LCP process + printf("-- PHASE 2. LCP process --"); + + // send LCP Request + { + // Magic number option + // option format (type value + length value + data) + // write magic number value + buf[0] = 0x05; // type value + buf[1] = 0x06; // length value + buf[2] = 0x01; buf[3] = 0x01; buf[4] = 0x01; buf[5]= 0x01; // data + // for MRU option, 1492 0x05d4 + // buf[6] = 0x01; buf[7] = 0x04; buf[8] = 0x05; buf[9] = 0xD4; + } + send_data_processing(0, buf, 0x06); + IINCHIP_WRITE(Sn_CR(0),Sn_CR_PCR); // send request + /* +20071122[chungs]:wait to process the command... */ + while( IINCHIP_READ(Sn_CR(0)) ) + ; + /* ------- */ + + wait_10ms(100); + + while (!((isr = IINCHIP_READ(Sn_IR(0))) & Sn_IR_PNEXT)) + { + if (isr & Sn_IR_PRECV) // Not support option + { + /* +200801[bj] clear interrupt value*/ + IINCHIP_WRITE(Sn_IR(0), Sn_IR_PRECV); + /*---*/ + len = getSn_RX_RSR(0); + if ( len > 0 ) + { + recv_data_processing(0, str, len); + IINCHIP_WRITE(Sn_CR(0),Sn_CR_RECV); + /* +20071122[chungs]:wait to process the command... */ + while( IINCHIP_READ(Sn_CR(0)) ) + ; + /* ------- */ + + // for debug + //printf("LCP proc\r\n"); for (i = 0; i < len; i++) printf ("%02x ", str[i]); printf("\r\n"); + // get option length + len = str[4]; len = ((len & 0x00ff) << 8) + str[5]; + len += 2; + str_idx = 6; dst_idx = 0; // ppp header is 6 byte, so starts at 6. + do + { + if ((str[str_idx] == 0x01) || (str[str_idx] == 0x02) || (str[str_idx] == 0x03) || (str[str_idx] == 0x05)) + { + // skip as length of support option. str_idx+1 is option's length. + str_idx += str[str_idx+1]; + } + else + { + // not support option , REJECT + memcpy((uint8 *)(buf+dst_idx), (uint8 *)(str+str_idx), str[str_idx+1]); + dst_idx += str[str_idx+1]; str_idx += str[str_idx+1]; + } + } while (str_idx != len); + // for debug + // printf("LCP dst proc\r\n"); for (i = 0; i < dst_idx; i++) printf ("%02x ", dst[i]); printf("\r\n"); + + // send LCP REJECT packet + send_data_processing(0, buf, dst_idx); + IINCHIP_WRITE(Sn_CR(0),Sn_CR_PCJ); + /* +20071122[chungs]:wait to process the command... */ + while( IINCHIP_READ(Sn_CR(0)) ) + ; + /* ------- */ + } + } + printf("."); + if (loop_idx++ == 10) // timeout + { + printf("timeout after LCP\r\n"); + return 3; + } + wait_10ms(100); + } + printf(" ok\r\n"); + printf("\r\n"); + + /* +200801[bj] clear interrupt value*/ + IINCHIP_WRITE(Sn_IR(0), 0xff); + /*---*/ + + printf("-- PHASE 3. PPPoE(ADSL) Authentication mode --\r\n"); + printf("Authentication protocol : %.2x %.2x, ", IINCHIP_READ(PATR0), IINCHIP_READ(PATR0+1)); + + loop_idx = 0; + if (IINCHIP_READ(PATR0) == 0xc0 && IINCHIP_READ(PATR0+1) == 0x23) + { + printf("PAP\r\n"); // in case of adsl normally supports PAP. + // send authentication data + // copy (idlen + id + passwdlen + passwd) + buf[loop_idx] = idlen; loop_idx++; + memcpy((uint8 *)(buf+loop_idx), (uint8 *)(id), idlen); loop_idx += idlen; + buf[loop_idx] = passwdlen; loop_idx++; + memcpy((uint8 *)(buf+loop_idx), (uint8 *)(passwd), passwdlen); loop_idx += passwdlen; + send_data_processing(0, buf, loop_idx); + IINCHIP_WRITE(Sn_CR(0),Sn_CR_PCR); + /* +20071122[chungs]:wait to process the command... */ + while( IINCHIP_READ(Sn_CR(0)) ) + ; + /* ------- */ + wait_10ms(100); + } + else if (IINCHIP_READ(PATR0) == 0xc2 && IINCHIP_READ(PATR0+1) == 0x23) + { + uint8 chal_len; + md5_ctx context; + uint8 digest[16]; + + len = getSn_RX_RSR(0); + if ( len > 0 ) + { + recv_data_processing(0, str, len); + IINCHIP_WRITE(Sn_CR(0),Sn_CR_RECV); + /* +20071122[chungs]:wait to process the command... */ + while( IINCHIP_READ(Sn_CR(0)) ) + ; + /* ------- */ +#ifdef __DEF_IINCHIP_DBG__ + printf("recv CHAP\r\n"); + { + int16 i; + + for (i = 0; i < 32; i++) + printf ("%02x ", str[i]); + } + printf("\r\n"); +#endif +// str is C2 23 xx CHAL_ID xx xx CHAP_LEN CHAP_DATA +// index 0 1 2 3 4 5 6 7 ... + + memset(buf,0x00,64); + buf[loop_idx] = str[3]; loop_idx++; // chal_id + memcpy((uint8 *)(buf+loop_idx), (uint8 *)(passwd), passwdlen); loop_idx += passwdlen; //passwd + chal_len = str[6]; // chal_id + memcpy((uint8 *)(buf+loop_idx), (uint8 *)(str+7), chal_len); loop_idx += chal_len; //challenge + buf[loop_idx] = 0x80; +#ifdef __DEF_IINCHIP_DBG__ + printf("CHAP proc d1\r\n"); + { + int16 i; + for (i = 0; i < 64; i++) + printf ("%02x ", buf[i]); + } + printf("\r\n"); +#endif + + md5_init(&context); + md5_update(&context, buf, loop_idx); + md5_final(digest, &context); + +#ifdef __DEF_IINCHIP_DBG__ + printf("CHAP proc d1\r\n"); + { + int16 i; + for (i = 0; i < 16; i++) + printf ("%02x", digest[i]); + } + printf("\r\n"); +#endif + loop_idx = 0; + buf[loop_idx] = 16; loop_idx++; // hash_len + memcpy((uint8 *)(buf+loop_idx), (uint8 *)(digest), 16); loop_idx += 16; // hashed value + memcpy((uint8 *)(buf+loop_idx), (uint8 *)(id), idlen); loop_idx += idlen; // id + send_data_processing(0, buf, loop_idx); + IINCHIP_WRITE(Sn_CR(0),Sn_CR_PCR); + /* +20071122[chungs]:wait to process the command... */ + while( IINCHIP_READ(Sn_CR(0)) ) + ; + /* ------- */ + wait_10ms(100); + } + } + else + { + printf("Not support\r\n"); +#ifdef __DEF_IINCHIP_DBG__ + printf("Not support PPP Auth type: %.2x%.2x\r\n",IINCHIP_READ(PATR0), IINCHIP_READ(PATR0+1)); +#endif + return 4; + } + printf("\r\n"); + + printf("-- Waiting for PPPoE server's admission --"); + loop_idx = 0; + while (!((isr = IINCHIP_READ(Sn_IR(0))) & Sn_IR_PNEXT)) + { + if (isr & Sn_IR_PFAIL) + { + /* +200801[bj] clear interrupt value*/ + IINCHIP_WRITE(Sn_IR(0), 0xff); + /*---*/ + printf("failed\r\nReinput id, password..\r\n"); + return 2; + } + printf("."); + if (loop_idx++ == 10) // timeout + { + /* +200801[bj] clear interrupt value*/ + IINCHIP_WRITE(Sn_IR(0), 0xff); + /*---*/ + printf("timeout after PAP\r\n"); + return 3; + } + wait_10ms(100); + } + /* +200801[bj] clear interrupt value*/ + IINCHIP_WRITE(Sn_IR(0), 0xff); + /*---*/ + printf("ok\r\n"); + printf("\r\n"); + printf("-- PHASE 4. IPCP process --"); + // IP Address + buf[0] = 0x03; buf[1] = 0x06; buf[2] = 0x00; buf[3] = 0x00; buf[4] = 0x00; buf[5] = 0x00; + send_data_processing(0, buf, 6); + IINCHIP_WRITE(Sn_CR(0),Sn_CR_PCR); + /* +20071122[chungs]:wait to process the command... */ + while( IINCHIP_READ(Sn_CR(0)) ) + ; + /* ------- */ + wait_10ms(100); + + loop_idx = 0; + while (1) + { + if (IINCHIP_READ(Sn_IR(0)) & Sn_IR_PRECV) + { + /* +200801[bj] clear interrupt value*/ + IINCHIP_WRITE(Sn_IR(0), 0xff); + /*---*/ + len = getSn_RX_RSR(0); + if ( len > 0 ) + { + recv_data_processing(0, str, len); + IINCHIP_WRITE(Sn_CR(0),Sn_CR_RECV); + /* +20071122[chungs]:wait to process the command... */ + while( IINCHIP_READ(Sn_CR(0)) ) + ; + /* ------- */ + //for debug + //printf("IPCP proc\r\n"); for (i = 0; i < len; i++) printf ("%02x ", str[i]); printf("\r\n"); + str_idx = 6; dst_idx = 0; + if (str[2] == 0x03) // in case of NAK + { + do + { + if (str[str_idx] == 0x03) // request only ip information + { + memcpy((uint8 *)(buf+dst_idx), (uint8 *)(str+str_idx), str[str_idx+1]); + dst_idx += str[str_idx+1]; str_idx += str[str_idx+1]; + } + else + { + // skip byte + str_idx += str[str_idx+1]; + } + // for debug + //printf("s: %d, d: %d, l: %d", str_idx, dst_idx, len); + } while (str_idx != len); + send_data_processing(0, buf, dst_idx); + IINCHIP_WRITE(Sn_CR(0),Sn_CR_PCR); // send ipcp request + /* +20071122[chungs]:wait to process the command... */ + while( IINCHIP_READ(Sn_CR(0)) ) + ; + /* ------- */ + wait_10ms(100); + break; + } + } + } + printf("."); + if (loop_idx++ == 10) // timeout + { + printf("timeout after IPCP\r\n"); + return 3; + } + wait_10ms(100); + send_data_processing(0, buf, 6); + IINCHIP_WRITE(Sn_CR(0),Sn_CR_PCR); //ipcp re-request + /* +20071122[chungs]:wait to process the command... */ + while( IINCHIP_READ(Sn_CR(0)) ) + ; + /* ------- */ + } + + loop_idx = 0; + while (!(IINCHIP_READ(Sn_IR(0)) & Sn_IR_PNEXT)) + { + printf("."); + if (loop_idx++ == 10) // timeout + { + printf("timeout after IPCP NAK\r\n"); + return 3; + } + wait_10ms(100); + IINCHIP_WRITE(Sn_CR(0),Sn_CR_PCR); // send ipcp request + /* +20071122[chungs]:wait to process the command... */ + while( IINCHIP_READ(Sn_CR(0)) ) + ; + /* ------- */ + } + /* +200801[bj] clear interrupt value*/ + IINCHIP_WRITE(Sn_IR(0), 0xff); + /*---*/ + printf("ok\r\n"); + printf("\r\n"); + return 1; + // after this function, User must save the pppoe server's mac address and pppoe session id in current connection +} + + +/** +@brief terminate PPPoE connection +*/ +uint8 pppterm(uint8 * mac, uint8 * sessionid) +{ + uint16 i; + uint8 isr; +#ifdef __DEF_IINCHIP_DBG__ + printf("pppterm()\r\n"); +#endif + /* Set PPPoE bit in MR(Common Mode Register) : enable socket0 pppoe */ + IINCHIP_WRITE(MR,IINCHIP_READ(MR) | MR_PPPOE); + + // write pppoe server's mac address and session id + // must be setted these value. + for (i = 0; i < 6; i++) IINCHIP_WRITE((Sn_DHAR0(0)+i),mac[i]); + for (i = 0; i < 2; i++) IINCHIP_WRITE((Sn_DPORT0(0)+i),sessionid[i]); + isr = IINCHIP_READ(Sn_IR(0)); + IINCHIP_WRITE(Sn_IR(0),isr); + + //open socket in pppoe mode + IINCHIP_WRITE(Sn_MR(0),Sn_MR_PPPOE); + IINCHIP_WRITE(Sn_CR(0),Sn_CR_OPEN); + /* +20071122[chungs]:wait to process the command... */ + while( IINCHIP_READ(Sn_CR(0)) ) + ; + /* ------- */ + wait_1us(1); + // close pppoe connection + IINCHIP_WRITE(Sn_CR(0),Sn_CR_PDISCON); + /* +20071122[chungs]:wait to process the command... */ + while( IINCHIP_READ(Sn_CR(0)) ) + ; + /* ------- */ + wait_10ms(100); + // close socket + /* +200801 (hwkim) */ + close(0); + /* ------- */ + + +#ifdef __DEF_IINCHIP_DBG__ + printf("pppterm() end ..\r\n"); +#endif + + return 1; +} +#endif diff --git a/arduino-0018-linux/libraries/Ethernet/utility/w5100.h b/arduino-0018-linux/libraries/Ethernet/utility/w5100.h new file mode 100755 index 0000000..6eddf91 --- /dev/null +++ b/arduino-0018-linux/libraries/Ethernet/utility/w5100.h @@ -0,0 +1,299 @@ +/* +@file w5100.h +*/ + +#ifndef _W5100_H_ +#define _W5100_H_ + + +#define MR __DEF_IINCHIP_MAP_BASE__ +#define IDM_OR ((__DEF_IINCHIP_MAP_BASE__ + 0x00)) +#define IDM_AR0 ((__DEF_IINCHIP_MAP_BASE__ + 0x01)) +#define IDM_AR1 ((__DEF_IINCHIP_MAP_BASE__ + 0x02)) +#define IDM_DR ((__DEF_IINCHIP_MAP_BASE__ + 0x03)) + + +/** + @brief Gateway IP Register address + */ +#define GAR0 (COMMON_BASE + 0x0001) +/** + @brief Subnet mask Register address + */ +#define SUBR0 (COMMON_BASE + 0x0005) +/** + @brief Source MAC Register address + */ +#define SHAR0 (COMMON_BASE + 0x0009) +/** + @brief Source IP Register address + */ +#define SIPR0 (COMMON_BASE + 0x000F) +/** + @brief Interrupt Register + */ +#define IR (COMMON_BASE + 0x0015) +/** + @brief Interrupt mask register + */ +#define IMR (COMMON_BASE + 0x0016) +/** + @brief Timeout register address( 1 is 100us ) + */ +#define RTR0 (COMMON_BASE + 0x0017) +/** + @brief Retry count reigster + */ +#define RCR (COMMON_BASE + 0x0019) +/** + @brief Receive memory size reigster + */ +#define RMSR (COMMON_BASE + 0x001A) +/** + @brief Transmit memory size reigster + */ +#define TMSR (COMMON_BASE + 0x001B) +/** + @brief Authentication type register address in PPPoE mode + */ +#define PATR0 (COMMON_BASE + 0x001C) +//#define PPPALGO (COMMON_BASE + 0x001D) +#define PTIMER (COMMON_BASE + 0x0028) +#define PMAGIC (COMMON_BASE + 0x0029) + +/** + @brief Unreachable IP register address in UDP mode + */ +#define UIPR0 (COMMON_BASE + 0x002A) +/** + @brief Unreachable Port register address in UDP mode + */ +#define UPORT0 (COMMON_BASE + 0x002E) + +/** + @brief socket register +*/ +#define CH_BASE (COMMON_BASE + 0x0400) +/** + @brief size of each channel register map + */ +#define CH_SIZE 0x0100 +/** + @brief socket Mode register + */ +#define Sn_MR(ch) (CH_BASE + ch * CH_SIZE + 0x0000) +/** + @brief channel Sn_CR register + */ +#define Sn_CR(ch) (CH_BASE + ch * CH_SIZE + 0x0001) +/** + @brief channel interrupt register + */ +#define Sn_IR(ch) (CH_BASE + ch * CH_SIZE + 0x0002) +/** + @brief channel status register + */ +#define Sn_SR(ch) (CH_BASE + ch * CH_SIZE + 0x0003) +/** + @brief source port register + */ +#define Sn_PORT0(ch) (CH_BASE + ch * CH_SIZE + 0x0004) +/** + @brief Peer MAC register address + */ +#define Sn_DHAR0(ch) (CH_BASE + ch * CH_SIZE + 0x0006) +/** + @brief Peer IP register address + */ +#define Sn_DIPR0(ch) (CH_BASE + ch * CH_SIZE + 0x000C) +/** + @brief Peer port register address + */ +#define Sn_DPORT0(ch) (CH_BASE + ch * CH_SIZE + 0x0010) +/** + @brief Maximum Segment Size(Sn_MSSR0) register address + */ +#define Sn_MSSR0(ch) (CH_BASE + ch * CH_SIZE + 0x0012) +/** + @brief Protocol of IP Header field register in IP raw mode + */ +#define Sn_PROTO(ch) (CH_BASE + ch * CH_SIZE + 0x0014) + +/** + @brief IP Type of Service(TOS) Register + */ +#define Sn_TOS(ch) (CH_BASE + ch * CH_SIZE + 0x0015) +/** + @brief IP Time to live(TTL) Register + */ +#define Sn_TTL(ch) (CH_BASE + ch * CH_SIZE + 0x0016) + +/** + @brief Transmit free memory size register + */ +#define Sn_TX_FSR0(ch) (CH_BASE + ch * CH_SIZE + 0x0020) +/** + @brief Transmit memory read pointer register address + */ +#define Sn_TX_RD0(ch) (CH_BASE + ch * CH_SIZE + 0x0022) +/** + @brief Transmit memory write pointer register address + */ +#define Sn_TX_WR0(ch) (CH_BASE + ch * CH_SIZE + 0x0024) +/** + @brief Received data size register + */ +#define Sn_RX_RSR0(ch) (CH_BASE + ch * CH_SIZE + 0x0026) +/** + @brief Read point of Receive memory + */ +#define Sn_RX_RD0(ch) (CH_BASE + ch * CH_SIZE + 0x0028) +/** + @brief Write point of Receive memory + */ +#define Sn_RX_WR0(ch) (CH_BASE + ch * CH_SIZE + 0x002A) + + + +/* MODE register values */ +#define MR_RST 0x80 /**< reset */ +#define MR_PB 0x10 /**< ping block */ +#define MR_PPPOE 0x08 /**< enable pppoe */ +#define MR_LB 0x04 /**< little or big endian selector in indirect mode */ +#define MR_AI 0x02 /**< auto-increment in indirect mode */ +#define MR_IND 0x01 /**< enable indirect mode */ + +/* IR register values */ +#define IR_CONFLICT 0x80 /**< check ip confict */ +#define IR_UNREACH 0x40 /**< get the destination unreachable message in UDP sending */ +#define IR_PPPoE 0x20 /**< get the PPPoE close message */ +#define IR_SOCK(ch) (0x01 << ch) /**< check socket interrupt */ + +/* Sn_MR values */ +#define Sn_MR_CLOSE 0x00 /**< unused socket */ +#define Sn_MR_TCP 0x01 /**< TCP */ +#define Sn_MR_UDP 0x02 /**< UDP */ +#define Sn_MR_IPRAW 0x03 /**< IP LAYER RAW SOCK */ +#define Sn_MR_MACRAW 0x04 /**< MAC LAYER RAW SOCK */ +#define Sn_MR_PPPOE 0x05 /**< PPPoE */ +#define Sn_MR_ND 0x20 /**< No Delayed Ack(TCP) flag */ +#define Sn_MR_MULTI 0x80 /**< support multicating */ + + +/* Sn_CR values */ +#define Sn_CR_OPEN 0x01 /**< initialize or open socket */ +#define Sn_CR_LISTEN 0x02 /**< wait connection request in tcp mode(Server mode) */ +#define Sn_CR_CONNECT 0x04 /**< send connection request in tcp mode(Client mode) */ +#define Sn_CR_DISCON 0x08 /**< send closing reqeuset in tcp mode */ +#define Sn_CR_CLOSE 0x10 /**< close socket */ +#define Sn_CR_SEND 0x20 /**< updata txbuf pointer, send data */ +#define Sn_CR_SEND_MAC 0x21 /**< send data with MAC address, so without ARP process */ +#define Sn_CR_SEND_KEEP 0x22 /**< send keep alive message */ +#define Sn_CR_RECV 0x40 /**< update rxbuf pointer, recv data */ + +#ifdef __DEF_IINCHIP_PPP__ + #define Sn_CR_PCON 0x23 + #define Sn_CR_PDISCON 0x24 + #define Sn_CR_PCR 0x25 + #define Sn_CR_PCN 0x26 + #define Sn_CR_PCJ 0x27 +#endif + +/* Sn_IR values */ +#ifdef __DEF_IINCHIP_PPP__ + #define Sn_IR_PRECV 0x80 + #define Sn_IR_PFAIL 0x40 + #define Sn_IR_PNEXT 0x20 +#endif +#define Sn_IR_SEND_OK 0x10 /**< complete sending */ +#define Sn_IR_TIMEOUT 0x08 /**< assert timeout */ +#define Sn_IR_RECV 0x04 /**< receiving data */ +#define Sn_IR_DISCON 0x02 /**< closed socket */ +#define Sn_IR_CON 0x01 /**< established connection */ + +/* Sn_SR values */ +#define SOCK_CLOSED 0x00 /**< closed */ +#define SOCK_INIT 0x13 /**< init state */ +#define SOCK_LISTEN 0x14 /**< listen state */ +#define SOCK_SYNSENT 0x15 /**< connection state */ +#define SOCK_SYNRECV 0x16 /**< connection state */ +#define SOCK_ESTABLISHED 0x17 /**< success to connect */ +#define SOCK_FIN_WAIT 0x18 /**< closing state */ +#define SOCK_CLOSING 0x1A /**< closing state */ +#define SOCK_TIME_WAIT 0x1B /**< closing state */ +#define SOCK_CLOSE_WAIT 0x1C /**< closing state */ +#define SOCK_LAST_ACK 0x1D /**< closing state */ +#define SOCK_UDP 0x22 /**< udp socket */ +#define SOCK_IPRAW 0x32 /**< ip raw mode socket */ +#define SOCK_MACRAW 0x42 /**< mac raw mode socket */ +#define SOCK_PPPOE 0x5F /**< pppoe socket */ + +/* IP PROTOCOL */ +#define IPPROTO_IP 0 /**< Dummy for IP */ +#define IPPROTO_ICMP 1 /**< Control message protocol */ +#define IPPROTO_IGMP 2 /**< Internet group management protocol */ +#define IPPROTO_GGP 3 /**< Gateway^2 (deprecated) */ +#define IPPROTO_TCP 6 /**< TCP */ +#define IPPROTO_PUP 12 /**< PUP */ +#define IPPROTO_UDP 17 /**< UDP */ +#define IPPROTO_IDP 22 /**< XNS idp */ +#define IPPROTO_ND 77 /**< UNOFFICIAL net disk protocol */ +#define IPPROTO_RAW 255 /**< Raw IP packet */ + + +/********************************************************* +* iinchip access function +*********************************************************/ +extern uint8 IINCHIP_READ(uint16 addr); +extern uint8 IINCHIP_WRITE(uint16 addr,uint8 data); +extern uint16 wiz_read_buf(uint16 addr, uint8* buf,uint16 len); +extern uint16 wiz_write_buf(uint16 addr,uint8* buf,uint16 len); + +extern void iinchip_init(void); // reset iinchip +extern void sysinit(uint8 tx_size, uint8 rx_size); // setting tx/rx buf size +extern uint8 getISR(uint8 s); +extern void putISR(uint8 s, uint8 val); +extern uint16 getIINCHIP_RxMAX(uint8 s); +extern uint16 getIINCHIP_TxMAX(uint8 s); +extern uint16 getIINCHIP_RxMASK(uint8 s); +extern uint16 getIINCHIP_TxMASK(uint8 s); +extern uint16 getIINCHIP_RxBASE(uint8 s); +extern uint16 getIINCHIP_TxBASE(uint8 s); +extern void setGAR(uint8 * addr); // set gateway address +extern void setSUBR(uint8 * addr); // set subnet mask address +extern void setSHAR(uint8 * addr); // set local MAC address +extern void setSIPR(uint8 * addr); // set local IP address +extern void setRTR(uint16 timeout); // set retry duration for data transmission, connection, closing ... +extern void setRCR(uint8 retry); // set retry count (above the value, assert timeout interrupt) +extern void setIMR(uint8 mask); // set interrupt mask. +extern void getGAR(uint8 * addr); +extern void getSUBR(uint8 * addr); +extern void getSHAR(uint8 * addr); +extern void getSIPR(uint8 * addr); +extern uint8 getIR( void ); +extern void setSn_MSS(SOCKET s, uint16 Sn_MSSR0); // set maximum segment size +extern void setSn_PROTO(SOCKET s, uint8 proto); // set IP Protocol value using IP-Raw mode +extern uint8 getSn_IR(SOCKET s); // get socket interrupt status +extern uint8 getSn_SR(SOCKET s); // get socket status +extern uint16 getSn_TX_FSR(SOCKET s); // get socket TX free buf size +extern uint16 getSn_RX_RSR(SOCKET s); // get socket RX recv buf size +extern void setSn_DHAR(SOCKET s, uint8 * addr); +extern void setSn_DIPR(SOCKET s, uint8 * addr); +extern void setSn_DPORT(SOCKET s, uint8 * addr); +extern void getSn_DHAR(SOCKET s, uint8 * addr); +extern void getSn_DIPR(SOCKET s, uint8 * addr); +extern void getSn_DPORT(SOCKET s, uint8 * addr); +extern void setSn_TTL(SOCKET s, uint8 ttl); +extern void setMR(uint8 val); + +#ifdef __DEF_IINCHIP_PPP__ +extern uint8 pppinit(uint8 *id, uint8 idlen, uint8 *passwd, uint8 passwdlen); +extern uint8 pppterm(uint8 *mac,uint8 *sessionid); +#endif + +extern void send_data_processing(SOCKET s, uint8 *data, uint16 len); +extern void recv_data_processing(SOCKET s, uint8 *data, uint16 len); +extern void read_data(SOCKET s, vuint8 * src, vuint8 * dst, uint16 len); +extern void write_data(SOCKET s, vuint8 * src, vuint8 * dst, uint16 len); + +#endif diff --git a/arduino-0018-linux/libraries/Firmata/Firmata.cpp b/arduino-0018-linux/libraries/Firmata/Firmata.cpp new file mode 100644 index 0000000..ffaff4d --- /dev/null +++ b/arduino-0018-linux/libraries/Firmata/Firmata.cpp @@ -0,0 +1,442 @@ +/* + Firmata.cpp - Firmata library + Copyright (C) 2006-2008 Hans-Christoph Steiner. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + See file LICENSE.txt for further informations on licensing terms. +*/ + +//****************************************************************************** +//* Includes +//****************************************************************************** + +#include "WProgram.h" +#include "HardwareSerial.h" +#include "Firmata.h" + +extern "C" { +#include +#include +} + +//****************************************************************************** +//* Support Functions +//****************************************************************************** + +void sendValueAsTwo7bitBytes(int value) +{ + Serial.print(value & B01111111, BYTE); // LSB + Serial.print(value >> 7 & B01111111, BYTE); // MSB +} + +void startSysex(void) +{ + Serial.print(START_SYSEX, BYTE); +} + +void endSysex(void) +{ + Serial.print(END_SYSEX, BYTE); +} + +//****************************************************************************** +//* Constructors +//****************************************************************************** + +FirmataClass::FirmataClass(void) +{ + firmwareVersionCount = 0; + systemReset(); +} + +//****************************************************************************** +//* Public Methods +//****************************************************************************** + +/* begin method for overriding default serial bitrate */ +void FirmataClass::begin(void) +{ + begin(57600); +} + +/* begin method for overriding default serial bitrate */ +void FirmataClass::begin(long speed) +{ +#if defined(__AVR_ATmega128__) // Wiring + Serial.begin((uint32_t)speed); +#else + Serial.begin(speed); +#endif + blinkVersion(); + delay(300); + printVersion(); + printFirmwareVersion(); +} + +// output the protocol version message to the serial port +void FirmataClass::printVersion(void) { + Serial.print(REPORT_VERSION, BYTE); + Serial.print(FIRMATA_MAJOR_VERSION, BYTE); + Serial.print(FIRMATA_MINOR_VERSION, BYTE); +} + +void FirmataClass::blinkVersion(void) +{ + // flash the pin with the protocol version + pinMode(VERSION_BLINK_PIN,OUTPUT); + pin13strobe(FIRMATA_MAJOR_VERSION, 200, 400); + delay(300); + pin13strobe(2,1,4); // separator, a quick burst + delay(300); + pin13strobe(FIRMATA_MINOR_VERSION, 200, 400); +} + +void FirmataClass::printFirmwareVersion(void) +{ + byte i; + + if(firmwareVersionCount) { // make sure that the name has been set before reporting + startSysex(); + Serial.print(REPORT_FIRMWARE, BYTE); + Serial.print(firmwareVersionVector[0]); // major version number + Serial.print(firmwareVersionVector[1]); // minor version number + for(i=2; i 0) && (inputData < 128) ) { + waitForData--; + storedInputData[waitForData] = inputData; + if( (waitForData==0) && executeMultiByteCommand ) { // got the whole message + switch(executeMultiByteCommand) { + case ANALOG_MESSAGE: + if(currentAnalogCallback) { + (*currentAnalogCallback)(multiByteChannel, + (storedInputData[0] << 7) + + storedInputData[1]); + } + break; + case DIGITAL_MESSAGE: + if(currentDigitalCallback) { + (*currentDigitalCallback)(multiByteChannel, + (storedInputData[0] << 7) + + storedInputData[1]); + } + break; + case SET_PIN_MODE: + if(currentPinModeCallback) + (*currentPinModeCallback)(storedInputData[1], storedInputData[0]); + break; + case REPORT_ANALOG: + if(currentReportAnalogCallback) + (*currentReportAnalogCallback)(multiByteChannel,storedInputData[0]); + break; + case REPORT_DIGITAL: + if(currentReportDigitalCallback) + (*currentReportDigitalCallback)(multiByteChannel,storedInputData[0]); + break; + } + executeMultiByteCommand = 0; + } + } else { + // remove channel info from command byte if less than 0xF0 + if(inputData < 0xF0) { + command = inputData & 0xF0; + multiByteChannel = inputData & 0x0F; + } else { + command = inputData; + // commands in the 0xF* range don't use channel data + } + switch (command) { + case ANALOG_MESSAGE: + case DIGITAL_MESSAGE: + case SET_PIN_MODE: + waitForData = 2; // two data bytes needed + executeMultiByteCommand = command; + break; + case REPORT_ANALOG: + case REPORT_DIGITAL: + waitForData = 1; // two data bytes needed + executeMultiByteCommand = command; + break; + case START_SYSEX: + parsingSysex = true; + sysexBytesRead = 0; + break; + case SYSTEM_RESET: + systemReset(); + break; + case REPORT_VERSION: + Firmata.printVersion(); + break; + } + } +} + +//------------------------------------------------------------------------------ +// Serial Send Handling + +// send an analog message +void FirmataClass::sendAnalog(byte pin, int value) +{ + // pin can only be 0-15, so chop higher bits + Serial.print(ANALOG_MESSAGE | (pin & 0xF), BYTE); + sendValueAsTwo7bitBytes(value); +} + +// send a single digital pin in a digital message +void FirmataClass::sendDigital(byte pin, int value) +{ + /* TODO add single pin digital messages to the protocol, this needs to + * track the last digital data sent so that it can be sure to change just + * one bit in the packet. This is complicated by the fact that the + * numbering of the pins will probably differ on Arduino, Wiring, and + * other boards. The DIGITAL_MESSAGE sends 14 bits at a time, but it is + * probably easier to send 8 bit ports for any board with more than 14 + * digital pins. + */ + + // TODO: the digital message should not be sent on the serial port every + // time sendDigital() is called. Instead, it should add it to an int + // which will be sent on a schedule. If a pin changes more than once + // before the digital message is sent on the serial port, it should send a + // digital message for each change. + + // if(value == 0) + // sendDigitalPortPair(); +} + + +// send 14-bits in a single digital message (protocol v1) +// send an 8-bit port in a single digital message (protocol v2) +void FirmataClass::sendDigitalPort(byte portNumber, int portData) +{ + Serial.print(DIGITAL_MESSAGE | (portNumber & 0xF),BYTE); + Serial.print((byte)portData % 128, BYTE); // Tx bits 0-6 + Serial.print(portData >> 7, BYTE); // Tx bits 7-13 +} + + +void FirmataClass::sendSysex(byte command, byte bytec, byte* bytev) +{ + byte i; + startSysex(); + Serial.print(command, BYTE); + for(i=0; i +#include + + +/* Version numbers for the protocol. The protocol is still changing, so these + * version numbers are important. This number can be queried so that host + * software can test whether it will be compatible with the currently + * installed firmware. */ +#define FIRMATA_MAJOR_VERSION 2 // for non-compatible changes +#define FIRMATA_MINOR_VERSION 1 // for backwards compatible changes + +#define MAX_DATA_BYTES 32 // max number of data bytes in non-Sysex messages + +// message command bytes (128-255/0x80-0xFF) +#define DIGITAL_MESSAGE 0x90 // send data for a digital pin +#define ANALOG_MESSAGE 0xE0 // send data for an analog pin (or PWM) +#define REPORT_ANALOG 0xC0 // enable analog input by pin # +#define REPORT_DIGITAL 0xD0 // enable digital input by port pair +// +#define SET_PIN_MODE 0xF4 // set a pin to INPUT/OUTPUT/PWM/etc +// +#define REPORT_VERSION 0xF9 // report protocol version +#define SYSTEM_RESET 0xFF // reset from MIDI +// +#define START_SYSEX 0xF0 // start a MIDI Sysex message +#define END_SYSEX 0xF7 // end a MIDI Sysex message + +// extended command set using sysex (0-127/0x00-0x7F) +/* 0x00-0x0F reserved for user-defined commands */ +#define SERVO_CONFIG 0x70 // set max angle, minPulse, maxPulse, freq +#define STRING_DATA 0x71 // a string message with 14-bits per char +#define SHIFT_DATA 0x75 // a bitstream to/from a shift register +#define I2C_REQUEST 0x76 // send an I2C read/write request +#define I2C_REPLY 0x77 // a reply to an I2C read request +#define I2C_CONFIG 0x78 // config I2C settings such as delay times and power pins +#define REPORT_FIRMWARE 0x79 // report name and version of the firmware +#define SAMPLING_INTERVAL 0x7A // set the poll rate of the main loop +#define SYSEX_NON_REALTIME 0x7E // MIDI Reserved for non-realtime messages +#define SYSEX_REALTIME 0x7F // MIDI Reserved for realtime messages +// these are DEPRECATED to make the naming more consistent +#define FIRMATA_STRING 0x71 // same as STRING_DATA +#define SYSEX_I2C_REQUEST 0x76 // same as I2C_REQUEST +#define SYSEX_I2C_REPLY 0x77 // same as I2C_REPLY +#define SYSEX_SAMPLING_INTERVAL 0x7A // same as SAMPLING_INTERVAL + +// pin modes +//#define INPUT 0x00 // defined in wiring.h +//#define OUTPUT 0x01 // defined in wiring.h +#define ANALOG 0x02 // analog pin in analogInput mode +#define PWM 0x03 // digital pin in PWM output mode +#define SERVO 0x04 // digital pin in Servo output mode +#define SHIFT 0x05 // shiftIn/shiftOut mode +#define I2C 0x06 // pin included in I2C setup + +extern "C" { +// callback function types + typedef void (*callbackFunction)(byte, int); + typedef void (*systemResetCallbackFunction)(void); + typedef void (*stringCallbackFunction)(char*); + typedef void (*sysexCallbackFunction)(byte command, byte argc, byte*argv); +} + + +// TODO make it a subclass of a generic Serial/Stream base class +class FirmataClass +{ +public: + FirmataClass(); +/* Arduino constructors */ + void begin(); + void begin(long); +/* querying functions */ + void printVersion(void); + void blinkVersion(void); + void printFirmwareVersion(void); + //void setFirmwareVersion(byte major, byte minor); // see macro below + void setFirmwareNameAndVersion(const char *name, byte major, byte minor); +/* serial receive handling */ + int available(void); + void processInput(void); +/* serial send handling */ + void sendAnalog(byte pin, int value); + void sendDigital(byte pin, int value); // TODO implement this + void sendDigitalPort(byte portNumber, int portData); + void sendString(const char* string); + void sendString(byte command, const char* string); + void sendSysex(byte command, byte bytec, byte* bytev); +/* attach & detach callback functions to messages */ + void attach(byte command, callbackFunction newFunction); + void attach(byte command, systemResetCallbackFunction newFunction); + void attach(byte command, stringCallbackFunction newFunction); + void attach(byte command, sysexCallbackFunction newFunction); + void detach(byte command); + +private: +/* firmware name and version */ + byte firmwareVersionCount; + byte *firmwareVersionVector; +/* input message handling */ + byte waitForData; // this flag says the next serial input will be data + byte executeMultiByteCommand; // execute this after getting multi-byte data + byte multiByteChannel; // channel data for multiByteCommands + byte storedInputData[MAX_DATA_BYTES]; // multi-byte data +/* sysex */ + boolean parsingSysex; + int sysexBytesRead; +/* callback functions */ + callbackFunction currentAnalogCallback; + callbackFunction currentDigitalCallback; + callbackFunction currentReportAnalogCallback; + callbackFunction currentReportDigitalCallback; + callbackFunction currentPinModeCallback; + systemResetCallbackFunction currentSystemResetCallback; + stringCallbackFunction currentStringCallback; + sysexCallbackFunction currentSysexCallback; + +/* private methods ------------------------------ */ + void processSysexMessage(void); + void systemReset(void); + void pin13strobe(int count, int onInterval, int offInterval); +}; + +extern FirmataClass Firmata; + +/*============================================================================== + * MACROS + *============================================================================*/ + +/* shortcut for setFirmwareNameAndVersion() that uses __FILE__ to set the + * firmware name. It needs to be a macro so that __FILE__ is included in the + * firmware source file rather than the library source file. + */ +#define setFirmwareVersion(x, y) setFirmwareNameAndVersion(__FILE__, x, y) + +// total number of pins currently supported +#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) // Arduino NG and Diecimila +#define TOTAL_ANALOG_PINS 8 +#define TOTAL_DIGITAL_PINS 22 // 14 digital + 8 analog +#define TOTAL_PORTS 3 // total number of ports for the board +#define ANALOG_PORT 2 // port# of analog used as digital +#define FIRST_ANALOG_PIN 14 // pin# corresponding to analog 0 +#define VERSION_BLINK_PIN 13 // digital pin to blink version on +#define FIRST_SERVO_PIN 2 // pin# of the first servo pin +#elif defined(__AVR_ATmega8__) // old Arduinos +#define TOTAL_ANALOG_PINS 6 +#define TOTAL_DIGITAL_PINS 20 // 14 digital + 6 analog +#define TOTAL_PORTS 3 // total number of ports for the board +#define ANALOG_PORT 2 // port# of analog used as digital +#define FIRST_ANALOG_PIN 14 // pin# corresponding to analog 0 +#define VERSION_BLINK_PIN 13 // digital pin to blink version on +#define FIRST_SERVO_PIN 2 // pin# of the first servo pin +#elif defined(__AVR_ATmega1280__)// Arduino Mega +#define TOTAL_ANALOG_PINS 16 +#define TOTAL_DIGITAL_PINS 70 // 54 digital + 16 analog +#define TOTAL_PORTS 9 // total number of ports for the board +#define ANALOG_PORT 8 // port# of analog used as digital +#define FIRST_ANALOG_PIN 54 // pin# corresponding to analog 0 +#define VERSION_BLINK_PIN 13 // digital pin to blink version on +#define FIRST_SERVO_PIN 2 // pin# of the first servo pin +#elif defined(__AVR_ATmega128__)// Wiring +#define TOTAL_ANALOG_PINS 8 +#define TOTAL_DIGITAL_PINS 51 +#define TOTAL_PORTS 7 // total number of ports for the board +#define ANALOG_PORT 5 // port# of analog used as digital +#define FIRST_ANALOG_PIN 40 // pin# corresponding to analog 0 +#define VERSION_BLINK_PIN 48 // digital pin to blink version on +#define FIRST_SERVO_PIN 8 // pin# of the first servo pin +#elif defined(__AVR_AT90USB162__) // Teensy +#define TOTAL_ANALOG_PINS 0 +#define TOTAL_DIGITAL_PINS 21 // 21 digital + no analog +#define TOTAL_PORTS 4 // total number of ports for the board +#define ANALOG_PORT 3 // port# of analog used as digital +#define FIRST_ANALOG_PIN 21 // pin# corresponding to analog 0 +#define VERSION_BLINK_PIN 6 // digital pin to blink version on +#elif defined(__AVR_ATmega32U4__) // Teensy +#define TOTAL_ANALOG_PINS 12 +#define TOTAL_DIGITAL_PINS 25 // 11 digital + 12 analog +#define TOTAL_PORTS 4 // total number of ports for the board +#define ANALOG_PORT 3 // port# of analog used as digital +#define FIRST_ANALOG_PIN 11 // pin# corresponding to analog 0 +#define VERSION_BLINK_PIN 11 // digital pin to blink version on +#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) // Teensy++ +#define TOTAL_ANALOG_PINS 8 +#define TOTAL_DIGITAL_PINS 46 // 38 digital + 8 analog +#define TOTAL_PORTS 6 // total number of ports for the board +#define ANALOG_PORT 5 // port# of analog used as digital +#define FIRST_ANALOG_PIN 38 // pin# corresponding to analog 0 +#define VERSION_BLINK_PIN 6 // digital pin to blink version on +#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__) // Sanguino +#define TOTAL_ANALOG_PINS 8 +#define TOTAL_DIGITAL_PINS 32 // 24 digital + 8 analog +#define TOTAL_PORTS 4 // total number of ports for the board +#define ANALOG_PORT 3 // port# of analog used as digital +#define FIRST_ANALOG_PIN 24 // pin# corresponding to analog 0 +#define VERSION_BLINK_PIN 0 // digital pin to blink version on +#elif defined(__AVR_ATmega645__) // Illuminato +#define TOTAL_ANALOG_PINS 6 +#define TOTAL_DIGITAL_PINS 42 // 36 digital + 6 analog +#define TOTAL_PORTS 6 // total number of ports for the board +#define ANALOG_PORT 4 // port# of analog used as digital +#define FIRST_ANALOG_PIN 36 // pin# corresponding to analog 0 +#define VERSION_BLINK_PIN 13 // digital pin to blink version on +#else // anything else +#define TOTAL_ANALOG_PINS 6 +#define TOTAL_DIGITAL_PINS 14 +#define TOTAL_PORTS 3 // total number of ports for the board +#define ANALOG_PORT 2 // port# of analog used as digital +#define FIRST_ANALOG_PIN 14 // pin# corresponding to analog 0 +#define VERSION_BLINK_PIN 13 // digital pin to blink version on +#endif + + + +#endif /* Firmata_h */ + diff --git a/arduino-0018-linux/libraries/Firmata/LICENSE.txt b/arduino-0018-linux/libraries/Firmata/LICENSE.txt new file mode 100644 index 0000000..77cec6d --- /dev/null +++ b/arduino-0018-linux/libraries/Firmata/LICENSE.txt @@ -0,0 +1,458 @@ + + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + diff --git a/arduino-0018-linux/libraries/Firmata/TODO.txt b/arduino-0018-linux/libraries/Firmata/TODO.txt new file mode 100644 index 0000000..86c9858 --- /dev/null +++ b/arduino-0018-linux/libraries/Firmata/TODO.txt @@ -0,0 +1,14 @@ + +- make Firmata a subclass of HardwareSerial + +- per-pin digital callback, since the per-port callback is a bit complicated + for beginners (maybe Firmata is not for beginners...) + +- simplify SimpleDigitalFirmata, take out the code that checks to see if the + data has changed, since it is a bit complicated for this example. Ideally + this example would be based on a call + +- turn current SimpleDigitalFirmata into DigitalPortFirmata for a more complex + example using the code which checks for changes before doing anything + +- test integration with Wiring diff --git a/arduino-0018-linux/libraries/Firmata/examples/AllInputsFirmata/AllInputsFirmata.pde b/arduino-0018-linux/libraries/Firmata/examples/AllInputsFirmata/AllInputsFirmata.pde new file mode 100644 index 0000000..cd50791 --- /dev/null +++ b/arduino-0018-linux/libraries/Firmata/examples/AllInputsFirmata/AllInputsFirmata.pde @@ -0,0 +1,71 @@ +/* + * This firmware reads all inputs and sends them as fast as it can. It was + * inspired by the ease-of-use of the Arduino2Max program. + * + * This example code is in the public domain. + */ +#include + +byte pin; + +int analogValue; +int previousAnalogValues[TOTAL_ANALOG_PINS]; + +byte portStatus[TOTAL_PORTS]; +byte previousPINs[TOTAL_PORTS]; + +/* timer variables */ +unsigned long currentMillis; // store the current value from millis() +unsigned long nextExecuteMillis; // for comparison with currentMillis +/* make sure that the FTDI buffer doesn't go over 60 bytes, otherwise you + get long, random delays. So only read analogs every 20ms or so */ +int samplingInterval = 19; // how often to run the main loop (in ms) + +void sendPort(byte portNumber, byte portValue) +{ + portValue = portValue &~ portStatus[portNumber]; + if(previousPINs[portNumber] != portValue) { + Firmata.sendDigitalPort(portNumber, portValue); + previousPINs[portNumber] = portValue; + } +} + +void setup() +{ + Firmata.setFirmwareVersion(0, 1); + + for(pin = 0; pin < TOTAL_DIGITAL_PINS; pin++) { + pinMode(pin, INPUT); + } + + portStatus[0] = B00000011; // ignore Tx/RX pins + portStatus[1] = B11000000; // ignore 14/15 pins + portStatus[2] = B00000000; + + Firmata.begin(57600); +} + +void loop() +{ + sendPort(0, PIND); + sendPort(1, PINB); + sendPort(2, PINC); + /* make sure that the FTDI buffer doesn't go over 60 bytes, otherwise you + get long, random delays. So only read analogs every 20ms or so */ + currentMillis = millis(); + if(currentMillis > nextExecuteMillis) { + nextExecuteMillis = currentMillis + samplingInterval; + while(Firmata.available()) { + Firmata.processInput(); + } + for(pin = 0; pin < TOTAL_ANALOG_PINS; pin++) { + analogValue = analogRead(pin); + if(analogValue != previousAnalogValues[pin]) { + Firmata.sendAnalog(pin, analogValue); + previousAnalogValues[pin] = analogValue; + } + } + } +} + + diff --git a/arduino-0018-linux/libraries/Firmata/examples/AnalogFirmata/AnalogFirmata.pde b/arduino-0018-linux/libraries/Firmata/examples/AnalogFirmata/AnalogFirmata.pde new file mode 100644 index 0000000..ab83726 --- /dev/null +++ b/arduino-0018-linux/libraries/Firmata/examples/AnalogFirmata/AnalogFirmata.pde @@ -0,0 +1,83 @@ +/* This firmware supports as many analog ports as possible, all analog inputs, + * four PWM outputs, and two with servo support. + * + * This example code is in the public domain. + */ +#include +#include + +/*============================================================================== + * GLOBAL VARIABLES + *============================================================================*/ + +/* servos */ +Servo servo9, servo10; // one instance per pin +/* analog inputs */ +int analogInputsToReport = 0; // bitwise array to store pin reporting +int analogPin = 0; // counter for reading analog pins +/* timer variables */ +unsigned long currentMillis; // store the current value from millis() +unsigned long nextExecuteMillis; // for comparison with currentMillis + + +/*============================================================================== + * FUNCTIONS + *============================================================================*/ + +void analogWriteCallback(byte pin, int value) +{ + switch(pin) { + case 9: servo9.write(value); break; + case 10: servo10.write(value); break; + case 3: + case 5: + case 6: + case 11: // PWM pins + analogWrite(pin, value); + break; + } +} +// ----------------------------------------------------------------------------- +// sets bits in a bit array (int) to toggle the reporting of the analogIns +void reportAnalogCallback(byte pin, int value) +{ + if(value == 0) { + analogInputsToReport = analogInputsToReport &~ (1 << pin); + } + else { // everything but 0 enables reporting of that pin + analogInputsToReport = analogInputsToReport | (1 << pin); + } + // TODO: save status to EEPROM here, if changed +} + +/*============================================================================== + * SETUP() + *============================================================================*/ +void setup() +{ + Firmata.setFirmwareVersion(0, 2); + Firmata.attach(ANALOG_MESSAGE, analogWriteCallback); + Firmata.attach(REPORT_ANALOG, reportAnalogCallback); + + servo9.attach(9); + servo10.attach(10); + Firmata.begin(57600); +} + +/*============================================================================== + * LOOP() + *============================================================================*/ +void loop() +{ + while(Firmata.available()) + Firmata.processInput(); + currentMillis = millis(); + if(currentMillis > nextExecuteMillis) { + nextExecuteMillis = currentMillis + 19; // run this every 20ms + for(analogPin=0;analogPin +# +# - Write prototypes for all your functions (or define them before you +# call them). A prototype declares the types of parameters a +# function will take and what type of value it will return. This +# means that you can have a call to a function before the definition +# of the function. A function prototype looks like the first line of +# the function, with a semi-colon at the end. For example: +# int digitalRead(int pin); +# +# Instructions for using the makefile: +# +# 1. Copy this file into the folder with your sketch. +# +# 2. Below, modify the line containing "TARGET" to refer to the name of +# of your program's file without an extension (e.g. TARGET = foo). +# +# 3. Modify the line containg "ARDUINO" to point the directory that +# contains the Arduino core (for normal Arduino installations, this +# is the hardware/cores/arduino sub-directory). +# +# 4. Modify the line containing "PORT" to refer to the filename +# representing the USB or serial connection to your Arduino board +# (e.g. PORT = /dev/tty.USB0). If the exact name of this file +# changes, you can use * as a wildcard (e.g. PORT = /dev/tty.USB*). +# +# 5. At the command line, change to the directory containing your +# program's file and the makefile. +# +# 6. Type "make" and press enter to compile/verify your program. +# +# 7. Type "make upload", reset your Arduino board, and press enter to +# upload your program to the Arduino board. +# +# $Id: Makefile,v 1.7 2007/04/13 05:28:23 eighthave Exp $ + +PORT = /dev/tty.usbserial-* +TARGET := $(shell pwd | sed 's|.*/\(.*\)|\1|') +ARDUINO = /Applications/arduino +ARDUINO_SRC = $(ARDUINO)/hardware/cores/arduino +ARDUINO_LIB_SRC = $(ARDUINO)/hardware/libraries +INCLUDE = -I$(ARDUINO_SRC) -I$(ARDUINO)/hardware/tools/avr/avr/include \ + -I$(ARDUINO_LIB_SRC)/EEPROM \ + -I$(ARDUINO_LIB_SRC)/Firmata \ + -I$(ARDUINO_LIB_SRC)/Servo \ + -I$(ARDUINO_LIB_SRC) +SRC = $(wildcard $(ARDUINO_SRC)/*.c) +CXXSRC = applet/$(TARGET).cpp $(ARDUINO_SRC)/HardwareSerial.cpp \ + $(ARDUINO_LIB_SRC)/EEPROM/EEPROM.cpp \ + $(ARDUINO_LIB_SRC)/Firmata/Firmata.cpp \ + $(ARDUINO_LIB_SRC)/Servo/Servo.cpp \ + $(ARDUINO_SRC)/WMath.cpp +HEADERS = $(wildcard $(ARDUINO_SRC)/*.h) $(wildcard $(ARDUINO_LIB_SRC)/*/*.h) + +MCU = atmega168 +#MCU = atmega8 +F_CPU = 16000000 +FORMAT = ihex +UPLOAD_RATE = 19200 + +# Name of this Makefile (used for "make depend"). +MAKEFILE = Makefile + +# Debugging format. +# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2. +# AVR (extended) COFF requires stabs, plus an avr-objcopy run. +DEBUG = stabs + +OPT = s + +# Place -D or -U options here +CDEFS = -DF_CPU=$(F_CPU) +CXXDEFS = -DF_CPU=$(F_CPU) + +# Compiler flag to set the C Standard level. +# c89 - "ANSI" C +# gnu89 - c89 plus GCC extensions +# c99 - ISO C99 standard (not yet fully implemented) +# gnu99 - c99 plus GCC extensions +CSTANDARD = -std=gnu99 +CDEBUG = -g$(DEBUG) +CWARN = -Wall -Wstrict-prototypes +CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums +#CEXTRA = -Wa,-adhlns=$(<:.c=.lst) + +CFLAGS = $(CDEBUG) $(CDEFS) $(INCLUDE) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA) +CXXFLAGS = $(CDEFS) $(INCLUDE) -O$(OPT) +#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs +LDFLAGS = + + +# Programming support using avrdude. Settings and variables. +AVRDUDE_PROGRAMMER = stk500 +AVRDUDE_PORT = $(PORT) +AVRDUDE_WRITE_FLASH = -U flash:w:applet/$(TARGET).hex +AVRDUDE_FLAGS = -F -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \ + -b $(UPLOAD_RATE) -q -V + +# Program settings +CC = avr-gcc +CXX = avr-g++ +OBJCOPY = avr-objcopy +OBJDUMP = avr-objdump +SIZE = avr-size +NM = avr-nm +AVRDUDE = avrdude +REMOVE = rm -f +MV = mv -f + +# Define all object files. +OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o) + +# Define all listing files. +LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst) + +# Combine all necessary flags and optional flags. +# Add target processor to flags. +ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) +ALL_CXXFLAGS = -mmcu=$(MCU) -I. $(CXXFLAGS) +ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) + + +# Default target. +all: build + +build: applet/$(TARGET).hex + +eep: applet/$(TARGET).eep +lss: applet/$(TARGET).lss +sym: applet/$(TARGET).sym + + +# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. +COFFCONVERT=$(OBJCOPY) --debugging \ +--change-section-address .data-0x800000 \ +--change-section-address .bss-0x800000 \ +--change-section-address .noinit-0x800000 \ +--change-section-address .eeprom-0x810000 + + +coff: applet/$(TARGET).elf + $(COFFCONVERT) -O coff-avr applet/$(TARGET).elf applet/$(TARGET).cof + + +extcoff: applet/$(TARGET).elf + $(COFFCONVERT) -O coff-ext-avr applet/$(TARGET).elf applet/$(TARGET).cof + + +.SUFFIXES: .elf .hex .eep .lss .sym .pde + +.elf.hex: + $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ + +.elf.eep: + -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ + --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ + +# Create extended listing file from ELF output file. +.elf.lss: + $(OBJDUMP) -h -S $< > $@ + +# Create a symbol table from ELF output file. +.elf.sym: + $(NM) -n $< > $@ + + +# Compile: create object files from C++ source files. +.cpp.o: $(HEADERS) + $(CXX) -c $(ALL_CXXFLAGS) $< -o $@ + +# Compile: create object files from C source files. +.c.o: $(HEADERS) + $(CC) -c $(ALL_CFLAGS) $< -o $@ + + +# Compile: create assembler files from C source files. +.c.s: + $(CC) -S $(ALL_CFLAGS) $< -o $@ + + +# Assemble: create object files from assembler source files. +.S.o: + $(CC) -c $(ALL_ASFLAGS) $< -o $@ + + + +applet/$(TARGET).cpp: $(TARGET).pde + test -d applet || mkdir applet + echo '#include "WProgram.h"' > applet/$(TARGET).cpp + echo '#include "avr/interrupt.h"' >> applet/$(TARGET).cpp + sed -n 's|^\(void .*)\).*|\1;|p' $(TARGET).pde | grep -v 'setup()' | \ + grep -v 'loop()' >> applet/$(TARGET).cpp + cat $(TARGET).pde >> applet/$(TARGET).cpp + cat $(ARDUINO_SRC)/main.cxx >> applet/$(TARGET).cpp + +# Link: create ELF output file from object files. +applet/$(TARGET).elf: applet/$(TARGET).cpp $(OBJ) + $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS) + +pd_close_serial: + echo 'close;' | /Applications/Pd-extended.app/Contents/Resources/bin/pdsend 34567 || true + +# Program the device. +upload: applet/$(TARGET).hex + $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) + + +pd_test: build pd_close_serial upload + +# Target: clean project. +clean: + $(REMOVE) -- applet/$(TARGET).hex applet/$(TARGET).eep \ + applet/$(TARGET).cof applet/$(TARGET).elf $(TARGET).map \ + applet/$(TARGET).sym applet/$(TARGET).lss applet/$(TARGET).cpp \ + $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d) + rmdir -- applet + +depend: + if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \ + then \ + sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \ + $(MAKEFILE).$$$$ && \ + $(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \ + fi + echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \ + >> $(MAKEFILE); \ + $(CC) -M -mmcu=$(MCU) $(CDEFS) $(INCLUDE) $(SRC) $(ASRC) >> $(MAKEFILE) + +.PHONY: all build eep lss sym coff extcoff clean depend pd_close_serial pd_test + +# for emacs +etags: + make etags_`uname -s` + etags *.pde \ + $(ARDUINO_SRC)/*.[ch] \ + $(ARDUINO_SRC)/*.cpp \ + $(ARDUINO_LIB_SRC)/*/*.[ch] \ + $(ARDUINO_LIB_SRC)/*/*.cpp \ + $(ARDUINO)/hardware/tools/avr/avr/include/avr/*.[ch] \ + $(ARDUINO)/hardware/tools/avr/avr/include/*.[ch] + +etags_Darwin: +# etags -a + +etags_Linux: +# etags -a /usr/include/*.h linux/input.h /usr/include/sys/*.h + +etags_MINGW: +# etags -a /usr/include/*.h /usr/include/sys/*.h + + + diff --git a/arduino-0018-linux/libraries/Firmata/examples/EchoString/EchoString.pde b/arduino-0018-linux/libraries/Firmata/examples/EchoString/EchoString.pde new file mode 100644 index 0000000..6559ae1 --- /dev/null +++ b/arduino-0018-linux/libraries/Firmata/examples/EchoString/EchoString.pde @@ -0,0 +1,40 @@ +/* This sketch accepts strings and raw sysex messages and echos them back. + * + * This example code is in the public domain. + */ +#include + +byte analogPin; + +void stringCallback(char *myString) +{ + Firmata.sendString(myString); +} + + +void sysexCallback(byte command, byte argc, byte*argv) +{ + Serial.print(START_SYSEX, BYTE); + Serial.print(command, BYTE); + for(byte i=0; i +# +# - Write prototypes for all your functions (or define them before you +# call them). A prototype declares the types of parameters a +# function will take and what type of value it will return. This +# means that you can have a call to a function before the definition +# of the function. A function prototype looks like the first line of +# the function, with a semi-colon at the end. For example: +# int digitalRead(int pin); +# +# Instructions for using the makefile: +# +# 1. Copy this file into the folder with your sketch. +# +# 2. Below, modify the line containing "TARGET" to refer to the name of +# of your program's file without an extension (e.g. TARGET = foo). +# +# 3. Modify the line containg "ARDUINO" to point the directory that +# contains the Arduino core (for normal Arduino installations, this +# is the hardware/cores/arduino sub-directory). +# +# 4. Modify the line containing "PORT" to refer to the filename +# representing the USB or serial connection to your Arduino board +# (e.g. PORT = /dev/tty.USB0). If the exact name of this file +# changes, you can use * as a wildcard (e.g. PORT = /dev/tty.USB*). +# +# 5. At the command line, change to the directory containing your +# program's file and the makefile. +# +# 6. Type "make" and press enter to compile/verify your program. +# +# 7. Type "make upload", reset your Arduino board, and press enter to +# upload your program to the Arduino board. +# +# $Id: Makefile,v 1.7 2007/04/13 05:28:23 eighthave Exp $ + +PORT = /dev/tty.usbserial-* +TARGET := $(shell pwd | sed 's|.*/\(.*\)|\1|') +ARDUINO = /Applications/arduino +ARDUINO_SRC = $(ARDUINO)/hardware/cores/arduino +ARDUINO_LIB_SRC = $(ARDUINO)/hardware/libraries +INCLUDE = -I$(ARDUINO_SRC) -I$(ARDUINO)/hardware/tools/avr/avr/include \ + -I$(ARDUINO_LIB_SRC)/EEPROM \ + -I$(ARDUINO_LIB_SRC)/Firmata \ + -I$(ARDUINO_LIB_SRC)/Servo \ + -I$(ARDUINO_LIB_SRC) +SRC = $(wildcard $(ARDUINO_SRC)/*.c) +CXXSRC = applet/$(TARGET).cpp $(ARDUINO_SRC)/HardwareSerial.cpp \ + $(ARDUINO_LIB_SRC)/EEPROM/EEPROM.cpp \ + $(ARDUINO_LIB_SRC)/Firmata/Firmata.cpp \ + $(ARDUINO_LIB_SRC)/Servo/Servo.cpp \ + $(ARDUINO_SRC)/WMath.cpp +HEADERS = $(wildcard $(ARDUINO_SRC)/*.h) $(wildcard $(ARDUINO_LIB_SRC)/*/*.h) + +MCU = atmega168 +#MCU = atmega8 +F_CPU = 16000000 +FORMAT = ihex +UPLOAD_RATE = 19200 + +# Name of this Makefile (used for "make depend"). +MAKEFILE = Makefile + +# Debugging format. +# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2. +# AVR (extended) COFF requires stabs, plus an avr-objcopy run. +DEBUG = stabs + +OPT = s + +# Place -D or -U options here +CDEFS = -DF_CPU=$(F_CPU) +CXXDEFS = -DF_CPU=$(F_CPU) + +# Compiler flag to set the C Standard level. +# c89 - "ANSI" C +# gnu89 - c89 plus GCC extensions +# c99 - ISO C99 standard (not yet fully implemented) +# gnu99 - c99 plus GCC extensions +CSTANDARD = -std=gnu99 +CDEBUG = -g$(DEBUG) +CWARN = -Wall -Wstrict-prototypes +CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums +#CEXTRA = -Wa,-adhlns=$(<:.c=.lst) + +CFLAGS = $(CDEBUG) $(CDEFS) $(INCLUDE) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA) +CXXFLAGS = $(CDEFS) $(INCLUDE) -O$(OPT) +#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs +LDFLAGS = + + +# Programming support using avrdude. Settings and variables. +AVRDUDE_PROGRAMMER = stk500 +AVRDUDE_PORT = $(PORT) +AVRDUDE_WRITE_FLASH = -U flash:w:applet/$(TARGET).hex +AVRDUDE_FLAGS = -F -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \ + -b $(UPLOAD_RATE) -q -V + +# Program settings +CC = avr-gcc +CXX = avr-g++ +OBJCOPY = avr-objcopy +OBJDUMP = avr-objdump +SIZE = avr-size +NM = avr-nm +AVRDUDE = avrdude +REMOVE = rm -f +MV = mv -f + +# Define all object files. +OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o) + +# Define all listing files. +LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst) + +# Combine all necessary flags and optional flags. +# Add target processor to flags. +ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) +ALL_CXXFLAGS = -mmcu=$(MCU) -I. $(CXXFLAGS) +ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) + + +# Default target. +all: build + +build: applet/$(TARGET).hex + +eep: applet/$(TARGET).eep +lss: applet/$(TARGET).lss +sym: applet/$(TARGET).sym + + +# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. +COFFCONVERT=$(OBJCOPY) --debugging \ +--change-section-address .data-0x800000 \ +--change-section-address .bss-0x800000 \ +--change-section-address .noinit-0x800000 \ +--change-section-address .eeprom-0x810000 + + +coff: applet/$(TARGET).elf + $(COFFCONVERT) -O coff-avr applet/$(TARGET).elf applet/$(TARGET).cof + + +extcoff: applet/$(TARGET).elf + $(COFFCONVERT) -O coff-ext-avr applet/$(TARGET).elf applet/$(TARGET).cof + + +.SUFFIXES: .elf .hex .eep .lss .sym .pde + +.elf.hex: + $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ + +.elf.eep: + -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ + --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ + +# Create extended listing file from ELF output file. +.elf.lss: + $(OBJDUMP) -h -S $< > $@ + +# Create a symbol table from ELF output file. +.elf.sym: + $(NM) -n $< > $@ + + +# Compile: create object files from C++ source files. +.cpp.o: $(HEADERS) + $(CXX) -c $(ALL_CXXFLAGS) $< -o $@ + +# Compile: create object files from C source files. +.c.o: $(HEADERS) + $(CC) -c $(ALL_CFLAGS) $< -o $@ + + +# Compile: create assembler files from C source files. +.c.s: + $(CC) -S $(ALL_CFLAGS) $< -o $@ + + +# Assemble: create object files from assembler source files. +.S.o: + $(CC) -c $(ALL_ASFLAGS) $< -o $@ + + + +applet/$(TARGET).cpp: $(TARGET).pde + test -d applet || mkdir applet + echo '#include "WProgram.h"' > applet/$(TARGET).cpp + echo '#include "avr/interrupt.h"' >> applet/$(TARGET).cpp + sed -n 's|^\(void .*)\).*|\1;|p' $(TARGET).pde | grep -v 'setup()' | \ + grep -v 'loop()' >> applet/$(TARGET).cpp + cat $(TARGET).pde >> applet/$(TARGET).cpp + cat $(ARDUINO_SRC)/main.cxx >> applet/$(TARGET).cpp + +# Link: create ELF output file from object files. +applet/$(TARGET).elf: applet/$(TARGET).cpp $(OBJ) + $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS) + +pd_close_serial: + echo 'close;' | /Applications/Pd-extended.app/Contents/Resources/bin/pdsend 34567 || true + +# Program the device. +upload: applet/$(TARGET).hex + $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) + + +pd_test: build pd_close_serial upload + +# Target: clean project. +clean: + $(REMOVE) -- applet/$(TARGET).hex applet/$(TARGET).eep \ + applet/$(TARGET).cof applet/$(TARGET).elf $(TARGET).map \ + applet/$(TARGET).sym applet/$(TARGET).lss applet/$(TARGET).cpp \ + $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d) + rmdir -- applet + +depend: + if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \ + then \ + sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \ + $(MAKEFILE).$$$$ && \ + $(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \ + fi + echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \ + >> $(MAKEFILE); \ + $(CC) -M -mmcu=$(MCU) $(CDEFS) $(INCLUDE) $(SRC) $(ASRC) >> $(MAKEFILE) + +.PHONY: all build eep lss sym coff extcoff clean depend pd_close_serial pd_test + +# for emacs +etags: + make etags_`uname -s` + etags *.pde \ + $(ARDUINO_SRC)/*.[ch] \ + $(ARDUINO_SRC)/*.cpp \ + $(ARDUINO_LIB_SRC)/*/*.[ch] \ + $(ARDUINO_LIB_SRC)/*/*.cpp \ + $(ARDUINO)/hardware/tools/avr/avr/include/avr/*.[ch] \ + $(ARDUINO)/hardware/tools/avr/avr/include/*.[ch] + +etags_Darwin: +# etags -a + +etags_Linux: +# etags -a /usr/include/*.h linux/input.h /usr/include/sys/*.h + +etags_MINGW: +# etags -a /usr/include/*.h /usr/include/sys/*.h + + + diff --git a/arduino-0018-linux/libraries/Firmata/examples/I2CFirmata/I2CFirmata.pde b/arduino-0018-linux/libraries/Firmata/examples/I2CFirmata/I2CFirmata.pde new file mode 100644 index 0000000..796a8d5 --- /dev/null +++ b/arduino-0018-linux/libraries/Firmata/examples/I2CFirmata/I2CFirmata.pde @@ -0,0 +1,217 @@ +/* + Copyright (C) 2009 Jeff Hoefs. All rights reserved. + Copyright (C) 2009 Shigeru Kobayashi. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + See file LICENSE.txt for further informations on licensing terms. + */ + +#include +#include + + +#define I2C_WRITE B00000000 +#define I2C_READ B00001000 +#define I2C_READ_CONTINUOUSLY B00010000 +#define I2C_STOP_READING B00011000 +#define I2C_READ_WRITE_MODE_MASK B00011000 + +#define MAX_QUERIES 8 + +unsigned long currentMillis; // store the current value from millis() +unsigned long nextExecuteMillis; // for comparison with currentMillis +unsigned int samplingInterval = 32; // default sampling interval is 33ms +unsigned int i2cReadDelayTime = 0; // default delay time between i2c read request and Wire.requestFrom() +unsigned int powerPinsEnabled = 0; // use as boolean to prevent enablePowerPins from being called more than once + +#define MINIMUM_SAMPLING_INTERVAL 10 + +#define REGISTER_NOT_SPECIFIED -1 + +struct i2c_device_info { + byte addr; + byte reg; + byte bytes; +}; + +i2c_device_info query[MAX_QUERIES]; + +byte i2cRxData[32]; +boolean readingContinuously = false; +byte queryIndex = 0; + +void readAndReportData(byte address, int theRegister, byte numBytes) +{ + if (theRegister != REGISTER_NOT_SPECIFIED) { + Wire.beginTransmission(address); + Wire.send((byte)theRegister); + Wire.endTransmission(); + delayMicroseconds(i2cReadDelayTime); // delay is necessary for some devices such as WiiNunchuck + } + else { + theRegister = 0; // fill the register with a dummy value + } + + Wire.requestFrom(address, numBytes); + + // check to be sure correct number of bytes were returned by slave + if(numBytes == Wire.available()) { + i2cRxData[0] = address; + i2cRxData[1] = theRegister; + for (int i = 0; i < numBytes; i++) { + i2cRxData[2 + i] = Wire.receive(); + } + // send slave address, register and received bytes + Firmata.sendSysex(I2C_REPLY, numBytes + 2, i2cRxData); + } + else { + if(numBytes > Wire.available()) { + Firmata.sendString("I2C Read Error: Too many bytes received"); + } else { + Firmata.sendString("I2C Read Error: Too few bytes received"); + } + } + +} + +void sysexCallback(byte command, byte argc, byte *argv) +{ + byte mode; + byte slaveAddress; + byte slaveRegister; + byte data; + int delayTime; + + if (command == I2C_REQUEST) { + mode = argv[1] & I2C_READ_WRITE_MODE_MASK; + slaveAddress = argv[0]; + + switch(mode) { + case I2C_WRITE: + Wire.beginTransmission(slaveAddress); + for (byte i = 2; i < argc; i += 2) { + data = argv[i] + (argv[i + 1] << 7); + Wire.send(data); + } + Wire.endTransmission(); + delayMicroseconds(70); // TODO is this needed? + break; + case I2C_READ: + if (argc == 6) { + // a slave register is specified + slaveRegister = argv[2] + (argv[3] << 7); + data = argv[4] + (argv[5] << 7); // bytes to read + readAndReportData(slaveAddress, (int)slaveRegister, data); + } + else { + // a slave register is NOT specified + data = argv[2] + (argv[3] << 7); // bytes to read + readAndReportData(slaveAddress, (int)REGISTER_NOT_SPECIFIED, data); + } + break; + case I2C_READ_CONTINUOUSLY: + if ((queryIndex + 1) >= MAX_QUERIES) { + // too many queries, just ignore + Firmata.sendString("too many queries"); + break; + } + query[queryIndex].addr = slaveAddress; + query[queryIndex].reg = argv[2] + (argv[3] << 7); + query[queryIndex].bytes = argv[4] + (argv[5] << 7); + readingContinuously = true; + queryIndex++; + break; + case I2C_STOP_READING: + readingContinuously = false; + queryIndex = 0; + break; + default: + break; + } + } + else if (command == SAMPLING_INTERVAL) { + samplingInterval = argv[0] + (argv[1] << 7); + + if (samplingInterval < MINIMUM_SAMPLING_INTERVAL) { + samplingInterval = MINIMUM_SAMPLING_INTERVAL; + } + + samplingInterval -= 1; + Firmata.sendString("sampling interval"); + } + + else if (command == I2C_CONFIG) { + delayTime = (argv[4] + (argv[5] << 7)); // MSB + delayTime = (delayTime << 8) + (argv[2] + (argv[3] << 7)); // add LSB + + if((argv[0] + (argv[1] << 7)) > 0) { + enablePowerPins(PORTC3, PORTC2); + } + + if(delayTime > 0) { + i2cReadDelayTime = delayTime; + } + + if(argc > 6) { + // If you extend I2C_Config, handle your data here + } + + } +} + +void systemResetCallback() +{ + readingContinuously = false; + queryIndex = 0; +} + +/* reference: BlinkM_funcs.h by Tod E. Kurt, ThingM, http://thingm.com/ */ +// Enables Pins A2 and A3 to be used as GND and Power +// so that I2C devices can be plugged directly +// into Arduino header (pins A2 - A5) +static void enablePowerPins(byte pwrpin, byte gndpin) +{ + if(powerPinsEnabled == 0) { + DDRC |= _BV(pwrpin) | _BV(gndpin); + PORTC &=~ _BV(gndpin); + PORTC |= _BV(pwrpin); + powerPinsEnabled = 1; + Firmata.sendString("Power pins enabled"); + delay(100); + } +} + +void setup() +{ + Firmata.setFirmwareVersion(2, 0); + + Firmata.attach(START_SYSEX, sysexCallback); + Firmata.attach(SYSTEM_RESET, systemResetCallback); + + for (int i = 0; i < TOTAL_DIGITAL_PINS; ++i) { + pinMode(i, OUTPUT); + } + + Firmata.begin(57600); + Wire.begin(); +} + +void loop() +{ + while (Firmata.available()) { + Firmata.processInput(); + } + + currentMillis = millis(); + if (currentMillis > nextExecuteMillis) { + nextExecuteMillis = currentMillis + samplingInterval; + + for (byte i = 0; i < queryIndex; i++) { + readAndReportData(query[i].addr, query[i].reg, query[i].bytes); + } + } +} diff --git a/arduino-0018-linux/libraries/Firmata/examples/OldStandardFirmata/LICENSE.txt b/arduino-0018-linux/libraries/Firmata/examples/OldStandardFirmata/LICENSE.txt new file mode 100644 index 0000000..77cec6d --- /dev/null +++ b/arduino-0018-linux/libraries/Firmata/examples/OldStandardFirmata/LICENSE.txt @@ -0,0 +1,458 @@ + + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + diff --git a/arduino-0018-linux/libraries/Firmata/examples/OldStandardFirmata/OldStandardFirmata.pde b/arduino-0018-linux/libraries/Firmata/examples/OldStandardFirmata/OldStandardFirmata.pde new file mode 100644 index 0000000..5dd3679 --- /dev/null +++ b/arduino-0018-linux/libraries/Firmata/examples/OldStandardFirmata/OldStandardFirmata.pde @@ -0,0 +1,228 @@ +/* + Copyright (C) 2006-2008 Hans-Christoph Steiner. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + See file LICENSE.txt for further informations on licensing terms. + */ + +/* + * This is an old version of StandardFirmata (v2.0). It is kept here because + * its the last version that works on an ATMEGA8 chip. Also, it can be used + * for host software that has not been updated to a newer version of the + * protocol. It also uses the old baud rate of 115200 rather than 57600. + */ + +#include +#include + +/*============================================================================== + * GLOBAL VARIABLES + *============================================================================*/ + +/* analog inputs */ +int analogInputsToReport = 0; // bitwise array to store pin reporting +int analogPin = 0; // counter for reading analog pins + +/* digital pins */ +byte reportPINs[TOTAL_PORTS]; // PIN == input port +byte previousPINs[TOTAL_PORTS]; // PIN == input port +byte pinStatus[TOTAL_DIGITAL_PINS]; // store pin status, default OUTPUT +byte portStatus[TOTAL_PORTS]; + +/* timer variables */ +unsigned long currentMillis; // store the current value from millis() +unsigned long nextExecuteMillis; // for comparison with currentMillis + + +/*============================================================================== + * FUNCTIONS + *============================================================================*/ + +void outputPort(byte portNumber, byte portValue) +{ + portValue = portValue &~ portStatus[portNumber]; + if(previousPINs[portNumber] != portValue) { + Firmata.sendDigitalPort(portNumber, portValue); + previousPINs[portNumber] = portValue; + Firmata.sendDigitalPort(portNumber, portValue); + } +} + +/* ----------------------------------------------------------------------------- + * check all the active digital inputs for change of state, then add any events + * to the Serial output queue using Serial.print() */ +void checkDigitalInputs(void) +{ + byte i, tmp; + for(i=0; i < TOTAL_PORTS; i++) { + if(reportPINs[i]) { + switch(i) { + case 0: outputPort(0, PIND &~ B00000011); break; // ignore Rx/Tx 0/1 + case 1: outputPort(1, PINB); break; + case ANALOG_PORT: outputPort(ANALOG_PORT, PINC); break; + } + } + } +} + +// ----------------------------------------------------------------------------- +/* sets the pin mode to the correct state and sets the relevant bits in the + * two bit-arrays that track Digital I/O and PWM status + */ +void setPinModeCallback(byte pin, int mode) { + byte port = 0; + byte offset = 0; + + if (pin < 8) { + port = 0; + offset = 0; + } else if (pin < 14) { + port = 1; + offset = 8; + } else if (pin < 22) { + port = 2; + offset = 14; + } + + if(pin > 1) { // ignore RxTx (pins 0 and 1) + pinStatus[pin] = mode; + switch(mode) { + case INPUT: + pinMode(pin, INPUT); + portStatus[port] = portStatus[port] &~ (1 << (pin - offset)); + break; + case OUTPUT: + digitalWrite(pin, LOW); // disable PWM + case PWM: + pinMode(pin, OUTPUT); + portStatus[port] = portStatus[port] | (1 << (pin - offset)); + break; + //case ANALOG: // TODO figure this out + default: + Firmata.sendString(""); + } + // TODO: save status to EEPROM here, if changed + } +} + +void analogWriteCallback(byte pin, int value) +{ + setPinModeCallback(pin,PWM); + analogWrite(pin, value); +} + +void digitalWriteCallback(byte port, int value) +{ + switch(port) { + case 0: // pins 2-7 (don't change Rx/Tx, pins 0 and 1) + // 0xFF03 == B1111111100000011 0x03 == B00000011 + PORTD = (value &~ 0xFF03) | (PORTD & 0x03); + break; + case 1: // pins 8-13 (14,15 are disabled for the crystal) + PORTB = (byte)value; + break; + case 2: // analog pins used as digital + PORTC = (byte)value; + break; + } +} + +// ----------------------------------------------------------------------------- +/* sets bits in a bit array (int) to toggle the reporting of the analogIns + */ +//void FirmataClass::setAnalogPinReporting(byte pin, byte state) { +//} +void reportAnalogCallback(byte pin, int value) +{ + if(value == 0) { + analogInputsToReport = analogInputsToReport &~ (1 << pin); + } + else { // everything but 0 enables reporting of that pin + analogInputsToReport = analogInputsToReport | (1 << pin); + } + // TODO: save status to EEPROM here, if changed +} + +void reportDigitalCallback(byte port, int value) +{ + reportPINs[port] = (byte)value; + if(port == ANALOG_PORT) // turn off analog reporting when used as digital + analogInputsToReport = 0; +} + +/*============================================================================== + * SETUP() + *============================================================================*/ +void setup() +{ + byte i; + + Firmata.setFirmwareVersion(2, 0); + + Firmata.attach(ANALOG_MESSAGE, analogWriteCallback); + Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback); + Firmata.attach(REPORT_ANALOG, reportAnalogCallback); + Firmata.attach(REPORT_DIGITAL, reportDigitalCallback); + Firmata.attach(SET_PIN_MODE, setPinModeCallback); + + portStatus[0] = B00000011; // ignore Tx/RX pins + portStatus[1] = B11000000; // ignore 14/15 pins + portStatus[2] = B00000000; + +// for(i=0; i nextExecuteMillis) { + nextExecuteMillis = currentMillis + 19; // run this every 20ms + /* SERIALREAD - Serial.read() uses a 128 byte circular buffer, so handle + * all serialReads at once, i.e. empty the buffer */ + while(Firmata.available()) + Firmata.processInput(); + /* SEND FTDI WRITE BUFFER - make sure that the FTDI buffer doesn't go over + * 60 bytes. use a timer to sending an event character every 4 ms to + * trigger the buffer to dump. */ + + /* ANALOGREAD - right after the event character, do all of the + * analogReads(). These only need to be done every 4ms. */ + for(analogPin=0;analogPin +# +# - Write prototypes for all your functions (or define them before you +# call them). A prototype declares the types of parameters a +# function will take and what type of value it will return. This +# means that you can have a call to a function before the definition +# of the function. A function prototype looks like the first line of +# the function, with a semi-colon at the end. For example: +# int digitalRead(int pin); +# +# Instructions for using the makefile: +# +# 1. Copy this file into the folder with your sketch. +# +# 2. Below, modify the line containing "TARGET" to refer to the name of +# of your program's file without an extension (e.g. TARGET = foo). +# +# 3. Modify the line containg "ARDUINO" to point the directory that +# contains the Arduino core (for normal Arduino installations, this +# is the hardware/cores/arduino sub-directory). +# +# 4. Modify the line containing "PORT" to refer to the filename +# representing the USB or serial connection to your Arduino board +# (e.g. PORT = /dev/tty.USB0). If the exact name of this file +# changes, you can use * as a wildcard (e.g. PORT = /dev/tty.USB*). +# +# 5. At the command line, change to the directory containing your +# program's file and the makefile. +# +# 6. Type "make" and press enter to compile/verify your program. +# +# 7. Type "make upload", reset your Arduino board, and press enter to +# upload your program to the Arduino board. +# +# $Id: Makefile,v 1.7 2007/04/13 05:28:23 eighthave Exp $ + +PORT = /dev/tty.usbserial-* +TARGET := $(shell pwd | sed 's|.*/\(.*\)|\1|') +ARDUINO = /Applications/arduino +ARDUINO_SRC = $(ARDUINO)/hardware/cores/arduino +ARDUINO_LIB_SRC = $(ARDUINO)/hardware/libraries +INCLUDE = -I$(ARDUINO_SRC) -I$(ARDUINO)/hardware/tools/avr/avr/include \ + -I$(ARDUINO_LIB_SRC)/EEPROM \ + -I$(ARDUINO_LIB_SRC)/Firmata \ + -I$(ARDUINO_LIB_SRC)/Servo \ + -I$(ARDUINO_LIB_SRC) +SRC = $(wildcard $(ARDUINO_SRC)/*.c) +CXXSRC = applet/$(TARGET).cpp $(ARDUINO_SRC)/HardwareSerial.cpp \ + $(ARDUINO_LIB_SRC)/EEPROM/EEPROM.cpp \ + $(ARDUINO_LIB_SRC)/Firmata/Firmata.cpp \ + $(ARDUINO_LIB_SRC)/Servo/Servo.cpp \ + $(ARDUINO_SRC)/WMath.cpp +HEADERS = $(wildcard $(ARDUINO_SRC)/*.h) $(wildcard $(ARDUINO_LIB_SRC)/*/*.h) + +MCU = atmega168 +#MCU = atmega8 +F_CPU = 16000000 +FORMAT = ihex +UPLOAD_RATE = 19200 + +# Name of this Makefile (used for "make depend"). +MAKEFILE = Makefile + +# Debugging format. +# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2. +# AVR (extended) COFF requires stabs, plus an avr-objcopy run. +DEBUG = stabs + +OPT = s + +# Place -D or -U options here +CDEFS = -DF_CPU=$(F_CPU) +CXXDEFS = -DF_CPU=$(F_CPU) + +# Compiler flag to set the C Standard level. +# c89 - "ANSI" C +# gnu89 - c89 plus GCC extensions +# c99 - ISO C99 standard (not yet fully implemented) +# gnu99 - c99 plus GCC extensions +CSTANDARD = -std=gnu99 +CDEBUG = -g$(DEBUG) +CWARN = -Wall -Wstrict-prototypes +CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums +#CEXTRA = -Wa,-adhlns=$(<:.c=.lst) + +CFLAGS = $(CDEBUG) $(CDEFS) $(INCLUDE) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA) +CXXFLAGS = $(CDEFS) $(INCLUDE) -O$(OPT) +#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs +LDFLAGS = + + +# Programming support using avrdude. Settings and variables. +AVRDUDE_PROGRAMMER = stk500 +AVRDUDE_PORT = $(PORT) +AVRDUDE_WRITE_FLASH = -U flash:w:applet/$(TARGET).hex +AVRDUDE_FLAGS = -F -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \ + -b $(UPLOAD_RATE) -q -V + +# Program settings +CC = avr-gcc +CXX = avr-g++ +OBJCOPY = avr-objcopy +OBJDUMP = avr-objdump +SIZE = avr-size +NM = avr-nm +AVRDUDE = avrdude +REMOVE = rm -f +MV = mv -f + +# Define all object files. +OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o) + +# Define all listing files. +LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst) + +# Combine all necessary flags and optional flags. +# Add target processor to flags. +ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) +ALL_CXXFLAGS = -mmcu=$(MCU) -I. $(CXXFLAGS) +ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) + + +# Default target. +all: build + +build: applet/$(TARGET).hex + +eep: applet/$(TARGET).eep +lss: applet/$(TARGET).lss +sym: applet/$(TARGET).sym + + +# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. +COFFCONVERT=$(OBJCOPY) --debugging \ +--change-section-address .data-0x800000 \ +--change-section-address .bss-0x800000 \ +--change-section-address .noinit-0x800000 \ +--change-section-address .eeprom-0x810000 + + +coff: applet/$(TARGET).elf + $(COFFCONVERT) -O coff-avr applet/$(TARGET).elf applet/$(TARGET).cof + + +extcoff: applet/$(TARGET).elf + $(COFFCONVERT) -O coff-ext-avr applet/$(TARGET).elf applet/$(TARGET).cof + + +.SUFFIXES: .elf .hex .eep .lss .sym .pde + +.elf.hex: + $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ + +.elf.eep: + -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ + --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ + +# Create extended listing file from ELF output file. +.elf.lss: + $(OBJDUMP) -h -S $< > $@ + +# Create a symbol table from ELF output file. +.elf.sym: + $(NM) -n $< > $@ + + +# Compile: create object files from C++ source files. +.cpp.o: $(HEADERS) + $(CXX) -c $(ALL_CXXFLAGS) $< -o $@ + +# Compile: create object files from C source files. +.c.o: $(HEADERS) + $(CC) -c $(ALL_CFLAGS) $< -o $@ + + +# Compile: create assembler files from C source files. +.c.s: + $(CC) -S $(ALL_CFLAGS) $< -o $@ + + +# Assemble: create object files from assembler source files. +.S.o: + $(CC) -c $(ALL_ASFLAGS) $< -o $@ + + + +applet/$(TARGET).cpp: $(TARGET).pde + test -d applet || mkdir applet + echo '#include "WProgram.h"' > applet/$(TARGET).cpp + echo '#include "avr/interrupt.h"' >> applet/$(TARGET).cpp + sed -n 's|^\(void .*)\).*|\1;|p' $(TARGET).pde | grep -v 'setup()' | \ + grep -v 'loop()' >> applet/$(TARGET).cpp + cat $(TARGET).pde >> applet/$(TARGET).cpp + cat $(ARDUINO_SRC)/main.cxx >> applet/$(TARGET).cpp + +# Link: create ELF output file from object files. +applet/$(TARGET).elf: applet/$(TARGET).cpp $(OBJ) + $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS) + +pd_close_serial: + echo 'close;' | /Applications/Pd-extended.app/Contents/Resources/bin/pdsend 34567 || true + +# Program the device. +upload: applet/$(TARGET).hex + $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) + + +pd_test: build pd_close_serial upload + +# Target: clean project. +clean: + $(REMOVE) -- applet/$(TARGET).hex applet/$(TARGET).eep \ + applet/$(TARGET).cof applet/$(TARGET).elf $(TARGET).map \ + applet/$(TARGET).sym applet/$(TARGET).lss applet/$(TARGET).cpp \ + $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d) + rmdir -- applet + +depend: + if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \ + then \ + sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \ + $(MAKEFILE).$$$$ && \ + $(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \ + fi + echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \ + >> $(MAKEFILE); \ + $(CC) -M -mmcu=$(MCU) $(CDEFS) $(INCLUDE) $(SRC) $(ASRC) >> $(MAKEFILE) + +.PHONY: all build eep lss sym coff extcoff clean depend pd_close_serial pd_test + +# for emacs +etags: + make etags_`uname -s` + etags *.pde \ + $(ARDUINO_SRC)/*.[ch] \ + $(ARDUINO_SRC)/*.cpp \ + $(ARDUINO_LIB_SRC)/*/*.[ch] \ + $(ARDUINO_LIB_SRC)/*/*.cpp \ + $(ARDUINO)/hardware/tools/avr/avr/include/avr/*.[ch] \ + $(ARDUINO)/hardware/tools/avr/avr/include/*.[ch] + +etags_Darwin: +# etags -a + +etags_Linux: +# etags -a /usr/include/*.h linux/input.h /usr/include/sys/*.h + +etags_MINGW: +# etags -a /usr/include/*.h /usr/include/sys/*.h + + + diff --git a/arduino-0018-linux/libraries/Firmata/examples/ServoFirmata/ServoFirmata.pde b/arduino-0018-linux/libraries/Firmata/examples/ServoFirmata/ServoFirmata.pde new file mode 100644 index 0000000..fa48e2b --- /dev/null +++ b/arduino-0018-linux/libraries/Firmata/examples/ServoFirmata/ServoFirmata.pde @@ -0,0 +1,39 @@ +/* This firmware supports as many servos as possible using the Servo" library + * included in Arduino 0012 + * + * TODO add message to configure minPulse/maxPulse/degrees + * + * This example code is in the public domain. + */ + +#include +#include + +Servo servo9; +Servo servo10; + +void analogWriteCallback(byte pin, int value) +{ + if(pin == 9) + servo9.write(value); + if(pin == 10) + servo10.write(value); +} + +void setup() +{ + Firmata.setFirmwareVersion(0, 2); + Firmata.attach(ANALOG_MESSAGE, analogWriteCallback); + + servo9.attach(9); + servo10.attach(10); + + Firmata.begin(57600); +} + +void loop() +{ + while(Firmata.available()) + Firmata.processInput(); +} + diff --git a/arduino-0018-linux/libraries/Firmata/examples/SimpleAnalogFirmata/Makefile b/arduino-0018-linux/libraries/Firmata/examples/SimpleAnalogFirmata/Makefile new file mode 100644 index 0000000..e968c0a --- /dev/null +++ b/arduino-0018-linux/libraries/Firmata/examples/SimpleAnalogFirmata/Makefile @@ -0,0 +1,263 @@ +# Arduino makefile +# +# This makefile allows you to build sketches from the command line +# without the Arduino environment (or Java). +# +# The Arduino environment does preliminary processing on a sketch before +# compiling it. If you're using this makefile instead, you'll need to do +# a few things differently: +# +# - Give your program's file a .cpp extension (e.g. foo.cpp). +# +# - Put this line at top of your code: #include +# +# - Write prototypes for all your functions (or define them before you +# call them). A prototype declares the types of parameters a +# function will take and what type of value it will return. This +# means that you can have a call to a function before the definition +# of the function. A function prototype looks like the first line of +# the function, with a semi-colon at the end. For example: +# int digitalRead(int pin); +# +# Instructions for using the makefile: +# +# 1. Copy this file into the folder with your sketch. +# +# 2. Below, modify the line containing "TARGET" to refer to the name of +# of your program's file without an extension (e.g. TARGET = foo). +# +# 3. Modify the line containg "ARDUINO" to point the directory that +# contains the Arduino core (for normal Arduino installations, this +# is the hardware/cores/arduino sub-directory). +# +# 4. Modify the line containing "PORT" to refer to the filename +# representing the USB or serial connection to your Arduino board +# (e.g. PORT = /dev/tty.USB0). If the exact name of this file +# changes, you can use * as a wildcard (e.g. PORT = /dev/tty.USB*). +# +# 5. At the command line, change to the directory containing your +# program's file and the makefile. +# +# 6. Type "make" and press enter to compile/verify your program. +# +# 7. Type "make upload", reset your Arduino board, and press enter to +# upload your program to the Arduino board. +# +# $Id: Makefile,v 1.7 2007/04/13 05:28:23 eighthave Exp $ + +PORT = /dev/tty.usbserial-* +TARGET := $(shell pwd | sed 's|.*/\(.*\)|\1|') +ARDUINO = /Applications/arduino +ARDUINO_SRC = $(ARDUINO)/hardware/cores/arduino +ARDUINO_LIB_SRC = $(ARDUINO)/hardware/libraries +INCLUDE = -I$(ARDUINO_SRC) -I$(ARDUINO)/hardware/tools/avr/avr/include \ + -I$(ARDUINO_LIB_SRC)/EEPROM \ + -I$(ARDUINO_LIB_SRC)/Firmata \ + -I$(ARDUINO_LIB_SRC)/Servo \ + -I$(ARDUINO_LIB_SRC) +SRC = $(wildcard $(ARDUINO_SRC)/*.c) +CXXSRC = applet/$(TARGET).cpp $(ARDUINO_SRC)/HardwareSerial.cpp \ + $(ARDUINO_LIB_SRC)/EEPROM/EEPROM.cpp \ + $(ARDUINO_LIB_SRC)/Firmata/Firmata.cpp \ + $(ARDUINO_LIB_SRC)/Servo/Servo.cpp \ + $(ARDUINO_SRC)/WMath.cpp +HEADERS = $(wildcard $(ARDUINO_SRC)/*.h) $(wildcard $(ARDUINO_LIB_SRC)/*/*.h) + +MCU = atmega168 +#MCU = atmega8 +F_CPU = 16000000 +FORMAT = ihex +UPLOAD_RATE = 19200 + +# Name of this Makefile (used for "make depend"). +MAKEFILE = Makefile + +# Debugging format. +# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2. +# AVR (extended) COFF requires stabs, plus an avr-objcopy run. +DEBUG = stabs + +OPT = s + +# Place -D or -U options here +CDEFS = -DF_CPU=$(F_CPU) +CXXDEFS = -DF_CPU=$(F_CPU) + +# Compiler flag to set the C Standard level. +# c89 - "ANSI" C +# gnu89 - c89 plus GCC extensions +# c99 - ISO C99 standard (not yet fully implemented) +# gnu99 - c99 plus GCC extensions +CSTANDARD = -std=gnu99 +CDEBUG = -g$(DEBUG) +CWARN = -Wall -Wstrict-prototypes +CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums +#CEXTRA = -Wa,-adhlns=$(<:.c=.lst) + +CFLAGS = $(CDEBUG) $(CDEFS) $(INCLUDE) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA) +CXXFLAGS = $(CDEFS) $(INCLUDE) -O$(OPT) +#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs +LDFLAGS = + + +# Programming support using avrdude. Settings and variables. +AVRDUDE_PROGRAMMER = stk500 +AVRDUDE_PORT = $(PORT) +AVRDUDE_WRITE_FLASH = -U flash:w:applet/$(TARGET).hex +AVRDUDE_FLAGS = -F -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \ + -b $(UPLOAD_RATE) -q -V + +# Program settings +CC = avr-gcc +CXX = avr-g++ +OBJCOPY = avr-objcopy +OBJDUMP = avr-objdump +SIZE = avr-size +NM = avr-nm +AVRDUDE = avrdude +REMOVE = rm -f +MV = mv -f + +# Define all object files. +OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o) + +# Define all listing files. +LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst) + +# Combine all necessary flags and optional flags. +# Add target processor to flags. +ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) +ALL_CXXFLAGS = -mmcu=$(MCU) -I. $(CXXFLAGS) +ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) + + +# Default target. +all: build + +build: applet/$(TARGET).hex + +eep: applet/$(TARGET).eep +lss: applet/$(TARGET).lss +sym: applet/$(TARGET).sym + + +# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. +COFFCONVERT=$(OBJCOPY) --debugging \ +--change-section-address .data-0x800000 \ +--change-section-address .bss-0x800000 \ +--change-section-address .noinit-0x800000 \ +--change-section-address .eeprom-0x810000 + + +coff: applet/$(TARGET).elf + $(COFFCONVERT) -O coff-avr applet/$(TARGET).elf applet/$(TARGET).cof + + +extcoff: applet/$(TARGET).elf + $(COFFCONVERT) -O coff-ext-avr applet/$(TARGET).elf applet/$(TARGET).cof + + +.SUFFIXES: .elf .hex .eep .lss .sym .pde + +.elf.hex: + $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ + +.elf.eep: + -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ + --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ + +# Create extended listing file from ELF output file. +.elf.lss: + $(OBJDUMP) -h -S $< > $@ + +# Create a symbol table from ELF output file. +.elf.sym: + $(NM) -n $< > $@ + + +# Compile: create object files from C++ source files. +.cpp.o: $(HEADERS) + $(CXX) -c $(ALL_CXXFLAGS) $< -o $@ + +# Compile: create object files from C source files. +.c.o: $(HEADERS) + $(CC) -c $(ALL_CFLAGS) $< -o $@ + + +# Compile: create assembler files from C source files. +.c.s: + $(CC) -S $(ALL_CFLAGS) $< -o $@ + + +# Assemble: create object files from assembler source files. +.S.o: + $(CC) -c $(ALL_ASFLAGS) $< -o $@ + + + +applet/$(TARGET).cpp: $(TARGET).pde + test -d applet || mkdir applet + echo '#include "WProgram.h"' > applet/$(TARGET).cpp + echo '#include "avr/interrupt.h"' >> applet/$(TARGET).cpp + sed -n 's|^\(void .*)\).*|\1;|p' $(TARGET).pde | grep -v 'setup()' | \ + grep -v 'loop()' >> applet/$(TARGET).cpp + cat $(TARGET).pde >> applet/$(TARGET).cpp + cat $(ARDUINO_SRC)/main.cxx >> applet/$(TARGET).cpp + +# Link: create ELF output file from object files. +applet/$(TARGET).elf: applet/$(TARGET).cpp $(OBJ) + $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS) + +pd_close_serial: + echo 'close;' | /Applications/Pd-extended.app/Contents/Resources/bin/pdsend 34567 || true + +# Program the device. +upload: applet/$(TARGET).hex + $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) + + +pd_test: build pd_close_serial upload + +# Target: clean project. +clean: + $(REMOVE) -- applet/$(TARGET).hex applet/$(TARGET).eep \ + applet/$(TARGET).cof applet/$(TARGET).elf $(TARGET).map \ + applet/$(TARGET).sym applet/$(TARGET).lss applet/$(TARGET).cpp \ + $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d) + rmdir -- applet + +depend: + if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \ + then \ + sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \ + $(MAKEFILE).$$$$ && \ + $(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \ + fi + echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \ + >> $(MAKEFILE); \ + $(CC) -M -mmcu=$(MCU) $(CDEFS) $(INCLUDE) $(SRC) $(ASRC) >> $(MAKEFILE) + +.PHONY: all build eep lss sym coff extcoff clean depend pd_close_serial pd_test + +# for emacs +etags: + make etags_`uname -s` + etags *.pde \ + $(ARDUINO_SRC)/*.[ch] \ + $(ARDUINO_SRC)/*.cpp \ + $(ARDUINO_LIB_SRC)/*/*.[ch] \ + $(ARDUINO_LIB_SRC)/*/*.cpp \ + $(ARDUINO)/hardware/tools/avr/avr/include/avr/*.[ch] \ + $(ARDUINO)/hardware/tools/avr/avr/include/*.[ch] + +etags_Darwin: +# etags -a + +etags_Linux: +# etags -a /usr/include/*.h linux/input.h /usr/include/sys/*.h + +etags_MINGW: +# etags -a /usr/include/*.h /usr/include/sys/*.h + + + diff --git a/arduino-0018-linux/libraries/Firmata/examples/SimpleAnalogFirmata/SimpleAnalogFirmata.pde b/arduino-0018-linux/libraries/Firmata/examples/SimpleAnalogFirmata/SimpleAnalogFirmata.pde new file mode 100644 index 0000000..430d0d0 --- /dev/null +++ b/arduino-0018-linux/libraries/Firmata/examples/SimpleAnalogFirmata/SimpleAnalogFirmata.pde @@ -0,0 +1,32 @@ +/* Supports as many analog inputs and analog PWM outputs as possible. + * + * This example code is in the public domain. + */ +#include + +byte analogPin; + +void analogWriteCallback(byte pin, int value) +{ + pinMode(pin,OUTPUT); + analogWrite(pin, value); +} + +void setup() +{ + Firmata.setFirmwareVersion(0, 1); + Firmata.attach(ANALOG_MESSAGE, analogWriteCallback); + Firmata.begin(57600); +} + +void loop() +{ + while(Firmata.available()) { + Firmata.processInput(); + } + for(analogPin = 0; analogPin < TOTAL_ANALOG_PINS; analogPin++) { + Firmata.sendAnalog(analogPin, analogRead(analogPin)); + } +} + + diff --git a/arduino-0018-linux/libraries/Firmata/examples/SimpleDigitalFirmata/Makefile b/arduino-0018-linux/libraries/Firmata/examples/SimpleDigitalFirmata/Makefile new file mode 100644 index 0000000..e968c0a --- /dev/null +++ b/arduino-0018-linux/libraries/Firmata/examples/SimpleDigitalFirmata/Makefile @@ -0,0 +1,263 @@ +# Arduino makefile +# +# This makefile allows you to build sketches from the command line +# without the Arduino environment (or Java). +# +# The Arduino environment does preliminary processing on a sketch before +# compiling it. If you're using this makefile instead, you'll need to do +# a few things differently: +# +# - Give your program's file a .cpp extension (e.g. foo.cpp). +# +# - Put this line at top of your code: #include +# +# - Write prototypes for all your functions (or define them before you +# call them). A prototype declares the types of parameters a +# function will take and what type of value it will return. This +# means that you can have a call to a function before the definition +# of the function. A function prototype looks like the first line of +# the function, with a semi-colon at the end. For example: +# int digitalRead(int pin); +# +# Instructions for using the makefile: +# +# 1. Copy this file into the folder with your sketch. +# +# 2. Below, modify the line containing "TARGET" to refer to the name of +# of your program's file without an extension (e.g. TARGET = foo). +# +# 3. Modify the line containg "ARDUINO" to point the directory that +# contains the Arduino core (for normal Arduino installations, this +# is the hardware/cores/arduino sub-directory). +# +# 4. Modify the line containing "PORT" to refer to the filename +# representing the USB or serial connection to your Arduino board +# (e.g. PORT = /dev/tty.USB0). If the exact name of this file +# changes, you can use * as a wildcard (e.g. PORT = /dev/tty.USB*). +# +# 5. At the command line, change to the directory containing your +# program's file and the makefile. +# +# 6. Type "make" and press enter to compile/verify your program. +# +# 7. Type "make upload", reset your Arduino board, and press enter to +# upload your program to the Arduino board. +# +# $Id: Makefile,v 1.7 2007/04/13 05:28:23 eighthave Exp $ + +PORT = /dev/tty.usbserial-* +TARGET := $(shell pwd | sed 's|.*/\(.*\)|\1|') +ARDUINO = /Applications/arduino +ARDUINO_SRC = $(ARDUINO)/hardware/cores/arduino +ARDUINO_LIB_SRC = $(ARDUINO)/hardware/libraries +INCLUDE = -I$(ARDUINO_SRC) -I$(ARDUINO)/hardware/tools/avr/avr/include \ + -I$(ARDUINO_LIB_SRC)/EEPROM \ + -I$(ARDUINO_LIB_SRC)/Firmata \ + -I$(ARDUINO_LIB_SRC)/Servo \ + -I$(ARDUINO_LIB_SRC) +SRC = $(wildcard $(ARDUINO_SRC)/*.c) +CXXSRC = applet/$(TARGET).cpp $(ARDUINO_SRC)/HardwareSerial.cpp \ + $(ARDUINO_LIB_SRC)/EEPROM/EEPROM.cpp \ + $(ARDUINO_LIB_SRC)/Firmata/Firmata.cpp \ + $(ARDUINO_LIB_SRC)/Servo/Servo.cpp \ + $(ARDUINO_SRC)/WMath.cpp +HEADERS = $(wildcard $(ARDUINO_SRC)/*.h) $(wildcard $(ARDUINO_LIB_SRC)/*/*.h) + +MCU = atmega168 +#MCU = atmega8 +F_CPU = 16000000 +FORMAT = ihex +UPLOAD_RATE = 19200 + +# Name of this Makefile (used for "make depend"). +MAKEFILE = Makefile + +# Debugging format. +# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2. +# AVR (extended) COFF requires stabs, plus an avr-objcopy run. +DEBUG = stabs + +OPT = s + +# Place -D or -U options here +CDEFS = -DF_CPU=$(F_CPU) +CXXDEFS = -DF_CPU=$(F_CPU) + +# Compiler flag to set the C Standard level. +# c89 - "ANSI" C +# gnu89 - c89 plus GCC extensions +# c99 - ISO C99 standard (not yet fully implemented) +# gnu99 - c99 plus GCC extensions +CSTANDARD = -std=gnu99 +CDEBUG = -g$(DEBUG) +CWARN = -Wall -Wstrict-prototypes +CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums +#CEXTRA = -Wa,-adhlns=$(<:.c=.lst) + +CFLAGS = $(CDEBUG) $(CDEFS) $(INCLUDE) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA) +CXXFLAGS = $(CDEFS) $(INCLUDE) -O$(OPT) +#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs +LDFLAGS = + + +# Programming support using avrdude. Settings and variables. +AVRDUDE_PROGRAMMER = stk500 +AVRDUDE_PORT = $(PORT) +AVRDUDE_WRITE_FLASH = -U flash:w:applet/$(TARGET).hex +AVRDUDE_FLAGS = -F -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \ + -b $(UPLOAD_RATE) -q -V + +# Program settings +CC = avr-gcc +CXX = avr-g++ +OBJCOPY = avr-objcopy +OBJDUMP = avr-objdump +SIZE = avr-size +NM = avr-nm +AVRDUDE = avrdude +REMOVE = rm -f +MV = mv -f + +# Define all object files. +OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o) + +# Define all listing files. +LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst) + +# Combine all necessary flags and optional flags. +# Add target processor to flags. +ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) +ALL_CXXFLAGS = -mmcu=$(MCU) -I. $(CXXFLAGS) +ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) + + +# Default target. +all: build + +build: applet/$(TARGET).hex + +eep: applet/$(TARGET).eep +lss: applet/$(TARGET).lss +sym: applet/$(TARGET).sym + + +# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. +COFFCONVERT=$(OBJCOPY) --debugging \ +--change-section-address .data-0x800000 \ +--change-section-address .bss-0x800000 \ +--change-section-address .noinit-0x800000 \ +--change-section-address .eeprom-0x810000 + + +coff: applet/$(TARGET).elf + $(COFFCONVERT) -O coff-avr applet/$(TARGET).elf applet/$(TARGET).cof + + +extcoff: applet/$(TARGET).elf + $(COFFCONVERT) -O coff-ext-avr applet/$(TARGET).elf applet/$(TARGET).cof + + +.SUFFIXES: .elf .hex .eep .lss .sym .pde + +.elf.hex: + $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ + +.elf.eep: + -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ + --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ + +# Create extended listing file from ELF output file. +.elf.lss: + $(OBJDUMP) -h -S $< > $@ + +# Create a symbol table from ELF output file. +.elf.sym: + $(NM) -n $< > $@ + + +# Compile: create object files from C++ source files. +.cpp.o: $(HEADERS) + $(CXX) -c $(ALL_CXXFLAGS) $< -o $@ + +# Compile: create object files from C source files. +.c.o: $(HEADERS) + $(CC) -c $(ALL_CFLAGS) $< -o $@ + + +# Compile: create assembler files from C source files. +.c.s: + $(CC) -S $(ALL_CFLAGS) $< -o $@ + + +# Assemble: create object files from assembler source files. +.S.o: + $(CC) -c $(ALL_ASFLAGS) $< -o $@ + + + +applet/$(TARGET).cpp: $(TARGET).pde + test -d applet || mkdir applet + echo '#include "WProgram.h"' > applet/$(TARGET).cpp + echo '#include "avr/interrupt.h"' >> applet/$(TARGET).cpp + sed -n 's|^\(void .*)\).*|\1;|p' $(TARGET).pde | grep -v 'setup()' | \ + grep -v 'loop()' >> applet/$(TARGET).cpp + cat $(TARGET).pde >> applet/$(TARGET).cpp + cat $(ARDUINO_SRC)/main.cxx >> applet/$(TARGET).cpp + +# Link: create ELF output file from object files. +applet/$(TARGET).elf: applet/$(TARGET).cpp $(OBJ) + $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS) + +pd_close_serial: + echo 'close;' | /Applications/Pd-extended.app/Contents/Resources/bin/pdsend 34567 || true + +# Program the device. +upload: applet/$(TARGET).hex + $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) + + +pd_test: build pd_close_serial upload + +# Target: clean project. +clean: + $(REMOVE) -- applet/$(TARGET).hex applet/$(TARGET).eep \ + applet/$(TARGET).cof applet/$(TARGET).elf $(TARGET).map \ + applet/$(TARGET).sym applet/$(TARGET).lss applet/$(TARGET).cpp \ + $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d) + rmdir -- applet + +depend: + if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \ + then \ + sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \ + $(MAKEFILE).$$$$ && \ + $(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \ + fi + echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \ + >> $(MAKEFILE); \ + $(CC) -M -mmcu=$(MCU) $(CDEFS) $(INCLUDE) $(SRC) $(ASRC) >> $(MAKEFILE) + +.PHONY: all build eep lss sym coff extcoff clean depend pd_close_serial pd_test + +# for emacs +etags: + make etags_`uname -s` + etags *.pde \ + $(ARDUINO_SRC)/*.[ch] \ + $(ARDUINO_SRC)/*.cpp \ + $(ARDUINO_LIB_SRC)/*/*.[ch] \ + $(ARDUINO_LIB_SRC)/*/*.cpp \ + $(ARDUINO)/hardware/tools/avr/avr/include/avr/*.[ch] \ + $(ARDUINO)/hardware/tools/avr/avr/include/*.[ch] + +etags_Darwin: +# etags -a + +etags_Linux: +# etags -a /usr/include/*.h linux/input.h /usr/include/sys/*.h + +etags_MINGW: +# etags -a /usr/include/*.h /usr/include/sys/*.h + + + diff --git a/arduino-0018-linux/libraries/Firmata/examples/SimpleDigitalFirmata/SimpleDigitalFirmata.pde b/arduino-0018-linux/libraries/Firmata/examples/SimpleDigitalFirmata/SimpleDigitalFirmata.pde new file mode 100644 index 0000000..50b54dd --- /dev/null +++ b/arduino-0018-linux/libraries/Firmata/examples/SimpleDigitalFirmata/SimpleDigitalFirmata.pde @@ -0,0 +1,57 @@ +/* Supports as many digital inputs and outputs as possible. + * + * This example code is in the public domain. + */ +#include + +byte previousPIN[2]; // PIN means PORT for input +byte previousPORT[2]; + +void outputPort(byte portNumber, byte portValue) +{ +// only send the data when it changes, otherwise you get too many messages! + if(previousPIN[portNumber] != portValue) { + Firmata.sendDigitalPort(portNumber, portValue); + previousPIN[portNumber] = portValue; + } +} + +void setPinModeCallback(byte pin, int mode) { + if(pin > 1) { // don't touch RxTx pins (0,1) + pinMode(pin, mode); + } +} + +void digitalWriteCallback(byte port, int value) +{ + byte i; + byte currentPinValue, previousPinValue; + + if(value != previousPORT[port]) { + for(i=0; i<8; i++) { + currentPinValue = (byte) value & (1 << i); + previousPinValue = previousPORT[port] & (1 << i); + if(currentPinValue != previousPinValue) { + digitalWrite(i + (port*8), currentPinValue); + } + } + previousPORT[port] = value; + } +} + +void setup() +{ + Firmata.setFirmwareVersion(0, 1); + Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback); + Firmata.attach(SET_PIN_MODE, setPinModeCallback); + Firmata.begin(57600); +} + +void loop() +{ + outputPort(0, PIND &~ B00000011); // pins 0-7, ignoring Rx/Tx pins (0/1) + outputPort(1, PINB); // pins 8-13 + while(Firmata.available()) { + Firmata.processInput(); + } +} diff --git a/arduino-0018-linux/libraries/Firmata/examples/StandardFirmata/LICENSE.txt b/arduino-0018-linux/libraries/Firmata/examples/StandardFirmata/LICENSE.txt new file mode 100644 index 0000000..77cec6d --- /dev/null +++ b/arduino-0018-linux/libraries/Firmata/examples/StandardFirmata/LICENSE.txt @@ -0,0 +1,458 @@ + + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + diff --git a/arduino-0018-linux/libraries/Firmata/examples/StandardFirmata/Makefile b/arduino-0018-linux/libraries/Firmata/examples/StandardFirmata/Makefile new file mode 100644 index 0000000..835187a --- /dev/null +++ b/arduino-0018-linux/libraries/Firmata/examples/StandardFirmata/Makefile @@ -0,0 +1,273 @@ +# Arduino makefile +# +# This makefile allows you to build sketches from the command line +# without the Arduino environment (or Java). +# +# The Arduino environment does preliminary processing on a sketch before +# compiling it. If you're using this makefile instead, you'll need to do +# a few things differently: +# +# - Give your program's file a .cpp extension (e.g. foo.cpp). +# +# - Put this line at top of your code: #include +# +# - Write prototypes for all your functions (or define them before you +# call them). A prototype declares the types of parameters a +# function will take and what type of value it will return. This +# means that you can have a call to a function before the definition +# of the function. A function prototype looks like the first line of +# the function, with a semi-colon at the end. For example: +# int digitalRead(int pin); +# +# Instructions for using the makefile: +# +# 1. Copy this file into the folder with your sketch. +# +# 2. Below, modify the line containing "TARGET" to refer to the name of +# of your program's file without an extension (e.g. TARGET = foo). +# +# 3. Modify the line containg "ARDUINO" to point the directory that +# contains the Arduino core (for normal Arduino installations, this +# is the hardware/cores/arduino sub-directory). +# +# 4. Modify the line containing "PORT" to refer to the filename +# representing the USB or serial connection to your Arduino board +# (e.g. PORT = /dev/tty.USB0). If the exact name of this file +# changes, you can use * as a wildcard (e.g. PORT = /dev/tty.USB*). +# +# 5. At the command line, change to the directory containing your +# program's file and the makefile. +# +# 6. Type "make" and press enter to compile/verify your program. +# +# 7. Type "make upload", reset your Arduino board, and press enter to +# upload your program to the Arduino board. +# +# $Id: Makefile,v 1.7 2007/04/13 05:28:23 eighthave Exp $ + +PORT = /dev/tty.usbserial-* +TARGET := $(shell pwd | sed 's|.*/\(.*\)|\1|') +ARDUINO = /Applications/arduino +ARDUINO_SRC = $(ARDUINO)/hardware/cores/arduino +ARDUINO_LIB_SRC = $(ARDUINO)/hardware/libraries +ARDUINO_TOOLS = $(ARDUINO)/hardware/tools +INCLUDE = -I$(ARDUINO_SRC) -I$(ARDUINO)/hardware/tools/avr/avr/include \ + -I$(ARDUINO_LIB_SRC)/EEPROM \ + -I$(ARDUINO_LIB_SRC)/Firmata \ + -I$(ARDUINO_LIB_SRC)/Matrix \ + -I$(ARDUINO_LIB_SRC)/Servo \ + -I$(ARDUINO_LIB_SRC)/Wire \ + -I$(ARDUINO_LIB_SRC) +SRC = $(wildcard $(ARDUINO_SRC)/*.c) +CXXSRC = applet/$(TARGET).cpp $(ARDUINO_SRC)/HardwareSerial.cpp \ + $(ARDUINO_LIB_SRC)/EEPROM/EEPROM.cpp \ + $(ARDUINO_LIB_SRC)/Firmata/Firmata.cpp \ + $(ARDUINO_LIB_SRC)/Servo/Servo.cpp \ + $(ARDUINO_SRC)/Print.cpp \ + $(ARDUINO_SRC)/WMath.cpp +HEADERS = $(wildcard $(ARDUINO_SRC)/*.h) $(wildcard $(ARDUINO_LIB_SRC)/*/*.h) + +MCU = atmega168 +#MCU = atmega8 +F_CPU = 16000000 +FORMAT = ihex +UPLOAD_RATE = 19200 + +# Name of this Makefile (used for "make depend"). +MAKEFILE = Makefile + +# Debugging format. +# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2. +# AVR (extended) COFF requires stabs, plus an avr-objcopy run. +DEBUG = stabs + +OPT = s + +# Place -D or -U options here +CDEFS = -DF_CPU=$(F_CPU) +CXXDEFS = -DF_CPU=$(F_CPU) + +# Compiler flag to set the C Standard level. +# c89 - "ANSI" C +# gnu89 - c89 plus GCC extensions +# c99 - ISO C99 standard (not yet fully implemented) +# gnu99 - c99 plus GCC extensions +CSTANDARD = -std=gnu99 +CDEBUG = -g$(DEBUG) +CWARN = -Wall -Wstrict-prototypes +CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums +#CEXTRA = -Wa,-adhlns=$(<:.c=.lst) + +CFLAGS = $(CDEBUG) $(CDEFS) $(INCLUDE) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA) +CXXFLAGS = $(CDEFS) $(INCLUDE) -O$(OPT) +#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs +LDFLAGS = + + +# Programming support using avrdude. Settings and variables. +AVRDUDE_PROGRAMMER = stk500 +AVRDUDE_PORT = $(PORT) +AVRDUDE_WRITE_FLASH = -U flash:w:applet/$(TARGET).hex +AVRDUDE_FLAGS = -F -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \ + -b $(UPLOAD_RATE) -q -V + +# Program settings +ARDUINO_AVR_BIN = $(ARDUINO_TOOLS)/avr/bin +CC = $(ARDUINO_AVR_BIN)/avr-gcc +CXX = $(ARDUINO_AVR_BIN)/avr-g++ +OBJCOPY = $(ARDUINO_AVR_BIN)/avr-objcopy +OBJDUMP = $(ARDUINO_AVR_BIN)/avr-objdump +SIZE = $(ARDUINO_AVR_BIN)/avr-size +NM = $(ARDUINO_AVR_BIN)/avr-nm +#AVRDUDE = $(ARDUINO_AVR_BIN)/avrdude +AVRDUDE = avrdude +REMOVE = rm -f +MV = mv -f + +# Define all object files. +OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o) + +# Define all listing files. +LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst) + +# Combine all necessary flags and optional flags. +# Add target processor to flags. +ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) +ALL_CXXFLAGS = -mmcu=$(MCU) -I. $(CXXFLAGS) +ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) + + +# Default target. +all: build + +build: applet/$(TARGET).hex + +eep: applet/$(TARGET).eep +lss: applet/$(TARGET).lss +sym: applet/$(TARGET).sym + + +# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. +COFFCONVERT=$(OBJCOPY) --debugging \ +--change-section-address .data-0x800000 \ +--change-section-address .bss-0x800000 \ +--change-section-address .noinit-0x800000 \ +--change-section-address .eeprom-0x810000 + + +coff: applet/$(TARGET).elf + $(COFFCONVERT) -O coff-avr applet/$(TARGET).elf applet/$(TARGET).cof + + +extcoff: applet/$(TARGET).elf + $(COFFCONVERT) -O coff-ext-avr applet/$(TARGET).elf applet/$(TARGET).cof + + +.SUFFIXES: .elf .hex .eep .lss .sym .pde + +.elf.hex: + $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ + +.elf.eep: + -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ + --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ + +# Create extended listing file from ELF output file. +.elf.lss: + $(OBJDUMP) -h -S $< > $@ + +# Create a symbol table from ELF output file. +.elf.sym: + $(NM) -n $< > $@ + + +# Compile: create object files from C++ source files. +.cpp.o: $(HEADERS) + $(CXX) -c $(ALL_CXXFLAGS) $< -o $@ + +# Compile: create object files from C source files. +.c.o: $(HEADERS) + $(CC) -c $(ALL_CFLAGS) $< -o $@ + + +# Compile: create assembler files from C source files. +.c.s: + $(CC) -S $(ALL_CFLAGS) $< -o $@ + + +# Assemble: create object files from assembler source files. +.S.o: + $(CC) -c $(ALL_ASFLAGS) $< -o $@ + + + +applet/$(TARGET).cpp: $(TARGET).pde + test -d applet || mkdir applet + echo '#include "WProgram.h"' > applet/$(TARGET).cpp + echo '#include "avr/interrupt.h"' >> applet/$(TARGET).cpp + sed -n 's|^\(void .*)\).*|\1;|p' $(TARGET).pde | grep -v 'setup()' | \ + grep -v 'loop()' >> applet/$(TARGET).cpp + cat $(TARGET).pde >> applet/$(TARGET).cpp + cat $(ARDUINO_SRC)/main.cxx >> applet/$(TARGET).cpp + +# Link: create ELF output file from object files. +applet/$(TARGET).elf: applet/$(TARGET).cpp $(OBJ) + $(CC) $(ALL_CFLAGS) $(OBJ) -lm --output $@ $(LDFLAGS) +# $(CC) $(ALL_CFLAGS) $(OBJ) $(ARDUINO_TOOLS)/avr/avr/lib/avr5/crtm168.o --output $@ $(LDFLAGS) + +pd_close_serial: + echo 'close;' | /Applications/Pd-extended.app/Contents/Resources/bin/pdsend 34567 || true + +# Program the device. +upload: applet/$(TARGET).hex + $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) + + +pd_test: build pd_close_serial upload + +# Target: clean project. +clean: + $(REMOVE) -- applet/$(TARGET).hex applet/$(TARGET).eep \ + applet/$(TARGET).cof applet/$(TARGET).elf $(TARGET).map \ + applet/$(TARGET).sym applet/$(TARGET).lss applet/$(TARGET).cpp \ + $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d) + rmdir -- applet + +depend: + if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \ + then \ + sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \ + $(MAKEFILE).$$$$ && \ + $(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \ + fi + echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \ + >> $(MAKEFILE); \ + $(CC) -M -mmcu=$(MCU) $(CDEFS) $(INCLUDE) $(SRC) $(ASRC) >> $(MAKEFILE) + +.PHONY: all build eep lss sym coff extcoff clean depend pd_close_serial pd_test + +# for emacs +etags: + make etags_`uname -s` + etags *.pde \ + $(ARDUINO_SRC)/*.[ch] \ + $(ARDUINO_SRC)/*.cpp \ + $(ARDUINO_LIB_SRC)/*/*.[ch] \ + $(ARDUINO_LIB_SRC)/*/*.cpp \ + $(ARDUINO)/hardware/tools/avr/avr/include/avr/*.[ch] \ + $(ARDUINO)/hardware/tools/avr/avr/include/*.[ch] + +etags_Darwin: +# etags -a + +etags_Linux: +# etags -a /usr/include/*.h linux/input.h /usr/include/sys/*.h + +etags_MINGW: +# etags -a /usr/include/*.h /usr/include/sys/*.h + + +path: + echo $(PATH) + echo $$PATH + diff --git a/arduino-0018-linux/libraries/Firmata/examples/StandardFirmata/StandardFirmata.pde b/arduino-0018-linux/libraries/Firmata/examples/StandardFirmata/StandardFirmata.pde new file mode 100644 index 0000000..9e16b8a --- /dev/null +++ b/arduino-0018-linux/libraries/Firmata/examples/StandardFirmata/StandardFirmata.pde @@ -0,0 +1,302 @@ +/* + Copyright (C) 2006-2008 Hans-Christoph Steiner. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + See file LICENSE.txt for further informations on licensing terms. + + formatted using the GNU C formatting and indenting +*/ + +/* + * TODO: use Program Control to load stored profiles from EEPROM + */ + +#include +#include + +/*============================================================================== + * GLOBAL VARIABLES + *============================================================================*/ + +/* analog inputs */ +int analogInputsToReport = 0; // bitwise array to store pin reporting +int analogPin = 0; // counter for reading analog pins + +/* digital pins */ +byte reportPINs[TOTAL_PORTS]; // PIN == input port +byte previousPINs[TOTAL_PORTS]; // PIN == input port +byte pinStatus[TOTAL_DIGITAL_PINS]; // store pin status, default OUTPUT +byte portStatus[TOTAL_PORTS]; + +/* timer variables */ +unsigned long currentMillis; // store the current value from millis() +unsigned long nextExecuteMillis; // for comparison with currentMillis +int samplingInterval = 19; // how often to run the main loop (in ms) + +Servo servos[MAX_SERVOS]; + +/*============================================================================== + * FUNCTIONS + *============================================================================*/ + +void outputPort(byte portNumber, byte portValue) +{ + portValue = portValue &~ portStatus[portNumber]; + if(previousPINs[portNumber] != portValue) { + Firmata.sendDigitalPort(portNumber, portValue); + previousPINs[portNumber] = portValue; + } +} + +/* ----------------------------------------------------------------------------- + * check all the active digital inputs for change of state, then add any events + * to the Serial output queue using Serial.print() */ +void checkDigitalInputs(void) +{ + byte i, tmp; + for(i=0; i < TOTAL_PORTS; i++) { + if(reportPINs[i]) { + switch(i) { + case 0: + outputPort(0, PIND &~ B00000011); // ignore Rx/Tx 0/1 + break; + case 1: + outputPort(1, PINB); + break; + case ANALOG_PORT: + outputPort(ANALOG_PORT, PINC); + break; + } + } + } +} + +// ----------------------------------------------------------------------------- +/* sets the pin mode to the correct state and sets the relevant bits in the + * two bit-arrays that track Digital I/O and PWM status + */ +void setPinModeCallback(byte pin, int mode) { + byte port = 0; + byte offset = 0; + + // TODO: abstract for different boards + if (pin < 8) { + port = 0; + offset = 0; + } else if (pin < 14) { + port = 1; + offset = 8; + } else if (pin < 22) { + port = 2; + offset = 14; + } + + if(pin > 1) { // ignore RxTx (pins 0 and 1) + if (isServoSupportedPin(pin) && mode != SERVO) + if (servos[pin - FIRST_SERVO_PIN].attached()) + servos[pin - FIRST_SERVO_PIN].detach(); + if(pin > 13) + reportAnalogCallback(pin - 14, mode == ANALOG ? 1 : 0); // turn on/off reporting + switch(mode) { + case ANALOG: + digitalWrite(pin, LOW); // disable internal pull-ups and fall thru to 'case INPUT:' + case INPUT: + pinStatus[pin] = mode; + pinMode(pin, INPUT); + portStatus[port] = portStatus[port] &~ (1 << (pin - offset)); + break; + case OUTPUT: + digitalWrite(pin, LOW); // disable PWM and fall thru to 'case PWM:' + case PWM: + pinStatus[pin] = mode; + pinMode(pin, OUTPUT); + portStatus[port] = portStatus[port] | (1 << (pin - offset)); + break; + case SERVO: + // TODO: Support Arduino Mega + if (isServoSupportedPin(pin)) { + pinStatus[pin] = mode; + if (!servos[pin - FIRST_SERVO_PIN].attached()) + servos[pin - FIRST_SERVO_PIN].attach(pin); + } else + Firmata.sendString("Servo only on pins from 2 to 13"); + break; + case I2C: + pinStatus[pin] = mode; + Firmata.sendString("I2C mode not yet supported"); + break; + default: + Firmata.sendString("Unknown pin mode"); // TODO: put error msgs in EEPROM + } + // TODO: save status to EEPROM here, if changed + } +} + +void analogWriteCallback(byte pin, int value) +{ + switch(pinStatus[pin]) { + case SERVO: + if (isServoSupportedPin(pin)) + servos[pin - FIRST_SERVO_PIN].write(value); + break; + case PWM: + analogWrite(pin, value); + break; + } +} + +void digitalWriteCallback(byte port, int value) +{ + switch(port) { + case 0: // pins 2-7 (don't change Rx/Tx, pins 0 and 1) + // 0xFF03 == B1111111100000011 0x03 == B00000011 + PORTD = (value &~ 0xFF03) | (PORTD & 0x03); + break; + case 1: // pins 8-13 (14,15 are disabled for the crystal) + PORTB = (byte)value; + break; + case 2: // analog pins used as digital + byte pin; + byte pinModeMask; + for(pin=0; pin<8; pin++) + if(pinStatus[pin] == OUTPUT) + pinModeMask += 1 << pin; + PORTC = (byte)value & pinModeMask; + break; + } +} + +// ----------------------------------------------------------------------------- +/* sets bits in a bit array (int) to toggle the reporting of the analogIns + */ +//void FirmataClass::setAnalogPinReporting(byte pin, byte state) { +//} +void reportAnalogCallback(byte pin, int value) +{ + if(value == 0) { + analogInputsToReport = analogInputsToReport &~ (1 << pin); + } + else { // everything but 0 enables reporting of that pin + analogInputsToReport = analogInputsToReport | (1 << pin); + } + // TODO: save status to EEPROM here, if changed +} + +void reportDigitalCallback(byte port, int value) +{ + reportPINs[port] = (byte)value; + if(port == ANALOG_PORT) // turn off analog reporting when used as digital + analogInputsToReport = 0; +} + +/*============================================================================== + * SYSEX-BASED commands + *============================================================================*/ + +void sysexCallback(byte command, byte argc, byte *argv) +{ + switch(command) { + case SERVO_CONFIG: + if(argc > 4) { + // these vars are here for clarity, they'll optimized away by the compiler + byte pin = argv[0]; + int minPulse = argv[1] + (argv[2] << 7); + int maxPulse = argv[3] + (argv[4] << 7); + + if (isServoSupportedPin(pin)) { + // servos are pins from 2 to 13, so offset for array + if (servos[pin - FIRST_SERVO_PIN].attached()) + servos[pin - FIRST_SERVO_PIN].detach(); + servos[pin - FIRST_SERVO_PIN].attach(pin, minPulse, maxPulse); + setPinModeCallback(pin, SERVO); + } + } + break; + case SAMPLING_INTERVAL: + if (argc > 1) + samplingInterval = argv[0] + (argv[1] << 7); + else + Firmata.sendString("Not enough data"); + break; + } +} + +boolean isServoSupportedPin(byte pin) +{ + return ((FIRST_SERVO_PIN <= pin) && (pin <= (FIRST_SERVO_PIN + MAX_SERVOS))); +} + +/*============================================================================== + * SETUP() + *============================================================================*/ +void setup() +{ + byte i; + + Firmata.setFirmwareVersion(2, 1); + + Firmata.attach(ANALOG_MESSAGE, analogWriteCallback); + Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback); + Firmata.attach(REPORT_ANALOG, reportAnalogCallback); + Firmata.attach(REPORT_DIGITAL, reportDigitalCallback); + Firmata.attach(SET_PIN_MODE, setPinModeCallback); + Firmata.attach(START_SYSEX, sysexCallback); + + portStatus[0] = B00000011; // ignore Tx/RX pins + portStatus[1] = B11000000; // ignore 14/15 pins + portStatus[2] = B00000000; + + for(i=0; i < FIRST_ANALOG_PIN; ++i) { + setPinModeCallback(i,OUTPUT); + } + // set all outputs to 0 to make sure internal pull-up resistors are off + PORTB = 0; // pins 8-15 + PORTC = 0; // analog port + PORTD = 0; // pins 0-7 + + // TODO rethink the init, perhaps it should report analog on default + for(i=0; i nextExecuteMillis) { + nextExecuteMillis = currentMillis + samplingInterval; + /* SERIALREAD - Serial.read() uses a 128 byte circular buffer, so handle + * all serialReads at once, i.e. empty the buffer */ + while(Firmata.available()) + Firmata.processInput(); + /* SEND FTDI WRITE BUFFER - make sure that the FTDI buffer doesn't go over + * 60 bytes. Ideally this could send an "event character" every 4 ms to + * trigger the buffer to dump. */ + + /* ANALOGREAD - do all of the analogReads() once per poll cycle */ + for(analogPin=0;analogPin +#include +#include +#include "WProgram.h" + +// When the display powers up, it is configured as follows: +// +// 1. Display clear +// 2. Function set: +// DL = 1; 8-bit interface data +// N = 0; 1-line display +// F = 0; 5x8 dot character font +// 3. Display on/off control: +// D = 0; Display off +// C = 0; Cursor off +// B = 0; Blinking off +// 4. Entry mode set: +// I/D = 1; Increment by 1 +// S = 0; No shift +// +// Note, however, that resetting the Arduino doesn't reset the LCD, so we +// can't assume that its in that state when a sketch starts (and the +// LiquidCrystal constructor is called). + +LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, + uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) +{ + init(0, rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7); +} + +LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, + uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) +{ + init(0, rs, 255, enable, d0, d1, d2, d3, d4, d5, d6, d7); +} + +LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3) +{ + init(1, rs, rw, enable, d0, d1, d2, d3, 0, 0, 0, 0); +} + +LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3) +{ + init(1, rs, 255, enable, d0, d1, d2, d3, 0, 0, 0, 0); +} + +void LiquidCrystal::init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, + uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) +{ + _rs_pin = rs; + _rw_pin = rw; + _enable_pin = enable; + + _data_pins[0] = d0; + _data_pins[1] = d1; + _data_pins[2] = d2; + _data_pins[3] = d3; + _data_pins[4] = d4; + _data_pins[5] = d5; + _data_pins[6] = d6; + _data_pins[7] = d7; + + pinMode(_rs_pin, OUTPUT); + // we can save 1 pin by not using RW. Indicate by passing 255 instead of pin# + if (_rw_pin != 255) { + pinMode(_rw_pin, OUTPUT); + } + pinMode(_enable_pin, OUTPUT); + + if (fourbitmode) + _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS; + else + _displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS; + + begin(16, 1); +} + +void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) { + if (lines > 1) { + _displayfunction |= LCD_2LINE; + } + _numlines = lines; + _currline = 0; + + // for some 1 line displays you can select a 10 pixel high font + if ((dotsize != 0) && (lines == 1)) { + _displayfunction |= LCD_5x10DOTS; + } + + // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! + // according to datasheet, we need at least 40ms after power rises above 2.7V + // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50 + delayMicroseconds(50000); + // Now we pull both RS and R/W low to begin commands + digitalWrite(_rs_pin, LOW); + digitalWrite(_enable_pin, LOW); + if (_rw_pin != 255) { + digitalWrite(_rw_pin, LOW); + } + + //put the LCD into 4 bit or 8 bit mode + if (! (_displayfunction & LCD_8BITMODE)) { + // this is according to the hitachi HD44780 datasheet + // figure 24, pg 46 + + // we start in 8bit mode, try to set 4 bit mode + write4bits(0x03); + delayMicroseconds(4500); // wait min 4.1ms + + // second try + write4bits(0x03); + delayMicroseconds(4500); // wait min 4.1ms + + // third go! + write4bits(0x03); + delayMicroseconds(150); + + // finally, set to 8-bit interface + write4bits(0x02); + } else { + // this is according to the hitachi HD44780 datasheet + // page 45 figure 23 + + // Send function set command sequence + command(LCD_FUNCTIONSET | _displayfunction); + delayMicroseconds(4500); // wait more than 4.1ms + + // second try + command(LCD_FUNCTIONSET | _displayfunction); + delayMicroseconds(150); + + // third go + command(LCD_FUNCTIONSET | _displayfunction); + } + + // finally, set # lines, font size, etc. + command(LCD_FUNCTIONSET | _displayfunction); + + // turn the display on with no cursor or blinking default + _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; + display(); + + // clear it off + clear(); + + // Initialize to default text direction (for romance languages) + _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT; + // set the entry mode + command(LCD_ENTRYMODESET | _displaymode); + +} + +/********** high level commands, for the user! */ +void LiquidCrystal::clear() +{ + command(LCD_CLEARDISPLAY); // clear display, set cursor position to zero + delayMicroseconds(2000); // this command takes a long time! +} + +void LiquidCrystal::home() +{ + command(LCD_RETURNHOME); // set cursor position to zero + delayMicroseconds(2000); // this command takes a long time! +} + +void LiquidCrystal::setCursor(uint8_t col, uint8_t row) +{ + int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 }; + if ( row > _numlines ) { + row = _numlines-1; // we count rows starting w/0 + } + + command(LCD_SETDDRAMADDR | (col + row_offsets[row])); +} + +// Turn the display on/off (quickly) +void LiquidCrystal::noDisplay() { + _displaycontrol &= ~LCD_DISPLAYON; + command(LCD_DISPLAYCONTROL | _displaycontrol); +} +void LiquidCrystal::display() { + _displaycontrol |= LCD_DISPLAYON; + command(LCD_DISPLAYCONTROL | _displaycontrol); +} + +// Turns the underline cursor on/off +void LiquidCrystal::noCursor() { + _displaycontrol &= ~LCD_CURSORON; + command(LCD_DISPLAYCONTROL | _displaycontrol); +} +void LiquidCrystal::cursor() { + _displaycontrol |= LCD_CURSORON; + command(LCD_DISPLAYCONTROL | _displaycontrol); +} + +// Turn on and off the blinking cursor +void LiquidCrystal::noBlink() { + _displaycontrol &= ~LCD_BLINKON; + command(LCD_DISPLAYCONTROL | _displaycontrol); +} +void LiquidCrystal::blink() { + _displaycontrol |= LCD_BLINKON; + command(LCD_DISPLAYCONTROL | _displaycontrol); +} + +// These commands scroll the display without changing the RAM +void LiquidCrystal::scrollDisplayLeft(void) { + command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT); +} +void LiquidCrystal::scrollDisplayRight(void) { + command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT); +} + +// This is for text that flows Left to Right +void LiquidCrystal::leftToRight(void) { + _displaymode |= LCD_ENTRYLEFT; + command(LCD_ENTRYMODESET | _displaymode); +} + +// This is for text that flows Right to Left +void LiquidCrystal::rightToLeft(void) { + _displaymode &= ~LCD_ENTRYLEFT; + command(LCD_ENTRYMODESET | _displaymode); +} + +// This will 'right justify' text from the cursor +void LiquidCrystal::autoscroll(void) { + _displaymode |= LCD_ENTRYSHIFTINCREMENT; + command(LCD_ENTRYMODESET | _displaymode); +} + +// This will 'left justify' text from the cursor +void LiquidCrystal::noAutoscroll(void) { + _displaymode &= ~LCD_ENTRYSHIFTINCREMENT; + command(LCD_ENTRYMODESET | _displaymode); +} + +// Allows us to fill the first 8 CGRAM locations +// with custom characters +void LiquidCrystal::createChar(uint8_t location, uint8_t charmap[]) { + location &= 0x7; // we only have 8 locations 0-7 + command(LCD_SETCGRAMADDR | (location << 3)); + for (int i=0; i<8; i++) { + write(charmap[i]); + } +} + +/*********** mid level commands, for sending data/cmds */ + +inline void LiquidCrystal::command(uint8_t value) { + send(value, LOW); +} + +inline void LiquidCrystal::write(uint8_t value) { + send(value, HIGH); +} + +/************ low level data pushing commands **********/ + +// write either command or data, with automatic 4/8-bit selection +void LiquidCrystal::send(uint8_t value, uint8_t mode) { + digitalWrite(_rs_pin, mode); + + // if there is a RW pin indicated, set it low to Write + if (_rw_pin != 255) { + digitalWrite(_rw_pin, LOW); + } + + if (_displayfunction & LCD_8BITMODE) { + write8bits(value); + } else { + write4bits(value>>4); + write4bits(value); + } +} + +void LiquidCrystal::pulseEnable(void) { + digitalWrite(_enable_pin, LOW); + delayMicroseconds(1); + digitalWrite(_enable_pin, HIGH); + delayMicroseconds(1); // enable pulse must be >450ns + digitalWrite(_enable_pin, LOW); + delayMicroseconds(100); // commands need > 37us to settle +} + +void LiquidCrystal::write4bits(uint8_t value) { + for (int i = 0; i < 4; i++) { + pinMode(_data_pins[i], OUTPUT); + digitalWrite(_data_pins[i], (value >> i) & 0x01); + } + + pulseEnable(); +} + +void LiquidCrystal::write8bits(uint8_t value) { + for (int i = 0; i < 8; i++) { + pinMode(_data_pins[i], OUTPUT); + digitalWrite(_data_pins[i], (value >> i) & 0x01); + } + + pulseEnable(); +} diff --git a/arduino-0018-linux/libraries/LiquidCrystal/LiquidCrystal.h b/arduino-0018-linux/libraries/LiquidCrystal/LiquidCrystal.h new file mode 100755 index 0000000..f66ec1b --- /dev/null +++ b/arduino-0018-linux/libraries/LiquidCrystal/LiquidCrystal.h @@ -0,0 +1,104 @@ +#ifndef LiquidCrystal_h +#define LiquidCrystal_h + +#include +#include "Print.h" + +// commands +#define LCD_CLEARDISPLAY 0x01 +#define LCD_RETURNHOME 0x02 +#define LCD_ENTRYMODESET 0x04 +#define LCD_DISPLAYCONTROL 0x08 +#define LCD_CURSORSHIFT 0x10 +#define LCD_FUNCTIONSET 0x20 +#define LCD_SETCGRAMADDR 0x40 +#define LCD_SETDDRAMADDR 0x80 + +// flags for display entry mode +#define LCD_ENTRYRIGHT 0x00 +#define LCD_ENTRYLEFT 0x02 +#define LCD_ENTRYSHIFTINCREMENT 0x01 +#define LCD_ENTRYSHIFTDECREMENT 0x00 + +// flags for display on/off control +#define LCD_DISPLAYON 0x04 +#define LCD_DISPLAYOFF 0x00 +#define LCD_CURSORON 0x02 +#define LCD_CURSOROFF 0x00 +#define LCD_BLINKON 0x01 +#define LCD_BLINKOFF 0x00 + +// flags for display/cursor shift +#define LCD_DISPLAYMOVE 0x08 +#define LCD_CURSORMOVE 0x00 +#define LCD_MOVERIGHT 0x04 +#define LCD_MOVELEFT 0x00 + +// flags for function set +#define LCD_8BITMODE 0x10 +#define LCD_4BITMODE 0x00 +#define LCD_2LINE 0x08 +#define LCD_1LINE 0x00 +#define LCD_5x10DOTS 0x04 +#define LCD_5x8DOTS 0x00 + +class LiquidCrystal : public Print { +public: + LiquidCrystal(uint8_t rs, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, + uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); + LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, + uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); + LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); + LiquidCrystal(uint8_t rs, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); + + void init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, + uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); + + void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS); + + void clear(); + void home(); + + void noDisplay(); + void display(); + void noBlink(); + void blink(); + void noCursor(); + void cursor(); + void scrollDisplayLeft(); + void scrollDisplayRight(); + void leftToRight(); + void rightToLeft(); + void autoscroll(); + void noAutoscroll(); + + void createChar(uint8_t, uint8_t[]); + void setCursor(uint8_t, uint8_t); + virtual void write(uint8_t); + void command(uint8_t); +private: + void send(uint8_t, uint8_t); + void write4bits(uint8_t); + void write8bits(uint8_t); + void pulseEnable(); + + uint8_t _rs_pin; // LOW: command. HIGH: character. + uint8_t _rw_pin; // LOW: write to LCD. HIGH: read from LCD. + uint8_t _enable_pin; // activated by a HIGH pulse. + uint8_t _data_pins[8]; + + uint8_t _displayfunction; + uint8_t _displaycontrol; + uint8_t _displaymode; + + uint8_t _initialized; + + uint8_t _numlines,_currline; +}; + +#endif diff --git a/arduino-0018-linux/libraries/LiquidCrystal/examples/Autoscroll/Autoscroll.pde b/arduino-0018-linux/libraries/LiquidCrystal/examples/Autoscroll/Autoscroll.pde new file mode 100644 index 0000000..bf33743 --- /dev/null +++ b/arduino-0018-linux/libraries/LiquidCrystal/examples/Autoscroll/Autoscroll.pde @@ -0,0 +1,70 @@ +/* + LiquidCrystal Library - Autoscroll + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch demonstrates the use of the autoscroll() + and noAutoscroll() functions to make new text scroll or not. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 25 July 2009 + by David A. Mellis + + http://www.arduino.cc/en/Tutorial/LiquidCrystal + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16,2); +} + +void loop() { + // set the cursor to (0,0): + lcd.setCursor(0, 0); + // print from 0 to 9: + for (int thisChar = 0; thisChar < 10; thisChar++) { + lcd.print(thisChar); + delay(500); + } + + // set the cursor to (16,1): + lcd.setCursor(16,1); + // set the display to automatically scroll: + lcd.autoscroll(); + // print from 0 to 9: + for (int thisChar = 0; thisChar < 10; thisChar++) { + lcd.print(thisChar); + delay(500); + } + // turn off automatic scrolling + lcd.noAutoscroll(); + + // clear screen for the next loop: + lcd.clear(); +} + diff --git a/arduino-0018-linux/libraries/LiquidCrystal/examples/Blink/Blink.pde b/arduino-0018-linux/libraries/LiquidCrystal/examples/Blink/Blink.pde new file mode 100644 index 0000000..83c79b4 --- /dev/null +++ b/arduino-0018-linux/libraries/LiquidCrystal/examples/Blink/Blink.pde @@ -0,0 +1,58 @@ +/* + LiquidCrystal Library - Blink + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "Hello World!" to the LCD and makes the + cursor block blink. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 25 July 2009 + by David A. Mellis + + http://www.arduino.cc/en/Tutorial/LiquidCrystal + + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +void setup() { + // set up the LCD's number of rows and columns: + lcd.begin(16, 2); + // Print a message to the LCD. + lcd.print("hello, world!"); +} + +void loop() { + // Turn off the blinking cursor: + lcd.noBlink(); + delay(3000); + // Turn on the blinking cursor: + lcd.blink(); + delay(3000); +} + + diff --git a/arduino-0018-linux/libraries/LiquidCrystal/examples/Cursor/Cursor.pde b/arduino-0018-linux/libraries/LiquidCrystal/examples/Cursor/Cursor.pde new file mode 100644 index 0000000..c0273f4 --- /dev/null +++ b/arduino-0018-linux/libraries/LiquidCrystal/examples/Cursor/Cursor.pde @@ -0,0 +1,58 @@ +/* + LiquidCrystal Library - Cursor + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "Hello World!" to the LCD and + uses the cursor() and noCursor() methods to turn + on and off the cursor. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 25 July 2009 + by David A. Mellis + + + http://www.arduino.cc/en/Tutorial/LiquidCrystal + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +void setup() { + // set up the LCD's number of rows and columns: + lcd.begin(16, 2); + // Print a message to the LCD. + lcd.print("hello, world!"); +} + +void loop() { + // Turn off the cursor: + lcd.noCursor(); + delay(500); + // Turn on the cursor: + lcd.cursor(); + delay(500); +} + diff --git a/arduino-0018-linux/libraries/LiquidCrystal/examples/Display/Display.pde b/arduino-0018-linux/libraries/LiquidCrystal/examples/Display/Display.pde new file mode 100644 index 0000000..b430539 --- /dev/null +++ b/arduino-0018-linux/libraries/LiquidCrystal/examples/Display/Display.pde @@ -0,0 +1,58 @@ +/* + LiquidCrystal Library - display() and noDisplay() + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "Hello World!" to the LCD and uses the + display() and noDisplay() functions to turn on and off + the display. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 25 July 2009 + by David A. Mellis + + + http://www.arduino.cc/en/Tutorial/LiquidCrystal + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +void setup() { + // set up the LCD's number of rows and columns: + lcd.begin(16, 2); + // Print a message to the LCD. + lcd.print("hello, world!"); +} + +void loop() { + // Turn off the display: + lcd.noDisplay(); + delay(500); + // Turn on the display: + lcd.display(); + delay(500); +} + diff --git a/arduino-0018-linux/libraries/LiquidCrystal/examples/HelloWorld/HelloWorld.pde b/arduino-0018-linux/libraries/LiquidCrystal/examples/HelloWorld/HelloWorld.pde new file mode 100644 index 0000000..76cd746 --- /dev/null +++ b/arduino-0018-linux/libraries/LiquidCrystal/examples/HelloWorld/HelloWorld.pde @@ -0,0 +1,56 @@ +/* + LiquidCrystal Library - Hello World + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "Hello World!" to the LCD + and shows the time. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 25 July 2009 + by David A. Mellis + + + http://www.arduino.cc/en/Tutorial/LiquidCrystal + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +void setup() { + // set up the LCD's number of rows and columns: + lcd.begin(16, 2); + // Print a message to the LCD. + lcd.print("hello, world!"); +} + +void loop() { + // set the cursor to column 0, line 1 + // (note: line 1 is the second row, since counting begins with 0): + lcd.setCursor(0, 1); + // print the number of seconds since reset: + lcd.print(millis()/1000); +} + diff --git a/arduino-0018-linux/libraries/LiquidCrystal/examples/Scroll/Scroll.pde b/arduino-0018-linux/libraries/LiquidCrystal/examples/Scroll/Scroll.pde new file mode 100644 index 0000000..9276553 --- /dev/null +++ b/arduino-0018-linux/libraries/LiquidCrystal/examples/Scroll/Scroll.pde @@ -0,0 +1,83 @@ +/* + LiquidCrystal Library - scrollDisplayLeft() and scrollDisplayRight() + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "Hello World!" to the LCD and uses the + scrollDisplayLeft() and scrollDisplayRight() methods to scroll + the text. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 25 July 2009 + by David A. Mellis + + http://www.arduino.cc/en/Tutorial/LiquidCrystal + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +void setup() { + // set up the LCD's number of rows and columns: + lcd.begin(16, 2); + //lcd.setCursor(0,7); + // Print a message to the LCD. + lcd.print("hello, world!"); + delay(1000); +} + +void loop() { + // scroll 13 positions (string length) to the left + // to move it offscreen left: + for (int positionCounter = 0; positionCounter < 13; positionCounter++) { + // scroll one position left: + lcd.scrollDisplayLeft(); + // wait a bit: + delay(150); + } + + // scroll 29 positions (string length + display length) to the right + // to move it offscreen right: + for (int positionCounter = 0; positionCounter < 29; positionCounter++) { + // scroll one position right: + lcd.scrollDisplayRight(); + // wait a bit: + delay(150); + } + + // scroll 16 positions (display length + string length) to the left + // to move it back to center: + for (int positionCounter = 0; positionCounter < 16; positionCounter++) { + // scroll one position left: + lcd.scrollDisplayLeft(); + // wait a bit: + delay(150); + } + + // delay at the end of the full loop: + delay(1000); + +} + diff --git a/arduino-0018-linux/libraries/LiquidCrystal/examples/SerialDisplay/SerialDisplay.pde b/arduino-0018-linux/libraries/LiquidCrystal/examples/SerialDisplay/SerialDisplay.pde new file mode 100644 index 0000000..a094c24 --- /dev/null +++ b/arduino-0018-linux/libraries/LiquidCrystal/examples/SerialDisplay/SerialDisplay.pde @@ -0,0 +1,62 @@ +/* + LiquidCrystal Library - Serial Input + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch displays text sent over the serial port + (e.g. from the Serial Monitor) on an attached LCD. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe +modified 25 July 2009 + by David A. Mellis + + http://www.arduino.cc/en/Tutorial/LiquidCrystal + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +void setup(){ + // set up the LCD's number of rows and columns: + lcd.begin(16, 2); + // initialize the serial communications: + Serial.begin(9600); +} + +void loop() +{ + // when characters arrive over the serial port... + if (Serial.available()) { + // wait a bit for the entire message to arrive + delay(100); + // clear the screen + lcd.clear(); + // read all the available characters + while (Serial.available() > 0) { + // display each character to the LCD + lcd.write(Serial.read()); + } + } +} diff --git a/arduino-0018-linux/libraries/LiquidCrystal/examples/TextDirection/TextDirection.pde b/arduino-0018-linux/libraries/LiquidCrystal/examples/TextDirection/TextDirection.pde new file mode 100644 index 0000000..725eb0d --- /dev/null +++ b/arduino-0018-linux/libraries/LiquidCrystal/examples/TextDirection/TextDirection.pde @@ -0,0 +1,84 @@ + /* + LiquidCrystal Library - TextDirection + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch demonstrates how to use leftToRight() and rightToLeft() + to move the cursor. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 25 July 2009 + by David A. Mellis + + http://www.arduino.cc/en/Tutorial/LiquidCrystal + + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +int thisChar = 'a'; + +void setup() { + // set up the LCD's number of rows and columns: + lcd.begin(16, 2); + // turn on the cursor: + lcd.cursor(); + Serial.begin(9600); +} + +void loop() { + // reverse directions at 'm': + if (thisChar == 'm') { + // go right for the next letter + lcd.rightToLeft(); + } + // reverse again at 's': + if (thisChar == 's') { + // go left for the next letter + lcd.leftToRight(); + } + // reset at 'z': + if (thisChar > 'z') { + // go to (0,0): + lcd.home(); + // start again at 0 + thisChar = 'a'; + } + // print the character + lcd.print(thisChar, BYTE); + // wait a second: + delay(1000); + // increment the letter: + thisChar++; +} + + + + + + + + diff --git a/arduino-0018-linux/libraries/LiquidCrystal/examples/setCursor/setCursor.pde b/arduino-0018-linux/libraries/LiquidCrystal/examples/setCursor/setCursor.pde new file mode 100644 index 0000000..edd2e77 --- /dev/null +++ b/arduino-0018-linux/libraries/LiquidCrystal/examples/setCursor/setCursor.pde @@ -0,0 +1,68 @@ +/* + LiquidCrystal Library - setCursor + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints to all the positions of the LCD using the + setCursor(0 method: + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 25 July 2009 + by David A. Mellis + + http://www.arduino.cc/en/Tutorial/LiquidCrystal + */ + +// include the library code: +#include + +// these constants won't change. But you can change the size of +// your LCD using them: +const int numRows = 2; +const int numCols = 16; + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +void setup() { + // set up the LCD's number of rows and columns: + lcd.begin(numRows, numCols); +} + +void loop() { + // loop from ASCII 'a' to ASCII 'z': + for (int thisLetter = 'a'; thisLetter <= 'z'; thisLetter++) { + // loop over the columns: + for (int thisCol = 0; thisCol < numRows; thisCol++) { + // loop over the rows: + for (int thisRow = 0; thisRow < numCols; thisRow++) { + // set the cursor position: + lcd.setCursor(thisRow,thisCol); + // print the letter: + lcd.print(thisLetter, BYTE); + delay(200); + } + } + } +} + + diff --git a/arduino-0018-linux/libraries/LiquidCrystal/keywords.txt b/arduino-0018-linux/libraries/LiquidCrystal/keywords.txt new file mode 100755 index 0000000..132845c --- /dev/null +++ b/arduino-0018-linux/libraries/LiquidCrystal/keywords.txt @@ -0,0 +1,37 @@ +####################################### +# Syntax Coloring Map For LiquidCrystal +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +LiquidCrystal KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +begin KEYWORD2 +clear KEYWORD2 +home KEYWORD2 +print KEYWORD2 +setCursor KEYWORD2 +cursor KEYWORD2 +noCursor KEYWORD2 +blink KEYWORD2 +noBlink KEYWORD2 +display KEYWORD2 +noDisplay KEYWORD2 +autoscroll KEYWORD2 +noAutoscroll KEYWORD2 +leftToRight KEYWORD2 +rightToLeft KEYWORD2 +scrollDisplayLeft KEYWORD2 +scrollDisplayRight KEYWORD2 +createChar KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### + diff --git a/arduino-0018-linux/libraries/Matrix/Matrix.cpp b/arduino-0018-linux/libraries/Matrix/Matrix.cpp new file mode 100755 index 0000000..2eb3e25 --- /dev/null +++ b/arduino-0018-linux/libraries/Matrix/Matrix.cpp @@ -0,0 +1,229 @@ +/* + Matrix.cpp - Max7219 LED Matrix library for Arduino & Wiring + Copyright (c) 2006 Nicholas Zambetti. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +// TODO: Support segment displays in api? +// TODO: Support varying vendor layouts? + +/****************************************************************************** + * Includes + ******************************************************************************/ + +extern "C" { + // AVR LibC Includes + #include + #include + + // Wiring Core Includes + #undef abs + #include "WConstants.h" + + // Wiring Core Prototypes + //void pinMode(uint8_t, uint8_t); + //void digitalWrite(int, uint8_t); +} + +#include "Sprite.h" +#include "Matrix.h" + +/****************************************************************************** + * Definitions + ******************************************************************************/ + +// Matrix registers +#define REG_NOOP 0x00 +#define REG_DIGIT0 0x01 +#define REG_DIGIT1 0x02 +#define REG_DIGIT2 0x03 +#define REG_DIGIT3 0x04 +#define REG_DIGIT4 0x05 +#define REG_DIGIT5 0x06 +#define REG_DIGIT6 0x07 +#define REG_DIGIT7 0x08 +#define REG_DECODEMODE 0x09 +#define REG_INTENSITY 0x0A +#define REG_SCANLIMIT 0x0B +#define REG_SHUTDOWN 0x0C +#define REG_DISPLAYTEST 0x0F + +/****************************************************************************** + * Constructors + ******************************************************************************/ + +Matrix::Matrix(uint8_t data, uint8_t clock, uint8_t load, uint8_t screens /* = 1 */) +{ + // record pins for sw spi + _pinData = data; + _pinClock = clock; + _pinLoad = load; + + // set ddr for sw spi pins + pinMode(_pinClock, OUTPUT); + pinMode(_pinData, OUTPUT); + pinMode(_pinLoad, OUTPUT); + + // allocate screenbuffers + _screens = screens; + _buffer = (uint8_t*)calloc(_screens, 64); + _maximumX = (_screens * 8); + + // initialize registers + clear(); // clear display + setScanLimit(0x07); // use all rows/digits + setBrightness(0x0F); // maximum brightness + setRegister(REG_SHUTDOWN, 0x01); // normal operation + setRegister(REG_DECODEMODE, 0x00); // pixels not integers + setRegister(REG_DISPLAYTEST, 0x00); // not in test mode +} + +/****************************************************************************** + * MAX7219 SPI + ******************************************************************************/ + +// sends a single byte by sw spi (no latching) +void Matrix::putByte(uint8_t data) +{ + uint8_t i = 8; + uint8_t mask; + while(i > 0) { + mask = 0x01 << (i - 1); // get bitmask + digitalWrite(_pinClock, LOW); // tick + if (data & mask){ // choose bit + digitalWrite(_pinData, HIGH); // set 1 + }else{ + digitalWrite(_pinData, LOW); // set 0 + } + digitalWrite(_pinClock, HIGH); // tock + --i; // move to lesser bit + } +} + +// sets register to a byte value for all screens +void Matrix::setRegister(uint8_t reg, uint8_t data) +{ + digitalWrite(_pinLoad, LOW); // begin + for(uint8_t i = 0; i < _screens; ++i){ + putByte(reg); // specify register + putByte(data); // send data + } + digitalWrite(_pinLoad, HIGH); // latch in data + digitalWrite(_pinLoad, LOW); // end +} + +// syncs row of display with buffer +void Matrix::syncRow(uint8_t row) +{ + if (!_buffer) return; + + // uint8_t's can't be negative, so don't test for negative row + if (row >= 8) return; + digitalWrite(_pinLoad, LOW); // begin + for(uint8_t i = 0; i < _screens; ++i){ + putByte(8 - row); // specify register + putByte(_buffer[row + (8 * i)]); // send data + } + digitalWrite(_pinLoad, HIGH); // latch in data + digitalWrite(_pinLoad, LOW); // end +} + +/****************************************************************************** + * MAX7219 Configuration + ******************************************************************************/ + +// sets how many digits are displayed +void Matrix::setScanLimit(uint8_t value) +{ + setRegister(REG_SCANLIMIT, value & 0x07); +} + +// sets brightness of the display +void Matrix::setBrightness(uint8_t value) +{ + setRegister(REG_INTENSITY, value & 0x0F); +} + +/****************************************************************************** + * Helper Functions + ******************************************************************************/ + +void Matrix::buffer(uint8_t x, uint8_t y, uint8_t value) +{ + if (!_buffer) return; + + // uint8_t's can't be negative, so don't test for negative x and y. + if (x >= _maximumX || y >= 8) return; + + uint8_t offset = x; // record x + x %= 8; // make x relative to a single matrix + offset -= x; // calculate buffer offset + + // wrap shift relative x for nexus module layout + if (x == 0){ + x = 8; + } + --x; + + // record value in buffer + if(value){ + _buffer[y + offset] |= 0x01 << x; + }else{ + _buffer[y + offset] &= ~(0x01 << x); + } +} + +/****************************************************************************** + * User API + ******************************************************************************/ + +// buffers and writes to screen +void Matrix::write(uint8_t x, uint8_t y, uint8_t value) +{ + buffer(x, y, value); + + // update affected row + syncRow(y); +} + +void Matrix::write(uint8_t x, uint8_t y, Sprite sprite) +{ + for (uint8_t i = 0; i < sprite.height(); i++){ + for (uint8_t j = 0; j < sprite.width(); j++) + buffer(x + j, y + i, sprite.read(j, i)); + + syncRow(y + i); + } +} + +// clears screens and buffers +void Matrix::clear(void) +{ + if (!_buffer) return; + + // clear buffer + for(uint8_t i = 0; i < 8; ++i){ + for(uint8_t j = 0; j < _screens; ++j){ + _buffer[i + (8 * j)] = 0x00; + } + } + + // clear registers + for(uint8_t i = 0; i < 8; ++i){ + syncRow(i); + } +} + diff --git a/arduino-0018-linux/libraries/Matrix/Matrix.h b/arduino-0018-linux/libraries/Matrix/Matrix.h new file mode 100755 index 0000000..7c6be91 --- /dev/null +++ b/arduino-0018-linux/libraries/Matrix/Matrix.h @@ -0,0 +1,54 @@ +/* + Matrix.h - Max7219 LED Matrix library for Arduino & Wiring + Copyright (c) 2006 Nicholas Zambetti. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef Matrix_h +#define Matrix_h + +#include + +class Sprite; + +class Matrix +{ + private: + uint8_t _pinData; + uint8_t _pinClock; + uint8_t _pinLoad; + + uint8_t* _buffer; + uint8_t _screens; + uint8_t _maximumX; + + void putByte(uint8_t); + void setRegister(uint8_t, uint8_t); + void syncRow(uint8_t); + + void setScanLimit(uint8_t); + + void buffer(uint8_t, uint8_t, uint8_t); + public: + Matrix(uint8_t, uint8_t, uint8_t, uint8_t = 1); + void setBrightness(uint8_t); + void write(uint8_t, uint8_t, uint8_t); + void write(uint8_t, uint8_t, Sprite); + void clear(void); +}; + +#endif + diff --git a/arduino-0018-linux/libraries/Matrix/examples/hello_matrix/hello_matrix.pde b/arduino-0018-linux/libraries/Matrix/examples/hello_matrix/hello_matrix.pde new file mode 100644 index 0000000..127917f --- /dev/null +++ b/arduino-0018-linux/libraries/Matrix/examples/hello_matrix/hello_matrix.pde @@ -0,0 +1,42 @@ +#include +#include + +// Hello Matrix +// by Nicholas Zambetti + +// Demonstrates the use of the Matrix library +// For MAX7219 LED Matrix Controllers +// Blinks welcoming face on screen + +// Created 13 February 2006 + +/* create a new Matrix instance + pin 0: data (din) + pin 1: load (load) + pin 2: clock (clk) +*/ +Matrix myMatrix = Matrix(0, 2, 1); + +void setup() +{ +} + +void loop() +{ + myMatrix.clear(); // clear display + + delay(1000); + + // turn some pixels on + myMatrix.write(1, 5, HIGH); + myMatrix.write(2, 2, HIGH); + myMatrix.write(2, 6, HIGH); + myMatrix.write(3, 6, HIGH); + myMatrix.write(4, 6, HIGH); + myMatrix.write(5, 2, HIGH); + myMatrix.write(5, 6, HIGH); + myMatrix.write(6, 5, HIGH); + + delay(1000); +} + diff --git a/arduino-0018-linux/libraries/Matrix/examples/sprite_animation/sprite_animation.pde b/arduino-0018-linux/libraries/Matrix/examples/sprite_animation/sprite_animation.pde new file mode 100644 index 0000000..bf7c6f5 --- /dev/null +++ b/arduino-0018-linux/libraries/Matrix/examples/sprite_animation/sprite_animation.pde @@ -0,0 +1,48 @@ +#include +#include + +// Sprite Animation +// by Nicholas Zambetti + +// Demonstrates the use of the Matrix & Sprite libraries +// Displays animated waveform graphic on screen + +// Created 29 March 2006 + +/* create a new Matrix instance + pin 0: data (din) + pin 1: load (load) + pin 2: clock (clk) +*/ +Matrix myMatrix = Matrix(0, 2, 1); + +/* create a new Sprite instance + 8 pixels wide, 4 pixels tall +*/ +Sprite wave = Sprite( + 8, 4, + B00011000, + B00100100, + B01000010, + B10000001 +); + +void setup() +{ +} + +int x = 0; + +void loop() +{ + myMatrix.write(x, 2, wave); // place sprite on screen + myMatrix.write(x - 8, 2, wave); // place sprite again, elsewhere on screen + delay(75); // wait a little bit + myMatrix.clear(); // clear the screen for next animation frame + if(x == 8) // if reached end of animation sequence + { + x = 0; // start from beginning + } + x++; // advance x coordinate to the right +} + diff --git a/arduino-0018-linux/libraries/Matrix/keywords.txt b/arduino-0018-linux/libraries/Matrix/keywords.txt new file mode 100644 index 0000000..b784f87 --- /dev/null +++ b/arduino-0018-linux/libraries/Matrix/keywords.txt @@ -0,0 +1,22 @@ +####################################### +# Syntax Coloring Map For Matrix +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +Matrix KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +setBrightness KEYWORD2 +write KEYWORD2 +clear KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### + diff --git a/arduino-0018-linux/libraries/Servo/Servo.cpp b/arduino-0018-linux/libraries/Servo/Servo.cpp new file mode 100755 index 0000000..44e5aa5 --- /dev/null +++ b/arduino-0018-linux/libraries/Servo/Servo.cpp @@ -0,0 +1,337 @@ +/* + Servo.cpp - Interrupt driven Servo library for Arduino using 16 bit timers- Version 2 + Copyright (c) 2009 Michael Margolis. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* + + A servo is activated by creating an instance of the Servo class passing the desired pin to the attach() method. + The servos are pulsed in the background using the value most recently written using the write() method + + Note that analogWrite of PWM on pins associated with the timer are disabled when the first servo is attached. + Timers are seized as needed in groups of 12 servos - 24 servos use two timers, 48 servos will use four. + + The methods are: + + Servo - Class for manipulating servo motors connected to Arduino pins. + + attach(pin ) - Attaches a servo motor to an i/o pin. + attach(pin, min, max ) - Attaches to a pin setting min and max values in microseconds + default min is 544, max is 2400 + + write() - Sets the servo angle in degrees. (invalid angle that is valid as pulse in microseconds is treated as microseconds) + writeMicroseconds() - Sets the servo pulse width in microseconds + read() - Gets the last written servo pulse width as an angle between 0 and 180. + readMicroseconds() - Gets the last written servo pulse width in microseconds. (was read_us() in first release) + attached() - Returns true if there is a servo attached. + detach() - Stops an attached servos from pulsing its i/o pin. + +*/ + +#include +#include + +#include "Servo.h" + +#define usToTicks(_us) (( clockCyclesPerMicrosecond()* _us) / 8) // converts microseconds to tick (assumes prescale of 8) // 12 Aug 2009 +#define ticksToUs(_ticks) (( (unsigned)_ticks * 8)/ clockCyclesPerMicrosecond() ) // converts from ticks back to microseconds + + +#define TRIM_DURATION 2 // compensation ticks to trim adjust for digitalWrite delays // 12 August 2009 + +//#define NBR_TIMERS (MAX_SERVOS / SERVOS_PER_TIMER) + +static servo_t servos[MAX_SERVOS]; // static array of servo structures +static volatile int8_t Channel[_Nbr_16timers ]; // counter for the servo being pulsed for each timer (or -1 if refresh interval) + +uint8_t ServoCount = 0; // the total number of attached servos + + +// convenience macros +#define SERVO_INDEX_TO_TIMER(_servo_nbr) ((timer16_Sequence_t)(_servo_nbr / SERVOS_PER_TIMER)) // returns the timer controlling this servo +#define SERVO_INDEX_TO_CHANNEL(_servo_nbr) (_servo_nbr % SERVOS_PER_TIMER) // returns the index of the servo on this timer +#define SERVO_INDEX(_timer,_channel) ((_timer*SERVOS_PER_TIMER) + _channel) // macro to access servo index by timer and channel +#define SERVO(_timer,_channel) (servos[SERVO_INDEX(_timer,_channel)]) // macro to access servo class by timer and channel + +#define SERVO_MIN() (MIN_PULSE_WIDTH - this->min * 4) // minimum value in uS for this servo +#define SERVO_MAX() (MAX_PULSE_WIDTH - this->max * 4) // maximum value in uS for this servo + +/************ static functions common to all instances ***********************/ + +static inline void handle_interrupts(timer16_Sequence_t timer, volatile uint16_t *TCNTn, volatile uint16_t* OCRnA) +{ + if( Channel[timer] < 0 ) + *TCNTn = 0; // channel set to -1 indicated that refresh interval completed so reset the timer + else{ + if( SERVO_INDEX(timer,Channel[timer]) < ServoCount && SERVO(timer,Channel[timer]).Pin.isActive == true ) + digitalWrite( SERVO(timer,Channel[timer]).Pin.nbr,LOW); // pulse this channel low if activated + } + + Channel[timer]++; // increment to the next channel + if( SERVO_INDEX(timer,Channel[timer]) < ServoCount && Channel[timer] < SERVOS_PER_TIMER) { + *OCRnA = *TCNTn + SERVO(timer,Channel[timer]).ticks; + if(SERVO(timer,Channel[timer]).Pin.isActive == true) // check if activated + digitalWrite( SERVO(timer,Channel[timer]).Pin.nbr,HIGH); // its an active channel so pulse it high + } + else { + // finished all channels so wait for the refresh period to expire before starting over + if( (unsigned)*TCNTn < (usToTicks(REFRESH_INTERVAL) + 4) ) // allow a few ticks to ensure the next OCR1A not missed + *OCRnA = (unsigned int)usToTicks(REFRESH_INTERVAL); + else + *OCRnA = *TCNTn + 4; // at least REFRESH_INTERVAL has elapsed + Channel[timer] = -1; // this will get incremented at the end of the refresh period to start again at the first channel + } +} + +#ifndef WIRING // Wiring pre-defines signal handlers so don't define any if compiling for the Wiring platform +// Interrupt handlers for Arduino +#if defined(_useTimer1) +SIGNAL (TIMER1_COMPA_vect) +{ + handle_interrupts(_timer1, &TCNT1, &OCR1A); +} +#endif + +#if defined(_useTimer3) +SIGNAL (TIMER3_COMPA_vect) +{ + handle_interrupts(_timer3, &TCNT3, &OCR3A); +} +#endif + +#if defined(_useTimer4) +SIGNAL (TIMER4_COMPA_vect) +{ + handle_interrupts(_timer4, &TCNT4, &OCR4A); +} +#endif + +#if defined(_useTimer5) +SIGNAL (TIMER5_COMPA_vect) +{ + handle_interrupts(_timer5, &TCNT5, &OCR5A); +} +#endif + +#elif defined WIRING +// Interrupt handlers for Wiring +#if defined(_useTimer1) +void Timer1Service() +{ + handle_interrupts(_timer1, &TCNT1, &OCR1A); +} +#endif +#if defined(_useTimer3) +void Timer3Service() +{ + handle_interrupts(_timer3, &TCNT3, &OCR3A); +} +#endif +#endif + + +static void initISR(timer16_Sequence_t timer) +{ +#if defined (_useTimer1) + if(timer == _timer1) { + TCCR1A = 0; // normal counting mode + TCCR1B = _BV(CS11); // set prescaler of 8 + TCNT1 = 0; // clear the timer count +#if defined(__AVR_ATmega8__)|| defined(__AVR_ATmega128__) + TIFR |= _BV(OCF1A); // clear any pending interrupts; + TIMSK |= _BV(OCIE1A) ; // enable the output compare interrupt +#else + // here if not ATmega8 or ATmega128 + TIFR1 |= _BV(OCF1A); // clear any pending interrupts; + TIMSK1 |= _BV(OCIE1A) ; // enable the output compare interrupt +#endif +#if defined(WIRING) + timerAttach(TIMER1OUTCOMPAREA_INT, Timer1Service); +#endif + } +#endif + +#if defined (_useTimer3) + if(timer == _timer3) { + TCCR3A = 0; // normal counting mode + TCCR3B = _BV(CS31); // set prescaler of 8 + TCNT3 = 0; // clear the timer count +#if defined(__AVR_ATmega128__) + TIFR |= _BV(OCF3A); // clear any pending interrupts; + ETIMSK |= _BV(OCIE3A); // enable the output compare interrupt +#else + TIFR3 = _BV(OCF3A); // clear any pending interrupts; + TIMSK3 = _BV(OCIE3A) ; // enable the output compare interrupt +#endif +#if defined(WIRING) + timerAttach(TIMER3OUTCOMPAREA_INT, Timer3Service); // for Wiring platform only +#endif + } +#endif + +#if defined (_useTimer4) + if(timer == _timer4) { + TCCR4A = 0; // normal counting mode + TCCR4B = _BV(CS41); // set prescaler of 8 + TCNT4 = 0; // clear the timer count + TIFR4 = _BV(OCF4A); // clear any pending interrupts; + TIMSK4 = _BV(OCIE4A) ; // enable the output compare interrupt + } +#endif + +#if defined (_useTimer5) + if(timer == _timer5) { + TCCR5A = 0; // normal counting mode + TCCR5B = _BV(CS51); // set prescaler of 8 + TCNT5 = 0; // clear the timer count + TIFR5 = _BV(OCF5A); // clear any pending interrupts; + TIMSK5 = _BV(OCIE5A) ; // enable the output compare interrupt + } +#endif +} + +static void finISR(timer16_Sequence_t timer) +{ + //disable use of the given timer +#if defined WIRING // Wiring + if(timer == _timer1) { + #if defined(__AVR_ATmega1281__)||defined(__AVR_ATmega2561__) + TIMSK1 &= ~_BV(OCIE1A) ; // disable timer 1 output compare interrupt + #else + TIMSK &= ~_BV(OCIE1A) ; // disable timer 1 output compare interrupt + #endif + timerDetach(TIMER1OUTCOMPAREA_INT); + } + else if(timer == _timer3) { + #if defined(__AVR_ATmega1281__)||defined(__AVR_ATmega2561__) + TIMSK3 &= ~_BV(OCIE3A); // disable the timer3 output compare A interrupt + #else + ETIMSK &= ~_BV(OCIE3A); // disable the timer3 output compare A interrupt + #endif + timerDetach(TIMER3OUTCOMPAREA_INT); + } +#else + //For arduino - in future: call here to a currently undefined function to reset the timer +#endif +} + +static boolean isTimerActive(timer16_Sequence_t timer) +{ + // returns true if any servo is active on this timer + for(uint8_t channel=0; channel < SERVOS_PER_TIMER; channel++) { + if(SERVO(timer,channel).Pin.isActive == true) + return true; + } + return false; +} + + +/****************** end of static functions ******************************/ + +Servo::Servo() +{ + if( ServoCount < MAX_SERVOS) { + this->servoIndex = ServoCount++; // assign a servo index to this instance + servos[this->servoIndex].ticks = usToTicks(DEFAULT_PULSE_WIDTH); // store default values - 12 Aug 2009 + } + else + this->servoIndex = INVALID_SERVO ; // too many servos +} + +uint8_t Servo::attach(int pin) +{ + return this->attach(pin, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH); +} + +uint8_t Servo::attach(int pin, int min, int max) +{ + if(this->servoIndex < MAX_SERVOS ) { + pinMode( pin, OUTPUT) ; // set servo pin to output + servos[this->servoIndex].Pin.nbr = pin; + // todo min/max check: abs(min - MIN_PULSE_WIDTH) /4 < 128 + this->min = (MIN_PULSE_WIDTH - min)/4; //resolution of min/max is 4 uS + this->max = (MAX_PULSE_WIDTH - max)/4; + // initialize the timer if it has not already been initialized + timer16_Sequence_t timer = SERVO_INDEX_TO_TIMER(servoIndex); + if(isTimerActive(timer) == false) + initISR(timer); + servos[this->servoIndex].Pin.isActive = true; // this must be set after the check for isTimerActive + } + return this->servoIndex ; +} + +void Servo::detach() +{ + servos[this->servoIndex].Pin.isActive = false; + timer16_Sequence_t timer = SERVO_INDEX_TO_TIMER(servoIndex); + if(isTimerActive(timer) == false) { + finISR(timer); + } +} + +void Servo::write(int value) +{ + if(value < MIN_PULSE_WIDTH) + { // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds) + if(value < 0) value = 0; + if(value > 180) value = 180; + value = map(value, 0, 180, SERVO_MIN(), SERVO_MAX()); + } + this->writeMicroseconds(value); +} + +void Servo::writeMicroseconds(int value) +{ + // calculate and store the values for the given channel + byte channel = this->servoIndex; + if( (channel >= 0) && (channel < MAX_SERVOS) ) // ensure channel is valid + { + if( value < SERVO_MIN() ) // ensure pulse width is valid + value = SERVO_MIN(); + else if( value > SERVO_MAX() ) + value = SERVO_MAX(); + + value = value - TRIM_DURATION; + value = usToTicks(value); // convert to ticks after compensating for interrupt overhead - 12 Aug 2009 + + uint8_t oldSREG = SREG; + cli(); + servos[channel].ticks = value; + SREG = oldSREG; + } +} + +int Servo::read() // return the value as degrees +{ + return map( this->readMicroseconds()+1, SERVO_MIN(), SERVO_MAX(), 0, 180); +} + +int Servo::readMicroseconds() +{ + unsigned int pulsewidth; + if( this->servoIndex != INVALID_SERVO ) + pulsewidth = ticksToUs(servos[this->servoIndex].ticks) + TRIM_DURATION ; // 12 aug 2009 + else + pulsewidth = 0; + + return pulsewidth; +} + +bool Servo::attached() +{ + return servos[this->servoIndex].Pin.isActive ; +} diff --git a/arduino-0018-linux/libraries/Servo/Servo.h b/arduino-0018-linux/libraries/Servo/Servo.h new file mode 100755 index 0000000..7d608b3 --- /dev/null +++ b/arduino-0018-linux/libraries/Servo/Servo.h @@ -0,0 +1,127 @@ +/* + Servo.h - Interrupt driven Servo library for Arduino using 16 bit timers- Version 2 + Copyright (c) 2009 Michael Margolis. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +/* + + A servo is activated by creating an instance of the Servo class passing the desired pin to the attach() method. + The servos are pulsed in the background using the value most recently written using the write() method + + Note that analogWrite of PWM on pins associated with the timer are disabled when the first servo is attached. + Timers are seized as needed in groups of 12 servos - 24 servos use two timers, 48 servos will use four. + The sequence used to sieze timers is defined in timers.h + + The methods are: + + Servo - Class for manipulating servo motors connected to Arduino pins. + + attach(pin ) - Attaches a servo motor to an i/o pin. + attach(pin, min, max ) - Attaches to a pin setting min and max values in microseconds + default min is 544, max is 2400 + + write() - Sets the servo angle in degrees. (invalid angle that is valid as pulse in microseconds is treated as microseconds) + writeMicroseconds() - Sets the servo pulse width in microseconds + read() - Gets the last written servo pulse width as an angle between 0 and 180. + readMicroseconds() - Gets the last written servo pulse width in microseconds. (was read_us() in first release) + attached() - Returns true if there is a servo attached. + detach() - Stops an attached servos from pulsing its i/o pin. + */ + +#ifndef Servo_h +#define Servo_h + +#include + +/* + * Defines for 16 bit timers used with Servo library + * + * If _useTimerX is defined then TimerX is a 16 bit timer on the curent board + * timer16_Sequence_t enumerates the sequence that the timers should be allocated + * _Nbr_16timers indicates how many 16 bit timers are available. + * + */ + +// Say which 16 bit timers can be used and in what order +#if defined(__AVR_ATmega1280__) +#define _useTimer5 +#define _useTimer1 +#define _useTimer3 +#define _useTimer4 +typedef enum { _timer5, _timer1, _timer3, _timer4, _Nbr_16timers } timer16_Sequence_t ; + +#elif defined(__AVR_ATmega32U4__) +#define _useTimer3 +#define _useTimer1 +typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ; + +#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) +#define _useTimer3 +#define _useTimer1 +typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ; + +#elif defined(__AVR_ATmega128__) ||defined(__AVR_ATmega1281__)||defined(__AVR_ATmega2561__) +#define _useTimer3 +#define _useTimer1 +typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ; + +#else // everything else +#define _useTimer1 +typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ; +#endif + +#define Servo_VERSION 2 // software version of this library + +#define MIN_PULSE_WIDTH 544 // the shortest pulse sent to a servo +#define MAX_PULSE_WIDTH 2400 // the longest pulse sent to a servo +#define DEFAULT_PULSE_WIDTH 1500 // default pulse width when servo is attached +#define REFRESH_INTERVAL 20000 // minumim time to refresh servos in microseconds + +#define SERVOS_PER_TIMER 12 // the maximum number of servos controlled by one timer +#define MAX_SERVOS (_Nbr_16timers * SERVOS_PER_TIMER) + +#define INVALID_SERVO 255 // flag indicating an invalid servo index + +typedef struct { + uint8_t nbr :6 ; // a pin number from 0 to 63 + uint8_t isActive :1 ; // true if this channel is enabled, pin not pulsed if false +} ServoPin_t ; + +typedef struct { + ServoPin_t Pin; + unsigned int ticks; +} servo_t; + +class Servo +{ +public: + Servo(); + uint8_t attach(int pin); // attach the given pin to the next free channel, sets pinMode, returns channel number or 0 if failure + uint8_t attach(int pin, int min, int max); // as above but also sets min and max values for writes. + void detach(); + void write(int value); // if value is < 200 its treated as an angle, otherwise as pulse width in microseconds + void writeMicroseconds(int value); // Write pulse width in microseconds + int read(); // returns current pulse width as an angle between 0 and 180 degrees + int readMicroseconds(); // returns current pulse width in microseconds for this servo (was read_us() in first release) + bool attached(); // return true if this servo is attached, otherwise false +private: + uint8_t servoIndex; // index into the channel data for this servo + int8_t min; // minimum is this value times 4 added to MIN_PULSE_WIDTH + int8_t max; // maximum is this value times 4 added to MAX_PULSE_WIDTH +}; + +#endif \ No newline at end of file diff --git a/arduino-0018-linux/libraries/Servo/examples/Knob/Knob.pde b/arduino-0018-linux/libraries/Servo/examples/Knob/Knob.pde new file mode 100644 index 0000000..886e107 --- /dev/null +++ b/arduino-0018-linux/libraries/Servo/examples/Knob/Knob.pde @@ -0,0 +1,22 @@ +// Controlling a servo position using a potentiometer (variable resistor) +// by Michal Rinott + +#include + +Servo myservo; // create servo object to control a servo + +int potpin = 0; // analog pin used to connect the potentiometer +int val; // variable to read the value from the analog pin + +void setup() +{ + myservo.attach(9); // attaches the servo on pin 9 to the servo object +} + +void loop() +{ + val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023) + val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180) + myservo.write(val); // sets the servo position according to the scaled value + delay(15); // waits for the servo to get there +} diff --git a/arduino-0018-linux/libraries/Servo/examples/Sweep/Sweep.pde b/arduino-0018-linux/libraries/Servo/examples/Sweep/Sweep.pde new file mode 100644 index 0000000..52e6056 --- /dev/null +++ b/arduino-0018-linux/libraries/Servo/examples/Sweep/Sweep.pde @@ -0,0 +1,29 @@ +// Sweep +// by BARRAGAN + +#include + +Servo myservo; // create servo object to control a servo + // a maximum of eight servo objects can be created + +int pos = 0; // variable to store the servo position + +void setup() +{ + myservo.attach(9); // attaches the servo on pin 9 to the servo object +} + + +void loop() +{ + for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees + { // in steps of 1 degree + myservo.write(pos); // tell servo to go to position in variable 'pos' + delay(15); // waits 15ms for the servo to reach the position + } + for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees + { + myservo.write(pos); // tell servo to go to position in variable 'pos' + delay(15); // waits 15ms for the servo to reach the position + } +} diff --git a/arduino-0018-linux/libraries/Servo/keywords.txt b/arduino-0018-linux/libraries/Servo/keywords.txt new file mode 100755 index 0000000..ca5ba79 --- /dev/null +++ b/arduino-0018-linux/libraries/Servo/keywords.txt @@ -0,0 +1,24 @@ +####################################### +# Syntax Coloring Map Servo +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +Servo KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### +attach KEYWORD2 +detach KEYWORD2 +write KEYWORD2 +read KEYWORD2 +attached KEYWORD2 +writeMicroseconds KEYWORD2 +readMicroseconds KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### diff --git a/arduino-0018-linux/libraries/SoftwareSerial/SoftwareSerial.cpp b/arduino-0018-linux/libraries/SoftwareSerial/SoftwareSerial.cpp new file mode 100755 index 0000000..6df04d2 --- /dev/null +++ b/arduino-0018-linux/libraries/SoftwareSerial/SoftwareSerial.cpp @@ -0,0 +1,227 @@ +/* + SoftwareSerial.cpp - Software serial library + Copyright (c) 2006 David A. Mellis. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +/****************************************************************************** + * Includes + ******************************************************************************/ + +#include "WConstants.h" +#include "SoftwareSerial.h" + +/****************************************************************************** + * Definitions + ******************************************************************************/ + +/****************************************************************************** + * Constructors + ******************************************************************************/ + +SoftwareSerial::SoftwareSerial(uint8_t receivePin, uint8_t transmitPin) +{ + _receivePin = receivePin; + _transmitPin = transmitPin; + _baudRate = 0; +} + +/****************************************************************************** + * User API + ******************************************************************************/ + +void SoftwareSerial::begin(long speed) +{ + _baudRate = speed; + _bitPeriod = 1000000 / _baudRate; + + digitalWrite(_transmitPin, HIGH); + delayMicroseconds( _bitPeriod); // if we were low this establishes the end +} + +int SoftwareSerial::read() +{ + int val = 0; + int bitDelay = _bitPeriod - clockCyclesToMicroseconds(50); + + // one byte of serial data (LSB first) + // ...--\ /--\/--\/--\/--\/--\/--\/--\/--\/--... + // \--/\--/\--/\--/\--/\--/\--/\--/\--/ + // start 0 1 2 3 4 5 6 7 stop + + while (digitalRead(_receivePin)); + + // confirm that this is a real start bit, not line noise + if (digitalRead(_receivePin) == LOW) { + // frame start indicated by a falling edge and low start bit + // jump to the middle of the low start bit + delayMicroseconds(bitDelay / 2 - clockCyclesToMicroseconds(50)); + + // offset of the bit in the byte: from 0 (LSB) to 7 (MSB) + for (int offset = 0; offset < 8; offset++) { + // jump to middle of next bit + delayMicroseconds(bitDelay); + + // read bit + val |= digitalRead(_receivePin) << offset; + } + + delayMicroseconds(_bitPeriod); + + return val; + } + + return -1; +} + +void SoftwareSerial::print(uint8_t b) +{ + if (_baudRate == 0) + return; + + int bitDelay = _bitPeriod - clockCyclesToMicroseconds(50); // a digitalWrite is about 50 cycles + byte mask; + + digitalWrite(_transmitPin, LOW); + delayMicroseconds(bitDelay); + + for (mask = 0x01; mask; mask <<= 1) { + if (b & mask){ // choose bit + digitalWrite(_transmitPin,HIGH); // send 1 + } + else{ + digitalWrite(_transmitPin,LOW); // send 1 + } + delayMicroseconds(bitDelay); + } + + digitalWrite(_transmitPin, HIGH); + delayMicroseconds(bitDelay); +} + +void SoftwareSerial::print(const char *s) +{ + while (*s) + print(*s++); +} + +void SoftwareSerial::print(char c) +{ + print((uint8_t) c); +} + +void SoftwareSerial::print(int n) +{ + print((long) n); +} + +void SoftwareSerial::print(unsigned int n) +{ + print((unsigned long) n); +} + +void SoftwareSerial::print(long n) +{ + if (n < 0) { + print('-'); + n = -n; + } + printNumber(n, 10); +} + +void SoftwareSerial::print(unsigned long n) +{ + printNumber(n, 10); +} + +void SoftwareSerial::print(long n, int base) +{ + if (base == 0) + print((char) n); + else if (base == 10) + print(n); + else + printNumber(n, base); +} + +void SoftwareSerial::println(void) +{ + print('\r'); + print('\n'); +} + +void SoftwareSerial::println(char c) +{ + print(c); + println(); +} + +void SoftwareSerial::println(const char c[]) +{ + print(c); + println(); +} + +void SoftwareSerial::println(uint8_t b) +{ + print(b); + println(); +} + +void SoftwareSerial::println(int n) +{ + print(n); + println(); +} + +void SoftwareSerial::println(long n) +{ + print(n); + println(); +} + +void SoftwareSerial::println(unsigned long n) +{ + print(n); + println(); +} + +void SoftwareSerial::println(long n, int base) +{ + print(n, base); + println(); +} + +// Private Methods ///////////////////////////////////////////////////////////// + +void SoftwareSerial::printNumber(unsigned long n, uint8_t base) +{ + unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars. + unsigned long i = 0; + + if (n == 0) { + print('0'); + return; + } + + while (n > 0) { + buf[i++] = n % base; + n /= base; + } + + for (; i > 0; i--) + print((char) (buf[i - 1] < 10 ? '0' + buf[i - 1] : 'A' + buf[i - 1] - 10)); +} diff --git a/arduino-0018-linux/libraries/SoftwareSerial/SoftwareSerial.h b/arduino-0018-linux/libraries/SoftwareSerial/SoftwareSerial.h new file mode 100755 index 0000000..95753fc --- /dev/null +++ b/arduino-0018-linux/libraries/SoftwareSerial/SoftwareSerial.h @@ -0,0 +1,56 @@ +/* + SoftwareSerial.h - Software serial library + Copyright (c) 2006 David A. Mellis. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef SoftwareSerial_h +#define SoftwareSerial_h + +#include + +class SoftwareSerial +{ + private: + uint8_t _receivePin; + uint8_t _transmitPin; + long _baudRate; + int _bitPeriod; + void printNumber(unsigned long, uint8_t); + public: + SoftwareSerial(uint8_t, uint8_t); + void begin(long); + int read(); + void print(char); + void print(const char[]); + void print(uint8_t); + void print(int); + void print(unsigned int); + void print(long); + void print(unsigned long); + void print(long, int); + void println(void); + void println(char); + void println(const char[]); + void println(uint8_t); + void println(int); + void println(long); + void println(unsigned long); + void println(long, int); +}; + +#endif + diff --git a/arduino-0018-linux/libraries/SoftwareSerial/keywords.txt b/arduino-0018-linux/libraries/SoftwareSerial/keywords.txt new file mode 100644 index 0000000..de5a74c --- /dev/null +++ b/arduino-0018-linux/libraries/SoftwareSerial/keywords.txt @@ -0,0 +1,18 @@ +####################################### +# Syntax Coloring Map For Ultrasound +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +SoftwareSerial KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +####################################### +# Constants (LITERAL1) +####################################### + diff --git a/arduino-0018-linux/libraries/Sprite/Sprite.cpp b/arduino-0018-linux/libraries/Sprite/Sprite.cpp new file mode 100644 index 0000000..6055876 --- /dev/null +++ b/arduino-0018-linux/libraries/Sprite/Sprite.cpp @@ -0,0 +1,95 @@ +/* + Sprite.cpp - 2D sprite buffer library for Arduino & Wiring + Copyright (c) 2006 David A. Mellis. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include +#include +//#include + +#include "Sprite.h" + +void Sprite::init(uint8_t width, uint8_t height) +{ + _width = width >= 8 ? 8 : width; + _height = height >= 8 ? 8 : height; + + // for now, do nothing if this allocation fails. methods that require it + // should silently fail if _buffer is null. + _buffer = (uint8_t *) calloc(_height, 1); +} + +Sprite::Sprite(uint8_t width, uint8_t height) +{ + init(width, height); +} + +Sprite::Sprite(uint8_t width, uint8_t height, uint8_t row, ...) +{ + init(width, height); + + if (!_buffer) return; + + va_list ap; + va_start(ap, row); + + int y = 0; + + for (y = 0; ; y++) { + for (int x = 0; x < width && x < 8; x++) + write(x, y, (row >> (width - x - 1)) & 0x01); + + if (y == height - 1) + break; + + row = va_arg(ap, int); // using '...' promotes uint8_t to int + } + + va_end(ap); +} + +uint8_t Sprite::width() const +{ + return _width; +} + +uint8_t Sprite::height() const +{ + return _height; +} + +void Sprite::write(uint8_t x, uint8_t y, uint8_t value) +{ + if (!_buffer) return; + + // uint8_t's can't be negative, so don't test for negative x and y. + if (x >= _width || y >= _height) return; + + // we need to bitwise-or the value of the other pixels in the byte with + // the new value, masked and shifted into the proper bits. + _buffer[y] = (_buffer[y] & ~(0x01 << x)) | ((value & 0x01) << x); +} + +uint8_t Sprite::read(uint8_t x, uint8_t y) const +{ + if (!_buffer) return 0; + + // uint8_t's can't be negative, so don't test for negative x and y. + if (x >= _width || y >= _height) return 0; + + return (_buffer[y] >> x) & 0x01; +} diff --git a/arduino-0018-linux/libraries/Sprite/Sprite.h b/arduino-0018-linux/libraries/Sprite/Sprite.h new file mode 100644 index 0000000..bdcfdb8 --- /dev/null +++ b/arduino-0018-linux/libraries/Sprite/Sprite.h @@ -0,0 +1,48 @@ +/* + Sprite.cpp - 2D sprite buffers library for Arduino & Wiring + Copyright (c) 2006 David A. Mellis. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef Sprite_h +#define Sprite_h + +#include + +#include "binary.h" + +class Sprite +{ + private: + uint8_t _width; + uint8_t _height; + uint8_t _depth; + uint8_t _ppb; + uint8_t _bpr; + uint8_t _mask; + uint8_t *_buffer; + + void init(uint8_t width, uint8_t height); + public: + Sprite(uint8_t width, uint8_t height); + Sprite(uint8_t width, uint8_t height, uint8_t row, ...); + uint8_t width() const; + uint8_t height() const; + void write(uint8_t x, uint8_t y, uint8_t value); + uint8_t read(uint8_t x, uint8_t y) const; +}; + +#endif diff --git a/arduino-0018-linux/libraries/Sprite/binary.h b/arduino-0018-linux/libraries/Sprite/binary.h new file mode 100644 index 0000000..af14980 --- /dev/null +++ b/arduino-0018-linux/libraries/Sprite/binary.h @@ -0,0 +1,515 @@ +#ifndef Binary_h +#define Binary_h + +#define B0 0 +#define B00 0 +#define B000 0 +#define B0000 0 +#define B00000 0 +#define B000000 0 +#define B0000000 0 +#define B00000000 0 +#define B1 1 +#define B01 1 +#define B001 1 +#define B0001 1 +#define B00001 1 +#define B000001 1 +#define B0000001 1 +#define B00000001 1 +#define B10 2 +#define B010 2 +#define B0010 2 +#define B00010 2 +#define B000010 2 +#define B0000010 2 +#define B00000010 2 +#define B11 3 +#define B011 3 +#define B0011 3 +#define B00011 3 +#define B000011 3 +#define B0000011 3 +#define B00000011 3 +#define B100 4 +#define B0100 4 +#define B00100 4 +#define B000100 4 +#define B0000100 4 +#define B00000100 4 +#define B101 5 +#define B0101 5 +#define B00101 5 +#define B000101 5 +#define B0000101 5 +#define B00000101 5 +#define B110 6 +#define B0110 6 +#define B00110 6 +#define B000110 6 +#define B0000110 6 +#define B00000110 6 +#define B111 7 +#define B0111 7 +#define B00111 7 +#define B000111 7 +#define B0000111 7 +#define B00000111 7 +#define B1000 8 +#define B01000 8 +#define B001000 8 +#define B0001000 8 +#define B00001000 8 +#define B1001 9 +#define B01001 9 +#define B001001 9 +#define B0001001 9 +#define B00001001 9 +#define B1010 10 +#define B01010 10 +#define B001010 10 +#define B0001010 10 +#define B00001010 10 +#define B1011 11 +#define B01011 11 +#define B001011 11 +#define B0001011 11 +#define B00001011 11 +#define B1100 12 +#define B01100 12 +#define B001100 12 +#define B0001100 12 +#define B00001100 12 +#define B1101 13 +#define B01101 13 +#define B001101 13 +#define B0001101 13 +#define B00001101 13 +#define B1110 14 +#define B01110 14 +#define B001110 14 +#define B0001110 14 +#define B00001110 14 +#define B1111 15 +#define B01111 15 +#define B001111 15 +#define B0001111 15 +#define B00001111 15 +#define B10000 16 +#define B010000 16 +#define B0010000 16 +#define B00010000 16 +#define B10001 17 +#define B010001 17 +#define B0010001 17 +#define B00010001 17 +#define B10010 18 +#define B010010 18 +#define B0010010 18 +#define B00010010 18 +#define B10011 19 +#define B010011 19 +#define B0010011 19 +#define B00010011 19 +#define B10100 20 +#define B010100 20 +#define B0010100 20 +#define B00010100 20 +#define B10101 21 +#define B010101 21 +#define B0010101 21 +#define B00010101 21 +#define B10110 22 +#define B010110 22 +#define B0010110 22 +#define B00010110 22 +#define B10111 23 +#define B010111 23 +#define B0010111 23 +#define B00010111 23 +#define B11000 24 +#define B011000 24 +#define B0011000 24 +#define B00011000 24 +#define B11001 25 +#define B011001 25 +#define B0011001 25 +#define B00011001 25 +#define B11010 26 +#define B011010 26 +#define B0011010 26 +#define B00011010 26 +#define B11011 27 +#define B011011 27 +#define B0011011 27 +#define B00011011 27 +#define B11100 28 +#define B011100 28 +#define B0011100 28 +#define B00011100 28 +#define B11101 29 +#define B011101 29 +#define B0011101 29 +#define B00011101 29 +#define B11110 30 +#define B011110 30 +#define B0011110 30 +#define B00011110 30 +#define B11111 31 +#define B011111 31 +#define B0011111 31 +#define B00011111 31 +#define B100000 32 +#define B0100000 32 +#define B00100000 32 +#define B100001 33 +#define B0100001 33 +#define B00100001 33 +#define B100010 34 +#define B0100010 34 +#define B00100010 34 +#define B100011 35 +#define B0100011 35 +#define B00100011 35 +#define B100100 36 +#define B0100100 36 +#define B00100100 36 +#define B100101 37 +#define B0100101 37 +#define B00100101 37 +#define B100110 38 +#define B0100110 38 +#define B00100110 38 +#define B100111 39 +#define B0100111 39 +#define B00100111 39 +#define B101000 40 +#define B0101000 40 +#define B00101000 40 +#define B101001 41 +#define B0101001 41 +#define B00101001 41 +#define B101010 42 +#define B0101010 42 +#define B00101010 42 +#define B101011 43 +#define B0101011 43 +#define B00101011 43 +#define B101100 44 +#define B0101100 44 +#define B00101100 44 +#define B101101 45 +#define B0101101 45 +#define B00101101 45 +#define B101110 46 +#define B0101110 46 +#define B00101110 46 +#define B101111 47 +#define B0101111 47 +#define B00101111 47 +#define B110000 48 +#define B0110000 48 +#define B00110000 48 +#define B110001 49 +#define B0110001 49 +#define B00110001 49 +#define B110010 50 +#define B0110010 50 +#define B00110010 50 +#define B110011 51 +#define B0110011 51 +#define B00110011 51 +#define B110100 52 +#define B0110100 52 +#define B00110100 52 +#define B110101 53 +#define B0110101 53 +#define B00110101 53 +#define B110110 54 +#define B0110110 54 +#define B00110110 54 +#define B110111 55 +#define B0110111 55 +#define B00110111 55 +#define B111000 56 +#define B0111000 56 +#define B00111000 56 +#define B111001 57 +#define B0111001 57 +#define B00111001 57 +#define B111010 58 +#define B0111010 58 +#define B00111010 58 +#define B111011 59 +#define B0111011 59 +#define B00111011 59 +#define B111100 60 +#define B0111100 60 +#define B00111100 60 +#define B111101 61 +#define B0111101 61 +#define B00111101 61 +#define B111110 62 +#define B0111110 62 +#define B00111110 62 +#define B111111 63 +#define B0111111 63 +#define B00111111 63 +#define B1000000 64 +#define B01000000 64 +#define B1000001 65 +#define B01000001 65 +#define B1000010 66 +#define B01000010 66 +#define B1000011 67 +#define B01000011 67 +#define B1000100 68 +#define B01000100 68 +#define B1000101 69 +#define B01000101 69 +#define B1000110 70 +#define B01000110 70 +#define B1000111 71 +#define B01000111 71 +#define B1001000 72 +#define B01001000 72 +#define B1001001 73 +#define B01001001 73 +#define B1001010 74 +#define B01001010 74 +#define B1001011 75 +#define B01001011 75 +#define B1001100 76 +#define B01001100 76 +#define B1001101 77 +#define B01001101 77 +#define B1001110 78 +#define B01001110 78 +#define B1001111 79 +#define B01001111 79 +#define B1010000 80 +#define B01010000 80 +#define B1010001 81 +#define B01010001 81 +#define B1010010 82 +#define B01010010 82 +#define B1010011 83 +#define B01010011 83 +#define B1010100 84 +#define B01010100 84 +#define B1010101 85 +#define B01010101 85 +#define B1010110 86 +#define B01010110 86 +#define B1010111 87 +#define B01010111 87 +#define B1011000 88 +#define B01011000 88 +#define B1011001 89 +#define B01011001 89 +#define B1011010 90 +#define B01011010 90 +#define B1011011 91 +#define B01011011 91 +#define B1011100 92 +#define B01011100 92 +#define B1011101 93 +#define B01011101 93 +#define B1011110 94 +#define B01011110 94 +#define B1011111 95 +#define B01011111 95 +#define B1100000 96 +#define B01100000 96 +#define B1100001 97 +#define B01100001 97 +#define B1100010 98 +#define B01100010 98 +#define B1100011 99 +#define B01100011 99 +#define B1100100 100 +#define B01100100 100 +#define B1100101 101 +#define B01100101 101 +#define B1100110 102 +#define B01100110 102 +#define B1100111 103 +#define B01100111 103 +#define B1101000 104 +#define B01101000 104 +#define B1101001 105 +#define B01101001 105 +#define B1101010 106 +#define B01101010 106 +#define B1101011 107 +#define B01101011 107 +#define B1101100 108 +#define B01101100 108 +#define B1101101 109 +#define B01101101 109 +#define B1101110 110 +#define B01101110 110 +#define B1101111 111 +#define B01101111 111 +#define B1110000 112 +#define B01110000 112 +#define B1110001 113 +#define B01110001 113 +#define B1110010 114 +#define B01110010 114 +#define B1110011 115 +#define B01110011 115 +#define B1110100 116 +#define B01110100 116 +#define B1110101 117 +#define B01110101 117 +#define B1110110 118 +#define B01110110 118 +#define B1110111 119 +#define B01110111 119 +#define B1111000 120 +#define B01111000 120 +#define B1111001 121 +#define B01111001 121 +#define B1111010 122 +#define B01111010 122 +#define B1111011 123 +#define B01111011 123 +#define B1111100 124 +#define B01111100 124 +#define B1111101 125 +#define B01111101 125 +#define B1111110 126 +#define B01111110 126 +#define B1111111 127 +#define B01111111 127 +#define B10000000 128 +#define B10000001 129 +#define B10000010 130 +#define B10000011 131 +#define B10000100 132 +#define B10000101 133 +#define B10000110 134 +#define B10000111 135 +#define B10001000 136 +#define B10001001 137 +#define B10001010 138 +#define B10001011 139 +#define B10001100 140 +#define B10001101 141 +#define B10001110 142 +#define B10001111 143 +#define B10010000 144 +#define B10010001 145 +#define B10010010 146 +#define B10010011 147 +#define B10010100 148 +#define B10010101 149 +#define B10010110 150 +#define B10010111 151 +#define B10011000 152 +#define B10011001 153 +#define B10011010 154 +#define B10011011 155 +#define B10011100 156 +#define B10011101 157 +#define B10011110 158 +#define B10011111 159 +#define B10100000 160 +#define B10100001 161 +#define B10100010 162 +#define B10100011 163 +#define B10100100 164 +#define B10100101 165 +#define B10100110 166 +#define B10100111 167 +#define B10101000 168 +#define B10101001 169 +#define B10101010 170 +#define B10101011 171 +#define B10101100 172 +#define B10101101 173 +#define B10101110 174 +#define B10101111 175 +#define B10110000 176 +#define B10110001 177 +#define B10110010 178 +#define B10110011 179 +#define B10110100 180 +#define B10110101 181 +#define B10110110 182 +#define B10110111 183 +#define B10111000 184 +#define B10111001 185 +#define B10111010 186 +#define B10111011 187 +#define B10111100 188 +#define B10111101 189 +#define B10111110 190 +#define B10111111 191 +#define B11000000 192 +#define B11000001 193 +#define B11000010 194 +#define B11000011 195 +#define B11000100 196 +#define B11000101 197 +#define B11000110 198 +#define B11000111 199 +#define B11001000 200 +#define B11001001 201 +#define B11001010 202 +#define B11001011 203 +#define B11001100 204 +#define B11001101 205 +#define B11001110 206 +#define B11001111 207 +#define B11010000 208 +#define B11010001 209 +#define B11010010 210 +#define B11010011 211 +#define B11010100 212 +#define B11010101 213 +#define B11010110 214 +#define B11010111 215 +#define B11011000 216 +#define B11011001 217 +#define B11011010 218 +#define B11011011 219 +#define B11011100 220 +#define B11011101 221 +#define B11011110 222 +#define B11011111 223 +#define B11100000 224 +#define B11100001 225 +#define B11100010 226 +#define B11100011 227 +#define B11100100 228 +#define B11100101 229 +#define B11100110 230 +#define B11100111 231 +#define B11101000 232 +#define B11101001 233 +#define B11101010 234 +#define B11101011 235 +#define B11101100 236 +#define B11101101 237 +#define B11101110 238 +#define B11101111 239 +#define B11110000 240 +#define B11110001 241 +#define B11110010 242 +#define B11110011 243 +#define B11110100 244 +#define B11110101 245 +#define B11110110 246 +#define B11110111 247 +#define B11111000 248 +#define B11111001 249 +#define B11111010 250 +#define B11111011 251 +#define B11111100 252 +#define B11111101 253 +#define B11111110 254 +#define B11111111 255 + +#endif diff --git a/arduino-0018-linux/libraries/Sprite/keywords.txt b/arduino-0018-linux/libraries/Sprite/keywords.txt new file mode 100644 index 0000000..73cd8d9 --- /dev/null +++ b/arduino-0018-linux/libraries/Sprite/keywords.txt @@ -0,0 +1,534 @@ +####################################### +# Syntax Coloring Map For Sprite +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +Sprite KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +width KEYWORD2 +height KEYWORD2 +write KEYWORD2 +read KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### + +B0 LITERAL1 +B00 LITERAL1 +B000 LITERAL1 +B0000 LITERAL1 +B00000 LITERAL1 +B000000 LITERAL1 +B0000000 LITERAL1 +B00000000 LITERAL1 +B1 LITERAL1 +B01 LITERAL1 +B001 LITERAL1 +B0001 LITERAL1 +B00001 LITERAL1 +B000001 LITERAL1 +B0000001 LITERAL1 +B00000001 LITERAL1 +B10 LITERAL1 +B010 LITERAL1 +B0010 LITERAL1 +B00010 LITERAL1 +B000010 LITERAL1 +B0000010 LITERAL1 +B00000010 LITERAL1 +B11 LITERAL1 +B011 LITERAL1 +B0011 LITERAL1 +B00011 LITERAL1 +B000011 LITERAL1 +B0000011 LITERAL1 +B00000011 LITERAL1 +B100 LITERAL1 +B0100 LITERAL1 +B00100 LITERAL1 +B000100 LITERAL1 +B0000100 LITERAL1 +B00000100 LITERAL1 +B101 LITERAL1 +B0101 LITERAL1 +B00101 LITERAL1 +B000101 LITERAL1 +B0000101 LITERAL1 +B00000101 LITERAL1 +B110 LITERAL1 +B0110 LITERAL1 +B00110 LITERAL1 +B000110 LITERAL1 +B0000110 LITERAL1 +B00000110 LITERAL1 +B111 LITERAL1 +B0111 LITERAL1 +B00111 LITERAL1 +B000111 LITERAL1 +B0000111 LITERAL1 +B00000111 LITERAL1 +B1000 LITERAL1 +B01000 LITERAL1 +B001000 LITERAL1 +B0001000 LITERAL1 +B00001000 LITERAL1 +B1001 LITERAL1 +B01001 LITERAL1 +B001001 LITERAL1 +B0001001 LITERAL1 +B00001001 LITERAL1 +B1010 LITERAL1 +B01010 LITERAL1 +B001010 LITERAL1 +B0001010 LITERAL1 +B00001010 LITERAL1 +B1011 LITERAL1 +B01011 LITERAL1 +B001011 LITERAL1 +B0001011 LITERAL1 +B00001011 LITERAL1 +B1100 LITERAL1 +B01100 LITERAL1 +B001100 LITERAL1 +B0001100 LITERAL1 +B00001100 LITERAL1 +B1101 LITERAL1 +B01101 LITERAL1 +B001101 LITERAL1 +B0001101 LITERAL1 +B00001101 LITERAL1 +B1110 LITERAL1 +B01110 LITERAL1 +B001110 LITERAL1 +B0001110 LITERAL1 +B00001110 LITERAL1 +B1111 LITERAL1 +B01111 LITERAL1 +B001111 LITERAL1 +B0001111 LITERAL1 +B00001111 LITERAL1 +B10000 LITERAL1 +B010000 LITERAL1 +B0010000 LITERAL1 +B00010000 LITERAL1 +B10001 LITERAL1 +B010001 LITERAL1 +B0010001 LITERAL1 +B00010001 LITERAL1 +B10010 LITERAL1 +B010010 LITERAL1 +B0010010 LITERAL1 +B00010010 LITERAL1 +B10011 LITERAL1 +B010011 LITERAL1 +B0010011 LITERAL1 +B00010011 LITERAL1 +B10100 LITERAL1 +B010100 LITERAL1 +B0010100 LITERAL1 +B00010100 LITERAL1 +B10101 LITERAL1 +B010101 LITERAL1 +B0010101 LITERAL1 +B00010101 LITERAL1 +B10110 LITERAL1 +B010110 LITERAL1 +B0010110 LITERAL1 +B00010110 LITERAL1 +B10111 LITERAL1 +B010111 LITERAL1 +B0010111 LITERAL1 +B00010111 LITERAL1 +B11000 LITERAL1 +B011000 LITERAL1 +B0011000 LITERAL1 +B00011000 LITERAL1 +B11001 LITERAL1 +B011001 LITERAL1 +B0011001 LITERAL1 +B00011001 LITERAL1 +B11010 LITERAL1 +B011010 LITERAL1 +B0011010 LITERAL1 +B00011010 LITERAL1 +B11011 LITERAL1 +B011011 LITERAL1 +B0011011 LITERAL1 +B00011011 LITERAL1 +B11100 LITERAL1 +B011100 LITERAL1 +B0011100 LITERAL1 +B00011100 LITERAL1 +B11101 LITERAL1 +B011101 LITERAL1 +B0011101 LITERAL1 +B00011101 LITERAL1 +B11110 LITERAL1 +B011110 LITERAL1 +B0011110 LITERAL1 +B00011110 LITERAL1 +B11111 LITERAL1 +B011111 LITERAL1 +B0011111 LITERAL1 +B00011111 LITERAL1 +B100000 LITERAL1 +B0100000 LITERAL1 +B00100000 LITERAL1 +B100001 LITERAL1 +B0100001 LITERAL1 +B00100001 LITERAL1 +B100010 LITERAL1 +B0100010 LITERAL1 +B00100010 LITERAL1 +B100011 LITERAL1 +B0100011 LITERAL1 +B00100011 LITERAL1 +B100100 LITERAL1 +B0100100 LITERAL1 +B00100100 LITERAL1 +B100101 LITERAL1 +B0100101 LITERAL1 +B00100101 LITERAL1 +B100110 LITERAL1 +B0100110 LITERAL1 +B00100110 LITERAL1 +B100111 LITERAL1 +B0100111 LITERAL1 +B00100111 LITERAL1 +B101000 LITERAL1 +B0101000 LITERAL1 +B00101000 LITERAL1 +B101001 LITERAL1 +B0101001 LITERAL1 +B00101001 LITERAL1 +B101010 LITERAL1 +B0101010 LITERAL1 +B00101010 LITERAL1 +B101011 LITERAL1 +B0101011 LITERAL1 +B00101011 LITERAL1 +B101100 LITERAL1 +B0101100 LITERAL1 +B00101100 LITERAL1 +B101101 LITERAL1 +B0101101 LITERAL1 +B00101101 LITERAL1 +B101110 LITERAL1 +B0101110 LITERAL1 +B00101110 LITERAL1 +B101111 LITERAL1 +B0101111 LITERAL1 +B00101111 LITERAL1 +B110000 LITERAL1 +B0110000 LITERAL1 +B00110000 LITERAL1 +B110001 LITERAL1 +B0110001 LITERAL1 +B00110001 LITERAL1 +B110010 LITERAL1 +B0110010 LITERAL1 +B00110010 LITERAL1 +B110011 LITERAL1 +B0110011 LITERAL1 +B00110011 LITERAL1 +B110100 LITERAL1 +B0110100 LITERAL1 +B00110100 LITERAL1 +B110101 LITERAL1 +B0110101 LITERAL1 +B00110101 LITERAL1 +B110110 LITERAL1 +B0110110 LITERAL1 +B00110110 LITERAL1 +B110111 LITERAL1 +B0110111 LITERAL1 +B00110111 LITERAL1 +B111000 LITERAL1 +B0111000 LITERAL1 +B00111000 LITERAL1 +B111001 LITERAL1 +B0111001 LITERAL1 +B00111001 LITERAL1 +B111010 LITERAL1 +B0111010 LITERAL1 +B00111010 LITERAL1 +B111011 LITERAL1 +B0111011 LITERAL1 +B00111011 LITERAL1 +B111100 LITERAL1 +B0111100 LITERAL1 +B00111100 LITERAL1 +B111101 LITERAL1 +B0111101 LITERAL1 +B00111101 LITERAL1 +B111110 LITERAL1 +B0111110 LITERAL1 +B00111110 LITERAL1 +B111111 LITERAL1 +B0111111 LITERAL1 +B00111111 LITERAL1 +B1000000 LITERAL1 +B01000000 LITERAL1 +B1000001 LITERAL1 +B01000001 LITERAL1 +B1000010 LITERAL1 +B01000010 LITERAL1 +B1000011 LITERAL1 +B01000011 LITERAL1 +B1000100 LITERAL1 +B01000100 LITERAL1 +B1000101 LITERAL1 +B01000101 LITERAL1 +B1000110 LITERAL1 +B01000110 LITERAL1 +B1000111 LITERAL1 +B01000111 LITERAL1 +B1001000 LITERAL1 +B01001000 LITERAL1 +B1001001 LITERAL1 +B01001001 LITERAL1 +B1001010 LITERAL1 +B01001010 LITERAL1 +B1001011 LITERAL1 +B01001011 LITERAL1 +B1001100 LITERAL1 +B01001100 LITERAL1 +B1001101 LITERAL1 +B01001101 LITERAL1 +B1001110 LITERAL1 +B01001110 LITERAL1 +B1001111 LITERAL1 +B01001111 LITERAL1 +B1010000 LITERAL1 +B01010000 LITERAL1 +B1010001 LITERAL1 +B01010001 LITERAL1 +B1010010 LITERAL1 +B01010010 LITERAL1 +B1010011 LITERAL1 +B01010011 LITERAL1 +B1010100 LITERAL1 +B01010100 LITERAL1 +B1010101 LITERAL1 +B01010101 LITERAL1 +B1010110 LITERAL1 +B01010110 LITERAL1 +B1010111 LITERAL1 +B01010111 LITERAL1 +B1011000 LITERAL1 +B01011000 LITERAL1 +B1011001 LITERAL1 +B01011001 LITERAL1 +B1011010 LITERAL1 +B01011010 LITERAL1 +B1011011 LITERAL1 +B01011011 LITERAL1 +B1011100 LITERAL1 +B01011100 LITERAL1 +B1011101 LITERAL1 +B01011101 LITERAL1 +B1011110 LITERAL1 +B01011110 LITERAL1 +B1011111 LITERAL1 +B01011111 LITERAL1 +B1100000 LITERAL1 +B01100000 LITERAL1 +B1100001 LITERAL1 +B01100001 LITERAL1 +B1100010 LITERAL1 +B01100010 LITERAL1 +B1100011 LITERAL1 +B01100011 LITERAL1 +B1100100 LITERAL1 +B01100100 LITERAL1 +B1100101 LITERAL1 +B01100101 LITERAL1 +B1100110 LITERAL1 +B01100110 LITERAL1 +B1100111 LITERAL1 +B01100111 LITERAL1 +B1101000 LITERAL1 +B01101000 LITERAL1 +B1101001 LITERAL1 +B01101001 LITERAL1 +B1101010 LITERAL1 +B01101010 LITERAL1 +B1101011 LITERAL1 +B01101011 LITERAL1 +B1101100 LITERAL1 +B01101100 LITERAL1 +B1101101 LITERAL1 +B01101101 LITERAL1 +B1101110 LITERAL1 +B01101110 LITERAL1 +B1101111 LITERAL1 +B01101111 LITERAL1 +B1110000 LITERAL1 +B01110000 LITERAL1 +B1110001 LITERAL1 +B01110001 LITERAL1 +B1110010 LITERAL1 +B01110010 LITERAL1 +B1110011 LITERAL1 +B01110011 LITERAL1 +B1110100 LITERAL1 +B01110100 LITERAL1 +B1110101 LITERAL1 +B01110101 LITERAL1 +B1110110 LITERAL1 +B01110110 LITERAL1 +B1110111 LITERAL1 +B01110111 LITERAL1 +B1111000 LITERAL1 +B01111000 LITERAL1 +B1111001 LITERAL1 +B01111001 LITERAL1 +B1111010 LITERAL1 +B01111010 LITERAL1 +B1111011 LITERAL1 +B01111011 LITERAL1 +B1111100 LITERAL1 +B01111100 LITERAL1 +B1111101 LITERAL1 +B01111101 LITERAL1 +B1111110 LITERAL1 +B01111110 LITERAL1 +B1111111 LITERAL1 +B01111111 LITERAL1 +B10000000 LITERAL1 +B10000001 LITERAL1 +B10000010 LITERAL1 +B10000011 LITERAL1 +B10000100 LITERAL1 +B10000101 LITERAL1 +B10000110 LITERAL1 +B10000111 LITERAL1 +B10001000 LITERAL1 +B10001001 LITERAL1 +B10001010 LITERAL1 +B10001011 LITERAL1 +B10001100 LITERAL1 +B10001101 LITERAL1 +B10001110 LITERAL1 +B10001111 LITERAL1 +B10010000 LITERAL1 +B10010001 LITERAL1 +B10010010 LITERAL1 +B10010011 LITERAL1 +B10010100 LITERAL1 +B10010101 LITERAL1 +B10010110 LITERAL1 +B10010111 LITERAL1 +B10011000 LITERAL1 +B10011001 LITERAL1 +B10011010 LITERAL1 +B10011011 LITERAL1 +B10011100 LITERAL1 +B10011101 LITERAL1 +B10011110 LITERAL1 +B10011111 LITERAL1 +B10100000 LITERAL1 +B10100001 LITERAL1 +B10100010 LITERAL1 +B10100011 LITERAL1 +B10100100 LITERAL1 +B10100101 LITERAL1 +B10100110 LITERAL1 +B10100111 LITERAL1 +B10101000 LITERAL1 +B10101001 LITERAL1 +B10101010 LITERAL1 +B10101011 LITERAL1 +B10101100 LITERAL1 +B10101101 LITERAL1 +B10101110 LITERAL1 +B10101111 LITERAL1 +B10110000 LITERAL1 +B10110001 LITERAL1 +B10110010 LITERAL1 +B10110011 LITERAL1 +B10110100 LITERAL1 +B10110101 LITERAL1 +B10110110 LITERAL1 +B10110111 LITERAL1 +B10111000 LITERAL1 +B10111001 LITERAL1 +B10111010 LITERAL1 +B10111011 LITERAL1 +B10111100 LITERAL1 +B10111101 LITERAL1 +B10111110 LITERAL1 +B10111111 LITERAL1 +B11000000 LITERAL1 +B11000001 LITERAL1 +B11000010 LITERAL1 +B11000011 LITERAL1 +B11000100 LITERAL1 +B11000101 LITERAL1 +B11000110 LITERAL1 +B11000111 LITERAL1 +B11001000 LITERAL1 +B11001001 LITERAL1 +B11001010 LITERAL1 +B11001011 LITERAL1 +B11001100 LITERAL1 +B11001101 LITERAL1 +B11001110 LITERAL1 +B11001111 LITERAL1 +B11010000 LITERAL1 +B11010001 LITERAL1 +B11010010 LITERAL1 +B11010011 LITERAL1 +B11010100 LITERAL1 +B11010101 LITERAL1 +B11010110 LITERAL1 +B11010111 LITERAL1 +B11011000 LITERAL1 +B11011001 LITERAL1 +B11011010 LITERAL1 +B11011011 LITERAL1 +B11011100 LITERAL1 +B11011101 LITERAL1 +B11011110 LITERAL1 +B11011111 LITERAL1 +B11100000 LITERAL1 +B11100001 LITERAL1 +B11100010 LITERAL1 +B11100011 LITERAL1 +B11100100 LITERAL1 +B11100101 LITERAL1 +B11100110 LITERAL1 +B11100111 LITERAL1 +B11101000 LITERAL1 +B11101001 LITERAL1 +B11101010 LITERAL1 +B11101011 LITERAL1 +B11101100 LITERAL1 +B11101101 LITERAL1 +B11101110 LITERAL1 +B11101111 LITERAL1 +B11110000 LITERAL1 +B11110001 LITERAL1 +B11110010 LITERAL1 +B11110011 LITERAL1 +B11110100 LITERAL1 +B11110101 LITERAL1 +B11110110 LITERAL1 +B11110111 LITERAL1 +B11111000 LITERAL1 +B11111001 LITERAL1 +B11111010 LITERAL1 +B11111011 LITERAL1 +B11111100 LITERAL1 +B11111101 LITERAL1 +B11111110 LITERAL1 +B11111111 LITERAL1 + diff --git a/arduino-0018-linux/libraries/Stepper/Stepper.cpp b/arduino-0018-linux/libraries/Stepper/Stepper.cpp new file mode 100644 index 0000000..d5c16a3 --- /dev/null +++ b/arduino-0018-linux/libraries/Stepper/Stepper.cpp @@ -0,0 +1,220 @@ +/* + Stepper.cpp - - Stepper library for Wiring/Arduino - Version 0.4 + + Original library (0.1) by Tom Igoe. + Two-wire modifications (0.2) by Sebastian Gassner + Combination version (0.3) by Tom Igoe and David Mellis + Bug fix for four-wire (0.4) by Tom Igoe, bug fix from Noah Shibley + + Drives a unipolar or bipolar stepper motor using 2 wires or 4 wires + + When wiring multiple stepper motors to a microcontroller, + you quickly run out of output pins, with each motor requiring 4 connections. + + By making use of the fact that at any time two of the four motor + coils are the inverse of the other two, the number of + control connections can be reduced from 4 to 2. + + A slightly modified circuit around a Darlington transistor array or an L293 H-bridge + connects to only 2 microcontroler pins, inverts the signals received, + and delivers the 4 (2 plus 2 inverted ones) output signals required + for driving a stepper motor. + + The sequence of control signals for 4 control wires is as follows: + + Step C0 C1 C2 C3 + 1 1 0 1 0 + 2 0 1 1 0 + 3 0 1 0 1 + 4 1 0 0 1 + + The sequence of controls signals for 2 control wires is as follows + (columns C1 and C2 from above): + + Step C0 C1 + 1 0 1 + 2 1 1 + 3 1 0 + 4 0 0 + + The circuits can be found at + +http://www.arduino.cc/en/Tutorial/Stepper + + + */ + + +#include "WProgram.h" +#include "Stepper.h" + +/* + * two-wire constructor. + * Sets which wires should control the motor. + */ +Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2) +{ + this->step_number = 0; // which step the motor is on + this->speed = 0; // the motor speed, in revolutions per minute + this->direction = 0; // motor direction + this->last_step_time = 0; // time stamp in ms of the last step taken + this->number_of_steps = number_of_steps; // total number of steps for this motor + + // Arduino pins for the motor control connection: + this->motor_pin_1 = motor_pin_1; + this->motor_pin_2 = motor_pin_2; + + // setup the pins on the microcontroller: + pinMode(this->motor_pin_1, OUTPUT); + pinMode(this->motor_pin_2, OUTPUT); + + // When there are only 2 pins, set the other two to 0: + this->motor_pin_3 = 0; + this->motor_pin_4 = 0; + + // pin_count is used by the stepMotor() method: + this->pin_count = 2; +} + + +/* + * constructor for four-pin version + * Sets which wires should control the motor. + */ + +Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2, int motor_pin_3, int motor_pin_4) +{ + this->step_number = 0; // which step the motor is on + this->speed = 0; // the motor speed, in revolutions per minute + this->direction = 0; // motor direction + this->last_step_time = 0; // time stamp in ms of the last step taken + this->number_of_steps = number_of_steps; // total number of steps for this motor + + // Arduino pins for the motor control connection: + this->motor_pin_1 = motor_pin_1; + this->motor_pin_2 = motor_pin_2; + this->motor_pin_3 = motor_pin_3; + this->motor_pin_4 = motor_pin_4; + + // setup the pins on the microcontroller: + pinMode(this->motor_pin_1, OUTPUT); + pinMode(this->motor_pin_2, OUTPUT); + pinMode(this->motor_pin_3, OUTPUT); + pinMode(this->motor_pin_4, OUTPUT); + + // pin_count is used by the stepMotor() method: + this->pin_count = 4; +} + +/* + Sets the speed in revs per minute + +*/ +void Stepper::setSpeed(long whatSpeed) +{ + this->step_delay = 60L * 1000L / this->number_of_steps / whatSpeed; +} + +/* + Moves the motor steps_to_move steps. If the number is negative, + the motor moves in the reverse direction. + */ +void Stepper::step(int steps_to_move) +{ + int steps_left = abs(steps_to_move); // how many steps to take + + // determine direction based on whether steps_to_mode is + or -: + if (steps_to_move > 0) {this->direction = 1;} + if (steps_to_move < 0) {this->direction = 0;} + + + // decrement the number of steps, moving one step each time: + while(steps_left > 0) { + // move only if the appropriate delay has passed: + if (millis() - this->last_step_time >= this->step_delay) { + // get the timeStamp of when you stepped: + this->last_step_time = millis(); + // increment or decrement the step number, + // depending on direction: + if (this->direction == 1) { + this->step_number++; + if (this->step_number == this->number_of_steps) { + this->step_number = 0; + } + } + else { + if (this->step_number == 0) { + this->step_number = this->number_of_steps; + } + this->step_number--; + } + // decrement the steps left: + steps_left--; + // step the motor to step number 0, 1, 2, or 3: + stepMotor(this->step_number % 4); + } + } +} + +/* + * Moves the motor forward or backwards. + */ +void Stepper::stepMotor(int thisStep) +{ + if (this->pin_count == 2) { + switch (thisStep) { + case 0: /* 01 */ + digitalWrite(motor_pin_1, LOW); + digitalWrite(motor_pin_2, HIGH); + break; + case 1: /* 11 */ + digitalWrite(motor_pin_1, HIGH); + digitalWrite(motor_pin_2, HIGH); + break; + case 2: /* 10 */ + digitalWrite(motor_pin_1, HIGH); + digitalWrite(motor_pin_2, LOW); + break; + case 3: /* 00 */ + digitalWrite(motor_pin_1, LOW); + digitalWrite(motor_pin_2, LOW); + break; + } + } + if (this->pin_count == 4) { + switch (thisStep) { + case 0: // 1010 + digitalWrite(motor_pin_1, HIGH); + digitalWrite(motor_pin_2, LOW); + digitalWrite(motor_pin_3, HIGH); + digitalWrite(motor_pin_4, LOW); + break; + case 1: // 0110 + digitalWrite(motor_pin_1, LOW); + digitalWrite(motor_pin_2, HIGH); + digitalWrite(motor_pin_3, HIGH); + digitalWrite(motor_pin_4, LOW); + break; + case 2: //0101 + digitalWrite(motor_pin_1, LOW); + digitalWrite(motor_pin_2, HIGH); + digitalWrite(motor_pin_3, LOW); + digitalWrite(motor_pin_4, HIGH); + break; + case 3: //1001 + digitalWrite(motor_pin_1, HIGH); + digitalWrite(motor_pin_2, LOW); + digitalWrite(motor_pin_3, LOW); + digitalWrite(motor_pin_4, HIGH); + break; + } + } +} + +/* + version() returns the version of the library: +*/ +int Stepper::version(void) +{ + return 4; +} diff --git a/arduino-0018-linux/libraries/Stepper/Stepper.h b/arduino-0018-linux/libraries/Stepper/Stepper.h new file mode 100644 index 0000000..4094aee --- /dev/null +++ b/arduino-0018-linux/libraries/Stepper/Stepper.h @@ -0,0 +1,83 @@ +/* + Stepper.h - - Stepper library for Wiring/Arduino - Version 0.4 + + Original library (0.1) by Tom Igoe. + Two-wire modifications (0.2) by Sebastian Gassner + Combination version (0.3) by Tom Igoe and David Mellis + Bug fix for four-wire (0.4) by Tom Igoe, bug fix from Noah Shibley + + Drives a unipolar or bipolar stepper motor using 2 wires or 4 wires + + When wiring multiple stepper motors to a microcontroller, + you quickly run out of output pins, with each motor requiring 4 connections. + + By making use of the fact that at any time two of the four motor + coils are the inverse of the other two, the number of + control connections can be reduced from 4 to 2. + + A slightly modified circuit around a Darlington transistor array or an L293 H-bridge + connects to only 2 microcontroler pins, inverts the signals received, + and delivers the 4 (2 plus 2 inverted ones) output signals required + for driving a stepper motor. + + The sequence of control signals for 4 control wires is as follows: + + Step C0 C1 C2 C3 + 1 1 0 1 0 + 2 0 1 1 0 + 3 0 1 0 1 + 4 1 0 0 1 + + The sequence of controls signals for 2 control wires is as follows + (columns C1 and C2 from above): + + Step C0 C1 + 1 0 1 + 2 1 1 + 3 1 0 + 4 0 0 + + The circuits can be found at + http://www.arduino.cc/en/Tutorial/Stepper +*/ + +// ensure this library description is only included once +#ifndef Stepper_h +#define Stepper_h + +// library interface description +class Stepper { + public: + // constructors: + Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2); + Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2, int motor_pin_3, int motor_pin_4); + + // speed setter method: + void setSpeed(long whatSpeed); + + // mover method: + void step(int number_of_steps); + + int version(void); + + private: + void stepMotor(int this_step); + + int direction; // Direction of rotation + int speed; // Speed in RPMs + unsigned long step_delay; // delay between steps, in ms, based on speed + int number_of_steps; // total number of steps this motor can take + int pin_count; // whether you're driving the motor with 2 or 4 pins + int step_number; // which step the motor is on + + // motor pin numbers: + int motor_pin_1; + int motor_pin_2; + int motor_pin_3; + int motor_pin_4; + + long last_step_time; // time stamp in ms of when the last step was taken +}; + +#endif + diff --git a/arduino-0018-linux/libraries/Stepper/examples/MotorKnob/MotorKnob.pde b/arduino-0018-linux/libraries/Stepper/examples/MotorKnob/MotorKnob.pde new file mode 100644 index 0000000..062cac9 --- /dev/null +++ b/arduino-0018-linux/libraries/Stepper/examples/MotorKnob/MotorKnob.pde @@ -0,0 +1,40 @@ +/* + * MotorKnob + * + * A stepper motor follows the turns of a potentiometer + * (or other sensor) on analog input 0. + * + * http://www.arduino.cc/en/Reference/Stepper + */ + +#include + +// change this to the number of steps on your motor +#define STEPS 100 + +// create an instance of the stepper class, specifying +// the number of steps of the motor and the pins it's +// attached to +Stepper stepper(STEPS, 8, 9, 10, 11); + +// the previous reading from the analog input +int previous = 0; + +void setup() +{ + // set the speed of the motor to 30 RPMs + stepper.setSpeed(30); +} + +void loop() +{ + // get the sensor value + int val = analogRead(0); + + // move a number of steps equal to the change in the + // sensor reading + stepper.step(val - previous); + + // remember the previous value of the sensor + previous = val; +} \ No newline at end of file diff --git a/arduino-0018-linux/libraries/Stepper/keywords.txt b/arduino-0018-linux/libraries/Stepper/keywords.txt new file mode 100644 index 0000000..19a0fad --- /dev/null +++ b/arduino-0018-linux/libraries/Stepper/keywords.txt @@ -0,0 +1,28 @@ +####################################### +# Syntax Coloring Map For Test +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +Stepper KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +step KEYWORD2 +setSpeed KEYWORD2 +version KEYWORD2 + +###################################### +# Instances (KEYWORD2) +####################################### +direction KEYWORD2 +speed KEYWORD2 + + +####################################### +# Constants (LITERAL1) +####################################### diff --git a/arduino-0018-linux/libraries/Wire/Wire.cpp b/arduino-0018-linux/libraries/Wire/Wire.cpp new file mode 100755 index 0000000..0ee3012 --- /dev/null +++ b/arduino-0018-linux/libraries/Wire/Wire.cpp @@ -0,0 +1,265 @@ +/* + TwoWire.cpp - TWI/I2C library for Wiring & Arduino + Copyright (c) 2006 Nicholas Zambetti. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +extern "C" { + #include + #include + #include + #include "twi.h" +} + +#include "Wire.h" + +// Initialize Class Variables ////////////////////////////////////////////////// + +uint8_t* TwoWire::rxBuffer = 0; +uint8_t TwoWire::rxBufferIndex = 0; +uint8_t TwoWire::rxBufferLength = 0; + +uint8_t TwoWire::txAddress = 0; +uint8_t* TwoWire::txBuffer = 0; +uint8_t TwoWire::txBufferIndex = 0; +uint8_t TwoWire::txBufferLength = 0; + +uint8_t TwoWire::transmitting = 0; +void (*TwoWire::user_onRequest)(void); +void (*TwoWire::user_onReceive)(int); + +// Constructors //////////////////////////////////////////////////////////////// + +TwoWire::TwoWire() +{ +} + +// Public Methods ////////////////////////////////////////////////////////////// + +void TwoWire::begin(void) +{ + // init buffer for reads + rxBuffer = (uint8_t*) calloc(BUFFER_LENGTH, sizeof(uint8_t)); + rxBufferIndex = 0; + rxBufferLength = 0; + + // init buffer for writes + txBuffer = (uint8_t*) calloc(BUFFER_LENGTH, sizeof(uint8_t)); + txBufferIndex = 0; + txBufferLength = 0; + + twi_init(); +} + +void TwoWire::begin(uint8_t address) +{ + twi_setAddress(address); + twi_attachSlaveTxEvent(onRequestService); + twi_attachSlaveRxEvent(onReceiveService); + begin(); +} + +void TwoWire::begin(int address) +{ + begin((uint8_t)address); +} + +uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity) +{ + // clamp to buffer length + if(quantity > BUFFER_LENGTH){ + quantity = BUFFER_LENGTH; + } + // perform blocking read into buffer + uint8_t read = twi_readFrom(address, rxBuffer, quantity); + // set rx buffer iterator vars + rxBufferIndex = 0; + rxBufferLength = read; + + return read; +} + +uint8_t TwoWire::requestFrom(int address, int quantity) +{ + return requestFrom((uint8_t)address, (uint8_t)quantity); +} + +void TwoWire::beginTransmission(uint8_t address) +{ + // indicate that we are transmitting + transmitting = 1; + // set address of targeted slave + txAddress = address; + // reset tx buffer iterator vars + txBufferIndex = 0; + txBufferLength = 0; +} + +void TwoWire::beginTransmission(int address) +{ + beginTransmission((uint8_t)address); +} + +uint8_t TwoWire::endTransmission(void) +{ + // transmit buffer (blocking) + int8_t ret = twi_writeTo(txAddress, txBuffer, txBufferLength, 1); + // reset tx buffer iterator vars + txBufferIndex = 0; + txBufferLength = 0; + // indicate that we are done transmitting + transmitting = 0; + return ret; +} + +// must be called in: +// slave tx event callback +// or after beginTransmission(address) +void TwoWire::send(uint8_t data) +{ + if(transmitting){ + // in master transmitter mode + // don't bother if buffer is full + if(txBufferLength >= BUFFER_LENGTH){ + return; + } + // put byte in tx buffer + txBuffer[txBufferIndex] = data; + ++txBufferIndex; + // update amount in buffer + txBufferLength = txBufferIndex; + }else{ + // in slave send mode + // reply to master + twi_transmit(&data, 1); + } +} + +// must be called in: +// slave tx event callback +// or after beginTransmission(address) +void TwoWire::send(uint8_t* data, uint8_t quantity) +{ + if(transmitting){ + // in master transmitter mode + for(uint8_t i = 0; i < quantity; ++i){ + send(data[i]); + } + }else{ + // in slave send mode + // reply to master + twi_transmit(data, quantity); + } +} + +// must be called in: +// slave tx event callback +// or after beginTransmission(address) +void TwoWire::send(char* data) +{ + send((uint8_t*)data, strlen(data)); +} + +// must be called in: +// slave tx event callback +// or after beginTransmission(address) +void TwoWire::send(int data) +{ + send((uint8_t)data); +} + +// must be called in: +// slave rx event callback +// or after requestFrom(address, numBytes) +uint8_t TwoWire::available(void) +{ + return rxBufferLength - rxBufferIndex; +} + +// must be called in: +// slave rx event callback +// or after requestFrom(address, numBytes) +uint8_t TwoWire::receive(void) +{ + // default to returning null char + // for people using with char strings + uint8_t value = '\0'; + + // get each successive byte on each call + if(rxBufferIndex < rxBufferLength){ + value = rxBuffer[rxBufferIndex]; + ++rxBufferIndex; + } + + return value; +} + +// behind the scenes function that is called when data is received +void TwoWire::onReceiveService(uint8_t* inBytes, int numBytes) +{ + // don't bother if user hasn't registered a callback + if(!user_onReceive){ + return; + } + // don't bother if rx buffer is in use by a master requestFrom() op + // i know this drops data, but it allows for slight stupidity + // meaning, they may not have read all the master requestFrom() data yet + if(rxBufferIndex < rxBufferLength){ + return; + } + // copy twi rx buffer into local read buffer + // this enables new reads to happen in parallel + for(uint8_t i = 0; i < numBytes; ++i){ + rxBuffer[i] = inBytes[i]; + } + // set rx iterator vars + rxBufferIndex = 0; + rxBufferLength = numBytes; + // alert user program + user_onReceive(numBytes); +} + +// behind the scenes function that is called when data is requested +void TwoWire::onRequestService(void) +{ + // don't bother if user hasn't registered a callback + if(!user_onRequest){ + return; + } + // reset tx buffer iterator vars + // !!! this will kill any pending pre-master sendTo() activity + txBufferIndex = 0; + txBufferLength = 0; + // alert user program + user_onRequest(); +} + +// sets function called on slave write +void TwoWire::onReceive( void (*function)(int) ) +{ + user_onReceive = function; +} + +// sets function called on slave read +void TwoWire::onRequest( void (*function)(void) ) +{ + user_onRequest = function; +} + +// Preinstantiate Objects ////////////////////////////////////////////////////// + +TwoWire Wire = TwoWire(); + diff --git a/arduino-0018-linux/libraries/Wire/Wire.h b/arduino-0018-linux/libraries/Wire/Wire.h new file mode 100755 index 0000000..9e849d5 --- /dev/null +++ b/arduino-0018-linux/libraries/Wire/Wire.h @@ -0,0 +1,67 @@ +/* + TwoWire.h - TWI/I2C library for Arduino & Wiring + Copyright (c) 2006 Nicholas Zambetti. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef TwoWire_h +#define TwoWire_h + +#include + +#define BUFFER_LENGTH 32 + +class TwoWire +{ + private: + static uint8_t* rxBuffer; + static uint8_t rxBufferIndex; + static uint8_t rxBufferLength; + + static uint8_t txAddress; + static uint8_t* txBuffer; + static uint8_t txBufferIndex; + static uint8_t txBufferLength; + + static uint8_t transmitting; + static void (*user_onRequest)(void); + static void (*user_onReceive)(int); + static void onRequestService(void); + static void onReceiveService(uint8_t*, int); + public: + TwoWire(); + void begin(); + void begin(uint8_t); + void begin(int); + void beginTransmission(uint8_t); + void beginTransmission(int); + uint8_t endTransmission(void); + uint8_t requestFrom(uint8_t, uint8_t); + uint8_t requestFrom(int, int); + void send(uint8_t); + void send(uint8_t*, uint8_t); + void send(int); + void send(char*); + uint8_t available(void); + uint8_t receive(void); + void onReceive( void (*)(int) ); + void onRequest( void (*)(void) ); +}; + +extern TwoWire Wire; + +#endif + diff --git a/arduino-0018-linux/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.pde b/arduino-0018-linux/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.pde new file mode 100755 index 0000000..c89b0f0 --- /dev/null +++ b/arduino-0018-linux/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.pde @@ -0,0 +1,84 @@ +// I2C SRF10 or SRF08 Devantech Ultrasonic Ranger Finder +// by Nicholas Zambetti +// and James Tichenor + +// Demonstrates use of the Wire library reading data from the +// Devantech Utrasonic Rangers SFR08 and SFR10 + +// Created 29 April 2006 + +#include + +void setup() +{ + Wire.begin(); // join i2c bus (address optional for master) + Serial.begin(9600); // start serial communication at 9600bps +} + +int reading = 0; + +void loop() +{ + // step 1: instruct sensor to read echoes + Wire.beginTransmission(112); // transmit to device #112 (0x70) + // the address specified in the datasheet is 224 (0xE0) + // but i2c adressing uses the high 7 bits so it's 112 + Wire.send(0x00); // sets register pointer to the command register (0x00) + Wire.send(0x50); // command sensor to measure in "inches" (0x50) + // use 0x51 for centimeters + // use 0x52 for ping microseconds + Wire.endTransmission(); // stop transmitting + + // step 2: wait for readings to happen + delay(70); // datasheet suggests at least 65 milliseconds + + // step 3: instruct sensor to return a particular echo reading + Wire.beginTransmission(112); // transmit to device #112 + Wire.send(0x02); // sets register pointer to echo #1 register (0x02) + Wire.endTransmission(); // stop transmitting + + // step 4: request reading from sensor + Wire.requestFrom(112, 2); // request 2 bytes from slave device #112 + + // step 5: receive reading from sensor + if(2 <= Wire.available()) // if two bytes were received + { + reading = Wire.receive(); // receive high byte (overwrites previous reading) + reading = reading << 8; // shift high byte to be high 8 bits + reading |= Wire.receive(); // receive low byte as lower 8 bits + Serial.println(reading); // print the reading + } + + delay(250); // wait a bit since people have to read the output :) +} + + +/* + +// The following code changes the address of a Devantech Ultrasonic Range Finder (SRF10 or SRF08) +// usage: changeAddress(0x70, 0xE6); + +void changeAddress(byte oldAddress, byte newAddress) +{ + Wire.beginTransmission(oldAddress); + Wire.send(0x00); + Wire.send(0xA0); + Wire.endTransmission(); + + Wire.beginTransmission(oldAddress); + Wire.send(0x00); + Wire.send(0xAA); + Wire.endTransmission(); + + Wire.beginTransmission(oldAddress); + Wire.send(0x00); + Wire.send(0xA5); + Wire.endTransmission(); + + Wire.beginTransmission(oldAddress); + Wire.send(0x00); + Wire.send(newAddress); + Wire.endTransmission(); +} + +*/ diff --git a/arduino-0018-linux/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.pde b/arduino-0018-linux/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.pde new file mode 100644 index 0000000..35ee5d6 --- /dev/null +++ b/arduino-0018-linux/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.pde @@ -0,0 +1,34 @@ +// I2C Digital Potentiometer +// by Nicholas Zambetti +// and Shawn Bonkowski + +// Demonstrates use of the Wire library +// Controls AD5171 digital potentiometer via I2C/TWI + +// Created 31 March 2006 + +#include + +void setup() +{ + Wire.begin(); // join i2c bus (address optional for master) +} + +byte val = 0; + +void loop() +{ + Wire.beginTransmission(44); // transmit to device #44 (0x2c) + // device address is specified in datasheet + Wire.send(0x00); // sends instruction byte + Wire.send(val); // sends potentiometer value byte + Wire.endTransmission(); // stop transmitting + + val++; // increment value + if(val == 64) // if reached 64th position (max) + { + val = 0; // start over from lowest value + } + delay(500); +} + diff --git a/arduino-0018-linux/libraries/Wire/examples/master_reader/master_reader.pde b/arduino-0018-linux/libraries/Wire/examples/master_reader/master_reader.pde new file mode 100644 index 0000000..1b139de --- /dev/null +++ b/arduino-0018-linux/libraries/Wire/examples/master_reader/master_reader.pde @@ -0,0 +1,29 @@ +// Wire Master Reader +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Reads data from an I2C/TWI slave device +// Refer to the "Wire Slave Sender" example for use with this + +// Created 29 March 2006 + +#include + +void setup() +{ + Wire.begin(); // join i2c bus (address optional for master) + Serial.begin(9600); // start serial for output +} + +void loop() +{ + Wire.requestFrom(2, 6); // request 6 bytes from slave device #2 + + while(Wire.available()) // slave may send less than requested + { + char c = Wire.receive(); // receive a byte as character + Serial.print(c); // print the character + } + + delay(500); +} diff --git a/arduino-0018-linux/libraries/Wire/examples/master_writer/master_writer.pde b/arduino-0018-linux/libraries/Wire/examples/master_writer/master_writer.pde new file mode 100644 index 0000000..d0ff9fa --- /dev/null +++ b/arduino-0018-linux/libraries/Wire/examples/master_writer/master_writer.pde @@ -0,0 +1,28 @@ +// Wire Master Writer +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Writes data to an I2C/TWI slave device +// Refer to the "Wire Slave Receiver" example for use with this + +// Created 29 March 2006 + +#include + +void setup() +{ + Wire.begin(); // join i2c bus (address optional for master) +} + +byte x = 0; + +void loop() +{ + Wire.beginTransmission(4); // transmit to device #4 + Wire.send("x is "); // sends five bytes + Wire.send(x); // sends one byte + Wire.endTransmission(); // stop transmitting + + x++; + delay(500); +} diff --git a/arduino-0018-linux/libraries/Wire/examples/slave_receiver/slave_receiver.pde b/arduino-0018-linux/libraries/Wire/examples/slave_receiver/slave_receiver.pde new file mode 100644 index 0000000..53c86b5 --- /dev/null +++ b/arduino-0018-linux/libraries/Wire/examples/slave_receiver/slave_receiver.pde @@ -0,0 +1,35 @@ +// Wire Slave Receiver +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Receives data as an I2C/TWI slave device +// Refer to the "Wire Master Writer" example for use with this + +// Created 29 March 2006 + +#include + +void setup() +{ + Wire.begin(4); // join i2c bus with address #4 + Wire.onReceive(receiveEvent); // register event + Serial.begin(9600); // start serial for output +} + +void loop() +{ + delay(100); +} + +// function that executes whenever data is received from master +// this function is registered as an event, see setup() +void receiveEvent(int howMany) +{ + while(1 < Wire.available()) // loop through all but the last + { + char c = Wire.receive(); // receive byte as a character + Serial.print(c); // print the character + } + int x = Wire.receive(); // receive byte as an integer + Serial.println(x); // print the integer +} diff --git a/arduino-0018-linux/libraries/Wire/examples/slave_sender/slave_sender.pde b/arduino-0018-linux/libraries/Wire/examples/slave_sender/slave_sender.pde new file mode 100644 index 0000000..f500644 --- /dev/null +++ b/arduino-0018-linux/libraries/Wire/examples/slave_sender/slave_sender.pde @@ -0,0 +1,29 @@ +// Wire Slave Sender +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Sends data as an I2C/TWI slave device +// Refer to the "Wire Master Reader" example for use with this + +// Created 29 March 2006 + +#include + +void setup() +{ + Wire.begin(2); // join i2c bus with address #2 + Wire.onRequest(requestEvent); // register event +} + +void loop() +{ + delay(100); +} + +// function that executes whenever data is requested by master +// this function is registered as an event, see setup() +void requestEvent() +{ + Wire.send("hello "); // respond with message of 6 bytes + // as expected by master +} diff --git a/arduino-0018-linux/libraries/Wire/keywords.txt b/arduino-0018-linux/libraries/Wire/keywords.txt new file mode 100644 index 0000000..12f129b --- /dev/null +++ b/arduino-0018-linux/libraries/Wire/keywords.txt @@ -0,0 +1,31 @@ +####################################### +# Syntax Coloring Map For Wire +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +begin KEYWORD2 +beginTransmission KEYWORD2 +endTransmission KEYWORD2 +requestFrom KEYWORD2 +send KEYWORD2 +receive KEYWORD2 +onReceive KEYWORD2 +onRequest KEYWORD2 + +####################################### +# Instances (KEYWORD2) +####################################### + +Wire KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### + diff --git a/arduino-0018-linux/libraries/Wire/utility/twi.c b/arduino-0018-linux/libraries/Wire/utility/twi.c new file mode 100644 index 0000000..2ad2a71 --- /dev/null +++ b/arduino-0018-linux/libraries/Wire/utility/twi.c @@ -0,0 +1,479 @@ +/* + twi.c - TWI/I2C library for Wiring & Arduino + Copyright (c) 2006 Nicholas Zambetti. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include +#include +#include +#include +#include +#include + +#ifndef cbi +#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) +#endif + +#ifndef sbi +#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) +#endif + +#include "twi.h" + +static volatile uint8_t twi_state; +static uint8_t twi_slarw; + +static void (*twi_onSlaveTransmit)(void); +static void (*twi_onSlaveReceive)(uint8_t*, int); + +static uint8_t* twi_masterBuffer; +static volatile uint8_t twi_masterBufferIndex; +static uint8_t twi_masterBufferLength; + +static uint8_t* twi_txBuffer; +static volatile uint8_t twi_txBufferIndex; +static volatile uint8_t twi_txBufferLength; + +static uint8_t* twi_rxBuffer; +static volatile uint8_t twi_rxBufferIndex; + +static volatile uint8_t twi_error; + +/* + * Function twi_init + * Desc readys twi pins and sets twi bitrate + * Input none + * Output none + */ +void twi_init(void) +{ + // initialize state + twi_state = TWI_READY; + + #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega328P__) + // activate internal pull-ups for twi + // as per note from atmega8 manual pg167 + sbi(PORTC, 4); + sbi(PORTC, 5); + #else + // activate internal pull-ups for twi + // as per note from atmega128 manual pg204 + sbi(PORTD, 0); + sbi(PORTD, 1); + #endif + + // initialize twi prescaler and bit rate + cbi(TWSR, TWPS0); + cbi(TWSR, TWPS1); + TWBR = ((CPU_FREQ / TWI_FREQ) - 16) / 2; + + /* twi bit rate formula from atmega128 manual pg 204 + SCL Frequency = CPU Clock Frequency / (16 + (2 * TWBR)) + note: TWBR should be 10 or higher for master mode + It is 72 for a 16mhz Wiring board with 100kHz TWI */ + + // enable twi module, acks, and twi interrupt + TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA); + + // allocate buffers + twi_masterBuffer = (uint8_t*) calloc(TWI_BUFFER_LENGTH, sizeof(uint8_t)); + twi_txBuffer = (uint8_t*) calloc(TWI_BUFFER_LENGTH, sizeof(uint8_t)); + twi_rxBuffer = (uint8_t*) calloc(TWI_BUFFER_LENGTH, sizeof(uint8_t)); +} + +/* + * Function twi_slaveInit + * Desc sets slave address and enables interrupt + * Input none + * Output none + */ +void twi_setAddress(uint8_t address) +{ + // set twi slave address (skip over TWGCE bit) + TWAR = address << 1; +} + +/* + * Function twi_readFrom + * Desc attempts to become twi bus master and read a + * series of bytes from a device on the bus + * Input address: 7bit i2c device address + * data: pointer to byte array + * length: number of bytes to read into array + * Output number of bytes read + */ +uint8_t twi_readFrom(uint8_t address, uint8_t* data, uint8_t length) +{ + uint8_t i; + + // ensure data will fit into buffer + if(TWI_BUFFER_LENGTH < length){ + return 0; + } + + // wait until twi is ready, become master receiver + while(TWI_READY != twi_state){ + continue; + } + twi_state = TWI_MRX; + // reset error state (0xFF.. no error occured) + twi_error = 0xFF; + + // initialize buffer iteration vars + twi_masterBufferIndex = 0; + twi_masterBufferLength = length-1; // This is not intuitive, read on... + // On receive, the previously configured ACK/NACK setting is transmitted in + // response to the received byte before the interrupt is signalled. + // Therefor we must actually set NACK when the _next_ to last byte is + // received, causing that NACK to be sent in response to receiving the last + // expected byte of data. + + // build sla+w, slave device address + w bit + twi_slarw = TW_READ; + twi_slarw |= address << 1; + + // send start condition + TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT) | _BV(TWSTA); + + // wait for read operation to complete + while(TWI_MRX == twi_state){ + continue; + } + + if (twi_masterBufferIndex < length) + length = twi_masterBufferIndex; + + // copy twi buffer to data + for(i = 0; i < length; ++i){ + data[i] = twi_masterBuffer[i]; + } + + return length; +} + +/* + * Function twi_writeTo + * Desc attempts to become twi bus master and write a + * series of bytes to a device on the bus + * Input address: 7bit i2c device address + * data: pointer to byte array + * length: number of bytes in array + * wait: boolean indicating to wait for write or not + * Output 0 .. success + * 1 .. length to long for buffer + * 2 .. address send, NACK received + * 3 .. data send, NACK received + * 4 .. other twi error (lost bus arbitration, bus error, ..) + */ +uint8_t twi_writeTo(uint8_t address, uint8_t* data, uint8_t length, uint8_t wait) +{ + uint8_t i; + + // ensure data will fit into buffer + if(TWI_BUFFER_LENGTH < length){ + return 1; + } + + // wait until twi is ready, become master transmitter + while(TWI_READY != twi_state){ + continue; + } + twi_state = TWI_MTX; + // reset error state (0xFF.. no error occured) + twi_error = 0xFF; + + // initialize buffer iteration vars + twi_masterBufferIndex = 0; + twi_masterBufferLength = length; + + // copy data to twi buffer + for(i = 0; i < length; ++i){ + twi_masterBuffer[i] = data[i]; + } + + // build sla+w, slave device address + w bit + twi_slarw = TW_WRITE; + twi_slarw |= address << 1; + + // send start condition + TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT) | _BV(TWSTA); + + // wait for write operation to complete + while(wait && (TWI_MTX == twi_state)){ + continue; + } + + if (twi_error == 0xFF) + return 0; // success + else if (twi_error == TW_MT_SLA_NACK) + return 2; // error: address send, nack received + else if (twi_error == TW_MT_DATA_NACK) + return 3; // error: data send, nack received + else + return 4; // other twi error +} + +/* + * Function twi_transmit + * Desc fills slave tx buffer with data + * must be called in slave tx event callback + * Input data: pointer to byte array + * length: number of bytes in array + * Output 1 length too long for buffer + * 2 not slave transmitter + * 0 ok + */ +uint8_t twi_transmit(uint8_t* data, uint8_t length) +{ + uint8_t i; + + // ensure data will fit into buffer + if(TWI_BUFFER_LENGTH < length){ + return 1; + } + + // ensure we are currently a slave transmitter + if(TWI_STX != twi_state){ + return 2; + } + + // set length and copy data into tx buffer + twi_txBufferLength = length; + for(i = 0; i < length; ++i){ + twi_txBuffer[i] = data[i]; + } + + return 0; +} + +/* + * Function twi_attachSlaveRxEvent + * Desc sets function called before a slave read operation + * Input function: callback function to use + * Output none + */ +void twi_attachSlaveRxEvent( void (*function)(uint8_t*, int) ) +{ + twi_onSlaveReceive = function; +} + +/* + * Function twi_attachSlaveTxEvent + * Desc sets function called before a slave write operation + * Input function: callback function to use + * Output none + */ +void twi_attachSlaveTxEvent( void (*function)(void) ) +{ + twi_onSlaveTransmit = function; +} + +/* + * Function twi_reply + * Desc sends byte or readys receive line + * Input ack: byte indicating to ack or to nack + * Output none + */ +void twi_reply(uint8_t ack) +{ + // transmit master read ready signal, with or without ack + if(ack){ + TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWINT) | _BV(TWEA); + }else{ + TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWINT); + } +} + +/* + * Function twi_stop + * Desc relinquishes bus master status + * Input none + * Output none + */ +void twi_stop(void) +{ + // send stop condition + TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT) | _BV(TWSTO); + + // wait for stop condition to be exectued on bus + // TWINT is not set after a stop condition! + while(TWCR & _BV(TWSTO)){ + continue; + } + + // update twi state + twi_state = TWI_READY; +} + +/* + * Function twi_releaseBus + * Desc releases bus control + * Input none + * Output none + */ +void twi_releaseBus(void) +{ + // release bus + TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT); + + // update twi state + twi_state = TWI_READY; +} + +SIGNAL(TWI_vect) +{ + switch(TW_STATUS){ + // All Master + case TW_START: // sent start condition + case TW_REP_START: // sent repeated start condition + // copy device address and r/w bit to output register and ack + TWDR = twi_slarw; + twi_reply(1); + break; + + // Master Transmitter + case TW_MT_SLA_ACK: // slave receiver acked address + case TW_MT_DATA_ACK: // slave receiver acked data + // if there is data to send, send it, otherwise stop + if(twi_masterBufferIndex < twi_masterBufferLength){ + // copy data to output register and ack + TWDR = twi_masterBuffer[twi_masterBufferIndex++]; + twi_reply(1); + }else{ + twi_stop(); + } + break; + case TW_MT_SLA_NACK: // address sent, nack received + twi_error = TW_MT_SLA_NACK; + twi_stop(); + break; + case TW_MT_DATA_NACK: // data sent, nack received + twi_error = TW_MT_DATA_NACK; + twi_stop(); + break; + case TW_MT_ARB_LOST: // lost bus arbitration + twi_error = TW_MT_ARB_LOST; + twi_releaseBus(); + break; + + // Master Receiver + case TW_MR_DATA_ACK: // data received, ack sent + // put byte into buffer + twi_masterBuffer[twi_masterBufferIndex++] = TWDR; + case TW_MR_SLA_ACK: // address sent, ack received + // ack if more bytes are expected, otherwise nack + if(twi_masterBufferIndex < twi_masterBufferLength){ + twi_reply(1); + }else{ + twi_reply(0); + } + break; + case TW_MR_DATA_NACK: // data received, nack sent + // put final byte into buffer + twi_masterBuffer[twi_masterBufferIndex++] = TWDR; + case TW_MR_SLA_NACK: // address sent, nack received + twi_stop(); + break; + // TW_MR_ARB_LOST handled by TW_MT_ARB_LOST case + + // Slave Receiver + case TW_SR_SLA_ACK: // addressed, returned ack + case TW_SR_GCALL_ACK: // addressed generally, returned ack + case TW_SR_ARB_LOST_SLA_ACK: // lost arbitration, returned ack + case TW_SR_ARB_LOST_GCALL_ACK: // lost arbitration, returned ack + // enter slave receiver mode + twi_state = TWI_SRX; + // indicate that rx buffer can be overwritten and ack + twi_rxBufferIndex = 0; + twi_reply(1); + break; + case TW_SR_DATA_ACK: // data received, returned ack + case TW_SR_GCALL_DATA_ACK: // data received generally, returned ack + // if there is still room in the rx buffer + if(twi_rxBufferIndex < TWI_BUFFER_LENGTH){ + // put byte in buffer and ack + twi_rxBuffer[twi_rxBufferIndex++] = TWDR; + twi_reply(1); + }else{ + // otherwise nack + twi_reply(0); + } + break; + case TW_SR_STOP: // stop or repeated start condition received + // put a null char after data if there's room + if(twi_rxBufferIndex < TWI_BUFFER_LENGTH){ + twi_rxBuffer[twi_rxBufferIndex] = '\0'; + } + // callback to user defined callback + twi_onSlaveReceive(twi_rxBuffer, twi_rxBufferIndex); + // ack future responses + twi_reply(1); + // leave slave receiver state + twi_state = TWI_READY; + break; + case TW_SR_DATA_NACK: // data received, returned nack + case TW_SR_GCALL_DATA_NACK: // data received generally, returned nack + // nack back at master + twi_reply(0); + break; + + // Slave Transmitter + case TW_ST_SLA_ACK: // addressed, returned ack + case TW_ST_ARB_LOST_SLA_ACK: // arbitration lost, returned ack + // enter slave transmitter mode + twi_state = TWI_STX; + // ready the tx buffer index for iteration + twi_txBufferIndex = 0; + // set tx buffer length to be zero, to verify if user changes it + twi_txBufferLength = 0; + // request for txBuffer to be filled and length to be set + // note: user must call twi_transmit(bytes, length) to do this + twi_onSlaveTransmit(); + // if they didn't change buffer & length, initialize it + if(0 == twi_txBufferLength){ + twi_txBufferLength = 1; + twi_txBuffer[0] = 0x00; + } + // transmit first byte from buffer, fall + case TW_ST_DATA_ACK: // byte sent, ack returned + // copy data to output register + TWDR = twi_txBuffer[twi_txBufferIndex++]; + // if there is more to send, ack, otherwise nack + if(twi_txBufferIndex < twi_txBufferLength){ + twi_reply(1); + }else{ + twi_reply(0); + } + break; + case TW_ST_DATA_NACK: // received nack, we are done + case TW_ST_LAST_DATA: // received ack, but we are done already! + // ack future responses + twi_reply(1); + // leave slave receiver state + twi_state = TWI_READY; + break; + + // All + case TW_NO_INFO: // no state information + break; + case TW_BUS_ERROR: // bus error, illegal stop/start + twi_error = TW_BUS_ERROR; + twi_stop(); + break; + } +} + diff --git a/arduino-0018-linux/libraries/Wire/utility/twi.h b/arduino-0018-linux/libraries/Wire/utility/twi.h new file mode 100755 index 0000000..1258d8d --- /dev/null +++ b/arduino-0018-linux/libraries/Wire/utility/twi.h @@ -0,0 +1,57 @@ +/* + twi.h - TWI/I2C library for Wiring & Arduino + Copyright (c) 2006 Nicholas Zambetti. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef twi_h +#define twi_h + + #include + + //#define ATMEGA8 + + #ifndef CPU_FREQ + #define CPU_FREQ 16000000L + #endif + + #ifndef TWI_FREQ + #define TWI_FREQ 100000L + #endif + + #ifndef TWI_BUFFER_LENGTH + #define TWI_BUFFER_LENGTH 32 + #endif + + #define TWI_READY 0 + #define TWI_MRX 1 + #define TWI_MTX 2 + #define TWI_SRX 3 + #define TWI_STX 4 + + void twi_init(void); + void twi_setAddress(uint8_t); + uint8_t twi_readFrom(uint8_t, uint8_t*, uint8_t); + uint8_t twi_writeTo(uint8_t, uint8_t*, uint8_t, uint8_t); + uint8_t twi_transmit(uint8_t*, uint8_t); + void twi_attachSlaveRxEvent( void (*)(uint8_t*, int) ); + void twi_attachSlaveTxEvent( void (*)(void) ); + void twi_reply(uint8_t); + void twi_stop(void); + void twi_releaseBus(void); + +#endif + diff --git a/arduino-0018-linux/readme.txt b/arduino-0018-linux/readme.txt new file mode 100644 index 0000000..cde4f7c --- /dev/null +++ b/arduino-0018-linux/readme.txt @@ -0,0 +1,408 @@ +Arduino is an open-source physical computing platform based on a simple i/o +board and a development environment that implements the Processing/Wiring +language. Arduino can be used to develop stand-alone interactive objects or +can be connected to software on your computer (e.g. Flash, Processing, MaxMSP). +The boards can be assembled by hand or purchased preassembled; the open-source +IDE can be downloaded for free. + +For more information, see the website at: http://www.arduino.cc/ +or the forums at: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl + +To report a bug or a make a suggestions, go to: +[hardware] http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?board=hwbugs +[software] http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?board=swbugs + +INSTALLATION +Detailed instructions are in reference/Guide_Windows.html and +reference/Guide_MacOSX.html. For Linux, see the Arduino playground: +http://www.arduino.cc/playground/Learning/Linux + +If you are using a USB Arduino, you will need to install the drivers for the +FTDI chip on the board. These can be found in the drivers/ directory. + +* On Windows, plug in the Arduino board and point the Windows Add Hardware + wizard to the drivers/FTDI USB Drivers sub-directory of the Arduino + application directory. + +* On the Mac, install the FTDIUSBSerialDriver_10_4_10_5_10_6.mpkg package. + +* On Linux, drivers are included in kernel versions 2.4.20 or greater. + +CREDITS +Arduino is an open source project, supported by many. + +The Arduino team is composed of Massimo Banzi, David Cuartielles, Tom Igoe, +Gianluca Martino, and David A. Mellis. + +Arduino uses the GNU avr-gcc toolchain, avrdude, avr-libc, and code from +Processing and Wiring. + +Icon Design and Artwork created by Thomas Glaser (envis precisely). + +UPDATES + +0018 + +[core / libraries] + +* Added tone() and noTone() functions for frequency generation. +* Added Serial.end() command. +* Added precision parameter for printing of floats / doubles. +* Incorporated latest version of Firmata. +* Fixed bug w/ disabling use of the RW pin in the LiquidCrystal library. +* No longer disabling interrupts in delayMicroseconds(). +* Fixed bug w/ micros() returning incorrect values from within an interrupt. +* Fixed bug that broke use of analog inputs 8-15 on the Mega. + +[environment] + +* Synchronized with the Processing 1.0.9 code base, bringing various fixes, + including to a bug causing saving to fail when closing the last sketch. + +* Added support for third-party hardware in the SKETCHBOOK/hardware folder, + mirroring the current structure of the hardware folder in Arduino. + +* Added Ctrl-Shift-M / Command-Shift-M shortcut for serial monitor. + +* Hold down shift when pressing the Verify / Compile or Upload toolbar + buttons to generate verbose output (including command lines). + +* Moving build (on upload) from the applet/ sub-folder of the sketch + to a temporary directory (fixing problems with uploading examples from + within the Mac OS X disk image or a Linux application directory). + +* Fixed bug the prevented the inclusion of .cpp and .h (or .c and .h) files + of the same name in a sketch. + +* Improved the Mac OS X disk image (.dmg): added a shortcut to the + Applications folder, a background image with arrow, and new FTDI drivers. + +0017 - 2009.07.25 + +[documentation / examples] +* Many new and revised examples from Tom Igoe. + +[core / libraries] +* Updated LiquidCrystal library by Limor Fried. See reference for details. +* Updated Firmata library to version 2.1 (rev. 25). +* Replaced the Servo library with one (MegaServo) by Michael Margolis. + Supports up to 12 servos on most Arduino boards and 48 on the Mega. +* Improving the accuracy of the baud rate calculations for serial + communication (fixing double-speed problems on 8 MHz Arduino boards). + Thanks to gabebear. + +[environment] +* Synchronized with the Processing 1.0.3 code base (rev. 5503), bringing + many improvements (listed below). +* New icons and about image by Thomas Glaser (envis precisely). +* Support for multiple sketch windows. +* The serial monitor now has its own window. +* Comment / Uncomment menu item (in Edit) and keyboard shortcut. +* Increase and Decrease Indent menu items (in Edit) and keyboard shortcuts. +* Support for third-party libraries in the SKETCHBOOK/libraries folder. +* Libraries are now compiled with the sketch, eliminating the delay when + switching boards and the need to delete .o files when changing library + source code. +* Arduino now comes as an app file (in a dmg) on the Mac. +* Adding the Arduino Nano w/ ATmega328 to the Tools > Board menu. + +0016 - 2009.05.30 + +[documentation / examples] +* New communication examples (w/ corresponding Processing and Max/MSP code) by + Tom Igoe. + +[core / libraries] +* Adding support for the Arduino Pro and Pro Mini 3.3V / 8 MHz w/ ATmega328. +* Adding support for the LilyPad Arduino w/ ATmega328. +* Adding write(str) and write(buf, size) methods to Print, Serial, and the + Ethernet library Client and Server classes. This allows for more efficient + (fewer packet) Ethernet communication. (Thanks to mikalhart.) +* Improvements to the way the Ethernet library Client class connects and + disconnects. Should reduce or eliminate failed connections and long + timeouts. (Thanks to Bruce Luckcuck.) +* Optimizing the timer0 overflow interrupt handler (used for millis() and + micros()). Thanks to westfw and mikalhart. +* Fixing bug that limited the bit() macro to 15 bits. Thanks to Paul Badger. +* Adding ARDUINO version constant (thanks to prodding from mikalhart). + +[environment] +* Ordering the items in the Tools > Board menu. +* Adding "Copy as HTML" command to the Tools menu. +* Eliminating (maybe) the occasional "Couldn't determine program size" errors. + Thanks to the Clever Monkey. +* Moving selection of Linux look-and-feel into the arduino script so it can + be changed by users. Thanks to Eberhard Fahle. + +[tools] +* Adding automatic dependency generation to the Makefile. (Lars Immisch) + +0015 - 2009.03.26 + +[core / libraries] +* Adding support for the Arduino Mega (ATmega1280). + +[environment] +* Reinstating use of core.a library in the build process, slightly shrinking + compiled sketch sizes. (Thanks to William Westfield.) +* Fixing bug in copy for forum (thanks to eried). + +0014 - 2009.03.07 + +[core / libraries] +* Fixing bug that prevented multiple outgoing Client connections with the + ethernet library. + +[environment] +* Clarifying ATmega168 vs. ATmega328 in the Tools > Boards menu. + +[tools] +* Updating the Mac OS X AVR tools to AVR MacPack 20081213. This includes + avr-gcc 4.3.2, which should fix problems with functions called from + within interrupts. + +0013 - 2009.02.06 + +[documentation / examples] +* Adding examples for Parallax Ping Sensor and Memsic 2125 accelerometer. + +[core / libraries] +* Adding support for the ATmega328. The upload speed is 57600 baud, so you + may need to edit boards.txt or reburn your bootloader if you bought an + ATmega328 w/ bootloader from adafruit or other supplier. +* Adding support for printing floats to Print class (meaning that it works + in the Serial, Ethernet, and LiquidCrystal classes too). Includes two + decimal places. +* Added word, word(), bitRead(), bitWrite(), bitSet(), bitClear(), bit(), + lowByte(), and highByte(); see reference for details. +* Working around problem that caused PWM output on pins 5 and 6 to never go + to 0 (causing, for example, an LED to continue to glow faintly). +* Removing cast macros, since function-style casts are a feature of C++. This + should fix contributed libraries that broke in Arduino 0012. +* Modifying pulseIn() to wait for a transition to start timing (i.e. ignoring + any pulse that had already started when the function was called). +* Fixing bug in random() that limited the ranges of values generated. Thanks + to Mikal Hart. +* Modifying delay() to pause for at least the given number of milliseconds. +* Fixing bug in Ethernet library that interfered with use of pins 8 and 9. +* Originating each outgoing network connection from a different port (in the + Client class of the Ethernet library). Thanks to Paul and joquer. +* Updating ATmega168 bootloader to work with standard distributions of avrdude + (responding to signature requests made with the universal SPI command) and + correctly store EEPROM data. Thanks to ladyada. + +[environment] +* Omitting unused functions from compiled sketches, reducing their size. +* Changing compilation process to allow for use of EEMEM directive (although + not yet uploading EEPROM data). + +0012 - 2008.09.18 + +* Added Arduino Nano to the boards menu. +* Arduino Pro or Pro Mini (8 MHz) to the boards menu. +* Added Firmata library by Hans Steiner and others. This provides a standard + protocol for communicating with software on the computer. +* Added an Ethernet library for use with the Arduino Ethernet Shield. +* Added a Servo library based on the work of Jim Studt. +* Added a LiquidCrystal library based on the work in the playground. It + supports both 4- and 8-bit modes. +* Improved millis(): it now overflows after 49 days instead of 9 hours, but + now uses slightly more processing power. +* Fixed reversing direction bug in Stepper library. (Thanks to Wayne Holder.) +* Moved insertion of #include to after any comments and #include + statements in the main sketch file. This means that an #include + now works. +* Upgraded to newer versions of avr-gcc (4.3.0) and avr-libc (1.6). This + provides support for newer Atmel chips, but may increase the size + of sketches. +* Allowing per-board specification of the upload.using preference, allowing + upload via bootloader to some boards and via a programmer to others. +* Added return values to some functions in the Wire library to allow for + better error handling. +* Fixed random() to work with long values. +* Creation of an abstract Print base-class to allow Serial, SoftwareSerial, + and LiquidCrystal to share code for print() and println(). +* Incorporated ladyada's watchdog timer mods to the bootloader source, but + only compiling them in for the Pro and Pro Mini (because they are included + in the bootloader being burned on the boards by SparkFun). + +0011 - 2008.03.28 + +* Fixed Find in Reference. +* Added map() function for mapping values from one range to another. +* Added analogReference() function. +* Added interrupts() and noInterrupts() functions. +* Added degrees() and radians() functions. +* Added timeout parameter (in microseconds) to pulseIn(); default is 1 second. +* Support for uploading sketch using a programmer. +* Improved detection of functions that need prototyping. +* Placing function prototypes after #include's and #define's. +* No longer moving #include statements to the top of the sketch. +* Can now drag .pde files onto the Arduino dock icon on Mac OS X. + Thanks to Peter Sgouros. +* New script for downloading the reference from Tom Pollard. Thanks Tom! +* Miscellaneous Mac OS X and other patches from Wim Lewis. Thanks Wim! +* Updated Mac OS X FTDI drivers. + +0010 - 2007.10.11 + +* Support for the LilyPad Arduino. +* Vista support. +* Mac OS X universal distribution. +* Printing! +* Copy for discourse. +* New Board menu replaces the Microcontroller menu. +* New Burn Bootloader menu offers a choice of programmers. +* New and improved keyboard shortcuts. +* Fixed some find/replace bugs. +* Better auto-format. +* Improved error messages when uploading. +* Support for COM10 and higher on Windows. +* Fixed automatic refresh of the Serial Port menu under Windows. +* Quaqua look-and-feel on Mac OS X. +* Reorganization of the Arduino application directory. + +0009 - 2007.08.06 + +* Added support for the Arduino Diecimila. +* Switched to using avrdude (instead of uisp) for uploading sketches. +* Added the ability to burn NG and Diecimila bootlaoders (with an AVRISPmkII). +* Fixed a bug in SoftwareSerial (a hardware serial function was being called + instead of the software serial equivalent). Thanks to brianbr for the + report and fix. + +0008 - 2007.06.09 + +* Updated examples (in distribution and on the website). +* Added an EEPROM library (see reference for details). +* Added a Stepper motor library (see reference). +* Patched to reduce binary sketch sizes by building the Arduino core as + a library (.a) file - now only the needed parts of the core are linked into + a sketch. Originally written by Nicolas Roland, revised by Don Cross. +* Fixed bug in Serial.available(). Report and fix by Don Cross. +* Now recompiling libraries when switching microcontrollers. Report by + Julian Bleecker; fix by Nicholas Zambetti. +* Cleaned up core functions: moved pin definitions into program space to save + RAM, and other minor improvements. Contributed by Jim Studt. +* Lots of reference additions and fixes from Paul Badger. +* Changed default microcontroller to ATmega168 from ATmega8. +* Removed the delay from analogRead(). +* Activating TWI/I2C pullup resistors on the ATmega168 (in addition to the + ATmega8). + +0007 - 2006.12.25 + +* Smaller core (about 3.5 KB instead of 4.5 KB). +* Added a SoftwareSerial library (thanks to Antonio, Heather Dewey-Hagborg, and + bigengineer for their help). +* Implemented a Serial.flush() routine; see reference for details. +* Digital pins 0 and 1 can be used for i/o until a call to Serial.begin(). +* Replaced avr-lib's uart routines with custom code for handling serial + communication and modified C++ serial commands to call the C serial commands; + the code may behave slightly differently in border cases (e.g. non-standard + speeds, or on overflow). +* Added attachInterrupt() and detachInterrupt() functions for handling of + external interrupts on pins 2 and 3. +* Implemented shiftOut() routine; see reference for details. +* Defining binary constants: e.g. B1010 is 6. +* Mac versions no longer require running of the macosx_setup.command script. +* Windows version comes with the FTDI USB drivers already unzipped. +* New Linux binary distribution (still requires some programs to be + pre-installed). + +0006 - 2006.10.21 + +* Mac version no longer requires Java 1.5, meaning it should run on 10.3.9. +* Added support for analog inputs 6 and 7 and pwm on pins 5 and 6 on the + on the ATmega168 used in the Arduino Mini (extra analog inputs not available + in DIP ATmega168s). +* You now select the baud rate for the serial monitor from within the editor + status bar when the serial monitor is running instead of from the Tools menu. +* Pressing enter within the serial monitor edit box no longer appends a newline + to the message sent to the board. +* Included the Wire (TWI) library from Wiring. +* Updated the reference. + +0005 - 2006.09.26 + +* Applied patch from Hans Steiner to improve Linux support by searching for avr + tools in the user's path instead of expecting them at a fixed location. +* Added an upload.verbose preference for help in debugging. +* ATmega168 support! +* New Wiring-compatible randomSeed(), random(max) and random(min, max) functions + (except operating on longs instead of floats). +* Fixed bug that sometimes caused uploading of old versions of a sketch. +* Serial monitor nows include an interface to send messages to the Arduino + board. Pressing return appends a newline, pushing the send button doesn't. +* Now displaying "burning bootloader..." and "compiling..." status messages. + +0004 - 2006.04.26 + +* Main sketch is now compiled as C++ (instead of C). +* Updated avr toolchain. +* printInteger(), printHex(), etc. now handle longs. +* millis() fixed (now overflows after days, not minutes) +* Fixed path to java in Windows run.bat. +* Added Matrix and Sprite libraries (written with Nicholas Zambetti). +* PWM now working on pin 11 (in addition to pins 9 and 10). +* Slowed PWM frequency (on all three PWM pins) to 1KHz. +* Now give an error if compiled sketch is too big. +* Fixed abs(), min(), max(), and constrain() macros. +* Added menu items to the IDE to burn bootloader. +* Now display binary sketch size on upload, and give error if too big. +* Added C++ serial library. +* Resynced with Processing/Wiring IDE code (improved auto-format, faster logging + to serial monitor console, other bug fixes) +* New library system. +* Updated to latest version of the RXTX serial library; Mac users will need to + rerun macosx_setup.command. + +0003 - 2006.01.16 + +API Changes +* Reversed the analog input pins to correspond to newer boards. This means + a call, for example, to analogRead(0) must be changed to analogRead(5) in + order to read the same physical pin. +* Added a printNewline() function (which sends '\n' = ASCII 10). + +New Stuff +* Reference is included (features native to C not yet documented). +* Serial monitor added (click the toolbar button to turn it on or off). Baud + rate is controlled by the Serial Monitor Baud Rate Menu, defaults to 9600. + Icon and implementation from Wiring. +* Serial port menu now automatically refreshes when opened. +* New blue color scheme and icons courtesy of Noah Shibley (colors are hardcoded + into the source to ensure consistency with image files). +* Keyspan and FTDI USB drivers included with Mac and Windows distributions. + +Bug Fixes +* millis() now updates every millisecond instead of every second. +* Bootloader included with Windows distribution (it was already in the Mac + dist). +* Updated icon of the Windows executable. +* Now flushing the serial port before uploading (should fix some errors). +* Improved accuracy of the delayMicroseconds() function. + +Other +* Upload rate no longer selectable from a menu within the IDE. Instead, edit + the serial.download_rate item in the preferences.txt file. +* Created Xcode project for building Arduino on the Mac (doesn't yet regenerate + the grammar files or package the distribution); active target should be "App". +* Removed unused or unimplemented items from menus. + +0002 - 2005.10.05 + +* New build process no longer uses makefiles; now controlled by preferences.txt. +* core/ replaced with targets/; can now link against Wiring libraries. +* Replaced print() with printString, printInteger, printHex, printByte, etc. +* Added menu for selecting serial port speed. +* Updated icon. +* Bootloader shrunk to less than 1 KB; fuses updated accordingly. +* Added serialRead(), serialAvailable(), and delayMicroseconds(). + +0001 - 2005.08.25 + +* This is the first released of the unified IDE + language library + it's a terrible hack... but it works. at the moment it's in alpha stage + but it can be used to work. +* The processing preprocessor is included but not used. diff --git a/arduino-0018-linux/reference/ASCIIchart.html b/arduino-0018-linux/reference/ASCIIchart.html new file mode 100644 index 0000000..3584950 --- /dev/null +++ b/arduino-0018-linux/reference/ASCIIchart.html @@ -0,0 +1,232 @@ + + + + Arduino - ASCIIchart + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

ASCII chart

+

The ASCII (American Standard Code for Information Interchange) encoding dates to the 1960's. It is the standard way that text is encoded numerically. +

+

Note that the first 32 characters (0-31) are non-printing characters, often called control characters. The more useful characters have been labeled. +

+

+
+
+DEC     Character
+Value
+
+0	null
+1
+2
+3
+4
+5
+6
+7
+8
+9	tab	
+10	line feed	
+11
+12
+13	carriage return
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+
+
+
+
+
+DEC     Character
+Value
+
+32	space
+33	!
+34	"
+35	#
+36	$
+37	%
+38	&
+39	'
+40	(
+41	)
+42	*
+43	+
+44	,
+45	-
+46	.
+47	/
+48	0
+49	1
+50	2
+51	3
+52	4
+53	5
+54	6
+55	7
+56	8
+57	9
+58	:
+59	;
+60	<
+61	=
+62	>
+63	?
+
+
+
+
+
+DEC     Character
+Value
+
+64	@
+65	A
+66	B
+67	C
+68	D
+69	E
+70	F
+71	G
+72	H
+73	I
+74	J
+75	K
+76	L
+77	M
+78	N
+79	O
+80	P
+81	Q
+82	R
+83	S
+84	T
+85	U
+86	V
+87	W
+88	X
+89	Y
+90	Z
+91	[
+92	\
+93	]
+94	^
+95	_
+
+
+
+
+
+DEC     Character
+Value
+
+96	`
+97	a
+98	b
+99	c
+100	d
+101	e
+102	f
+103	g
+104	h
+105	i
+106	j
+107	k
+108	l
+109	m
+110	n
+111	o
+112	p
+113	q
+114	r
+115	s
+116	t
+117	u
+118	v
+119	w
+120	x
+121	y
+122	z
+123	{
+124	|
+125	}
+126	~
+127
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Abs.html b/arduino-0018-linux/reference/Abs.html new file mode 100644 index 0000000..dbd76b3 --- /dev/null +++ b/arduino-0018-linux/reference/Abs.html @@ -0,0 +1,89 @@ + + + + Arduino - Abs + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

abs(x)

+

Description

+

Computes the absolute value of a number. +

+

Parameters

+

x: the number +

+

Returns

+

x: if x is greater than or equal to 0. +

+

-x: if x is less than 0. +

+

Warning

+

Because of the way the abs() function is implemented, avoid using other functions inside the brackets, it may lead to incorrect results. +

+

+abs(a++);   // avoid this - yields incorrect results
+
+a++;          // use this instead -
+abs(a);       // keep other math outside the function
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/AnalogRead.html b/arduino-0018-linux/reference/AnalogRead.html new file mode 100644 index 0000000..b62e970 --- /dev/null +++ b/arduino-0018-linux/reference/AnalogRead.html @@ -0,0 +1,107 @@ + + + + Arduino - AnalogRead + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

analogRead()

+

Description

+

Reads the value from the specified analog pin. The Arduino board contains a 6 channel (8 channels on the Mini and Nano), 10-bit analog to digital converter. This means that it will map input voltages between 0 and 5 volts into integer values between 0 and 1023. This yields a resolution between readings of: 5 volts / 1024 units or, .0049 volts (4.9 mV) per unit. +

+

It takes about 100 us (0.0001 s) to read an analog input, so the maximum reading rate is about 10,000 times a second. +

+

Syntax

+

analogRead(pin) +

+

Parameters

+

pin: the number of the analog input pin to read from (0 to 5 on most boards, 0 to 7 on the Mini and Nano) +

+

Returns

+

int (0 to 1023) +

+

Note

+

If the analog input pin is not connected to anything, the value returned by analogRead() will fluctuate based on a number of factors (e.g. the values of the other analog inputs, how close your hand is to the board, etc.). +

+

Example

+
 
+int analogPin = 3;     // potentiometer wiper (middle terminal) connected to analog pin 3
+                       // outside leads to ground and +5V
+int val = 0;           // variable to store the value read
+
+void setup()
+{
+  Serial.begin(9600);          //  setup serial
+}
+
+void loop()
+{
+  val = analogRead(analogPin);    // read the input pin
+  Serial.println(val);             // debug value
+}
+
+
+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/AnalogReference.html b/arduino-0018-linux/reference/AnalogReference.html new file mode 100644 index 0000000..43f8cf7 --- /dev/null +++ b/arduino-0018-linux/reference/AnalogReference.html @@ -0,0 +1,99 @@ + + + + Arduino - AnalogReference + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

analogReference(type)

+

Description

+

Configures the reference voltage used for analog input. The analogRead() function will return 1023 for an input equal to the reference voltage. The options are: +

+

  • DEFAULT: the default analog reference of 5 volts. +
  • INTERNAL: an built-in reference, equal to 1.1 volts on the ATmega168 and 2.56 volts on the ATmega8. +
  • EXTERNAL: the voltage applied to the AREF pin is used as the reference. +

Parameters

+

type: which type of reference to use (DEFAULT, INTERNAL, or EXTERNAL). +

+

Returns

+

None. +

+

Warning

+

It is a good idea to connect external voltages to the AREF pin through a 5K resistor. This will prevent possible internal damage to the Atmega chip if analogReference() software settings are incompatible with the current hardware setup. Note that the resistor will alter the voltage that gets used as the reference because there is an internal 32K resistor on the AREF pin. The two act as a voltage divider, so, for example, 2.5V applied through the resistor will yield ~2.2V at the AREF pin. +

+

Connecting external voltages through a resistor makes it possible to switch the AREF voltage on the fly, say from the 5 volt DEFAULT setting, to a 3.3 volt EXTERNAL setting (and applied voltage), without the hardware setup affecting either ADC configuration. +

+

Use of the AREF pin

+

The voltage applied to the AREF pin directly governs the ADC and sets the voltage at which the ADC will report its highest reading, 1023. Lower voltages applied to ADC (analog) pins will be scaled proportionally, so at the DEFAULT setting (5 volt internal connection), 2.5 volts on an analog pin will report approximately 512. +

+

The default configuration on all Arduino implementations is to have nothing connected externally to the AREF pin (Atmega pin 21). In this case the DEFAULT analogReference software setting connects the AVCC voltage, internally, to the AREF pin. This appears to be a low impedance connection (high current) and voltages, other than AVCC, applied (erroneously) to the AREF pin in the DEFAULT setting could damage the ATMEGA chip. +

+

The AREF pin may also be connected internally to an (internal) 1.1 volt source (or 2.56 on the ATmega8) with analogReference(INTERNAL). With this setting voltages applied to the ADC (analog) pins that are at or above the reference will report 1023 when read with analogRead. Lower voltages will report proportional values, so 0.55 volts will report about 512. +

+

The connection between the 1.1 volt source and the AREF pin is a very high impedance (low current) connection, so that reading the 1.1 (internally supplied) voltage at the AREF pin may only be done with a more expensive, high-impedance multimeter. An external voltage applied (erroneously) to AREF pin while using the INTERNAL setting will not damage the chip, but will totally override the 1.1 volt source, and ADC readings will be governed by the external voltage. It is still desirable to connect any external voltage to the AREF pin however, through a 5K resistor to avoid the problem cited above. +

+

The correct software setting for using the AREF pin with an external voltage is analogReference(EXTERNAL). This disconnects both of the internal references and the voltage applied externally to the AREF pin sets the reference voltage for the ADC. +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/AnalogWrite.html b/arduino-0018-linux/reference/AnalogWrite.html new file mode 100644 index 0000000..8f0d708 --- /dev/null +++ b/arduino-0018-linux/reference/AnalogWrite.html @@ -0,0 +1,115 @@ + + + + Arduino - AnalogWrite + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

analogWrite()

+

Description

+

Writes an analog value (PWM wave) to a pin. Can be used to light a LED at varying brightnesses or drive a motor at various speeds. After a call to analogWrite(), the pin will generate a steady square wave of the specified duty cycle until the next call to analogWrite() (or a call to digitalRead() or digitalWrite() on the same pin). The frequency of the PWM signal is approximately 490 Hz. +

+

On newer Arduino boards (including the Mini and BT) with the ATmega168 chip, this function works on pins 3, 5, 6, 9, 10, and 11. Older USB and serial Arduino boards with an ATmega8 only support analogWrite() on pins 9, 10, and 11. +

+

Syntax

+

analogWrite(pin, value) +

+

Parameters

+

pin: the pin to write to. +

+

value: the duty cycle: between 0 (always off) and 255 (always on). +

+

Returns

+

nothing +

+

Notes and Known Issues

+

analogWrite has nothing whatsoever to do with the analog pins or analogRead. +

+

You do not need to call pinMode() to set the pin as an output before calling analogWrite(). +

+

The PWM outputs generated on pins 5 and 6 will have higher-than-expected duty cycles. This is because of interactions with the millis() and delay() functions, which share the same internal timer used to generate those PWM outputs. This will be noticed mostly on low duty-cycle settings (e.g 0 - 10) and may result in analogWrite(x, 0) not fully turning off the output on pins 5 & 6, as one would expect. +

+

Example

+

Sets the output to the LED proportional to the value read from the potentiometer. +

+

 
+int ledPin = 9;      // LED connected to digital pin 9
+int analogPin = 3;   // potentiometer connected to analog pin 3
+int val = 0;         // variable to store the read value
+
+void setup()
+{
+  pinMode(ledPin, OUTPUT);   // sets the pin as output
+}
+
+void loop()
+{
+  val = analogRead(analogPin);   // read the input pin
+  analogWrite(ledPin, val / 4);  // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
+}
+
+
+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Arithmetic.html b/arduino-0018-linux/reference/Arithmetic.html new file mode 100644 index 0000000..5fe17bc --- /dev/null +++ b/arduino-0018-linux/reference/Arithmetic.html @@ -0,0 +1,100 @@ + + + + Arduino - Arithmetic + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Addition, Subtraction, Multiplication, & Division

+

Description

+

These operators return the sum, difference, product, or quotient (respectively) of the two operands. The operation is conducted using the data type of the operands, so, for example, 9 / 4 gives 2 since 9 and 4 are ints. This also means that the operation can overflow if the result is larger than that which can be stored in the data type (e.g. adding 1 to an int with the value 32,767 gives -32,768). If the operands are of different types, the "larger" type is used for the calculation. +

+

If one of the numbers (operands) are of the type float or of type double, floating point math will be used for the calculation. +

+

Examples

+
+y = y + 3;
+x = x - 7;
+i = j * 6;
+r = r / 5;
+
+
+

Syntax

+
+result = value1 + value2;
+result = value1 - value2;
+result = value1 * value2;
+result = value1 / value2;
+
+
+

Parameters:

+

value1: any variable or constant +

+

value2: any variable or constant +

+

Programming Tips:

+
  • Know that integer constants default to int, so some constant calculations may overflow (e.g. 60 * 1000 will yield a negative result). +

  • Choose variable sizes that are large enough to hold the largest results from your calculations +

  • Know at what point your variable will "roll over" and also what happens in the other direction e.g. (0 - 1) OR (0 - - 32768) +

  • For math that requires fractions, use float variables, but be aware of their drawbacks: large size, slow computation speeds +

  • Use the cast operator e.g. (int)myFloat to convert one variable type to another on the fly. +

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Array.html b/arduino-0018-linux/reference/Array.html new file mode 100644 index 0000000..01382b4 --- /dev/null +++ b/arduino-0018-linux/reference/Array.html @@ -0,0 +1,119 @@ + + + + Arduino - Array + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Arrays

+

An array is a collection of variables that are accessed with an index number. Arrays in the C programming language, on which Arduino is based, can be complicated, but using simple arrays is relatively straightforward. +

+

Creating (Declaring) an Array

+

All of the methods below are valid ways to create (declare) an array. +

+

+  int myInts[6];
+  int myPins[] = {2, 4, 8, 3, 6};
+  int mySensVals[6] = {2, 4, -8, 3, 2};
+  char message[6] = "hello";
+
+
+

You can declare an array without initializing it as in myInts.

In myPins we declare an array without explicitly choosing a size. The compiler counts the elements and creates an array of the appropriate size. +

+

Finally you can both initialize and size your array, as in mySensVals. Note that when declaring an array of type char, one more element than your initialization is required, to hold the required null character. +

+

Accessing an Array

+

Arrays are zero indexed, that is, referring to the array initialization above, the first element of the array is at index 0, hence

mySensVals[0] == 2, mySensVals[1] == 4, and so forth. +

+

It also means that in an array with ten elements, index nine is the last element. Hence: +

+int myArray[10]={9,3,2,4,3,2,7,8,9,11};
+     // myArray[9]    contains 11
+     // myArray[10]   is invalid and contains random information (other memory address)      
+
+
+

For this reason you should be careful in accessing arrays. Accessing past the end of an array (using an index number greater than your declared array size - 1) is reading from memory that is in use for other purposes. Reading from these locations is probably not going to do much except yield invalid data. Writing to random memory locations is definitely a bad idea and can often lead to unhappy results such as crashes or program malfunction. This can also be a difficult bug to track down. +

+

Unlike BASIC or JAVA, the C compiler does no checking to see if array access is within legal bounds of the array size that you have declared. +

+

To assign a value to an array:

+
+mySensVals[0] = 10;
+
+

To retrieve a value from an array:

+

x = mySensVals[4]; +

+

Arrays and FOR Loops

+

Arrays are often manipulated inside for loops, where the loop counter is used as the index for each array element. For example, to print the elements of an array over the serial port, you could do something like this: +

+

+int i;
+for (i = 0; i < 5; i = i + 1) {
+  Serial.println(myPins[i]);
+}
+

Example

+

For a complete program that demonstrates the use of arrays, see the Knight Rider example from the Tutorials. +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Assignment.html b/arduino-0018-linux/reference/Assignment.html new file mode 100644 index 0000000..a514842 --- /dev/null +++ b/arduino-0018-linux/reference/Assignment.html @@ -0,0 +1,86 @@ + + + + Arduino - Assignment + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

= assignment operator (single equal sign)

+

Stores the value to the right of the equal sign in the variable to the left of the equal sign. +

+

The single equal sign in the C programming language is called the assignment operator. It has a different meaning than in algebra class where it indicated an equation or equality. The assignment operator tells the microcontroller to evaluate whatever value or expression is on the right side of the equal sign, and store it in the variable to the left of the equal sign. +

+

Example

+
 int sensVal;                 // declare an integer variable named sensVal
+ senVal = analogRead(0);       // store the (digitized) input voltage at analog pin 0 in SensVal
+
+

Programming Tips

+

The variable on the left side of the assignment operator ( = sign ) needs to be able to hold the value stored in it. If it is not large enough to hold a value, the value stored in the variable will be incorrect. +

+

Don't confuse the assignment operator [ = ] (single equal sign) with the comparison operator [ == ] (double equal signs), which evaluates whether two expressions are equal. +

+

See Also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/AttachInterrupt.html b/arduino-0018-linux/reference/AttachInterrupt.html new file mode 100644 index 0000000..df4b626 --- /dev/null +++ b/arduino-0018-linux/reference/AttachInterrupt.html @@ -0,0 +1,115 @@ + + + + Arduino - AttachInterrupt + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

attachInterrupt(interrupt, function, mode)

+

Description

+

Specifies a function to call when an external interrupt occurs. Replaces any previous function that was attached to the interrupt. Most Arduino boards have two external interrupts: numbers 0 (on digital pin 2) and 1 (on digital pin 3). The Arduino Mega has an additional four: numbers 2 (pin 21), 3 (pin 20), 4 (pin 19), and 5 (pin 18). +

+

Parameters

+

interrupt: the number of the interrupt (int) +

+

function: the function to call when the interrupt occurs; this function must take no parameters and return nothing. This function is sometimes referred to as an interrupt service routine. +

+

mode defines when the interrupt should be triggered. Four contstants are predefined as valid values: +

  • LOW to trigger the interrupt whenever the pin is low, +
  • CHANGE to trigger the interrupt whenever the pin changes value +
  • RISING to trigger when the pin goes from low to high, +
  • FALLING for when the pin goes from high to low. +

Returns

+

none +

+

Note

+

Inside the attached function, delay() won't work and the value returned by millis() will not increment. Serial data received while in the function may be lost. You should declare as volatile any variables that you modify within the attached function. +

+

Using Interrupts

+

Interrupts are useful for making things happen automatically in microcontroller programs, and can help solve timing problems. A good task for using an interrupt might be reading a rotary encoder, monitoring user input. +

+

If you wanted to insure that a program always caught the pulses from a rotary encoder, never missing a pulse, it would make it very tricky to write a program to do anything else, because the program would need to constantly poll the sensor lines for the encoder, in order to catch pulses when they occurred. Other sensors have a similar interface dynamic too, such as trying to read a sound sensor that is trying to catch a click, or an infrared slot sensor (photo-interrupter) trying to catch a coin drop. In all of these situations, using an interrupt can free the microcontroller to get some other work done while not missing the doorbell. +

+

Example

+
int pin = 13;
+volatile int state = LOW;
+
+void setup()
+{
+  pinMode(pin, OUTPUT);
+  attachInterrupt(0, blink, CHANGE);
+}
+
+void loop()
+{
+  digitalWrite(pin, state);
+}
+
+void blink()
+{
+  state = !state;
+}
+
+
+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/BeginSerial.html b/arduino-0018-linux/reference/BeginSerial.html new file mode 100644 index 0000000..b206a2a --- /dev/null +++ b/arduino-0018-linux/reference/BeginSerial.html @@ -0,0 +1,85 @@ + + + + Arduino - BeginSerial + + + +
+ + + + + + +
+ +
+

Language | Libraries | Comparison +

beginSerial(speed)

+

Description

+

Initializes the serial port. Should be called from inside setup(). +

+

Parameters

+

speed: the baud rate to use for the serial communication (e.g. 9600 or 19200) +

+

Returns

+

None +

+

Note

+

Serial Arduino boards supports speeds up to 19200 baud. USB boards support up to 115200 baud (with release 0003 and later of the Arduino software). +

+

See also

+

Reference Home +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Bit.html b/arduino-0018-linux/reference/Bit.html new file mode 100644 index 0000000..0baa8c1 --- /dev/null +++ b/arduino-0018-linux/reference/Bit.html @@ -0,0 +1,85 @@ + + + + Arduino - Bit + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

bit()

+

Description

+

Computes the value of the specified bit (bit 0 is 1, bit 1 is 2, bit 2 is 4, etc.). +

+

Syntax

+

bit(n) +

+

Parameters

+

n: the bit whose value to compute +

+

Returns

+

the value of the bit +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/BitClear.html b/arduino-0018-linux/reference/BitClear.html new file mode 100644 index 0000000..d392c2c --- /dev/null +++ b/arduino-0018-linux/reference/BitClear.html @@ -0,0 +1,87 @@ + + + + Arduino - BitClear + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

bitClear()

+

Description

+

Clears (writes a 0 to) a bit of a numeric variable. +

+

Syntax

+

bitClear(x, n) +

+

Parameters

+

x: the numeric variable whose bit to clear +

+

n: which bit to clear, starting at 0 for the least-significant (rightmost) bit +

+

Returns

+

none +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/BitRead.html b/arduino-0018-linux/reference/BitRead.html new file mode 100644 index 0000000..dd45e33 --- /dev/null +++ b/arduino-0018-linux/reference/BitRead.html @@ -0,0 +1,87 @@ + + + + Arduino - BitRead + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

bitRead()

+

Description

+

Reads a bit of a number. +

+

Syntax

+

bitRead(x, n) +

+

Parameters

+

x: the number from which to read +

+

n: which bit to read, starting at 0 for the least-significant (rightmost) bit +

+

Returns

+

the value of the bit (0 or 1). +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/BitSet.html b/arduino-0018-linux/reference/BitSet.html new file mode 100644 index 0000000..8e27a94 --- /dev/null +++ b/arduino-0018-linux/reference/BitSet.html @@ -0,0 +1,87 @@ + + + + Arduino - BitSet + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

bitSet()

+

Description

+

Sets (writes a 1 to) a bit of a numeric variable. +

+

Syntax

+

bitSet(x, n) +

+

Parameters

+

x: the numeric variable whose bit to set +

+

n: which bit to set, starting at 0 for the least-significant (rightmost) bit +

+

Returns

+

none +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/BitWrite.html b/arduino-0018-linux/reference/BitWrite.html new file mode 100644 index 0000000..468ba00 --- /dev/null +++ b/arduino-0018-linux/reference/BitWrite.html @@ -0,0 +1,89 @@ + + + + Arduino - BitWrite + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

bitWrite()

+

Description

+

Writes a bit of a numeric variable. +

+

Syntax

+

bitWrite(x, n, b) +

+

Parameters

+

x: the numeric variable to which to write +

+

n: which bit of the number to write, starting at 0 for the least-significant (rightmost) bit +

+

b: the value to write to the bit (0 or 1) +

+

Returns

+

none +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Bitshift.html b/arduino-0018-linux/reference/Bitshift.html new file mode 100644 index 0000000..084a803 --- /dev/null +++ b/arduino-0018-linux/reference/Bitshift.html @@ -0,0 +1,119 @@ + + + + Arduino - Bitshift + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

bitshift left (<<), bitshift right (>>)

+

Description

+

From The Bitmath Tutorial in The Playground +

+

There are two bit shift operators in C++: the left shift operator << and the right shift operator >>. These operators cause the bits in the left operand to be shifted left or right by the number of positions specified by the right operand.

More on bitwise math may be found here. +

+

Syntax

+

variable << number_of_bits +

+

variable >> number_of_bits +

+

Parameters

+

variable - (byte, int, long) +number_of_bits integer <= 32 +

+

Example:

+
    int a = 5;        // binary: 0000000000000101
+    int b = a << 3;   // binary: 0000000000101000, or 40 in decimal
+    int c = b >> 3;   // binary: 0000000000000101, or back to 5 like we started with
+
+

When you shift a value x by y bits (x << y), the leftmost y bits in x are lost, literally shifted out of existence: +

+

    int a = 5;        // binary: 0000000000000101
+    int b = a << 14;  // binary: 0100000000000000 - the first 1 in 101 was discarded
+
+

If you are certain that none of the ones in a value are being shifted into oblivion, a simple way to think of the left-shift operator is that it multiplies the left operand by 2 raised to the right operand power. For example, to generate powers of 2, the following expressions can be employed: +

+

    1 <<  0  ==    1
+    1 <<  1  ==    2
+    1 <<  2  ==    4
+    1 <<  3  ==    8
+    ...
+    1 <<  8  ==  256
+    1 <<  9  ==  512
+    1 << 10  == 1024
+    ...
+
+

When you shift x right by y bits (x >> y), and the highest bit in x is a 1, the behavior depends on the exact data type of x. If x is of type int, the highest bit is the sign bit, determining whether x is negative or not, as we have discussed above. In that case, the sign bit is copied into lower bits, for esoteric historical reasons: +

+

    int x = -16;     // binary: 1111111111110000
+    int y = x >> 3;  // binary: 1111111111111110
+
+

This behavior, called sign extension, is often not the behavior you want. Instead, you may wish zeros to be shifted in from the left. It turns out that the right shift rules are different for unsigned int expressions, so you can use a typecast to suppress ones being copied from the left: +

+

    int x = -16;                   // binary: 1111111111110000
+    int y = (unsigned int)x >> 3;  // binary: 0001111111111110
+
+

If you are careful to avoid sign extension, you can use the right-shift operator >> as a way to divide by powers of 2. For example: +

+

    int x = 1000;
+    int y = x >> 3;   // integer division of 1000 by 8, causing y = 125.
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/BitwiseAnd.html b/arduino-0018-linux/reference/BitwiseAnd.html new file mode 100644 index 0000000..7bf6c5b --- /dev/null +++ b/arduino-0018-linux/reference/BitwiseAnd.html @@ -0,0 +1,169 @@ + + + + Arduino - BitwiseAnd + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Bitwise AND (&), Bitwise OR (|), Bitwise XOR (^)

+

Bitwise AND (&)

+

The bitwise operators perform their calculations at the bit level of variables. They help solve a wide range of common programming problems. Much of the material below is from an excellent tutorial on bitwise math wihch may be found here. +

+

Description and Syntax

+

Below are descriptions and syntax for all of the operators. Further details may be found in the referenced tutorial. +

+

Bitwise AND (&)

+

The bitwise AND operator in C++ is a single ampersand, &, used between two other integer expressions. Bitwise AND operates on each bit position of the surrounding expressions independently, according to this rule: if both input bits are 1, the resulting output is 1, otherwise the output is 0. Another way of expressing this is: +

+

    0  0  1  1    operand1
+    0  1  0  1    operand2
+    ----------
+    0  0  0  1    (operand1 & operand2) - returned result
+
+

In Arduino, the type int is a 16-bit value, so using & between two int expressions causes 16 simultaneous AND operations to occur. In a code fragment like: +

+

    int a =  92;    // in binary: 0000000001011100
+    int b = 101;    // in binary: 0000000001100101
+    int c = a & b;  // result:    0000000001000100, or 68 in decimal.
+
+

Each of the 16 bits in a and b are processed by using the bitwise AND, and all 16 resulting bits are stored in c, resulting in the value 01000100 in binary, which is 68 in decimal. +

+

One of the most common uses of bitwise AND is to select a particular bit (or bits) from an integer value, often called masking. See below for an example +

+

Bitwise OR (|)

+

The bitwise OR operator in C++ is the vertical bar symbol, |. Like the & operator, | operates independently each bit in its two surrounding integer expressions, but what it does is different (of course). The bitwise OR of two bits is 1 if either or both of the input bits is 1, otherwise it is 0. In other words: +

+

    0  0  1  1    operand1
+    0  1  0  1    operand2
+    ----------
+    0  1  1  1    (operand1 | operand2) - returned result
+
+

Here is an example of the bitwise OR used in a snippet of C++ code: +

+

    int a =  92;    // in binary: 0000000001011100
+    int b = 101;    // in binary: 0000000001100101
+    int c = a | b;  // result:    0000000001111101, or 125 in decimal.
+
+

Example Program

+

A common job for the bitwise AND and OR operators is what programmers call Read-Modify-Write on a port. On microcontrollers, a port is an 8 bit number that represents something about the condition of the pins. Writing to a port controls all of the pins at once. +

+

PORTD is a built-in constant that refers to the output states of digital pins 0,1,2,3,4,5,6,7. If there is 1 in an bit position, then that pin is HIGH. (The pins already need to be set to outputs with the pinMode() command.) So if we write PORTD = B00110001; we have made pins 2,3 & 7 HIGH. +One slight hitch here is that we may also have changeed the state of Pins 0 & 1, which are used by the Arduino for serial communications so we may have interfered with serial communication. +

+

     Our algorithm for the program is:
+
  • Get PORTD and clear out only the bits corresponding to the pins we wish to control (with bitwise AND). +
  • Combine the modified PORTD value with the new value for the pins under control (with biwise OR). +

int i;     // counter variable
+int j;
+
+void setup(){
+DDRD = DDRD | B11111100; // set direction bits for pins 2 to 7, leave 0 and 1 untouched (xx | 00 == xx)
+// same as pinMode(pin, OUTPUT) for pins 2 to 7
+Serial.begin(9600);
+}
+
+void loop(){
+for (i=0; i<64; i++){
+
+PORTD = PORTD & B00000011;  // clear out bits 2 - 7, leave pins 0 and 1 untouched (xx & 11 == xx)
+j = (i << 2);               // shift variable up to pins 2 - 7 - to avoid pins 0 and 1
+PORTD = PORTD | j;          // combine the port information with the new information for LED pins
+Serial.println(PORTD, BIN); // debug to show masking
+delay(100);
+   }
+}
+
+

Bitwise XOR (^)

+

There is a somewhat unusual operator in C++ called bitwise EXCLUSIVE OR, also known as bitwise XOR. (In English this is usually pronounced "eks-or".) The bitwise XOR operator is written using the caret symbol ^. This operator is very similar to the bitwise OR operator |, only it evaluates to 0 for a given bit position when both of the input bits for that position are 1: +

+

    0  0  1  1    operand1
+    0  1  0  1    operand2
+    ----------
+    0  1  1  0    (operand1 ^ operand2) - returned result
+
+

Another way to look at bitwise XOR is that each bit in the result is a 1 if the input bits are different, or 0 if they are the same. +

+

Here is a simple code example: +

+

    int x = 12;     // binary: 1100
+    int y = 10;     // binary: 1010
+    int z = x ^ y;  // binary: 0110, or decimal 6
+
+

The ^ operator is often used to toggle (i.e. change from 0 to 1, or 1 to 0) some of the bits in an integer expression. In a bitwise OR operation if there is a 1 in the mask bit, that bit is inverted; if there is a 0, the bit is not inverted and stays the same. Below is a program to blink digital pin 5. +

+

+// Blink_Pin_5
+// demo for Exclusive OR
+void setup(){
+DDRD = DDRD | B00100000; // set digital pin five as OUTPUT 
+Serial.begin(9600);
+}
+
+void loop(){
+PORTD = PORTD ^ B00100000;  // invert bit 5 (digital pin 5), leave others untouched
+delay(100);
+}
+
+

See Also +

  • &&(Boolean AND) +
  • ||(Boolean OR) +

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/BitwiseCompound.html b/arduino-0018-linux/reference/BitwiseCompound.html new file mode 100644 index 0000000..593b219 --- /dev/null +++ b/arduino-0018-linux/reference/BitwiseCompound.html @@ -0,0 +1,185 @@ + + + + Arduino - BitwiseCompound + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

compound bitwise AND (&=), compound bitwise OR (|=)

+

The compound bitwise operators perform their calculations at the bit level of variables. They are often used to clear and set specific bits of a variable. +

+

See the bitwise AND (&) and bitwise OR (|) operators for the details of their operation, and also the Bitmath Tutorial for more information on bitwise operators. +

+

compound bitwise AND (&=)

+

Description

+

The compound bitwise AND operator (&=) is often used with a variable and a constant to force particular bits in a variable to the LOW state (to 0). This is often referred to in programming guides as "clearing" or "resetting" bits. +

+

Syntax:

+
+x &= y;   // equivalent to x = x & y; 
+
+

Parameters

+

x: a char, int or long variable
y: an integer constant or char, int, or long +

+

Example:

+

First, a review of the Bitwise AND (&) operator +

+   0  0  1  1    operand1
+   0  1  0  1    operand2
+   ----------
+   0  0  0  1    (operand1 & operand2) - returned result
+
+
+

Bits that are "bitwise ANDed" with 0 are cleared to 0 so, if myByte is a byte variable,
+myByte & B00000000 = 0; +

+

Bits that are "bitwise ANDed" with 1 are unchanged so,
+myByte & B11111111 = myByte; +

+

Note: because we are dealing with bits in a bitwise operator - it is convenient to use the binary formatter with constants. The numbers are still the same value in other representations, they are just not as easy to understand. Also, B00000000 is shown for clarity, but zero in any number format is zero (hmmm something philosophical there?) +

+

Consequently - to clear (set to zero) bits 0 & 1 of a variable, while leaving the rest of the variable unchanged, use the compound bitwise AND operator (&=) with the constant B11111100 +

+   1  0  1  0  1  0  1  0    variable  
+   1  1  1  1  1  1  0  0    mask
+   ----------------------
+   1  0  1  0  1  0  0  0
+
+ variable unchanged
+                     bits cleared
+  
+

Here is the same representation with the variable's bits replaced with the symbol x +

+

+   x  x  x  x  x  x  x  x    variable
+   1  1  1  1  1  1  0  0    mask
+   ----------------------
+   x  x  x  x  x  x  0  0
+
+ variable unchanged
+                     bits cleared
+ 
+

So if: +

+myByte =  10101010;
+
+myByte &= B1111100 == B10101000;
+
+

compound bitwise OR (|=)

+

Description

+

The compound bitwise OR operator (|=) is often used with a variable and a constant to "set" (set to 1) particular bits in a variable. +

+

Syntax:

+
+x |= y;   // equivalent to x = x | y; 
+
+

Parameters

+

x: a char, int or long variable
y: an integer constant or char, int, or long +

+

Example:

+

First, a review of the Bitwise OR (|) operator +

+   0  0  1  1    operand1
+   0  1  0  1    operand2
+   ----------
+   0  1  1  1    (operand1 | operand2) - returned result
+
+

Bits that are "bitwise ORed" with 0 are unchanged, so if myByte is a byte variable,
+myByte | B00000000 = myByte; +

+

Bits that are "bitwise ORed" with 1 are set to 1 so:
myByte & B11111111 = B11111111; +

+

Consequently - to set bits 0 & 1 of a variable, while leaving the rest of the variable unchanged, use the compound bitwise AND operator (&=) with the constant B00000011 +

+   1  0  1  0  1  0  1  0    variable
+   0  0  0  0  0  0  1  1    mask
+   ----------------------
+   1  0  1  0  1  0  1  1
+
+ variable unchanged
+                     bits set
+
+
+

Here is the same representation with the variables bits replaced with the symbol x +

+

+   x  x  x  x  x  x  x  x    variable
+   0  0  0  0  0  0  1  1    mask
+   ----------------------
+   x  x  x  x  x  x  1  1
+
+ variable unchanged
+                     bits set
+
+

So if: +

+myByte =  B10101010;
+
+myByte |= B00000011 == B10101011;
+
+
+

See Also +

  • & (bitwise AND) +
  • | (bitwise OR) +
  • && (Boolean AND) +
  • || (Boolean OR) +

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/BitwiseXorNot.html b/arduino-0018-linux/reference/BitwiseXorNot.html new file mode 100644 index 0000000..016b5f5 --- /dev/null +++ b/arduino-0018-linux/reference/BitwiseXorNot.html @@ -0,0 +1,84 @@ + + + + Arduino - BitwiseXorNot + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Bitwise NOT (~)

+

The bitwise NOT operator in C++ is the tilde character ~. Unlike & and |, the bitwise NOT operator is applied to a single operand to its right. Bitwise NOT changes each bit to its opposite: 0 becomes 1, and 1 becomes 0. For example: +

+

    0  1    operand1
+
+

   ----------
+    1  0   ~ operand1
+
+

    int a = 103;    // binary:  0000000001100111
+    int b = ~a;     // binary:  1111111110011000 = -104
+
+

You might be surprised to see a negative number like -104 as the result of this operation. This is because the highest bit in an int variable is the so-called sign bit. If the highest bit is 1, the number is interpreted as negative. This encoding of positive and negative numbers is referred to as two's complement. For more information, see the Wikipedia article on two's complement. +

+

As an aside, it is interesting to note that for any integer x, ~x is the same as -x-1. +

+

At times, the sign bit in a signed integer expression can cause some unwanted surprises. +

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Board.html b/arduino-0018-linux/reference/Board.html new file mode 100644 index 0000000..ed5fb2a --- /dev/null +++ b/arduino-0018-linux/reference/Board.html @@ -0,0 +1,132 @@ + + + + Arduino - Board + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Board +

+

Introduction to the Arduino Board

+

Looking at the board from the top down, this is an outline of what you will see (parts of the board you might interact with in the course of normal use are highlighted): +

+

+

Starting clockwise from the top center: +

+

  • Analog Reference pin (orange) +
  • Digital Ground (light green) +
  • Digital Pins 2-13 (green) +
  • Digital Pins 0-1/Serial In/Out - TX/RX (dark green) - These pins cannot be used for digital i/o (digitalRead and digitalWrite) if you are also using serial communication (e.g. Serial.begin). +
  • Reset Button - S1 (dark blue) +
  • In-circuit Serial Programmer (blue-green) +
  • Analog In Pins 0-5 (light blue) +
  • Power and Ground Pins (power: orange, grounds: light orange) +
  • External Power Supply In (9-12VDC) - X1 (pink) +
  • Toggles External Power and USB Power (place jumper on two pins closest to desired supply) - SV1 (purple) +
  • USB (used for uploading sketches to the board and for serial communication between the board and the computer; can be used to power the board) (yellow) +

Microcontrollers

+
+

ATmega168 (used on most Arduino boards) +

+

+ + + + + + +
Digital I/O Pins14 (of which 6 provide PWM output)
Analog Input Pins6 (DIP) or 8 (SMD)
DC Current per I/O Pin40 mA
Flash Memory16 KB
SRAM1 KB
EEPROM512 bytes
+

(datasheet) +

+

+

ATmega8 (used on some older board) +

+

+ + + + + + +
Digital I/O Pins14 (of which 3 provide PWM output)
Analog Input Pins6
DC Current per I/O Pin40 mA
Flash Memory8 KB
SRAM1 KB
EEPROM512 bytes
+

(datasheet) +

+

+

Digital Pins

+

In addition to the specific functions listed below, the digital pins on an Arduino board can be used for general purpose input and output via the pinMode(), digitalRead(), and digitalWrite() commands. Each pin has an internal pull-up resistor which can be turned on and off using digitalWrite() (w/ a value of HIGH or LOW, respectively) when the pin is configured as an input. The maximum current per pin is 40 mA. +

+

  • Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data. On the Arduino Diecimila, these pins are connected to the corresponding pins of the FTDI USB-to-TTL Serial chip. On the Arduino BT, they are connected to the corresponding pins of the WT11 Bluetooth module. On the Arduino Mini and LilyPad Arduino, they are intended for use with an external TTL serial module (e.g. the Mini-USB Adapter). +

  • External Interrupts: 2 and 3. These pins can be configured to trigger an interrupt on a low value, a rising or falling edge, or a change in value. See the attachInterrupt() function for details. +

  • PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the analogWrite() function. On boards with an ATmega8, PWM output is available only on pins 9, 10, and 11. +

  • BT Reset: 7. (Arduino BT-only) Connected to the reset line of the bluetooth module. +

  • SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI communication, which, although provided by the underlying hardware, is not currently included in the Arduino language. +

  • LED: 13. On the Diecimila and LilyPad, there is a built-in LED connected to digital pin 13. When the pin is HIGH value, the LED is on, when the pin is LOW, it's off. +

Analog Pins

+

In addition to the specific functions listed below, the analog input pins support 10-bit analog-to-digital conversion (ADC) using the analogRead() function. Most of the analog inputs can also be used as digital pins: analog input 0 as digital pin 14 through analog input 5 as digital pin 19. Analog inputs 6 and 7 (present on the Mini and BT) cannot be used as digital pins. +

+

  • I2C: 4 (SDA) and 5 (SCL). Support I2C (TWI) communication using the Wire library (documentation on the Wiring website). +

Power Pins

+
  • VIN (sometimes labelled "9V"). The input voltage to the Arduino board when it's using an external power source (as opposed to 5 volts from the USB connection or other regulated power source). You can supply voltage through this pin, or, if supplying voltage via the power jack, access it through this pin. Note that different boards accept different input voltages ranges, please see the documentation for your board. Also note that the LilyPad has no VIN pin and accepts only a regulated input. +

  • 5V. The regulated power supply used to power the microcontroller and other components on the board. This can come either from VIN via an on-board regulator, or be supplied by USB or another regulated 5V supply. +

  • 3V3. (Diecimila-only) A 3.3 volt supply generated by the on-board FTDI chip. +

  • GND. Ground pins. +

Other Pins

+
  • AREF. Reference voltage for the analog inputs. Used with analogReference(). +

  • Reset. (Diecimila-only) Bring this line LOW to reset the microcontroller. Typically used to add a reset button to shields which block the one on the board. +

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Boolean.html b/arduino-0018-linux/reference/Boolean.html new file mode 100644 index 0000000..df98a02 --- /dev/null +++ b/arduino-0018-linux/reference/Boolean.html @@ -0,0 +1,111 @@ + + + + Arduino - Boolean + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Boolean Operators

+

These can be used inside the condition of an if statement. +

+

&& (logical and)

+

True only if both operands are true, e.g. +

+if (digitalRead(2) == HIGH  && digitalRead(3) == HIGH) { // read two switches 
+  // ...
+} 
+

is true only if both inputs are high. +

+

|| (logical or)

+

True if either operand is true, e.g. +

+if (x > 0 || y > 0) {
+  // ...
+} 
+

is true if either x or y is greater than 0. +

+

! (not)

+

True if the operand is false, e.g. +

+if (!x) { 
+  // ...
+} 
+

is true if x is false (i.e. if x equals 0). +

+

Warning

+

Make sure you don't mistake the boolean AND operator, && (double ampersand) for the bitwise AND operator & (single ampersand). They are entirely different beasts. +

+

Similarly, do not confuse the boolean || (double pipe) operator with the bitwise OR operator | (single pipe). +

+

The bitwise not ~ (tilde) looks much different than the boolean not ! (exclamation point or "bang" as the programmers say) but you still have to be sure which one you want where. +

+

Examples

+
+if (a >= 10 && a <= 20){}   // true if a is between 10 and 20
+
+
+

See also

+
  • & (bitwise AND) +
  • | (bitwise OR) +
  • ~ (bitwise NOT +
  • if +

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/BooleanVariables.html b/arduino-0018-linux/reference/BooleanVariables.html new file mode 100644 index 0000000..671b0b3 --- /dev/null +++ b/arduino-0018-linux/reference/BooleanVariables.html @@ -0,0 +1,102 @@ + + + + Arduino - BooleanVariables + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

boolean

+

A boolean holds one of two values, true or false. (Each boolean variable occupies one byte of memory.) +

+

Example

+
+int LEDpin = 5;       // LED on pin 5
+int switchPin = 13;   // momentary switch on 13, other side connected to ground
+
+boolean running = false;
+
+void setup()
+{
+  pinMode(LEDpin, OUTPUT);
+  pinMode(switchPin, INPUT);
+  digitalWrite(switchPin, HIGH);      // turn on pullup resistor
+}
+
+void loop()
+{
+  if (digitalRead(switchPin) == LOW)
+  {  // switch is pressed - pullup keeps pin high normally
+    delay(100);                        // delay to debounce switch
+    running = !running;                // toggle running variable
+    digitalWrite(LEDpin, running)      // indicate via LED
+  }
+}
+
+
+
+
+
+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Braces.html b/arduino-0018-linux/reference/Braces.html new file mode 100644 index 0000000..5e41ad2 --- /dev/null +++ b/arduino-0018-linux/reference/Braces.html @@ -0,0 +1,119 @@ + + + + Arduino - Braces + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

{} Curly Braces

+

Curly braces (also referred to as just "braces" or as "curly brackets") are a major part of the C programming language. They are used in several different constructs, outlined below, and this can sometimes be confusing for beginners. +

+

An opening curly brace "{" must always be followed by a closing curly brace "}". This is a condition that is often referred to as the braces being balanced. The Arduino IDE (integrated development environment) includes a convenient feature to check the balance of curly braces. Just select a brace, or even click the insertion point immediately following a brace, and its logical companion will be highlighted. +

+

At present this feature is slightly buggy as the IDE will often find (incorrectly) a brace in text that has been "commented out." +

+

Beginning programmers, and programmers coming to C from the BASIC language often find using braces confusing or daunting. After all, the same curly braces replace the RETURN statement in a subroutine (function), the ENDIF statement in a conditional and the NEXT statement in a FOR loop. +

+

Because the use of the curly brace is so varied, it is good programming practice to type the closing brace immediately after typing the opening brace when inserting a construct which requires curly braces. Then insert some carriage returns between your braces and begin inserting statements. Your braces, and your attitude, will never become unbalanced. +

+

Unbalanced braces can often lead to cryptic, impenetrable compiler errors that can sometimes be hard to track down in a large program. Because of their varied usages, braces are also incredibly important to the syntax of a program and moving a brace one or two lines will often dramatically affect the meaning of a program. +

+

The main uses of curly braces

+

Functions

+
  void myfunction(datatype argument){
+    statements(s)
+  }
+
+

Loops

+
  while (boolean expression)
+  {
+     statement(s)
+  }
+
+  do
+  {
+     statement(s)
+  } while (boolean expression);
+
+  for (initialisation; termination condition; incrementing expr)
+  {
+     statement(s)
+  } 
+
+

Conditional statements

+

  if (boolean expression)
+  {
+     statement(s)
+  }
+
+  else if (boolean expression)
+  {
+     statement(s)
+  } 
+  else
+  {
+     statement(s)
+  }
+
+

Reference Home +

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Break.html b/arduino-0018-linux/reference/Break.html new file mode 100644 index 0000000..beb2b5f --- /dev/null +++ b/arduino-0018-linux/reference/Break.html @@ -0,0 +1,85 @@ + + + + Arduino - Break + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

break

+

break is used to exit from a do, for, or while loop, bypassing the normal loop condition. It is also used to exit from a switch statement. +

+

Example

+
+for (x = 0; x < 255; x ++)
+{
+    digitalWrite(PWMpin, x);
+    sens = analogRead(sensorPin);  
+    if (sens > threshold){      // bail out on sensor detect
+       x = 0;
+       break;
+    }  
+    delay(50);
+}
+
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Byte.html b/arduino-0018-linux/reference/Byte.html new file mode 100644 index 0000000..0ce2492 --- /dev/null +++ b/arduino-0018-linux/reference/Byte.html @@ -0,0 +1,78 @@ + + + + Arduino - Byte + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

byte

+

Description

+

A byte stores an 8-bit unsigned number, from 0 to 255. +

+

Example

+
    byte b = B10010;  // "B" is the binary formatter (B10010 = 18 decimal) 
+
+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/ByteCast.html b/arduino-0018-linux/reference/ByteCast.html new file mode 100644 index 0000000..d700b11 --- /dev/null +++ b/arduino-0018-linux/reference/ByteCast.html @@ -0,0 +1,82 @@ + + + + Arduino - ByteCast + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

byte()

+

Description

+

Converts a value to the byte data type. +

+

Syntax

+

byte(x) +

+

Parameters

+

x: a value of any type +

+

Returns

+

byte +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Cast.html b/arduino-0018-linux/reference/Cast.html new file mode 100644 index 0000000..8e15e95 --- /dev/null +++ b/arduino-0018-linux/reference/Cast.html @@ -0,0 +1,90 @@ + + + + Arduino - Cast + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Board +

+

Cast

+

Description

+

The cast operator translates one variable type into another and forces calculations to be performed in the cast type. +

+

Syntax

+

(type)variable +

+

Parameters:

+

type: any variable type (e.g. int, float, byte) +

+

variable: any variable or constant +

+

Example

+
+int i;
+float f;
+
+f = 3.6; 
+i = (int) f; // now i is 3
+
+
+

Note

+

When casting from a float to an int, the value is truncated not rounded. So both (int) 3.2 and (int) 3.7 are 3. +

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Changes.html b/arduino-0018-linux/reference/Changes.html new file mode 100644 index 0000000..c5e7c29 --- /dev/null +++ b/arduino-0018-linux/reference/Changes.html @@ -0,0 +1,89 @@ + + + + Arduino - Changes + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Changes

+

This page lists major changes to the Arduino core, libraries, and environment. For details, see the release notes. +

+

Changes in Arduino 0017

+
  • Environment: The code base for the Arduino development environment was largely re-written to bring it back into sync with Processing (1.0.3). The main differences include support for multiple sketch windows open simultaneously and a dedicated window for the serial monitor. +

  • Icons: The icons and about images were updated. +

  • Arduino.app: The Mac OS X version of Arduino is now a .app file packaged in a .dmg. +

  • Libraries: Support was added for third-party libraries in the SKETCHBOOK/libraries directory. This allows user-installed libraries to persist across upgrades of the Arduino software. +

  • Servo: The servo library was rewritten to allow support for up to 12 servos (on any pins) and up to 48 on the Mega. +

  • LiquidCrystal: The begin(), cursor(), noCursor(), blink(), noBlink(), display(), noDisplay(), scrollDisplayLeft(), scrollDisplayRight(), autoscroll(), noAutoscroll(), leftToRight(), rightToLeft(), and createChar() functions were added. +

Changes in Arduino 0016

+
  • New functions for writing a string, write(str), or buffer, write(buf, len), were added to the Print, Serial, and Ethernet library Client and Server classes. +

Changes in Arduino 0015

+
  • Support for the Arduino Mega. +

Changes in Arduino 0013

+
  • Support for printing floats was added to the Print, Serial, and Ethernet library Client and Server classes. +

  • The word type and word(), bitRead(), bitWrite(), bitSet(), bitClear(), bit(), lowByte(), and highByte() functions were added. +

Changes in Arduino 0012

+
  • Added the Firmata library, which provides a standard protocol for serial communication. +

  • Added Ethernet library. +

  • Added Servo library. +

  • Added LiquidCrystal library. +

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Char.html b/arduino-0018-linux/reference/Char.html new file mode 100644 index 0000000..f539cbd --- /dev/null +++ b/arduino-0018-linux/reference/Char.html @@ -0,0 +1,85 @@ + + + + Arduino - Char + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

char

+

Description

+

A data type that takes up 1 byte of memory that stores a character value. Character literals are written in single quotes, like this: 'A' (for multiple characters - strings - use double quotes: "ABC"). +

+

Characters are stored as numbers however. You can see the specific encoding in the ASCII chart. This means that it is possible to do arithmetic on characters, in which the ASCII value of the character is used (e.g. 'A' + 1 has the value 66, since the ASCII value of the capital letter A is 65). See Serial.println reference for more on how characters are translated to numbers. +

+

The char datatype is a signed type, meaning that it encodes numbers from -128 to 127. For an unsigned, one-byte (8 bit) data type, use the byte data type. +

+

Example

+
  char myChar = 'A';
+  char myChar = 65;      // both are equivalent
+
+
+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/CharCast.html b/arduino-0018-linux/reference/CharCast.html new file mode 100644 index 0000000..0690347 --- /dev/null +++ b/arduino-0018-linux/reference/CharCast.html @@ -0,0 +1,82 @@ + + + + Arduino - CharCast + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

char()

+

Description

+

Converts a value to the char data type. +

+

Syntax

+

char(x) +

+

Parameters

+

x: a value of any type +

+

Returns

+

char +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/ClientAvailable.html b/arduino-0018-linux/reference/ClientAvailable.html new file mode 100644 index 0000000..7bbd5d8 --- /dev/null +++ b/arduino-0018-linux/reference/ClientAvailable.html @@ -0,0 +1,126 @@ + + + + Arduino - ClientAvailable + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Ethernet : Client class +

+

available()

+

Description

+

Returns the number of bytes available for reading (that is, the amount of data that has been written to the client by the server it is connected to). +

+

Syntax

+

client.available() +

+

Parameters

+

none +

+

Returns

+

The number of bytes available. +

+

+#include <Ethernet.h>
+
+byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
+byte ip[] = { 10, 0, 0, 177 };
+byte server[] = { 64, 233, 187, 99 }; // Google
+
+Client client(server, 80);
+
+void setup()
+{
+  Ethernet.begin(mac, ip);
+  Serial.begin(9600);
+
+  delay(1000);
+
+  Serial.println("connecting...");
+
+  if (client.connect()) {
+    Serial.println("connected");
+    client.println("GET /search?q=arduino HTTP/1.0");
+    client.println();
+  } else {
+    Serial.println("connection failed");
+  }
+}
+
+void loop()
+{
+  if (client.available()) {
+    char c = client.read();
+    Serial.print(c);
+  }
+
+  if (!client.connected()) {
+    Serial.println();
+    Serial.println("disconnecting.");
+    client.stop();
+    for(;;)
+      ;
+  }
+}
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/ClientConnect.html b/arduino-0018-linux/reference/ClientConnect.html new file mode 100644 index 0000000..d45d793 --- /dev/null +++ b/arduino-0018-linux/reference/ClientConnect.html @@ -0,0 +1,127 @@ + + + + Arduino - ClientConnect + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Ethernet : Client class +

+

connect()

+

Description

+

Connect to the IP address and port specified in the constructor. The return value indicates success or failure. +

+

Syntax

+

client.connect() +

+

Parameters

+

none +

+

Returns

+

Returns true if the connection succeeds, false if not. +

+

Example

+
+#include <Ethernet.h>
+
+byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
+byte ip[] = { 10, 0, 0, 177 };
+byte server[] = { 64, 233, 187, 99 }; // Google
+
+Client client(server, 80);
+
+void setup()
+{
+  Ethernet.begin(mac, ip);
+  Serial.begin(9600);
+
+  delay(1000);
+
+  Serial.println("connecting...");
+
+  if (client.connect()) {
+    Serial.println("connected");
+    client.println("GET /search?q=arduino HTTP/1.0");
+    client.println();
+  } else {
+    Serial.println("connection failed");
+  }
+}
+
+void loop()
+{
+  if (client.available()) {
+    char c = client.read();
+    Serial.print(c);
+  }
+
+  if (!client.connected()) {
+    Serial.println();
+    Serial.println("disconnecting.");
+    client.stop();
+    for(;;)
+      ;
+  }
+}
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/ClientConnected.html b/arduino-0018-linux/reference/ClientConnected.html new file mode 100644 index 0000000..b419713 --- /dev/null +++ b/arduino-0018-linux/reference/ClientConnected.html @@ -0,0 +1,127 @@ + + + + Arduino - ClientConnected + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Ethernet : Client class +

+

connected()

+

Description

+

Whether or not the client is connected. Note that a client is considered connected if the connection has been closed but there is still unread data. +

+

Syntax

+

client.connected() +

+

Parameters

+

none +

+

Returns

+

Returns true if the client is connected, false if not. +

+

Example

+
+#include <Ethernet.h>
+
+byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
+byte ip[] = { 10, 0, 0, 177 };
+byte server[] = { 64, 233, 187, 99 }; // Google
+
+Client client(server, 80);
+
+void setup()
+{
+  Ethernet.begin(mac, ip);
+  Serial.begin(9600);
+
+  delay(1000);
+
+  Serial.println("connecting...");
+
+  if (client.connect()) {
+    Serial.println("connected");
+    client.println("GET /search?q=arduino HTTP/1.0");
+    client.println();
+  } else {
+    Serial.println("connection failed");
+  }
+}
+
+void loop()
+{
+  if (client.available()) {
+    char c = client.read();
+    Serial.print(c);
+  }
+
+  if (!client.connected()) {
+    Serial.println();
+    Serial.println("disconnecting.");
+    client.stop();
+    for(;;)
+      ;
+  }
+}
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/ClientConstructor.html b/arduino-0018-linux/reference/ClientConstructor.html new file mode 100644 index 0000000..2ea0256 --- /dev/null +++ b/arduino-0018-linux/reference/ClientConstructor.html @@ -0,0 +1,126 @@ + + + + Arduino - ClientConstructor + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Ethernet : Client class +

+

Client()

+

Description

+

Creates a client which can connect to the specified internet IP address and port. +

+

Syntax

+

Client(ip, port) +

+

Parameters

+

ip: the IP address that the client will connect to (array of 4 bytes) +

+

port: the port that the client will connect to (int) +

+

Example

+
+#include <Ethernet.h>
+
+byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
+byte ip[] = { 10, 0, 0, 177 };
+byte server[] = { 64, 233, 187, 99 }; // Google
+
+Client client(server, 80);
+
+void setup()
+{
+  Ethernet.begin(mac, ip);
+  Serial.begin(9600);
+
+  delay(1000);
+
+  Serial.println("connecting...");
+
+  if (client.connect()) {
+    Serial.println("connected");
+    client.println("GET /search?q=arduino HTTP/1.0");
+    client.println();
+  } else {
+    Serial.println("connection failed");
+  }
+}
+
+void loop()
+{
+  if (client.available()) {
+    char c = client.read();
+    Serial.print(c);
+  }
+
+  if (!client.connected()) {
+    Serial.println();
+    Serial.println("disconnecting.");
+    client.stop();
+    for(;;)
+      ;
+  }
+}
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/ClientFlush.html b/arduino-0018-linux/reference/ClientFlush.html new file mode 100644 index 0000000..0b42c67 --- /dev/null +++ b/arduino-0018-linux/reference/ClientFlush.html @@ -0,0 +1,81 @@ + + + + Arduino - ClientFlush + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Ethernet : Client class +

+

flush()

+

Discard any bytes that have been written to the client but not yet read. +

+

Syntax

+

client.flush() +

+

Parameters

+

none +

+

Returns

+

none +

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/ClientPrint.html b/arduino-0018-linux/reference/ClientPrint.html new file mode 100644 index 0000000..1f9bb8b --- /dev/null +++ b/arduino-0018-linux/reference/ClientPrint.html @@ -0,0 +1,85 @@ + + + + Arduino - ClientPrint + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Ethernet : Client class +

+

print()

+

Description

+

Print data to the server that a client is connected to. Prints numbers as a sequence of digits, each an ASCII character (e.g. the number 123 is sent as the three characters '1', '2', '3'). +

+

Syntax

+

client.print(data)
client.print(data, BASE) +

+

Parameters

+

data: the data to print (char, byte, int, long, or string) +

+

BASE (optional): the base in which to print numbers: BIN for binary (base 2), DEC for decimal (base 10), OCT for octal (base 8), HEX for hexadecimal (base 16). +

+

Example

+
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/ClientPrintln.html b/arduino-0018-linux/reference/ClientPrintln.html new file mode 100644 index 0000000..492cd3b --- /dev/null +++ b/arduino-0018-linux/reference/ClientPrintln.html @@ -0,0 +1,85 @@ + + + + Arduino - ClientPrintln + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Ethernet : Client class +

+

println()

+

Description

+

Print data, followed by a newline, to the server a client is connected to. Prints numbers as a sequence of digits, each an ASCII character (e.g. the number 123 is sent as the three characters '1', '2', '3'). +

+

Syntax

+

client.println()
client.println(data)
client.print(data, BASE) +

+

Parameters

+

data (optional): the data to print (char, byte, int, long, or string) +

+

BASE (optional): the base in which to print numbers: BIN for binary (base 2), DEC for decimal (base 10), OCT for octal (base 8), HEX for hexadecimal (base 16). +

+

Example

+
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/ClientRead.html b/arduino-0018-linux/reference/ClientRead.html new file mode 100644 index 0000000..4a36640 --- /dev/null +++ b/arduino-0018-linux/reference/ClientRead.html @@ -0,0 +1,81 @@ + + + + Arduino - ClientRead + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Ethernet : Client class +

+

read()

+

Read the next byte received from the server the client is connected to (after the last call to read()). +

+

Syntax

+

client.read() +

+

Parameters

+

none +

+

Returns

+

The next byte (or character), or -1 if none is available. +

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/ClientStop.html b/arduino-0018-linux/reference/ClientStop.html new file mode 100644 index 0000000..2596eb0 --- /dev/null +++ b/arduino-0018-linux/reference/ClientStop.html @@ -0,0 +1,82 @@ + + + + Arduino - ClientStop + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Ethernet : Client class +

+

stop()

+

Description

+

Disconnect from the server. +

+

Syntax

+

client.stop() +

+

Parameters

+

none +

+

Returns

+

none +

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/ClientWrite.html b/arduino-0018-linux/reference/ClientWrite.html new file mode 100644 index 0000000..0508d2b --- /dev/null +++ b/arduino-0018-linux/reference/ClientWrite.html @@ -0,0 +1,80 @@ + + + + Arduino - ClientWrite + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Ethernet : Client class +

+

write()

+

Description

+

Write data to the server the client is connected to. +

+

Syntax

+

client.write(data) +

+

Parameters

+

data: the byte or char to write +

+

Example

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Comments.html b/arduino-0018-linux/reference/Comments.html new file mode 100644 index 0000000..f9fa2d9 --- /dev/null +++ b/arduino-0018-linux/reference/Comments.html @@ -0,0 +1,88 @@ + + + + Arduino - Comments + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Comments

+

Comments are lines in the program that are used to inform yourself or others about the way the program works. They are ignored by the compiler, and not exported to the processor, so they don't take up any space on the Atmega chip. +

+

Comments only purpose are to help you understand (or remember) how your program works or to inform others how your program works. +There are two different ways of marking a line as a comment: +

+

Example

+
 x = 5;  // This is a single line comment. Anything after the slashes is a comment 
+         // to the end of the line
+
+/* this is multiline comment - use it to comment out whole blocks of code
+
+if (gwb == 0){   // single line comment is OK inside a multiline comment
+x = 3;           /* but not another multiline comment - this is invalid */
+}
+// don't forget the "closing" comment - they have to be balanced!
+*/
+
+
+

Tip
When experimenting with code, "commenting out" parts of your program is a convenient way to remove lines that may be buggy. This leaves the lines in the code, but turns them into comments, so the compiler just ignores them. This can be especially useful when trying to locate a problem, or when a program refuses to compile and the compiler error is cryptic or unhelpful. +

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Comparison.html b/arduino-0018-linux/reference/Comparison.html new file mode 100644 index 0000000..e8ab3c1 --- /dev/null +++ b/arduino-0018-linux/reference/Comparison.html @@ -0,0 +1,94 @@ + + + + Arduino - Comparison + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Arduino/Processing Language Comparison

+

The Arduino language (based on Wiring) is implemented in C/C++, and therefore has some differences from the Processing language, which is based on Java. +

+

Arrays

+
Arduino + Processing +
int bar[8];
bar[0] = 1; +
int[] bar = new int[8];
bar[0] = 1; +
int foo[] = { 0, 1, 2 }; + int foo[] = { 0, 1, 2 };
or
int[] foo = { 0, 1, 2 }; +
+

Loops

+
Arduino + Processing +
int i;
for (i = 0; i < 5; i++) { ... } +
for (int i = 0; i < 5; i++) { ... } +
+

Printing

+
Arduino + Processing +
Serial.println("hello world"); + println("hello world"); +
int i = 5;
Serial.println(i); +
int i = 5;
println(i); +
int i = 5;
Serial.print("i = ");
Serial.print(i);
Serial.println(); +
int i = 5;
println("i = " + i); +
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Const.html b/arduino-0018-linux/reference/Const.html new file mode 100644 index 0000000..1042b50 --- /dev/null +++ b/arduino-0018-linux/reference/Const.html @@ -0,0 +1,90 @@ + + + + Arduino - Const + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

const keyword

+

The const keyword stands for constant. It is a variable qualifier that modifies the behavior of the variable, making a variable "read-only". This means that the variable can be used just as any other variable of its type, but its value cannot be changed. You will get a compiler error if you try to assign a value to a const variable. +

+

Constants defined with the const keyword obey the rules of variable scoping that govern other variables. This, and the pitfalls of using#define, makes the const keyword a superior method for defining constants and is preferred over using #define. +

+

Example

+
+const float pi = 3.14;
+float x;
+
+// ....
+
+x = pi * 2;    // it's fine to use const's in math
+
+pi = 7;        // illegal - you can't write to (modify) a constant
+
+
+

#define or const

+

You can use either const or #define for creating numeric or string constants. For arrays, you will need to use const. In general const is preferred over #define for defining constants. +

+

See also: +

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Constants.html b/arduino-0018-linux/reference/Constants.html new file mode 100644 index 0000000..265be3d --- /dev/null +++ b/arduino-0018-linux/reference/Constants.html @@ -0,0 +1,112 @@ + + + + Arduino - Constants + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

constants

+

Constants are predefined variables in the Arduino language. They are used to make the programs easier to read. We classify constants in groups. +

+

Defining Logical Levels, true and false (Boolean Constants)

+

There are two constants used to represent truth and falsity in the Arduino language: true, and false. +

+

false

+

false is the easier of the two to define. false is defined as 0 (zero). +

+

true

+

true is often said to be defined as 1, which is correct, but true has a wider definition. Any integer which is non-zero is TRUE, in a Boolean sense. So -1, 2 and -200 are all defined as true, too, in a Boolean sense. +

+

Note that the true and false constants are typed in lowercase unlike HIGH, LOW, INPUT, & OUTPUT. +

+

Defining Pin Levels, HIGH and LOW

+

When reading or writing to a digital pin there are only two possible values a pin can take/be-set-to: HIGH and LOW. +

+

HIGH +

+

The meaning of HIGH (in reference to a pin) is somewhat different depending on whether a pin is set to an INPUT or OUTPUT. +When a pin is configured as an INPUT with pinMode, and read with digitalRead, the microcontroller will report HIGH if a voltage of 3 volts or more is present at the pin. +

+

A pin may also be configured as an INPUT with pinMode, and subsequently made HIGH with digitalWrite, this will set the internal 20K pullup resistors, which will steer the input pin to a HIGH reading unless it is pulled LOW by external circuitry. +

+

When a pin is configured to OUTPUT with pinMode, and set to HIGH with digitalWrite, the pin is at 5 volts. In this state it can source current, e.g. light an LED that is connected through a series resistor to ground, or to another pin configured as an output, and set to LOW. +

+

LOW +

+

The meaning of LOW also has a different meaning depending on whether a pin is set to INPUT or OUTPUT. When a pin is configured as an INPUT with pinMode, and read with digitalRead, the microcontroller will report LOW if a voltage of 2 volts or less is present at the pin. +

+

When a pin is configured to OUTPUT with pinMode, and set to LOW with digitalWrite, the pin is at 0 volts. In this state it can sink current, e.g. light an LED that is connected through a series resistor to, +5 volts, or to another pin configured as an output, and set to HIGH. +

+

Defining Digital Pins, INPUT and OUTPUT

+

Digital pins can be used either as INPUT or OUTPUT. Changing a pin from INPUT TO OUTPUT with pinMode() drastically changes the electrical behavior of the pin. +

+

Pins Configured as Inputs

+

Arduino (Atmega) pins configured as INPUT with pinMode() are said to be in a high-impedance state. One way of explaining this is that pins configured as INPUT make extremely small demands on the circuit that they are sampling, say equivalent to a series resistor of 100 Megohms in front of the pin. This makes them useful for reading a sensor, but not powering an LED. +

+

Pins Configured as Outputs

+

Pins configured as OUTPUT with pinMode() are said to be in a low-impedance state. This means that they can provide a substantial amount of current to other circuits. Atmega pins can source (provide positive current) or sink (provide negative current) up to 40 mA (milliamps) of current to other devices/circuits. This makes them useful for powering LED's but useless for reading sensors. Pins configured as outputs can also be damaged or destroyed if short circuited to either ground or 5 volt power rails. The amount of current provided by an Atmega pin is also not enough to power most relays or motors, and some interface circuitry will be required. +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Constrain.html b/arduino-0018-linux/reference/Constrain.html new file mode 100644 index 0000000..d56b429 --- /dev/null +++ b/arduino-0018-linux/reference/Constrain.html @@ -0,0 +1,92 @@ + + + + Arduino - Constrain + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

constrain(x, a, b)

+

Description

+

Constrains a number to be within a range. +

+

Parameters

+

x: the number to constrain, all data types +

+

a: the lower end of the range, all data types +

+

b: the upper end of the range, all data types +

+

Returns

+

x: if x is between a and b +

+

a: if x is less than a +

+

b: if x is greater than b +

+

Example

+
sensVal = constrain(sensVal, 10, 150);
+// limits range of sensor values to between 10 and 150 
+
+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Continue.html b/arduino-0018-linux/reference/Continue.html new file mode 100644 index 0000000..5ea4968 --- /dev/null +++ b/arduino-0018-linux/reference/Continue.html @@ -0,0 +1,84 @@ + + + + Arduino - Continue + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

continue

+

The continue statement skips the rest of the current iteration of a loop (do, for, or while). It continues by checking the conditional expression of the loop, and proceeding with any subsequent iterations. +

+

Example

+
+
+for (x = 0; x < 255; x ++)
+{
+    if (x > 40 && x < 120){      // create jump in values
+        continue;
+    }
+
+    digitalWrite(PWMpin, x);
+    delay(50);
+}
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Cos.html b/arduino-0018-linux/reference/Cos.html new file mode 100644 index 0000000..130c650 --- /dev/null +++ b/arduino-0018-linux/reference/Cos.html @@ -0,0 +1,84 @@ + + + + Arduino - Cos + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

cos(rad)

+

Description

+

Calculates the cos of an angle (in radians). The result will be between -1 and 1.
+

Parameters

+

rad: the angle in radians (float) +

+

Returns

+

The cos of the angle ("double") +

+

Note

+

Serial.print() and Serial.println() do not currently support printing floats. +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Define.html b/arduino-0018-linux/reference/Define.html new file mode 100644 index 0000000..2aec281 --- /dev/null +++ b/arduino-0018-linux/reference/Define.html @@ -0,0 +1,99 @@ + + + + Arduino - Define + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Define

+

#define is a useful C component that allows the programmer to give a name to a constant value before the program is compiled. Defined constants in arduino don't take up any program memory space on the chip. The compiler will replace references to these constants with the defined value at compile time. +

+

This can have some unwanted side effects though, if for example, a constant name that had been #defined is included in some other constant or variable name. In that case the text would be replaced by the #defined number (or text). +

+

In general, the const keyword is preferred for defining constants and should be used instead of #define. +

+

Arduino defines have the same syntax as C defines: +

+

Syntax

+

#define constantName value +

+

Note that the # is necessary. +

+

Example

+
#define ledPin 3
+// The compiler will replace any mention of ledPin with the value 3 at compile time.
+
+

Tip

+

There is no semicolon after the #define statement. If you include one, the compiler will throw cryptic errors further down the page. +

+

#define ledPin 3;    // this is an error 
+
+
+

Similarly, including an equal sign after the #define statement will also generate a cryptic compiler error further down the page. +

+

#define ledPin  = 3  // this is also an error 
+
+
+

See

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Delay.html b/arduino-0018-linux/reference/Delay.html new file mode 100644 index 0000000..6f4a923 --- /dev/null +++ b/arduino-0018-linux/reference/Delay.html @@ -0,0 +1,108 @@ + + + + Arduino - Delay + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

delay()

+

Description

+

Pauses the program for the amount of time (in miliseconds) specified as parameter. (There are 1000 milliseconds in a second.) +

+

Syntax

+

delay(ms) +

+

Parameters

+

ms: the number of milliseconds to pause (unsigned long) +

+

Returns

+

nothing +

+

Example

+
+int ledPin = 13;                 // LED connected to digital pin 13
+
+void setup()
+{
+  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
+}
+
+void loop()
+{
+  digitalWrite(ledPin, HIGH);   // sets the LED on
+  delay(1000);                  // waits for a second
+  digitalWrite(ledPin, LOW);    // sets the LED off
+  delay(1000);                  // waits for a second
+}
+
+
+

Caveat

+

While it is easy to create a blinking LED with the delay() function, and many sketches use short delays for such tasks as switch debouncing, the use of delay() in a sketch has significant drawbacks. No other reading of sensors, mathematical calculations, or pin manipulation can go on during the delay function, so in effect, it brings most other activity to a halt. For alternative approaches to controlling timing see the millis() function and the sketch sited below. More knowledgeable programmers usually avoid the use of delay() for timing of events longer than 10's of milliseconds unless the Arduino sketch is very simple. +

+

Certain things do go on while the delay() function is controlling the Atmega chip however, because the delay function does not disable interrupts. Serial communication that appears at the RX pin is recorded, PWM (analogWrite) values and pin states are maintained, and interrupts will work as they should. +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/DelayMicroseconds.html b/arduino-0018-linux/reference/DelayMicroseconds.html new file mode 100644 index 0000000..66ee0ef --- /dev/null +++ b/arduino-0018-linux/reference/DelayMicroseconds.html @@ -0,0 +1,110 @@ + + + + Arduino - DelayMicroseconds + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

delayMicroseconds()

+

Description

+

Pauses the program for the amount of time (in microseconds) specified as parameter. There are a thousand microseconds in a millisecond, and a million microseconds in a second. +

+

Currently, the largest value that will produce an accurate delay is 16383. This could change in future Arduino releases. For delays longer than a few thousand microseconds, you should use delay() instead. +

+

Parameters

+

us: the number of microseconds to pause (unsigned int) +

+

Returns

+

None +

+

Example

+
 
+int outPin = 8;                 // digital pin 8
+
+void setup()
+{
+  pinMode(outPin, OUTPUT);      // sets the digital pin as output
+}
+
+void loop()
+{
+  digitalWrite(outPin, HIGH);   // sets the pin on
+  delayMicroseconds(50);        // pauses for 50 microseconds      
+  digitalWrite(outPin, LOW);    // sets the pin off
+  delayMicroseconds(50);        // pauses for 50 microseconds      
+}
+
+
+

configures pin number 8 to work as an output pin. It sends a train of pulses with 100 microseconds period. +

+

Caveats and Known Issues

+

This function works very accurately in the range 3 microseconds and up. We cannot assure that delayMicroseconds will perform precisely for smaller delay-times. +

+

To ensure more accurate delays, this functions disables interrupts during its operation, meaning that some things (like receiving serial data, or incrementing the value returned by millis()) will not happen during the delay. Thus, you should only use this function for short delays, and use delay() for longer ones. +

+

delayMicroseconds(0) will generate a much longer delay than expected (~1020 us) as will using negative numbers as a parameter. +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/DetachInterrupt.html b/arduino-0018-linux/reference/DetachInterrupt.html new file mode 100644 index 0000000..3576883 --- /dev/null +++ b/arduino-0018-linux/reference/DetachInterrupt.html @@ -0,0 +1,76 @@ + + + + Arduino - DetachInterrupt + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

detachInterrupt(interrupt)

+

Description

+

Turns off the given interrupt. +

+

Parameters

+

interrupt: the number of interrupt to disable (0 or 1). +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/DigitalRead.html b/arduino-0018-linux/reference/DigitalRead.html new file mode 100644 index 0000000..a7dbbc2 --- /dev/null +++ b/arduino-0018-linux/reference/DigitalRead.html @@ -0,0 +1,110 @@ + + + + Arduino - DigitalRead + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

digitalRead()

+

Description

+

Reads the value from a specified digital pin, either HIGH or LOW. +

+

Syntax

+

digitalRead(pin) +

+

Parameters

+

pin: the number of the digital pin you want to read (int) +

+

Returns

+

HIGH or LOW +

+

Example

+
 
+int ledPin = 13; // LED connected to digital pin 13
+int inPin = 7;   // pushbutton connected to digital pin 7
+int val = 0;     // variable to store the read value
+
+void setup()
+{
+  pinMode(ledPin, OUTPUT);      // sets the digital pin 13 as output
+  pinMode(inPin, INPUT);      // sets the digital pin 7 as input
+}
+
+void loop()
+{
+  val = digitalRead(inPin);   // read the input pin
+  digitalWrite(ledPin, val);    // sets the LED to the button's value
+}
+
+
+

Sets pin 13 to the same value as the pin 7, which is an input. +

+

Note

+

If the pin isn't connected to anything, digitalRead() can return either HIGH or LOW (and this can change randomly). +

+

The analog input pins can be used as digital pins w/ numbers 14 (analog input 0) to 19 (analog input 5). +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/DigitalWrite.html b/arduino-0018-linux/reference/DigitalWrite.html new file mode 100644 index 0000000..eba6f0b --- /dev/null +++ b/arduino-0018-linux/reference/DigitalWrite.html @@ -0,0 +1,113 @@ + + + + Arduino - DigitalWrite + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

digitalWrite()

+

Description

+

Write a HIGH or a LOW value to a digital pin. +

+

If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set to the corresponding value: 5V (or 3.3V on 3.3V boards) for HIGH, 0V (ground) for LOW. +

+

If the pin is configured as an INPUT, writing a HIGH value with digitalWrite() will enable an internal 20K pullup resistor (see the tutorial on digital pins). Writing LOW will disable the pullup. The pullup resistor is enough to light an LED dimly, so if LEDs appear to work, but very dimly, this is a likely cause. The remedy is to set the pin to an output with the pinMode() function. +

+

Syntax

+

digitalWrite(pin, value) +

+

Parameters

+

pin: the pin number +

+

value: HIGH or LOW +

+

Returns

+

none +

+

Example

+
 
+int ledPin = 13;                 // LED connected to digital pin 13
+
+void setup()
+{
+  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
+}
+
+void loop()
+{
+  digitalWrite(ledPin, HIGH);   // sets the LED on
+  delay(1000);                  // waits for a second
+  digitalWrite(ledPin, LOW);    // sets the LED off
+  delay(1000);                  // waits for a second
+}
+
+
+

Sets pin 13 to HIGH, makes a one-second-long delay, and sets the pin back to LOW. +

+

Note

+

The analog input pins can also be used as digital pins, referred to as numbers 14 (analog input 0) to 19 (analog input 5). +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/DoWhile.html b/arduino-0018-linux/reference/DoWhile.html new file mode 100644 index 0000000..fc452fd --- /dev/null +++ b/arduino-0018-linux/reference/DoWhile.html @@ -0,0 +1,87 @@ + + + + Arduino - DoWhile + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

do - while

+

The do loop works in the same manner as the while loop, with the exception that the condition is tested at the end of the loop, so the do loop will always run at least once. +

+

+do
+{
+    // statement block
+} while (test condition);
+
+
+

Example

+
+do
+{
+  delay(50);          // wait for sensors to stabilize
+  x = readSensors();  // check the sensors
+
+} while (x < 100);
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Double.html b/arduino-0018-linux/reference/Double.html new file mode 100644 index 0000000..4b9c1a5 --- /dev/null +++ b/arduino-0018-linux/reference/Double.html @@ -0,0 +1,78 @@ + + + + Arduino - Double + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

double

+

Desciption

+

Double precision floating point number. Occupies 4 bytes. +

+

The double implementation on the Arduino is currently exactly the same as the float, with no gain in precision. +

+

Tip

+

Users who borrow code from other sources that includes double variables may wish to examine the code to see if the implied precision is different from that actually achieved on the Arduino. +

+

See:

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/EEPROM.html b/arduino-0018-linux/reference/EEPROM.html new file mode 100644 index 0000000..fbeda8b --- /dev/null +++ b/arduino-0018-linux/reference/EEPROM.html @@ -0,0 +1,73 @@ + + + + Arduino - EEPROM + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

EEPROM Library

+

The microcontroller on the Arduino board has 512 bytes of EEPROM: memory whose values are kept when the board is turned off (like a tiny hard drive). This library enables you to read and write those bytes. +

+

Functions

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/EEPROMRead.html b/arduino-0018-linux/reference/EEPROMRead.html new file mode 100644 index 0000000..dc05d93 --- /dev/null +++ b/arduino-0018-linux/reference/EEPROMRead.html @@ -0,0 +1,109 @@ + + + + Arduino - EEPROMRead + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

byte EEPROM.read(address)

+

Description

+

Reads a byte from the EEPROM. Locations that have never been written to have the value of 255. +

+

Parameters

+

address: the location to read from, from 0 to 511 (int) +

+

Returns

+

the value stored in that location (byte) +

+

Example

+
+#include <EEPROM.h>
+
+int a = 0;
+int value;
+
+void setup()
+{
+  Serial.begin(9600);
+}
+
+void loop()
+{
+  value = EEPROM.read(a);
+
+  Serial.print(a);
+  Serial.print("\t");
+  Serial.print(value);
+  Serial.println();
+
+  a = a + 1;
+
+  if (a == 512)
+    a = 0;
+
+  delay(500);
+}
+
+
+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/EEPROMWrite.html b/arduino-0018-linux/reference/EEPROMWrite.html new file mode 100644 index 0000000..fffacc8 --- /dev/null +++ b/arduino-0018-linux/reference/EEPROMWrite.html @@ -0,0 +1,102 @@ + + + + Arduino - EEPROMWrite + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

EEPROM.write(address, value)

+

Description

+

Write a byte to the EEPROM. +

+

Parameters

+

address: the location to write to, from 0 to 511 (int) +

+

value: the value to write, from 0 to 255 (byte) +

+

Returns

+

none +

+

The Atmega 168 datasheet says that EEPROM memory has a specified life of 100000 write/erase cycles, so there is a limit to how many times you can write information to that memory space. Keep this in mind for long-lived projects or fast-moving data. +

+

The datasheet also specifies that a write cycle takes 3.3 ms to complete. Other EEPROM write and read requests will fail if executed in this time period. This delay appears to be built into the EEPROM library as a casual test shows each cycle taking 3.33 ms to execute. +

+

Hence, you do not specifically need to add a delay to an EEPROM write, just be aware of the built-in time delay. +

+

Example

+
+#include <EEPROM.h>
+
+void setup()
+{
+  for (int i = 0; i < 512; i++)
+    EEPROM.write(i, i);
+}
+
+void loop()
+{
+}
+
+
+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Else.html b/arduino-0018-linux/reference/Else.html new file mode 100644 index 0000000..ece51e9 --- /dev/null +++ b/arduino-0018-linux/reference/Else.html @@ -0,0 +1,103 @@ + + + + Arduino - Else + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

if / else

+

if/else allows greater control over the flow of code than the basic if statement, by allowing multiple tests to be grouped together. For example, an analog input could be tested and one action taken if the input was less than 500, and another action taken if the input was 500 or greater. The code would look like this: +

+

if (pinFiveInput < 500)
+{
+  // action A
+}
+else
+{
+  // action B
+}
+
+

else can proceed another if test, so that multiple, mutually exclusive tests can be run at the same time. +

+

Each test will proceed to the next one until a true test is encountered. When a true test is found, its associated block of code is run, and the program then skips to the line following the entire if/else construction. If no test proves to be true, the default else block is executed, if one is present, and sets the default behavior. +

+

Note that an else if block may be used with or without a terminating else block and vice versa. An unlimited number of such else if branches is allowed. +

+

if (pinFiveInput < 500)
+{
+  // do Thing A
+}
+else if (pinFiveInput >= 1000)
+{
+  // do Thing B
+}
+else
+{
+  // do Thing C
+}
+
+

Another way to express branching, mutually exclusive tests, is with the switch case statement. +

+

See also:

+

switch case +

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Ethernet.html b/arduino-0018-linux/reference/Ethernet.html new file mode 100644 index 0000000..95361e9 --- /dev/null +++ b/arduino-0018-linux/reference/Ethernet.html @@ -0,0 +1,96 @@ + + + + Arduino - Ethernet + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Ethernet library

+

With the Arduino Ethernet Shield, this library allows an Arduino board to connect to the internet. It can serve as either a server accepting incoming connections or a client making outgoing ones. The library supports up to four concurrent connection (incoming or outgoing or a combination). +

+

Ethernet class

+

The Ethernet class initializes the ethernet library and network settings. +

+

Server class

+

The Server class creates servers which can send data to and receive data from connected clients (programs running on other computers or devices). +

+

Client class

+

The client class creates clients that can connect to servers and send and receive data. +

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/EthernetBegin.html b/arduino-0018-linux/reference/EthernetBegin.html new file mode 100644 index 0000000..ffd56d9 --- /dev/null +++ b/arduino-0018-linux/reference/EthernetBegin.html @@ -0,0 +1,102 @@ + + + + Arduino - EthernetBegin + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Ethernet +

+

Ethernet.begin()

+

Description

+

Initializes the ethernet library and network settings. +

+

Syntax

+

Ethernet.begin(mac, ip);
Ethernet.begin(mac, ip, gateway);
Ethernet.begin(mac, ip, gateway, subnet);
+

Parameters

+

mac: the MAC address for the device (array of 6 bytes) +

+

ip: the IP address of the device (array of 4 bytes) +

+

gateway: the IP address of the network gateway (array of 4 bytes). optional: defaults to the device IP address with the last octet set to 1 +

+

subnet: the subnet mask of the network (array of 4 bytes). optional: defaults to 255.255.255.0 +

+

Returns

+

None +

+

Example

+
+#include <Ethernet.h>
+
+byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
+byte ip[] = { 10, 0, 0, 177 };
+
+void setup()
+{
+  Ethernet.begin(mac, ip);
+}
+
+void loop () {}
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Extended.html b/arduino-0018-linux/reference/Extended.html new file mode 100644 index 0000000..a7778c0 --- /dev/null +++ b/arduino-0018-linux/reference/Extended.html @@ -0,0 +1,226 @@ + + + + Arduino - Extended Reference + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Language Reference (extended)

+

The Arduino language is based on C/C++ and supports all standard C constructs and some C++ features. It links against AVR Libc and allows the use of any of its functions; see its user manual for details. +

+

+
+

Structure

+

Control Structures

+

Further Syntax

+

Arithmetic Operators

+
  • = (assignment operator) +
  • (addition) +
  • - (subtraction) +
  • * (multiplication) +
  • / (division) +
  • % (modulo) +

Comparison Operators

+
  • == (equal to) +
  • != (not equal to) +
  • < (less than) +
  • > (greater than) +
  • <= (less than or equal to) +
  • >= (greater than or equal to) +

Boolean Operators

+
  • && (and) +
  • || (or) +
  • ! (not) +

Pointer Access Operators

+

Bitwise Operators

+
  • & (bitwise and) +
  • | (bitwise or) +
  • ^ (bitwise xor) +
  • ~ (bitwise not) +
  • << (bitshift left) +
  • >> (bitshift right) +

  • Port Manipulation +

Compound Operators

+
  • ++ (increment) +
  • -- (decrement) +
  • += (compound addition) +
  • -= (compound subtraction) +
  • *= (compound multiplication) +
  • /= (compound division) +

  • &= (compound bitwise and) +
  • |= (compound bitwise or) +

Variables

+

Constants

+

Data Types

+

Conversion

+

Variable Scope & Qualifiers

+

Utilities

+

Reference

+
+

Functions

+

Digital I/O +

Analog I/O +

Advanced I/O +

  • shiftOut(dataPin, clockPin, bitOrder, value) +
  • unsigned long pulseIn(pin, value) +

Time +

Math +

Trigonometry +

Random Numbers +

+

Bits and Bytes +

External Interrupts +

+

Interrupts +

+

Communication +

+

Looking for something else? Try the list of community-contributed code. +

+

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/FAQ.html b/arduino-0018-linux/reference/FAQ.html new file mode 100644 index 0000000..981931c --- /dev/null +++ b/arduino-0018-linux/reference/FAQ.html @@ -0,0 +1,125 @@ + + + + Arduino - FAQ + + + + +
+ + + + + + +
+ +
+

Frequently Asked Questions

+

What is an Arduino? +

+

Glad you asked, we have a great introduction page on Arduino, click here to read it. +

+

What do you mean by open-source hardware? +

+

Open-source hardware shares much of the principles and approach of free and open-source software. In particular, we believe that people should be able to study our hardware to understand how it works, make changes to it, and share those changes. To facilitate this, we release all of the original design files (Eagle CAD) for the Arduino hardware. These files are licensed under a Creative Commons Attribution Share-Alike license, which allows for both personal and commercial derivative works, as long as they credit Arduino and release their designs under the same license. +

+

The Arduino software is also open-source. The source code for the Java environment is released under the GPL and the C/C++ microcontroller libraries are under the LGPL. +

+

How can I get an Arduino board? +

+

You can buy an Arduino board from one of the distributors listed on the buy page. If you'd prefer to build your own, see the Arduino Single-Sided Serial board, which can be easily etched and assembled. +

+

Who makes Arduino boards? +

+

Most of the official Arduino boards are manufactured by SmartProjects in Italy. The Arduino Pro, Pro Mini, and LilyPad are manufactured by SparkFun Electronics (a US company). The Arduino Nano is manufactured by Gravitech (also a US company). +

+

Which are the official Arduino boards? +

+

The official Arduino boards are the ones listed on the hardware page: the Duemilanove, Nano, Mega, Bluetooth (BT), LilyPad, Mini, Pro, Pro Mini, and a few older models, along with the Ethernet, XBee, motor, and prototyping shields. These are boards whose manufacturers work with the Arduino team to ensure a good user experience, compatibility with the Arduino software, and a quality product. In return for their status as official boards, the manufacturers pay a licensing fee to the Arduino team to support the further development of the project. +

+

In general, we try to restrict use of the name “Arduino” to the official boards. If you find a product under a different name but described as “Arduino compatible”, it’s probably not an official board and doesn’t fund continued work on the project. +

+

I want to design my own board; what should I do? +

+

The reference designs for the Arduino boards are available from the hardware page. They're licensed under a Creative Commons Attribution Share-Alike license, so you are free to use and adapt them for your own needs without asking permission or paying a fee. If you're looking to make something of interest to the community, we'd encourage you to discuss your ideas on the hardware development forum so that potential users can offer suggestions. +

+

What should I call my boards? +

+

If you're making your own board, come up with your own name! This will allow people identify you with your products and help you to build a brand. Be creative: try to suggest what people might use the board for, or emphasize the form factor, or just pick a random word that sounds cool. "Arduino" is a trademark of Arduino team and should not be used for unofficial variants. If you're interested in having your design included in the official Arduino product line, please see the So you want to make an Arduino document and contact the Arduino team. Note that while we don't attempt to restrict uses of the "duino" suffix, its use causes the Italians on the team to cringe (apparently it sounds terrible); you might want to avoid it. +

+

Can I build a commercial product based on Arduino? +

+

Yes, with the following conditions: +

+

  • Physically embedding an Arduino board inside a commercial product does not require you to disclose or open-source any information about its design. +

  • Deriving the design of a commercial product from the Eagle files for an Arduino board requires you to release the modified files under the same Creative Commons Attribution Share-Alike license. You may manufacture and sell the resulting product. +

  • Using the Arduino core and libraries for the firmware of a commercial product does not require you to release the source code for the firmware. The LGPL does, however, require you to make available object files that allow for the relinking of the firmware against updated versions of the Arduino core and libraries. Any modifications to the core and libraries must be released under the LGPL. +

  • The source code for the Arduino environment is covered by the GPL, which requires any modifications to be open-sourced under the same license. It does not prevent the sale of derivative software or its inclusion in commercial products. +

In all cases, the exact requirements are determined by the applicable license. Additionally, see the previous question for information about the use of the name “Arduino”. +

+

+How can I run the Arduino IDE under Linux? +

+

See instructions for Ubuntu Linux, for Debian Linux, for Gentoo Linux, for Linux, or for Linux on PPC. This this forum thread has more information. Or, you can use Arduino from the command line, and not have to install Java. +

+

Can I program the Arduino board in C? +

+

In fact, you already are; the Arduino language is merely a set of C/C++ functions that can be called from your code. Your sketch undergoes minor changes (e.g. automatic generation of function prototypes) and then is passed directly to a C/C++ compiler (avr-g++). All standard C and C++ constructs supported by avr-g++ should work in Arduino. For more details, see the page on the Arduino build process. +

+

Can I use a different IDE to program the Arduino board? +

+

It is possible to compile programs for the Arduino using a Makefile and the command line. If you can get your IDE to run make, you should be all set. +

+

Can I use an Arduino board without the Arduino software? +

+

Sure. It's just an AVR development board, you can use straight AVR C or C++ (with avr-gcc and avrdude or AVR Studio) to program it. +

+

Can I use the Arduino software with other AVR boards? +

+

Yes, although it may require some modifications to the Arduino core libraries. See the porting page in the Arduino Google Code project for details. +

+

Troubleshooting

+

These questions have moved to the troubleshooting section of the Arduino guide. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Float.html b/arduino-0018-linux/reference/Float.html new file mode 100644 index 0000000..ce02ead --- /dev/null +++ b/arduino-0018-linux/reference/Float.html @@ -0,0 +1,98 @@ + + + + Arduino - Float + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

float

+

Description

+

Datatype for floating-point numbers, a number that has a decimal point. Floating-point numbers are often used to approximate analog and continuous values because they have greater resolution than integers. Floating-point numbers can be as large as 3.4028235E+38 and as low as -3.4028235E+38. They are stored as 32 bits (4 bytes) of information. +

+

Floating point numbers are not exact, and may yield strange results when compared. For example 6.0 / 3.0 may not equal 2.0. You should instead check that the absolute value of the difference between the numbers is less than some small number. +

+

Floating point math is also much slower than integer math in performing calculations, so should be avoided if, for example, a loop has to run at top speed for a critical timing function. Programmers often go to some lengths to convert floating point calculations to integer math to increase speed. +

+

Examples

+
    float myfloat;
+    float sensorCalbrate = 1.117;
+
+

Syntax

+
    float var = val;
+
+

  • var - your float variable name +
  • val - the value you assign to that variable +

Example Code

+
+   int x;
+   int y;
+   float z;
+
+   x = 1;
+   y = x / 2;            // y now contains 0, ints can't hold fractions
+   z = (float)x / 2.0;   // z now contains .5 (you have to use 2.0, not 2)
+
+

See Also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/FloatCast.html b/arduino-0018-linux/reference/FloatCast.html new file mode 100644 index 0000000..e45d843 --- /dev/null +++ b/arduino-0018-linux/reference/FloatCast.html @@ -0,0 +1,82 @@ + + + + Arduino - FloatCast + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

float()

+

Description

+

Converts a value to the float data type. +

+

Syntax

+

float(x) +

+

Parameters

+

x: a value of any type +

+

Returns

+

float +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/For.html b/arduino-0018-linux/reference/For.html new file mode 100644 index 0000000..3d5efb1 --- /dev/null +++ b/arduino-0018-linux/reference/For.html @@ -0,0 +1,105 @@ + + + + Arduino - For + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

for statements

+

Desciption

+

The for statement is used to repeat a block of statements enclosed in curly braces. An increment counter is usually used to increment and terminate the loop. The for statement is useful for any repetitive operation, and is often used in combination with arrays to operate on collections of data/pins. +

+

There are three parts to the for loop header: +

+

for (initialization; condition; increment) { +

+

//statement(s); +

+

} +

+

The initialization happens first and exactly once. Each time through the loop, the condition is tested; if it's true, the statement block, and the increment is executed, then the condition is tested again. When the condition becomes false, the loop ends. +

+

Example

+
+// Dim an LED using a PWM pin
+int PWMpin = 10; // LED in series with 1k resistor on pin 10
+
+void setup()
+{
+  // no setup needed
+}
+
+void loop()
+{
+   for (int i=0; i <= 255; i++){
+      analogWrite(PWMpin, i);
+      delay(10);
+   } 
+}
+
+
+

Coding Tip

+

The C for loop is much more flexible than for loops found in some other computer languages, including BASIC. Any or all of the three header elements may be omitted, although the semicolons are required. Also the statements for initialization, condition, and increment can be any valid C statements with unrelated variables. These types of unusual for statements may provide solutions to some rare programming problems. +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Fpconstants.html b/arduino-0018-linux/reference/Fpconstants.html new file mode 100644 index 0000000..c8f6394 --- /dev/null +++ b/arduino-0018-linux/reference/Fpconstants.html @@ -0,0 +1,86 @@ + + + + Arduino - Fpconstants + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

floating point constants

+

Similar to integer constants, floating point constants are used to make code more readable. Floating point constants are swapped at compile time for the value to which the expression evaluates. +

+

Examples: +

+

n = .005; +

+

Floating point constants can also be expressed in a variety of scientific notation. 'E' and 'e' are both accepted as valid exponent indicators. +

+

+
+floating-point   evaluates to:      also evaluates to:
+  constant 
+
+   10.0	             10
+  2.34E5          2.34 * 10^5             234000
+  67e-12        67.0 * 10^-12         .000000000067
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/FunctionDeclaration.html b/arduino-0018-linux/reference/FunctionDeclaration.html new file mode 100644 index 0000000..0fca4dd --- /dev/null +++ b/arduino-0018-linux/reference/FunctionDeclaration.html @@ -0,0 +1,140 @@ + + + + Arduino - FunctionDeclaration + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Board +

+

Functions

+

Segmenting code into functions allows a programmer to create modular pieces of code that perform a defined task and then return to the area of code from which the function was "called". The typical case for creating a function is when one needs to perform the same action multiple times in a program. +

+

For programmers accustomed to using BASIC, functions in Arduino provide (and extend) the utility of using subroutines (GOSUB in BASIC). +

+

Standardizing code fragments into functions has several advantages: +

+

  • Functions help the programmer stay organized. Often this helps to conceptualize the program. +

  • Functions codify one action in one place so that the function only has to be thought out and debugged once. +

  • This also reduces chances for errors in modification, if the code needs to be changed. +

  • Functions make the whole sketch smaller and more compact because sections of code are reused many times. +

  • They make it easier to reuse code in other programs by making it more modular, and as a nice side effect, using functions also often makes the code more readable. +

There are two required functions in an Arduino sketch, setup() and loop(). Other functions must be created outside the brackets of those two functions. As an example, we will create a simple function to multiply two numbers. +

+

Example

+
+

To "call" our simple multiply function, we pass it parameters of the datatype that it is expecting: +

+

+void loop{
+int i = 2;
+int j = 3;
+int k;
+
+k = myMultiplyFunction(i, j); // k now contains 6
+}
+
+

Our function needs to be declared outside any other function, so "myMultiplyFunction()" can go either above or below the "loop()" function. +

+

The entire sketch would then look like this: +

void setup(){
+  Serial.begin(9600);
+}
+
+void loop{
+  int i = 2;
+  int j = 3;
+  int k;
+
+  k = myMultiplyFunction(i, j); // k now contains 6
+  Serial.println(k);
+  delay(500);
+}
+
+int myMultiplyFunction(int x, int y){
+  int result;
+  result = x * y;
+  return result;
+}
+
+

Another example

+

This function will read a sensor five times with analogRead() and calculate the average of five readings. It then scales the data to 8 bits (0-255), and inverts it, returning the inverted result. +

+

int ReadSens_and_Condition(){
+  int i;
+  int sval;
+
+  for (i = 0; i < 5; i++){
+    sval = sval + analogRead(0);    // sensor on analog pin 0
+  }
+
+  sval = sval / 5;    // average
+  sval = sval / 4;    // scale to 8 bits (0 - 255)
+  sval = 255 - sval;  // invert output
+  return sval;
+}
+
+

To call our function we just assign it to a variable. +

+

int sens;
+
+sens = ReadSens_and_Condition();
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Goto.html b/arduino-0018-linux/reference/Goto.html new file mode 100644 index 0000000..1e45932 --- /dev/null +++ b/arduino-0018-linux/reference/Goto.html @@ -0,0 +1,93 @@ + + + + Arduino - Goto + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

goto

+

Transfers program flow to a labeled point in the program +

+

Syntax

+

label: +

+

goto label; // sends program flow to the label +

+

Tip

+

The use of goto is discouraged in C programming, and some authors of C programming books claim that the goto statement is never necessary, but used judiciously, it can simplify certain programs. The reason that many programmers frown upon the use of goto is that with the unrestrained use of goto statements, it is easy to create a program with undefined program flow, which can never be debugged. +

+

With that said, there are instances where a goto statement can come in handy, and simplify coding. One of these situations is to break out of deeply nested for loops, or if logic blocks, on a certain condition. +

+

Example

+
+for(byte r = 0; r < 255; r++){
+    for(byte g = 255; g > -1; g--){
+        for(byte b = 0; b < 255; b++){
+            if (analogRead(0) > 250){ goto bailout;}
+            // more statements ... 
+        }
+    }
+}
+bailout:
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Guide_ArduinoBT.html b/arduino-0018-linux/reference/Guide_ArduinoBT.html new file mode 100644 index 0000000..6c155d2 --- /dev/null +++ b/arduino-0018-linux/reference/Guide_ArduinoBT.html @@ -0,0 +1,80 @@ + + + + Arduino - ArduinoBT + + + + +
+ + + + + + +
+ +
+

ArduinoBT

+

The Arduino BT is an Arduino board with built-in bluetooth module, allowing for wireless communication. To get started with the Arduino BT, follow the directions for the Arduino NG on your operating system (Windows, Mac OS X, Linux), with the following modifications: +

+

  • First, pair the Arduino BT with your computer and create a virtual serial port for it. Look for a bluetooth device called ARDUINOBT and the pass code is 12345. +

  • Select Arduino BT from the Tools | Board menu of the Arduino environment. +

Information about the Arduino BT

+

In most respects, the Arduino BT is similar to the Arduino Diecimila. Here are the main differences of BT board (besides the fact that it communicates over bluetooth instead of USB): +

+

  • The Arduino BT is more fragile and easy to break than a regular Arduino board. +

  • Don't power the board with more than 5.5 volts to the or reverse the polarity (power and ground pins) of your power supply, or you might kill the ATmega168 on the Arduino BT. The Arduino BT can, however, run with a minimum of 1.2 volts, making it easier to power with batteries. +

  • The microcontroller (an ATmega168) on the Arduino BT is a physically smaller version of the chip on the USB Arduino boards. You can't remove it, so if you kill it, you need a new Arduino BT. +

  • There are two extra analog inputs on the Arduino BT (8 total). Two of these, however, are not connected to the pin headers on the board; you'll need to solder something to the pads next to the numbers "6" and "7". +

  • Pin 7 is connected to the reset pin of the bluetooth module; don't use it for anything (except resetting the module). +

For more details, see the Arduino BT hardware page. +

+

Using the Arduino BT

+

The on-board serial communication between the bluetooth module and the Arduino sketch (running on the ATmega168) needs to be at 115200 baud (i.e. call Serial.begin(115200) in your setup() function). Communication between the bluetooth module and the computer can be at any baud rate. +

+

Communication between the BT module and the computer can be temperamental. You might want to open the serial monitor a couple of seconds after resetting the board. +The text of the Arduino getting started guide is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the guide are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Guide_ArduinoEthernetShield.html b/arduino-0018-linux/reference/Guide_ArduinoEthernetShield.html new file mode 100644 index 0000000..dc30f26 --- /dev/null +++ b/arduino-0018-linux/reference/Guide_ArduinoEthernetShield.html @@ -0,0 +1,73 @@ + + + + Arduino - ArduinoEthernetShield + + + + +
+ + + + + + +
+ +
+

Arduino Ethernet Shield

+

The Arduino Ethernet shield allows an Arduino board to connect to the internet using the Ethernet library. +

+

Connecting the Shield

+
+

To use the shield, mount it on top of an Arduino board (e.g. the Diecimila). To upload sketches to the board, connect it to your computer with a USB cable as you normally would. Once the sketch has been uploaded, you can disconnect the board from your computer and power it with an external power supply. +

+

Connect the shield to your computer or a network hub or router using a standard ethernet cable (CAT5 or CAT6 with RJ45 connectors). Connecting to a computer may require the use of a cross-over cable (although many computers, including all recent Macs can do the cross-over internally). +

+

Network Settings

+

The shield must be assigned a MAC address and a fixed IP address using the Ethernet.begin() function. A MAC address is a globally unique identifier for a particular device; inventing a random one should work, but don't use the same one for multiple boards. Valid IP addresses depend on the configuration of your network. (It is possible to use DHCP to dynamically assign an IP to the shield, but this is not yet implemented.) Optionally, you can also specify a network gateway and subnet. +

+

The text of the Arduino getting started guide is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the guide are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Guide_ArduinoLilyPad.html b/arduino-0018-linux/reference/Guide_ArduinoLilyPad.html new file mode 100644 index 0000000..46244d9 --- /dev/null +++ b/arduino-0018-linux/reference/Guide_ArduinoLilyPad.html @@ -0,0 +1,81 @@ + + + + Arduino - ArduinoLilyPad + + + + +
+ + + + + + +
+ +
+

Guide to the LilyPad Arduino

+

To get started with the LilyPad Arduino, follow the directions for the Arduino NG on your operating system (Windows, Mac OS X, Linux. Connecting the LilyPad Arduino is a bit more complicated than a regular Arduino board (see below for instructions and photos). +

+

The LilyPad Arduino is more fragile and easy to break than a regular Arduino board. Don't connect more than 5.5 volts to the + tab or reverse the power and ground pins of your power supply, or you will very likely kill the ATmega on the LilyPad Arduino. You can't remove the ATmega, so if you kill it, you need a new LilyPad. +

+

Note: More information about getting started with the LilyPad Arduino can be found here. +

+

+

Connecting the LilyPad Arduino

+

To program the LilyPad Arduino, you need to connect it to your computer. The SparkFun FTDI Basic Breakout plugs into the 6-pin male header on the newest version of the LilyPad. Use a USB MiniB cable to connect the FTDI basic breakout to your computer. You can also use an FTDI USB-TTL Serial cable. +

+

+

To connect earlier versions of the board or for information on other connection options see the LilyPad Arduino tutorial on Leah's website +

+

Sewing the LilyPad Arduino

+

The hole on each tab of the LilyPad is large enough for a sewing needle to pass through. You can make both electrical and physical connections with stitching in conductive thread. Sew through the holes several times to insure good contact. Here's a picture showing a sewn LilyPad: +

+

+

See the LilyPad Arduino tutorial on Leah's website for more information about building a working wearable. See SparkFun for more stitchable modules that you can use with your LilyPad Arduino. +

+

The text of the Arduino getting started guide is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the guide are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Guide_ArduinoMini.html b/arduino-0018-linux/reference/Guide_ArduinoMini.html new file mode 100644 index 0000000..b8fa07a --- /dev/null +++ b/arduino-0018-linux/reference/Guide_ArduinoMini.html @@ -0,0 +1,106 @@ + + + + Arduino - ArduinoMini + + + + +
+ + + + + + +
+ +
+

Guide to the Arduino Mini

+

To get started with the Arduino Mini, follow the directions for the regular Arduino on your operating system (Windows, Mac OS X, Linux), with the following modifications: +

+

  • Connecting the Arduino Mini is a bit more complicated than a regular Arduino board (see below for instructions and photos). +

  • You need to select Arduino Mini from the Tools | Board menu of the Arduino environment. +

  • To upload a new sketch to the Arduino Mini, you need to press the reset button on the board immediately before pressing the upload button in the Arduino environment. +

Information about the Arduino Mini

+

The microcontroller (an ATmega168) on the Arduino Mini is a physically smaller version of the chip on the USB Arduino boards, with the following small difference: +

+

  • There are two extra analog inputs on the Mini (8 total). Four of these, however, are not connected to the legs that come on the Arduino Mini, requiring you to solder wires to their holes to use them. Two of these unconnected pins are also used by the Wire library (I2C), meaning that its use will require soldering as well. +

Also, the Arduino Mini is more fragile and easy to break than a regular Arduino board. +

+

  • Don't connect more than 9 volts to the +9V pin or reverse the power and ground pins of your power supply, or you might kill the ATmega168 on the Arduino Mini. +

  • You can't remove the ATmega168, so if you kill it, you need a new Mini. +

+

Connecting the Arduino Mini

+

Here's a diagram of the pin layout of the Arduino Mini: +

+

+
+

+

Mini 03 pinout (compatible with earlier revisions) +

+

+

+

Mini 04 pinout (the ground on the left has moved down one pin) +

+

+

To use the Arduino Mini, you need to connect: +

+

  • Power. This can be a regulated +5V power source (e.g. from the +5V pin of the Mini USB Adapter or an Arduino NG) connected to the +5V pin of the Arduino Mini. Or, a +9V power source (e.g. a 9 volt battery) connected to the +9V pin of the Arduino Mini. +

  • Ground. One of the ground pins on the Arduino Mini must be connected to ground of the power source. +

  • TX/RX. These pins are used both for uploading new sketches to the board and communicating with a computer or other device. +

  • Reset. Whenever this pin is connected to ground, the Arduino Mini resets. You can wire it to a pushbutton, or connect it to +5V to prevent the Arduino Mini from resetting (except when it loses power). If you leave the reset pin unconnected, the Arduino Mini will reset randomly. +

  • An LED. While not technically necessary, connecting an LED to the Arduino Mini makes it easier to check if it's working. Pin 13 has a 1 KB resistor on it, so you can connect an LED to it directly between it and ground. When using another pin, you will need an external resistor. +

You have a few options for connecting the board: the Mini USB Adapter, a regular Arduino board, or your own power supply and USB/Serial adapter. +

+

Connecting the Arduino Mini and Mini USB Adapter

+

Here is a photo showing the Arduino Mini connected to the Mini USB adapter. Notice that the reset pin is connected directly to +5V (the orange wire), without a pushbutton. Thus, to reset the Arduino Mini, you will need to unplug and reconnect the USB cable to the Mini USB Adapter, or manually move the orange wire connected to the reset pin from +5V to ground and back. +

+

+

Connecting the Arduino Mini and a regular Arduino

+

Here's a photo of the Arduino Mini connected to an Arduino NG. The NG has its ATmega8 removed and is being used for its USB connection, power source, and reset button. Thus, you can reset the Arduino Mini just by pressing the button on the NG. +

+

+

The text of the Arduino getting started guide is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the guide are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Guide_ArduinoNano.html b/arduino-0018-linux/reference/Guide_ArduinoNano.html new file mode 100644 index 0000000..8fb6f0f --- /dev/null +++ b/arduino-0018-linux/reference/Guide_ArduinoNano.html @@ -0,0 +1,73 @@ + + + + Arduino - ArduinoNano + + + + +
+ + + + + + +
+ +
+

Guide to the Arduino Nano

+
+

Connecting the Arduino Nano 2.2 to a computer with a Mini-B USB cable. Note the blue power LED underneath the board. +

+


+

+

To connect the Arduino Nano to your computer, you'll need a Mini-B USB cable. This also provides power to the board, as indicated by the blue LED (which is on the bottom of the Arduino Nano 2.x and the top of the Arduino Nano 3.0). +

+

If you have an Arduino Nano 3.0, you'll need to select Arduino Duemilanove or Nano w/ ATmega32 from the Tools > Board menu. If you have an Arduino Nano 2.x, select Arduino Diecimila, Duemilanove, or Nano w/ ATmega168. Select the correct serial port selected from the Tools > Serial Port menu. Then simply press the upload button in the Arduino environment. The board will automatically reset and the sketch will be uploaded. If you have any problems, see the troubleshooting guide. +

+

For more details on the Arduino Nano, see the hardware page. +

+

The text of the Arduino getting started guide is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the guide are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Guide_ArduinoPro.html b/arduino-0018-linux/reference/Guide_ArduinoPro.html new file mode 100644 index 0000000..22609db --- /dev/null +++ b/arduino-0018-linux/reference/Guide_ArduinoPro.html @@ -0,0 +1,96 @@ + + + + Arduino - ArduinoPro + + + + +
+ + + + + + +
+ +
+

Arduino Pro

+

The Arduino Pro is intended for advanced users who require flexibility and low-cost. It comes with the minimum of components (no on-board USB or pin headers) to keep the cost down. It's a good choice for a board you want to leave embedded in a project. Please note that there are multiple variants of the board which operate at different voltages and clock speeds. You need to know if you have the 3.3V / 8 MHz version or the 5V / 16 MHz version. +

+

Uploading Sketches

+

The board comes without built-in USB circuitry, so an off-board USB-to-TTL serial convertor must be used to upload sketches. For the 3.3V Arduino Pro boards, this can be a FTDI TTL-232R-3V3 USB - TTL Level Serial Converter Cable or the SparkFun FTDI Basic Breakout Board (3.3V). For the 5V Arduino Pro boards, use a TTL-232R USB - TTL Level Serial Converter or the SparkFun FTDI Basic Breakout Board (5V). (You can probably also get away with using a 5V USB-to-serial convertor with a 3.3V board and vice-versa, but it's not recommended.) +

+

If using the FTDI cable on Windows, you'll need to make one configuration change to enable the auto-reset. With the board connected, open the Device Manager (in Control Panels > System > Hardware), and find the USB Serial Port under Ports. Right-click and select properties, then go to Port Settings > Advanced and check Set RTS on Close under Miscellaneous Options. +

+

For the 3.3V versions of the Arduino Pro, select Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328 or Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega168 from the Tools > Board menu (depending on the microcontroller on your board). For the 5V versions of the Arduino Pro, select Arduino Duemilanove or Nano w/ ATmega328 or Arduino Diecimila, Duemilanove, or Nano w/ ATmega168. +

+


+

+

+

An Arduino Pro connected to (and powered by) an FTDI USB - TTL Level Serial Converter Cable. The green and yellow wires align with the words "green" and "yellow" written underneath the pins. +

+


+

+

+

The Arduino Pro connected to (and powered by) a SparkFun FTDI Basic Breakout Board (prototype version) and USB Mini-B cable. +

+


+

+

Power

+

The external USB-to-TTL serial convertor will power the Arduino Pro, regardless of the position of the switch. To use the board standalone, with no connection to a computer, it can be be powered by a battery or an external power supply (wall wart). You can solder the + and - wires of a battery connector to the corresponding holes on the board. For the 3.3V boards, you can connect a LiPo battery (with JST connector) to the JST jack. Alternatively, solder a DC power jack into the three large holes on the board, and connect a DC power supply (center positive). When the switch is in the "Batt" position, the board will draw power from an attached battery; when it is in the "Ext." position, power comes from an external power supply. In either position, the board can be powered by the 6-pin USB header. +

+


+

+

+

A 3.3V Arduino Pro powered by a 2000 mAh LiPo battery from SparkFun. +

+


+

+

Connectors

+

Any standard 0.1" spaced header can be soldered to the holes on the Arduino Pro. To use every pin requires two 6-pin header and two 8-pin headers. Bare wire can also be soldered directly to the holes. Note that the header spacing is compatible with Arduino shields. +

+

The text of the Arduino getting started guide is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the guide are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Guide_ArduinoProMini.html b/arduino-0018-linux/reference/Guide_ArduinoProMini.html new file mode 100644 index 0000000..155b7de --- /dev/null +++ b/arduino-0018-linux/reference/Guide_ArduinoProMini.html @@ -0,0 +1,90 @@ + + + + Arduino - ArduinoProMini + + + + +
+ + + + + + +
+ +
+

Arduino Pro Mini

+

The Arduino Pro Mini is intended for advanced users who require flexibility, low-cost, and small size. It comes with the minimum of components (no on-board USB or pin headers) to keep the cost down. It's a good choice for a board you want to leave embedded in a project. Please note that there are two versions of the board: one that operates at 5V (like most Arduino boards), and one that operates at 3.3V. Be sure to provide the correct power and use components whose operating voltage matches that of the board. +

+

Uploading Sketches

+

The board comes without built-in USB circuitry, so an off-board USB-to-TTL serial convertor must be used to upload sketches. This can be a FTDI TTL-232R USB - TTL Level Serial Converter Cable for the 5V Arduino Mini Pro), or a FTDI TTL-232R-3V3 USB - TTL Level Serial Converter Cable or the SparkFun FTDI Basic Breakout Board for a 3.3V Arduino Mini Pro. +One convenient way to connect these is by inserting a six-pin 0.1" male pin header into the end of the FTDI cable or breakout board, and pressing it against the six hole programming header on the Mini Pro. +

+

If using the FTDI cable on Windows, you'll need to make one configuration change to enable the auto-reset. With the board connected, open the Device Manager (in Control Panels > System > Hardware), and find the USB Serial Port under Ports. Right-click and select properties, then go to Port Settings > Advanced and check Set RTS on Close under Miscellaneous Options. +

+

For the 3.3V versions of the Arduino Pro Mini, select Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328 or Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega168 from the Tools > Board menu (depending on the microcontroller on your board). For the 5V versions of the Arduino Pro Mini, select Arduino Duemilanove or Nano w/ ATmega328 or Arduino Diecimila, Duemilanove, or Nano w/ ATmega168. +

+


+

+

+

The Arduino Pro Mini connected to (and powered by) an FTDI TTL-232R-3V3 USB - TTL Level Serial Converter Cable. The green and black wires align with the labels "GRN" and "BLK" written next to the holes. +

+


+

+

+

The Arduino Pro Mini connected to (and powered by) a SparkFun FTDI Basic Breakout Board and USB Mini-B cable. Note that on earlier Pro Mini boards the orientation of the 6-pin header may be reversed; check that the words GRN and BLK align on the Pro Mini and FTDI Basic Breakout. +

+


+

+

Power

+

The board can be powered through USB via the six-pin programming header, or from a regulated 5V or 3.3V (depending on the model) supply applied to the VCC pin or an unregulated supply on the RAW pin. +

+

Connectors

+

Any standard 0.1" spaced header can be soldered to the holes on the Arduino Pro Mini. To use every pin requires two 12-pin headers, plus a six pin header for programming, if desired. Bare wire can also be soldered directly to the holes. +

+

The text of the Arduino getting started guide is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the guide are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Guide_ArduinoXbeeShield.html b/arduino-0018-linux/reference/Guide_ArduinoXbeeShield.html new file mode 100644 index 0000000..eb0374b --- /dev/null +++ b/arduino-0018-linux/reference/Guide_ArduinoXbeeShield.html @@ -0,0 +1,150 @@ + + + + Arduino - ArduinoXbeeShield + + + + +
+ + + + + + +
+ +
+

Arduino XBee Shield

+

The Arduino Xbee shield allows your Arduino board to communicate wirelessly using Zigbee. It was developed in collaboration with Libelium. This documentation describes the use of the shield with the XBee 802.15.4 module. For the XBee ZNet 2.5 ("Series 2") modules, see this configuration guide. +

+

A Simple Example

+

You should be able to get two Arduino boards with Xbee shields talking to each other without any configuration, using just the standard Arduino serial commands (described in the reference). +

+

To upload a sketch to an Arduino board with a Xbee shield, you'll need to put both jumpers on the shield to the "USB" setting (i.e. place them on the two pins closest to the edge of the board) or remove them completely (but be sure not to lose them!). Then, you can upload a sketch normally from the Arduino environment. In this case, upload the Communication | Physical Pixel sketch to one of the boards. This sketch instructs the board to turn on the LED attached to pin 13 whenever it receives an 'H' over its serial connection, and turn the LED off when it gets an 'L'. You can test it by connecting to the board with the Arduino serial monitor (be sure it's set at 9600 baud), typing an H, and pressing enter (or clicking send). The LED should turn on. Send an L and the LED should turn off. If nothing happens, you may have an Arduino board that doesn't have a built-in LED on pin 13 (see the board index to check for sure), in this case you'll need to supply your own. +

+

Once you've uploaded the Physical Pixel sketch and made sure that it's working, unplug the first Arduino board from the computer. Switch the jumpers to the Xbee setting (i.e. place each on the center pin and the pin farthest from the edge of the board). Now, you need to upload a sketch to the other board. Make sure its jumpers are in the USB setting. Then upload the following sketch to the board: +

+

+void setup()
+{
+  Serial.begin(9600);
+}
+
+void loop()
+{
+  Serial.print('H');
+  delay(1000);
+  Serial.print('L');
+  delay(1000);
+}
+
+
+

When it's finished uploading, you can check that it's working with the Arduino serial monitor. You should see H's and L's arriving one a second. Turn off the serial monitor and unplug the board. Switch the jumpers to the Xbee setting. Now connect both boards to the computer. After a few seconds, you should see the LED on the first board turn on and off, once a second. (This is the LED on the Arduino board itself, not the one on the Xbee shield, which conveys information about the state of the Xbee module.) If so, congratulations, your Arduino boards are communicating wirelessly. This may not seem that exciting when both boards are connected to the same computer, but if you connect them to different computers (or power them with an external power supply - being sure to switch the power jumper on the Arduino board), they should still be able to communicate. +

+

A Few Notes

+

You can use any of the standard Arduino serial commands with the Xbee shield. With the shield's jumpers in the Xbee position, the print and println commands will send data over the Xbee shield and the USB connection (i.e. to other Xbee shields and to the computer at the same time). In this configuration, however, the board will only receive data from the Xbee shield not from the USB connection (you'll need to switch the jumpers to allow the board to receive data from the computer). +

+

The Xbee module on the shield is set up to work at 9600 baud by default, so unless you reconfigure it, you'll need to make sure you're passing 9600 to the Serial.begin() command in your sketch. +

+

To allow your computer to communicate directly with the Xbee shield, connect it to an Arduino board whose microcontroller has been removed and place its jumpers in the USB configuration. Then you can send data to and receive data from the Xbee module from any terminal program. This allows you, for example, to see the data that the module is receiving from other Xbee shields (e.g. to collect sensor data wirelessly from a number of locations). +

+

Configuring the Xbee Module

+

You can configure the Xbee module from code running on the Arduino board or from software on the computer. To configure it from the Arduino board, you'll need to have the jumpers in the Xbee position. To configure it from the computer, you'll need to have the jumpers in the USB configuration and have removed the microncontroller from your Arduino board. +

+

To get the module into configuration mode, you need to send it three plus signs: +++ and there needs to be at least one second before and after during which you send no other character to the module. Note that this includes newlines or carriage return characters. Thus, if you're trying to configure the module from the computer, you need to make sure your terminal software is configured to send characters as you type them, without waiting for you to press enter. Otherwise, it will send the plus signs immediately followed by a newline (i.e. you won't get the needed one second delay after the +++). If you successfully enter configuration mode, the module will send back the two characters 'OK', followed by a carriage return. +

+

+
Send Command + Expected Response +
+++ + OK<CR> +
+

Once in configuration mode, you can send AT commands to the module. Command strings have the form ATxx (where xx is the name of a setting). To read the current value of the setting, send the command string followed by a carriage return. To write a new value to the setting, send the command string, immediately followed by the new setting (with no spaces or newlines in-between), followed by a carriage return. For example, to read the network ID of the module (which determines which other Xbee modules it will communicate with), use the 'ATID command: +

+

+
Send Command + Expected Response +
ATID<enter> + 3332<CR> +
+

To change the network ID of the module: +

+

+
Send Command + Expected Response +
ATID3331<enter> + OK<CR> +
+

Now, check that the setting has taken effect: +

+

+
Send Command + Expected Response +
ATID<enter> + 3331<CR> +
+

Unless you tell the module to write the changes to non-volatile (long-term) memory, they will only be in effect until the module loses power. To save the changes permanently (until you explicitly modify them again), use the ATWR command: +

+

+
Send Command + Expected Response +
ATWR<enter> + OK<CR> +
+

To reset the module to the factory settings, use the ATRE command: +

+

+
Send Command + Expected Response +
ATRE<enter> + OK<CR> +
+

Note that like the other commands, the reset will not be permanent unless you follow it with the ATWR comamand. +

+

References

+

For more information, see: the hardware page for the Xbee shield, the Libelium SquidBee wiki, and the MaxStream Xbee page. +The text of the Arduino getting started guide is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the guide are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Guide_Board.html b/arduino-0018-linux/reference/Guide_Board.html new file mode 100644 index 0000000..8396c36 --- /dev/null +++ b/arduino-0018-linux/reference/Guide_Board.html @@ -0,0 +1,82 @@ + + + + Arduino - Board + + + +
+ + + + + + +
+ +
+

Guide   Contents | Introduction | How To: Windows, Mac OS X, Linux; Arduino Mini, Arduino BT, LilyPad Arduino; Xbee shield | Troubleshooting | Board | Environment +

Introduction to the Arduino Board

+

Looking at the board from the top down, this is an outline of what you will see (parts of the board you might interact with in the course of normal use are highlighted): +

+

+

Starting clockwise from the top center: +

+

  • Analog Reference pin (orange) +
  • Digital Ground (light green) +
  • Digital Pins 2-13 (green) +
  • Digital Pins 0-1/Serial In/Out - TX/RX (dark green) - These pins cannot be used for digital i/o (digitalRead and digitalWrite) if you are also using serial communication (e.g. Serial.begin). +
  • Reset Button - S1 (dark blue) +
  • In-circuit Serial Programmer (blue-green) +
  • Analog In Pins 0-5 (light blue) +
  • Power and Ground Pins (power: orange, grounds: light orange) +
  • External Power Supply In (9-12VDC) - X1 (pink) +
  • Toggles External Power and USB Power (place jumper on two pins closest to desired supply) - SV1 (purple) +
  • USB (used for uploading sketches to the board and for serial communication between the board and the computer; can be used to power the board) (yellow) +

The text of the Arduino getting started guide is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the guide are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Guide_Environment.html b/arduino-0018-linux/reference/Guide_Environment.html new file mode 100644 index 0000000..0c1daaf --- /dev/null +++ b/arduino-0018-linux/reference/Guide_Environment.html @@ -0,0 +1,166 @@ + + + + Arduino - Environment + + + + +
+ + + + + + +
+ +
+

Arduino Development Environment

+

The Arduino development environment contains a text editor for writing code, a message area, a text console, a toolbar with buttons for common functions, and a series of menus. It connects to the Arduino hardware to upload programs and communicate with them. +

+

Software written using Arduino are called sketches. These sketches are written in the text editor. It has features for cutting/pasting and for searching/replacing text. The message area gives feedback while saving and exporting and also displays errors. The console displays text output by the Arduino environment including complete error messages and other information. The toolbar buttons allow you to verify and upload programs, create, open, and save sketches, and open the serial monitor: +

+

+

+

+

+

Verify/Compile
Checks your code for errors. +

+

+

+

+

Stop
Stops the serial monitor, or unhighlight other buttons. +

+

+

+

+

New
Creates a new sketch. +

+

+

+

+

Open
Presents a menu of all the sketches in your sketchbook. Clicking one will open it within the current window. +

+

Note: due to a bug in Java, this menu doesn't scroll; if you need to open a sketch late in the list, use the File | Sketchbook menu instead. +

+

+

+

+

Save
Saves your sketch. +

+

+

+

+

Upload to I/O Board
Compiles your code and uploads it to the Arduino I/O board. See uploading below for details. +

+

+

+

+

Serial Monitor
Opens the serial monitor. +

+

+

Additional commands are found within the five menus: File, Edit, Sketch, Tools, Help. The menus are context sensitive which means only those items relevant to the work currently being carried out are available. +

+

Edit

+
  • Copy for Discourse
    Copies the code of your sketch to the clipboard in a forum suitable for posting to the forum, complete with syntax coloring. +

  • Copy as HTML
    Copies the code of your sketch to the clipboard as HTML, suitable for embedding in web pages. +

Sketch

+
  • Verify/Compile
    Checks your sketch for errors. +

  • Import Library
    Adds a library to your sketch by inserting #include statements at the code of your code. For more details, see libraries below. +

  • Show Sketch Folder
    Opens the sketch folder on the desktop. +

  • Add File...
    Adds a source file to the sketch (it will be copied from its current location). The new file appears in a new tab in the sketch window. Files can be removed from the sketch using the tab menu. +

Tools

+
  • Auto Format
    This formats your code nicely: i.e. indents it so that opening and closing curly braces line up, and that the statements instead curly braces are indented more. +

  • Board
    Select the board that you're using. See below for descriptions of the various boards. +

  • Serial Port
    This menu contains all the serial devices (real or virtual) on your machine. It should automatically refresh every time you open the top-level tools menu. +

  • Burn Bootloader
    The items in this menu allow you to burn a bootloader onto the microcontroller on an Arduino board. This is not required for normal use of an Arduino board but is useful if you purchase a new ATmega (which normally come without a bootloader). Ensure that you've selected the correct board from the Boards menu before burning the bootloader. When using an AVR ISP, you'll need to select the item corresponding to your programmer from the Serial Port menu. +

+

Sketchbook

+

The Arduino environment includes the concept of a sketchbook: a standard place to store your programs (or sketches). The sketches in your sketchbook can be opened from the File > Sketchbook menu or from the Open button on the toolbar. The first time you run the Arduino software, it will automatically create a directory for your sketchbook. You can view or change the location of the sketchbook location from with the Preferences dialog. +

+

Tabs, Multiple Files, and Compilation

+

Allows you to manage sketches with more than one file (each of which appears in its own tab). These can be normal Arduino code files (no extension), C files (.c extension), C++ files (.cpp), or header files (.h). +

+

+

Uploading

+

Before uploading your sketch, you need to select the correct items from the Tools > Board and Tools > Serial Port menus. The boards are described below. On the Mac, the serial port is probably something like /dev/tty.usbserial-1B1 (for a USB board), or /dev/tty.USA19QW1b1P1.1 (for a serial board connected with a Keyspan USB-to-Serial adapter). On Windows, it's probably COM1 or COM2 (for a serial board) or COM4, COM5, COM7, or higher (for a USB board) - to find out, you look for USB serial device in the ports section of the Windows Device Manager. On Linux, it should be /dev/ttyUSB0, /dev/ttyUSB1 or similar. +

+

Once you've selected the correct serial port and board, press the upload button in the toolbar or select the Upload to I/O Board item from the File menu. Current Arduino boards will reset automatically and begin the upload. With older boards that lack auto-reset, you'll need to press the reset button on the board just before starting the upload. On most boards, you'll see the RX and TX LEDs blink as the sketch is uploaded. The Arduino environment will display a message when the upload is complete, or show an error. +

+

When you upload a sketch, you're using the Arduino bootloader, a small program that has been loaded on to the microcontroller on your board. It allows you to upload code without using any additional hardware. The bootloader is active for a few seconds when the board resets; then it starts whichever sketch was most recently uploaded to the microcontroller. The bootloader will blink the on-board (pin 13) LED when it starts (i.e. when the board resets). +

+

+

Libraries

+

Libraries provide extra functionality for use in sketches, e.g. working with hardware or manipulating data. To use a library in a sketch, select it from the Sketch > Import Library menu. This will insert one or more #include statements at the top of the sketch and compile the library with your sketch. Because libraries are uploaded to the board with your sketch, they increase the amount of space it takes up. If a sketch no longer needs a library, simply delete its #include statements from the top of your code. +

+

There is a list of libraries in the reference. Some libraries are included with the Arduino software. Others can be downloaded from a variety of sources. To install these third-party libraries, create a directory called libraries within your sketchbook directory. Then unzip the library there. For example, to install the DateTime library, its files should be in the /libraries/DateTime sub-folder of your sketchbook folder. +

+

+

Serial Monitor

+

Displays serial data being sent from the Arduino board (USB or serial board). To send data to the board, enter text and click on the "send" button or press enter. Choose the baud rate from the drop-down that matches the rate passed to Serial.begin in your sketch. Note that on Mac or Linux, the Arduino board will reset (rerun your sketch from the beginning) when you connect with the serial monitor. +

+

You can also talk to the board from Processing, Flash, MaxMSP, etc (see the interfacing page for details). +

+

+

Preferences

+

Some preferences can be set in the preferences dialog (found under the Arduino menu on the Mac, or File on Windows and Linux). The rest can be found in the preferences file, whose location is shown in the preference dialog. +

+

+

Boards

+

The board selection has two effects: the parameters (e.g. CPU speed and baud rate) used when compiling and uploading sketches; and the file and fuse settings used by the burn bootloader command. Some of the board definitions differ only in the latter, so even if you've been uploading successfully with a particular selection you'll want to check it before burning the bootloader. +

+

  • Arduino Duemilanove or Nano w/ ATmega328
    An ATmega328 running at 16 MHz with auto-reset. Also used for the 16 MHz (5V) versions of the Arduino Pro or Pro Mini with an ATmega328. +

  • Arduino Diecimila, Duemilanove, or Nano w/ ATmega168
    An ATmega168 running at 16 MHz with auto-reset. Compilation and upload is equivalent to Arduino NG or older w/ ATmega168, but the bootloader burned has a faster timeout (and blinks the pin 13 LED only once on reset). Also used for the 16 MHz (5V) versions of the Arduino Pro and Pro Mini with an ATmega168. +

  • Arduino Mega
    An ATmega1280 running at 16 MHz with auto-reset. +

  • Arduino Mini
    Equivalent to Arduino NG or older w/ ATmega168 (i.e. an ATmega168 running at 16 MHz without auto-reset). +

  • Arduino BT
    ATmega168 running at 16 MHz. The bootloader burned includes codes to initialize the on-board bluetooth module. +

  • LilyPad Arduino w/ ATmega328
    An ATmega328 running at 8 MHz (3.3V) with auto-reset. Equivalent to Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328. +

  • LilyPad Arduino w/ ATmega168
    An ATmega168 running at 8 MHz. Compilation and upload is equivalent to the Arduino Pro or Pro Mini (8 MHz) w/ ATmega168. The bootloader burned, however, has a slower timeout (and blinks the pin 13 LED three times on reset) because the original versions of the LilyPad didn't support auto-reset. They also didn't include an external clock, so the burn bootloader command configures the fuses of ATmega168 for an internal 8 MHz clock.

    If you have a recent version of the LilyPad, (w/ a 6-pin programming header), you'll want to select Arduino Pro or Pro Mini (8 MHz) w/ ATmega168 before burning the bootloader. +

  • Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328
    An ATmega328 running at 8 MHz (3.3V) with auto-reset. Equivalent to LilyPad Arduino w/ ATmega328. +

  • Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega168
    An ATmega168 running at 8 MHz (3.3V) with auto-reset. +

  • Arduino NG or older w/ ATmega168
    An ATmega168 running at 16 MHz without auto-reset. Compilation and upload is equivalent to Arduino Diecimila or Duemilanove w/ ATmega168, but the bootloader burned has a slower timeout (and blinks the pin 13 LED three times on reset). +

  • Arduino NG or older w/ ATmega8
    An ATmega8 running at 16 MHz without auto-reset. +

The text of the Arduino getting started guide is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the guide are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Guide_Guide.html b/arduino-0018-linux/reference/Guide_Guide.html new file mode 100644 index 0000000..1e92b7a --- /dev/null +++ b/arduino-0018-linux/reference/Guide_Guide.html @@ -0,0 +1,61 @@ + + + + Arduino - Guide + + + + + + diff --git a/arduino-0018-linux/reference/Guide_HomePage.html b/arduino-0018-linux/reference/Guide_HomePage.html new file mode 100644 index 0000000..1016078 --- /dev/null +++ b/arduino-0018-linux/reference/Guide_HomePage.html @@ -0,0 +1,81 @@ + + + + Arduino - Guide + + + +
+ + + + + + +
+ +
+

Guide   Contents | Introduction | How To: Windows, Mac OS X, Linux; Arduino Mini, Arduino BT, LilyPad Arduino; Xbee shield | Troubleshooting | Board | Environment +

Guide to Arduino

+
+

In This Guide

+

This guide tell you everything you need to get started with Arduino. It consists of the following pages: +

+

Elsewhere on the Arduino website

+
  • Arduino booklet: an introduction to physical computing, electronics, and Arduino. +

+

External Resources

+

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Guide_Introduction.html b/arduino-0018-linux/reference/Guide_Introduction.html new file mode 100644 index 0000000..46da00a --- /dev/null +++ b/arduino-0018-linux/reference/Guide_Introduction.html @@ -0,0 +1,79 @@ + + + + Arduino - Introduction + + + + +
+ + + + + + +
+ +
+

What is Arduino?

+

Arduino is a tool for making computers that can sense and control more of the physical world than your desktop computer. It's an open-source physical computing platform based on a simple microcontroller board, and a development environment for writing software for the board. +

+

Arduino can be used to develop interactive objects, taking inputs from a variety of switches or sensors, and controlling a variety of lights, motors, and other physical outputs. Arduino projects can be stand-alone, or they can be communicate with software running on your computer (e.g. Flash, Processing, MaxMSP.) The boards can be assembled by hand or purchased preassembled; the open-source IDE can be downloaded for free. +

+

The Arduino programming language is an implementation of Wiring, a similar physical computing platform, which is based on the Processing multimedia programming environment. +

+

Why Arduino?

+

There are many other microcontrollers and microcontroller platforms available for physical computing. Parallax Basic Stamp, Netmedia's BX-24, Phidgets, MIT's Handyboard, and many others offer similar functionality. All of these tools take the messy details of microcontroller programming and wrap it up in an easy-to-use package. Arduino also simplifies the process of working with microcontrollers, but it offers some advantage for teachers, students, and interested amateurs over other systems: +

+

  • Inexpensive - Arduino boards are relatively inexpensive compared to other microcontroller platforms. The least expensive version of the Arduino module can be assembled by hand, and even the pre-assembled Arduino modules cost less than $50 +

  • Cross-platform - The Arduino software runs on Windows, Macintosh OSX, and Linux operating systems. Most microcontroller systems are limited to Windows. +

  • Simple, clear programming environment - The Arduino programming environment is easy-to-use for beginners, yet flexible enough for advanced users to take advantage of as well. For teachers, it's conveniently based on the Processing programming environment, so students learning to program in that environment will be familiar with the look and feel of Arduino +

  • Open source and extensible software- The Arduino software and is published as open source tools, available for extension by experienced programmers. The language can be expanded through C++ libraries, and people wanting to understand the technical details can make the leap from Arduino to the AVR C programming language on which it's based. SImilarly, you can add AVR-C code directly into your Arduino programs if you want to. +

  • Open source and extensible hardware - The Arduino is based on Atmel's ATMEGA8 and ATMEGA168 microcontrollers. The plans for the modules are published under a Creative Commons license, so experienced circuit designers can make their own version of the module, extending it and improving it. Even relatively inexperienced users can build the breadboard version of the module in order to understand how it works and save money. +

How do I use Arduino?

+

See the getting started guide. +

+

The text of the Arduino getting started guide is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the guide are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Guide_MacOSX.html b/arduino-0018-linux/reference/Guide_MacOSX.html new file mode 100644 index 0000000..7e8a9cf --- /dev/null +++ b/arduino-0018-linux/reference/Guide_MacOSX.html @@ -0,0 +1,125 @@ + + + + Arduino - MacOSX + + + + +
+ + + + + + +
+ +
+

How To Get Arduino Running on Mac OS X (10.3.9 or later)

+

This document explains how to connect your Arduino board to the computer and upload your first sketch. +

+

These are the steps that we'll go through: +

+

  1. Get an Arduino board and cable +
  2. Download the Arduino environment +
  3. Install the USB drivers +
  4. Connect the board +
  5. Run the Arduino environment +
  6. Upload a program +
  7. Look for the blinking LED +
  8. Learn to use Arduino +

1 | Get an Arduino board and cable

+

In this tutorial, we assume you're using an Arduino Duemilanove or Diecimila. If you have another board, read the corresponding page in this getting started guide. +

+

The Arduino is a simple board that contains everything you need to start working with electronics and microcontroller programming. This diagram illustrates the major components of an Arduino Diecimila. (The Arduino Duemilanove is almost identical.) +

+

+

You also need a standard USB cable (A plug to B plug): the kind you would connect to a USB printer, for example. +

+

2 | Download the Arduino environment

+

To program the Arduino board you need the Arduino environment. +

+

Download: the latest version from the download page. +

+

When the download finishes, unzip the downloaded file. Make sure to preserve the folder structure. Double-click the folder to open it. There should be a few files and sub-folders inside. +

+

3 | Install the USB drivers

+

If you are using a USB Arduino, you will need to install the drivers for the FTDI chip on the board. These can be found in the drivers directory of the Arduino distribution. +

+

You'll need to select the correct drivers for your computer. Use: +

  • FTDIUSBSerialDriver_v2_1_9.dmg for older (PPC) Macs like the Powerbook, iBook, G4 or G5 +
  • FTDIUSBSerialDriver_v2_2_9_Intel.dmg for newer (Intel) Macs like the MacBook, MacBook Pro, or Mac Pro +

(The latest version of the drivers can be found on the FTDI website.) +

+

4 | Connect the board

+

On the Diecimila, the power source is selected by the jumper between the USB and power plugs. To power the board from the USB port (good for controlling low power devices like LEDs), place the jumper on the two pins closest to the USB plug. To power the board from an external power supply (6-12V), place the jumper on the two pins closest to the power plug. On the Duemilanove, the power source is selected automatically (there is no power selection jumper). In any case, connect the board to a USB port on your computer. +

+

The green power LED (labelled PWR) should go on. +

+

5 | Run the Arduino environment

+

(Mac OSX): Copy the Arduino application to your Applications directory. Double-click the Arduino application. +

+

(Windows): Open the Arduino folder and double-click the Arduino application. +

+

6 | Upload a program

+

Open the LED blink example sketch: File > Sketchbook > Examples > Digital > Blink. +

+

Select the serial device of the Arduino board from the Tools > Serial Port menu. On the Mac, this should be something with /dev/tty.usbserial in it. +

+

You'll need to select the entry in the Tools > Board menu that corresponds to your Arduino. For newer Arduino boards with an ATmega328 (check the text on the chip on the board), select Arduino Duemilanove w/ ATmega328. Previously, Arduino boards came with an ATmega168; for those, select Arduino Diecimila or Duemilanove w/ ATmega168. +

+

Now, simply click the "Upload" button in the environment. Wait a few seconds - you should see the RX and TX leds on the board flashing. If the upload is successful, the message "Done uploading." will appear in the status bar. (Note: If you have an Arduino Mini, NG, or other board, you'll need to physically present the reset button on the board immediately before pressing the upload button.) +

+

+

7 | Look for the blinking LED

+

A few seconds after the upload finishes, you should see the pin 13 (L) LED on the board start to blink (in orange). If it does, congratulations! You've gotten Arduino up-and-running. +

+

If you have problems, please see the troubleshooting suggestions. +

+

8 | Learn to use Arduino

+
  • Examples: try these example programs. +
  • Reference: read the reference for the Arduino language. +

The text of the Arduino getting started guide is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the guide are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Guide_RecentChanges.html b/arduino-0018-linux/reference/Guide_RecentChanges.html new file mode 100644 index 0000000..8d26f86 --- /dev/null +++ b/arduino-0018-linux/reference/Guide_RecentChanges.html @@ -0,0 +1,135 @@ + + + + Arduino - RecentChanges + + + +
+ + + + + + +
+ +
+

Guide   Contents | Introduction | How To: Windows, Mac OS X, Linux; Arduino Mini, Arduino BT, LilyPad Arduino; Xbee shield | Troubleshooting | Board | Environment +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Guide_References.html b/arduino-0018-linux/reference/Guide_References.html new file mode 100644 index 0000000..de77798 --- /dev/null +++ b/arduino-0018-linux/reference/Guide_References.html @@ -0,0 +1,82 @@ + + + + Arduino - References + + + +
+ + + + + + +
+ +
+

Introduction | How To: Windows, Mac OS X, Linux; Arduino Mini, Arduino BT | Troubleshooting | Board | Environment +

Other Resources

+

On the Arduino Website

+
  • Tutorials: code examples and circuits for performing many tasks. +

  • Reference: documentation of the Arduino programming language and functions. +

  • Hardware: descriptions of the various Arduino boards and other hardware, with schematics, PCB layout files, assembly instructions, etc. +

  • Language comparison: compares the Arduino/Wiring language (based on C/C++) with Processing (based on Java). +

  • FAQ: frequently asked questions about Arduino. +

  • Discussion forums: for questions about anything Arduino related. +

  • Playground: a publicly editable wiki collecting community documentation (register here). +

External Resources on Arduino

+

Electronics and Physical Computing

+

Related Sites

+

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Guide_Troubleshooting.html b/arduino-0018-linux/reference/Guide_Troubleshooting.html new file mode 100644 index 0000000..d199d89 --- /dev/null +++ b/arduino-0018-linux/reference/Guide_Troubleshooting.html @@ -0,0 +1,257 @@ + + + + Arduino - Troubleshooting + + + + +
+ + + + + + +
+ +
+

Arduino Troubleshooting

+

On this page... (hide)

+

+

Why I can't upload my programs to the Arduino board?

+

There are a few things that could be wrong. +

+

  • First make sure your board is on (the green LED is on) and connected to the computer (if it's not, see "what if my board doesn't turn on" above). +

  • Then, check that the proper port is selected in the "Tools > Serial Port" menu (if your port doesn't appear, restart the IDE with the board connected to the computer). +

  • Make sure you have the right item selected in the Tools > Board menu. In particular, newer Arduino Duemilanove boards come with an ATmega328, while older ones have an ATmega168. To check, read the text on the microcontroller (the larger chip) on your Arduino board. For more information on the board menu items, see the guide to the Arduino environment. +

  • Disconnect digital pins 0 and 1 while uploading (they can connected and used after the code has been uploaded). +

  • Try uploading with nothing connected to the board (apart from the USB cable, of course). +

  • Make sure the board isn't touching anything metallic or conductive. +

  • Check that you're not running any programs that scan all serial ports, like PDA sync applications, Bluetooth-USB drivers (e.g. BlueSoleil), virtual daemon tools, etc. +

  • Make sure you don't have firewall software that blocks access to the serial port (e.g. ZoneAlarm). +

  • You may need to quit Processing, PD, vvvv, etc. if you're using them to read data over the USB or serial connection to the Arduino board. +

  • If you have a board that doesn't support auto-reset, be sure that you are resetting the board a couple of seconds before uploading. (The Arduino Diecimila, Duemilanove, and Nano support auto-reset as do the LilyPad, Pro, and Pro Mini with 6-pin programming headers). +

  • However, note that some Diecimila were accidently burned with the wrong bootloader and may require you to physically press the reset button before uploading; see this question below. +

  • However, on some computers, you may need to press the reset button on the board after you hit the upload button in the Arduino environment. Try different intervals of time between the two, up to 10 seconds or more. +

  • If you get this error: [VP 1] Device is not responding correctly. try uploading again (i.e. reset the board and press the download button a second time). +

  • Make sure there's a bootloader burned on your Arduino board. To check, connect an LED to pin 13 and reset the board. The LED should blink. If it doesn't, see the Bootloader page for instructions on burning a bootloader to the board. +

  • If you have a really ancient Arduino board, you may need to change the baud rate at which sketches are uploaded to 9600 (from the normal 19200). You will have to change the speed in the preferences file directly. See the preferences page for instructions on finding the file. Look for the file in your computer and change the serial.download_rate property to match the one in your board. If you have such a board, it's recommended that you burn the latest bootloader (which works at 19200 baud). This can be done with the 'Tools | Burn Bootloader menu item. +

If it still doesn't work, you can ask for help in the forum. Please include the following information: +

+

  • Your operating system. +

  • What kind of board you have. If it's a Mini, LilyPad or other board that requires extra wiring, include a photo of your circuit, if possible. +

  • Whether or not you were ever able to upload to the board. If so, what were you doing with the board before / when it stopped working, and what software have you recently added or removed from your computer? +

  • The messages displayed when you try to upload with verbose output enabled. To do this, you'll need to set upload.verbose to true in your Arduino preferences file. +

Why do I get "Build folder disappeared or could not be written" (Mac OS X)?

+

Did you drag the Arduino.app out of the disk image (and into, say, your Applications folder)? If not, you won't be able to upload the examples. +

+

+

Why doesn't the Arduino software run after I updated the Java on my Mac?

+

The latest Java update from Apple attempts to use 64-bit version of native libraries, but the Arduino application comes with a 32 bit version of the RXTX library. If you launch Arduino, you'll get an error like: +

+

Uncaught exception in main method: java.lang.UnsatisfiedLinkError: /Applications/arduino-0016/Arduino 16.app/Contents/Resources/Java/librxtxSerial.jnilib: no suitable image found. Did find: /Applications/arduino-0016/Arduino 16.app/Contents/Resources/Java/librxtxSerial.jnilib: no matching architecture in universal wrapper +

+

To fix this, click on the Arduino application (e.g. Arduino 16.app) in the Finder, and select Get Info from the File menu. In the info panel, click the Open in 32 Bit Mode checkbox. You should then be able to launch Arduino normally. +

+

+

Why do I get a java.lang.StackOverflowError when I try to compile my program?

+

The Arduino environment does some preliminary processing on your sketch by manipulating the code using regular expressions. This sometimes gets confused by certain strings of text. If you see an error like: +

+

+java.lang.StackOverflowError
+at java.util.Vector.addElement(Unknown Source)
+at java.util.Stack.push(Unknown Source)
+at com.oroinc.text.regex.Perl5Matcher._pushState(Perl5Matcher.java) 
+
+

this is what's happening. Look for unusual sequences involving "double-quotes", "single-quotes", \backslashes, comments, etc. In particular the sequence '\"' seems to cause problems; use '"' instead. +

+

+

Why doesn't my sketch start when I'm powering the board with an external power supply? (Arduino Diecimila or earlier)

+

Because the RX pin is unconnected, the bootloader on the board may be seeing garbage data coming in, meaning that it never times out and starts your sketch. Try tying the RX pin to ground with a 10K resistor (or connecting it to the TX pin). +

+

Why does the Arduino software freeze when I try to upload a program? (on Windows)?

+

This might be caused by a conflict with the Logitech process 'LVPrcSrv.exe'. Open the Task Manager and see if this program is running, and if so, kill it before attempting the upload. more information +

+

+

What if my board doesn't turn on (the green power LED doesn't light up)?

+

If you're using a USB board, make sure that the jumper (little plastic piece near the USB plug) is on the correct pins. If you're powering the board with an external power supply (plugged into the power plug), the jumper should be on the two pins closest to the power plug. If you're powering the board through the USB, the jumper should be on the two pins closest to the USB plug. This picture shows the arrangment for powering the board from the USB port. +

+

Attach:jumper.jpg Δ +

+

(thanks to mrbbp for report and picture) +

+

+

Why does my Diecimila take such a long time (6-8 seconds) to start my sketch?

+

Some of the Arduino Diecimila boards were accidently burned with the Arduino NG bootloader. It should work fine, but has a longer delay when the board is reset (because the NG doesn't have an automatic reset, so you have to time the uploads manually). You can recognize the NG bootloader because the LED on pin 13 will blink three times when you reset the board (as compared to once with the Diecimila bootloader). If your Diecimila has the NG bootloader on it, you may need to physically press the reset button on the board before uploading your sketch. You can burn the correct bootloader onto your Diecimila, see the bootloader page for details. +

+

+

What should I do if I get an error when launching arduino.exe on Windows?

+

If you get an error when double-clicking the arduino.exe executable on Windows, for example: +

+

Arduino has encountered a problem and needs to close. +

+

you'll need to launch Arduino using the run.bat file. Please be patient, the Arduino environment may take some time to open. +

+

Why won't Arduino run on old versions of Mac OS X?

+

If you get an error like this: +

+

Link (dyld) error: 
+
+dyld: /Applications/arduino-0004/Arduino 04.app/Contents/MacOS/Arduino Undefined symbols: 
+/Applications/arduino-0004/librxtxSerial.jnilib undefined reference to _printf$LDBL128 expected to be defined in /usr/lib/libSystem.B.dylib 
+
+

you probably need to upgrade to Max OS X 10.3.9 or later. Older versions have incompatible versions of some system libraries. +

+

Thanks to Gabe462 for the report. +

+

What do I do if I get an UnsatisfiedLinkError error (about native library librxtxSerial.jnilib) when launching Arduino?

+

If you get an error like this when launching Arduino: +

+

Uncaught exception in main method: java.lang.UnsatisfiedLinkError: Native Library /Users/anu/Desktop/arduino-0002/librxtxSerial.jnilib already loaded in another classloader +

+

you probably have an old version of the communications library lying around. Search for comm.jar or jcl.jar in /System/Library/Frameworks/JavaVM.framework/ or in directories in your CLASSPATH or PATH environment variables. (reported by Anurag Sehgal) +

+

What about the error "Could not find the main class."?

+

If you get this error when launching Arduino: +

+

Java Virtual Machine Launcher: Could not find the main class. Program will exit. +

+

make sure that you correctly extracted the contents of the Arduino .zip file - in particular that the lib directory is directly inside of the Arduino directory and contains the file pde.jar. +

+

What can I do about cygwin conflicts on Windows?

+

If you already have cygwin installed on your machine, you might get an error like this when you try to compile a sketch in Arduino: +

+

6 [main] ? (3512) C:\Dev\arduino-0006\tools\avr\bin\avr-gcc.exe: *** fatal error - C:\Dev\arduino-0006\tools\avr\bin\avr-gcc.exe: *** system shared memory version mismatch detected - 0x75BE0084/0x75BE009C. +

+

This problem is probably due to using incompatible versions of the cygwin DLL. +

+

Search for cygwin1.dll using the Windows Start->Find/Search facility and delete all but the most recent version. The most recent version *should* reside in x:\cygwin\bin, where 'x' is the drive on which you have installed the cygwin distribution. Rebooting is also suggested if you are unable to find another cygwin DLL. +

+

If so, first make sure that you don't have cygwin running when you use Arduino. If that doesn't help, you can try deleting cygwin1.dll from the Arduino directory and replacing it with the cygwin1.dll from your existing cygwin install (probably in c:\cygwin\bin). +

+

Thanks to karlcswanson for the suggestion. +

+

Why does do the Arduino software and the Tools menu take a long time to open (on Windows)?

+

If the Arduino software takes a long time to start up and appears to freeze when you try to open the Tools menu, there by a conflict with another device on your system. The Arduino software, on startup and when you open the Tools menu, tries to get a list of all the COM ports on your computer. It's possible that a COM port created by one of the devices on your computer slows down this process. Take a look in the Device Manager. Try disabling the devices that provide COM ports (e.g. Bluetooth devices). +

+

+

Why doesn't my board show in the Tools | Serial Port menu ?

+

If you're using a USB Arduino board, make sure you installed the FTDI drivers (see the Howto for directions). If you're using a USB-to-Serial adapter with a serial board, make sure you installed its drivers. +

+

Make sure that the board is plugged in: the serial port menu refreshes whenever you open the Tools menu, so if you just unplugged the board, it won't be in the menu. +

+

Check that you're not running any programs that scan all serial ports, like PDA sync applications, Bluetooth-USB drivers (e.g. BlueSoleil), virtual daemon tools, etc. +

+

On Windows, the COM port assigned to the board may be too high. From zeveland: +

+

"One little note if you aren't able to export and your USB board is trying to use a high COM port number: try changing the FTDI chip's COM port assignment to a lower one. +

+

"I had a bunch of virtual COM ports set up for Bluetooth so the board was set to use COM17. The IDE wasn't able to find the board so I deleted the other virtual ports in Control Panel (on XP) and moved the FTDI's assignment down to COM2. Make sure to set Arduino to use the new port and good luck." +

+

On the Mac, if you have an old version of the FTDI drivers, you may need to remove them and reinstall the latest version. See this forum thread for directions (thanks to gck). +

+

What if I get a gnu.io.PortInUseException when uploading code or using the serial monitor (on the Mac)?

+
+Error inside Serial.<init>() 
+gnu.io.PortInUseException: Unknown Application 
+     at gnu.io.CommPortIdentifier.open(CommPortIdentifier.java:354) 
+     at processing.app.Serial.<init>(Serial.java:127) 
+     at processing.app.Serial.<init>(Serial.java:72) 
+
+
+

This probably means that the port is actually in use by another application. Please make sure that you're not running other programs that access serial or USB ports, like PDA sync application, bluetooth device managers, certain firewalls, etc. Also, note that some programs (e.g. Max/MSP) keep the serial port open even when not using it - you may to need to close any patches that use the serial port or quit the application entirely. +

+

If you get this error with Arduino 0004 or earlier, or with Processing, you'll need to run the macosx_setup.command, and then restart your computer. Arduino 0004 includes a modified version of this script that all users need to run (even those who ran the one that came with Arduino 0003). You may also need to delete the contents of the /var/spool/uucp directory. +

+

I'm having trouble with the FTDI USB drivers.

+

Try installing the latest drivers from FTDI or contacting their support at support1@ftdichip.com. +

+

+

Why doesn't my sketch start when I power up or reset the Arduino board?

+

Most likely because you are sending serial data to the board when it firsts turns on. During the first few seconds, the bootloader (a program pre-burned onto the chip on the board) listens for the computer to send it a new sketch to be uploaded to the board. After a few seconds without communication, the bootloader will time out and start the sketch that's already on the board. If you continue to send data to the bootloader, it will never time out and your sketch will never start. You'll either need to find a way to stop serial data from arriving for the first few seconds when the board powers (e.g. by enabling the chip that sends the data from within your setup() function) or burn your sketch onto the board with an external programmer, replacing the bootloader. +

+

Why does my sketch appear to upload successfully but not do anything?

+

You have selected the wrong item from the Tools > Microcontroller menu. Make sure the selected microcontroller corresponds to the one on your board (either ATmega8 or ATmega168) - the name will be written on the largest chip on the board. +

+

Check for a noisy power supply. It's possible this could cause the chip to lose its sketch. +

+

Alternatively, the sketch may be too big for the board. When uploading your sketch, Arduino 0004 checks if it's too big for the ATmega8, but it bases its calculation on a 1 Kb bootloader. You may have a older bootloader that takes up 2 Kb of the 8 Kb of program space (flash) on the ATmega8 instead of the 1 Kb used by the current bootloader. If yours is bigger, only part of the sketch will be uploaded, but the software won't know, and your board will continually reset, pause, reset. +

+

If you have access to an AVR-ISP or parallel port programmer, you can burn the latest version of the bootloader to your board with the Tools | Burn Bootloader menu item. Otherwise, you can tell the Arduino environment the amount of space available for sketches by editing the upload.maximum_size variable in your preferences file (see: instructions on finding the file). Change 7168 to 6144, and the environment should correctly warn you when your sketch is too big. +

+

+

How can I reduce the size of my sketch?

+

The ATmega168 chip on the Arduino board is cheap, but it has only 16 Kb of program code, which isn't very much (and 2 Kb is used by the bootloader). +

+

If you're using floating point, try to rewrite your code with integer math, which should save you about 2 Kb. Delete any #include statements at the top of your sketch for libraries that you're not using. +

+

Otherwise, see if you can make your program shorter. +

+

We're always working to reduce the size of the Arduino core to leave more room for your sketches. +

+

Why don't I get a PWM (an analog output) when I call analogWrite() on pins other than 3, 5, 6, 9, 10, or 11?

+

The microcontroller on the Arduino board (the ATmega168) only supports PWM/analogWrite() on certain pins. Calling analogWrite() on any other pins will give high (5 volts) for values greater than 128 and low (0 volts) for values less than 128. (Older Arduino boards with an ATmega8 only support PWM output on pins 9, 10, and 11.) +

+

Why do I get errors about undeclared functions or undeclared types?

+

The Arduino environment attempts to automatically generate prototypes for your functions, so that you can order them as you like in your sketch. This process, however, isn't perfect, and sometimes leads to obscure error messages. +

+

If you declare a custom type in your code and create a function that accepts or returns a value of that type, you'll get an error when you try to compile the sketch. This is because the automatically-generated prototype for that function will appear above the type definition. +

+

If you declare a function with a two-word return type (e.g. "unsigned int") the environment will not realize it's a function and will not create a prototype for it. That means you need to provide your own, or place the definition of the function above any calls to it. +

+

Why do I get errors about an invalid device signature when trying to upload a sketch?

+

If you get an error like: +

+

+avrdude: Yikes!  Invalid device signature.
+       Double check connections and try again, or use -F to override
+       this check.
+
+
+

it can mean one of two things. Either you have the wrong board selected from the Tools > Board menu or you're not using the right version of avrdude. Arduino uses a slightly modified version of avrdude to upload sketches to the Arduino board. The standard version queries for the board's device signature in a way not understood by the bootloader, resulting in this error. Make sure you're using the version of avrdude that comes with Arduino (source code). +

+

Guide Home +The text of the Arduino getting started guide is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the guide are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Guide_Windows.html b/arduino-0018-linux/reference/Guide_Windows.html new file mode 100644 index 0000000..5783d2b --- /dev/null +++ b/arduino-0018-linux/reference/Guide_Windows.html @@ -0,0 +1,137 @@ + + + + Arduino - Windows + + + + +
+ + + + + + +
+ +
+

How To Get Arduino Running on Windows

+

This document explains how to connect your Arduino board to the computer and upload your first sketch. +

+

These are the steps that we'll go through: +

+

  1. Get an Arduino board and cable +
  2. Download the Arduino environment +
  3. Install the USB drivers +
  4. Connect the board +
  5. Run the Arduino environment +
  6. Upload a program +
  7. Look for the blinking LED +
  8. Learn to use Arduino +

1 | Get an Arduino board and cable

+

In this tutorial, we assume you're using an Arduino Duemilanove or Diecimila. If you have another board, read the corresponding page in this getting started guide. +

+

The Arduino is a simple board that contains everything you need to start working with electronics and microcontroller programming. This diagram illustrates the major components of an Arduino Diecimila. (The Arduino Duemilanove is almost identical.) +

+

+

You also need a standard USB cable (A plug to B plug): the kind you would connect to a USB printer, for example. +

+

2 | Download the Arduino environment

+

To program the Arduino board you need the Arduino environment. +

+

Download: the latest version from the download page. +

+

When the download finishes, unzip the downloaded file. Make sure to preserve the folder structure. Double-click the folder to open it. There should be a few files and sub-folders inside. +

+

3 | Locate the USB drivers

+

If you are using a USB Arduino, you will need to install the drivers for the FTDI chip on the board. These can be found in the drivers/FTDI USB Drivers directory of the Arduino distribution. In the next step ("Connect the board"), you will point Window's Add New Hardware wizard to these drivers. +

+

The latest version of the drivers can be found on the FTDI website. +

+

4 | Connect the board

+

On the Diecimila, the power source is selected by the jumper between the USB and power plugs. To power the board from the USB port (good for controlling low power devices like LEDs), place the jumper on the two pins closest to the USB plug. To power the board from an external power supply (6-12V), place the jumper on the two pins closest to the power plug. On the Duemilanove, the power source is selected automatically (there is no power selection jumper). In any case, connect the board to a USB port on your computer. +

+

The green power LED (labelled PWR) should go on. +

+

The Add New Hardware wizard will open. Tell it not to connect to Windows update and click next. +

+

+

Then select "Install from a list or specified location (Advanced)" and click next. +

+

+

Make sure that "Search for the best driver in these locations is checked"; uncheck "Search removable media"; check "Include this location in the search" and browse to the location you unzipped the USB drivers to in the previous step. Click next. +

+

+

The wizard will search for the driver and then tell you that a "USB Serial Converter" was found. Click finish. +

+

+

The new hardware wizard will appear again. Go through the same steps. This time, a "USB Serial Port" will be found. +

+

5 | Run the Arduino environment

+

(Mac OSX): Copy the Arduino application to your Applications directory. Double-click the Arduino application. +

+

(Windows): Open the Arduino folder and double-click the Arduino application. +

+

6 | Upload a program

+

Open the LED blink example sketch: File > Sketchbook > Examples > Digital > Blink. +

+

Select the serial device of the Arduino board from the Tools | Serial Port menu. On Windows, this should be COM1 or COM2 for a serial Arduino board, or COM3, COM4, or COM5 for a USB board. To find out, open the Windows Device Mananger (in the Hardware tab of System control panel). Look for a "USB Serial Port" in the Ports section; that's the Arduino board. +

+

+

You'll need to select the entry in the Tools > Board menu that corresponds to your Arduino. For newer Arduino boards with an ATmega328 (check the text on the chip on the board), select Arduino Duemilanove w/ ATmega328. Previously, Arduino boards came with an ATmega168; for those, select Arduino Diecimila or Duemilanove w/ ATmega168. +

+

Now, simply click the "Upload" button in the environment. Wait a few seconds - you should see the RX and TX leds on the board flashing. If the upload is successful, the message "Done uploading." will appear in the status bar. (Note: If you have an Arduino Mini, NG, or other board, you'll need to physically present the reset button on the board immediately before pressing the upload button.) +

+

+

7 | Look for the blinking LED

+

A few seconds after the upload finishes, you should see the pin 13 (L) LED on the board start to blink (in orange). If it does, congratulations! You've gotten Arduino up-and-running. +

+

If you have problems, please see the troubleshooting suggestions. +

+

8 | Learn to use Arduino

+
  • Examples: try these example programs. +
  • Reference: read the reference for the Arduino language. +

The text of the Arduino getting started guide is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the guide are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Guide_index.html b/arduino-0018-linux/reference/Guide_index.html new file mode 100644 index 0000000..a6b9a5c --- /dev/null +++ b/arduino-0018-linux/reference/Guide_index.html @@ -0,0 +1,86 @@ + + + + Arduino - Getting Started + + + + +
+ + + + + + +
+ +
+

Getting Started with Arduino

+

+

Introduction: What Arduino is and why you'd want to use it. +

+

Installation: Step-by-step instructions for setting up the Arduino software and connecting it to an Arduino Duemilanove. +

+

Environment: Description of the Arduino development environment. +

+

Troubleshooting: Advice on what to do if things don't work. +

+

+

Instructions for other boards: +

+

+

The text of the Arduino getting started guide is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the guide are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/HighByte.html b/arduino-0018-linux/reference/HighByte.html new file mode 100644 index 0000000..6be009e --- /dev/null +++ b/arduino-0018-linux/reference/HighByte.html @@ -0,0 +1,83 @@ + + + + Arduino - HighByte + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

highByte()

+

Description

+

Extracts the high-order (leftmost) byte of a word (or the second lowest byte of a larger data type). +

+

Syntax

+

highByte(x) +

+

Parameters

+

x: a value of any type +

+

Returns

+

byte +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/HomePage.html b/arduino-0018-linux/reference/HomePage.html new file mode 100644 index 0000000..459418b --- /dev/null +++ b/arduino-0018-linux/reference/HomePage.html @@ -0,0 +1,192 @@ + + + + Arduino - Reference + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison +

+

Arduino Reference

+

See the extended reference for more advanced features of the Arduino languages. +

+

Arduino programs can be divided in three main parts: structure, values (variables and constants), and functions. The Arduino language is based on C/C++. +

+

+
+

Structure

+

An Arduino program run in two parts: +

+

setup() is preparation, and loop() is execution. In the setup section, always at the top of your program, you would set pinModes, initialize serial communication, etc. The loop section is the code to be executed -- reading inputs, triggering outputs, etc. +

+

Control Structures

+

Further Syntax

+
  • ; (semicolon) +
  • {} (curly braces) +
  • // (single line comment) +
  • /* */ (multi-line comment) +

Arithmetic Operators

+
  • plus (addition) +
  • - (subtraction) +
  • * (multiplication) +
  • / (division) +
  • % (modulo) +

Comparison Operators

+
  • == (equal to) +
  • != (not equal to) +
  • < (less than) +
  • > (greater than) +
  • <= (less than or equal to) +
  • >= (greater than or equal to) +

Boolean Operators

+
  • && (and) +
  • || (or) +
  • ! (not) +

Compound Operators

+
  • ++ (increment) +
  • -- (decrement) +
  • += (compound addition) +
  • -= (compound subtraction) +
  • *= (compound multiplication) +
  • /= (compound division) +

Variables

+

Variables are expressions that you can use in programs to store values, such as a sensor reading from an analog pin. +

+

Constants

+

Constants are particular values with specific meanings. +

+

Data Types

+

Variables can have various types, which are described below. +

+

Reference

+

+

Functions

+

Digital I/O +

Analog I/O +

Advanced I/O +

  • shiftOut(dataPin, clockPin, bitOrder, value) +
  • unsigned long pulseIn(pin, value) +

Time +

Math +

Random Numbers +

+

Serial Communication +

+

Used for communication between the Arduino board and a computer or other devices. This communication happens via the Arduino board's serial or USB connection and on digital pins 0 (RX) and 1 (TX). Thus, if you use these functions, you cannot also use pins 0 and 1 for digital i/o. +

+


+

+

Didn't find something? Check the extended reference. +

+

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/If.html b/arduino-0018-linux/reference/If.html new file mode 100644 index 0000000..1401427 --- /dev/null +++ b/arduino-0018-linux/reference/If.html @@ -0,0 +1,110 @@ + + + + Arduino - If + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

if (conditional) and ==, !=, <, > (comparison operators)

+

if, which is used in conjunction with a comparison operator, tests whether a certain condition has been reached, such as an input being above a certain number. The format for an if test is: +

+

if (someVariable > 50)
+{
+  // do something here
+}
+
+

The program tests to see if someVariable is greater than 50. If it is, the program takes a particular action. Put another way, if the statement in parentheses is true, the statements inside the brackets are run. If not, the program skips over the code. +

+

The brackets may be omitted after an if statement. If this is done, the next line (defined by the semicolon) becomes the only conditional statement. +

+
+if (x > 120) digitalWrite(LEDpin, HIGH); 
+
+if (x > 120)
+digitalWrite(LEDpin, HIGH); 
+
+if (x > 120){ digitalWrite(LEDpin, HIGH); } 
+
+if (x > 120){ 
+  digitalWrite(LEDpin1, HIGH);
+  digitalWrite(LEDpin2, HIGH); 
+}                                 // all are correct
+
+
+

The statements being evaluated inside the parentheses require the use of one or more operators: +

+

Comparison Operators:

+
 x == y (x is equal to y)
+ x != y (x is not equal to y)
+ x <  y (x is less than y)  
+ x >  y (x is greater than y) 
+ x <= y (x is less than or equal to y) 
+ x >= y (x is greater than or equal to y)
+
+

Warning:

+

Beware of accidentally using the single equal sign (e.g. if (x = 10) ). The single equal sign is the assignment operator, and sets x to 10 (puts the value 10 into the variable x). Instead use the double equal sign (e.g. if (x == 10) ), which is the comparison operator, and tests whether x is equal to 10 or not. The latter statement is only true if x equals 10, but the former statement will always be true. +

+

This is because C evaluates the statement if (x=10) as follows: 10 is assigned to x (remember that the single equal sign is the assignment operator), so x now contains 10. Then the 'if' conditional evaluates 10, which always evaluates to TRUE, since any non-zero number evaluates to TRUE. Consequently, if (x = 10) will always evaluate to TRUE, which is not the desired result when using an 'if' statement. Additionally, the variable x will be set to 10, which is also not a desired action. +

+

if can also be part of a branching control structure using the if...else] construction. +

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Include.html b/arduino-0018-linux/reference/Include.html new file mode 100644 index 0000000..7a60fa8 --- /dev/null +++ b/arduino-0018-linux/reference/Include.html @@ -0,0 +1,84 @@ + + + + Arduino - Include + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

#include

+

#include is used to include outside libraries in your sketch. This gives the programmer access to a large group of standard C libraries (groups of pre-made functions), and also libraries written especially for Arduino. +

+

The main reference page for AVR C libraries (AVR is a reference to the Atmel chips on which the Arduino is based) is here. +

+

Note that #include, similar to #define, has no semicolon terminator, and the compiler will yield cryptic error messages if you add one. +

+

Example

+

This example includes a library that is used to put data into the program space flash instead of ram. This saves the ram space for dynamic memory needs and makes large lookup tables more practical. +

+

+#include <avr/pgmspace.h>
+
+prog_uint16_t myConstants[] PROGMEM = {0, 21140, 702  , 9128,  0, 25764, 8456,
+0,0,0,0,0,0,0,0,29810,8968,29762,29762,4500};
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Increment.html b/arduino-0018-linux/reference/Increment.html new file mode 100644 index 0000000..e3cefd2 --- /dev/null +++ b/arduino-0018-linux/reference/Increment.html @@ -0,0 +1,93 @@ + + + + Arduino - Increment + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

++ (increment) / -- (decrement)

+

Description

+

Increment or decrement a variable +

+

Syntax

+
+x++;  // increment x by one and returns the old value of x
+++x;  // increment x by one and returns the new value of x
+
+x-- ;   // decrement x by one and returns the old value of x 
+--x ;   // decrement x by one and returns the new value of x  
+
+

Parameters

+

x: an integer or long (possibly unsigned) +

+

Returns

+

The original or newly incremented / decremented value of the variable. +

+

Examples

+
x = 2;
+y = ++x;      // x now contains 3, y contains 3
+y = x--;      // x contains 2 again, y still contains 3 
+
+

See also

+

+=
-= +

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/IncrementCompound.html b/arduino-0018-linux/reference/IncrementCompound.html new file mode 100644 index 0000000..d99177a --- /dev/null +++ b/arduino-0018-linux/reference/IncrementCompound.html @@ -0,0 +1,92 @@ + + + + Arduino - IncrementCompound + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

+= , -= , *= , /=

+

Description

+

Perform a mathematical operation on a variable with another constant or variable. The += (et al) operators are just a convenient shorthand for the expanded syntax, listed below. +

+

Syntax

+
+x += y;   // equivalent to the expression x = x + y;
+x -= y;   // equivalent to the expression x = x - y; 
+x *= y;   // equivalent to the expression x = x * y; 
+x /= y;   // equivalent to the expression x = x / y; 
+
+
+

Parameters

+

x: any variable type +

+

y: any variable type or constant +

+

Examples

+
x = 2;
+x += 4;      // x now contains 6
+x -= 3;      // x now contains 3
+x *= 10;     // x now contains 30
+x /= 2;      // x now contains 15
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Int.html b/arduino-0018-linux/reference/Int.html new file mode 100644 index 0000000..be3a5f8 --- /dev/null +++ b/arduino-0018-linux/reference/Int.html @@ -0,0 +1,101 @@ + + + + Arduino - Int + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

int

+

Description

+

Integers are your primary datatype for number storage, and store a 2 byte value. This yields a range of -32,768 to 32,767 (minimum value of -2^15 and a maximum value of (2^15) - 1). +

+

Int's store negative numbers with a technique called 2's complement math. The highest bit, sometimes refered to as the "sign" bit, flags the number as a negative number. The rest of the bits are inverted and 1 is added. +

+

The Arduino takes care of dealing with negative numbers for you, so that arithmetic operations work transparently in the expected manner. There can be an unexpected complication in dealing with the bitshift right operator (>>) however. +

+

Example

+
    int ledPin = 13;
+
+

Syntax

+
    int var = val;
+
+

  • var - your int variable name +
  • val - the value you assign to that variable +

Coding Tip

+

When variables are made to exceed their maximum capacity they "roll over" back to their minimum capacitiy, note that this happens in both directions. +

+

   int x
+   x = -32,768;
+   x = x - 1;       // x now contains 32,767 - rolls over in neg. direction
+
+   x = 32,767;
+   x = x + 1;       // x now contains -32,768 - rolls over
+
+
+

See Also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/IntCast.html b/arduino-0018-linux/reference/IntCast.html new file mode 100644 index 0000000..2f062cb --- /dev/null +++ b/arduino-0018-linux/reference/IntCast.html @@ -0,0 +1,82 @@ + + + + Arduino - IntCast + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

int()

+

Description

+

Converts a value to the int data type. +

+

Syntax

+

int(x) +

+

Parameters

+

x: a value of any type +

+

Returns

+

int +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/IntegerConstants.html b/arduino-0018-linux/reference/IntegerConstants.html new file mode 100644 index 0000000..48b9c0f --- /dev/null +++ b/arduino-0018-linux/reference/IntegerConstants.html @@ -0,0 +1,133 @@ + + + + Arduino - IntegerConstants + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Integer Constants

+

Integer constants are numbers used directly in a sketch, like 123. By default, these numbers are treated as int's but you can change this with the U and L modifiers (see below). +

+

Normally, integer constants are treated as base 10 (decimal) integers, but special notation (formatters) may be used to enter numbers in other bases. +

+

+Base               Example    Formatter        Comment
+
+10 (decimal)           123    none
+
+2 (binary)        B1111011    leading 'B'      only works with 8 bit values (0 to 255)
+                                               characters 0-1 valid
+
+8 (octal)             0173    leading "0"      characters 0-7 valid       
+
+16 (hexadecimal)      0x7B    leading "0x"     characters 0-9, A-F, a-f valid    
+
+
+

Decimal is base 10. This is the common-sense math with which you are acquainted. Constants without other prefixes are assumed to be in decimal format. +

+

Example:
+101     // same as 101 decimal   ((1 * 10^2) + (0 * 10^1) + 1)
+
+


+Binary is base two. Only characters 0 and 1 are valid. +

+

Example:
+B101    // same as 5 decimal   ((1 * 2^2) + (0 * 2^1) + 1)
+
+

The binary formatter only works on bytes (8 bits) between 0 (B0) and 255 (B11111111). If it is convenient to input an int (16 bits) in binary form you can do it a two-step procedure such as: +

+

+myInt = (B11001100 * 256) + B10101010;    // B11001100 is the high byte
+
+
+

Octal is base eight. Only characters 0 through 7 are valid. Octal values are indicated by the prefix "0" +

+

Example: +

+0101    // same as 65 decimal   ((1 * 8^2) + (0 * 8^1) + 1) 
+
Warning +
It is possible to generate a hard-to-find bug by (unintentionally) including a leading zero before a constant and having the compiler unintentionally interpret your constant as octal. +


+Hexadecimal (or hex) is base sixteen. Valid characters are 0 through 9 and letters A through F; A has the value 10, B is 11, up to F, which is 15. Hex values are indicated by the prefix "0x". Note that A-F may be syted in upper or lower case (a-f). +

+

Example: +

+0x101   // same as 257 decimal   ((1 * 16^2) + (0 * 16^1) + 1)
+
+
+

U & L formatters

+

By default, an integer constant is treated as an int with the attendant limitations in values. To specify an integer constant with another data type, follow it with: +

+

  • a 'u' or 'U' to force the constant into an unsigned data format. Example: 33u +
  • a 'l' or 'L' to force the constant into a long data format. Example: 100000L +
  • a 'ul' or 'UL' to force the constant into an unsigned long constant. Example: 32767ul +


+

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Interrupts.html b/arduino-0018-linux/reference/Interrupts.html new file mode 100644 index 0000000..e331d98 --- /dev/null +++ b/arduino-0018-linux/reference/Interrupts.html @@ -0,0 +1,94 @@ + + + + Arduino - Interrupts + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

interrupts()

+

Description

+

Re-enables interrupts (after they've been disabled by noInterrupts()). Interrupts allow certain important tasks to happen in the background and are enabled by default. Some functions will not work while interrupts are disabled, and incoming communication may be ignored. Interrupts can slightly disrupt the timing of code, however, and may be disabled for particularly critical sections of code. +

+

Parameters

+

None +

+

Returns

+

None +

+

Example

+
+void setup() {}
+
+void loop()
+{
+  noInterrupts();
+  // critical, time-sensitive code here
+  interrupts();
+  // other code here
+}
+
+
+

See Also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Keywords.html b/arduino-0018-linux/reference/Keywords.html new file mode 100644 index 0000000..a529407 --- /dev/null +++ b/arduino-0018-linux/reference/Keywords.html @@ -0,0 +1,275 @@ + + + + Arduino - Keywords + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Board +

+

Keywords

+

Keywords are constants, variables and function names that are defined as part of the Arduino language. Avoid using keywords for variable names. +

+

+
+
+# Constants
+
+HIGH	
+LOW	
+INPUT	
+OUTPUT	
+SERIAL	
+DISPLAY	
+PI	
+HALF_PI	
+TWO_PI	
+LSBFIRST	
+MSBFIRST	
+CHANGE	
+FALLING	
+RISING	
+false		
+true		
+null	
+
+# Port Variables & Constants
+
+DDRB
+PINB
+PORTB
+PB0
+PB1
+PB2
+PB3
+PB4
+PB5
+PB6
+PB7
+
+DDRC
+PINC
+PORTC
+PC0
+PC1
+PC2
+PC3
+PC4
+PC5
+PC6
+PC7
+
+DDRD
+PIND
+PORTD
+PD0
+PD1
+PD2
+PD3
+PD4
+PD5
+PD6
+PD7
+
+# Datatypes
+
+boolean	
+byte	
+char	
+class		
+default		
+do		
+double		
+int	
+long	
+
+
+
+private		
+protected		
+public		
+return		
+short		
+signed	
+static		
+switch		
+throw		
+try		
+unsigned	
+void		
+
+# Other
+
+abs
+acos
++=
++
+[]
+asin
+=
+atan
+atan2
+&
+|
+boolean
+byte
+case
+ceil
+char
+char
+class
+,
+//
+?:
+constrain
+cos
+{}
+--
+default
+delay
+delayMicroseconds
+/
+/**
+. 
+else
+==
+exp
+false
+float
+float
+floor
+for
+<
+<=
+HALF_PI
+if
+++
+!=
+int
+<<
+<
+<=
+log
+&&
+!
+||
+
+
+
+

+

+
+loop
+max
+millis
+min
+-
+%
+/*
+*
+new
+null
+()
+PI
+return
+>>
+;
+Serial	
+Setup
+sin
+sq
+sqrt
+-=
+switch
+tan
+this
+true
+TWO_PI
+void
+while
+Serial	
+begin	
+read
+print
+write
+println
+available
+digitalWrite	
+digitalRead
+pinMode
+analogRead
+analogWrite
+attachInterrupts
+detachInterrupts
+beginSerial
+serialWrite
+serialRead
+serialAvailable
+printString
+printInteger
+printByte
+printHex
+printOctal
+printBinary
+printNewline
+pulseIn
+shiftOut
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Libraries.html b/arduino-0018-linux/reference/Libraries.html new file mode 100644 index 0000000..f1d112d --- /dev/null +++ b/arduino-0018-linux/reference/Libraries.html @@ -0,0 +1,120 @@ + + + + Arduino - Libraries + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Libraries

+

To use a library in a sketch, select it from Sketch > Import Library. For details, see the page on the Arduino environment. +

+

Standard Libraries

+
  • EEPROM - reading and writing to "permanent" storage +
  • Ethernet - for connecting to the internet using the Arduino Ethernet Shield +
  • Firmata - for communicating with applications on the computer using a standard serial protocol. +
  • LiquidCrystal - for controlling liquid crystal displays (LCDs) +
  • Servo - for controlling servo motors +
  • SoftwareSerial - for serial communication on any digital pins +
  • Stepper - for controlling stepper motors +
  • Wire - Two Wire Interface (TWI/I2C) for sending and receiving data over a net of devices or sensors. +

These libraries are compatible Wiring versions, and the links below point to the (excellent) Wiring documentation. +

+

  • Matrix - Basic LED Matrix display manipulation library +
  • Sprite - Basic image sprite manipulation library for use in animations with an LED matrix +

Contributed Libraries

+

To install a contributed library, unzip it to the libraries sub-folder of your sketchbook. For details, see the page on the Arduino environment. +

+

Communication (networking and protocols): +

  • Messenger - for processing text-based messages from the computer +
  • NewSoftSerial - an improved version of the SoftwareSerial library +
  • OneWire - control devices (from Dallas Semiconductor) that use the One Wire protocol. +
  • PS2Keyboard - read characters from a PS2 keyboard. +
  • Simple Message System - send messages between Arduino and the computer +
  • SSerial2Mobile - send text messages or emails using a cell phone (via AT commands over software serial) +
  • Webduino - extensible web server library (for use with the Arduino Ethernet Shield) +
  • X10 - Sending X10 signals over AC power lines +
  • XBee - for communicating with XBees in API mode +
  • SerialControl - Remote control other Arduinos over a serial connection +

Sensing: +

  • Capacitive Sensing - turn two or more pins into capacitive sensors +
  • Debounce - for reading noisy digital inputs (e.g. from buttons) +

Displays and LEDs: +

  • Improved LCD library fixes LCD initialization bugs in official Arduino LCD library +
  • GLCD - graphics routines for LCD based on the KS0108 or equivalent chipset. +
  • LedControl - for controlling LED matrices or seven-segment displays with a MAX7221 or MAX7219. +
  • LedControl - an alternative to the Matrix library for driving multiple LEDs with Maxim chips. +
  • LedDisplay - control of a HCMS-29xx scrolling LED display. +

Frequency Generation and Audio: +

  • Tone - generate audio frequency square waves in the background on any microcontroller pin +

Motors and PWM: +

  • TLC5940 - 16 channel 12 bit PWM controller. +

Timing: +

  • DateTime - a library for keeping track of the current date and time in software. +
  • Metro - help you time actions at regular intervals +
  • MsTimer2 - uses the timer 2 interrupt to trigger an action every N milliseconds. +

Utilities: +

For a guide to writing your own libraries, see this tutorial. +

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/LiquidCrystal.html b/arduino-0018-linux/reference/LiquidCrystal.html new file mode 100644 index 0000000..6589f59 --- /dev/null +++ b/arduino-0018-linux/reference/LiquidCrystal.html @@ -0,0 +1,101 @@ + + + + Arduino - LiquidCrystal + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

LiquidCrystal Library

+

This library allows an Arduino board to control LiquidCrystal displays (LCDs) based on the Hitachi HD44780 (or a compatible) chipset, which is found on most text-based LCDs. The library works with in either 4- or 8-bit mode (i.e. using 4 or 8 data lines in addition to the rs, enable, and, optionally, the rw control lines). +

+

Function

+

Examples +

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/LiquidCrystalAutoscroll.html b/arduino-0018-linux/reference/LiquidCrystalAutoscroll.html new file mode 100644 index 0000000..e85adad --- /dev/null +++ b/arduino-0018-linux/reference/LiquidCrystalAutoscroll.html @@ -0,0 +1,81 @@ + + + + Arduino - LiquidCrystalAutoscroll + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

LiquidCrystal +

+

autoscroll()

+

Description

+

Turns on automatic scrolling of the LCD. This causes each character output to the display to push previous characters over by one space. If the current text direction is left-to-right (the default), the display scrolls to the left; if the current direction is right-to-left, the display scrolls to the right. This has the effect of outputting each new character to the same location on the LCD. +

+

Syntax

+

lcd.autoscroll() +

+

Parameters

+

lcd: a variable of type LiquidCrystal +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/LiquidCrystalBegin.html b/arduino-0018-linux/reference/LiquidCrystalBegin.html new file mode 100644 index 0000000..0f79234 --- /dev/null +++ b/arduino-0018-linux/reference/LiquidCrystalBegin.html @@ -0,0 +1,83 @@ + + + + Arduino - LiquidCrystalBegin + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

LiquidCrystal +

+

begin()

+

Description

+

Specifies the dimensions (width and height) of the display. +

+

Syntax

+

lcd.begin(cols, rows) +

+

Parameters

+

lcd: a variable of type LiquidCrystal +

+

cols: the number of columns that the display has +

+

rows: the number of rows that the display has +

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/LiquidCrystalBlink.html b/arduino-0018-linux/reference/LiquidCrystalBlink.html new file mode 100644 index 0000000..067dd29 --- /dev/null +++ b/arduino-0018-linux/reference/LiquidCrystalBlink.html @@ -0,0 +1,84 @@ + + + + Arduino - LiquidCrystalBlink + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

LiquidCrystal +

+

blink()

+

Description

+

Display the blinking LCD cursor. If used in combination with the cursor() function, the result will depend on the particular display. +

+

Syntax

+

lcd.blink() +

+

Parameters

+

lcd: a variable of type LiquidCrystal +

+

Example

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/LiquidCrystalClear.html b/arduino-0018-linux/reference/LiquidCrystalClear.html new file mode 100644 index 0000000..8091c68 --- /dev/null +++ b/arduino-0018-linux/reference/LiquidCrystalClear.html @@ -0,0 +1,79 @@ + + + + Arduino - LiquidCrystalClear + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

LiquidCrystal +

+

clear()

+

Description

+

Clears the LCD screen and positions the cursor in the upper-left corner. +

+

Syntax

+

lcd.clear() +

+

Parameters

+

lcd: a variable of type LiquidCrystal +

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/LiquidCrystalConstructor.html b/arduino-0018-linux/reference/LiquidCrystalConstructor.html new file mode 100644 index 0000000..3dfb225 --- /dev/null +++ b/arduino-0018-linux/reference/LiquidCrystalConstructor.html @@ -0,0 +1,99 @@ + + + + Arduino - LiquidCrystalConstructor + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

LiquidCrystal +

+

LiquidCrystal()

+

Description

+

Creates a variable of type LiquidCrystal. The display can be controlled using 4 or 8 data lines. If the former, omit the pin numbers for d0 to d3 and leave those lines unconnected. The RW pin can be tied to ground instead of connected to a pin on the Arduino; if so, omit it from this function's parameters. +

+

Syntax

+

LiquidCrystal(rs, enable, d4, d5, d6, d7)
LiquidCrystal(rs, rw, enable, d4, d5, d6, d7)
LiquidCrystal(rs, enable, d0, d1, d2, d3, d4, d5, d6, d7)
LiquidCrystal(rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7) +

+

Parameters

+

rs: the number of the Arduino pin that is connected to the RS pin on the LCD +

+

rw: the number of the Arduino pin that is connected to the RW pin on the LCD (optional) +

+

enable: the number of the Arduino pin that is connected to the enable pin on the LCD +

+

d0, d1, d2, d3, d4, d5, d6, d7: the numbers of the Arduino pins that are connected to the corresponding data pins on the LCD. d0, d1, d2, and d3 are optional; if omitted, the LCD will be controlled using only the four data lines (d4, d5, d6, d7). +

+

Example

+
+#include <LiquidCrystal.h>
+
+LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
+
+void setup()
+{
+  lcd.print("hello, world!");
+}
+
+void loop() {}
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/LiquidCrystalCreateChar.html b/arduino-0018-linux/reference/LiquidCrystalCreateChar.html new file mode 100644 index 0000000..5172a75 --- /dev/null +++ b/arduino-0018-linux/reference/LiquidCrystalCreateChar.html @@ -0,0 +1,110 @@ + + + + Arduino - LiquidCrystalCreateChar + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

LiquidCrystal +

+

createChar()

+

Description

+

Create a custom character (gylph) for use on the LCD. Up to eight characters of 5x8 pixels are supported (numbered 0 to 7). The appearance of each custom character is specified by an array of eight bytes, one for each row. The five least significant bits of each byte determine the pixels in that row. To display a custom character on the screen, write() its number. +

+

Syntax

+

lcd.createChar(num, data) +

+

Parameters

+

lcd: a variable of type LiquidCrystal +

+

num: which character to create (0 to 7) +

+

data: the character's pixel data +

+

Example

+
+
+#include <LiquidCrystal.h>
+
+LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
+
+byte smiley[8] = {
+  B00000,
+  B10001,
+  B00000,
+  B00000,
+  B10001,
+  B01110,
+  B00000,
+};
+
+void setup() {
+  lcd.createChar(0, smiley);
+  lcd.begin(16, 2);  
+  lcd.write(0);
+}
+
+void loop() {}
+
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/LiquidCrystalCursor.html b/arduino-0018-linux/reference/LiquidCrystalCursor.html new file mode 100644 index 0000000..992922b --- /dev/null +++ b/arduino-0018-linux/reference/LiquidCrystalCursor.html @@ -0,0 +1,83 @@ + + + + Arduino - LiquidCrystalCursor + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

LiquidCrystal +

+

cursor()

+

Description

+

Display the LCD cursor: an underscore (line) at the position to which the next character will be written. +

+

Syntax

+

lcd.cursor() +

+

Parameters

+

lcd: a variable of type LiquidCrystal +

+

Example

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/LiquidCrystalDisplay.html b/arduino-0018-linux/reference/LiquidCrystalDisplay.html new file mode 100644 index 0000000..80ad657 --- /dev/null +++ b/arduino-0018-linux/reference/LiquidCrystalDisplay.html @@ -0,0 +1,83 @@ + + + + Arduino - LiquidCrystalDisplay + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

LiquidCrystal +

+

display()

+

Description

+

Turns on the LCD display, after it's been turned off with noDisplay(). This will restore the text (and cursor) that was on the display. +

+

Syntax

+

lcd.display() +

+

Parameters

+

lcd: a variable of type LiquidCrystal +

+

Example

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/LiquidCrystalHome.html b/arduino-0018-linux/reference/LiquidCrystalHome.html new file mode 100644 index 0000000..0108a6e --- /dev/null +++ b/arduino-0018-linux/reference/LiquidCrystalHome.html @@ -0,0 +1,79 @@ + + + + Arduino - LiquidCrystalHome + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

LiquidCrystal +

+

home()

+

Description

+

Positions the cursor in the upper-left of the LCD. That is, use that location in outputting subsequent text to the display. To also clear the display, use the clear() function instead. +

+

Syntax

+

lcd.home() +

+

Parameters

+

lcd: a variable of type LiquidCrystal +

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/LiquidCrystalLeftToRight.html b/arduino-0018-linux/reference/LiquidCrystalLeftToRight.html new file mode 100644 index 0000000..a89161f --- /dev/null +++ b/arduino-0018-linux/reference/LiquidCrystalLeftToRight.html @@ -0,0 +1,81 @@ + + + + Arduino - LiquidCrystalLeftToRight + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

LiquidCrystal +

+

leftToRight()

+

Description

+

Set the direction for text written to the LCD to left-to-right, the default. This means that subsequent characters written to the display will go from left to right, but does not affect previously-output text. +

+

Syntax

+

lcd.leftTorRight() +

+

Parameters

+

lcd: a variable of type LiquidCrystal +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/LiquidCrystalNoAutoscroll.html b/arduino-0018-linux/reference/LiquidCrystalNoAutoscroll.html new file mode 100644 index 0000000..55678d1 --- /dev/null +++ b/arduino-0018-linux/reference/LiquidCrystalNoAutoscroll.html @@ -0,0 +1,81 @@ + + + + Arduino - LiquidCrystalNoAutoscroll + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

LiquidCrystal +

+

noAutoscroll()

+

Description

+

Turns off automatic scrolling of the LCD. +

+

Syntax

+

lcd.noAutoscroll() +

+

Parameters

+

lcd: a variable of type LiquidCrystal +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/LiquidCrystalNoBlink.html b/arduino-0018-linux/reference/LiquidCrystalNoBlink.html new file mode 100644 index 0000000..11488b5 --- /dev/null +++ b/arduino-0018-linux/reference/LiquidCrystalNoBlink.html @@ -0,0 +1,83 @@ + + + + Arduino - LiquidCrystalNoBlink + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

LiquidCrystal +

+

noBlink()

+

Description

+

Turns off the blinking LCD cursor. +

+

Syntax

+

lcd.noBlink() +

+

Parameters

+

lcd: a variable of type LiquidCrystal +

+

Example

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/LiquidCrystalNoCursor.html b/arduino-0018-linux/reference/LiquidCrystalNoCursor.html new file mode 100644 index 0000000..f3ca96b --- /dev/null +++ b/arduino-0018-linux/reference/LiquidCrystalNoCursor.html @@ -0,0 +1,83 @@ + + + + Arduino - LiquidCrystalNoCursor + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

LiquidCrystal +

+

noCursor()

+

Description

+

Hides the LCD cursor. +

+

Syntax

+

lcd.noCursor() +

+

Parameters

+

lcd: a variable of type LiquidCrystal +

+

Example

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/LiquidCrystalNoDisplay.html b/arduino-0018-linux/reference/LiquidCrystalNoDisplay.html new file mode 100644 index 0000000..31779fd --- /dev/null +++ b/arduino-0018-linux/reference/LiquidCrystalNoDisplay.html @@ -0,0 +1,83 @@ + + + + Arduino - LiquidCrystalNoDisplay + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

LiquidCrystal +

+

noDisplay()

+

Description

+

Turns off the LCD display, without losing the text currently shown on it. +

+

Syntax

+

lcd.noDisplay() +

+

Parameters

+

lcd: a variable of type LiquidCrystal +

+

Example

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/LiquidCrystalPrint.html b/arduino-0018-linux/reference/LiquidCrystalPrint.html new file mode 100644 index 0000000..d8c5b01 --- /dev/null +++ b/arduino-0018-linux/reference/LiquidCrystalPrint.html @@ -0,0 +1,97 @@ + + + + Arduino - LiquidCrystalPrint + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

LiquidCrystal +

+

print()

+

Description

+

Prints text to the LCD. +

+

Syntax

+

lcd.print(data)
lcd.print(data, BASE) +

+

Parameters

+

lcd: a variable of type LiquidCrystal +

+

data: the data to print (char, byte, int, long, or string) +

+

BASE (optional): the base in which to print numbers: BIN for binary (base 2), DEC for decimal (base 10), OCT for octal (base 8), HEX for hexadecimal (base 16). +

+

Example

+
+#include <LiquidCrystal.h>
+
+LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
+
+void setup()
+{
+  lcd.print("hello, world!");
+}
+
+void loop() {}
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/LiquidCrystalRightToLeft.html b/arduino-0018-linux/reference/LiquidCrystalRightToLeft.html new file mode 100644 index 0000000..21bfea9 --- /dev/null +++ b/arduino-0018-linux/reference/LiquidCrystalRightToLeft.html @@ -0,0 +1,81 @@ + + + + Arduino - LiquidCrystalRightToLeft + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

LiquidCrystal +

+

rightToLeft()

+

Description

+

Set the direction for text written to the LCD to right-to-left (the default is left-to-right). This means that subsequent characters written to the display will go from right to left, but does not affect previously-output text. +

+

Syntax

+

lcd.rightToLeft() +

+

Parameters

+

lcd: a variable of type LiquidCrystal +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/LiquidCrystalScrollDisplayLeft.html b/arduino-0018-linux/reference/LiquidCrystalScrollDisplayLeft.html new file mode 100644 index 0000000..58dc3a3 --- /dev/null +++ b/arduino-0018-linux/reference/LiquidCrystalScrollDisplayLeft.html @@ -0,0 +1,83 @@ + + + + Arduino - LiquidCrystalScrollDisplayLeft + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

LiquidCrystal +

+

scrollDisplayLeft()

+

Description

+

Scrolls the contents of the display (text and cursor) one space to the left. +

+

Syntax

+

lcd.scrollDisplayLeft() +

+

Parameters

+

lcd: a variable of type LiquidCrystal +

+

Example

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/LiquidCrystalScrollDisplayRight.html b/arduino-0018-linux/reference/LiquidCrystalScrollDisplayRight.html new file mode 100644 index 0000000..d908eb2 --- /dev/null +++ b/arduino-0018-linux/reference/LiquidCrystalScrollDisplayRight.html @@ -0,0 +1,83 @@ + + + + Arduino - LiquidCrystalScrollDisplayRight + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

LiquidCrystal +

+

scrollDisplayRight()

+

Description

+

Scrolls the contents of the display (text and cursor) one space to the right. +

+

Syntax

+

lcd.scrollDisplayRight() +

+

Parameters

+

lcd: a variable of type LiquidCrystal +

+

Example

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/LiquidCrystalSetCursor.html b/arduino-0018-linux/reference/LiquidCrystalSetCursor.html new file mode 100644 index 0000000..41da461 --- /dev/null +++ b/arduino-0018-linux/reference/LiquidCrystalSetCursor.html @@ -0,0 +1,83 @@ + + + + Arduino - LiquidCrystalSetCursor + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

LiquidCrystal +

+

setCursor()

+

Description

+

Position the LCD cursor; that is, set the location at which subsequent text written to the LCD will be displayed. +

+

Syntax

+

lcd.setCursor(col, row) +

+

Parameters

+

lcd: a variable of type LiquidCrystal +

+

col: the column at which to position the cursor (with 0 being the first column) +

+

row: the row at which to position the cursor (with 0 being the first row) +

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/LiquidCrystalWrite.html b/arduino-0018-linux/reference/LiquidCrystalWrite.html new file mode 100644 index 0000000..9dc32f2 --- /dev/null +++ b/arduino-0018-linux/reference/LiquidCrystalWrite.html @@ -0,0 +1,100 @@ + + + + Arduino - LiquidCrystalWrite + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

LiquidCrystal +

+

write()

+

Description

+

Write a character to the LCD. +

+

Syntax

+

lcd.write(data) +

+

Parameters

+

lcd: a variable of type LiquidCrystal +

+

data: the character to write to the display +

+

Example

+
+#include <LiquidCrystal.h>
+
+LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
+
+void setup()
+{
+  Serial.begin(9600);
+}
+
+void loop()
+{
+  if (Serial.available()) {
+    lcd.write(Serial.read());
+  }
+}
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Long.html b/arduino-0018-linux/reference/Long.html new file mode 100644 index 0000000..4ea9d85 --- /dev/null +++ b/arduino-0018-linux/reference/Long.html @@ -0,0 +1,87 @@ + + + + Arduino - Long + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

long

+

Description

+

Long variables are extended size variables for number storage, and store 32 bits (4 bytes), from -2,147,483,648 to 2,147,483,647. +

+

Example

+

    long speedOfLight = 186000L;   // see Integer Constants for explanation of the 'L'
+
+
+

Syntax

+
    long var = val;
+
+

  • var - the long variable name +
  • val - the value assigned to the variable +

See Also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/LongCast.html b/arduino-0018-linux/reference/LongCast.html new file mode 100644 index 0000000..7cb4131 --- /dev/null +++ b/arduino-0018-linux/reference/LongCast.html @@ -0,0 +1,82 @@ + + + + Arduino - LongCast + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

long()

+

Description

+

Converts a value to the long data type. +

+

Syntax

+

long(x) +

+

Parameters

+

x: a value of any type +

+

Returns

+

long +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Loop.html b/arduino-0018-linux/reference/Loop.html new file mode 100644 index 0000000..b78358d --- /dev/null +++ b/arduino-0018-linux/reference/Loop.html @@ -0,0 +1,94 @@ + + + + Arduino - Loop + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

loop()

+

After creating a setup() function, which initializes and sets the initial values, the loop() function does precisely what its name suggests, and loops consecutively, allowing your program to change and respond. Use it to actively control the Arduino board. +

+

Example

+
 
+int buttonPin = 3;
+
+// setup initializes serial and the button pin
+void setup()
+{
+  beginSerial(9600);
+  pinMode(buttonPin, INPUT);
+}
+
+// loop checks the button pin each time,
+// and will send serial if it is pressed
+void loop()
+{
+  if (digitalRead(buttonPin) == HIGH)
+    serialWrite('H');
+  else
+    serialWrite('L');
+
+  delay(1000);
+}
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/LowByte.html b/arduino-0018-linux/reference/LowByte.html new file mode 100644 index 0000000..3c81042 --- /dev/null +++ b/arduino-0018-linux/reference/LowByte.html @@ -0,0 +1,83 @@ + + + + Arduino - LowByte + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

lowByte()

+

Description

+

Extracts the low-order (rightmost) byte of a variable (e.g. a word). +

+

Syntax

+

lowByte(x) +

+

Parameters

+

x: a value of any type +

+

Returns

+

byte +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Map.html b/arduino-0018-linux/reference/Map.html new file mode 100644 index 0000000..02d7d25 --- /dev/null +++ b/arduino-0018-linux/reference/Map.html @@ -0,0 +1,125 @@ + + + + Arduino - Map + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

map(value, fromLow, fromHigh, toLow, toHigh)

+

Description

+

Re-maps a number from one range to another. That is, a value of fromLow would get mapped to toLow, a value of fromHigh to toHigh, values in-between to values in-between, etc. +

+

Does not constrain values to within the range, because out-of-range values are sometimes intended and useful. The constrain() function may be used either before or after this function, if limits to the ranges are desired. +

+

Note that the "lower bounds" of either range may be larger or smaller than the "upper bounds" so the map() function may be used to reverse a range of numbers, for example +

+

y = map(x, 1, 50, 50, 1); +

+

The function also handles negative numbers well, so +that this example +

+

y = map(x, 1, 50, 50, -100); +

+

is also valid and works well. +

+

The map() function uses integer math so will not generate fractions, when the math might indicate that it should do so. Fractional remainders are truncated, and are not rounded or averaged. +

+

Parameters

+

value: the number to map +

+

fromLow: the lower bound of the value's current range +

+

fromHigh: the upper bound of the value's current range +

+

toLow: the lower bound of the value's target range +

+

toHigh: the upper bound of the value's target range +

+

Returns

+

The mapped value. +

+

Example

+
+/* Map an analog value to 8 bits (0 to 255) */
+void setup() {}
+
+void loop()
+{
+  int val = analogRead(0);
+  val = map(val, 0, 1023, 0, 255);
+  analogWrite(9, val);
+}
+
+
+

Appendix

+

For the mathematically inclined, here's the whole function +

+

+long map(long x, long in_min, long in_max, long out_min, long out_max)
+{
+  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
+}
+
+
+

See Also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Max.html b/arduino-0018-linux/reference/Max.html new file mode 100644 index 0000000..3f39d5a --- /dev/null +++ b/arduino-0018-linux/reference/Max.html @@ -0,0 +1,98 @@ + + + + Arduino - Max + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

max(x, y)

+

Description

+

Calculates the maximum of two numbers. +

+

Parameters

+

x: the first number, any data type +

+

y: the second number, any data type +

+

Returns

+

The larger of the two parameter values. +

+

Example

+
sensVal = max(senVal, 20); // assigns sensVal to the larger of sensVal or 20
+                           // (effectively ensuring that it is at least 20)
+

Note

+

Perhaps counter-intuitively, max() is often used to constrain the lower end of a variable's range, while min() is used to constrain the upper end of the range. +

+

Warning

+

Because of the way the max() function is implemented, avoid using other functions inside the brackets, it may lead to incorrect results +

+

+max(a--, 0);   // avoid this - yields incorrect results
+
+a--;           // use this instead -
+max(a, 0);     // keep other math outside the function
+
+
+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Micros.html b/arduino-0018-linux/reference/Micros.html new file mode 100644 index 0000000..20da518 --- /dev/null +++ b/arduino-0018-linux/reference/Micros.html @@ -0,0 +1,100 @@ + + + + Arduino - Micros + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

micros()

+

Description

+

Returns the number of microseconds since the Arduino board began running the current program. This number will overflow (go back to zero), after approximately 70 minutes. On 16 MHz Arduino boards (e.g. Duemilanove and Nano), this function has a resolution of four microseconds (i.e. the value returned is always a multiple of four). On 8 MHz Arduino boards (e.g. the LilyPad), this function has a resolution of eight microseconds. +

+

Note: there are 1,000 microseconds in a millisecond and 1,000,000 microseconds in a second. +

+

Parameters

+

None +

+

Returns

+

Number of microseconds since the program started (unsigned long) +

+

Example

+
+unsigned long time;
+
+void setup(){
+  Serial.begin(9600);
+}
+void loop(){
+  Serial.print("Time: ");
+  time = micros();
+  //prints time since program started
+  Serial.println(time);
+  // wait a second so as not to send massive amounts of data
+  delay(1000);
+}
+
+
+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Millis.html b/arduino-0018-linux/reference/Millis.html new file mode 100644 index 0000000..11706b2 --- /dev/null +++ b/arduino-0018-linux/reference/Millis.html @@ -0,0 +1,102 @@ + + + + Arduino - Millis + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

millis()

+

Description

+

Returns the number of milliseconds since the Arduino board began running the current program. This number will overflow (go back to zero), after approximately 50 days. +

+

Parameters

+

None +

+

Returns

+

Number of milliseconds since the program started (unsigned long) +

+

Example

+
+unsigned long time;
+
+void setup(){
+  Serial.begin(9600);
+}
+void loop(){
+  Serial.print("Time: ");
+  time = millis();
+  //prints time since program started
+  Serial.println(time);
+  // wait a second so as not to send massive amounts of data
+  delay(1000);
+}
+
+
+

Tip:

+

Note that the parameter for millis is an unsigned long, errors may be generated if a programmer tries to do math with other datatypes such as ints. +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Min.html b/arduino-0018-linux/reference/Min.html new file mode 100644 index 0000000..e926162 --- /dev/null +++ b/arduino-0018-linux/reference/Min.html @@ -0,0 +1,98 @@ + + + + Arduino - Min + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

min(x, y)

+

Description

+

Calculates the minimum of two numbers. +

+

Parameters

+

x: the first number, any data type +

+

y: the second number, any data type +

+

Returns

+

The smaller of the two numbers. +

+

Examples

+
sensVal = min(sensVal, 100); // assigns sensVal to the smaller of sensVal or 100
+                             // ensuring that it never gets above 100.
+

Note

+

Perhaps counter-intuitively, max() is often used to constrain the lower end of a variable's range, while min() is used to constrain the upper end of the range. +

+

Warning

+

Because of the way the min() function is implemented, avoid using other functions inside the brackets, it may lead to incorrect results +

+

+min(a++, 100);   // avoid this - yields incorrect results
+
+a++;
+min(a, 100);    // use this instead - keep other math outside the function
+
+
+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Modulo.html b/arduino-0018-linux/reference/Modulo.html new file mode 100644 index 0000000..83fd47e --- /dev/null +++ b/arduino-0018-linux/reference/Modulo.html @@ -0,0 +1,110 @@ + + + + Arduino - Modulo + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

% (modulo)

+

Description

+

Calculates the remainder when one integer is divided by another. It is useful for keeping a variable within a particular range (e.g. the size of an array). +

+

Syntax

+

result = dividend % divisor +

+

Parameters

+

dividend: the number to be divided +

+

divisor: the number to divide by +

+

Returns

+

the remainder +

+

Examples

+
x = 7 % 5;   // x now contains 2
+x = 9 % 5;   // x now contains 4
+x = 5 % 5;   // x now contains 0
+x = 4 % 5;   // x now contains 4
+
+
+

Example Code

+
+/* update one value in an array each time through a loop */
+
+int values[10];
+int i = 0;
+
+void setup() {}
+
+void loop()
+{
+  values[i] = analogRead(0);
+  i = (i + 1) % 10;   // modulo operator rolls over variable  
+}
+
+
+

Tip

+

The modulo operator does not work on floats. +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/NoInterrupts.html b/arduino-0018-linux/reference/NoInterrupts.html new file mode 100644 index 0000000..94b2e02 --- /dev/null +++ b/arduino-0018-linux/reference/NoInterrupts.html @@ -0,0 +1,92 @@ + + + + Arduino - NoInterrupts + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

noInterrupts()

+

Description

+

Disables interrupts (you can re-enable them with interrupts()). Interrupts allow certain important tasks to happen in the background and are enabled by default. Some functions will not work while interrupts are disabled, and incoming communication may be ignored. Interrupts can slightly disrupt the timing of code, however, and may be disabled for particularly critical sections of code. +

+

Parameters

+

None. +

+

Returns

+

None. +

+

Example

+
+void setup() {}
+
+void loop()
+{
+  noInterrupts();
+  // critical, time-sensitive code here
+  interrupts();
+  // other code here
+}
+
+
+

See Also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/NoTone.html b/arduino-0018-linux/reference/NoTone.html new file mode 100644 index 0000000..48b4864 --- /dev/null +++ b/arduino-0018-linux/reference/NoTone.html @@ -0,0 +1,82 @@ + + + + Arduino - NoTone + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

noTone()

+

Description

+

Stops the generation of a square wave triggered by tone(). Has no effect if no tone is being generated. +

+

Syntax

+

noTone(pin) +

+

Parameters

+

pin: the pin on which to stop generating the tone +

+

Returns

+

nothing +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/PROGMEM.html b/arduino-0018-linux/reference/PROGMEM.html new file mode 100644 index 0000000..4b7eb62 --- /dev/null +++ b/arduino-0018-linux/reference/PROGMEM.html @@ -0,0 +1,197 @@ + + + + Arduino - PROGMEM + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Board +

+

PROGMEM

+

Store data in flash (program) memory instead of SRAM. There's a description of the various types of memory available on an Arduino board. +

+

The PROGMEM keyword is a variable modifier, it should be used only with the datatypes defined in pgmspace.h. It tells the compiler "put this information into flash memory", instead of into SRAM, where it would normally go. +

+

PROGMEM is part of the pgmspace.h library. So you first need to include the library at the top your sketch, like this: +

+#include <avr/pgmspace.h>
+
+

Syntax

+
+dataType variableName[] PROGMEM = {dataInt0, dataInt1, dataInt3...}; 
+
+

  • program memory dataType - any program memory variable type (see below) +
  • variableName - the name for your array of data +

Note that because PROGMEM is a variable modifier, there is no hard and fast rule about where it should go, so the Arduino compiler accepts all of the definitions below, which are also synonymous. +

+

+dataType variableName[] PROGMEM = {};
+dataType PROGMEM variableName[] = {};
+PROGMEM dataType variableName[] = {};
+

Common programming styles favor one of the first two however. +

+

While PROGMEM could be used on a single variable, it is really only worth the fuss if you have a larger block of data that needs to be stored, which is usually easiest in an array, (or another C data structure beyond our present discussion). +

+

Using PROGMEM is also a two-step procedure. After getting the data into Flash memory, it requires special methods (functions), also defined in the pgmspace.h library, to read the data from program memory back into SRAM, so we can do something useful with it. +

+

As mentioned above, it is important to use the datatypes outlined in pgmspace.h. Some cryptic bugs are generated by using ordinary datatypes for program memory calls. Below is a list of variable types to use. Floating point numbers in program memory do not appear to be supported. +

+

 prog_char      - a signed char (1 byte) -127 to 128
+ prog_uchar     - an unsigned char (1 byte) 0 to 255
+ prog_int16_t   - a signed int (2 bytes) -32,767 to 32,768
+ prog_uint16_t  - an unsigned int (2 bytes) 0 to 65,535
+ prog_int32_t   - a signed long (4 bytes) -2,147,483,648 to * 2,147,483,647.
+ prog_uint32_t  - an unsigned long (4 bytes) 0 to 4,294,967,295
+
+

Example

+

The following code fragments illustrate how to read and write unsigned chars (bytes) and ints (2 bytes) to PROGMEM. +

+#include <avr/pgmspace.h>
+
+
+// save some unsigned ints
+PROGMEM  prog_uint16_t charSet[]  = { 65000, 32796, 16843, 10, 11234};
+
+// save some chars
+prog_uchar signMessage[] PROGMEM  = {"I AM PREDATOR,  UNSEEN COMBATANT. CREATED BY THE UNITED STATES DEPART"};
+
+unsigned int displayInt;
+int k;    // counter variable
+char myChar;  
+
+// read back a 2-byte int
+ displayInt = pgm_read_word_near(charSet + k)
+
+// read back a char 
+myChar =  pgm_read_byte_near(signMessage + k); 
+
+
+
+

Arrays of strings +

+

It is often convenient when working with large amounts of text, such as a project with an LCD display, to setup an array of strings. Because strings themselves are arrays, this is in actually an example of a two-dimensional array. +

+

These tend to be large structures so putting them into program memory is often desirable. The code below illustrates the idea. +

+

+
+/*
+ PROGMEM string demo
+ How to store a table of strings in program memory (flash), 
+ and retrieve them.
+
+ Information summarized from:
+ http://www.nongnu.org/avr-libc/user-manual/pgmspace.html
+
+ Setting up a table (array) of strings in program memory is slightly complicated, but
+ here is a good template to follow. 
+
+ Setting up the strings is a two-step process. First define the strings.
+
+*/
+
+#include <avr/pgmspace.h>
+prog_char string_0[] PROGMEM = "String 0";   // "String 0" etc are strings to store - change to suit.
+prog_char string_1[] PROGMEM = "String 1";
+prog_char string_2[] PROGMEM = "String 2";
+prog_char string_3[] PROGMEM = "String 3";
+prog_char string_4[] PROGMEM = "String 4";
+prog_char string_5[] PROGMEM = "String 5";
+
+
+// Then set up a table to refer to your strings.
+
+PGM_P PROGMEM string_table[] =	   // change "string_table" name to suit
+{   
+  string_0,
+  string_1,
+  string_2,
+  string_3,
+  string_4,
+  string_5 };
+
+char buffer[30];    // make sure this is large enough for the largest string it must hold
+
+void setup()			  
+{
+  Serial.begin(9600);
+}
+
+
+void loop()			  
+{
+  /* Using the string table in program memory requires the use of special functions to retrieve the data.
+     The strcpy_P function copies a string from program space to a string in RAM ("buffer"). 
+     Make sure your receiving string in RAM  is large enough to hold whatever
+     you are retrieving from program space. */
+
+
+  for (int i = 0; i < 6; i++)
+  {
+    strcpy_P(buffer, (char*)pgm_read_word(&(string_table[i]))); // Necessary casts and dereferencing, just copy. 
+    Serial.println( buffer );
+    delay( 500 );
+  }
+}
+
+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/PinMode.html b/arduino-0018-linux/reference/PinMode.html new file mode 100644 index 0000000..986bb3f --- /dev/null +++ b/arduino-0018-linux/reference/PinMode.html @@ -0,0 +1,109 @@ + + + + Arduino - PinMode + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

pinMode()

+

Description

+

Configures the specified pin to behave either as an input or an output. See the description of digital pins for details. +

+

Syntax

+

pinMode(pin, mode) +

+

Parameters

+

pin: the number of the pin whose mode you wish to set +

+

mode: either INPUT or OUTPUT +

+

Returns

+

None +

+

Example

+
+
+int ledPin = 13;                 // LED connected to digital pin 13
+
+void setup()
+{
+  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
+}
+
+void loop()
+{
+  digitalWrite(ledPin, HIGH);   // sets the LED on
+  delay(1000);                  // waits for a second
+  digitalWrite(ledPin, LOW);    // sets the LED off
+  delay(1000);                  // waits for a second
+}
+
+
+

Note

+

The analog input pins can be used as digital pins, referred to as numbers 14 (analog input 0) to 19 (analog input 5). +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Pointer.html b/arduino-0018-linux/reference/Pointer.html new file mode 100644 index 0000000..9f9008d --- /dev/null +++ b/arduino-0018-linux/reference/Pointer.html @@ -0,0 +1,71 @@ + + + + Arduino - Pointer + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

The pointer operators

+

& (reference) and * (dereference)

+

Pointers are one of the more complicated subjects for beginners in learning C, and it is possible to write the vast majority of Arduino sketches without ever encountering pointers. However for manipulating certain data structures, the use of pointers can simplify the code, and and knowledge of manipulating pointers is handy to have in one's toolkit. +

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/PortManipulation.html b/arduino-0018-linux/reference/PortManipulation.html new file mode 100644 index 0000000..4ae95c5 --- /dev/null +++ b/arduino-0018-linux/reference/PortManipulation.html @@ -0,0 +1,128 @@ + + + + Arduino - PortManipulation + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Port Registers

+

Port registers allow for lower-level and faster manipulation of the i/o pins of the microcontroller on an Arduino board. The chips used on the Arduino board (the ATmega8 and ATmega168) have three ports: +

  • B (digital pin 8 to 13) +
  • C (analog input pins) +
  • D (digital pins 0 to 7) +

Each port is controlled by three registers, which are also defined variables in the arduino language. The DDR register, determines whether the pin is an INPUT or OUTPUT. The PORT register controls whether the pin is HIGH or LOW, and the PIN register reads the state of INPUT pins set to input with pinMode(). The maps of the ATmega8 and ATmega168 chips show the ports. +

+

DDR and PORT registers may be both written to, and read. PIN registers correspond to the state of inputs and may only be read. +

+

PORTD maps to Arduino digital pins 0 to 7 +

DDRD - The Port D Data Direction Register - read/write +
PORTD - The Port D Data Register - read/write +
PIND - The Port D Input Pins Register - read only +

PORTB maps to Arduino digital pins 8 to 13 The two high bits (6 & 7) map to the crystal pins and are not usable +

+

DDRB - The Port B Data Direction Register - read/write +
PORTB - The Port B Data Register - read/write +
PINB - The Port B Input Pins Register - read only +

PORTC maps to Arduino analog pins 0 to 5. Pins 6 & 7 are only accessible on the Arduino Mini +

DDRC - The Port C Data Direction Register - read/write +
PORTC - The Port C Data Register - read/write +
PINC - The Port C Input Pins Register - read only +

Each bit of these registers corresponds to a single pin; e.g. the low bit of DDRB, PORTB, and PINB refers to pin PB0 (digital pin 8). For a complete mapping of Arduino pin numbers to ports and bits, see the diagram for your chip: ATmega8, ATmega168. (Note that some bits of a port may be used for things other than i/o; be careful not to change the values of the register bits corresponding to them.) +

+

Examples

+

Referring to the pin map above, the PortD registers control Arduino digital pins 0 � 7. +

+

You should note, however, that pins 0 & 1 are used for serial communications for programming and debugging the Arduino, so changing these pins should usually be avoided unless needed for serial input or output functions. Be aware that this can interfere with program download or debugging. +

+

DDRD is the direction register for Port D (Arduino digital pins 0-7). The bits in this register control whether the pins in PORTD are configured as inputs or outputs so, for example: +

+

DDRD = B11111110;  // sets Arduino pins 1 � 7 as outputs, pin 0 as input
+DDRD = DDRD | B11111100;  // this is safer � it sets pins 2 to 7 as outputs
+	                  // without changing the value of pins 0 & 1, which are RX & TX 
+
+

//See the bitwise operators reference pages and +The Bitmath Tutorial in the Playground +

+

PORTB is the register for the state of the outputs. For example; +

+

PORTD = B10101000; // sets digital pins 7,5,3 HIGH +

+

You will only see 5 volts on these pins however if the pins have been set as outputs using the DDRD register or with pinMode(). +

+

PINB is the input register variable It will read all of the digital input pins at the same time. +

+

Why use port manipulation?

+

From The Bitmath Tutorial +

+

Generally speaking, doing this sort of thing is not a good idea. Why not? Here are a few reasons: +

+

  • The code is much more difficult for you to debug and maintain, and is a lot harder for other people to understand. It only takes a few microseconds for the processor to execute code, but it might take hours for you to figure out why it isn't working right and fix it! Your time is valuable, right? But the computer's time is very cheap, measured in the cost of the electricity you feed it. Usually it is much better to write code the most obvious way. +

  • The code is less portable. If you use digitalRead() and digitalWrite(), it is much easier to write code that will run on all of the Atmel microcontrollers, whereas the control and port registers can be different on each kind of microcontroller. +

  • It is a lot easier to cause unintentional malfunctions with direct port access. Notice how the line DDRD = B11111110; above mentions that it must leave pin 0 as an input pin. Pin 0 is the receive line (RX) on the serial port. It would be very easy to accidentally cause your serial port to stop working by changing pin 0 into an output pin! Now that would be very confusing when you suddenly are unable to receive serial data, wouldn't it? +

So you might be saying to yourself, great, why would I ever want to use this stuff then? Here are some of the positive aspects of direct port access: +

+

  • You may need to be able to turn pins on and off very quickly, meaning within fractions of a microsecond. If you look at the source code in lib/targets/arduino/wiring.c, you will see that digitalRead() and digitalWrite() are each about a dozen or so lines of code, which get compiled into quite a few machine instructions. Each machine instruction requires one clock cycle at 16MHz, which can add up in time-sensitive applications. Direct port access can do the same job in a lot fewer clock cycles. +

  • Sometimes you might need to set multiple output pins at exactly the same time. Calling digitalWrite(10,HIGH); followed by digitalWrite(11,HIGH); will cause pin 10 to go HIGH several microseconds before pin 11, which may confuse certain time-sensitive external digital circuits you have hooked up. Alternatively, you could set both pins high at exactly the same moment in time using PORTB |= B1100; +

  • If you are running low on program memory, you can use these tricks to make your code smaller. It requires a lot fewer bytes of compiled code to simultaneously write a bunch of hardware pins simultaneously via the port registers than it would using a for loop to set each pin separately. In some cases, this might make the difference between your program fitting in flash memory or not! +

See

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Pow.html b/arduino-0018-linux/reference/Pow.html new file mode 100644 index 0000000..011c422 --- /dev/null +++ b/arduino-0018-linux/reference/Pow.html @@ -0,0 +1,86 @@ + + + + Arduino - Pow + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

pow(base, exponent)

+

Description

+

Calculates the value of a number raised to a power. Pow() can be used to raise a number to a fractional power. This is useful for generating exponential mapping of values or curves. +

+

Parameters

+

base: the number (float) +

+

exponent: the power to which the base is raised (float) +

+

Returns

+

The result of the exponentiation (double) +

+

Example

+

See the fscale function in the code library. +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/PrintBinary.html b/arduino-0018-linux/reference/PrintBinary.html new file mode 100644 index 0000000..81ec0ba --- /dev/null +++ b/arduino-0018-linux/reference/PrintBinary.html @@ -0,0 +1,80 @@ + + + + Arduino - PrintBinary + + + +
+ + + + + + +
+ +
+

Language | Libraries | Comparison +

printBinary(num)

+

Description

+

Prints a binary integer to the serial port; that is, transmits the sequence of ASCII bytes of the base 2 representation of the integer. +

+

Parameters

+

num: the number to print +

+

Returns

+

None +

+

See also

+

Reference Home +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/PrintByte.html b/arduino-0018-linux/reference/PrintByte.html new file mode 100644 index 0000000..4ff3949 --- /dev/null +++ b/arduino-0018-linux/reference/PrintByte.html @@ -0,0 +1,80 @@ + + + + Arduino - PrintByte + + + +
+ + + + + + +
+ +
+

Language | Libraries | Comparison +

printByte(b)

+

Description

+

Prints a single byte to the serial port (not the ASCII characters that represent the numeric value of that byte). +

+

Parameters

+

b: the byte to print +

+

Returns

+

None +

+

See also

+

Reference Home +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/PrintHex.html b/arduino-0018-linux/reference/PrintHex.html new file mode 100644 index 0000000..c74c3de --- /dev/null +++ b/arduino-0018-linux/reference/PrintHex.html @@ -0,0 +1,80 @@ + + + + Arduino - PrintHex + + + +
+ + + + + + +
+ +
+

Language | Libraries | Comparison +

printHex(num)

+

Description

+

Prints a hexadecimal integer to the serial port; that is, transmits the sequence of ASCII bytes of the base 16 representation of the integer. +

+

Parameters

+

num: the number to print +

+

Returns

+

None +

+

See also

+

Reference Home +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/PrintInteger.html b/arduino-0018-linux/reference/PrintInteger.html new file mode 100644 index 0000000..b288130 --- /dev/null +++ b/arduino-0018-linux/reference/PrintInteger.html @@ -0,0 +1,80 @@ + + + + Arduino - PrintInteger + + + +
+ + + + + + +
+ +
+

Language | Libraries | Comparison +

printInteger(num)

+

Description

+

Prints an integer to the serial port; that is, transmits the sequence of ASCII bytes of the base 10 representation of the integer. +

+

Parameters

+

num: the number to print +

+

Returns

+

None +

+

See also

+

Reference Home +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/PrintMode.html b/arduino-0018-linux/reference/PrintMode.html new file mode 100644 index 0000000..717baa8 --- /dev/null +++ b/arduino-0018-linux/reference/PrintMode.html @@ -0,0 +1,79 @@ + + + + Arduino - PrintMode + + + +
+ + + + + + +
+ +
+

Language | Libraries | Comparison +

printMode(mode)

+

Description

+

In theory, this function determines whether the output of the print() functions goes to the serial port or an LCD. Since, however, there is currently no LCD support in Arduino, this function does nothing and the print() functions always send their output to the serial port. +

+

Parameters

+

mode: SERIAL or DISPLAY +

+

Returns

+

None +

+

See also

+ +
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/PrintNewline.html b/arduino-0018-linux/reference/PrintNewline.html new file mode 100644 index 0000000..d319291 --- /dev/null +++ b/arduino-0018-linux/reference/PrintNewline.html @@ -0,0 +1,80 @@ + + + + Arduino - PrintNewline + + + +
+ + + + + + +
+ +
+

Language | Libraries | Comparison +

printNewline()

+

Description

+

Prints a newline character ('\n' or ASCII code 10) to the serial port. +

+

Parameters

+

None +

+

Returns

+

None +

+

See also

+

Reference Home +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/PrintOctal.html b/arduino-0018-linux/reference/PrintOctal.html new file mode 100644 index 0000000..184439e --- /dev/null +++ b/arduino-0018-linux/reference/PrintOctal.html @@ -0,0 +1,80 @@ + + + + Arduino - PrintOctal + + + +
+ + + + + + +
+ +
+

Language | Libraries | Comparison +

printOctal(num)

+

Description

+

Prints an octal integer to the serial port; that is, transmits the sequence of ASCII bytes of the base 8 representation of the integer. +

+

Parameters

+

num: the number to print +

+

Returns

+

None +

+

See also

+

Reference Home +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/PrintString.html b/arduino-0018-linux/reference/PrintString.html new file mode 100644 index 0000000..072aa03 --- /dev/null +++ b/arduino-0018-linux/reference/PrintString.html @@ -0,0 +1,80 @@ + + + + Arduino - PrintString + + + +
+ + + + + + +
+ +
+

Language | Libraries | Comparison +

printString(str)

+

Description

+

Outputs a string to the serial port; that is, transmits the ASCII byte of each character in the string. +

+

Parameters

+

str: the string to output +

+

Returns

+

None +

+

See also

+

Reference Home +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/PulseIn.html b/arduino-0018-linux/reference/PulseIn.html new file mode 100644 index 0000000..69e140b --- /dev/null +++ b/arduino-0018-linux/reference/PulseIn.html @@ -0,0 +1,103 @@ + + + + Arduino - PulseIn + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

pulseIn()

+

Description

+

Reads a pulse (either HIGH or LOW) on a pin. For example, if value is HIGH, pulseIn() waits for the pin to go HIGH, starts timing, then waits for the pin to go LOW and stops timing. Returns the length of the pulse in microseconds. Gives up and returns 0 if no pulse starts within a specified time out. +

+

The timing of this function has been determined empirically and will probably show errors in longer pulses. Works on pulses from 10 microseconds to 3 minutes in length. +

+

Syntax

+

pulseIn(pin, value)
pulseIn(pin, value, timeout) +

+

Parameters

+

pin: the number of the pin on which you want to read the pulse. (int) +

+

value: type of pulse to read: either HIGH or LOW. (int) +

+

timeout (optional): the number of microseconds to wait for the pulse to start; default is one second (unsigned long) +

+

Returns

+

the length of the pulse (in microseconds) or 0 if no pulse started before the timeout (unsigned long) +

+

Example

+
 
+
+int pin = 7;
+unsigned long duration;
+
+void setup()
+{
+  pinMode(pin, INPUT);
+}
+
+void loop()
+{
+  duration = pulseIn(pin, HIGH);
+}
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Random.html b/arduino-0018-linux/reference/Random.html new file mode 100644 index 0000000..7635f21 --- /dev/null +++ b/arduino-0018-linux/reference/Random.html @@ -0,0 +1,116 @@ + + + + Arduino - Random + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

random()

+

Description

+

The random function generates pseudo-random numbers. +

+

Syntax

+

random(max)
random(min, max) +

+

Parameters

+

min - lower bound of the random value, inclusive (optional) +

+

max - upper bound of the random value, exclusive +

+

Returns

+

a random number between min and max-1 (long) +

+

Note:

+

If it is important for a sequence of values generated by random() to differ, on subsequent executions of a sketch, use randomSeed() to initialize the random number generator with a fairly random input, such as analogRead() on an unconnected pin. +

+

Conversely, it can occasionally be useful to use pseudo-random sequences that repeat exactly. This can be accomplished by calling randomSeed() with a fixed number, before starting the random sequence. +

+

Example

+
+long randNumber;
+
+void setup(){
+  Serial.begin(9600);
+
+  // if analog input pin 0 is unconnected, random analog
+  // noise will cause the call to randomSeed() to generate
+  // different seed numbers each time the sketch runs.
+  // randomSeed() will then shuffle the random function.
+  randomSeed(analogRead(0));
+}
+
+void loop() {
+  // print a random number from 0 to 299
+  randNumber = random(300);
+  Serial.println(randNumber);  
+
+  // print a random number from 10 to 19
+  randNumber = random(10, 20);
+  Serial.println(randNumber);
+
+  delay(50);
+}
+
+
+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/RandomSeed.html b/arduino-0018-linux/reference/RandomSeed.html new file mode 100644 index 0000000..dfe6700 --- /dev/null +++ b/arduino-0018-linux/reference/RandomSeed.html @@ -0,0 +1,100 @@ + + + + Arduino - RandomSeed + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

randomSeed(seed)

+

Description

+

randomSeed() initializes the pseudo-random number generator, causing it to start at an arbitrary point in its random sequence. This sequence, while very long, and random, is always the same. +

+

If it is important for a sequence of values generated by random() to differ, on subsequent executions of a sketch, use randomSeed() to initialize the random number generator with a fairly random input, such as analogRead() on an unconnected pin. +

+

Conversely, it can occasionally be useful to use pseudo-random sequences that repeat exactly. This can be accomplished by calling randomSeed() with a fixed number, before starting the random sequence. +

+

Parameters

+

long, int - pass a number to generate the seed. +

+

Returns

+

no returns +

+

Example

+
+long randNumber;
+
+void setup(){
+  Serial.begin(9600);
+  randomSeed(analogRead(0));
+}
+
+void loop(){
+  randNumber = random(300);
+  Serial.println(randNumber);
+
+  delay(50);
+}
+
+
+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/RecentChanges.html b/arduino-0018-linux/reference/RecentChanges.html new file mode 100644 index 0000000..a9f4e8a --- /dev/null +++ b/arduino-0018-linux/reference/RecentChanges.html @@ -0,0 +1,395 @@ + + + + Arduino - RecentChanges + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison +

+

=] +

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Return.html b/arduino-0018-linux/reference/Return.html new file mode 100644 index 0000000..6d870a3 --- /dev/null +++ b/arduino-0018-linux/reference/Return.html @@ -0,0 +1,103 @@ + + + + Arduino - Return + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

return

+

Terminate a function and return a value from a function to the calling function, if desired. +

+

Syntax:

+

return; +

+

return value; // both forms are valid +

+

Parameters

+

value: any variable or constant type +

+

Examples:

+

A function to compare a sensor input to a threshold +

 int checkSensor(){       
+    if (analogRead(0) > 400) {
+        return 1;
+    else{
+        return 0;
+    }
+}
+
+

The return keyword is handy to test a section of code without having to "comment out" large sections of possibly buggy code. +

+

void loop(){
+
+// brilliant code idea to test here
+
+return;
+
+// the rest of a dysfunctional sketch here
+// this code will never be executed
+}
+
+

See also

+

comments +

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Scope.html b/arduino-0018-linux/reference/Scope.html new file mode 100644 index 0000000..49422d7 --- /dev/null +++ b/arduino-0018-linux/reference/Scope.html @@ -0,0 +1,96 @@ + + + + Arduino - Scope + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Variable Scope

+

Variables in the C programming language, which Arduino uses, have a property called scope. This is in contrast to languages such as BASIC where every variable is a global variable. +

+

A global variable is one that can be seen by every function in a program. Local variables are only visible to the function in which they are declared. In the Arduino environment, any variable declared outside of a function (e.g. setup(), loop(), etc. ), is a global variable. +

+

When programs start to get larger and more complex, local variables are a useful way to insure that only one function has access to its own variables. This prevents programming errors when one function inadvertently modifies variables used by another function. +

+

It is also sometimes handy to declare and initialize a variable inside a for loop. This creates a variable that can only be accessed from inside the for-loop brackets. +

+

Example:

+
int gPWMval;  // any function will see this variable
+
+void setup()
+{
+  // ...
+}
+
+void loop()
+{
+  int i;    // "i" is only "visible" inside of "loop"
+  float f;  // "f" is only "visible" inside of "loop"
+  // ...
+
+  for (int j = 0; j <100; j++){
+  // variable j can only be accessed inside the for-loop brackets
+  }
+
+}
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/SemiColon.html b/arduino-0018-linux/reference/SemiColon.html new file mode 100644 index 0000000..62cc0c8 --- /dev/null +++ b/arduino-0018-linux/reference/SemiColon.html @@ -0,0 +1,77 @@ + + + + Arduino - SemiColon + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

; semicolon

+

Used to end a statement. +

+

Example

+
+int a = 13;
+
+

Tip

+

Forgetting to end a line in a semicolon will result in a compiler error. The error text may be obvious, and refer to a missing semicolon, or it may not. If an impenetrable or seemingly illogical compiler error comes up, one of the first things to check is a missing semicolon, in the immediate vicinity, preceding the line at which the compiler complained. +

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Serial.html b/arduino-0018-linux/reference/Serial.html new file mode 100644 index 0000000..47e0d78 --- /dev/null +++ b/arduino-0018-linux/reference/Serial.html @@ -0,0 +1,90 @@ + + + + Arduino - Serial + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Serial

+

Used for communication between the Arduino board and a computer or other devices. All Arduino boards have at least one serial port (also known as a UART or USART): Serial. It communicates on digital pins 0 (RX) and 1 (TX) as well as with the computer via USB. Thus, if you use these functions, you cannot also use pins 0 and 1 for digital input or output. +

+

You can use the Arduino environment's built-in serial monitor to communicate with an Arduino board. Click the serial monitor button in the toolbar and select the same baud rate used in the call to begin(). +

+

The Arduino Mega has three additional serial ports: Serial1 on pins 19 (RX) and 18 (TX), Serial2 on pins 17 (RX) and 16 (TX), Serial3 on pins 15 (RX) and 14 (TX). To use these pins to communicate with your personal computer, you will need an additional USB-to-serial adaptor, as they are not connected to the Mega's USB-to-serial adaptor. To use them to communicate with an external TTL serial device, connect the TX pin to your device's RX pin, the RX to your device's TX pin, and the ground of your Mega to your device's ground. (Don't connect these pins directly to an RS232 serial port; they operate at +/- 12V and can damage your Arduino board.) +

+

Functions

+

Examples

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/SerialAvailable.html b/arduino-0018-linux/reference/SerialAvailable.html new file mode 100644 index 0000000..5c5c35f --- /dev/null +++ b/arduino-0018-linux/reference/SerialAvailable.html @@ -0,0 +1,82 @@ + + + + Arduino - SerialAvailable + + + +
+ + + + + + +
+ +
+

Language | Libraries | Comparison +

int serialAvailable()

+

Description

+

Get the number of bytes (characters) available for reading over the serial port. +

+

Parameters

+

None +

+

Returns

+

the number of bytes available, or 0 if there aren't any +

+

See also

+

Reference Home +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/SerialRead.html b/arduino-0018-linux/reference/SerialRead.html new file mode 100644 index 0000000..4ff63d9 --- /dev/null +++ b/arduino-0018-linux/reference/SerialRead.html @@ -0,0 +1,82 @@ + + + + Arduino - SerialRead + + + +
+ + + + + + +
+ +
+

Language | Libraries | Comparison +

int serialRead()

+

Description

+

Reads a byte (a character) from the serial port. +

+

Parameters

+

None +

+

Returns

+

The next byte from the serial port, or -1 if there aren't any. +

+

See also

+

Reference Home +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/SerialWrite.html b/arduino-0018-linux/reference/SerialWrite.html new file mode 100644 index 0000000..3ba95de --- /dev/null +++ b/arduino-0018-linux/reference/SerialWrite.html @@ -0,0 +1,82 @@ + + + + Arduino - SerialWrite + + + +
+ + + + + + +
+ +
+

Language | Libraries | Comparison +

serialWrite(c)

+

Description

+

Writes a byte to the serial port. +

+

Parameters

+

c: the byte (character) to write +

+

Returns

+

None +

+

See also

+

Reference Home +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Serial_Available.html b/arduino-0018-linux/reference/Serial_Available.html new file mode 100644 index 0000000..452818e --- /dev/null +++ b/arduino-0018-linux/reference/Serial_Available.html @@ -0,0 +1,121 @@ + + + + Arduino - Available + + + + +
+ + + + + + +
+ +
+

int Serial.available()

+

Description

+

Get the number of bytes (characters) available for reading over the serial port. +

+

Parameters

+

None +

+

Returns

+

The number of bytes are available to read in the serial buffer, or 0 if none are available. If any data has come in, Serial.available() will be greater than 0. The serial buffer can hold up to 128 bytes. +

+

Example

+
+int incomingByte = 0;	// for incoming serial data
+
+void setup() {
+	Serial.begin(9600);	// opens serial port, sets data rate to 9600 bps
+}
+
+void loop() {
+
+	// send data only when you receive data:
+	if (Serial.available() > 0) {
+		// read the incoming byte:
+		incomingByte = Serial.read();
+
+		// say what you got:
+		Serial.print("I received: ");
+		Serial.println(incomingByte, DEC);
+	}
+}
+
+
+

Arduino Mega example: +

+

+void setup() {
+  Serial.begin(9600);
+  Serial1.begin(9600);
+
+}
+
+void loop() {
+  // read from port 0, send to port 1:
+  if (Serial.available()) {
+    int inByte = Serial.read();
+    Serial1.print(inByte, BYTE); 
+
+  }
+  // read from port 1, send to port 0:
+  if (Serial1.available()) {
+    int inByte = Serial1.read();
+    Serial.print(inByte, BYTE); 
+  }
+}
+
+
+

See also

+

Reference Home +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Serial_Begin.html b/arduino-0018-linux/reference/Serial_Begin.html new file mode 100644 index 0000000..8058f02 --- /dev/null +++ b/arduino-0018-linux/reference/Serial_Begin.html @@ -0,0 +1,108 @@ + + + + Arduino - Begin + + + + +
+ + + + + + +
+ +
+

Serial.begin(int speed)

+

Description

+

Sets the data rate in bits per second (baud) for serial data transmission. For communicating with the computer, use one of these rates: 300, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, or 115200. You can, however, specify other rates - for example, to communicate over pins 0 and 1 with a component that requires a particular baud rate. +

+

Parameters

+

long datarate, in bits per second (baud) +

+

Returns

+

nothing +

+

Example:

+
+void setup() {
+	Serial.begin(9600);	// opens serial port, sets data rate to 9600 bps
+}
+
+void loop() {}
+
+
+

Arduino Mega example: +

+

+// Arduino Mega using all four of its Serial ports 
+// (Serial, Serial1, Serial2, Serial3), 
+// with different baud rates:
+
+void setup(){
+  Serial.begin(9600);
+  Serial1.begin(38400);
+  Serial2.begin(19200);
+  Serial3.begin(4800);
+
+  Serial.println("Hello Computer");
+  Serial1.println("Hello Serial 1");
+  Serial2.println("Hello Serial 2");
+  Serial3.println("Hello Serial 3");
+}
+
+void loop() {}
+
+
+

Thanks to Jeff Gray for the mega example +

+

See also

+

Reference Home +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Serial_Flush.html b/arduino-0018-linux/reference/Serial_Flush.html new file mode 100644 index 0000000..081b15f --- /dev/null +++ b/arduino-0018-linux/reference/Serial_Flush.html @@ -0,0 +1,73 @@ + + + + Arduino - Flush + + + + +
+ + + + + + +
+ +
+

Serial.flush()

+

Description

+

Flushes the buffer of incoming serial data. That is, any call to Serial.read() or Serial.available() will return only data received after all the most recent call to Serial.flush(). +

+

Parameters

+

none +

+

Returns

+

none +

+

See also

+

Reference Home +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Serial_Print.html b/arduino-0018-linux/reference/Serial_Print.html new file mode 100644 index 0000000..780e174 --- /dev/null +++ b/arduino-0018-linux/reference/Serial_Print.html @@ -0,0 +1,200 @@ + + + + Arduino - Print + + + + +
+ + + + + + +
+ +
+

Serial.print(data)

+

Description

+

Prints data to the serial port. +

+

Parameter

+

data: integer types, including char, floats
Printing of floats is supported with a precision of two places to the right of the decimal point.
This may change soon. +

+

Syntax

+

This command can take many forms: +

+

Serial.print(b) +with no format specified, prints b as a decimal number in an ASCII string. For example, +

+

+int b = 79;
+Serial.print(b);
+

prints the ASCII string "79". +

+

Serial.print(b, DEC) +prints b as a decimal number in an ASCII string. For example, +

+

+int b = 79;
+Serial.print(b, DEC);
+

prints the string "79". +

+

Serial.print(b, HEX) +prints b as a hexadecimal number in an ASCII string. For example, +

+

+int b = 79;
+Serial.print(b, HEX);
+

prints the string "4F". +

+

Serial.print(b, OCT) +prints b as an octal number in an ASCII string. For example, +

+

+int b = 79;
+Serial.print(b, OCT);
+

prints the string "117". +

+

Serial.print(b, BIN) +prints b as a binary number in an ASCII string. For example, +

+

+int b = 79;
+Serial.print(b, BIN);
+

prints the string "1001111". +

+

Serial.print(b, BYTE) +prints b as a single byte. For example, +

+

+int b = 79;
+Serial.print(b, BYTE);
+

returns the string "O", which is the ASCII character represented by the value 79. For more information see the ASCII table. +

+

Serial.print(str) +if str is a string or an array of chars, prints str as an ASCII string. For example, +

+

+Serial.print("Hello World!");
+

prints the string "Hello World!". +

+

Parameters

+

b: the byte to print, or +

+

str: the string to print +

+

Returns

+

None +

+

Example:

+
/*
+Uses a FOR loop for data and prints a number in various formats.
+*/
+int x = 0;    // variable
+
+void setup() {
+  Serial.begin(9600);      // open the serial port at 9600 bps:    
+}
+
+void loop() {  
+  // print labels 
+  Serial.print("NO FORMAT");       // prints a label
+  Serial.print("\t");              // prints a tab
+
+  Serial.print("DEC");  
+  Serial.print("\t");      
+
+  Serial.print("HEX"); 
+  Serial.print("\t");   
+
+  Serial.print("OCT");
+  Serial.print("\t");
+
+  Serial.print("BIN");
+  Serial.print("\t"); 
+
+  Serial.println("BYTE");
+
+  for(x=0; x< 64; x++){    // only part of the ASCII chart, change to suit
+
+    // print it out in many formats:
+    Serial.print(x);       // print as an ASCII-encoded decimal - same as "DEC"
+    Serial.print("\t");    // prints a tab
+
+    Serial.print(x, DEC);  // print as an ASCII-encoded decimal
+    Serial.print("\t");    // prints a tab
+
+    Serial.print(x, HEX);  // print as an ASCII-encoded hexadecimal
+    Serial.print("\t");    // prints a tab
+
+    Serial.print(x, OCT);  // print as an ASCII-encoded octal
+    Serial.print("\t");    // prints a tab
+
+    Serial.print(x, BIN);  // print as an ASCII-encoded binary
+    Serial.print("\t");    // prints a tab
+
+    Serial.println(x, BYTE);    // prints as a raw byte value, 
+    //                             then adds the carriage return with "println"
+    delay(200);            // delay 200 milliseconds
+  }
+  Serial.println("");      // prints another carriage return
+}
+
+

Programming Tips / Known Issues

+

Serial.print() doesn't work on floats, so you'll need to cast them to an integral type, losing any fractional values. It is sometimes useful to multiply your float by a power of ten, to preserve some of this fractional resolution. +

+

Be careful about doing math inside the brackets e.g.
Serial.print(x-2, DEC);
The unsigned char data type, and byte data type will yield incorrect results and act as though they are signed types i.e. type char. +

+

The Serial.print function puts data into a buffer. It will wait for one character to send, before going on to the next character. However the function returns before sending the last character. +

+

See also

+

Reference Home +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Serial_Println.html b/arduino-0018-linux/reference/Serial_Println.html new file mode 100644 index 0000000..6b04b4f --- /dev/null +++ b/arduino-0018-linux/reference/Serial_Println.html @@ -0,0 +1,137 @@ + + + + Arduino - Println + + + + +
+ + + + + + +
+ +
+

Serial.println(data)

+

Description

+

Prints a data to the serial port, followed by a carriage return character(ASCII 13, or '\r') and a newline character (ASCII 10, or '\n'). This command takes the same forms as Serial.print(): +

+

Serial.println(b) +prints b as a decimal number in an ASCII string followed by a carriage return and a linefeed. +

+

Serial.println(b, DEC) +prints b as a decimal number in an ASCII string followed by a carriage return and a linefeed. +

+

Serial.println(b, HEX) +prints b as a hexadecimal number in an ASCII string followed by a carriage return and a linefeed. +

+

Serial.println(b, OCT) +prints b as an octal number in an ASCII string followed by a carriage return and a linefeed. +

+

Serial.println(b, BIN) +prints b as a binary number in an ASCII string followed by a carriage return and a linefeed. +

+

Serial.print(b, BYTE) +prints b as a single byte followed by a carriage return and a linefeed. +

+

Serial.println(str) +if str is a string or an array of chars, prints str an ASCII string. +

+

Serial.println() +just prints a carriage return and a linefeed. +

+

Parameter

+

data types: integer types, including char, strings (char arrays) & floats
Printing of floats is supported with a precision of two places to the right of the decimal point.
This may change soon. +

+

Returns

+

None +

+

Example:

+
+/*
+  Analog input
+
+ reads an analog input on analog in 0, prints the value out.
+
+ created 24 March 2006
+ by Tom Igoe
+ */
+
+int analogValue = 0;    // variable to hold the analog value
+
+void setup() {
+  // open the serial port at 9600 bps:
+  Serial.begin(9600);
+}
+
+void loop() {
+  // read the analog input on pin 0:
+  analogValue = analogRead(0);
+
+  // print it out in many formats:
+  Serial.println(analogValue);       // print as an ASCII-encoded decimal
+  Serial.println(analogValue, DEC);  // print as an ASCII-encoded decimal
+  Serial.println(analogValue, HEX);  // print as an ASCII-encoded hexadecimal
+  Serial.println(analogValue, OCT);  // print as an ASCII-encoded octal
+  Serial.println(analogValue, BIN);  // print as an ASCII-encoded binary
+  Serial.println(analogValue, BYTE); // print as a raw byte value
+
+  // delay 10 milliseconds before the next reading:
+  delay(10);
+}
+
+

Programming Tip / Known Issues

+

see Serial.print +

+

See also

+

Reference Home +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Serial_Read.html b/arduino-0018-linux/reference/Serial_Read.html new file mode 100644 index 0000000..40efbc3 --- /dev/null +++ b/arduino-0018-linux/reference/Serial_Read.html @@ -0,0 +1,98 @@ + + + + Arduino - Read + + + + +
+ + + + + + +
+ +
+

int Serial.read()

+

Description

+

Reads incoming serial data. +

+

Parameters

+

None +

+

Returns

+

the first byte of incoming serial data available (or -1 if no data is available) int +

+

Example

+
+int incomingByte = 0;	// for incoming serial data
+
+void setup() {
+	Serial.begin(9600);	// opens serial port, sets data rate to 9600 bps
+}
+
+void loop() {
+
+	// send data only when you receive data:
+	if (Serial.available() > 0) {
+		// read the incoming byte:
+		incomingByte = Serial.read();
+
+		// say what you got:
+		Serial.print("I received: ");
+		Serial.println(incomingByte, DEC);
+	}
+}
+
+
+
+

See also

+

Reference Home +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Serial_Write.html b/arduino-0018-linux/reference/Serial_Write.html new file mode 100644 index 0000000..d16f156 --- /dev/null +++ b/arduino-0018-linux/reference/Serial_Write.html @@ -0,0 +1,79 @@ + + + + Arduino - Write + + + + +
+ + + + + + +
+ +
+

Serial.write()

+

Description

+

Writes binary data to the serial port. This data is sent as a byte or series of bytes; to send the characters representing the digits of a number use the print() function instead. +

+

Syntax

+

serial.write(val)
serial.write(str)
serial.write(buf, len) +

+

Parameters

+

val: a value to send as a single byte +

+

str: a string to send as a series of bytes +

+

buf: an array to send as a series of bytes +

+

len: the length of the buffer +

+

See also

+ +
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/ServerAvailable.html b/arduino-0018-linux/reference/ServerAvailable.html new file mode 100644 index 0000000..bb99d76 --- /dev/null +++ b/arduino-0018-linux/reference/ServerAvailable.html @@ -0,0 +1,113 @@ + + + + Arduino - ServerAvailable + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Ethernet : Server class +

+

available()

+

Description

+

Gets a client that is connected to the server and has data available for reading. The connection persists when the returned client object goes out of scope; you can close it by calling client.stop(). +

+

Syntax

+

server.available() +

+

Parameters

+

None +

+

Returns

+

None +

+

Example

+
+#include <Ethernet.h>
+
+// network configuration.  gateway and subnet are optional.
+byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
+byte ip[] = { 10, 0, 0, 177 };
+byte gateway[] = { 10, 0, 0, 1 };
+byte subnet[] = { 255, 255, 0, 0 };
+
+// telnet defaults to port 23
+Server server = Server(23);
+
+void setup()
+{
+  // initialize the ethernet device
+  Ethernet.begin(mac, ip, gateway, subnet);
+
+  // start listening for clients
+  server.begin();
+}
+
+void loop()
+{
+  Client client = server.available();
+  if (client) {
+    server.write(client.read());
+  }
+}
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/ServerBegin.html b/arduino-0018-linux/reference/ServerBegin.html new file mode 100644 index 0000000..10410d6 --- /dev/null +++ b/arduino-0018-linux/reference/ServerBegin.html @@ -0,0 +1,113 @@ + + + + Arduino - ServerBegin + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Ethernet : Server class +

+

begin()

+

Description

+

Tells the server to begin listening for incoming connections. +

+

Syntax

+

server.begin() +

+

Parameters

+

None +

+

Returns

+

None +

+

Example

+
+#include <Ethernet.h>
+
+// network configuration.  gateway and subnet are optional.
+byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
+byte ip[] = { 10, 0, 0, 177 };
+byte gateway[] = { 10, 0, 0, 1 };
+byte subnet[] = { 255, 255, 0, 0 };
+
+// telnet defaults to port 23
+Server server = Server(23);
+
+void setup()
+{
+  // initialize the ethernet device
+  Ethernet.begin(mac, ip, gateway, subnet);
+
+  // start listening for clients
+  server.begin();
+}
+
+void loop()
+{
+  Client client = server.available();
+  if (client) {
+    server.write(client.read());
+  }
+}
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/ServerConstructor.html b/arduino-0018-linux/reference/ServerConstructor.html new file mode 100644 index 0000000..4164daa --- /dev/null +++ b/arduino-0018-linux/reference/ServerConstructor.html @@ -0,0 +1,113 @@ + + + + Arduino - ServerConstructor + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Ethernet : Server class +

+

Server()

+

Description

+

Create a server that listens for incoming connections on the specified port. +

+

Syntax

+

Server(port); +

+

Parameters

+

port: the port to listen on (int) +

+

Returns

+

None +

+

Example

+
+#include <Ethernet.h>
+
+// network configuration.  gateway and subnet are optional.
+byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
+byte ip[] = { 10, 0, 0, 177 };
+byte gateway[] = { 10, 0, 0, 1 };
+byte subnet[] = { 255, 255, 0, 0 };
+
+// telnet defaults to port 23
+Server server = Server(23);
+
+void setup()
+{
+  // initialize the ethernet device
+  Ethernet.begin(mac, ip, gateway, subnet);
+
+  // start listening for clients
+  server.begin();
+}
+
+void loop()
+{
+  Client client = server.available();
+  if (client) {
+    server.write(client.read());
+  }
+}
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/ServerPrint.html b/arduino-0018-linux/reference/ServerPrint.html new file mode 100644 index 0000000..747524e --- /dev/null +++ b/arduino-0018-linux/reference/ServerPrint.html @@ -0,0 +1,85 @@ + + + + Arduino - ServerPrint + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Ethernet : Server class +

+

print()

+

Description

+

Print data to all the clients connected to a server. Prints numbers as a sequence of digits, each an ASCII character (e.g. the number 123 is sent as the three characters '1', '2', '3'). +

+

Syntax

+

server.print(data)
server.print(data, BASE) +

+

Parameters

+

data: the data to print (char, byte, int, long, or string) +

+

BASE (optional): the base in which to print numbers: BIN for binary (base 2), DEC for decimal (base 10), OCT for octal (base 8), HEX for hexadecimal (base 16). +

+

Example

+
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/ServerPrintln.html b/arduino-0018-linux/reference/ServerPrintln.html new file mode 100644 index 0000000..0bf8a46 --- /dev/null +++ b/arduino-0018-linux/reference/ServerPrintln.html @@ -0,0 +1,85 @@ + + + + Arduino - ServerPrintln + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Ethernet : Server class +

+

println()

+

Description

+

Print data, followed by a newline, to all the clients connected to a server. Prints numbers as a sequence of digits, each an ASCII character (e.g. the number 123 is sent as the three characters '1', '2', '3'). +

+

Syntax

+

server.println()
server.println(data)
server.println(data, BASE) +

+

Parameters

+

data (optional): the data to print (char, byte, int, long, or string) +

+

BASE (optional): the base in which to print numbers: BIN for binary (base 2), DEC for decimal (base 10), OCT for octal (base 8), HEX for hexadecimal (base 16). +

+

Example

+
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/ServerWrite.html b/arduino-0018-linux/reference/ServerWrite.html new file mode 100644 index 0000000..fc42015 --- /dev/null +++ b/arduino-0018-linux/reference/ServerWrite.html @@ -0,0 +1,113 @@ + + + + Arduino - ServerWrite + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Ethernet : Server class +

+

write()

+

Description

+

Write data to all the clients connected to a server. +

+

Syntax

+

server.write(data) +

+

Parameters

+

data: the value to write (byte or char) +

+

Returns

+

None +

+

Example

+
+#include <Ethernet.h>
+
+// network configuration.  gateway and subnet are optional.
+byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
+byte ip[] = { 10, 0, 0, 177 };
+byte gateway[] = { 10, 0, 0, 1 };
+byte subnet[] = { 255, 255, 0, 0 };
+
+// telnet defaults to port 23
+Server server = Server(23);
+
+void setup()
+{
+  // initialize the ethernet device
+  Ethernet.begin(mac, ip, gateway, subnet);
+
+  // start listening for clients
+  server.begin();
+}
+
+void loop()
+{
+  Client client = server.available();
+  if (client) {
+    server.write(client.read());
+  }
+}
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Servo.html b/arduino-0018-linux/reference/Servo.html new file mode 100644 index 0000000..2376fb3 --- /dev/null +++ b/arduino-0018-linux/reference/Servo.html @@ -0,0 +1,86 @@ + + + + Arduino - Servo + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Servo library

+

This library allows an Arduino board to control RC (hobby) servo motors. Servos have integrated gears and a shaft that can precisely controlled. Standard servos allow the shaft to be positioned at various angles, usually between 0 and 180 degrees. Continuous rotation servos allow the rotation of the shaft to be set to various speeds. +

+

As of Arduino 0017, the Servo library supports up to 12 motors on most Arduino boards and 48 on the Arduino Mega. On boards other than the Mega, use of the library disables analogWrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on those pins. On the Mega, up to 12 servos can be used without interfering with PWM functionality; use of 12 to 23 motors will disable PWM on pins 11 and 12. +

+

In Arduino 0016 and earlier, the Servo library uses functionality built in to the hardware, and works only on pins 9 and 10 (and does not work on the Arduino Mega). In this case, if only one servo is used, the other pin cannot be used for normal PWM output with analogWrite(). For example, in Arduino 0016 and earlier, you can't have a servo on pin 9 and PWM output on pin 10. +

+

Circuit

+

Servo motors have three wires: power, ground, and signal. The power wire is typically red, and should be connected to the 5V pin on the Arduino board. The ground wire is typically black or brown and should be connected to a ground pin on the Arduino board. The signal pin is typically yellow, orange or white and should be connected to a digital pin on the Arduino board. Note servos draw considerable power, so if you need to drive more than one or two, you'll probably need to power them from a separate supply (i.e. not the +5V pin on your Arduino). Be sure to connect the grounds of the Arduino and external power supply together. +

+

Functions

+

Examples

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/ServoAttach.html b/arduino-0018-linux/reference/ServoAttach.html new file mode 100644 index 0000000..679e0b5 --- /dev/null +++ b/arduino-0018-linux/reference/ServoAttach.html @@ -0,0 +1,102 @@ + + + + Arduino - ServoAttach + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Servo +

+

attach()

+

Description

+

Attach the Servo variable to a pin. Note that in Arduino 0016 and earlier, the Servo library supports only servos on only two pins: 9 and 10. +

+

Syntax

+

servo.attach(pin)
servo.attach(pin, min, max) +

+

Parameters

+

servo: a variable of type Servo +

+

pin: the number of the pin that the servo is attached to +

+

min (optional): the pulse width, in microseconds, corresponding to the minimum (0-degree) angle on the servo (defaults to 544) +

+

max (optional): the pulse width, in microseconds, corresponding to the maximum (180-degree) angle on the servo (defaults to 2400) +

+

Example

+
+#include <Servo.h> 
+
+Servo myservo;
+
+void setup() 
+{ 
+  myservo.attach(9);
+} 
+
+void loop() {} 
+
+
+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/ServoAttached.html b/arduino-0018-linux/reference/ServoAttached.html new file mode 100644 index 0000000..e7157e9 --- /dev/null +++ b/arduino-0018-linux/reference/ServoAttached.html @@ -0,0 +1,85 @@ + + + + Arduino - ServoAttached + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Servo +

+

attached()

+

Description

+

Check whether the Servo variable is attached to a pin. +

+

Syntax

+

servo.attached() +

+

Parameters

+

servo: a variable of type Servo +

+

Returns

+

true if the servo is attached to pin; false otherwise. +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/ServoDetach.html b/arduino-0018-linux/reference/ServoDetach.html new file mode 100644 index 0000000..08038fc --- /dev/null +++ b/arduino-0018-linux/reference/ServoDetach.html @@ -0,0 +1,82 @@ + + + + Arduino - ServoDetach + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Servo +

+

detach()

+

Description

+

Detach the Servo variable from its pin. If all Servo variables are detached, then pins 9 and 10 can be used for PWM output with analogWrite(). +

+

Syntax

+

servo.detach() +

+

Parameters

+

servo: a variable of type Servo +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/ServoRead.html b/arduino-0018-linux/reference/ServoRead.html new file mode 100644 index 0000000..0d1d2e9 --- /dev/null +++ b/arduino-0018-linux/reference/ServoRead.html @@ -0,0 +1,84 @@ + + + + Arduino - ServoRead + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Servo +

+

read()

+

Description

+

Read the current angle of the servo (the value passed to the last call to write()). +

+

Syntax

+

servo.read() +

+

Parameters

+

servo: a variable of type Servo +

+

Returns

+

The angle of the servo, from 0 to 180 degrees. +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/ServoWrite.html b/arduino-0018-linux/reference/ServoWrite.html new file mode 100644 index 0000000..16412d2 --- /dev/null +++ b/arduino-0018-linux/reference/ServoWrite.html @@ -0,0 +1,99 @@ + + + + Arduino - ServoWrite + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Servo +

+

write()

+

Description

+

Writes a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with 0 being full-speed in one direction, 180 being full speed in the other, and a value near 90 being no movement). +

+

Syntax

+

servo.write(angle) +

+

Parameters

+

servo: a variable of type Servo +

+

angle: the value to write to the servo, from 0 to 180 +

+

Example

+
+#include <Servo.h> 
+
+Servo myservo;
+
+void setup() 
+{ 
+  myservo.attach(9);
+  myservo.write(90);  // set servo to mid-point
+} 
+
+void loop() {} 
+
+
+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/ServoWriteMicroseconds.html b/arduino-0018-linux/reference/ServoWriteMicroseconds.html new file mode 100644 index 0000000..9fee605 --- /dev/null +++ b/arduino-0018-linux/reference/ServoWriteMicroseconds.html @@ -0,0 +1,103 @@ + + + + Arduino - ServoWriteMicroseconds + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Servo +

+

writeMicroseconds()

+

Description

+

Writes a value in microseconds (uS) to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft. On standard servos a parameter value of 1000 is fully counter-clockwise, 2000 is fully clockwise, and 1500 is in the middle. +

+

Note that some manufactures do not follow this standard very closely so that servos often respond to values between 700 and 2300. Feel free to increase these endpoints until the servo no longer continues to increase its range. Note however that attempting to drive a servo past its endpoints (often indicated by a growling sound) is a high-current state, and should be avoided. +

+

Continuous-rotation servos will respond to the writeMicrosecond function in an analogous manner to the write function. +

+

Syntax

+

servo.writeMicroseconds(uS) +

+

Parameters

+

servo: a variable of type Servo +

+

uS: the value of the parameter in microseconds (int) +

+

Example

+
+#include <Servo.h> 
+
+Servo myservo;
+
+void setup() 
+{ 
+  myservo.attach(9);
+  myservo.writeMicroseconds(1500);  // set servo to mid-point
+} 
+
+void loop() {} 
+
+
+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Setup.html b/arduino-0018-linux/reference/Setup.html new file mode 100644 index 0000000..3099ede --- /dev/null +++ b/arduino-0018-linux/reference/Setup.html @@ -0,0 +1,86 @@ + + + + Arduino - Setup + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

setup()

+

The setup() function is called when a sketch starts. Use it to initialize variables, pin modes, start using libraries, etc. The setup function will only run once, after each powerup or reset of the Arduino board. +

+

Example

+
 
+int buttonPin = 3;
+
+void setup()
+{
+  Serial.begin(9600);
+  pinMode(buttonPin, INPUT);
+}
+
+void loop()
+{
+  // ...
+}
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/ShiftOut.html b/arduino-0018-linux/reference/ShiftOut.html new file mode 100644 index 0000000..12925c7 --- /dev/null +++ b/arduino-0018-linux/reference/ShiftOut.html @@ -0,0 +1,146 @@ + + + + Arduino - ShiftOut + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

shiftOut()

+

Description

+

Shifts out a byte of data one bit at a time. Starts from either the most (i.e. the leftmost) or least (rightmost) significant bit. Each bit is written in turn to a data pin, after which a clock pin is toggled to indicate that the bit is available. +

+

This is known as synchronous serial protocol and is a common way that microcontrollers communicate with sensors, and with other microcontrollers. The two devices stay synchronized, and communicate at close to maximum speeds, since they both share the same clock line. This is often referred to in chip hardware documentation as Serial Peripheral Interface (SPI). +

+

Syntax

+

shiftOut(dataPin, clockPin, bitOrder, value) +

+

Parameters

+

dataPin: the pin on which to output each bit (int) +

+

clockPin: the pin to toggle once the dataPin has been set to the correct value (int) +

+

bitOrder: which order to shift out the bits; either MSBFIRST or LSBFIRST.
(Most Significant Bit First, or, Least Significant Bit First) +

+

value: the data to shift out. (byte) +

+

Returns

+

None +

+

Note

+

The dataPin and clockPin must already be configured as outputs by a call to pinMode(). +

+

shiftOut is currently written to output 1 byte (8 bits) so it requires a two step operation to output values larger than 255. +

+// Do this for MSBFIRST serial
+int data = 500;
+// shift out highbyte
+shiftOut(dataPin, clock, MSBFIRST, (data >> 8));  
+// shift out lowbyte
+shiftOut(data, clock, MSBFIRST, data);
+
+// Or do this for LSBFIRST serial
+data = 500;
+// shift out lowbyte
+shiftOut(dataPin, clock, LSBFIRST, data);  
+// shift out highbyte 
+shiftOut(dataPin, clock, LSBFIRST, (data >> 8)); 
+
+

Example

+

For accompanying circuit, see the tutorial on controlling a 74HC595 shift register. +

+

//**************************************************************//
+//  Name    : shiftOutCode, Hello World                         //
+//  Author  : Carlyn Maw,Tom Igoe                               //
+//  Date    : 25 Oct, 2006                                      //
+//  Version : 1.0                                               //
+//  Notes   : Code for using a 74HC595 Shift Register           //
+//          : to count from 0 to 255                            //
+//****************************************************************
+
+//Pin connected to ST_CP of 74HC595
+int latchPin = 8;
+//Pin connected to SH_CP of 74HC595
+int clockPin = 12;
+////Pin connected to DS of 74HC595
+int dataPin = 11;
+
+void setup() {
+  //set pins to output because they are addressed in the main loop
+  pinMode(latchPin, OUTPUT);
+  pinMode(clockPin, OUTPUT);
+  pinMode(dataPin, OUTPUT);
+}
+
+void loop() {
+  //count up routine
+  for (int j = 0; j < 256; j++) {
+    //ground latchPin and hold low for as long as you are transmitting
+    digitalWrite(latchPin, LOW);
+    shiftOut(dataPin, clockPin, LSBFIRST, j);   
+    //return the latch pin high to signal chip that it 
+    //no longer needs to listen for information
+    digitalWrite(latchPin, HIGH);
+    delay(1000);
+  }
+} 
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Sin.html b/arduino-0018-linux/reference/Sin.html new file mode 100644 index 0000000..3d07f48 --- /dev/null +++ b/arduino-0018-linux/reference/Sin.html @@ -0,0 +1,85 @@ + + + + Arduino - Sin + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

sin(rad)

+

Description

+

Calculates the sine of an angle (in radians). The result will be between -1 and 1. +

+

Parameters

+

rad: the angle in radians (float) +

+

Returns

+

the sine of the angle (double) +

+

Note

+

Serial.print() and Serial.println() do not currently support printing floats. +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Sizeof.html b/arduino-0018-linux/reference/Sizeof.html new file mode 100644 index 0000000..e526ad2 --- /dev/null +++ b/arduino-0018-linux/reference/Sizeof.html @@ -0,0 +1,107 @@ + + + + Arduino - Sizeof + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

sizeof

+

Description

+

The sizeof operator returns the number of bytes in a variable type, or the number of bytes occupied by an array. +

+

Syntax

+

sizeof(variable) +

+

Parameters

+

variable: any variable type or array (e.g. int, float, byte) +

+

Example code

+

The sizeof operator is useful for dealing with arrays (such as strings) where it is convenient to be able to change the size of the array without breaking other parts of the program. +

+

This program prints out a text string one character at a time. Try changing the text phrase. +

+

+char myStr[] = "this is a test";
+int i;
+
+void setup(){
+  Serial.begin(9600);
+}
+
+void loop() { 
+  for (i = 0; i < sizeof(myStr) - 1; i++){
+    Serial.print(i, DEC);
+    Serial.print(" = ");
+    Serial.println(myStr[i], BYTE);
+  }
+}
+
+
+

Note that sizeof returns the total number of bytes. So for larger variable types such as ints, the for loop would look something like this. +

+

+for (i = 0; i < (sizeof(myInts)/sizeof(int)) - 1; i++) {
+  // do something with myInts[i]
+}
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/SoftwareSerial.html b/arduino-0018-linux/reference/SoftwareSerial.html new file mode 100644 index 0000000..5f4ad92 --- /dev/null +++ b/arduino-0018-linux/reference/SoftwareSerial.html @@ -0,0 +1,91 @@ + + + + Arduino - SoftwareSerial + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

SoftwareSerial Library

+

The Arduino hardware has built-in support for serial communication on pins 0 and 1 (which also goes to the computer via the USB connection). The native serial support happens via a piece of hardware (built into the chip) called a UART. This hardware allows the Atmega chip to receive serial communication even while working on other tasks, as long as there room in the 64 byte serial buffer. +

+

The SoftwareSerial library has been developed to allow serial communication on other digital pins of the Arduino, using software to replicate the functionality (hence the name "SoftwareSerial"). +

+

Limitations

+

Because it's not supported by hardware, the library has a few limitations: +

+

  • Only speeds up to 9600 baud work +
  • Serial.available() doesn't work +
  • Serial.read() will wait until data arrives +
  • Only data received while Serial.read() is being called will be received. Data received at other times will be lost, since the chip is not "listening". +

SoftwareSerial appears to have some timing issues and/or software issues. Check this forum thread for discussion. +Software Serial Discussion. In particular, if you are having problems using SoftwareSerial with an Atmega168 chip delete SoftwareSerial.o in your Arduino directory. +

+

Example

+
 SoftwareSerialExample
+
+

Functions

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/SoftwareSerialBegin.html b/arduino-0018-linux/reference/SoftwareSerialBegin.html new file mode 100644 index 0000000..8cb8f3b --- /dev/null +++ b/arduino-0018-linux/reference/SoftwareSerialBegin.html @@ -0,0 +1,105 @@ + + + + Arduino - SoftwareSerialBegin + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

SoftwareSerial: begin(speed)

+

Description

+

Sets the speed (baud rate) for the serial communication. Using speeds higher than 9600 baud will result in faulty communication. +

+

Parameters

+

speed: the baud rate (long) +

+

Returns

+

none +

+

Example

+
// include the SoftwareSerial library so you can use its functions:
+#include <SoftwareSerial.h>
+
+#define rxPin 2
+#define txPin 3
+
+// set up a new serial port
+SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);
+
+void setup()  {
+  // define pin modes for tx, rx:
+  pinMode(rxPin, INPUT);
+  pinMode(txPin, OUTPUT);
+  // set the data rate for the SoftwareSerial port
+  mySerial.begin(9600);
+}
+
+void loop() {
+  // ...
+}
+
+
+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/SoftwareSerialConstructor.html b/arduino-0018-linux/reference/SoftwareSerialConstructor.html new file mode 100644 index 0000000..051ea59 --- /dev/null +++ b/arduino-0018-linux/reference/SoftwareSerialConstructor.html @@ -0,0 +1,88 @@ + + + + Arduino - SoftwareSerialConstructor + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

SoftwareSerial(rxPin, txPin)

+

Description

+

A call to SoftwareSerial(rxPin, txPin) creates a new SoftwareSerial object, whose name you need to provide as in the example below. You still need to call SoftwareSerial.begin(). +

+

Parameters

+

rxPin: the pin on which to receive serial data +

+

txPin: the pin on which to transmit serial data +

+

Example

+
#define rxPin 2
+#define txPin 3
+
+// set up a new serial port
+SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);
+
+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/SoftwareSerialExample.html b/arduino-0018-linux/reference/SoftwareSerialExample.html new file mode 100644 index 0000000..da69d58 --- /dev/null +++ b/arduino-0018-linux/reference/SoftwareSerialExample.html @@ -0,0 +1,124 @@ + + + + Arduino - SoftwareSerialExample + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

This is a very basic example of SoftwareSerial. It reads in a byte at a time and mirrors it back to you: +

+

+/*
+  SoftwareSerial example
+
+  Sample of the SoftwareSerial library.  Listens for serial in on pin 2
+  and sends it out again on pin 3.
+
+  by Tom Igoe
+  based on examples by David Mellis and Heather Dewey-Hagborg
+  written: 6 Jan 2007
+
+
+*/
+
+// include the SoftwareSerial library so you can use its functions:
+#include <SoftwareSerial.h>
+
+#define rxPin 2
+#define txPin 3
+#define ledPin 13
+
+// set up a new serial port
+SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);
+byte pinState = 0;
+
+void setup()  {
+  // define pin modes for tx, rx, led pins:
+  pinMode(rxPin, INPUT);
+  pinMode(txPin, OUTPUT);
+  pinMode(ledPin, OUTPUT);
+  // set the data rate for the SoftwareSerial port
+  mySerial.begin(9600);
+}
+
+void loop() {
+  // listen for new serial coming in:
+  char someChar = mySerial.read();
+  // print out the character:
+  mySerial.print(someChar);
+  // toggle an LED just so you see the thing's alive.  
+  // this LED will go on with every OTHER character received:
+  toggle(13);
+
+}
+
+
+void toggle(int pinNum) {
+  // set the LED pin using the pinState variable:
+  digitalWrite(pinNum, pinState); 
+  // if pinState = 0, set it to 1, and vice versa:
+  pinState = !pinState;
+}
+
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/SoftwareSerialPrint.html b/arduino-0018-linux/reference/SoftwareSerialPrint.html new file mode 100644 index 0000000..00ffe99 --- /dev/null +++ b/arduino-0018-linux/reference/SoftwareSerialPrint.html @@ -0,0 +1,118 @@ + + + + Arduino - SoftwareSerialPrint + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

SoftwareSerial: print(data)

+

Description

+

Prints data to the transmit pin of the software serial port. Works the same as the Serial.print() function. +

+

Parameters

+

vary, see Serial.print() for details +

+

Returns

+

none +

+

Example

+
SoftwareSerial serial(6, 7);
+int analogValue;
+
+void setup()
+{
+  serial.begin(9600);
+}
+
+void loop()
+{
+  // read the analog input on pin 0:
+  analogValue = analogRead(0);
+
+  // print it out in many formats:
+  serial.print(analogValue);         // print as an ASCII-encoded decimal
+  serial.print("\t");                // print a tab character
+  serial.print(analogValue, DEC);    // print as an ASCII-encoded decimal
+  serial.print("\t");                // print a tab character
+  serial.print(analogValue, HEX);    // print as an ASCII-encoded hexadecimal
+  serial.print("\t");                // print a tab character
+  serial.print(analogValue, OCT);    // print as an ASCII-encoded octal
+  serial.print("\t");                // print a tab character
+  serial.print(analogValue, BIN);    // print as an ASCII-encoded binary
+  serial.print("\t");                // print a tab character
+  serial.print(analogValue/4, BYTE); // print as a raw byte value (divide the
+                                     // value by 4 because analogRead() returns numbers
+                                     // from 0 to 1023, but a byte can only hold values
+                                     // up to 255)
+  serial.print("\t");                // print a tab character    
+  serial.println();                  // print a linefeed character
+
+  // delay 10 milliseconds before the next reading:
+  delay(10);
+} 
+
+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/SoftwareSerialPrintln.html b/arduino-0018-linux/reference/SoftwareSerialPrintln.html new file mode 100644 index 0000000..25a97c2 --- /dev/null +++ b/arduino-0018-linux/reference/SoftwareSerialPrintln.html @@ -0,0 +1,118 @@ + + + + Arduino - SoftwareSerialPrintln + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

SoftwareSerial: println(data)

+

Description

+

Prints data to the transmit pin of the software serial port, followed by a carriage return and line feed. Works the same as the Serial.println() function. +

+

Parameters

+

vary, see Serial.println() for details +

+

Returns

+

none +

+

Example

+
SoftwareSerial serial(6, 7);
+int analogValue;
+
+void setup()
+{
+  serial.begin(9600);
+}
+
+void loop()
+{
+  // read the analog input on pin 0:
+  analogValue = analogRead(0);
+
+  // print it out in many formats:
+  serial.print(analogValue);         // print as an ASCII-encoded decimal
+  serial.print("\t");                // print a tab character
+  serial.print(analogValue, DEC);    // print as an ASCII-encoded decimal
+  serial.print("\t");                // print a tab character
+  serial.print(analogValue, HEX);    // print as an ASCII-encoded hexadecimal
+  serial.print("\t");                // print a tab character
+  serial.print(analogValue, OCT);    // print as an ASCII-encoded octal
+  serial.print("\t");                // print a tab character
+  serial.print(analogValue, BIN);    // print as an ASCII-encoded binary
+  serial.print("\t");                // print a tab character
+  serial.print(analogValue/4, BYTE); // print as a raw byte value (divide the
+                                     // value by 4 because analogRead() returns numbers
+                                     // from 0 to 1023, but a byte can only hold values
+                                     // up to 255)
+  serial.print("\t");                // print a tab character    
+  serial.println();                  // print a linefeed character
+
+  // delay 10 milliseconds before the next reading:
+  delay(10);
+} 
+
+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/SoftwareSerialRead.html b/arduino-0018-linux/reference/SoftwareSerialRead.html new file mode 100644 index 0000000..4d7c0b9 --- /dev/null +++ b/arduino-0018-linux/reference/SoftwareSerialRead.html @@ -0,0 +1,95 @@ + + + + Arduino - SoftwareSerialRead + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

SoftwareSerial: int read()

+

Description

+

Reads a character from the receive pin of the software serial port. This function waits for a character to arrive, reads it, and returns the character read. Data that arrives at other times is lost. +

+

Parameters

+

none +

+

Returns

+

the character read +

+

Example

+
SoftwareSerial serial(6, 7);
+
+void setup()
+{
+  serial.begin(9600);
+}
+
+void loop()
+{
+  char c = serial.read();
+} 
+
+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Sq.html b/arduino-0018-linux/reference/Sq.html new file mode 100644 index 0000000..171b570 --- /dev/null +++ b/arduino-0018-linux/reference/Sq.html @@ -0,0 +1,80 @@ + + + + Arduino - Sq + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

sq(x)

+

Description

+

Calculates the square of a number: the number multiplied by itself. +

+

Parameters

+

x: the number, any data type +

+

Returns

+

the square of the number +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Sqrt.html b/arduino-0018-linux/reference/Sqrt.html new file mode 100644 index 0000000..6096bb1 --- /dev/null +++ b/arduino-0018-linux/reference/Sqrt.html @@ -0,0 +1,80 @@ + + + + Arduino - Sqrt + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

sqrt(x)

+

Description

+

Calculates the square root of a number. +

+

Parameters

+

x: the number, any data type +

+

Returns

+

double, the number's square root. +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Static.html b/arduino-0018-linux/reference/Static.html new file mode 100644 index 0000000..b135661 --- /dev/null +++ b/arduino-0018-linux/reference/Static.html @@ -0,0 +1,123 @@ + + + + Arduino - Static + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Static

+

The static keyword is used to create variables that are visible to only one function. However unlike local variables that get created and destroyed every time a function is called, static variables persist beyond the function call, preserving their data between function calls. +

+

Variables declared as static will only be created and initialized the first time a function is called. +

+

Example

+
+
+
+/* RandomWalk
+* Paul Badger 2007
+* RandomWalk wanders up and down randomly between two
+* endpoints. The maximum move in one loop is governed by
+* the parameter "stepsize".
+* A static variable is moved up and down a random amount.
+* This technique is also known as "pink noise" and "drunken walk".
+*/
+
+#define randomWalkLowRange -20
+#define randomWalkHighRange 20
+int stepsize;
+
+int thisTime;
+int total;
+
+void setup()
+{
+  Serial.begin(9600);
+}
+
+void loop()
+{        //  tetst randomWalk function
+  stepsize = 5;
+  thisTime = randomWalk(stepsize);
+  Serial.println(thisTime);
+   delay(10);
+}
+
+int randomWalk(int moveSize){
+  static int  place;     // variable to store value in random walk - declared static so that it stores
+                         // values in between function calls, but no other functions can change its value
+
+  place = place + (random(-moveSize, moveSize + 1));
+
+  if (place < randomWalkLowRange){                    // check lower and upper limits
+    place = place + (randomWalkLowRange - place);     // reflect number back in positive direction
+  }
+  else if(place > randomWalkHighRange){
+    place = place - (place - randomWalkHighRange);     // reflect number back in negative direction
+  }
+
+  return place;
+}
+
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Stepper.html b/arduino-0018-linux/reference/Stepper.html new file mode 100644 index 0000000..e07956d --- /dev/null +++ b/arduino-0018-linux/reference/Stepper.html @@ -0,0 +1,80 @@ + + + + Arduino - Stepper + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Stepper Library

+

This library allows you to control unipolar or bipolar stepper motors. To use it you will need a stepper motor, and the appropriate hardware to control it. For more on that, see Tom Igoe's notes on steppers. +

+

Circuits

+

Functions

+

Example

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/StepperBipolarCircuit.html b/arduino-0018-linux/reference/StepperBipolarCircuit.html new file mode 100644 index 0000000..883bde7 --- /dev/null +++ b/arduino-0018-linux/reference/StepperBipolarCircuit.html @@ -0,0 +1,72 @@ + + + + Arduino - StepperBipolarCircuit + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Circuit for Bipolar Stepper Motor

+

Two Pins

+
+

Four Pins

+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/StepperConstructor.html b/arduino-0018-linux/reference/StepperConstructor.html new file mode 100644 index 0000000..bbecb2e --- /dev/null +++ b/arduino-0018-linux/reference/StepperConstructor.html @@ -0,0 +1,88 @@ + + + + Arduino - StepperConstructor + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Stepper(steps, pin1, pin2)

+

Stepper(steps, pin1, pin2, pin3, pin4)

+

Description

+

This function creates a new instance of the Stepper class that represents a particular stepper motor attached to your Arduino board. Use it at the top of your sketch, above setup() and loop(). The number of parameters depends on how you've wired your motor - either using two or four pins of the Arduino board. +

+

Parameters

+

steps: the number of steps in one revolution of your motor. If your motor gives the number of degrees per step, divide that number into 360 to get the number of steps (e.g. 360 / 3.6 gives 100 steps). (int) +

+

pin1, pin2: two pins that are attached to the motor (int) +

+

pin3, pin4: optional the last two pins attached to the motor, if it's connected to four pins (int) +

+

Returns

+

A new instance of the Stepper motor class. +

+

Example

+

Stepper myStepper = Stepper(100, 5, 6); +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/StepperExample.html b/arduino-0018-linux/reference/StepperExample.html new file mode 100644 index 0000000..6968f5b --- /dev/null +++ b/arduino-0018-linux/reference/StepperExample.html @@ -0,0 +1,108 @@ + + + + Arduino - StepperExample + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison +

+

Stepper Library Example Sketch

+

Description

+

A stepper motor follows the turns of a potentiometer (or other sensor) on analog input 0. The unipolar or bipolar stepper is controlled with pins 8, 9, 10, and 11, using one of the circuits on the linked pages. +

+

Code

+
+#include <Stepper.h>
+
+// change this to the number of steps on your motor
+#define STEPS 100
+
+// create an instance of the stepper class, specifying
+// the number of steps of the motor and the pins it's
+// attached to
+Stepper stepper(STEPS, 8, 9, 10, 11);
+
+// the previous reading from the analog input
+int previous = 0;
+
+void setup()
+{
+  // set the speed of the motor to 30 RPMs
+  stepper.setSpeed(30);
+}
+
+void loop()
+{
+  // get the sensor value
+  int val = analogRead(0);
+
+  // move a number of steps equal to the change in the
+  // sensor reading
+  stepper.step(val - previous);
+
+  // remember the previous value of the sensor
+  previous = val;
+}
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/StepperSetSpeed.html b/arduino-0018-linux/reference/StepperSetSpeed.html new file mode 100644 index 0000000..3ba8b06 --- /dev/null +++ b/arduino-0018-linux/reference/StepperSetSpeed.html @@ -0,0 +1,81 @@ + + + + Arduino - StepperSetSpeed + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Stepper: setSpeed(rpms)

+

Description

+

Sets the motor speed in rotations per minute (RPMs). This function doesn't make the motor turn, just sets the speed at which it will when you call step(). +

+

Parameters

+

rpms: the speed at which the motor should turn in rotations per minute - a positive number (long) +

+

Returns

+

None +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/StepperStep.html b/arduino-0018-linux/reference/StepperStep.html new file mode 100644 index 0000000..847ba44 --- /dev/null +++ b/arduino-0018-linux/reference/StepperStep.html @@ -0,0 +1,81 @@ + + + + Arduino - StepperStep + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Stepper: step(steps)

+

Description

+

Turns the motor a specific number of steps, at a speed determined by the most recent call to setSpeed(). This function is blocking; that is, it will wait until the motor has finished moving to pass control to the next line in your sketch. For example, if you set the speed to, say, 1 RPM and called step(100) on a 100-step motor, this function would take a full minute to run. For better control, keep the speed high and only go a few steps with each call to step(). +

+

Parameters

+

steps: the number of steps to turn the motor - positive to turn one direction, negative to turn the other (int) +

+

Returns

+

None +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/StepperUnipolarCircuit.html b/arduino-0018-linux/reference/StepperUnipolarCircuit.html new file mode 100644 index 0000000..921574f --- /dev/null +++ b/arduino-0018-linux/reference/StepperUnipolarCircuit.html @@ -0,0 +1,73 @@ + + + + Arduino - StepperUnipolarCircuit + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Circuits for Unipolar Stepper Motors

+

Two Pins

+
  
+
+

Four Pins

+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/String.html b/arduino-0018-linux/reference/String.html new file mode 100644 index 0000000..70cb5ec --- /dev/null +++ b/arduino-0018-linux/reference/String.html @@ -0,0 +1,138 @@ + + + + Arduino - String + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

string

+

Description

+

Strings are represented as arrays of type char and are null-terminated. +

+

Examples

+

All of the following are valid declarations for strings. +

+  char Str1[15];
+  char Str2[8] = {'a', 'r', 'd', 'u', 'i', 'n', 'o'};
+  char Str3[8] = {'a', 'r', 'd', 'u', 'i', 'n', 'o', '\0'};
+  char Str4[ ] = "arduino";
+  char Str5[8] = "arduino";
+  char Str6[15] = "arduino";
+
+
+

Possibilities for declaring strings +

+

  • Declare an array of chars without initializing it as in Str1 +
  • Declare an array of chars (with one extra char) and the compiler will add the required null character, as in Str2 +
  • Explicitly add the null character, Str3 +
  • Initialize with a string constant in quotation marks; the compiler will size the array to fit the string constant and a terminating null character, Str4 +
  • Initialize the array with an explicit size and string constant, Str5 +
  • Initialize the array, leaving extra space for a larger string, Str6 +

Null termination +

+

Generally, strings are terminated with a null character (ASCII code 0). This allows functions (like Serial.print()) to tell where the end of a string is. Otherwise, they would continue reading subsequent bytes of memory that aren't actually part of the string. +

+

This means that your string needs to have space for one more character than the text you want it to contain. That is why Str2 and Str5 need to be eight characters, even though "arduino" is only seven - the last position is automatically filled with a null character. Str4 will be automatically sized to eight characters, one for the extra null. In Str3, we've explicitly included the null character (written '\0') ourselves. +

+

Note that it's possible to have a string without a final null character (e.g. if you had specified the length of Str2 as seven instead of eight). This will break most functions that use strings, so you shouldn't do it intentionally. If you notice something behaving strangely (operating on characters not in the string), however, this could be the problem. +

+

Single quotes or double quotes? +

+

Strings are always defined inside double quotes ("Abc") and characters are always defined inside single quotes('A'). +

+

Wrapping long strings +

+

You can wrap long strings like this: +

+char myString[] = "This is the first line"
+" this is the second line"
+" etcetera";
+
+
+

Arrays of strings +

+

It is often convenient, when working with large amounts of text, such as a project with an LCD display, to setup an array of strings. Because strings themselves are arrays, this is in actually an example of a two-dimensional array. +

+

In the code below, the asterisk after the datatype char "char*" indicates that this is an array of "pointers". All array names are actually pointers, so this is required to make an array of arrays. Pointers are one of the more esoteric parts of C for beginners to understand, but it isn't necessary to understand pointers in detail to use them effectively here. +

+

Example

+
+
+char* myStrings[]={"This is string 1", "This is string 2", "This is string 3",
+"This is string 4", "This is string 5","This is string 6"};
+
+void setup(){
+Serial.begin(9600);
+}
+
+void loop(){
+for (int i = 0; i < 6; i++){
+   Serial.println(myStrings[i]);
+   delay(500);
+   }
+}
+
+

See Also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/StyleGuide.html b/arduino-0018-linux/reference/StyleGuide.html new file mode 100644 index 0000000..59ab3bb --- /dev/null +++ b/arduino-0018-linux/reference/StyleGuide.html @@ -0,0 +1,192 @@ + + + + Arduino - StyleGuide + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison +

+

Arduino style guide

+

This is a guide for writing clear Arduino examples that can be read by beginners and advanced users alike. You don't have to code this way, but it helps if you want your code to be clear to all levels of users. +

+

This is not a set of hard and fast rules, it's a set of guidelines. Some of these guidelines might even conflict with each other. Use your judgment on when they're best followed, and if you're not sure, ask someone who'll be learning from what you write what makes the most sense. +

+

Writing a tutorial (most of this is borrowed from various editors over the years)

+

Write in the active voice. +

+

Write clearly and conversationally, as if the person following your instructions were there in the room with you. +

+

When giving instruction, write in the second person, so the reader understands that she's the one who'll be doing it. +

+

Use short, simple sentences rather than compound sentences. It's easier for the reader to digest one instruction at a time. +

+

Use pictures and schematics rather than just schematics alone. Many electronics hobbyists don't read schematics +

+

Check your assumptions. Does the reader understand all the concepts you've used in your tutorial? If not, explain them or link to another tutorial that does. +

+

Explain things conceptually, then lay out instructions on how to use it step-by-step. +

+

Make your example do one thing well. Don't combine concepts unless it's a tutorial about combining concepts. +

+

Writing Example Code

+

Efficiency is not paramount; readability is. +

+

The most important users of Arduino are beginners and people who don't care about code, but about getting projects done. +

+

Think generously about people who know less than you about code. Don't think they should understand some technical concept. They don't, and they're not stupid for not understanding. Your code should explain itself, or use comments to do the same. If it needs a complex concept like registers or interrupts or pointers, either explain it or skip it. +

+

When forced to choose between technically simple and technically efficient, choose the former. +

+

Introduce concepts only when they are useful and try to minimize the number of new concepts you introduce in each example. For example, at the very beginning, you can explain simple functions with no variable types other than int, nor for consts to define pin numbers. On the other hand, in an intermediate example, you might want to introduce peripheral concepts as they become useful. Concepts like using const ints to define pin numbers, choosing bytes over ints when you don't need more than 0 - 255, etc. are useful, but not central to getting started. So use them sparingly, and explain them when they're new to your lesson plan. +

+

Put your setup() and your loop() at the beginning of the program. They help beginners to get an overview of the program, since all other functions are called from those two. +

+

Commenting Your Code

+

Comment every variable or constant declaration with a description of what the variable does. +

+

Comment every code block. Do it before the block if possible, so the reader knows what's coming +

+

Comment every for loop +

+

Use verbose if statements. For simplicity to the beginning reader, use the block format for everything, i.e. avoid this: +

+

+if (somethingIsTrue) doSomething;
+
+
+

Instead, use this: +

+if (somethingIsTrue == TRUE) {
+   doSomething;
+}
+
+
+

Avoid pointers +

+

Avoid #defines +

+

Variables

+

Avoid single letter variable names. Make them descriptive +

+

Avoid variable names like val or pin. Be more descriptive, like buttonState or switchPin +

+

If you want to define pin names and other quantities which won't change, use const ints. They're less messy than #defines, yet still give you a way to teach the difference between a variable and a constant. +

+

Use the wiring/Processing-style variable types, e.g. boolean,char,byte,int,unsigned int,long,unsigned long,float,double,string,array,void when possible, rather than uint8_t, etc. The former are explained in the documentation, and less terse names. +

+

Avoid numbering schemes that confuse the user, e.g.: +

+pin1 = 2
+pin2 = 3
+etc.
+
+
+

If you need to renumber pins, consider using an array, like this: +

+

+int myPins[] = { 2, 7, 6, 5, 4, 3 };
+
+
+

This allows you to refer to the new pin numbers using the array elements, like this: +

+

+  digitalWrite(myPins[1], HIGH);  // turns on pin 7
+
+
+

It also allows you to turn all the pins on or off in the sequence you want, like this: +

+

+for (int thisPin = 0; thisPin < 6; thisPin++) {
+   digitalWrite(myPins[thisPin], HIGH);
+   delay(500);
+   digitalWrite(myPins[thisPin], LOW);
+   delay(500);
+}
+
+
+

Explain the code at the start

+

Here's a good title block: +

+

		
+/*
+	Sketch title
+
+	Describe what it does in layman's terms.  Refer to the components
+	attached to the various pins.
+
+	The circuit:
+	* list the components attached to each input
+	* list the components attached to each output
+
+	Created day month year
+	By author's name
+	Modified day month year
+	By author's name
+
+	http://url/of/online/tutorial.cc
+
+*/
+
+

Circuits

+

For digital input switches, the default is to use a pulldown resistor on the switch rather than a pullup. That way, the logic of a switch's interaction makes sense to the non-engineer. +

+

Keep your circuits simple. For example, bypass capacitors are handy, but most simple inputs will work without them. If a component is incidental, explain it later. +

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/SwitchCase.html b/arduino-0018-linux/reference/SwitchCase.html new file mode 100644 index 0000000..009e66c --- /dev/null +++ b/arduino-0018-linux/reference/SwitchCase.html @@ -0,0 +1,109 @@ + + + + Arduino - SwitchCase + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

switch / case statements

+

Like if statements, switch...case controls the flow of programs by allowing programmers to specify different code that should be executed in various conditions. In particular, a switch statement compares the value of a variable to the values specified in case statements. When a case statement is found whose value matches that of the variable, the code in that case statement is run. +

+

The break keyword exits the switch statement, and is typically used at the end of each case. Without a break statement, the switch statement will continue executing the following expressions ("falling-through") until a break, or the end of the switch statement is reached. +

+

Example

+
+  switch (var) {
+    case 1:
+      //do something when var equals 1
+      break;
+    case 2:
+      //do something when var equals 2
+      break;
+    default: 
+      // if nothing else matches, do the default
+      // default is optional
+  }
+
+
+

Syntax

+
+switch (var) {
+  case label:
+    // statements
+    break;
+  case label:
+    // statements
+    break;
+  default: 
+    // statements
+}
+
+
+

Parameters

+

var: the variable whose value to compare to the various cases +

+

label: a value to compare the variable to +

+

See also:

+

if...else +

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Tan.html b/arduino-0018-linux/reference/Tan.html new file mode 100644 index 0000000..c08220f --- /dev/null +++ b/arduino-0018-linux/reference/Tan.html @@ -0,0 +1,85 @@ + + + + Arduino - Tan + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

tan(rad)

+

Description

+

Calculates the tangent of an angle (in radians). The result will be between negative infinity and infinity. +

+

Parameters

+

rad: the angle in radians (float) +

+

Returns

+

The tangent of the angle (double) +

+

Note

+

Serial.print() and Serial.println() do not currently support printing floats. +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Tone.html b/arduino-0018-linux/reference/Tone.html new file mode 100644 index 0000000..a5afc5e --- /dev/null +++ b/arduino-0018-linux/reference/Tone.html @@ -0,0 +1,90 @@ + + + + Arduino - Tone + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

tone()

+

Description

+

Generates a square wave of the specified frequency (and 50% duty cycle) on a pin. A duration can be specified, otherwise the wave continues until a call to noTone(). The pin can be connected to a piezo buzzer or other speaker to play tones. +

+

Only one tone can be generated at a time. If a tone is already playing on a different pin, the call to tone() will have no effect. If the tone is playing on the same pin, the call will set its frequency. +

+

Syntax

+

tone(pin, frequency)
tone(pin, frequency, duration) +

+

Parameters

+

pin: the pin on which to generate the tone +

+

frequency: the frequency of the tone in hertz +

+

duration: the duration of the tone in milliseconds (optional) +

+

Returns

+

nothing +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/UnsignedChar.html b/arduino-0018-linux/reference/UnsignedChar.html new file mode 100644 index 0000000..7862231 --- /dev/null +++ b/arduino-0018-linux/reference/UnsignedChar.html @@ -0,0 +1,83 @@ + + + + Arduino - UnsignedChar + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

unsigned char

+

Description

+

An unsigned data type that occupies 1 byte of memory. Same as the byte datatype. +

+

The unsigned char datatype encodes numbers from 0 to 255. +

+

For consistency of Arduino programming style, the byte data type is to be preferred. +

+

Example

+
    unsigned char myChar = 240;
+
+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/UnsignedInt.html b/arduino-0018-linux/reference/UnsignedInt.html new file mode 100644 index 0000000..be42ed5 --- /dev/null +++ b/arduino-0018-linux/reference/UnsignedInt.html @@ -0,0 +1,97 @@ + + + + Arduino - UnsignedInt + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

unsigned int

+

Description

+

Unsigned ints (unsigned integers) are the same as ints in +that they store a 2 byte value. Instead of storing negative numbers however they only store positive values, yielding a useful range of 0 to 65,535 (2^16) - 1). +

+

The difference between unsigned ints and (signed) ints, lies in the way the highest bit, sometimes refered to as the "sign" bit, is interpreted. In the Arduino int type (which is signed), if the high bit is a "1", the number is interpreted as a negative number, and the other 15 bits are interpreted with 2's complement math. +

+

Example

+
    unsigned int ledPin = 13;
+
+

Syntax

+
     unsigned int var = val;
+
+

  • var - your unsigned int variable name +
  • val - the value you assign to that variable +

Coding Tip

+

When variables are made to exceed their maximum capacity they "roll over" back to their minimum capacitiy, note that this happens in both directions +

+

   unsigned int x
+   x = 0;
+   x = x - 1;       // x now contains 65535 - rolls over in neg direction
+   x = x + 1;       // x now contains 0 - rolls over
+
+
+

See Also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/UnsignedLong.html b/arduino-0018-linux/reference/UnsignedLong.html new file mode 100644 index 0000000..0031049 --- /dev/null +++ b/arduino-0018-linux/reference/UnsignedLong.html @@ -0,0 +1,101 @@ + + + + Arduino - UnsignedLong + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

unsigned long

+

Description

+

Unsigned long variables are extended size variables for number storage, and store 32 bits (4 bytes). Unlike standard longs unsigned longs won't store negative numbers, making their range from 0 to 4,294,967,295 (2^32 - 1). +

+

Example

+
+unsigned long time;
+
+void setup()
+{
+  Serial.begin(9600);
+}
+
+void loop()
+{
+  Serial.print("Time: ");
+  time = millis();
+  //prints time since program started
+  Serial.println(time);
+  // wait a second so as not to send massive amounts of data
+  delay(1000);
+}
+
+

Syntax

+
    unsigned long var = val;
+
+

  • var - your long variable name +
  • val - the value you assign to that variable +

See Also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/VariableDeclaration.html b/arduino-0018-linux/reference/VariableDeclaration.html new file mode 100644 index 0000000..34ca959 --- /dev/null +++ b/arduino-0018-linux/reference/VariableDeclaration.html @@ -0,0 +1,113 @@ + + + + Arduino - VariableDeclaration + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Board +

+

Variables

+

A variable is a way of naming and storing a value for later use by the program, such as data from a analog pin set to input. (See pinMode for more on setting pins to input or output.) +

+

Declaring Variables

+

Before they are used, all variables have to be declared. Declaring a variable means defining its type, and optionally, setting an initial value (initializing the variable). Variables do not have to be initialized (assigned a value) when they are declared, but it is often useful. +

+

Programmers should consider the size of the numbers they wish to store in choosing variable types. Also the specific place that variables are declared influences how the program will see the variable. This is called variable scope. +

+

+int inputVariable1;
+int inputVariable2 = 0;     // both are correct
+
+
+

Using Variables

+

Once variables have been declared, they are used by setting the variable equal to the value one wishes to store with the assignment operator (single equal sign). The assignment operator tells the program to put whatever is on the right side of the equal sign into the variable on the left side. +

+

+inputVariable1 = 7;             // sets the variable named inputVariable1 to 7
+inputVariable2 = analogRead(2); // sets the variable named inputVariable2 to the 
+                                // (digitized) input voltage read from analog pin #2
+
+

Example

+

Once a variable has been set (assigned a value), you can test its value to see if it meets certain conditions, or you can use its value directly. For instance, the following code tests whether the inputVariable2 is less than 100, then sets a delay based on inputVariable2 which is a minimum of 100: +

+

+if (inputVariable2 < 100)
+{
+  inputVariable2 = 100;
+}
+
+delay(inputVariable2);
+
+

This example shows all three useful operations with variables. It tests the variable ( if (inputVariable2 < 100) ), it sets the variable if it passes the test ( inputVariable2 = 100 ), and it uses the value of the variable as an input to the delay() function ( delay(inputVariable2) ) +

+

Style Note: You should give your variables descriptive names, so as to make your code more readable. Variable names like tiltSensor or pushButton help you (and anyone else reading your code) understand what the variable represents. Variable names like var or value, on the other hand, do little to make your code readable. +

+

You can name a variable any word that is not already one of the keywords in Arduino. Avoid beginning variable names with numeral characters. +

+

Some variable types

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Void.html b/arduino-0018-linux/reference/Void.html new file mode 100644 index 0000000..cd847e9 --- /dev/null +++ b/arduino-0018-linux/reference/Void.html @@ -0,0 +1,89 @@ + + + + Arduino - Void + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

void

+

The void keyword is used only in function declarations. It indicates that the function is expected to return no information to the function from which it was called. +

+

Example:

+
+// actions are performed in the functions "setup" and "loop"
+// but  no information is reported to the larger program
+
+void setup()
+{
+  // ...
+}
+
+void loop()
+{
+  // ...
+}
+ 
+
+

See also

+

function declaration +

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Volatile.html b/arduino-0018-linux/reference/Volatile.html new file mode 100644 index 0000000..c35264d --- /dev/null +++ b/arduino-0018-linux/reference/Volatile.html @@ -0,0 +1,102 @@ + + + + Arduino - Volatile + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

volatile keyword

+

volatile is a keyword known as a variable qualifier, it is usually used before the datatype of a variable, to modify the way in which the compiler and subsequent program treats the variable. +

+

Declaring a variable volatile is a directive to the compiler. The compiler is software which translates your C/C++ code into the machine code, which are the real instructions for the Atmega chip in the Arduino. +

+

Specifically, it directs the compiler to load the variable from RAM and not from a storage register, which is a temporary memory location where program variables are stored and manipulated. Under certain conditions, the value for a variable stored in registers can be inaccurate. +

+

A variable should be declared volatile whenever its value can be changed by something beyond the control of the code section in which it appears, such as a concurrently executing thread. In the Arduino, the only place that this is likely to occur is in sections of code associated with interrupts, called an interrupt service routine. +

+

Example

+
+// toggles LED when interrupt pin changes state
+
+int pin = 13;
+volatile int state = LOW;
+
+void setup()
+{
+  pinMode(pin, OUTPUT);
+  attachInterrupt(0, blink, CHANGE);
+}
+
+void loop()
+{
+  digitalWrite(pin, state);
+}
+
+void blink()
+{
+  state = !state;
+}
+
+
+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/While.html b/arduino-0018-linux/reference/While.html new file mode 100644 index 0000000..8fe183e --- /dev/null +++ b/arduino-0018-linux/reference/While.html @@ -0,0 +1,88 @@ + + + + Arduino - While + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

while loops

+

Description

+

while loops will loop continuously, and infinitely, until the expression inside the parenthesis, () becomes false. Something must change the tested variable, or the while loop will never exit. This could be in your code, such as an incremented variable, or an external condition, such as testing a sensor. +

+

Syntax

+
while(expression){
+  // statement(s)
+}
+
+

Parameters

+

expression - a (boolean) C statement that evaluates to true or false +

+

Example

+
+var = 0;
+while(var < 200){
+  // do something repetitive 200 times
+  var++;
+}
+
+
+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Wire.html b/arduino-0018-linux/reference/Wire.html new file mode 100644 index 0000000..f3fd4af --- /dev/null +++ b/arduino-0018-linux/reference/Wire.html @@ -0,0 +1,84 @@ + + + + Arduino - Wire + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Wire Library

+

This library allows you to communicate with I2C / TWI devices. On most Arduino boards, SDA (data line) is on analog input pin 4, and SCL (clock line) is on analog input pin 5. On the Arduino Mega, SDA is digital pin 20 and SCL is 21. +

+

Functions

+

Note

+

There are both 7- and 8-bit versions of I2C addresses. 7 bits identify the device, and the eighth bit determines if it's being written to or read from. The Wire library uses 7 bit addresses throughout. If you have a datasheet or sample code that uses 8 bit address, you'll want to drop the low bit (i.e. shift the value one bit to the right), yielding an address between 0 and 127. +

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/WireAvailable.html b/arduino-0018-linux/reference/WireAvailable.html new file mode 100644 index 0000000..9ba2bb8 --- /dev/null +++ b/arduino-0018-linux/reference/WireAvailable.html @@ -0,0 +1,79 @@ + + + + Arduino - WireAvailable + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Wire.available()

+

Description

+

Returns the number of bytes available for retrieval with receive(). This should be called on a master device after a call to requestFrom() or on a slave inside the onReceive() handler. +

+

Parameters

+

None +

+

Returns

+

The number of bytes available for reading. +

+

See Also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/WireBegin.html b/arduino-0018-linux/reference/WireBegin.html new file mode 100644 index 0000000..c47a2ea --- /dev/null +++ b/arduino-0018-linux/reference/WireBegin.html @@ -0,0 +1,78 @@ + + + + Arduino - WireBegin + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Wire.begin()

+

Wire.begin(address)

+

Description

+

Initiate the Wire library and join the I2C bus as a master or slave. +

+

Parameters

+

address: the 7-bit slave address (optional); if not specified, join the bus as a master. +

+

Returns

+

None +

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/WireBeginTransmission.html b/arduino-0018-linux/reference/WireBeginTransmission.html new file mode 100644 index 0000000..5058661 --- /dev/null +++ b/arduino-0018-linux/reference/WireBeginTransmission.html @@ -0,0 +1,80 @@ + + + + Arduino - WireBeginTransmission + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Wire.beginTransmission(address)

+

Description

+

Begin a transmission to the I2C slave device with the given address. Subsequently, queue bytes for transmission with the send() function and transmit them by calling endTransmission(). +

+

Parameters

+

address: the 7-bit address of the device to transmit to +

+

Returns

+

None +

+

See Also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/WireEndTransmission.html b/arduino-0018-linux/reference/WireEndTransmission.html new file mode 100644 index 0000000..21d9371 --- /dev/null +++ b/arduino-0018-linux/reference/WireEndTransmission.html @@ -0,0 +1,80 @@ + + + + Arduino - WireEndTransmission + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Wire.endTransmission()

+

Description

+

Ends a transmission to a slave device that was begun by beginTransmission() and actually transmits the bytes that were queued by send(). +

+

Parameters

+

None +

+

Returns

+

None +

+

See Also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/WireOnReceive.html b/arduino-0018-linux/reference/WireOnReceive.html new file mode 100644 index 0000000..84f9f94 --- /dev/null +++ b/arduino-0018-linux/reference/WireOnReceive.html @@ -0,0 +1,79 @@ + + + + Arduino - WireOnReceive + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Wire.onReceive(handler)

+

Description

+

Registers a function to be called when a slave device receives a transmission from a master. +

+

Parameters

+

handler: the function to be called when the slave receives data; this should take a single int parameter (the number of bytes received from the master) and return nothing, e.g.: void myHandler(int numBytes) +

+

Returns

+

None +

+

See Also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/WireOnRequest.html b/arduino-0018-linux/reference/WireOnRequest.html new file mode 100644 index 0000000..a5845ca --- /dev/null +++ b/arduino-0018-linux/reference/WireOnRequest.html @@ -0,0 +1,79 @@ + + + + Arduino - WireOnRequest + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Wire.onRequest(handler)

+

Description

+

Register a function to be called when a master requests data from this slave device. +

+

Parameters

+

handler: the function to be called, takes no parameters and returns nothing, e.g.: void myHandler() +

+

Returns

+

None +

+

See Also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/WireReceive.html b/arduino-0018-linux/reference/WireReceive.html new file mode 100644 index 0000000..b92d4bf --- /dev/null +++ b/arduino-0018-linux/reference/WireReceive.html @@ -0,0 +1,79 @@ + + + + Arduino - WireReceive + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

byte Wire.receive()

+

Description

+

Retrieve a byte that was transmitted from a slave device to a master after a call to requestFrom or was transmitted from a master to a slave. +

+

Parameters

+

None +

+

Returns

+

The next byte received. +

+

See Also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/WireRequestFrom.html b/arduino-0018-linux/reference/WireRequestFrom.html new file mode 100644 index 0000000..ddf944d --- /dev/null +++ b/arduino-0018-linux/reference/WireRequestFrom.html @@ -0,0 +1,82 @@ + + + + Arduino - WireRequestFrom + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Wire.requestFrom(address, quantity)

+

Description

+

Request bytes from another device. The bytes may then be retrieved with the available() and receive() functions. +

+

Parameters

+

address: the 7-bit address of the device to request bytes from +

+

quantity: the number of bytes to request +

+

Returns

+

None +

+

See Also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/WireSend.html b/arduino-0018-linux/reference/WireSend.html new file mode 100644 index 0000000..e01a5fd --- /dev/null +++ b/arduino-0018-linux/reference/WireSend.html @@ -0,0 +1,88 @@ + + + + Arduino - WireSend + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Wire.send(value)

+

Wire.send(string)

+

Wire.send(data, quantity)

+

Description

+

Sends data from a slave device in response to a request from a master, or queues bytes for transmission from a master to slave device (in-between calls to beginTransmission() and endTransmission()). +

+

Parameters

+

value: a byte to send (byte) +

+

string: a string to send (char *) +

+

data: an array of data to send (byte *) +

+

quantity: the number of bytes of data to transmit (byte) +

+

Returns

+

None +

+

See Also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/Word.html b/arduino-0018-linux/reference/Word.html new file mode 100644 index 0000000..7c07959 --- /dev/null +++ b/arduino-0018-linux/reference/Word.html @@ -0,0 +1,77 @@ + + + + Arduino - Word + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

word

+

Description

+

A word stores a 16-bit unsigned number, from 0 to 65536. Same as an unsigned int. +

+

Example

+
    word w = 10000; 
+
+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/WordCast.html b/arduino-0018-linux/reference/WordCast.html new file mode 100644 index 0000000..add7654 --- /dev/null +++ b/arduino-0018-linux/reference/WordCast.html @@ -0,0 +1,86 @@ + + + + Arduino - WordCast + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

word()

+

Description

+

Convert a value to the word data type or create a word from two bytes. +

+

Syntax

+

word(x)
word(h, l) +

+

Parameters

+

x: a value of any type +

+

h: the high-order (leftmost) byte of the word +

+

l: the low-order (rightmost) byte of the word +

+

Returns

+

word +

+

See also

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/reference/arduino.css b/arduino-0018-linux/reference/arduino.css new file mode 100644 index 0000000..dc20f30 --- /dev/null +++ b/arduino-0018-linux/reference/arduino.css @@ -0,0 +1,140 @@ +body { + margin: 0px 20px 20px 20px; + padding: 0px 0px 0px 0px; + background-color: #aaa; + font-family: Verdana, Geneva, Arial, sans-serif; + font-size: 10px; + line-height: 15px; + xxxbackground: url(bg.gif) +} + +h1 { + font-family: Georgia, Times, serif; + color: #555; +} + +h2 { + font-family: Georgia, Times, serif; + color: #555; +} + +h3 { + font-family: Georgia, Times, serif; + color: #555; +} + +p ul li { + color: #555; +} + +a { + color: #111; +} + +hr { + border-top: 1px dotted #555; +} + +a:link { + text-decoration: none; + padding-bottom: 0px; + border-bottom: 1px solid #bbb; +} +a:visited { + text-decoration: none; + padding-bottom: 0px; + border-bottom: 1px solid #bbb; +} +a:active { + text-decoration: none; + padding-bottom: 0px; + border-bottom: 1px solid #bbb; +} +a:hover { + text-decoration: none; + padding-bottom: 0px; + background-color: #ddd; + border-bottom: none; +} + +a.selflink { + font-weight: bold; + text-decoration: none; + border-bottom: 0px solid white; +} + +#page { + width: 700px; +} + + +#pageheader { + height: 60px; + text-align: right; + padding-top: 40px; +} + +#pageheader .title { + float: left; + text-align: left; + margin-left: 20px; + font-family: Georgia, Times, serif; + padding-top: -19px; + font-size: 38px; + letter-spacing: 0px; + color: #fff; + font-weight: bold; + text-shadow: #aaa 0px 0px 5px; +} + +#pageheader .title a { + color: #fff; + border: none; +} + +#pageheader .title a:hover { + color: #fff; + border: none; + background-color: transparent; +} + +#pageheader .search { +} + +#pagenav { + background-color: #fff; + padding: 10px 20px; + border:1px solid #BBBBBB; +} + +#pagenav p { + display: inline; +} + +#pagetext { + padding-left: 20px; + padding-right: 20px; + padding-bottom: 10px; + padding-top: 10px; + color: #555; + background-color: #fff; + border: 1px solid #bbb; +} + +#pagefooter { + clear: both; + height: 30px; + padding-top: 15px; + padding-left: 20px; +} + +#pagefooter a { + color: #666; + border: none; + padding: 2px; +} + +#pagefooter a:hover { + color: #111; + background-color: #eee; +} diff --git a/arduino-0018-linux/reference/environment.html b/arduino-0018-linux/reference/environment.html new file mode 100644 index 0000000..6f52489 --- /dev/null +++ b/arduino-0018-linux/reference/environment.html @@ -0,0 +1,3 @@ + + + Redirect \ No newline at end of file diff --git a/arduino-0018-linux/reference/index.html b/arduino-0018-linux/reference/index.html new file mode 100644 index 0000000..f02c6cc --- /dev/null +++ b/arduino-0018-linux/reference/index.html @@ -0,0 +1,195 @@ + + + + Arduino - Reference + + + + +
+ + + + + + +
+ +
+

Reference   Language (extended) | Libraries | Comparison | Changes +

+

Language Reference

+

See the extended reference for more advanced features of the Arduino languages and the libraries page for interfacing with particular types of hardware. +

+

Arduino programs can be divided in three main parts: structure, values (variables and constants), and functions. The Arduino language is based on C/C++. +

+

+
+

Structure

+

Control Structures

+

Further Syntax

+
  • ; (semicolon) +
  • {} (curly braces) +
  • // (single line comment) +
  • /* */ (multi-line comment) +

Arithmetic Operators

+

Comparison Operators

+
  • == (equal to) +
  • != (not equal to) +
  • < (less than) +
  • > (greater than) +
  • <= (less than or equal to) +
  • >= (greater than or equal to) +

Boolean Operators

+
  • && (and) +
  • || (or) +
  • ! (not) +

Compound Operators

+
  • ++ (increment) +
  • -- (decrement) +
  • += (compound addition) +
  • -= (compound subtraction) +
  • *= (compound multiplication) +
  • /= (compound division) +

Variables

+

Variables are expressions that you can use in programs to store values, such as a sensor reading from an analog pin. +

+

Constants

+

Constants are particular values with specific meanings. +

+

Data Types

+

Variables can have various types, which are described below. +

+

Conversion

+

Reference

+

+

Functions

+

Digital I/O +

Analog I/O +

Advanced I/O +

Time +

Math +

Trigonometry +

Random Numbers +

+

Communication +

+


+

+

Didn't find something? Check the extended reference or the libraries. Or see the list of community-contributed code. +

+

+

Reference Home +

+

Corrections, suggestions, and new documentation should be posted to the Forum. +

+

The text of the Arduino reference is licensed under a +Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain. +

+
+ +
+ + + +
+ + diff --git a/arduino-0018-linux/tools/Mangler/make.sh b/arduino-0018-linux/tools/Mangler/make.sh new file mode 100755 index 0000000..e1c1ce3 --- /dev/null +++ b/arduino-0018-linux/tools/Mangler/make.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +# The pde.jar file may be buried inside the .app file on Mac OS X. +PDE=`find ../.. -name pde.jar` + +javac -target 1.5 \ + -cp "../../lib/core.jar:$PDE" \ + -d bin \ + src/Mangler.java + +cd bin && zip -r ../tool/mangler.jar * && cd .. diff --git a/arduino-0018-linux/tools/Mangler/src/Mangler.java b/arduino-0018-linux/tools/Mangler/src/Mangler.java new file mode 100644 index 0000000..cfd5279 --- /dev/null +++ b/arduino-0018-linux/tools/Mangler/src/Mangler.java @@ -0,0 +1,94 @@ +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + Part of the Processing project - http://processing.org + + Copyright (c) 2008 Ben Fry and Casey Reas + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package com.transformers.supermangletron; + + +import java.text.SimpleDateFormat; +import java.util.Date; + +import javax.swing.JOptionPane; + +import processing.app.Editor; +import processing.app.tools.Tool; + + +/** + * Example Tools menu entry. + */ +public class Mangler implements Tool { + Editor editor; + + + public void init(Editor editor) { + this.editor = editor; + } + + + public String getMenuTitle() { + return "Mangle Selection"; + } + + + public void run() { + String sketchName = editor.getSketch().getName(); + + Object[] options = { "Yes, please", "No, thanks" }; + int result = JOptionPane.showOptionDialog(editor, + "Is " + sketchName + + " ready for destruction?", + "Super Mangle Tron", + JOptionPane.YES_NO_OPTION, + JOptionPane.QUESTION_MESSAGE, + null, + options, + options[1]); + if (result == JOptionPane.YES_OPTION) { + mangleSelection(); + } + } + + + protected void mangleSelection() { + if (editor.isSelectionActive()) { + String selection = editor.getSelectedText(); + char[] stuff = selection.toCharArray(); + // Randomly swap a bunch of characters in the text + for (int i = 0; i < stuff.length / 10; i++) { + int a = (int) (Math.random() * stuff.length); + int b = (int) (Math.random() * stuff.length); + if (stuff[a] == '\n' || stuff[b] == '\n') { + continue; // skip newline characters + } + stuff[a] = selection.charAt(b); + stuff[b] = selection.charAt(a); + } + editor.startCompoundEdit(); + editor.setSelectedText(new String(stuff)); + editor.stopCompoundEdit(); + editor.statusNotice("Now that feels better, doesn't it?"); + + } else { + editor.statusError("No selection, no dice."); + } + } +} diff --git a/arduino-0018-linux/tools/howto.txt b/arduino-0018-linux/tools/howto.txt new file mode 100644 index 0000000..77df31c --- /dev/null +++ b/arduino-0018-linux/tools/howto.txt @@ -0,0 +1,143 @@ +TOOLS IN PROCESSING + +With initial help from code contributed by fjen, Processing release 0147 and +later have a dynamically loading tools menu, which can be used to expand the +environment in fun and fantastic ways. + +A Tool is a chunk of code that runs from the Tools menu. Tools are a means +of building onto the Processing Development Environment without needing to +rebuild the beast from source. + +The interface (at least for now) is extremely simple: + + +package processing.app.tools.Tool; + +public interface Tool extends Runnable { + + public void init(Editor editor); + + public void run(); + + public String getMenuTitle(); +} + + +The init() method is called when an Editor window first opens. This means +you won't have access to a sketch object, or a GUI, and should only do minimal +setup. (However it'd be a good idea to stash the "Editor" object for later.) + +The run() method will be called by the main application when the tool is +selected from the menu. This is called using invokeLater(), so that the tool +can safely use Swing and any other GUI yackety yack. If you're using a Frame, +you'll need to detect whether the Frame is already open (and bring it to the +front) or whether to create a new window. + +Faceless tools also use the run() method. You should avail yourselves of the +statusNotice() and statusError() methods in Editor, to let the user know what's +happened. (As per p. 107 of the Processing Development Environment Tools +Reference User Interface Guide.) + +The getMenuTitle() method just returns the title for what should appear in the +Tools menu. Not doing shortcuts for now, because resolving them between tools +(and the rest of the interface) is fugly. We would also need additional +modifiers for shift and alt. It just gets messy quick. Ordering in the Tools +menu is alphabetical. + + +////////////////////////////////////////////////////////////// + + +Where to put Tools + +Core tools live inside the "tools" subfolder of the Processing distribution, +however users should install "contributed" tools in their sketchbook folder, +inside a subfolder named "tools". + +If a tool works only with a particular release of Processing, then it may make +sense for the user to put things into the Processing tools folder, however we'd +like to keep users out of there as much as possible. In fact, it may not be +visible in future releases of Processing (for instance, on Mac OS X, the tools +folder is hidden inside the .app bundle). + +Tools should be laid out similar to libraries, though the structure is a little +more flexible. The tool folder should be the name of the main class (without +its package name but using the same capitalization), and have a subfolder named +"tool" that contains the .jar and .zip files it uses. I'll use the included +"Mangler" tool as an example. + +(This Tool is not built by default, due to a lack of non-dubious arguments +regarding the usefulness of including (by default) a Tool that mangles code.) + +The folder should be called Mangler (note the capitalization), and contain: + +sketchbook/Mangler -> tool folder +sketchbook/Mangler/tool -> location for code +sketchbook/Mangler/tool/mangle.jar -> jar with one or more classes + +The naming of jar and zip files in the tool/* directory doesn't matter. + +When Processing loads, the jar and zip files will be searched for +Mangler.class. Even though this tool is found in package poos.shoe, +it will be sussed out. Package names are required. + +Loose .class files are not supported, use only jar and zip files. + + +////////////////////////////////////////////////////////////// + + +What You Can and Cannot Do + +The only API methods that are officially scrubbed and sanctioned by the +Commissioner on Fair API and Proper Manners for use by the Tools classes +are found in: + +processing.app.Base +processing.app.Editor +processing.app.Preferences +processing.app.Sketch +processing.app.SketchCode + +In fact, most of the API you should be talking to is inside Editor. +Full API documentation can be found on dev.processing.org: +http://dev.processing.org/reference/everything/ +(Keep in mind that this is not always perfectly up to date, but we'll try.) + +Of course, you're welcome to go spelunking through the rest of the API +(that's where all the fun stuff is anyway), but don't be upset when something +changes and breaks your tool and makes your users sad. + +Currently, native code is not supported with tools. This might be possible, +but it's another potentially messy thing to dynamically add native library +paths to running code. (See "Future Releases" below.) + + +////////////////////////////////////////////////////////////// + + +Future Releases + +In future releases, we are considering the following features: + +1. How shortcut keys are handled. + http://dev.processing.org/bugs/show_bug.cgi?id=140 + +2. Whether to allow tools to dock into the Preferences panel. + http://dev.processing.org/bugs/show_bug.cgi?id=883 + +3. A means to run native code from the Tools menu. + http://dev.processing.org/bugs/show_bug.cgi?id=884 + +4. Methods for reorganizing the Tools menu, or placing contributed + Tools inside other menus (such as Edit or Sketch). + http://dev.processing.org/bugs/show_bug.cgi?id=885 + +This is the first round of documentation for the Tools menu, we reserve the +right to update, clarify, and change our mind in future releases. + + +////////////////////////////////////////////////////////////// + + +Ben Fry, last updated 19 August 2008