├── EngineController └── EngineController.ino ├── EngineMath ├── EngineMath.cpp ├── EngineMath.h ├── EngineMath.ino └── keywords.txt ├── LICENSE.txt ├── LoadCell ├── LoadCell.cpp ├── LoadCell.h ├── LoadCell.ino └── keywords.txt ├── MAX31855 ├── Adafruit_MAX31855.cpp ├── Adafruit_MAX31855.h ├── README.txt ├── examples │ ├── lcdthermocouple │ │ └── LCDthermocouple.pde │ └── serialthermocouple │ │ └── serialthermocouple.pde ├── keywords.txt └── license.txt ├── PMCtrl ├── PMCtrl.cpp ├── PMCtrl.h ├── examples │ └── PMCtrl │ │ └── PMCtrl.ino └── keywords.txt ├── README.md ├── SoftwareSerial ├── SoftwareSerial.cpp ├── SoftwareSerial.h ├── examples │ ├── SoftwareSerialExample │ │ └── SoftwareSerialExample.ino │ └── TwoPortReceive │ │ └── TwoPortReceive.ino └── keywords.txt ├── StopWatch ├── StopWatch.cpp ├── StopWatch.h ├── StopWatch.ino └── keywords.txt ├── ThermoTemp ├── ThermoSensor.ino ├── ThermoTemp.cpp ├── ThermoTemp.h └── keywords.txt └── Transducer ├── PressureTransducer.ino ├── Transducer.cpp ├── Transducer.h └── keywords.txt /EngineController/EngineController.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Title: Engine Controller v2 3 | Author: gNSortino@yahoo.com 4 | Description: This code is for safely lighting my regenerative 5 | engine. It is comprised of the main engine element and a small 6 | igniter engine. The main engine is actuated via 2 servo valves 7 | and the igniter is actuated via 2 solenoid valves and ignited 8 | via a spark plug. This code measures the following: 9 | - engine/igniter temp 10 | - engine pressure/flow 11 | - igniter pressure 12 | - fuel pressure/flow 13 | - ox pressure/flow 14 | Safety Features: 15 | - Upon resetting the code shuts off all vales 16 | and the ignition source. 17 | - Any input durring the test automatically aborts the engine 18 | Configuration: Configurable variables can be found in the 19 | Global Vars section. Anything that can be configured will 20 | be documented. 21 | Revision History: 22 | 2014-07-20 - Original Version 23 | 2014-09-08 - Added support for dynamic input of orifice diameters 24 | */ 25 | //////////////////////////////////// 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | /////////////////////////////////////// 35 | // Start of Global Variables Section // 36 | /////////////////////////////////////// 37 | // Pins (Configurable) 38 | int servoWrite = 12; 39 | int servoRead = 11; 40 | int igniterPin = 10; 41 | int solenoidFuelValve = 9; 42 | int solenoidOxValve = 8; 43 | int thermoDO = 7; 44 | int igniterThermoCS = 6; // Igniter Thermocouple Pin 45 | int engineThermoCS = 5; // Engine Thermocouple Pin 46 | int thermoCLK = 4; 47 | int fuelPSIpin = A0; 48 | int oxPSIpin = A1; 49 | int igniterPSIpin = A2; 50 | int enginePSIpin = A3; 51 | int loadCellPin = A4; 52 | 53 | // mathematical constants 54 | const float pi = 3.141592654; 55 | 56 | // Servo Properties 57 | int servoClosed = 800; 58 | int servoOpened = 1600; 59 | unsigned char fuelChannel = 0; 60 | unsigned char oxChannel = 1; 61 | int deviceID = 12; //servo device ID # (Default is 12) 62 | 63 | 64 | // Known Engine Properties (Configurable) 65 | float kI = 1.155; // specific heat ratio for the igniter 66 | float aThroatI = 0.00001371; // Nozzle throat area for the igniter m^2 67 | float aExitI = 0.0000251; // Nozzle exit area for the igniter m^2 68 | 69 | // Known Engine Properties (Configurable) 70 | float kE = 1.22; // specific heat ratio for the engine 71 | float aThroatE = 0.00017; // Nozzle throat area for the engine m^2 72 | float aExitE = 0.00038; // Nozzle exit area for the engine m^2 73 | 74 | // additional properties 75 | float p2PSI = 14.696; // exit pressure (PSI) 76 | float p3PSI = 14.696; // atmospheric pressure (PSI) 77 | 78 | // Engine Gas (Ox) Flow Properties (Configurable) 79 | float gcd = 0.32; // Coefficient of Discharge (Dimensionless) 80 | float gk = 1.40; // Gas Specific Heat Ratio (Dimensionless) 81 | float gz = 0.98; // Gas Compressability Factor (Dimensionless). Typically .975 82 | float gtemp = 277.0; // Gas Temperature at inlet (Kelvin) 83 | float gm = 32; // Gas Molecular Mass (mol). Ox is 32, Nitrogen, 28.02, Air = 28.97 84 | float gd = 0.141; // Orifice Diameter in (in^2) 85 | float ga = orificeArea(gd); // Orifice Area (m^2) 86 | 87 | // Engine Liquid (Fuel) Flow Properties (Configurable) 88 | float lcd = 0.7; // Coefficient of Discharge (Dimensionless) *** 0.65 igniter, .47 main engine 89 | float lden = 800; // Liquid Density (kg/m^3) *** 800 ethanol, 1000 water 90 | float ld = 0.023; // Orifice Diameter (in^2) 91 | float la = orificeArea(ld); // Orifice Area (m^2) 92 | 93 | // Load Cell Calibration Parameters 94 | float inV = 5.0; // input supply voltage 95 | float noLoadCalcV = 0.547; // no load calculated voltage (used for calibration) 96 | float loadMassV = 4.0; // the calibrated output voltage at full mass 97 | float loadMassLBF = 100.0; // the mass of the calibration input; 98 | 99 | // do not edit past this line 100 | float fuelPSI; 101 | float fuelFlow; // kg/sec 102 | float oxPSI; 103 | float oxFlow; // kg/sec 104 | float igniterPSI; 105 | double igniterTemp; // Celsius 106 | float igniterForce; // lbf 107 | float enginePSI; 108 | float engineFlow; // kg/sec 109 | double engineTemp; // Celsius 110 | float engineForceCalc; // calculated value (lbf) 111 | float engineForceSensor; // read from a load cell (lbf) 112 | float g = 9.80665; // Gravity m/sec^2 113 | long serialData; 114 | StopWatch sw; 115 | EngineMath em; 116 | Transducer transducer; 117 | Adafruit_MAX31855 igniterThermo(thermoCLK, igniterThermoCS, thermoDO); // igniter thermocouple 118 | Adafruit_MAX31855 engineThermo(thermoCLK, engineThermoCS, thermoDO); // engine thermocouple 119 | PMCtrl servoCtrl (servoRead, servoWrite, 57600); // RX, TX, Baud 120 | LoadCell loadCell (inV, noLoadCalcV, loadMassV, loadMassLBF); // load cell calibration 121 | 122 | ////////////////////////////////////// 123 | // End of Global Variables Section // 124 | ////////////////////////////////////// 125 | 126 | void setup () 127 | { 128 | Serial.begin(57600); //57600 needed for xbee modules 129 | 130 | // Setup Pins 131 | pinMode (solenoidFuelValve, OUTPUT); 132 | pinMode (solenoidOxValve, OUTPUT); 133 | pinMode (igniterPin, OUTPUT); 134 | 135 | // Set the global servo speed (Can be modified further below). Note - 50 is ~1 second to open and hgher numbers are faster 136 | //servoCtrl.setServoSpeed (25, fuelChannel, deviceID); 137 | //servoCtrl.setServoSpeed (200, oxChannel, deviceID); 138 | } 139 | 140 | void loop () 141 | { 142 | emergencyStop(); 143 | 144 | ////////////////////// 145 | ///// Main Menu ///// 146 | ///////////////////// 147 | Serial.println (F("(1) Test Sensors")); 148 | Serial.println (F("(2) Test Valves + Igniter")); 149 | Serial.println (F("(3) Manual Valve Check")); 150 | Serial.print (F("(4) Set Orifice Diameters (currently ")); 151 | Serial.print (ld,3); 152 | Serial.print (F("/")); 153 | Serial.print (gd,3); 154 | Serial.println (F(" F/O in)")); 155 | Serial.println (F("(5) Run Engine")); 156 | 157 | getSerial(); 158 | switch (serialData) 159 | { 160 | case 1: // Test Sensors 161 | { 162 | testSensors(); 163 | break; 164 | } 165 | case 2: // Test Valves + Igniter 166 | { 167 | testControl(); 168 | break; 169 | } 170 | case 3: // Manual Valve Check 171 | { 172 | manualValveCheck(); 173 | break; 174 | } 175 | case 4: // Set the Orifice Diameters 176 | { 177 | setOrificeDiameters(); 178 | break; 179 | } 180 | case 5: // Run Engine 181 | { 182 | runEngine(); 183 | break; 184 | } 185 | } 186 | } 187 | //////////////////////// 188 | // Supporting Methods // 189 | //////////////////////// 190 | 191 | /* 192 | Output Sensor Data until user interupt is received 193 | */ 194 | void testSensors() 195 | { 196 | Serial.println(F("Press any key to interupt.")); 197 | sw.millisToSleep(1500); 198 | sw.startTimer(0); 199 | sensorDisplay(true); 200 | while (isAbort() == false) 201 | { 202 | sw.millisToSleep(2000); 203 | sensorDisplay(false); 204 | } 205 | } 206 | 207 | /* 208 | Runs through a series of valve and igniter tests to ensure they 209 | are working correctly. 210 | */ 211 | void testControl() 212 | { 213 | Serial.println(F("Opening fuel igniter valve")); 214 | digitalWrite(solenoidFuelValve, HIGH); 215 | if (isAbortAutoCheck(2000) == true) 216 | return; 217 | 218 | Serial.println(F("Opening ox igniter valve")); 219 | digitalWrite(solenoidOxValve, HIGH); 220 | if (isAbortAutoCheck(2000) == true) 221 | return; 222 | 223 | Serial.println(F("Turning on igniter")); 224 | digitalWrite(igniterPin, HIGH); 225 | if (isAbortAutoCheck(2000) == true) 226 | return; 227 | 228 | Serial.println(F("Closing fuel igniter valve")); 229 | digitalWrite(solenoidFuelValve, LOW); 230 | if (isAbortAutoCheck(2000) == true) 231 | return; 232 | 233 | Serial.println(F("Closing ox igniter valve")); 234 | digitalWrite(solenoidOxValve, LOW); 235 | if (isAbortAutoCheck(2000) == true) 236 | return; 237 | 238 | Serial.println(F("Turning off igniter")); 239 | digitalWrite(igniterPin, LOW); 240 | if (isAbortAutoCheck(2000) == true) 241 | return; 242 | 243 | Serial.println(F("Turning on engine fuel valve")); 244 | servoCtrl.setTarget (servoOpened, fuelChannel, deviceID); 245 | if (isAbortAutoCheck(3000) == true) 246 | return; 247 | 248 | Serial.println(F("Turning on engine ox valve")); 249 | servoCtrl.setTarget (servoOpened, oxChannel, deviceID); 250 | if (isAbortAutoCheck(3000) == true) 251 | return; 252 | 253 | Serial.println(F("Turning off engine fuel valve")); 254 | servoCtrl.setTarget (servoClosed, fuelChannel, deviceID); 255 | if (isAbortAutoCheck(3000) == true) 256 | return; 257 | 258 | Serial.println(F("Turning on engine ox valve")); 259 | servoCtrl.setTarget (servoClosed, oxChannel, deviceID); 260 | if (isAbortAutoCheck(3000) == true) 261 | return; 262 | 263 | 264 | Serial.println(F("On all at once")); 265 | digitalWrite(solenoidFuelValve, HIGH); 266 | digitalWrite(solenoidOxValve, HIGH); 267 | digitalWrite(igniterPin, HIGH); 268 | servoCtrl.setTarget (servoOpened, fuelChannel, deviceID); 269 | servoCtrl.setTarget (servoOpened, oxChannel, deviceID); 270 | if (isAbortAutoCheck(5000) == true) 271 | return; 272 | 273 | Serial.println(F("Off all at once")); 274 | digitalWrite(solenoidFuelValve, LOW); 275 | digitalWrite(solenoidOxValve, LOW); 276 | digitalWrite(igniterPin, LOW); 277 | servoCtrl.setTarget (servoClosed, fuelChannel, deviceID); 278 | servoCtrl.setTarget (servoClosed, oxChannel, deviceID); 279 | } 280 | 281 | /* 282 | Allows the user to manually open a valve for a set period of time 283 | */ 284 | void manualValveCheck() 285 | { 286 | unsigned long valveOpenTime; 287 | 288 | Serial.println (F("How long should the valve stay open?")); 289 | getSerial(); 290 | valveOpenTime = serialData; 291 | 292 | Serial.println(F("Which valve? 1=IgniterFuel, 2=IgniterOx, 3=EngineFuel, 4=EngineOx")); 293 | getSerial(); 294 | switch (serialData) 295 | { 296 | case 1: 297 | { 298 | digitalWrite(solenoidFuelValve, HIGH); 299 | break; 300 | } 301 | case 2: 302 | { 303 | digitalWrite(solenoidOxValve, HIGH); 304 | break; 305 | } 306 | case 3: 307 | { 308 | servoCtrl.setTarget (servoOpened, fuelChannel, deviceID); 309 | break; 310 | } 311 | case 4: 312 | { 313 | servoCtrl.setTarget (servoOpened, oxChannel, deviceID); 314 | break; 315 | } 316 | default: 317 | return; 318 | } 319 | if (isAbortAutoCheck(valveOpenTime) == true) 320 | return; 321 | } 322 | 323 | /* 324 | Fires the engine for 'x' milliseconds 325 | */ 326 | void runEngine () 327 | { 328 | unsigned long engineRunTime; 329 | Serial.println(F("Run engine for how many milliseconds?")); 330 | getSerial(); 331 | if (serialData <= 0) 332 | return; 333 | engineRunTime = serialData; 334 | Serial.print(F("Starting Engine in: ")); 335 | for (int i=5; i>0; i--) 336 | { 337 | if (isAbortAutoCheck(1000) == true) 338 | return; 339 | Serial.print (i); 340 | Serial.print (F(", ")); 341 | } 342 | Serial.print(F("\n")); 343 | digitalWrite(igniterPin, HIGH); 344 | sw.millisToSleep(425); 345 | digitalWrite(solenoidOxValve, HIGH); 346 | sw.millisToSleep(75); 347 | digitalWrite(solenoidFuelValve, HIGH); 348 | sw.startTimer(engineRunTime); 349 | sensorDisplay(true); 350 | // run for up to 1000ms to give it a chance for pressure to come up 351 | while (sw.timeElapsed() < 1000 && (sw.timerStatus() == true)) 352 | { 353 | if (isAbort() == true) 354 | return; 355 | sensorDisplay(false); 356 | } 357 | Serial.println(F("Initial Startup Complete. Opening Main Valves...")); 358 | servoCtrl.setServoSpeed (25, fuelChannel, deviceID); 359 | servoCtrl.setServoSpeed (200, oxChannel, deviceID); 360 | servoCtrl.setTarget (servoOpened, fuelChannel, deviceID); 361 | servoCtrl.setTarget (servoOpened, oxChannel, deviceID); 362 | while (sw.timeElapsed() < 2000 && (sw.timerStatus() == true)) 363 | { 364 | sensorDisplay(false); 365 | if (/*(isDanger(1) == true) OR */(isAbort() == true)) 366 | return; 367 | if ((servoCtrl.getPosition(fuelChannel, deviceID) >= servoOpened - 10) && 368 | (servoCtrl.getPosition(oxChannel, deviceID) >= servoOpened - 10)) 369 | break; 370 | } 371 | digitalWrite(solenoidFuelValve, LOW); 372 | digitalWrite(solenoidOxValve, LOW); 373 | Serial.println(F("Main Valves Open. Firing...")); 374 | while (sw.timerStatus() == true) 375 | { 376 | sensorDisplay(false); 377 | // Check for Dangerous Conditions or Aborts 378 | if (/*(isDanger() == true) OR */(isAbort() == true)) 379 | return; 380 | } 381 | digitalWrite(solenoidFuelValve, LOW); 382 | digitalWrite(solenoidOxValve, LOW); 383 | servoCtrl.setServoSpeed (200, fuelChannel, deviceID); 384 | servoCtrl.setServoSpeed (25, oxChannel, deviceID); 385 | servoCtrl.setTarget (servoClosed, fuelChannel, deviceID); 386 | servoCtrl.setTarget (servoClosed, oxChannel, deviceID); 387 | Serial.println(F("Run Complete. Shutting Down...")); 388 | digitalWrite(igniterPin, LOW); 389 | while ((igniterPSI > 30) && (sw.timeElapsed() < engineRunTime + 3000)) 390 | { 391 | if (/*(isDanger(0) == true) OR */(isAbort() == true)) 392 | return; 393 | sensorDisplay(false); 394 | } 395 | } 396 | 397 | /* 398 | Dynamically set the Orifice Diameters and calculate the resulting orifice Areas 399 | */ 400 | void setOrificeDiameters () 401 | { 402 | Serial.println (F("Orifice diameters are currently: ")); 403 | Serial.print (ld,3); 404 | Serial.print (F("/")); 405 | Serial.print (gd,3); 406 | Serial.println (F(" F/O in. Type '1' to change")); 407 | getSerial(); 408 | 409 | if (serialData == 1) { 410 | Serial.println (F("Enter new fuel Orifice Diameter: ")); 411 | getSerial(); 412 | ld = (serialData / 1000.0); 413 | la = orificeArea (ld); 414 | Serial.println (F("Enter new oxidizer Orifice Diameter: ")); 415 | getSerial(); 416 | gd = (serialData / 1000.0); 417 | ga = orificeArea (gd); 418 | Serial.println (F("Orifice diameters are now: ")); 419 | Serial.print (ld,3); 420 | Serial.print (F("/")); 421 | Serial.print (gd,3); 422 | Serial.println (F(" F/O in.")); 423 | } 424 | } 425 | /* 426 | Gets Sensor data and sets the corresponding sensor values 427 | */ 428 | void sensorRead() 429 | { 430 | 431 | 432 | fuelPSI = transducer.getPSI(transducer.getVoltage(analogRead(fuelPSIpin))); 433 | oxPSI = transducer.getPSI(transducer.getVoltage(analogRead(oxPSIpin))); 434 | igniterPSI = transducer.getPSI(transducer.getVoltage(analogRead(igniterPSIpin))); 435 | enginePSI = transducer.getPSI(transducer.getVoltage(analogRead(enginePSIpin))); 436 | fuelFlow = em.LiquidMassFlow (lcd, lden, fuelPSI, enginePSI, la); 437 | oxFlow = em.GasMassFlow (gcd, g, gk, gz, gtemp, gm, oxPSI, enginePSI, ga); 438 | igniterTemp = igniterThermo.readCelsius(); 439 | igniterForce = em.thrustCalc(kI, igniterPSI, enginePSI, p3PSI, aExitI, aThroatI); 440 | engineFlow = oxFlow + fuelFlow; // Can this be made more sophisticated? 441 | engineTemp = engineThermo.readCelsius(); 442 | engineForceCalc = em.thrustCalc(kE, enginePSI, p2PSI, p3PSI, aExitE, aThroatE); 443 | engineForceSensor = loadCell.getForce (analogRead(loadCellPin)); 444 | } 445 | 446 | /* 447 | Displays sensor information to the client. An optional boolean flag 448 | if set to true tells the method to display the column headers 449 | */ 450 | void sensorDisplay(boolean showHeader) 451 | { 452 | sensorRead(); 453 | 454 | if (showHeader == true) 455 | { 456 | Serial.println(F("Millis,fuelPos(us),fuelPSI,fuelFlow(kg/sec),oxPos(us),oxPSI,oxFlow(kg/sec),igniterPSI,igniterTemp(C),igniterForce(lbf),enginePSI,engineFlow(kg/sec),engineTemp(C),engineForceCalc(lbf),engineForceSensor(lbf)")); 457 | } 458 | Serial.print(sw.timeElapsed()); 459 | Serial.print ((char) ','); 460 | Serial.print (servoCtrl.getPosition(fuelChannel, deviceID)); 461 | Serial.print ((char) ','); 462 | Serial.print(fuelPSI); 463 | Serial.print ((char) ','); 464 | Serial.print(fuelFlow,8); 465 | Serial.print ((char) ','); 466 | Serial.print (servoCtrl.getPosition(oxChannel, deviceID)); 467 | Serial.print ((char) ','); 468 | Serial.print(oxPSI); 469 | Serial.print ((char) ','); 470 | Serial.print(oxFlow,8); 471 | Serial.print ((char) ','); 472 | Serial.print(igniterPSI); 473 | Serial.print ((char) ','); 474 | Serial.print(igniterTemp); 475 | Serial.print ((char) ','); 476 | Serial.print(igniterForce); 477 | Serial.print ((char) ','); 478 | Serial.print(enginePSI); 479 | Serial.print ((char) ','); 480 | Serial.print(engineFlow,8); 481 | Serial.print ((char) ','); 482 | Serial.print(engineTemp); 483 | Serial.print ((char) ','); 484 | Serial.print(engineForceCalc); 485 | Serial.print ((char) ','); 486 | Serial.println(engineForceSensor); 487 | } 488 | 489 | /* 490 | Reads Serial information from the user terminal until a newline character 491 | is received. Results are echoed back and saved to the serial buffer. 492 | */ 493 | void getSerial() 494 | { 495 | int newline = '/'; 496 | int inbyte; 497 | serialData = 0; //clear any old serial data before proceeding. 498 | 499 | while (inbyte != newline) 500 | { 501 | inbyte = Serial.read(); 502 | if (inbyte > 0 && inbyte != newline) 503 | serialData = serialData * 10 + inbyte - '0'; 504 | } 505 | Serial.println(serialData); 506 | } 507 | 508 | /* 509 | Reads from the user input serial buffer to see if any data 510 | is present. If data is present assume the user is trying to 511 | abort the current operation and return true. Otherwise 512 | false is returned. 513 | */ 514 | boolean isAbort () 515 | { 516 | int inbyte; 517 | inbyte = Serial.read(); 518 | if (inbyte > 0) 519 | return true; 520 | else 521 | return false; 522 | } 523 | 524 | /* 525 | A function that calls isAbort repeatedly for 'x' milliseconds. 526 | It will return true if an abort is detected. 527 | */ 528 | boolean isAbortAutoCheck (unsigned long sleepTime) 529 | { 530 | sw.startTimer(sleepTime); 531 | while (sw.timerStatus() == true) 532 | { 533 | if (isAbort() == true) 534 | { 535 | return true; 536 | } 537 | } 538 | return false; 539 | } 540 | 541 | /* 542 | Checks for dangerous conditions. If one is found true is returned. 543 | False otherwise. 544 | 0 = [Default] check engine and igniter 545 | 1 = check igniter only 546 | 2 = check engine only 547 | * = (Anthying Else) return true 548 | */ 549 | boolean isDanger(int toCheck = 0) 550 | { 551 | switch (serialData) 552 | { 553 | case 0: // check engine and igniter 554 | { 555 | if ((isDanger(1) == true) && (isDanger(2) == true)) 556 | return true; 557 | else 558 | return false; 559 | } 560 | case 1: // check igniter only 561 | { 562 | if ((igniterPSI > 150) || (igniterTemp > 400)) // Check for excessive conditions 563 | return true; 564 | else if (igniterPSI < 50) // Check for no-go conditions 565 | return true; 566 | else 567 | return false; 568 | } 569 | case 2: // check engine only 570 | { 571 | if ((enginePSI > 200) || (engineTemp > 400)) // Check for excessive conditions 572 | return true; 573 | else if (enginePSI < 50) // Check for no-go conditions 574 | return true; 575 | else 576 | return false; 577 | break; 578 | } 579 | default: // (Anthying Else) return true 580 | return true; 581 | } 582 | } 583 | 584 | /* 585 | Shuts down all controllers (valves & igniter) 586 | */ 587 | void emergencyStop () 588 | { 589 | digitalWrite (solenoidFuelValve, LOW); 590 | digitalWrite (solenoidOxValve, LOW); 591 | digitalWrite (igniterPin, LOW); 592 | servoCtrl.setTarget (servoClosed, fuelChannel, deviceID); 593 | servoCtrl.setTarget (servoClosed, oxChannel, deviceID); 594 | sw.millisToSleep(50); 595 | digitalWrite (solenoidFuelValve, LOW); 596 | digitalWrite (solenoidOxValve, LOW); 597 | digitalWrite (igniterPin, LOW); 598 | servoCtrl.setTarget (servoClosed, fuelChannel, deviceID); 599 | servoCtrl.setTarget (servoClosed, oxChannel, deviceID); 600 | sw.millisToSleep(100); 601 | digitalWrite (solenoidFuelValve, LOW); 602 | digitalWrite (solenoidOxValve, LOW); 603 | digitalWrite (igniterPin, LOW); 604 | servoCtrl.setTarget (servoClosed, fuelChannel, deviceID); 605 | servoCtrl.setTarget (servoClosed, oxChannel, deviceID); 606 | sw.millisToSleep(500); 607 | digitalWrite (solenoidFuelValve, LOW); 608 | digitalWrite (solenoidOxValve, LOW); 609 | digitalWrite (igniterPin, LOW); 610 | servoCtrl.setTarget (servoClosed, fuelChannel, deviceID); 611 | servoCtrl.setTarget (servoClosed, oxChannel, deviceID); 612 | } 613 | 614 | 615 | /* 616 | computes the orifice area in m^2 for a given orifice diameter supplied in in 617 | */ 618 | float orificeArea (float orificeDiameter) 619 | { 620 | const float pi = 3.141592654; 621 | const float in2m2 = 0.00064516; 622 | return (pi * pow ((orificeDiameter / 2), 2) * in2m2); 623 | } 624 | -------------------------------------------------------------------------------- /EngineMath/EngineMath.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Title: EngineMath.cpp 3 | Author/Date: gNSortino@yahoo.com / 2012-05-26 4 | Description: This library is used to calculate properties 5 | of a rocket engine. Currently it will calculate the following 6 | properties 7 | (1) GasMassFlow. 8 | -> Returns kg/sec as a float 9 | (2) LiquidMassFlow. 10 | -> Returns kg/sec as a float 11 | (3) MassFlowConvert. Convers kg/sec to: 12 | -> [0] kg/sec 13 | -> [1] kg/min 14 | -> [2] lbs/sec 15 | -> [3] lbs/min 16 | Note that this library will not setup any pins. It 17 | is expected that these will be defined by the calling 18 | program. 19 | Change Log: 20 | GNS 2013-07-28: Corrected incorrect gas-flow calculation. Removed input 21 | value for static constant 'r' Gas Coefficient 22 | GNS 2014-01-20: added thrustCalc method to return the engine thrust in lbf 23 | GNS 2014-05-18: added support for dynamic calculation of choked and non-choked gas flow 24 | */ 25 | 26 | #include "Arduino.h" 27 | #include "EngineMath.h" 28 | 29 | //Empty Constructor 30 | EngineMath::EngineMath() 31 | { 32 | 33 | } 34 | 35 | /* 36 | Note that the array mf is passed by reference so 37 | the calling function should use this to view results. 38 | */ 39 | void EngineMath::MassFlowConvert ( float mf[]) // Mass Flow array 40 | { 41 | mf[0] = mf[0]; // kg/sec 42 | mf[1] = mf[0] * 60.0; // kg/min 43 | mf[2] = mf[0] *2.20462262; // lbs/sec 44 | mf[3] = mf[2] * 60; // lbs/min 45 | } 46 | 47 | float EngineMath::LiquidMassFlow ( float cd, // Coefficient of Discharge (Dimensionless) 48 | float den, // Liquid Density (kg/m^3) 49 | float p1, // Inlet Pressure (psi) 50 | float p2, // Outlet Pressure (psi) 51 | float a) // Orifice Area (m^2) 52 | { 53 | //Convert psi to kg/(m*s^2) 54 | p1 = (p1*6894.75729); 55 | p2 = (p2*6894.75729); 56 | float pdrop = p1 - p2; //pressure drop across orifice 57 | float lasmf =a*(cd*sqrt(2*pdrop*den)); 58 | return lasmf; 59 | } 60 | 61 | /* 62 | Function determines whether flow is choked (or not) and then 63 | calculates flow appropriately. 64 | */ 65 | float EngineMath::GasMassFlow ( float cd, // Coefficient of Discharge (Dimensionless) 66 | float g, // Gravity 9.80665 (m/sec^2) 67 | float k, // Gas Specific Heat Ratio (Dimensionless) 68 | float z, // Gas Compressability Factor (Dimensionless) 69 | float temp, // Gas Temperature at inlet (Kelvin) 70 | float m, // Gas Molecular Mass (mol) 71 | float p1, // Inlet Pressure (psi) 72 | float p2, // Outlet Pressure (psi) 73 | float a) // Orifice Area (m^2) 74 | { 75 | float r = 8314.4621; // J/Kg^-1*mol^-1 76 | //Convert psi to kg/(m*s^2) 77 | p1 = (p1*6894.75729); 78 | p2 = (p2*6894.75729); 79 | float pratio = p2 /p1; 80 | float pcritical = pow((2 / (k + 1)),( k / (k -1))); 81 | float density = p1 / (z * (r / m) * temp); 82 | float gasmf; 83 | if ((pcritical * p1) > p2) // choked 84 | gasmf = cd * a * sqrt( k * density * p1 * pow ((2 / (k + 1)), ((k + 1) / (k - 1)))); 85 | else // non-choked 86 | gasmf = a*(cd*p1*sqrt(((2*m*g)/(z*r*temp))*(k/(k-1)) * (pow(pratio,(2/k))- pow(pratio,((k+1)/k))))); 87 | return gasmf; 88 | } 89 | 90 | /* 91 | Returns thrust in lbf given the below inputs 92 | */ 93 | float EngineMath::thrustCalc ( float k, // specific heat ratio for the engine 94 | float p1PSI, // chamber pressure (PSI) 95 | float p2PSI, // exit pressure (PSI) 96 | float p3PSI, // atmospheric pressure (PSI) 97 | float aExit, // Nozzle exit area m^2 98 | float aThroat) // Nozzle throat area m^2 99 | { 100 | float p1Mpa = p1PSI * 0.00689475729; 101 | float p2Mpa = p2PSI * 0.00689475729; 102 | float p3Mpa = p3PSI * 0.00689475729; 103 | float Cf = sqrt(((2.0 * pow(k,2.0))/(k - 1.0)) * pow(2.0 / (k + 1.0), (k + 1.0)/(k - 1.0)) * (1.0 - pow(p2Mpa / p1Mpa, (k - 1.0) / k) )) + ((p2Mpa - p3Mpa)/ p1Mpa)*(aExit / aThroat); 104 | return Cf * p1Mpa * aThroat * 1000000.0 * 0.22481; 105 | } -------------------------------------------------------------------------------- /EngineMath/EngineMath.h: -------------------------------------------------------------------------------- 1 | /* 2 | Title: EngineMath.h 3 | Author/Date: gNSortino@yahoo.com / 2012-05-26 4 | Description: This library is used to calculate properties 5 | of a rocket engine. Currently it will calculate the following 6 | properties 7 | (1) GasMassFlow. 8 | -> Returns kg/sec as a float 9 | (2) LiquidMassFlow. 10 | -> Returns kg/sec as a float 11 | (3) MassFlowConvert. Convers kg/sec to: 12 | -> [0] kg/sec 13 | -> [1] kg/min 14 | -> [2] lbs/sec 15 | -> [3] lbs/min 16 | Note that this library will not setup any pins. It 17 | is expected that these will be defined by the calling 18 | program. 19 | */ 20 | #ifndef EngineMath_h 21 | #define Engine_h 22 | 23 | #include "Arduino.h" 24 | 25 | class EngineMath 26 | { 27 | public: 28 | EngineMath (); 29 | float LiquidMassFlow ( float cd, // Coefficient of Discharge (Dimensionless) 30 | float den, // Liquid Density (kg/m^3) 31 | float p1, // Inlet Pressure (psi) 32 | float p2, // Outlet Pressure (psi) 33 | float a); // Orifice Area (m^2) 34 | float GasMassFlow ( float cd, // Coefficient of Discharge (Dimensionless) 35 | float g, // Gravity 9.80665 (m/sec2) 36 | float k, // Gas Specific Heat Ratio (Dimensionless) 37 | float z, // Gas Compressability Factor (Dimensionless) 38 | float temp, // Gas Temperature at inlet (Kelvin) 39 | float m, // Gas Molecular Mass (mol) 40 | float p1, // Inlet Pressure (psi) 41 | float p2, // Outlet Pressure (psi) 42 | float a); // Orifice Area (m^2) 43 | void MassFlowConvert ( float mf[]); // Mass Flow array 44 | float thrustCalc ( float k, // specific heat ratio for the engine 45 | float p1PSI, // chamber pressure (PSI) 46 | float p2PSI, // exit pressure (PSI) 47 | float p3PSI, // atmospheric pressure (PSI) 48 | float aExit, // Nozzle exit area m^2 49 | float aThroat); // Nozzle throat area m^2 50 | 51 | }; 52 | 53 | #endif -------------------------------------------------------------------------------- /EngineMath/EngineMath.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include //For dtostrf function http://www.nongnu.org/avr-libc/user-manual/group__avr__stdlib.html#ga060c998e77fb5fc0d3168b3ce8771d42 4 | 5 | EngineMath em; 6 | Transducer transducer; 7 | float pressures[5]; 8 | char s[64]; // buffer for dtostrf 9 | float raw; // holds raw analog read 10 | float mf[4]; // array to hold mass flow properties. Re-used for liquid and gas 11 | float r = 8314.4621; // Universal Gas Constant (J/kg mol-K) 12 | float g = 9.80665; // Gravity m/sec^2 13 | //Gas Flow Properties 14 | float gcd = 0.7; // Coefficient of Discharge (Dimensionless) 15 | float gk = 1.227; // Gas Specific Heat Ratio (Dimensionless) 16 | float gz = 0.975; // Gas Compressability Factor (Dimensionless) 17 | float gtemp = 296.0; // Gas Temperature at inlet (Kelvin) 18 | float gm = 28.9; // Gas Molecular Mass (mol) 19 | float gp1 = 459.0; // Inlet Pressure (psi) 20 | float gp2 = 300.0; // Outlet Pressure (psi) 21 | float ga = 0.000004453483703; // Orifice Area (m^2) =((PI()*((3/32")/2)^2)*0.00064516) 22 | //Liquid Flow Properties 23 | float lcd = 0.6; // Coefficient of Discharge (Dimensionless) 24 | float lden = 785.0; // Liquid Density (kg/m^3) 25 | float lp1 = 500.0; // Inlet Pressure (psi) 26 | float lp2 = 300.0; // Outlet Pressure (psi) 27 | float la = 0.000000198132573; // Orifice Area (m^2) 28 | ///////////////////////////////////////////// 29 | 30 | void setup() { 31 | Serial.begin(57600); 32 | Serial.println ("Pressure,Signal,Voltage,PSI,Pa,MPa"); 33 | Serial.println ("LiquidFlow,kg per sec,kg per min,lbs per sec,lbs per min"); 34 | Serial.println ("GasFlow,kg per sec,kg per min,lbs per sec,lbs per min"); 35 | } 36 | 37 | void loop() { 38 | raw = analogRead(A1); 39 | transducer.getPressures (raw, pressures); 40 | Serial.println ("Pressure," + 41 | (String)dtostrf (pressures[0], 2,6, s) + "," + // Analog Signal 42 | (String)dtostrf (pressures[1], 2,6, s) + "," + // Voltage 43 | (String)dtostrf (pressures[2], 5,6, s) + "," + // Pounds per Square Inch 44 | (String)dtostrf (pressures[3], 8,6, s) + "," + // Pascal 45 | (String)dtostrf (pressures[4], 2,10, s) + ","); // MegaPascal 46 | mf[0] = em.LiquidMassFlow (lcd, g, lden, lp1, lp2, la); 47 | em.MassFlowConvert (mf); 48 | Serial.println ("LiquidFlow," + 49 | (String)dtostrf (mf[0], 2,15, s) + "," + // kg/sec 50 | (String)dtostrf (mf[1], 3,10, s) + "," + // kg/min 51 | (String)dtostrf (mf[2], 3,15, s) + "," + // lbs/sec 52 | (String)dtostrf (mf[3], 3,15, s)); // lbs/min 53 | mf[0] = em.GasMassFlow (gcd, g, gk, r, gz, gtemp, gm, gp1, gp2, ga); 54 | em.MassFlowConvert (mf); 55 | Serial.println ("GasFlow," + 56 | (String)dtostrf (mf[0], 2,15, s) + "," + // kg/sec 57 | (String)dtostrf (mf[1], 3,10, s) + "," + // kg/min 58 | (String)dtostrf (mf[2], 3,15, s) + "," + // lbs/sec 59 | (String)dtostrf (mf[3], 3,15, s)); // lbs/min 60 | delay(100000); 61 | } 62 | -------------------------------------------------------------------------------- /EngineMath/keywords.txt: -------------------------------------------------------------------------------- 1 | EngineMath KEYWORD1 2 | LiquidMassFlow KEYWORD2 3 | GasMassFlow KEYWORD2 4 | MassFlowConvert KEYWORD2 5 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /LoadCell/LoadCell.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Title: LoadCell.h 3 | Author/Date: gNSortino@yahoo.com / 2014-07-26 4 | Description: This library will take the input from an 5 | FC22 MSI Load Cell (0.5V - 4.5V) and convert it into lbf 6 | configuration inputs: 7 | inV: 8 | the supply voltage (should be 5 volts) 9 | noLoadCalcV: 10 | the no load calculated voltage 11 | loadMassV: 12 | the full load mass voltage 13 | loadMassLBF: 14 | the full load mass in pounds force 15 | measurement input: 16 | loadCellAnalogIn: 17 | output: 18 | mass: 19 | outputs the calculated mass given the aforementioned 20 | inputs. 21 | Note that this library will not setup any pins. It 22 | is expected that these will be defined by the calling 23 | program. 24 | Change Log: 25 | GNS 2014-07-26: initial version 26 | */ 27 | 28 | #include "Arduino.h" 29 | #include "LoadCell.h" 30 | 31 | /* 32 | Calibration parameters for the load cell 33 | */ 34 | LoadCell::LoadCell(float inV, float noLoadCalcV, float loadMassV, float loadMassLBF) 35 | { 36 | // Calculate the ratiometric scale factor given the fact that 37 | // the nominal input voltage should be 5V (per datasheet) 38 | _ratiometricScaleFactor = (inV / 5.0); 39 | 40 | _calibratedSpan = (loadMassV / loadMassLBF) * _ratiometricScaleFactor; 41 | _noLoadCalcV = noLoadCalcV; 42 | 43 | } 44 | 45 | /* 46 | Load cell voltage is a linear function defined as: Y = mX+b 47 | where: 48 | Y= measured voltage 49 | m = mV/lbf 50 | X= Force input 51 | b =output at zero load input 52 | */ 53 | float LoadCell::getForce (int loadCellAnalogIn) 54 | { 55 | float vCalc = getVoltage (loadCellAnalogIn); 56 | return ((vCalc - _noLoadCalcV) / _calibratedSpan); 57 | } 58 | 59 | float LoadCell::getVoltage (int loadCellAnalogIn) 60 | { 61 | float voltage = ((5.0 * loadCellAnalogIn) / 1023.0); 62 | return voltage; 63 | 64 | } -------------------------------------------------------------------------------- /LoadCell/LoadCell.h: -------------------------------------------------------------------------------- 1 | /* 2 | Title: LoadCell.h 3 | Author/Date: gNSortino@yahoo.com / 2014-07-26 4 | Description: This library will take the input from an 5 | FC22 MSI Load Cell (0.5V - 4.5V) and convert it into lbf 6 | configuration inputs: 7 | inV: 8 | the supply voltage (should be 5 volts) 9 | noLoadCalcV: 10 | the no load calculated voltage 11 | loadMassV: 12 | the full load mass voltage 13 | loadMassLBF: 14 | the full load mass in pounds force 15 | measurement input: 16 | loadCellAnalogIn: 17 | output: 18 | mass: 19 | outputs the calculated mass given the aforementioned 20 | inputs. 21 | Note that this library will not setup any pins. It 22 | is expected that these will be defined by the calling 23 | program. 24 | Change Log: 25 | GNS 2014-07-26: initial version 26 | */ 27 | #ifndef LoadCell_h 28 | #define LoadCell_h 29 | 30 | #include "Arduino.h" 31 | #include "LoadCell.h" 32 | 33 | class LoadCell 34 | { 35 | public: 36 | LoadCell (float inV, float noLoadCalcV, float loadMassV, float loadMassLBF); 37 | float getForce (int loadCellAnalogIn); 38 | private: 39 | float getVoltage (int loadCellAnalogIn); 40 | float _ratiometricScaleFactor; 41 | float _calibratedSpan; 42 | float _noLoadCalcV; 43 | 44 | }; 45 | 46 | #endif -------------------------------------------------------------------------------- /LoadCell/LoadCell.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int sensorPin = A0; // force sensor input 4 | int sensorValue; 5 | float calcForce; 6 | 7 | //Calibration Parameters 8 | float inV = 5.0; // input supply voltage 9 | float noLoadCalcV = 0.500; // no load calculated voltage (used for calibration) 10 | float loadMassV = 4.0; // the calibrated output voltage at full mass 11 | float loadMassLBF = 100.0; // the mass of the calibration input; 12 | LoadCell loadCell (inV, noLoadCalcV, loadMassV, loadMassLBF); 13 | 14 | void setup() { 15 | 16 | Serial.begin(57600); 17 | Serial.println ("Signal (0 - 1023),Force (lbf)"); 18 | } 19 | 20 | void loop() { 21 | sensorValue = analogRead(sensorPin); 22 | calcForce = loadCell.getForce (sensorValue); 23 | Serial.print (sensorValue); //Analog Signal 24 | Serial.print (","); 25 | Serial.println (calcForce,3); //Force in lbf 26 | delay(2000); 27 | } 28 | -------------------------------------------------------------------------------- /LoadCell/keywords.txt: -------------------------------------------------------------------------------- 1 | LoadCell KEYWORD1 2 | getForce KEYWORD2 3 | getVoltage KEYWORD2 -------------------------------------------------------------------------------- /MAX31855/Adafruit_MAX31855.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is a library for the Adafruit Thermocouple Sensor w/MAX31855K 3 | 4 | Designed specifically to work with the Adafruit Thermocouple Sensor 5 | ----> https://www.adafruit.com/products/269 6 | 7 | These displays use SPI to communicate, 3 pins are required to 8 | interface 9 | Adafruit invests time and resources providing this open source code, 10 | please support Adafruit and open-source hardware by purchasing 11 | products from Adafruit! 12 | 13 | Written by Limor Fried/Ladyada for Adafruit Industries. 14 | BSD license, all text above must be included in any redistribution 15 | 16 | Change Log: 17 | GNS 2014-01-12: updated the code to use _delay_us instead of 18 | _delay_ms as the latter was to slow. See: 19 | http://forums.adafruit.com/viewtopic.php?f=31&t=47944&p=242638#p242638 20 | for details. 21 | ****************************************************/ 22 | 23 | #include "Adafruit_MAX31855.h" 24 | #include 25 | #include 26 | #include 27 | 28 | 29 | Adafruit_MAX31855::Adafruit_MAX31855(int8_t SCLK, int8_t CS, int8_t MISO) { 30 | sclk = SCLK; 31 | cs = CS; 32 | miso = MISO; 33 | 34 | //define pin modes 35 | pinMode(cs, OUTPUT); 36 | pinMode(sclk, OUTPUT); 37 | pinMode(miso, INPUT); 38 | 39 | digitalWrite(cs, HIGH); 40 | } 41 | 42 | 43 | double Adafruit_MAX31855::readInternal(void) { 44 | uint32_t v; 45 | 46 | v = spiread32(); 47 | 48 | // ignore bottom 4 bits - they're just thermocouple data 49 | v >>= 4; 50 | 51 | // pull the bottom 11 bits off 52 | float internal = v & 0x7FF; 53 | internal *= 0.0625; // LSB = 0.0625 degrees 54 | // check sign bit! 55 | if (v & 0x800) 56 | internal *= -1; 57 | //Serial.print("\tInternal Temp: "); Serial.println(internal); 58 | return internal; 59 | } 60 | 61 | double Adafruit_MAX31855::readCelsius(void) { 62 | 63 | int32_t v; 64 | 65 | v = spiread32(); 66 | 67 | //Serial.print("0x"); Serial.println(v, HEX); 68 | 69 | /* 70 | float internal = (v >> 4) & 0x7FF; 71 | internal *= 0.0625; 72 | if ((v >> 4) & 0x800) 73 | internal *= -1; 74 | Serial.print("\tInternal Temp: "); Serial.println(internal); 75 | */ 76 | 77 | if (v & 0x7) { 78 | // uh oh, a serious problem! 79 | return NAN; 80 | } 81 | 82 | // get rid of internal temp data, and any fault bits 83 | v >>= 18; 84 | //Serial.println(v, HEX); 85 | 86 | // pull the bottom 13 bits off 87 | int16_t temp = v & 0x3FFF; 88 | 89 | // check sign bit 90 | if (v & 0x2000) 91 | temp |= 0xC000; 92 | //Serial.println(temp); 93 | 94 | double centigrade = v; 95 | 96 | // LSB = 0.25 degrees C 97 | centigrade *= 0.25; 98 | return centigrade; 99 | } 100 | 101 | uint8_t Adafruit_MAX31855::readError() { 102 | return spiread32() & 0x7; 103 | } 104 | 105 | double Adafruit_MAX31855::readFarenheit(void) { 106 | float f = readCelsius(); 107 | f *= 9.0; 108 | f /= 5.0; 109 | f += 32; 110 | return f; 111 | } 112 | 113 | uint32_t Adafruit_MAX31855::spiread32(void) { 114 | int i; 115 | uint32_t d = 0; 116 | 117 | digitalWrite(sclk, LOW); 118 | _delay_us(1); 119 | digitalWrite(cs, LOW); 120 | _delay_us(1); 121 | 122 | for (i=31; i>=0; i--) 123 | { 124 | digitalWrite(sclk, LOW); 125 | _delay_us(1); 126 | d <<= 1; 127 | if (digitalRead(miso)) { 128 | d |= 1; 129 | } 130 | 131 | digitalWrite(sclk, HIGH); 132 | _delay_us(1); 133 | } 134 | 135 | digitalWrite(cs, HIGH); 136 | //Serial.println(d, HEX); 137 | return d; 138 | } 139 | -------------------------------------------------------------------------------- /MAX31855/Adafruit_MAX31855.h: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is a library for the Adafruit Thermocouple Sensor w/MAX31855K 3 | 4 | Designed specifically to work with the Adafruit Thermocouple Sensor 5 | ----> https://www.adafruit.com/products/269 6 | 7 | These displays use SPI to communicate, 3 pins are required to 8 | interface 9 | Adafruit invests time and resources providing this open source code, 10 | please support Adafruit and open-source hardware by purchasing 11 | products from Adafruit! 12 | 13 | Written by Limor Fried/Ladyada for Adafruit Industries. 14 | BSD license, all text above must be included in any redistribution 15 | ****************************************************/ 16 | 17 | 18 | #if (ARDUINO >= 100) 19 | #include "Arduino.h" 20 | #else 21 | #include "WProgram.h" 22 | #endif 23 | 24 | class Adafruit_MAX31855 { 25 | public: 26 | Adafruit_MAX31855(int8_t SCLK, int8_t CS, int8_t MISO); 27 | 28 | double readInternal(void); 29 | double readCelsius(void); 30 | double readFarenheit(void); 31 | uint8_t readError(); 32 | 33 | private: 34 | int8_t sclk, miso, cs; 35 | uint32_t spiread32(void); 36 | }; 37 | -------------------------------------------------------------------------------- /MAX31855/README.txt: -------------------------------------------------------------------------------- 1 | This is the Adafruit MAX31885 Arduino Library 2 | 3 | Tested and works great with the Adafruit Thermocouple Breakout w/MAX31885K 4 | ------> http://www.adafruit.com/products/269 5 | 6 | These modules use SPI to communicate, 3 pins are required to 7 | interface 8 | 9 | Adafruit invests time and resources providing this open source code, 10 | please support Adafruit and open-source hardware by purchasing 11 | products from Adafruit! 12 | 13 | Written by Limor Fried/Ladyada for Adafruit Industries. 14 | BSD license, check license.txt for more information 15 | All text above must be included in any redistribution 16 | 17 | To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_MAX31885. Check that the Adafruit_MAX31885 folder contains Adafruit_MAX31885.cpp and Adafruit_MAX31885.h 18 | 19 | Place the Adafruit_MAX31885 library folder your /libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE. -------------------------------------------------------------------------------- /MAX31855/examples/lcdthermocouple/LCDthermocouple.pde: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is an example for the Adafruit Thermocouple Sensor w/MAX31855K 3 | 4 | Designed specifically to work with the Adafruit Thermocouple Sensor 5 | ----> https://www.adafruit.com/products/269 6 | 7 | These displays use SPI to communicate, 3 pins are required to 8 | interface 9 | Adafruit invests time and resources providing this open source code, 10 | please support Adafruit and open-source hardware by purchasing 11 | products from Adafruit! 12 | 13 | Written by Limor Fried/Ladyada for Adafruit Industries. 14 | BSD license, all text above must be included in any redistribution 15 | ****************************************************/ 16 | 17 | #include "Adafruit_MAX31855.h" 18 | #include 19 | 20 | int thermoCLK = 3; 21 | int thermoCS = 4; 22 | int thermoDO = 5; 23 | 24 | // Initialize the Thermocouple 25 | Adafruit_MAX31855 thermocouple(thermoCLK, thermoCS, thermoDO); 26 | // initialize the library with the numbers of the interface pins 27 | LiquidCrystal lcd(7, 8, 9, 10, 11, 12); 28 | 29 | 30 | void setup() { 31 | Serial.begin(9600); 32 | // set up the LCD's number of columns and rows: 33 | lcd.begin(16, 2); 34 | 35 | lcd.print("MAX31855 test"); 36 | // wait for MAX chip to stabilize 37 | delay(500); 38 | } 39 | 40 | void loop() { 41 | // basic readout test, just print the current temp 42 | lcd.setCursor(0, 0); 43 | lcd.print("Int. Temp = "); 44 | lcd.println(thermocouple.readInternal()); 45 | lcd.print(" "); 46 | 47 | double c = thermocouple.readCelsius(); 48 | lcd.setCursor(0, 1); 49 | if (isnan(c)) 50 | { 51 | lcd.print("T/C Problem"); 52 | } 53 | else 54 | { 55 | lcd.print("C = "); 56 | lcd.print(c); 57 | lcd.print(" "); 58 | } 59 | 60 | delay(1000); 61 | } 62 | -------------------------------------------------------------------------------- /MAX31855/examples/serialthermocouple/serialthermocouple.pde: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is an example for the Adafruit Thermocouple Sensor w/MAX31855K 3 | 4 | Designed specifically to work with the Adafruit Thermocouple Sensor 5 | ----> https://www.adafruit.com/products/269 6 | 7 | These displays use SPI to communicate, 3 pins are required to 8 | interface 9 | Adafruit invests time and resources providing this open source code, 10 | please support Adafruit and open-source hardware by purchasing 11 | products from Adafruit! 12 | 13 | Written by Limor Fried/Ladyada for Adafruit Industries. 14 | BSD license, all text above must be included in any redistribution 15 | ****************************************************/ 16 | 17 | #include "Adafruit_MAX31855.h" 18 | 19 | int thermoDO = 3; 20 | int thermoCS = 4; 21 | int thermoCLK = 5; 22 | 23 | Adafruit_MAX31855 thermocouple(thermoCLK, thermoCS, thermoDO); 24 | 25 | void setup() { 26 | Serial.begin(9600); 27 | 28 | Serial.println("MAX31855 test"); 29 | // wait for MAX chip to stabilize 30 | delay(500); 31 | } 32 | 33 | void loop() { 34 | // basic readout test, just print the current temp 35 | Serial.print("Internal Temp = "); 36 | Serial.println(thermocouple.readInternal()); 37 | 38 | double c = thermocouple.readCelsius(); 39 | if (isnan(c)) { 40 | Serial.println("Something wrong with thermocouple!"); 41 | } else { 42 | Serial.print("C = "); 43 | Serial.println(c); 44 | } 45 | //Serial.print("F = "); 46 | //Serial.println(thermocouple.readFarenheit()); 47 | 48 | delay(1000); 49 | } -------------------------------------------------------------------------------- /MAX31855/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map for NewSoftSerial 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | Adafruit_MAX31855 KEYWORD1 9 | max6675 KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | 15 | readCelsius KEYWORD2 16 | readFarenheit KEYWORD2 17 | 18 | ####################################### 19 | # Constants (LITERAL1) 20 | ####################################### 21 | 22 | -------------------------------------------------------------------------------- /MAX31855/license.txt: -------------------------------------------------------------------------------- 1 | Software License Agreement (BSD License) 2 | 3 | Copyright (c) 2012, Adafruit Industries 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of the copyright holders nor the 14 | names of its contributors may be used to endorse or promote products 15 | derived from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /PMCtrl/PMCtrl.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Title: PMCtrl.h 3 | Author: gNSortino@yahoo.com 4 | Description: This library implements the main features 5 | of the Pololu Maestro. It was tested against the 6 | micro-maestro. Additional features will be added as 7 | needed/requested. 8 | 9 | The code is based off the Pololu user guide as 10 | well as the software serial** arduino library see 11 | the relevant links below: 12 | # Sofware Serial Library 13 | http://arduino.cc/en/Reference/SoftwareSerial 14 | # Pololu Arduino Tutorial 15 | http://forum.pololu.com/viewtopic.php?f=16&t=5696 16 | # Pololu User Guide 17 | http://www.pololu.com/docs/0J40/all#7.c 18 | 19 | **This code relies on the SoftwareSerial Arduino 20 | library. It is recommended that this library also be 21 | #included in the calling code as the Arduino can 22 | sometimes have problems if this isn't done. 23 | Revision History: 24 | 2013-07-06 gNSortino@yahoo.com : initial release 25 | 2014-11-02 gNSortino@yahoo.com: updated getPosition and getErrors libraries to 26 | account latency when reading data. getErrors will probably need further work. 27 | 2015-01-19 gNSortino@yahoo.com: added setAcceleration method 28 | */ 29 | 30 | #include "Arduino.h" 31 | #include "SoftwareSerial.h" 32 | #include "PMCtrl.h" 33 | 34 | /* 35 | Sets the transit and receive pins on the 36 | SoftwareSerial Interface. 37 | */ 38 | PMCtrl::PMCtrl (int rxPin, int txPin, long baudRate) : _serialCtrl (rxPin, txPin) // RX, TX 39 | { 40 | // The highest Baud rate the micro seems to support is 57600 (un-confirmed) 41 | _serialCtrl.begin (baudRate); 42 | } 43 | 44 | /* 45 | sets the servo to the desired 'pos'ition in 46 | microseconds. 47 | */ 48 | void PMCtrl::setTarget (unsigned int pos, unsigned char channel, int deviceID) 49 | { 50 | //Maestro uses quarter microseconds so convert accordingly 51 | pos = pos * 4; 52 | 53 | _serialCtrl.write(0xAA); // start byte 54 | _serialCtrl.write(deviceID); // device id 55 | _serialCtrl.write(0x04); // command number 56 | _serialCtrl.write(channel); // servo number 57 | _serialCtrl.write(pos & 0x7F); // target low bits 58 | _serialCtrl.write((pos >> 7) & 0x7F); // target high bits 59 | 60 | } 61 | 62 | 63 | /* 64 | Sets the speed that the servo moves at. Note that 65 | this does not have to be set. If left alone it will 66 | take the default value, which should be instantaneous. 67 | Although this is of course limited by the physical speed 68 | of the servo. Speed is set set in units of .25us/10ms. 69 | For example, setting a value of 140 corresponds to a 70 | speed of 3.5 us/ms eg. 71 | 3.5 = 140 * (.25 us / 10ms) 72 | In practical terms this means that the servo can move 73 | 3.5us in 1 ms. For example, moving from 1000us to 1350us 74 | would take 100ms 75 | */ 76 | void PMCtrl::setServoSpeed (unsigned int servoSpeed, unsigned char channel, int deviceID) 77 | { 78 | 79 | _serialCtrl.write(0xAA); // start byte 80 | _serialCtrl.write(deviceID); // device id 81 | _serialCtrl.write(0x07); // command number 82 | _serialCtrl.write(channel); // servo number 83 | _serialCtrl.write(servoSpeed & 0x7F); // target low bits 84 | _serialCtrl.write((servoSpeed >> 7) & 0x7F); // target high bits 85 | } 86 | 87 | /* 88 | Sets the acceleration of the servo 89 | */ 90 | void PMCtrl::setAcceleration (unsigned int acceleration, unsigned char channel, int deviceID) 91 | { 92 | 93 | _serialCtrl.write(0xAA); // start byte 94 | _serialCtrl.write(deviceID); // device id 95 | _serialCtrl.write(0x09); // command number 96 | _serialCtrl.write(channel); // servo number 97 | _serialCtrl.write(acceleration & 0x7F); // target low bits 98 | _serialCtrl.write((acceleration >> 7) & 0x7F); // target high bits 99 | } 100 | 101 | /* 102 | Sends all servos to their home positions 103 | */ 104 | void PMCtrl::goHome (int deviceID) 105 | { 106 | _serialCtrl.write(0xAA); // start byte 107 | _serialCtrl.write(deviceID); // device id 108 | _serialCtrl.write(0x22); // command number 109 | } 110 | 111 | /* 112 | Returns the position of the specified servo in microseconds 113 | Note that if the microcontroller is unable to read from the 114 | servo for any reason than Null or some other obscure value 115 | could be returned. 116 | */ 117 | unsigned int PMCtrl::getPosition (unsigned char channel, int deviceID) 118 | { 119 | unsigned int servoPosition = 0; 120 | 121 | // Clear any un-read data from the buffer 122 | while (_serialCtrl.available()) 123 | _serialCtrl.read(); 124 | 125 | _serialCtrl.write(0xAA); // start byte 126 | _serialCtrl.write(deviceID); // device id 127 | _serialCtrl.write(0x10); // command number 128 | _serialCtrl.write(channel); // servo number 129 | 130 | 131 | // try 'i' times to read from the buffer (this accounts for latency) 132 | for (int i = 0; i < 10; i += 1) 133 | { 134 | if ( _serialCtrl.available() >= 2) 135 | { 136 | 137 | servoPosition = _serialCtrl.read(); 138 | if ( _serialCtrl.available() ) 139 | { 140 | servoPosition += ( _serialCtrl.read() * 256 ); 141 | servoPosition = servoPosition / 4; 142 | break; 143 | } 144 | } 145 | } 146 | return servoPosition; 147 | } 148 | 149 | 150 | /* 151 | Returns error codes from the maestro. 152 | See: http://www.pololu.com/docs/0J40/all#4.b for a list of error 153 | codes. 154 | */ 155 | unsigned int PMCtrl::getErrors (unsigned char channel, int deviceID) 156 | { 157 | unsigned int errors = 0; 158 | 159 | _serialCtrl.write(0xAA); // start byte 160 | _serialCtrl.write(deviceID); // device id 161 | _serialCtrl.write(0x21); // command number 162 | 163 | for (int i = 0; i < 10; i += 1) 164 | { 165 | if ( _serialCtrl.available() ) 166 | { 167 | errors = _serialCtrl.read(); 168 | if ( _serialCtrl.available() ) 169 | { 170 | errors += _serialCtrl.read() * 256; 171 | break; 172 | } 173 | } 174 | } 175 | return errors; 176 | } 177 | 178 | /* 179 | Destructor (cleanup) 180 | */ 181 | PMCtrl::~PMCtrl() 182 | { 183 | 184 | } -------------------------------------------------------------------------------- /PMCtrl/PMCtrl.h: -------------------------------------------------------------------------------- 1 | /* 2 | Title: PMCtrl.h 3 | Author: gNSortino@yahoo.com 4 | Description: This library implements the main features 5 | of the Pololu Maestro. It was tested against the 6 | micro-maestro. Additional features will be added as 7 | needed/requested. 8 | 9 | The code is based off the Pololu user guide as 10 | well as the software serial** arduino library see 11 | the relevant links below: 12 | # Sofware Serial Library 13 | http://arduino.cc/en/Reference/SoftwareSerial 14 | # Pololu Arduino Tutorial 15 | http://forum.pololu.com/viewtopic.php?f=16&t=5696 16 | # Pololu User Guide 17 | http://www.pololu.com/docs/0J40/all#7.c 18 | 19 | **This code relies on the SoftwareSerial Arduino 20 | library. It is recommended that this library also be 21 | #included in the calling code as the Arduino can 22 | sometimes have problems if this isn't done. 23 | 24 | Function descriptions and change history can be found in the 25 | .cpp file of the same name. 26 | */ 27 | 28 | 29 | #ifndef PMCtrl_h 30 | #define PMCtrl_h 31 | 32 | #include "Arduino.h" 33 | #include "SoftwareSerial.h" 34 | 35 | class PMCtrl 36 | { 37 | public: 38 | PMCtrl (int rxPin, int txPin, long baudRate); 39 | ~PMCtrl(); 40 | void setTarget (unsigned int pos, unsigned char channel, int deviceID); 41 | void setServoSpeed (unsigned int servoSpeed, unsigned char channel, int deviceID); 42 | void setAcceleration (unsigned int acceleration, unsigned char channel, int deviceID); 43 | void goHome (int deviceID); 44 | unsigned int getPosition (unsigned char channel, int deviceID); 45 | unsigned int getErrors (unsigned char channel, int deviceID); 46 | private: 47 | int _rxPin; 48 | int _txPin; 49 | SoftwareSerial _serialCtrl; 50 | }; 51 | 52 | #endif -------------------------------------------------------------------------------- /PMCtrl/examples/PMCtrl/PMCtrl.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Title: PMCtrl (Demo) 3 | Author: gNSortino@yahoo.com 4 | Description: This is a demo library that shows how to 5 | test the main features of the Pololu Maestro library (PMCtrl) 6 | written for the arduino development environment. 7 | 8 | The code is based off the Pololu user guide as 9 | well as the software serial** arduino library see 10 | the relevant links below: 11 | # Sofware Serial Library 12 | http://arduino.cc/en/Reference/SoftwareSerial 13 | # Pololu Arduino Tutorial 14 | http://forum.pololu.com/viewtopic.php?f=16&t=5696 15 | # Pololu User Guide 16 | http://www.pololu.com/docs/0J40/all#7.c 17 | 18 | **This code relies on the SoftwareSerial Arduino 19 | library. It is recomended that this library also be 20 | #included in the calling code as the Arduino can 21 | sometimes have problems if this isn't done. 22 | 23 | Function descriptions can be found in the .cpp file 24 | of the same name. I am happy to add additional functions 25 | as requested or have others add them as well. 26 | Revision History: 27 | 2013-07-06/gNSortino@yahoo.com : inital release 28 | 2014-11-02/gNSortino@yahoo.com : changed structure of sample program to reflect 29 | arduino standards. Code suggestions were kindly made by Adriano @ Adrirobot 30 | http://it.emcelettronica.com/author/adrirobot/ 31 | */ 32 | 33 | #include 34 | #include 35 | 36 | 37 | PMCtrl servoCtrl (11, 3, 9600); //RX, TX, Baud 38 | 39 | void setup () 40 | { 41 | Serial.begin(9600); // needed for console output 42 | } 43 | 44 | void loop () 45 | { 46 | Serial.println ("Beginning"); 47 | 48 | Serial.println ("Now I rotate the servo - Speed 50"); 49 | servoCtrl.setServoSpeed (0, 0, 12); 50 | servoCtrl.setTarget (608, 0, 12); 51 | delay (5000); 52 | servoCtrl.getPosition(0,12); 53 | Serial.print ("Position is: "); Serial.println (servoCtrl.getPosition(0,12)); 54 | 55 | 56 | Serial.println ("Now I rotate the servo - Speed 15"); 57 | servoCtrl.setServoSpeed (15, 0, 12); 58 | servoCtrl.setTarget (2224, 0, 12); 59 | delay (5000); 60 | servoCtrl.getPosition(0,12); Serial.print ("Position is: "); Serial.println (servoCtrl.getPosition(0,12)); 61 | 62 | 63 | servoCtrl.setAcceleration(30,0,12); 64 | servoCtrl.goHome(12); 65 | delay (5000); 66 | 67 | Serial.println ("Done"); 68 | delay (2000); 69 | } -------------------------------------------------------------------------------- /PMCtrl/keywords.txt: -------------------------------------------------------------------------------- 1 | PMCtrl KEYWORD1 2 | setTarget KEYWORD2 3 | setServoSpeed KEYWORD2 4 | setAcceleration KEYWORD2 5 | goHome KEYWORD2 6 | getPosition KEYWORD2 7 | getErrors KEYWORD2 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Arduino-Liquid-Engine-Software 2 | 3 | ## Control and Data Capture Software for My Liquid Fueled Engines 4 | 5 | Author: Graham N. Sortino 6 | Web Site: http://wiki.fubarlabs.org/fubarwiki/Small-Liquid-Fueled-Rocket-Engines.ashx 7 | Git Hub URL: https://github.com/gNSortino/Arduino-Liquid-Engine-Software 8 | 9 | ## Start Here 10 | This file contains information about the contents of the software included in this 11 | repository. It also contains some quick usage instructions. I try to keep most of 12 | the documentation w/in the libraries themselves in order to prevent the readme 13 | file from getting out of date so please consultant the relevant libraries 14 | for further information. 15 | 16 | ## What is This??? 17 | Over the past few years I developed a small liquid fueled rocket engine and some 18 | softawre that was used to control/analyze it. The results of which can be found 19 | here. The software was written to run on an Arduino Uno (rev3) micro-controller 20 | but could easily be ported to another micro. 21 | 22 | ## What is in Here??? 23 | Many librarires for controlling and measuring my rocket engine and igniter plus a main EngineController.ino piece of code. The libraries may be generally useful in other projects, however, EngineController.ino is fairly bespoke to my needs. Each library is fully documented and contains it's own demo function to show how it works. So, for example, if you are just interested in using the Thermocouple libraries to handle temperature for a project then you can just 24 | grab the relevant piece of code without worrying about doing a complicated build process. 25 | 26 | ## Libraries 27 | * **ThermoTemp -** Reads the output of a type K thermocouple connected to an AD595AQ thermocouple. See 28 | the [datasheet](http://www.analog.com/static/imported-files/data_sheets/AD594_595.pdf) for more info. 29 | The library calculates temperature in Celsius, Kelvin, Fahrenheit, and Rankine. The sample routine 30 | included in this library outputs the aforementioned data in CSV format. 31 | 32 | * **MAX31855 -** reads the temperature of the adafruit [MAX31855 w/ associated breakout board](http://www.adafruit.com/product/269). This is an adafruit library (not mine) but I put it here for convenience. 33 | 34 | * **Transducer -** Reads data from an analog pressure transducer and outputs Pounds Per Square Inch (PSI), 35 | Pascal (Pa), and Mega Pascal (MPa). The library was specifically designed to work with 2 brands of 36 | pressure transducers: SSI 1000psi absolute gauge transducer and MSI 1000psi Ratio Metric. However, 37 | it could easily be converted to support other vendors. 38 | 39 | * **EngineMath -** This sophisticated library calculates the thermodynamic properties of Gas and Liquid 40 | mass flow given pressure, orifice area, density, and a few other relevant parameters. It was used 41 | to calculate the mass-flow characters of my engine in real-time. The sample library outputs a variety 42 | of engine data-points in a CSV format 43 | 44 | * **LoadCell -** This library will take the input from an FC22 MSI Load Cell (0.5V - 4.5V) and convert it into lbf. However, it could easily be configured to work with other load cells. 45 | 46 | * **PMCtrl -** This library, while included for convenience, is maintained on a separate [GitHub repository](https://github.com/gNSortino/PMCtrl). It is an interface between the Arduino and the [Pololu Maestro Server controller](https://www.pololu.com/product/1350) 47 | 48 | * **StopWatch -** This library performs the basic functions of a stop watch and is used to simplify the process of keeping track of time on an arduino. 49 | 50 | * **EngineController -** This is the main library and is responsible for controlling the engine and 51 | sending back relevant data. It performs the following functions (see software documentation for 52 | full details). 53 | 1. Test Sensors 54 | 2. Test Valves + Spark Igniter 55 | 3. Manual Valve Check 56 | 4. Set Orifice Diameters for Measurements 57 | 5. Run Engine 58 | 59 | It also has various safety features built in to help mitigate any dangerous conditions. 60 | -------------------------------------------------------------------------------- /SoftwareSerial/SoftwareSerial.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SoftwareSerial.cpp (formerly NewSoftSerial.cpp) - 3 | Multi-instance software serial library for Arduino/Wiring 4 | -- Interrupt-driven receive and other improvements by ladyada 5 | (http://ladyada.net) 6 | -- Tuning, circular buffer, derivation from class Print/Stream, 7 | multi-instance support, porting to 8MHz processors, 8 | various optimizations, PROGMEM delay tables, inverse logic and 9 | direct port writing by Mikal Hart (http://www.arduiniana.org) 10 | -- Pin change interrupt macros by Paul Stoffregen (http://www.pjrc.com) 11 | -- 20MHz processor support by Garrett Mace (http://www.macetech.com) 12 | -- ATmega1280/2560 support by Brett Hagman (http://www.roguerobotics.com/) 13 | 14 | This library is free software; you can redistribute it and/or 15 | modify it under the terms of the GNU Lesser General Public 16 | License as published by the Free Software Foundation; either 17 | version 2.1 of the License, or (at your option) any later version. 18 | 19 | This library is distributed in the hope that it will be useful, 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | Lesser General Public License for more details. 23 | 24 | You should have received a copy of the GNU Lesser General Public 25 | License along with this library; if not, write to the Free Software 26 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 27 | 28 | The latest version of this library can always be found at 29 | http://arduiniana.org. 30 | */ 31 | 32 | // When set, _DEBUG co-opts pins 11 and 13 for debugging with an 33 | // oscilloscope or logic analyzer. Beware: it also slightly modifies 34 | // the bit times, so don't rely on it too much at high baud rates 35 | #define _DEBUG 0 36 | #define _DEBUG_PIN1 11 37 | #define _DEBUG_PIN2 13 38 | // 39 | // Includes 40 | // 41 | #include 42 | #include 43 | #include 44 | #include 45 | // 46 | // Lookup table 47 | // 48 | typedef struct _DELAY_TABLE 49 | { 50 | long baud; 51 | unsigned short rx_delay_centering; 52 | unsigned short rx_delay_intrabit; 53 | unsigned short rx_delay_stopbit; 54 | unsigned short tx_delay; 55 | } DELAY_TABLE; 56 | 57 | #if F_CPU == 16000000 58 | 59 | static const DELAY_TABLE PROGMEM table[] = 60 | { 61 | // baud rxcenter rxintra rxstop tx 62 | { 115200, 1, 17, 17, 12, }, 63 | { 57600, 10, 37, 37, 33, }, 64 | { 38400, 25, 57, 57, 54, }, 65 | { 31250, 31, 70, 70, 68, }, 66 | { 28800, 34, 77, 77, 74, }, 67 | { 19200, 54, 117, 117, 114, }, 68 | { 14400, 74, 156, 156, 153, }, 69 | { 9600, 114, 236, 236, 233, }, 70 | { 4800, 233, 474, 474, 471, }, 71 | { 2400, 471, 950, 950, 947, }, 72 | { 1200, 947, 1902, 1902, 1899, }, 73 | { 600, 1902, 3804, 3804, 3800, }, 74 | { 300, 3804, 7617, 7617, 7614, }, 75 | }; 76 | 77 | const int XMIT_START_ADJUSTMENT = 5; 78 | 79 | #elif F_CPU == 8000000 80 | 81 | static const DELAY_TABLE table[] PROGMEM = 82 | { 83 | // baud rxcenter rxintra rxstop tx 84 | { 115200, 1, 5, 5, 3, }, 85 | { 57600, 1, 15, 15, 13, }, 86 | { 38400, 2, 25, 26, 23, }, 87 | { 31250, 7, 32, 33, 29, }, 88 | { 28800, 11, 35, 35, 32, }, 89 | { 19200, 20, 55, 55, 52, }, 90 | { 14400, 30, 75, 75, 72, }, 91 | { 9600, 50, 114, 114, 112, }, 92 | { 4800, 110, 233, 233, 230, }, 93 | { 2400, 229, 472, 472, 469, }, 94 | { 1200, 467, 948, 948, 945, }, 95 | { 600, 948, 1895, 1895, 1890, }, 96 | { 300, 1895, 3805, 3805, 3802, }, 97 | }; 98 | 99 | const int XMIT_START_ADJUSTMENT = 4; 100 | 101 | #elif F_CPU == 20000000 102 | 103 | // 20MHz support courtesy of the good people at macegr.com. 104 | // Thanks, Garrett! 105 | 106 | static const DELAY_TABLE PROGMEM table[] = 107 | { 108 | // baud rxcenter rxintra rxstop tx 109 | { 115200, 3, 21, 21, 18, }, 110 | { 57600, 20, 43, 43, 41, }, 111 | { 38400, 37, 73, 73, 70, }, 112 | { 31250, 45, 89, 89, 88, }, 113 | { 28800, 46, 98, 98, 95, }, 114 | { 19200, 71, 148, 148, 145, }, 115 | { 14400, 96, 197, 197, 194, }, 116 | { 9600, 146, 297, 297, 294, }, 117 | { 4800, 296, 595, 595, 592, }, 118 | { 2400, 592, 1189, 1189, 1186, }, 119 | { 1200, 1187, 2379, 2379, 2376, }, 120 | { 600, 2379, 4759, 4759, 4755, }, 121 | { 300, 4759, 9523, 9523, 9520, }, 122 | }; 123 | 124 | const int XMIT_START_ADJUSTMENT = 6; 125 | 126 | #else 127 | 128 | #error This version of SoftwareSerial supports only 20, 16 and 8MHz processors 129 | 130 | #endif 131 | 132 | // 133 | // Statics 134 | // 135 | SoftwareSerial *SoftwareSerial::active_object = 0; 136 | char SoftwareSerial::_receive_buffer[_SS_MAX_RX_BUFF]; 137 | volatile uint8_t SoftwareSerial::_receive_buffer_tail = 0; 138 | volatile uint8_t SoftwareSerial::_receive_buffer_head = 0; 139 | 140 | // 141 | // Debugging 142 | // 143 | // This function generates a brief pulse 144 | // for debugging or measuring on an oscilloscope. 145 | inline void DebugPulse(uint8_t pin, uint8_t count) 146 | { 147 | #if _DEBUG 148 | volatile uint8_t *pport = portOutputRegister(digitalPinToPort(pin)); 149 | 150 | uint8_t val = *pport; 151 | while (count--) 152 | { 153 | *pport = val | digitalPinToBitMask(pin); 154 | *pport = val; 155 | } 156 | #endif 157 | } 158 | 159 | // 160 | // Private methods 161 | // 162 | 163 | /* static */ 164 | inline void SoftwareSerial::tunedDelay(uint16_t delay) { 165 | uint8_t tmp=0; 166 | 167 | asm volatile("sbiw %0, 0x01 \n\t" 168 | "ldi %1, 0xFF \n\t" 169 | "cpi %A0, 0xFF \n\t" 170 | "cpc %B0, %1 \n\t" 171 | "brne .-10 \n\t" 172 | : "+r" (delay), "+a" (tmp) 173 | : "0" (delay) 174 | ); 175 | } 176 | 177 | // This function sets the current object as the "listening" 178 | // one and returns true if it replaces another 179 | bool SoftwareSerial::listen() 180 | { 181 | if (active_object != this) 182 | { 183 | _buffer_overflow = false; 184 | uint8_t oldSREG = SREG; 185 | cli(); 186 | _receive_buffer_head = _receive_buffer_tail = 0; 187 | active_object = this; 188 | SREG = oldSREG; 189 | return true; 190 | } 191 | 192 | return false; 193 | } 194 | 195 | // 196 | // The receive routine called by the interrupt handler 197 | // 198 | void SoftwareSerial::recv() 199 | { 200 | 201 | #if GCC_VERSION < 40302 202 | // Work-around for avr-gcc 4.3.0 OSX version bug 203 | // Preserve the registers that the compiler misses 204 | // (courtesy of Arduino forum user *etracer*) 205 | asm volatile( 206 | "push r18 \n\t" 207 | "push r19 \n\t" 208 | "push r20 \n\t" 209 | "push r21 \n\t" 210 | "push r22 \n\t" 211 | "push r23 \n\t" 212 | "push r26 \n\t" 213 | "push r27 \n\t" 214 | ::); 215 | #endif 216 | 217 | uint8_t d = 0; 218 | 219 | // If RX line is high, then we don't see any start bit 220 | // so interrupt is probably not for us 221 | if (_inverse_logic ? rx_pin_read() : !rx_pin_read()) 222 | { 223 | // Wait approximately 1/2 of a bit width to "center" the sample 224 | tunedDelay(_rx_delay_centering); 225 | DebugPulse(_DEBUG_PIN2, 1); 226 | 227 | // Read each of the 8 bits 228 | for (uint8_t i=0x1; i; i <<= 1) 229 | { 230 | tunedDelay(_rx_delay_intrabit); 231 | DebugPulse(_DEBUG_PIN2, 1); 232 | uint8_t noti = ~i; 233 | if (rx_pin_read()) 234 | d |= i; 235 | else // else clause added to ensure function timing is ~balanced 236 | d &= noti; 237 | } 238 | 239 | // skip the stop bit 240 | tunedDelay(_rx_delay_stopbit); 241 | DebugPulse(_DEBUG_PIN2, 1); 242 | 243 | if (_inverse_logic) 244 | d = ~d; 245 | 246 | // if buffer full, set the overflow flag and return 247 | if ((_receive_buffer_tail + 1) % _SS_MAX_RX_BUFF != _receive_buffer_head) 248 | { 249 | // save new data in buffer: tail points to where byte goes 250 | _receive_buffer[_receive_buffer_tail] = d; // save new byte 251 | _receive_buffer_tail = (_receive_buffer_tail + 1) % _SS_MAX_RX_BUFF; 252 | } 253 | else 254 | { 255 | #if _DEBUG // for scope: pulse pin as overflow indictator 256 | DebugPulse(_DEBUG_PIN1, 1); 257 | #endif 258 | _buffer_overflow = true; 259 | } 260 | } 261 | 262 | #if GCC_VERSION < 40302 263 | // Work-around for avr-gcc 4.3.0 OSX version bug 264 | // Restore the registers that the compiler misses 265 | asm volatile( 266 | "pop r27 \n\t" 267 | "pop r26 \n\t" 268 | "pop r23 \n\t" 269 | "pop r22 \n\t" 270 | "pop r21 \n\t" 271 | "pop r20 \n\t" 272 | "pop r19 \n\t" 273 | "pop r18 \n\t" 274 | ::); 275 | #endif 276 | } 277 | 278 | void SoftwareSerial::tx_pin_write(uint8_t pin_state) 279 | { 280 | if (pin_state == LOW) 281 | *_transmitPortRegister &= ~_transmitBitMask; 282 | else 283 | *_transmitPortRegister |= _transmitBitMask; 284 | } 285 | 286 | uint8_t SoftwareSerial::rx_pin_read() 287 | { 288 | return *_receivePortRegister & _receiveBitMask; 289 | } 290 | 291 | // 292 | // Interrupt handling 293 | // 294 | 295 | /* static */ 296 | inline void SoftwareSerial::handle_interrupt() 297 | { 298 | if (active_object) 299 | { 300 | active_object->recv(); 301 | } 302 | } 303 | 304 | #if defined(PCINT0_vect) 305 | ISR(PCINT0_vect) 306 | { 307 | SoftwareSerial::handle_interrupt(); 308 | } 309 | #endif 310 | 311 | #if defined(PCINT1_vect) 312 | ISR(PCINT1_vect) 313 | { 314 | SoftwareSerial::handle_interrupt(); 315 | } 316 | #endif 317 | 318 | #if defined(PCINT2_vect) 319 | ISR(PCINT2_vect) 320 | { 321 | SoftwareSerial::handle_interrupt(); 322 | } 323 | #endif 324 | 325 | #if defined(PCINT3_vect) 326 | ISR(PCINT3_vect) 327 | { 328 | SoftwareSerial::handle_interrupt(); 329 | } 330 | #endif 331 | 332 | // 333 | // Constructor 334 | // 335 | SoftwareSerial::SoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic /* = false */) : 336 | _rx_delay_centering(0), 337 | _rx_delay_intrabit(0), 338 | _rx_delay_stopbit(0), 339 | _tx_delay(0), 340 | _buffer_overflow(false), 341 | _inverse_logic(inverse_logic) 342 | { 343 | setTX(transmitPin); 344 | setRX(receivePin); 345 | } 346 | 347 | // 348 | // Destructor 349 | // 350 | SoftwareSerial::~SoftwareSerial() 351 | { 352 | end(); 353 | } 354 | 355 | void SoftwareSerial::setTX(uint8_t tx) 356 | { 357 | pinMode(tx, OUTPUT); 358 | digitalWrite(tx, HIGH); 359 | _transmitBitMask = digitalPinToBitMask(tx); 360 | uint8_t port = digitalPinToPort(tx); 361 | _transmitPortRegister = portOutputRegister(port); 362 | } 363 | 364 | void SoftwareSerial::setRX(uint8_t rx) 365 | { 366 | pinMode(rx, INPUT); 367 | if (!_inverse_logic) 368 | digitalWrite(rx, HIGH); // pullup for normal logic! 369 | _receivePin = rx; 370 | _receiveBitMask = digitalPinToBitMask(rx); 371 | uint8_t port = digitalPinToPort(rx); 372 | _receivePortRegister = portInputRegister(port); 373 | } 374 | 375 | // 376 | // Public methods 377 | // 378 | 379 | void SoftwareSerial::begin(long speed) 380 | { 381 | _rx_delay_centering = _rx_delay_intrabit = _rx_delay_stopbit = _tx_delay = 0; 382 | 383 | for (unsigned i=0; i 36 | #include 37 | 38 | /****************************************************************************** 39 | * Definitions 40 | ******************************************************************************/ 41 | 42 | #define _SS_MAX_RX_BUFF 64 // RX buffer size 43 | #ifndef GCC_VERSION 44 | #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) 45 | #endif 46 | 47 | class SoftwareSerial : public Stream 48 | { 49 | private: 50 | // per object data 51 | uint8_t _receivePin; 52 | uint8_t _receiveBitMask; 53 | volatile uint8_t *_receivePortRegister; 54 | uint8_t _transmitBitMask; 55 | volatile uint8_t *_transmitPortRegister; 56 | 57 | uint16_t _rx_delay_centering; 58 | uint16_t _rx_delay_intrabit; 59 | uint16_t _rx_delay_stopbit; 60 | uint16_t _tx_delay; 61 | 62 | uint16_t _buffer_overflow:1; 63 | uint16_t _inverse_logic:1; 64 | 65 | // static data 66 | static char _receive_buffer[_SS_MAX_RX_BUFF]; 67 | static volatile uint8_t _receive_buffer_tail; 68 | static volatile uint8_t _receive_buffer_head; 69 | static SoftwareSerial *active_object; 70 | 71 | // private methods 72 | void recv(); 73 | uint8_t rx_pin_read(); 74 | void tx_pin_write(uint8_t pin_state); 75 | void setTX(uint8_t transmitPin); 76 | void setRX(uint8_t receivePin); 77 | 78 | // private static method for timing 79 | static inline void tunedDelay(uint16_t delay); 80 | 81 | public: 82 | // public methods 83 | SoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic = false); 84 | ~SoftwareSerial(); 85 | void begin(long speed); 86 | bool listen(); 87 | void end(); 88 | bool isListening() { return this == active_object; } 89 | bool overflow() { bool ret = _buffer_overflow; _buffer_overflow = false; return ret; } 90 | int peek(); 91 | 92 | virtual size_t write(uint8_t byte); 93 | virtual int read(); 94 | virtual int available(); 95 | virtual void flush(); 96 | 97 | using Print::write; 98 | 99 | // public only for easy access by interrupt handlers 100 | static inline void handle_interrupt(); 101 | }; 102 | 103 | // Arduino 0012 workaround 104 | #undef int 105 | #undef char 106 | #undef long 107 | #undef byte 108 | #undef float 109 | #undef abs 110 | #undef round 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Software serial multple serial test 3 | 4 | Receives from the hardware serial, sends to software serial. 5 | Receives from software serial, sends to hardware serial. 6 | 7 | The circuit: 8 | * RX is digital pin 10 (connect to TX of other device) 9 | * TX is digital pin 11 (connect to RX of other device) 10 | 11 | Note: 12 | Not all pins on the Mega and Mega 2560 support change interrupts, 13 | so only the following can be used for RX: 14 | 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69 15 | 16 | Not all pins on the Leonardo support change interrupts, 17 | so only the following can be used for RX: 18 | 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI). 19 | 20 | created back in the mists of time 21 | modified 25 May 2012 22 | by Tom Igoe 23 | based on Mikal Hart's example 24 | 25 | This example code is in the public domain. 26 | 27 | */ 28 | #include 29 | 30 | SoftwareSerial mySerial(10, 11); // RX, TX 31 | 32 | void setup() 33 | { 34 | // Open serial communications and wait for port to open: 35 | Serial.begin(57600); 36 | while (!Serial) { 37 | ; // wait for serial port to connect. Needed for Leonardo only 38 | } 39 | 40 | 41 | Serial.println("Goodnight moon!"); 42 | 43 | // set the data rate for the SoftwareSerial port 44 | mySerial.begin(4800); 45 | mySerial.println("Hello, world?"); 46 | } 47 | 48 | void loop() // run over and over 49 | { 50 | if (mySerial.available()) 51 | Serial.write(mySerial.read()); 52 | if (Serial.available()) 53 | mySerial.write(Serial.read()); 54 | } 55 | 56 | -------------------------------------------------------------------------------- /SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Software serial multple serial test 3 | 4 | Receives from the two software serial ports, 5 | sends to the hardware serial port. 6 | 7 | In order to listen on a software port, you call port.listen(). 8 | When using two software serial ports, you have to switch ports 9 | by listen()ing on each one in turn. Pick a logical time to switch 10 | ports, like the end of an expected transmission, or when the 11 | buffer is empty. This example switches ports when there is nothing 12 | more to read from a port 13 | 14 | The circuit: 15 | Two devices which communicate serially are needed. 16 | * First serial device's TX attached to digital pin 2, RX to pin 3 17 | * Second serial device's TX attached to digital pin 4, RX to pin 5 18 | 19 | Note: 20 | Not all pins on the Mega and Mega 2560 support change interrupts, 21 | so only the following can be used for RX: 22 | 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69 23 | 24 | Not all pins on the Leonardo support change interrupts, 25 | so only the following can be used for RX: 26 | 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI). 27 | 28 | created 18 Apr. 2011 29 | modified 25 May 2012 30 | by Tom Igoe 31 | based on Mikal Hart's twoPortRXExample 32 | 33 | This example code is in the public domain. 34 | 35 | */ 36 | 37 | #include 38 | // software serial #1: TX = digital pin 10, RX = digital pin 11 39 | SoftwareSerial portOne(10,11); 40 | 41 | // software serial #2: TX = digital pin 8, RX = digital pin 9 42 | // on the Mega, use other pins instead, since 8 and 9 don't work on the Mega 43 | SoftwareSerial portTwo(8,9); 44 | 45 | void setup() 46 | { 47 | // Open serial communications and wait for port to open: 48 | Serial.begin(9600); 49 | while (!Serial) { 50 | ; // wait for serial port to connect. Needed for Leonardo only 51 | } 52 | 53 | 54 | // Start each software serial port 55 | portOne.begin(9600); 56 | portTwo.begin(9600); 57 | } 58 | 59 | void loop() 60 | { 61 | // By default, the last intialized port is listening. 62 | // when you want to listen on a port, explicitly select it: 63 | portOne.listen(); 64 | Serial.println("Data from port one:"); 65 | // while there is data coming in, read it 66 | // and send to the hardware serial port: 67 | while (portOne.available() > 0) { 68 | char inByte = portOne.read(); 69 | Serial.write(inByte); 70 | } 71 | 72 | // blank line to separate data from the two ports: 73 | Serial.println(); 74 | 75 | // Now listen on the second port 76 | portTwo.listen(); 77 | // while there is data coming in, read it 78 | // and send to the hardware serial port: 79 | Serial.println("Data from port two:"); 80 | while (portTwo.available() > 0) { 81 | char inByte = portTwo.read(); 82 | Serial.write(inByte); 83 | } 84 | 85 | // blank line to separate data from the two ports: 86 | Serial.println(); 87 | } 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /SoftwareSerial/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map for NewSoftSerial 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | NewSoftSerial KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | 15 | begin KEYWORD2 16 | end KEYWORD2 17 | read KEYWORD2 18 | available KEYWORD2 19 | isListening KEYWORD2 20 | overflow KEYWORD2 21 | flush KEYWORD2 22 | listen KEYWORD2 23 | 24 | ####################################### 25 | # Constants (LITERAL1) 26 | ####################################### 27 | 28 | -------------------------------------------------------------------------------- /StopWatch/StopWatch.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Title: StopWatch.h 3 | Author/Date: gNSortino@yahoo.com / 2014-01-11 4 | Description: This library performs the basic functions 5 | of a stop watch and is used to simplify the process of 6 | keeping track of time on an arduino. All methods are 7 | documented in the body below 8 | 9 | This code uses unsigned longs which can store 32 bits 10 | or 4 bytes of information on an arduino uno. In practical 11 | terms this equates to: 12 | 4,294,967.29 seconds (2^32 - 1) 13 | 71,582.79 minutes 14 | 1,193.05 hours 15 | 49.71 days 16 | 17 | Revision History: 18 | (GNS) 2014-01-11: inital version 19 | */ 20 | 21 | 22 | #include "Arduino.h" 23 | #include "StopWatch.h" 24 | 25 | /* 26 | Empty Constructor 27 | */ 28 | StopWatch::StopWatch () 29 | { 30 | } 31 | 32 | /* 33 | sets a timer to run for 'x' milliseconds 34 | */ 35 | void StopWatch::startTimer (unsigned long millisToTime) 36 | { 37 | _startTime = millis(); 38 | _stopTime = _startTime + millisToTime; 39 | } 40 | 41 | 42 | /* 43 | Returns true if the timer is still active. False otherwise 44 | */ 45 | boolean StopWatch::timerStatus () 46 | { 47 | if ( (millis() >= _startTime) && (millis() <= _stopTime) ) 48 | return true; 49 | else 50 | return false; 51 | } 52 | 53 | /* 54 | Returns the elapsed time since the timer was started. 55 | */ 56 | unsigned long StopWatch::timeElapsed () 57 | { 58 | return millis() - _startTime; 59 | } 60 | 61 | /* 62 | A sleep without delay function 63 | */ 64 | void StopWatch::millisToSleep (unsigned long sleepTime) 65 | { 66 | unsigned long wakeupTime = millis() + sleepTime; 67 | 68 | while(true) 69 | { 70 | if (millis() >= wakeupTime) 71 | break; 72 | } 73 | } -------------------------------------------------------------------------------- /StopWatch/StopWatch.h: -------------------------------------------------------------------------------- 1 | /* 2 | Title: StopWatch.h 3 | Author/Date: gNSortino@yahoo.com / 2014-01-11 4 | Description: This library performs the basic functions 5 | of a stop watch and is used to simplify the process of 6 | keeping track of time on an arduino. 7 | 8 | This code uses unsigned longs which can store 32 bits 9 | or 4 bytes of information on an arduino uno. In practical 10 | terms this equates to: 11 | 4,294,967.29 seconds (2^32 - 1) 12 | 71,582.79 minutes 13 | 1,193.05 hours 14 | 49.71 days 15 | 16 | Function descriptions can be found in the .cpp file 17 | of the same name. 18 | */ 19 | 20 | 21 | #ifndef StopWatch_h 22 | #define StopWatch_h 23 | 24 | #include "Arduino.h" 25 | 26 | class StopWatch 27 | { 28 | public: 29 | StopWatch (); 30 | void startTimer (unsigned long millisToTime); 31 | boolean timerStatus (); 32 | unsigned long timeElapsed (); 33 | void millisToSleep (unsigned long sleepTime); 34 | private: 35 | unsigned long _startTime; 36 | unsigned long _stopTime; 37 | }; 38 | 39 | #endif -------------------------------------------------------------------------------- /StopWatch/StopWatch.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Title: StopWatch (Demo) 3 | Author/Date: gNSortino@yahoo.com / 2014-01-14 4 | Description: This is a demo library that shows how to 5 | use the features of the StopWatch library 6 | 7 | Function descriptions can be found in the .cpp file 8 | of the same name. 9 | */ 10 | 11 | #include "StopWatch.h" 12 | 13 | 14 | StopWatch sw; 15 | 16 | void setup () 17 | { 18 | Serial.begin(115200); 19 | } 20 | 21 | void loop () 22 | { 23 | Serial.println ("Commence 10,000 millisecond timer countdown"); 24 | sw.startTimer(10000); 25 | while (sw.timerStatus() == true) 26 | { 27 | Serial.println (sw.timeElapsed()); 28 | sw.millisToSleep (1000); 29 | } 30 | Serial.println ("Countdown Completed"); 31 | sw.millisToSleep (1000); 32 | Serial.println ("waiting for a bit..."); 33 | sw.millisToSleep (3999); 34 | Serial.print (sw.timeElapsed()); 35 | Serial.println (" (Should be: 10599)"); 36 | Serial.println ("Done!\n"); 37 | sw.millisToSleep (2500); 38 | } 39 | -------------------------------------------------------------------------------- /StopWatch/keywords.txt: -------------------------------------------------------------------------------- 1 | StopWatch KEYWORD1 2 | startTimer KEYWORD2 3 | timerStatus KEYWORD2 4 | timeElapsed KEYWORD2 5 | millisToSleep KEYWORD2 -------------------------------------------------------------------------------- /ThermoTemp/ThermoSensor.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include //For dtostrf function http://www.nongnu.org/avr-libc/user-manual/group__avr__stdlib.html#ga060c998e77fb5fc0d3168b3ce8771d42 3 | 4 | ThermoTemp thermoTemp; 5 | int raw; 6 | float temps[6]; 7 | char s[32]; //buffer for dtostrf 8 | 9 | void setup() { 10 | Serial.begin(9600); 11 | Serial.println ("Signal,Voltage,Celsius,Kelvin,Fahrenheit,Rankine"); 12 | } 13 | 14 | void loop() { 15 | raw = analogRead(A0); 16 | thermoTemp.getTemps(raw, temps); 17 | String myVal = dtostrf (1234.9999, 8,20, s); 18 | Serial.println ((String)dtostrf (temps[0], 4,0, s) + "," + //Analog Signal 19 | (String)dtostrf (temps[1], 4,4, s) + "," + //Voltage 20 | (String)dtostrf (temps[2], 6,4, s) + "," + //Celsius 21 | (String)dtostrf (temps[3], 6,4, s) + "," + //Kelvin 22 | (String)dtostrf (temps[4], 6,4, s) + "," + //Fahrenheit 23 | (String)dtostrf (temps[5], 6,4, s) + ","); //Rankine 24 | delay(1000); 25 | } 26 | -------------------------------------------------------------------------------- /ThermoTemp/ThermoTemp.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Title: ThermoTemp.cpp 3 | Author/Date: gNSortino@yahoo.com / 2012-05-05 4 | Description: This library will take the input from a 5 | K type thermocouple sensor and return the following 6 | values as an array: 7 | [0] raw interval 8 | [1] voltage (in milivolts) 9 | [2] temperature in Celsius 10 | [3] temperature in Kelvin 11 | [4] temperature in Fahrenheit 12 | [5] temperature in Rankine 13 | Additionally this library has some handy methods 14 | to calculate Kelvin, Fahrenheit, and Rankine given 15 | a Celsius measurement. 16 | Note that this library will not setup any pins. It 17 | is expected that these will be defined by the calling 18 | program. 19 | */ 20 | 21 | #include "Arduino.h" 22 | #include "ThermoTemp.h" 23 | 24 | //Empty Constructor 25 | ThermoTemp::ThermoTemp() 26 | { 27 | 28 | } 29 | 30 | /* 31 | Note that the array tempsF is passed by reference so 32 | the calling function should use this to view results. 33 | */ 34 | void ThermoTemp::getTemps (int analogSignalF, float tempsF[]) 35 | { 36 | tempsF[0] = analogSignalF; 37 | tempsF[1] = getVoltage (tempsF[0]); 38 | tempsF[2] = getCelsius (tempsF[1]); 39 | tempsF[3] = getKelvin (tempsF[2]); 40 | tempsF[4] = getFahrenheit (tempsF[2]); 41 | tempsF[5] = getRankine (tempsF[2]); 42 | } 43 | 44 | float ThermoTemp::getVoltage (float analogSignal) 45 | { 46 | float voltage = ((5.0 * analogSignal) / 1024.0); 47 | return voltage; 48 | 49 | } 50 | float ThermoTemp::getCelsius (float voltage) 51 | { 52 | float celsius = (voltage * 100); 53 | return celsius; 54 | } 55 | 56 | float ThermoTemp::getKelvin (float celsius) 57 | { 58 | float kelvin = (celsius + 273.15); 59 | return kelvin; 60 | } 61 | float ThermoTemp::getFahrenheit (float celsius) 62 | { 63 | float fahrenheit = (((celsius * 9) / 5.0) + 32); 64 | return fahrenheit; 65 | } 66 | float ThermoTemp::getRankine (float celsius) 67 | { 68 | float rankine = (9.0 / 5.0) * (celsius + 273.15 ); 69 | return rankine; 70 | } -------------------------------------------------------------------------------- /ThermoTemp/ThermoTemp.h: -------------------------------------------------------------------------------- 1 | /* 2 | Title: ThermoTemp.h 3 | Author/Date: gNSortino@yahoo.com / 2012-05-05 4 | Description: This library will take the input from a 5 | K type thermocouple sensor and return the following 6 | values as an array: 7 | [0] raw interval 8 | [1] voltage (in volts) 9 | [2] temperature in Celsius 10 | [3] temperature in Kelvin 11 | [4] temperature in Fahrenheit 12 | [5] temperature in Rankine 13 | Additionally this library has some handy methods 14 | to calculate Kelvin, Fahrenheit, and Rankine given 15 | a Celsius measurement. 16 | Note that this library will not setup any pins. It 17 | is expected that these will be defined by the calling 18 | program. 19 | */ 20 | #ifndef ThermoTemp_h 21 | #define ThermoTemp_h 22 | 23 | #include "Arduino.h" 24 | 25 | class ThermoTemp 26 | { 27 | public: 28 | ThermoTemp (); 29 | void getTemps (int analogSignalF, float tempsF[]); 30 | float getVoltage (float analogSignal); 31 | float getCelsius (float voltage); 32 | float getKelvin (float clesius); 33 | float getFahrenheit (float celsius); 34 | float getRankine (float celsius); 35 | }; 36 | 37 | #endif -------------------------------------------------------------------------------- /ThermoTemp/keywords.txt: -------------------------------------------------------------------------------- 1 | ThermoTemp KEYWORD1 2 | getTemps KEYWORD2 3 | getVoltage KEYWORD2 4 | getCelsius KEYWORD2 5 | getKelvin KEYWORD2 6 | getFahrenheit KEYWORD2 7 | getRankine KEYWORD2 -------------------------------------------------------------------------------- /Transducer/PressureTransducer.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include //For dtostrf function http://www.nongnu.org/avr-libc/user-manual/group__avr__stdlib.html#ga060c998e77fb5fc0d3168b3ce8771d42 3 | 4 | Transducer transducer; 5 | char s[64]; //buffer for dtostrf 6 | float raw; 7 | float pressures[5]; 8 | 9 | 10 | void setup() { 11 | Serial.begin(9600); 12 | Serial.println ("Signal,Voltage,PSI,Pa,MPa"); 13 | } 14 | 15 | void loop() { 16 | raw = analogRead(A2); 17 | transducer.getPressures (raw, pressures); 18 | Serial.println ((String)dtostrf (pressures[0], 2,6, s) + "," + //Analog Signal 19 | (String)dtostrf (pressures[1], 2,6, s) + "," + //Voltage 20 | (String)dtostrf (pressures[2], 5,6, s) + "," + //Pounds per Square Inch 21 | (String)dtostrf (pressures[3], 8,6, s) + "," + //Pascal 22 | (String)dtostrf (pressures[4], 2,10, s) + ","); //MegaPascal 23 | delay(2000); 24 | } 25 | -------------------------------------------------------------------------------- /Transducer/Transducer.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gNSortino/Arduino-Liquid-Engine-Software/c5a2c3eeec2755e140e53f5f1ee18b63db30bad2/Transducer/Transducer.cpp -------------------------------------------------------------------------------- /Transducer/Transducer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Title: Transducer.h 3 | Author/Date: gNSortino@yahoo.com / 2012-05-06 4 | Description: This library will take the input from an 5 | SSI 1000psi (0.5V - 4.5V) sealed gauge transducer and 6 | output 7 | [0] raw interval 8 | [1] voltage (in volts) 9 | [2] Pounds per Square Inch (PSI) 10 | [3] Pascal (Pa) 11 | [4] Mega Pascal (MPa) 12 | Additionally this library has some handy methods 13 | to calculate pressure in different units given a 14 | voltage or psi value 15 | Note that this library will not setup any pins. It 16 | is expected that these will be defined by the calling 17 | program. 18 | Change Log: 19 | GNS 2013-07-28: updated psi to reflect atmospheric (psia) 20 | rather than gauge 21 | */ 22 | #ifndef Transducer_h 23 | #define Transducer_h 24 | 25 | #include "Arduino.h" 26 | 27 | class Transducer 28 | { 29 | public: 30 | Transducer (); 31 | void getPressures (int analogSignalF, float pressures[]); 32 | float getVoltage (float analogSignal); 33 | float getPSI (float voltage); 34 | float getPa (float psi); 35 | float getMPa (float psi); 36 | }; 37 | 38 | #endif -------------------------------------------------------------------------------- /Transducer/keywords.txt: -------------------------------------------------------------------------------- 1 | Transducer KEYWORD1 2 | getPressures KEYWORD2 3 | getVoltage KEYWORD2 4 | getPSI KEYWORD2 5 | getPa KEYWORD2 6 | getMPa KEYWORD2 --------------------------------------------------------------------------------