From 6297a32e9961804964f687be58cf2122ef4c57b6 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 6 Dec 2006 03:29:06 +0000 Subject: - fixed up help file so that everything loads with Pd-extended - fixed up [arduino] so that everything loads with Pd-extended - started to clean up the firmware and wrote lots of TODOs svn path=/trunk/externals/hardware/arduino/; revision=6662 --- Pd_firmware/Pd_firmware.pde | 153 ++++++++++++++++++++++----------------- arduino-help.pd | 170 +++++++++++++++++++++++--------------------- arduino.pd | 56 +++++++-------- 3 files changed, 204 insertions(+), 175 deletions(-) diff --git a/Pd_firmware/Pd_firmware.pde b/Pd_firmware/Pd_firmware.pde index d7e10bc..566abac 100644 --- a/Pd_firmware/Pd_firmware.pde +++ b/Pd_firmware/Pd_firmware.pde @@ -45,16 +45,17 @@ * TODO: * TODO: add "pinMode all 0/1" command * TODO: add cycle markers to mark start of analog, digital, pulseIn, and PWM + * TODO: convert to MIDI protocol using SysEx for longer messages */ -/* cvs version: $Id: Pd_firmware.pde,v 1.21 2006-10-31 00:39:07 eighthave Exp $ */ +/* cvs version: $Id: Pd_firmware.pde,v 1.22 2006-12-06 03:29:06 eighthave Exp $ */ /* 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 MAJOR_VERSION 0 -#define MINOR_VERSION 2 +#define MAJOR_VERSION 0 // for non-compatible changes +#define MINOR_VERSION 3 // for backwards compatible changes /* firmata protocol * =============== @@ -112,26 +113,25 @@ #define OUTPUT_TO_DIGITAL_PINS 229 // next two bytes set digital output data /* 230-239 // UNASSIGNED */ #define REPORT_VERSION 240 // return the firmware version -/* 240-249 // UNASSIGNED */ +/* 240-248 // UNASSIGNED */ +#define SET_PIN_STATE 249 // set a digital pit to INPUT or OUTPUT #define DISABLE_PWM 250 // next byte sets pin # to disable #define ENABLE_PWM 251 // next two bytes set pin # and duty cycle -#define DISABLE_SOFTWARE_PWM 252 // next byte sets pin # to disable -#define ENABLE_SOFTWARE_PWM 253 // next two bytes set pin # and duty cycle -#define SET_SOFTWARE_PWM_FREQ 254 // set master frequency for software PWMs +#define RESET 254 // reset if receive 8 of these bytes /* 255 // UNASSIGNED */ /* two byte digital output data format * ---------------------- - * 0 get ready for digital input bytes (229) + * 0 set digital output bytes (229/OUTPUT_TO_DIGITAL_PINS) * 1 digitalOut 7-13 bitmask * 2 digitalOut 0-6 bitmask */ -/* two byte PWM data format +/* control PWM * ---------------------- - * 0 get ready for digital input bytes (ENABLE_SOFTWARE_PWM/ENABLE_PWM) - * 1 pin # + * 0 send digital input bytes (ENABLE_PWM) + * 1 pin # (0-127) * 2 duty cycle expressed as 1 byte (255 = 100%) */ @@ -149,6 +149,47 @@ * 2 low byte from analog input */ +/* version report format + * Send a single byte 240, Arduino will reply with: + * ---------------------- + * 0 version report header (240) + * 1 major version (0-127) + * 2 minor version (0-127) + */ + +/* PROPOSED PROTOCOL ADDITIONS */ + +/* set digital pin state (249/SET_PIN_STATE) + * ---------------------- + * 0 set digital pin state + * 1 pin number (0-127) + * 2 state (OUTPUT/INPUT, 0/1) */ + +/* toggle analogIn reporting (249/SET_PIN_STATE) + * ---------------------- + * 0 analogIn reporting mode + * 1 pin number (0-127) + * 2 state (0/1) + */ + +/* control PWM 14-bit + * ---------------------- + * 0 send digital input bytes (ENABLE_PWM) + * 1 pin # (0-127) + * 2 duty cycle, high bits (8-13) + * 3 duty cycle, low bits (0-7) + */ + + +/* pulseIn (uses 32-bit value) + * ---------------------- + * 0 pulseIn + * 1 bits 24-31 (most significant byte) + * 2 bits 16-23 + * 3 bits 8-15 + * 4 bits 0-7 (least significant byte) + */ + #define TOTAL_DIGITAL_PINS 14 // for comparing along with INPUT and OUTPUT @@ -181,6 +222,7 @@ int digitalPinStatus = 0; int pwmStatus = 0; boolean digitalInputsEnabled = true; +// TODO: convert this to a bit array int, 1=report, 0=no report byte analogInputsEnabled = 6; byte analogPin; @@ -273,12 +315,6 @@ void processInput(byte inputData) { case DISABLE_PWM: setPinMode(storedInputData[0],INPUT); break; - case ENABLE_SOFTWARE_PWM: - break; - case DISABLE_SOFTWARE_PWM: - break; - case SET_SOFTWARE_PWM_FREQ: - break; } executeMultiByteCommand = 0; } @@ -306,6 +342,40 @@ void processInput(byte inputData) { } else { switch (inputData) { + case REPORT_VERSION: + Serial.print(REPORT_VERSION, BYTE); + Serial.print(MAJOR_VERSION, BYTE); + Serial.print(MINOR_VERSION, BYTE); + break; + case ENABLE_PWM: + waitForData = 2; // 2 bytes needed (pin#, dutyCycle) + executeMultiByteCommand = inputData; + break; + case DISABLE_PWM: + waitForData = 1; // 1 byte needed (pin#) + executeMultiByteCommand = inputData; + break; + case OUTPUT_TO_DIGITAL_PINS: // bytes to send to digital outputs + firstInputByte = true; + break; + case DISABLE_DIGITAL_INPUTS: // all digital inputs off + digitalInputsEnabled = false; + break; + case ENABLE_DIGITAL_INPUTS: // all digital inputs on + digitalInputsEnabled = true; + break; + case ZERO_ANALOG_INS: // analog input off + case ONE_ANALOG_IN: // analog 0 on + case TWO_ANALOG_INS: // analog 0,1 on + case THREE_ANALOG_INS: // analog 0-2 on + case FOUR_ANALOG_INS: // analog 0-3 on + case FIVE_ANALOG_INS: // analog 0-4 on + case SIX_ANALOG_INS: // analog 0-5 on + case SEVEN_ANALOG_INS: // analog 0-6 on + case EIGHT_ANALOG_INS: // analog 0-7 on + case NINE_ANALOG_INS: // analog 0-8 on + analogInputsEnabled = inputData - ZERO_ANALOG_INS; + break; case SET_PIN_ZERO_TO_IN: // set digital pins to INPUT case SET_PIN_ONE_TO_IN: case SET_PIN_TWO_TO_IN: @@ -338,52 +408,6 @@ void processInput(byte inputData) { case SET_PIN_THIRTEEN_TO_OUT: setPinMode(inputData - SET_PIN_ZERO_TO_OUT, OUTPUT); break; - case DISABLE_DIGITAL_INPUTS: // all digital inputs off - digitalInputsEnabled = false; - break; - case ENABLE_DIGITAL_INPUTS: // all digital inputs on - digitalInputsEnabled = true; - break; - case ZERO_ANALOG_INS: // analog input off - case ONE_ANALOG_IN: // analog 0 on - case TWO_ANALOG_INS: // analog 0,1 on - case THREE_ANALOG_INS: // analog 0-2 on - case FOUR_ANALOG_INS: // analog 0-3 on - case FIVE_ANALOG_INS: // analog 0-4 on - case SIX_ANALOG_INS: // analog 0-5 on - case SEVEN_ANALOG_INS: // analog 0-6 on - case EIGHT_ANALOG_INS: // analog 0-7 on - case NINE_ANALOG_INS: // analog 0-8 on - analogInputsEnabled = inputData - ZERO_ANALOG_INS; - break; - case ENABLE_PWM: - waitForData = 2; // 2 bytes needed (pin#, dutyCycle) - executeMultiByteCommand = inputData; - break; - case DISABLE_PWM: - waitForData = 1; // 1 byte needed (pin#) - executeMultiByteCommand = inputData; - break; - case SET_SOFTWARE_PWM_FREQ: - waitForData = 1; // 1 byte needed (pin#) - executeMultiByteCommand = inputData; - break; - case ENABLE_SOFTWARE_PWM: - waitForData = 2; // 2 bytes needed (pin#, dutyCycle) - executeMultiByteCommand = inputData; - break; - case DISABLE_SOFTWARE_PWM: - waitForData = 1; // 1 byte needed (pin#) - executeMultiByteCommand = inputData; - break; - case OUTPUT_TO_DIGITAL_PINS: // bytes to send to digital outputs - firstInputByte = true; - break; - case REPORT_VERSION: - Serial.print(REPORT_VERSION, BYTE); - Serial.print(MAJOR_VERSION, BYTE); - Serial.print(MINOR_VERSION, BYTE); - break; } } } @@ -397,6 +421,8 @@ void setup() { // TODO: load state from EEPROM here + Serial.begin(115200); + /* TODO: send digital inputs here, if enabled, to set the initial state on the * host computer, since once in the loop(), the Arduino will only send data on * change. */ @@ -412,7 +438,6 @@ void setup() { for(i=0; i +#N canvas 497 22 624 356 10; +#X obj 323 8 import hardware flatspace iemlib mapping; +#X text 415 317 released under the GNU GPL; +#X text 10 317 (C) Copyright 2006 Hans-Christoph Steiner ; -#X obj 11 21 inlet; -#X obj 10 241 outlet; -#X obj 494 241 outlet; +#X obj 11 61 inlet; +#X obj 10 281 outlet; +#X obj 494 281 outlet; #N canvas 382 102 637 357 command 0; #X obj 24 7 inlet; #X obj 281 289 outlet; @@ -180,11 +181,11 @@ to input; #X connect 12 5 9 0; #X connect 12 6 11 0; #X connect 13 0 6 0; -#X restore 11 52 pd command processing; -#X text 257 242 DEBUG/RAW data (this will change); -#X obj 379 19 inlet; -#X text 354 0 raw input; -#X text 10 -1 processed input; +#X restore 11 92 pd command processing; +#X text 257 282 DEBUG/RAW data (this will change); +#X obj 379 59 inlet; +#X text 354 40 raw input; +#X text 10 39 processed input; #N canvas 505 101 491 417 make 0; #X obj 37 8 inlet; #X obj 37 37 moses 128; @@ -363,21 +364,20 @@ to input; #X connect 11 0 6 0; #X connect 12 0 6 0; #X connect 12 1 7 0; -#X restore 10 165 pd make lists; -#X obj 288 103 spigot; -#X obj 319 81 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 +#X restore 10 205 pd make lists; +#X obj 288 143 spigot; +#X obj 319 121 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 1; -#X obj 125 120 print comport; -#X obj 11 96 comport \$1 115200; -#X obj 288 126 print command; -#X obj 438 19 import flatspace iemlib mapping; -#X connect 2 0 5 0; -#X connect 5 0 11 0; -#X connect 5 0 14 0; -#X connect 7 0 14 0; -#X connect 10 0 3 0; -#X connect 11 0 15 0; -#X connect 12 0 11 1; -#X connect 14 0 4 0; -#X connect 14 0 10 0; -#X connect 14 1 13 0; +#X obj 125 160 print comport; +#X obj 11 136 comport \$1 115200; +#X obj 288 166 print command; +#X connect 3 0 6 0; +#X connect 6 0 12 0; +#X connect 6 0 15 0; +#X connect 8 0 15 0; +#X connect 11 0 4 0; +#X connect 12 0 16 0; +#X connect 13 0 12 1; +#X connect 15 0 5 0; +#X connect 15 0 11 0; +#X connect 15 1 14 0; -- cgit v1.2.1