diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..412eeda --- /dev/null +++ b/.gitattributes @@ -0,0 +1,22 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp +*.sln merge=union +*.csproj merge=union +*.vbproj merge=union +*.fsproj merge=union +*.dbproj merge=union + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b9d6bd9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,215 @@ +################# +## Eclipse +################# + +*.pydevproject +.project +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.classpath +.settings/ +.loadpath + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# PDT-specific +.buildpath + + +################# +## Visual Studio +################# + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results + +[Dd]ebug/ +[Rr]elease/ +x64/ +build/ +[Bb]in/ +[Oo]bj/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.log +*.scc + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +*.ncrunch* +.*crunch*.local.xml + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.Publish.xml +*.pubxml + +# NuGet Packages Directory +## TODO: If you have NuGet Package Restore enabled, uncomment the next line +#packages/ + +# Windows Azure Build Output +csx +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.[Pp]ublish.xml +*.pfx +*.publishsettings + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +App_Data/*.mdf +App_Data/*.ldf + +############# +## Windows detritus +############# + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Mac crap +.DS_Store + + +############# +## Python +############# + +*.py[co] + +# Packages +*.egg +*.egg-info +dist/ +build/ +eggs/ +parts/ +var/ +sdist/ +develop-eggs/ +.installed.cfg + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox + +#Translations +*.mo + +#Mr Developer +.mr.developer.cfg diff --git a/AmpAndRHT_Ethernet/AmpAndRHT_Ethernet.ino b/AmpAndRHT_Ethernet/AmpAndRHT_Ethernet.ino new file mode 100644 index 0000000..2ad6199 --- /dev/null +++ b/AmpAndRHT_Ethernet/AmpAndRHT_Ethernet.ino @@ -0,0 +1,209 @@ +#define DEBUG true +#define STATICIP false + +#include +#include +#include +#include +#include + +#define DHT22_PIN 2 + +#define LM358N1_PIN 0 +#define LM358N2_PIN 1 + + +int maxReadingLM358N1 = 0; +int maxReadingLM358N2 = 0; +int currReadingLM358N1 = 0; +int currReadingLM358N2 = 0; +float main1 = 0.0; +float main2 = 0.0; +float comb = 0.0; + +int packetSent = false; + +// Setup a DHT22 instance +DHT22 myDHT22(DHT22_PIN); + +// MAC address from sticker*** +byte mac[] = { + 0x90, 0xA2, 0xDA, 0x0D, 0x57, 0xD4 }; + +#if STATICPIP +IPAddress ip(192,168,1, 177); +#endif + +// Your Xively key to let you upload data +char xivelyKey[] = "YOUR_XIVELY_API_KEY"; + +// Define the strings for our datastream IDs +char humidity1Stream[] = "humidity1"; +char temp1Stream[] = "temp1"; + +char main1Stream[] = "main1"; +char main2Stream[] = "main2"; +char combStream[] = "combined"; + +XivelyDatastream datastreams[] = { + // Float datastreams are set up like this: + XivelyDatastream(humidity1Stream, strlen(humidity1Stream), DATASTREAM_FLOAT), + XivelyDatastream(temp1Stream, strlen(temp1Stream), DATASTREAM_FLOAT), + // Int datastreams are set up like this: + XivelyDatastream(main1Stream, strlen(main1Stream), DATASTREAM_FLOAT), + XivelyDatastream(main2Stream, strlen(main2Stream), DATASTREAM_FLOAT), + XivelyDatastream(combStream, strlen(combStream), DATASTREAM_FLOAT) + }; + +// Finally, wrap the datastreams into a feed +XivelyFeed feed(FEED_ID, datastreams, 5); + +// Initialize the Ethernet server library +EthernetServer server(8080); + +void setup(){ + #if DEBUG + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + Serial.println("Starting single datastream upload to Xively..."); + Serial.println(); + #endif + + // start the Ethernet connection and the server: + #if STATICPIP + Ethernet.begin(mac, ip); + #else + while (Ethernet.begin(mac) != 1) { + #if DEBUG + Serial.println("Error getting IP address via DHCP, trying again..."); + #endif + delay(15000); + } + #if DEBUG + // report the dhcp IP address: + Serial.println(Ethernet.localIP()); + #endif + #endif + server.begin(); + } + + void loop(){ + //----------------Amperage-------------------------------------------------- + //Reset values for new packet + if (packetSent){ + packetSent = false; + maxReadingLM358N1 = 0; + maxReadingLM358N2 = 0; + } + int i; + //Capture max value from 20 samples + for (i=0; i<250; i++) { + // Get ADC reading for both sensors + currReadingLM358N1 = analogRead(LM358N1_PIN); + currReadingLM358N2 = analogRead(LM358N2_PIN); + if (currReadingLM358N1 > maxReadingLM358N1) { + maxReadingLM358N1 = currReadingLM358N1; + } + if (currReadingLM358N2 > maxReadingLM358N2) { + maxReadingLM358N2 = currReadingLM358N2; + } + } + // \/ -- Arduino AREF \/--------Burden Resistance + main1 = (maxReadingLM358N1 * 5 * 3100.0) / (1023.0 * sqrt(2) * 150); + main2 = (maxReadingLM358N2 * 5 * 3100.0) / (1023.0 * sqrt(2) * 150); + comb = main1 + main2; + + //----------------------------------------------------------------------------- + //---------------------RHT----------------------------------------------------- + DHT22_ERROR_t errorCode; + float temperature = 0; + float tempF = 0; + float humidity = 0; + + DHT22_ERROR_t errorCode2; + float temperature2 = 0; + float tempF2 = 0; + float humidity2 = 0; + // The sensor can only be read from every 1-2s, and requires a minimum + // 2s warm-up after power-on. + delay(2000); + errorCode = myDHT22.readData(); + temperature = myDHT22.getTemperatureC(); + humidity = myDHT22.getHumidity(); + tempF = (temperature*1.8)+32; + + #if DEBUG + Serial.println("Temp: "); + Serial.println(tempF); + Serial.println("Humidity: "); + Serial.println(humidity); + Serial.println(); + Serial.println("Raw Reading"); + Serial.println("Main 1: "); + Serial.println(maxReadingLM358N1); + Serial.println("Main 2: "); + Serial.println(maxReadingLM358N2); + Serial.println(); + Serial.println("Calculated Amperage"); + Serial.println("Main 1: "); + Serial.println(main1); + Serial.println("Main 2: "); + Serial.println(main2); + Serial.println("Combined: "); + Serial.println(comb); + Serial.println("#################################"); + packetSent = true; + #endif + + switch(errorCode) + { + case DHT_ERROR_NONE: + temperature = myDHT22.getTemperatureC(); + humidity = myDHT22.getHumidity(); + break; + case DHT_ERROR_CHECKSUM: + temperature = 100; + humidity = 100; + break; + case DHT_BUS_HUNG: + Serial.println("BUS Hung "); + break; + case DHT_ERROR_NOT_PRESENT: + Serial.println("Not Present "); + break; + case DHT_ERROR_ACK_TOO_LONG: + Serial.println("ACK time out "); + break; + case DHT_ERROR_SYNC_TIMEOUT: + Serial.println("Sync Timeout "); + break; + case DHT_ERROR_DATA_TIMEOUT: + Serial.println("Data Timeout "); + break; + case DHT_ERROR_TOOQUICK: + Serial.println("RHT03 Polled to quick "); + break; + } + + //--------------------------------------------------------------------------- + //--------------Ethernet---------------------------------------------------- + // listen for incoming clients + EthernetClient client; + XivelyClient xivelyclient(client); + datastreams[0].setFloat(humidity); // Push a float datapoint + datastreams[1].setFloat(tempF); + datastreams[2].setFloat(main1); + datastreams[3].setFloat(main2); + datastreams[4].setFloat(comb); + + #if DEBUG + Serial.println("Uploading it to Xively"); + #endif + + int ret = xivelyclient.put(feed, xivelyKey); + + } + diff --git a/AmpAndRHT_Serial/AmpAndRHT_Serial.ino b/AmpAndRHT_Serial/AmpAndRHT_Serial.ino new file mode 100644 index 0000000..4189048 --- /dev/null +++ b/AmpAndRHT_Serial/AmpAndRHT_Serial.ino @@ -0,0 +1,163 @@ +#define DEBUG true +#include + +#define DHT22_PIN 2 + +#define LM358N1_PIN 0 +#define LM358N2_PIN 1 +#define ledPin 13 + +int maxReadingLM358N1 = 0; +int maxReadingLM358N2 = 0; +int currReadingLM358N1 = 0; +int currReadingLM358N2 = 0; +float main1 = 0.0; +float main2 = 0.0; +float comb = 0.0; +int ledState = LOW; + +int packetSent = false; + +// Setup a DHT22 instance +DHT22 myDHT22(DHT22_PIN); + + +void setup(){ + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + pinMode(ledPin, OUTPUT); + } + + void loop(){ + //----------------Amperage-------------------------------------------------- + //Reset values for new packet + if (packetSent){ + packetSent = false; + maxReadingLM358N1 = 0; + maxReadingLM358N2 = 0; + } + int i; + for (i=0; i<250; i++) { + // Get ADC reading for both sensors + currReadingLM358N1 = analogRead(LM358N1_PIN); + currReadingLM358N2 = analogRead(LM358N2_PIN); + + if (currReadingLM358N1 > maxReadingLM358N1) { + maxReadingLM358N1 = currReadingLM358N1; + } + if (currReadingLM358N2 > maxReadingLM358N2) { + maxReadingLM358N2 = currReadingLM358N2; + } + + } + // \/ -- Arduino AREF \/--------Burden Resistance + main1 = (maxReadingLM358N1 * 5 * 3100.0) / (1023.0 * sqrt(2) * 150); + main2 = (maxReadingLM358N2 * 5 * 3100.0) / (1023.0 * sqrt(2) * 150); + comb = main1 + main2; + + //----------------------------------------------------------------------------- + //---------------------RHT----------------------------------------------------- + DHT22_ERROR_t errorCode; + float temperature = 0; + float tempF = 0; + float humidity = 0; + + DHT22_ERROR_t errorCode2; + float temperature2 = 0; + float tempF2 = 0; + float humidity2 = 0; + // The sensor can only be read from every 1-2s, and requires a minimum + // 2s warm-up after power-on. + delay(2000); + errorCode = myDHT22.readData(); + temperature = myDHT22.getTemperatureC(); + humidity = myDHT22.getHumidity(); + tempF = (temperature*1.8)+32; + + #if DEBUG + Serial.println("Temp: "); + Serial.println(tempF); + Serial.println("Humidity: "); + Serial.println(humidity); + Serial.println(); + Serial.println("Raw Reading"); + Serial.println("Main 1: "); + Serial.println(maxReadingLM358N1); + Serial.println("Main 2: "); + Serial.println(maxReadingLM358N2); + Serial.println(); + Serial.println("Calculated Amperage"); + Serial.println("Main 1: "); + Serial.println(main1); + Serial.println("Main 2: "); + Serial.println(main2); + Serial.println("Combined: "); + Serial.println(comb); + Serial.println("#################################"); + packetSent = true; + #endif + + Serial.print(tempF); + Serial.print(":"); + Serial.print(humidity); + Serial.print(":"); + Serial.print(main1); + Serial.print(":"); + Serial.print(main2); + Serial.print(":"); + Serial.print(comb); + Serial.println(); + ledState = HIGH; + digitalWrite(ledPin, ledState); + delay(5); + ledState = LOW; + digitalWrite(ledPin, ledState); + ledState = HIGH; + digitalWrite(ledPin, ledState); + delay(5); + ledState = LOW; + digitalWrite(ledPin, ledState); + ledState = HIGH; + digitalWrite(ledPin, ledState); + delay(5); + ledState = LOW; + digitalWrite(ledPin, ledState); + packetSent = true; + + switch(errorCode) + { + case DHT_ERROR_NONE: + temperature = myDHT22.getTemperatureC(); + humidity = myDHT22.getHumidity(); + break; + case DHT_ERROR_CHECKSUM: + temperature = 100; + humidity = 100; + break; + case DHT_BUS_HUNG: + Serial.println("BUS Hung "); + break; + case DHT_ERROR_NOT_PRESENT: + Serial.println("Not Present "); + break; + case DHT_ERROR_ACK_TOO_LONG: + Serial.println("ACK time out "); + break; + case DHT_ERROR_SYNC_TIMEOUT: + Serial.println("Sync Timeout "); + break; + case DHT_ERROR_DATA_TIMEOUT: + Serial.println("Data Timeout "); + break; + case DHT_ERROR_TOOQUICK: + Serial.println("RHT03 Polled to quick "); + break; + } + + //--------------------------------------------------------------------------- + + } + diff --git a/AmpAndRHT_Serial/AmpAndRHT_Serial.pde b/AmpAndRHT_Serial/AmpAndRHT_Serial.pde new file mode 100644 index 0000000..7757f33 --- /dev/null +++ b/AmpAndRHT_Serial/AmpAndRHT_Serial.pde @@ -0,0 +1,352 @@ +/* +BBCC_Plotter + by Tim Hirzel, Feb 2008 + v 1.1 + + with gratitude, based on: + Grapher Pro! + by Tom Igoe + + + This Processing application is designed to plot and display values + coming from the BBCC PID controller for Arduino. With minimal modification, + it could be setup to plot and show different incoming data + + Please refer to the top section for alterations of plot ranges, graph size etc. + + All code released under + Creative Commons Attribution-Noncommercial-Share Alike 3.0 + */ + +import processing.serial.*; + +// ********* unlikely that you want to change these ********* +int BAUDRATE = 9600; +char DELIM = ':'; // the delimeter for parsing incoming data +//char INIT_MARKER = '!'; //Look for this character before sending init message + +//String INIT_MESSAGE = "?gu"; //Send these characters to the arduino after init to start up messages +// this gets the help string from teh device, and then turns on plotting mode with constant update strings + +// ********* SETINGS ********* + +int yBorder = 60; // Size of the background area around the plot in screen pixels +int xBorder = 90; + +// the plot size in screen pixels +int plotHeight = 450; +int plotWidth = 750; + +int ExpectUpdateSpeed = 200; // milliseconds. This just allows the axis labels in the X direction accurate + +// These are all in real number space +// all X values measured in ExpectedUpdateSpeed Intervals + // all y measured in degrees +int gridSpaceX = 50; +int gridSpaceY = 10; +int startX = 0; +int endX = 600; +int startY = 0; +int endY = 120; + +// leave these to be calculated +float pixPerRealY = float(plotHeight)/(endY - float(startY)); +float pixPerRealX = float(plotWidth)/(endX - float(startX)); + +// These are calculated here, but could be changed if you wanted +int windowWidth = plotWidth + 2*xBorder; +int windowHeight = plotHeight + 2*yBorder; + +// ******* Legend ******** +// Define the location and size of the Legend area +int legendWidth = 125; +int legendHeight = 130; +int legendX = windowWidth - 140; +int legendY = 15; + +// ******* Help Window ******** +// Define the size of the help area. It always sits in the middle +int helpWidth = 600; +int helpHeight = 400; + + +String title = "Home Monitor Data"; // Plot Title +String names = "Temp. Humidity MainA MainB Combined"; // The names of the values that get sent over serial +String yLabel = "T\ne\nm\np\ne A\nr m\na p\nt s\nu\nr\ne\n\nF A"; // this is kind of a hack to make the vertical label +String xLabel = "Time"; // X axis label +String fontType = "Courier"; // Y axis label +boolean[] plotThisName = { + true, true, true, true, true}; // For each of the values, you can choose if you want it plotted or not here + +// **************** end of Settings area **************** + +String helpBase = "-Plotter Help-\n(all characters are case sensitive)\nh : toggle this help screen\nl : toggle the Legend\nS : save screen\nE : export shown data as text\n\n-Device Help- \n"; +String helpString = ""; +Serial myPort; // The serial port + +boolean displayLegend = true; +boolean displayHelp = true; + +int sensorCount = 5; // number of values to expect +float[][] sensorValues = new float[endX-startX][sensorCount]; // array to hold the incoming values +int currentValue = -1; +int hPosition = startX; // horizontal position on the plot +int displayChannel = 0; // which of the five readings is being displayed +int threshold = 50; // threshold for whether or not to write +// data to a file +boolean updatePlot = false; +//int [] lastSet = new int[sensorCount]; + +int[][] colors = new int[sensorCount][3]; + +PFont titleFont; +PFont labelFont; + +void setupColors() { + // Thanks to colorbrewer for this pallete + colors[0][0] = 102; + colors[0][1] =194; + colors[0][2] = 165; + colors[1][0] = 252; + colors[1][1] = 141; + colors[1][2]= 98; + colors[2][0] = 141; + colors[2][1] = 160; + colors[2][2]= 203; + colors[3][0] = 231; + colors[3][1] = 138; + colors[3][2]= 195; + colors[4][0] = 166; + colors[4][1] = 216; + colors[4][2]= 84; + //colors[5][0] = 255; + //colors[5][1] = 217; + //colors[5][2]= 47; +} + + +void setup () { + size(windowWidth, windowHeight); // window size + setupColors(); + smooth(); + // println(PFont.list()); + titleFont = createFont(fontType, 18); + labelFont = createFont(fontType, 14 ); + + clearPlot(); + // List all the available serial ports + println(Serial.list()); + + // On my mac, the arduino is the first on this list. + // Open whatever port is the one you're using. + myPort = new Serial(this, Serial.list()[1], BAUDRATE); + // clear the serial buffer: + myPort.clear(); +} + +void draw () { + // if the value for the given channel is valid, plot it: + if (updatePlot) { + // draw the plot: + plot(); + updatePlot = false; + } +} + +void clearPlot() { + background(5); + strokeWeight(1.5); + stroke(10); + fill(40); + // draw boundary + rect(xBorder,yBorder,plotWidth, plotHeight); + + textAlign(CENTER); + fill(70); + textFont(titleFont); + text(title, windowWidth/2, yBorder/2); + + textFont(labelFont); + stroke(10); + //draw grid + fill(70); + textAlign(RIGHT); + for (int i = startY; i <= endY; i+= gridSpaceY) { + line(xBorder - 3, realToScreenY(i), xBorder + plotWidth - 1, realToScreenY(i)); + text(str(i), xBorder - 10, realToScreenY(i)); + } + + textAlign(LEFT); + for (int i = startX; i <= endX ; i+= gridSpaceX) { + line(realToScreenX(i), yBorder+1, realToScreenX(i), yBorder + plotHeight + 3); + text(str((i)/ (1000 / ExpectUpdateSpeed)), realToScreenX(i), yBorder + plotHeight + 20); + } + + // Draw Axis Labels + fill(70); + text(yLabel, xBorder - 70, yBorder + 100 ); + + textAlign(CENTER); + text(xLabel, windowWidth/2, yBorder + plotHeight + 50); + + +} + +float realToScreenX(float x) { + float shift = x - startX; + return (xBorder + shift * pixPerRealX); +} + +float realToScreenY(float y) { + float shift = y - startY; + return yBorder + plotHeight - 1 - (shift) * pixPerRealY; + +} + +void plot () { + clearPlot(); + // draw the line: + for (int i = 0; i < sensorCount; i++) { + // assign color to each plot + stroke(colors[i][0], colors[i][1],colors[i][2]); + + for (int x = 1; x < currentValue; x++) { + if(plotThisName[i]) { + + line(realToScreenX(x-1), + realToScreenY(sensorValues[x-1][i]) , + realToScreenX(x), + realToScreenY(sensorValues[x][i]) + ); + + } + } + } + + if (hPosition >= endX) { + hPosition = startX; + // wipe the screen clean: + clearPlot(); + } + else { + hPosition += 1; + } + + + noStroke(); + // DRAW LEGEND + if (displayLegend) { + fill(128,128,128,80); + rect(legendX, legendY, legendWidth, legendHeight); + + // print the name of the channel being graphed: + String line; + for (int i = 0; i < sensorCount; i++) { + fill(colors[i][0], colors[i][1],colors[i][2]); + textAlign(LEFT); + text(split(names,' ')[i] , legendX+5, legendY + (i+1) * 20); + textAlign(RIGHT); + text(nf(sensorValues[currentValue][i], 0,2), legendX+legendWidth - 5, legendY + (i+1) * 20); + } + } + + if (displayHelp) { + textAlign(LEFT); + fill(128,128,128,80); + noStroke(); + rect(windowWidth/2 - helpWidth/2, windowHeight/2 - helpHeight / 2, helpWidth, helpHeight); + fill(255,255,255); + helpWidth -= 20; + helpHeight -=20; + text(helpString,windowWidth/2 - helpWidth/2, windowHeight/2 - helpHeight / 2, helpWidth, helpHeight); + helpWidth += 20; + helpHeight +=20; + + } +} + +void keyPressed() { + // if the key pressed is "0" through "4" + if (key == 'l') { + // set the display channel accordingly + displayLegend = ! displayLegend; + updatePlot = true; + } + if (key == 'h') { + // set the display channel accordingly + displayHelp = ! displayHelp; + updatePlot = true; + } + if (key == 'S') { + // set the display channel accordingly + save(str(hour()) + "h" + str(minute()) + "m" + str(second()) + "s" + str(month()) + "." + str(day()) + "." + str(year())+".jpg") ; + } + if (key == 'E') { + exportText(); + } + myPort.write(key); + +} + +void exportText() { + // string for the new data you'll write to the file: + String[] outStrings = new String[currentValue+1]; + outStrings[0] = names; + for (int i =0; i < currentValue; i++) { + outStrings[i+1] = ""; + for (int j=0; j < sensorCount; j++) { + outStrings[i+1] += str(sensorValues[i][j]); + if (j < sensorCount - 1) { + outStrings[i+1] += ", "; + } + } + } + saveStrings(str(hour()) + "h" + str(minute()) + "m" + str(second()) + "s" + str(month()) + "." + str(day()) + "." + str(year())+".txt", outStrings); +} + +// make up a timeStamp string for writing data to the file: +String timeStamp() { + String now = hour()+ ":" + minute()+ ":" + second()+ " " + + month() + "/" + day() + "/" + year(); + return now; +} + + +void serialEvent(Serial myPort) { + // read incoming data until you get a newline: + String serialString = myPort.readStringUntil('\n'); + // if the read data is a real string, parse it: + + if (serialString != null) { + println(serialString); + // split it into substrings on the DELIM character: + String[] numbers = split(serialString, DELIM); + // convert each subastring into an int + if (numbers.length == sensorCount) { + currentValue += 1; + if (currentValue >= (endX-startX)) + { + currentValue = 0; + } + for (int i = 0; i < numbers.length; i++) { + // make sure you're only reading as many numbers as + // you can fit in the array: + if (i <= sensorCount) { + // trim off any whitespace from the substring: + numbers[i] = trim(numbers[i]); + sensorValues[currentValue][i] = float(numbers[i]); + } + } + updatePlot = true; + } + else if (currentValue == -1){ + // The help string from the first '?' character gets appended to the plotter help string + helpString += serialString; + } + else { + // Things we don't handle in particular can get output to the text window + print(serialString); + } + } +} +