text:
How do I keep track of the time passed in this code? (PCR machine)
I am desperate need of help with my code. It is meant to be a biology project (a pcr machine) and I struggle with inplementing a time tracker. Everytime the cyclus goes to a function, I need it to save that exact time, and then lt it run for a certain amount of time (this variable is given in a parameter). So help is really really appreciated.
//variabelen

#include <Adafruit_MAX31855.h>

int maxSO =  4;
int maxCS = 5;
int maxSCK = 6;

Adafruit_MAX31855 thermocouple(maxSCK, maxCS, maxSO);

int fan = 9; //connected to transistor base
int temp;
int tempMin = 18;   //variable to check if the thermocouple is connected
int tempMax = 100;   //never exceed this temperature
int fanSpeed;
int RelayP = 3; //still got to check if it is 3 or 4
int cyclusamount = 3; //still got to add a button

//cyclussen op één rij
float DENTEMP = 94;
float ANTEMP = 62;
float EXTEMP = 72;

//tijden op een rij
unsigned int INITDENTIME = 53000;
unsigned int DENTIME = 33000;
unsigned int ANTIME = 33000;
unsigned int EXTIME = 33000;
unsigned int ENDEXTIME = 42000;

unsigned long timer1 = 0;
unsigned long timer2 = 0;
double temp;
double MaxTempIncrease = 2;

//int cycles = 0;
int phase = 0;
int a = 0;
int g = -1;
int phaseOfCyclus = 0;
int timesArray[] = [33000, 33000, 33000];
int tempsArray[] = [94, 62, 72];
int cycluscounter = 0;

const unsigned long startTime;
unsigned long startMillis;

void setup() {
  Serial.begin(9600);
  delay(500);
  pinMode(fan, OUTPUT);
  digitalWrite(fan, LOW);
  pinMode(RelayP, OUTPUT);
  digitalWrite(RelayP, LOW);
  delay(5500);
}

void loop() {
  //eerst is er een delay, na de delay zal a springen op a=1
if(a == 0) {
    delay(1000);
    a++;
  }

//wanneer a=1 geldt dan zal de temperatuur stijgen naar 94 graden, wanneer dit is bereikt wordt  a=2 en phaseOfCyclus=1
else if(a == 1){
     raiseTemp(DENTEMP);
  }

//wanneer a=2 geldt dan zal de temperatuur stabiel worden gehouden (dus 94 graden) voor de initiatie-stap duur, dat is ongeveer rond de 4minuten
//wanneer deze tijd is verstreken dan wordt a=3 (en phaseOfCyclus=1 (nog steeds))
else if(a == 2) {
    holdTemp(DENTEMP, INITDENTIME);
  }

else if(a == 3) {

//De eerste fase van één cyclus in de PCR machine begint met 94 graden voor 30 seconden.
//de functie raiseTemp heeft 1 parameter en die wordt verkregen door het eerste getal uit de tempsArray
//Is dit volbracht, dan wordt phaseOfCyclus=2
if(phaseOfCycles = 1) {
  raiseTemp(tempsArray[1];
}

//de temperatuur wordt dan weer stabiel gehouden, de twee parameters geven de tijdsduur en de temperatuur van de fase waarin de cyclus van de pcr machine zich bevind
//is dit volbracht en was phaseOfCyclus=2, dan wordt phaseofcyclus=3
else if (phaseOfCyclus = 2) {
  holdTemp(tempsArray[1], timesArray[1]; //hoort 0

}

//dan zal de temperatuur afkoelen tot een bepaalde temperatuur, als dit is volbracht -> als phaseofcyclus=3 dan wordt phaseofcyclus=4
else if (phaseOfCyclus = 3) {
  cooldown(tempsArray[2]; //hoort 1
}

//de temperatuur wordt weer stabiel gehouden, voor 30 seconden en als phaseofcyclus is 4 dan phaseofcyclus=5
else if (phaseOfCyclus = 4) {
  holdTemp(tempsArray[2], timesArray[2]; //hoort 1

}

//dan zal de temperatuur verder afkoelen tot een bepaalde temperatuur, als dit is volbracht -> als phaseofcyclus=5 dan wordt phaseofcyclus=6
else if (phaseOfCyclus = 5) {
  cooldown(tempsArray[3]; //hoort 2
}

//de temperatuur wordt weer stabiel gehouden, voor 30 seconden en als phaseofcyclus is 5 dan phaseofcyclus=6
//bij één hele cyclus zal holdtemp 3x worden aangeroepen, elke keer als dit dus 3x gebeurt dan zal de cyclusamount +1 in hoeveelheid toenemen
//als de cyclusamount niet gelijk is aan het aantal cyclussen dat iemand wil uitvoeren dan zal -> phaseofCyclus = 1
//is dit wel groter of gelijk aan het aantal cyclussen dat iemand wil uitvoeren dan zal -> a =4  (als a = 3 en phaseofcyclus = 6)
else if (phaseOfCyclus = 6) {
  holdTemp(tempsArray[3], timesArray[3]; //hoort 2
}}

//dan zal de extending temperatuur stabiel worden gehouden en als de tijd is verstreken dan zal a = 5 worden en zal de lcd zeggen dat de cyclus is volbracht
else if (a == 4) {
   holdTemp(EXTEMP, 42000);
  }
else if(a == 5) {
  digitalWrite(fan, LOW);
  digitalWrite(RelayP, LOW);
  Serial.println("Cyclus completed");
}
}

void raiseTemp(double y) {
  double prevTemp = thermocouple.readCelsius();
  temp = thermocouple.readCelsius();

if (temp < tempMin) {
   Serial.println("is the thermocouple connected???");
  }

while (temp < y) {
    int waittime = min(650, ((650*(y-temp))));
    digitalWrite(RelayP, HIGH);
    delay(waittime);
    digitalWrite(RelayP, LOW);
    temp=thermocouple.readCelsius();

if(temp >= y) {
    if(phaseOfCyclus = 1) {
      phaseOfCyclus = 2;
      a = 3;
    }
    else if (phaseOfCyclus = 0){
      phaseOfCyclus++;
      a = 2;
    }
      // break; //wat doet dit precies?
    }

if((y-temp) < 1) {
      do  {
        prevTemp = temp;
        delay(250);
        temp = thermocouple.readCelsius();
      }
      while(temp > prevTemp);
    }

if(temp >= TempMax)
     break;

else {
      prevTemp = temp;
   }

   while ((temp-prevTemp) >= MaxHeatIncrease) {
     prevTemp = temp;
     Serial.print("HEATING UP TOO FAST! ");
     delay(1000);
     temp = thermocouple.readCelsius();
     Serial.println(temp);
   }

   while(temp >= y) {
     delay(1000);
     Serial.print("DANGER DANGER DANGER");
     Serial.println(temp);
   }
}}

void holdTemp(double phaseTemp, double duration) {
  g++;
  z = phaseTemp;

  startMillis = millis();
  unsigned long whatitneedstobe = startTime + duration;
  //startMillis < whatitneedstobe

  if(timegone < duration){
        temp = thermocouple.readCelsius();
      if(temp < z) {
        digitalWrite(RelayP, HIGH);
        delay(90);
        digitalWrite(RelayP, LOW);
      }
      else if (temp > (z+0.5)) {
        digitalWrite(fan, HIGH);
        delay(90);
        digitalWrite(fan, LOW);
        //or
        //fanSpeed = map(temp, tempMin, y, 32, 255);
        //analogWrite(fan, fanSpeed);
      }
     delay(210);
     timegone = millis() - startTime;
     }

  else {
    if(phaseOfClus = 1) {
      a = 3;
    }
    else if(phaseOfCyclus = 2) {
      phaseOfCyclus = 3;
    }
    else if(phaseOfCyclus = 4) {
      phaseOfCyclus = 5;
    }
    else if(g == 3) {
    g = 0;
    cycluscounter++;
    if(cycluscounter < cyclusamount) {
      a = 3;
      phaseOfCyclus = 1;
    }
    else(cycluscounter >= cyclusamount {
      a = 4;
    }
  }
  else if(a = 4) {
    a = 5;
  }
    }
  }

void cooldown(double c) {
  unsigned long startTime = millis();
while ((temp = thermocouple.readCelsius()) > (minTemp+0.75)) {
    digitalWrite(fanPin, HIGH);
    delay(300);
   }
   digitalWrite(fanPin, LOW);
if(thermocouple.readCelsius() == c){
  if(phaseOfCyclus = 3) {
    phaseOfCyclus = 4;
  }
  else if(phaseOfCyclus = 5) {
    phaseOfCyclus = 6;
  }
}
}

I am logged in now, but can't change what I have put inside the question. I meant: I am in desperate need of help with my code. It is a biology/electronics project (a pcr machine) and I struggle with implementing a time tracker in the code. I want that Everytime the cyclus goes to a holdtemp(), the time when it reaches the code gets saved and then let the code run for a certain amount of time (that certain amount of time is giving in a parameter). Help and advice is much appreciated.

Please request merging your accounts. That will give you access to your original post.  See: https://stackoverflow.com/help/merging-accounts

Lines like  holdTemp(tempsArray[1], timesArray[1]; //hoort 0 have bad syntax/missing parentheses.   /// In holdTemp(), what's the difference/intention between startMillis and startTime?

If you want the holdTemp() function to run for a specified duration,
you can write it like this:
void holdTemp(double phaseTemp, unsigned long duration) {
    unsigned long start_time = millis();
    while (millis() - start_time < duration) {
        // whatever...
    }
}

Note that if you use delay() inside the function, the time spent in it
may get longer than the requested duration, by as much as the duration
of the delay.


text:
How to Simulate and Tune a PID
I've been trying to simulate a PID using Brett Beauregard's PID library in order to understand it better. Here is my code.
#include <PID_v1.h>

const unsigned int numReadings = 500;
double analogVals[numReadings];
unsigned int i = 0;
int angle = 0;
//Define Variables we'll be connecting to
double Setpoint, Input, Output;
//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint,2,5,1, DIRECT);
void setup()

{
  //turn the PID on
  myPID.SetMode(AUTOMATIC);
  Serial.begin(115200);
  Setpoint = 300;
  myPID.SetOutputLimits(-2,2);
  myPID.SetSampleTime(100);
  Input = random(292, 302) ;
}

void loop()
{
  if (i % 2 == 0) {
  Input += random(-2,3);
  }
  angle += 1 % 360;
  Input += sin(angle*355/(113*180));
  myPID.Compute();
  Input += Output;
    analogVals[i] = Input;
    i++;
    if (i>= numReadings)
    {
      for (int j = 0; j < i; j++) {
      Serial.println(analogVals[j]);
      }

      i = 0; //reset to beginning of array, so you don't try to save readings outside of the bounds of the array
    }
}

Even if I restrict the output of the PID to a very small value, I get huge nonsense results of this code. It oscillates like -1000 to 1000. I've read this https://robotics.stackexchange.com/questions/167/what-are-good-strategies-for-tuning-pid-loops
and tried to adjust my parameters, but they're just shots in the dark really, I can't even damp these massive oscillations. How would I tune a PID to cancel out a sin error ?
Thanks in advance

please post the link to the PID library?

I do not have your PID_v1.h, but I made a simple experiment trying to control your example with a simple P-Controller instead of the PID lib. I made the following changes to your code:
...
double K_P = 1;
...
//myPID.Compute();
  Output = K_P*(Setpoint - Input);
  Input += Output;

This is working for very small amounts of K_P, but as soon as K_P gets higher than 2.0 it gets instable very fast. I guess this is what you are observing. The reason for me is, that you have implemented a ideal control path. In real control tasks you will always have some transfer behavior
Therefore I added a simple PT1 element (first-order lag element) to your code, now your system is much more stable and you can experiment with the K, I and D factors. Here it works with K_P even higher than 400:
// #include <PID_v1.h>

const unsigned int numReadings = 500;
double analogVals[numReadings];
unsigned int i = 0;
int angle = 0;
//Define Variables we'll be connecting to
double Setpoint, Input, Output;
double Input_PT1;
double K_P = 20;
//Specify the links and initial tuning parameters
//PID myPID(&Input, &Output, &Setpoint,2,5,1, DIRECT);
void setup()

{
  //turn the PID on
  // myPID.SetMode(AUTOMATIC);
  Serial.begin(115200);
  Setpoint = 300;
  // myPID.SetOutputLimits(-2,2);
  //myPID.SetSampleTime(100);
  Input = random(292, 302) ;
}

void loop()
{
  if (i % 2 == 0) {
    Input += random(-2, 3);
  }
  angle += 1 % 360;
  Input += sin(angle * 355 / (113 * 180));
  //myPID.Compute();
  Output = K_P * (Setpoint - Input_PT1);
  Input += Output;
  // start PT1
  Input_PT1 -= Input_PT1 / 25;
  Input_PT1 += Input / 25;
  // end PT1
  analogVals[i] = Input_PT1;
  i++;
  if (i >= numReadings)
  {
    for (int j = 0; j < i; j++) {
      Serial.println(analogVals[j]);
    }

    i = 0; //reset to beginning of array, so you don't try to save readings outside of the bounds of the array
  }
}

Some hint:

The sketch above does not initialize Input_PT1, so it takes some secondes until you reach a steady value of 300, if you do not want to wait, just initialize Input_PT1 with 300. But this is exactly where you can start increasing first I, then D factors to try to increase speed for reaching a steady value of 300 and experiencing what influence I and D part will have.
Input_PT1 is not a good naming, since this is the output of the PT1 element, but since you are using it as the PID Input, I did not change.

Here a drawing of what I implemented in contrast to your sketch (at least I hope so ;-))

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
Arduino keypad and RF 433MHz transmitter problem
So, the basic idea is that user presses a key on keypad, and key that is pressed is sent with RF transmitter.
I got individual parts to work(keypad and transmitter), but can't send the actual key. When I try to send it, I get a strange string on the other end. I am convinced its simple issue with my syntax, so if anyone could help me, that would be great. Code is below:
#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile
RH_ASK driver; //use this driver for transmitter

#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {10, 9, 8, 7}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6, 5, 4, 3}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup()
{
    Serial.begin(9600);   // Debugging only
    if (!driver.init())
         Serial.println("init failed");
}

void loop()
{

    char key = keypad.getKey();

    if (key){
      Serial.println(key);//outputs correct key
      //transmitter part
//      const char *msg = "Hello World!";
      const char *msg = key;//here is the problem, when i send the string above, it works okay, when I send this, i get strange string on other end
      driver.send((uint8_t *)msg, strlen(msg));
      driver.waitPacketSent();
      Serial.println(key);//outputs correct key
      Serial.println("packet_sent");
    }
}

With the VirtualWire library, the (unused) pins are assigned to certain pins. You could check the source code of the RadioHead library which pins are used by default or you can set every possible pin that RadioHead can control to unused pins.

Sir, can you please share the receiver's side program?

The problem is you send a character of type char, thus exactly one byte.
However, when you send it you have to give the length and you use strlen. However, msg is an array (at least that is what you want), but that array contains only the character to sent. What you want is to send only 1 character, so use 1 instead of strlen.
Also, you can get rid of the special msg pointer and instead of
  const char *msg = key;//here is the problem, when i send the string above, it works okay, when I send this, i get strange string on other end
  driver.send((uint8_t *)msg, strlen(msg

use
  driver.send(&key, 1);

Where &key defines the address (pointer to) key, and since there is always exactly 1 byte in key (the key itself), 1 can be used. To be more safe, you can use sizeof(key) thus
  driver.send(&key, sizeof(key));

What you also can do is create a string that ends with \0, so the first is the character to send, and strlen can be used, but the easiest way is to set the length to exactly 1.
Actually, using strlen on a string that does not end with \0 can result in strange behavior, because maybe there is no \0 in memory.

Thanks for your answer, I tried both solutions (just "1" and sizeof), and it got me closer to the solution. On the other side I get "1k⸮⸮⸮******8" when the key value is 1, "2k⸮⸮⸮******8" for 2, and so on.
Again sorry for needing to be handheld, but as PHP programmer, this is whole new world for me :)

No problem, I think the writing is ok, but maybe where you read it (where you get the package) you have to do the same... If the other side expect a null terminated string, than try to send a string of 2 characters, first is the keypad value, second is a null string, and send length 2.
However, since the first character is correct, I think, you can just do a read of exactly 1 character (which is the character you want). The k⸮⸮⸮*****8 part is just some random memory that is not written since the buffer is only 1 byte.

You were right, I updated receiver code and it works correctly now. Thanks for your help!

You're welcome, good luck with your project

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
How can I transfer multiple frames from the Arducam's fifo buffer to file without zero padding?
I've been unable to resolve a coding problem I've been having with the Arducam Mini 2MP and I was hoping someone might be willing to give me some pointers or clear up any apparent misconceptions I've had regarding the cameras capabilities.
I have my loop setup so the camera captures an image and following this, a lux measurement is taken. If lux exceeds a specified threshold, the image is transferred to an SD card. If not, then fifo is flushed and start_capture is returned to zero.
What I'd like to have is a series of say 3 images, leading up to the point in time when lux exceeds the threshold.
I can buffer more than one frame by writing to the Arduchip registry
    (myCAM.write_reg(ARDUCHIP_FRAMES. 0x03);
The tricky part for me has been transferring multiple buffered images to the SD card. After multiple attempts, I was able to save the images. However, only the first image from the series is viewable. The remaining images, when opened with a hex editor contain a varying number of zeros before the FFD8, causing them to be unrecognizable as jpegs).
This is the code in its entirety, complete with some debugging techniques I was fortunate to stumble upon while trying to resolve the issue (serial printing an asterisks after each 256 byte transfer really helped to develop some understanding of how the SPI transfer was being achieved).

// Logs a lux reading and time stamp at approximately ___ms intervals
// 1. three image frames are acquired
// 2. A lux reading and corresponding time of reading is written to the log
// 3. If lux exceeds threshold, the log is closed and the three buffered images are written to the SD card,
// 4. If lux does not exceed threshold, the buffer is wiped
// Image file names indicates the time at which the log was closed and order of image acquisition
// lux readings resume when images are saved (within __s of last lux reading)
// Note: flush command have been removed to speed up sampling rate. lux readings are written to SD when the buffer is full (some data at end will be lost)

#include <SD.h>
#include <Wire.h>
#include <ArduCAM.h>
#include <SPI.h>
#include "memorysaver.h"
#include "RTClib.h"
#include <Adafruit_Sensor.h>
#include "Adafruit_TSL2591.h"
#if defined(__arm__)
#include <itoa.h>
#endif

/* SPI (Serial Peripheral Interface) synchronous  serial communications interface. */
/* CS (chip select) or SS (slave select)- command pin which enables or disables slave device access to shared I/Os */
const int chipSelect = 10;     // pin 10 is the SS for the SD-card
const int SPI_CS = 23;         // SPI slave select for Arducam
ArduCAM myCAM(OV2640, SPI_CS); // instruct the arducam that its SS is SPI_CS which we just defined as pin 23

float LUX;
char charFileName;
int q;
int k;
unsigned long T;
volatile uint32_t length;

RTC_DS1307 RTC;                                // define Real Time  Clock
File logfile;                                  // logging file
Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591); // the sensor identifier

#define ECHO_TO_SERIAL   1           // zero shuts off serial output
#define WAIT_TO_START    1           // Wait for serial input in setup()

void configureSensor(void)
{
 tsl.setGain(TSL2591_GAIN_LOW);    // 1x gain (bright light)
 tsl.setTiming(TSL2591_INTEGRATIONTIME_100MS);
}

void stamp()
{
  if (! logfile) {
    logfile = SD.open("test.csv", FILE_WRITE);
  }
  DateTime now;
  now = RTC.now();                  // fetch the time
  logfile.print(now.month(), DEC);
  logfile.print("-");
  logfile.print(now.day(), DEC);
  logfile.print("-");
  logfile.print(now.year(), DEC);
  logfile.print("__");
  logfile.print(now.hour(), DEC);
  logfile.print(":");
  logfile.print(now.minute(), DEC);
  logfile.print(":");
  logfile.println(now.second(), DEC);
}

void setup()
{
  uint8_t vid, pid;
  uint8_t temp;
  Wire.begin();
  Serial.begin(115200);

  #if WAIT_TO_START
    Serial.println("Type any character to start");
    while (!Serial.available());
  #endif //WAIT_TO_START

  Serial.println("ArduCAM Start!");

  pinMode(SPI_CS, OUTPUT);            // set the SPI_CS as an output.
  SPI.begin();                        // initialize SPI
  myCAM.write_reg(ARDUCHIP_TEST1, 0x55);  // is ArduCAM SPI bus is OK
  temp = myCAM.read_reg(ARDUCHIP_TEST1);
  if (temp != 0x55)
  {
    Serial.println("SPI interface Error!");
    while (1);
  }

  myCAM.rdSensorReg8_8(OV2640_CHIPID_HIGH, &vid);
  myCAM.rdSensorReg8_8(OV2640_CHIPID_LOW, &pid);
  if ((vid != 0x26) || (pid != 0x42))
    Serial.println("Can't find OV2640 module!");
  else
    Serial.println("OV2640 detected");

  myCAM.set_format(JPEG);
  myCAM.InitCAM();
  myCAM.write_reg(ARDUCHIP_FRAMES,0x03);  //Number of frames to captured

  //Initialize SD Card
   if (!SD.begin(10, 11, 12, 13))
  {
    //while (1);        //If failed, stop here
    Serial.println("SD Card Error");
  }
  else
  {
    Serial.println("SD Card detected!");
  }

  if (!RTC.begin()) {
    Serial.println("RTC failed");
  }

  if (tsl.begin())
  {
    Serial.println("Found a TSL2591 sensor");
  }
  else
  {
    Serial.println("No sensor found ... check your wiring?");
    while (1);
  }

configureSensor();
stamp();
}

void loop()
{
 acquire();
 k=0;
}

void acquire(){
  char str[8];
  File outFile;
  byte buf[256];
  static int i = 0;
  uint8_t temp, temp_last;
  uint8_t start_capture = 0;
  int total_time = 0;
  start_capture = 1;
  if (start_capture)
  {
myCAM.flush_fifo(); // reset the fifo read pointer to 0 (clear the camera buffer?)
myCAM.clear_fifo_flag(); //clears flag before next capture command
myCAM.start_capture();
  }

  while (!myCAM.get_bit(ARDUCHIP_TRIG , CAP_DONE_MASK));  // what does "CAP_DONE_MASK" mean? Seems like this does nothing. "Polling the capture done flag". Why?
//determine ambient light intensity
uint32_t lum = tsl.getFullLuminosity();
uint16_t ir, full;
ir = lum >> 16;
full = lum & 0xFFFF;
LUX = tsl.calculateLux(full, ir);
T = (millis());
if (! logfile) {
logfile = SD.open("test.csv", FILE_WRITE);
}
#if ECHO_TO_SERIAL
      Serial.print (T); Serial.print(" ");
      Serial.print(LUX); Serial.println("  ");
#endif //ECHO_TO_SERIAL
      logfile.print(" "); logfile.print(T); logfile.print(" ");
      logfile.print(" "); logfile.print(LUX); logfile.println(" ");
    // Did is suddenly get very bright? If it did, retrieve the last series of frames so we can figure out what's going on in this environment.
    if (LUX > 10000) {
    logfile.print ("threshold_exceeded_"); logfile.print (T); logfile.println ("_ms");
    Serial.print ("threshold_exceeded_"); Serial.print (T); Serial.println ("_ms");
    logfile.close();
    length = myCAM.read_fifo_length();
    Serial.print("The fifo length is :");
    Serial.println(length, DEC);

         for  (int q=0; q<3; q++)
          { transfer();
          }
      /* Clear the capture done flag */
        myCAM.clear_fifo_flag();
      /* Clear the start capture flag. */
        start_capture = 0;
          }
    }

void transfer(){
char str[8];
File outFile;
byte buf[256];
static int i = 0;
uint8_t temp, temp_last;
int total_time = 0;

  //Construct a file name
    k = k + 1;
    String fileName = String();
    fileName = T;
    fileName += "_";
    fileName += k;
    fileName += ".jpg";
    char charFileName[fileName.length() +1];
    fileName.toCharArray(charFileName, sizeof(charFileName));
    outFile = SD.open(charFileName, O_WRITE | O_CREAT | O_TRUNC);
  if (! outFile)
  {
    Serial.println("open file failed");
    return;
  }
  Serial.print("Writing to: ");
  Serial.println(charFileName);

            total_time = millis();
            i = 0;
            myCAM.CS_LOW();
            myCAM.set_fifo_burst();
            temp = SPI.transfer(0x00);
            Serial.print ("temp= "); Serial.println(temp,HEX);
          /* Read JPEG data from FIFO  to temp until the final memory address is reached. */
        while ( (temp != 0xD9) | (temp_last != 0xFF))
        {
          temp_last = temp;
          temp = SPI.transfer(0x00);
        length--;
      /* Write image data to buffer if not full. The buffer can hold 256 bytes of data. Increment through the cells of the buffer, adding the data from temp until the buffer is full. */
          if (i < 256)
            buf[i++] = temp;
          else
          {
      /* Write 256 bytes image data to file. */
            myCAM.CS_HIGH();
            Serial.print("*");    // each time 256 bytes of data is written to the file, serial print an "*"
            outFile.write(buf, 256);
            i = 0;
            buf[i++] = temp;
            myCAM.CS_LOW();
            myCAM.set_fifo_burst();
          }
        }
        Serial.print("finished (?) temp=0x");Serial.print(temp,HEX);Serial.print(" temp_last=0x");Serial.println(temp_last,HEX);
      /* Write the remain bytes in the buffer */
        if (i > 0)
        {
          myCAM.CS_HIGH();
          outFile.write(buf, i);
        }
      /* Close the file. */
        outFile.close();
        total_time = millis() - total_time;
        Serial.print("Total time used:");
        Serial.print(total_time, DEC);
        Serial.println(" ms");

    Serial.print("The fifo length is :");
    Serial.println(length, DEC);
    }

Can someone recommend a way to avoid writing these anomalous 0x00 into my jpeg images?


text:
Compiling Error
I am trying  to compile this code on arduino IDE...It showing error
code is
#include <IRremote.h>

int RECV_PIN = 6;
int led = 12;//1FE50AF
int led1 = 10;//1FED827
int led2 = 9; //1FEF807
int led3 = 8;//1FE3087
int led4 = 7;//1FEB04F
boolean previousState=LOW;
boolean previousState1=LOW;
boolean previousState2=LOW;
boolean previousState3=LOW;
boolean previousState4=LOW;
boolean state;
boolean state1;
boolean state2;
boolean state3;
boolean state4;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
  Serial.begin(9600);
  pinMode(12,OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(9,OUTPUT);
  pinMode(8,OUTPUT);
  pinMode(7,OUTPUT);
  irrecv.enableIRIn();// Start the receiver
}
void loop() {
  if (irrecv.decode(&results))
  {
    Serial.println(results.value, HEX);
    switch(results.value)
    {
       case 0x1FE50AF:
       if (previousState == LOW)
       {state=HIGH;
        digitalWrite(led,state);
       previousState=state;}
       else
       {state=LOW;
       digitalWrite(led,state);
       previousState=state;}
       break;
        case 0x1FED827:
       if (previousState1 == LOW)
       {state=HIGH;
        digitalWrite(led1,state1);
       previousState1=state1;}
       else
       {state1=LOW;
       digitalWrite(led1,state1);
       previousState1=state1;}
       break;
       case 0x1FEF807:
       if (previousState2 == LOW)
       {state2=HIGH;
       digitalWrite(led2,state2);
       previousState2=state2;}
       else
       {state2=LOW;
       digitalWrite(led2,state2);
       previousState2=state2;}
       break;
        case 0x1FE30CF:
       if (previousState3 == LOW)
       {state3=HIGH;
        digitalWrite(led3,state3);
       previousState3=state3;}
       else
       {state3=LOW;
       digitalWrite(led3,state3);
       previousState3=state3;}
       break;
        case 0x1FEB04F:
       if (previousState4 == LOW)
       {state4=HIGH;
        digitalWrite(led4,state4);
       previousState4=state4;}
       else
       {state4=LOW;
       digitalWrite(led4,state4);
       previousState4=state4;}
       break;
    }
    irrecv.resume(); // Receive the next value
  }
}

Error massage which I Getting during compiling

Arduino: 1.6.5 (Windows XP), Board: "Arduino/Genuino Uno"
Using library IRremote in folder: C:\Documents and Settings\Santanu
  Mandal\My Documents\Arduino\libraries\IRremote (legacy)
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard -IC:\Documents
  and Settings\Santanu Mandal\My Documents\Arduino\libraries\IRremote
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\IRrecvDemowithled.cpp
  -o C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\IRrecvDemowithled.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard -IC:\Documents
  and Settings\Santanu Mandal\My Documents\Arduino\libraries\IRremote
  -IC:\Documents and Settings\Santanu Mandal\My Documents\Arduino\libraries\IRremote\utility C:\Documents and
  Settings\Santanu Mandal\My
  Documents\Arduino\libraries\IRremote\IRremote.cpp -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\IRremote\IRremote.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-gcc -c -g -x
  assembler-with-cpp -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605
  -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\wiring_pulse.S -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\wiring_pulse.S.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-gcc -c -g -Os
  -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\hooks.c -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\hooks.c.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-gcc -c -g -Os
  -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\WInterrupts.c -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\WInterrupts.c.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-gcc -c -g -Os
  -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\wiring.c
  -o C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\wiring.c.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-gcc -c -g -Os
  -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\wiring_analog.c -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\wiring_analog.c.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-gcc -c -g -Os
  -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\wiring_digital.c -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\wiring_digital.c.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-gcc -c -g -Os
  -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\wiring_pulse.c -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\wiring_pulse.c.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-gcc -c -g -Os
  -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\wiring_shift.c -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\wiring_shift.c.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\abi.cpp -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\abi.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\CDC.cpp -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\CDC.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\HardwareSerial.cpp -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\HardwareSerial.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\HardwareSerial0.cpp
  -o C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\HardwareSerial0.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\HardwareSerial1.cpp
  -o C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\HardwareSerial1.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\HardwareSerial2.cpp
  -o C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\HardwareSerial2.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\HardwareSerial3.cpp
  -o C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\HardwareSerial3.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\HID.cpp -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\HID.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\IPAddress.cpp -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\IPAddress.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\main.cpp -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\main.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\new.cpp -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\new.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\Print.cpp -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\Print.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\Stream.cpp -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\Stream.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\Tone.cpp -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\Tone.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\USBCore.cpp -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\USBCore.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\WMath.cpp -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\WMath.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\WString.cpp -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\WString.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\wiring_pulse.S.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\hooks.c.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\WInterrupts.c.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\wiring.c.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\wiring_analog.c.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\wiring_digital.c.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\wiring_pulse.c.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\wiring_shift.c.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\abi.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\CDC.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\HardwareSerial.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\HardwareSerial0.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\HardwareSerial1.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\HardwareSerial2.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\HardwareSerial3.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\HID.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\IPAddress.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\main.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\new.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\Print.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\Stream.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\Tone.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\USBCore.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\WMath.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\WString.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-gcc -Os
  -Wl,--gc-sections -mmcu=atmega328p -o C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/IRrecvDemowithled.cpp.elf
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\IRrecvDemowithled.cpp.o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\IRremote\IRremote.cpp.o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  -LC:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp -lm
collect2.exe: error: ld returned 5 exit status Error compiling.

Windows XP...... Sorry but we are in 2016 (almost 2017) and Windows XP is like not even supported anymore (since a LONG LONG time). Could that be your problem??

I have been faced with this GCC LD issue on Windows a million times. I finally decided to build all my Arduino stuff on Linux without any problem. This LD issue has loads of reported errors, discussions on Internet, with various weird workarounds that sometimes work once but fail the next time...

Sir, I have used  IDE 1.6.12 to compile this code but it also give error    Arduino: 1.6.12 (Windows XP), Board: "Arduino/Genuino Uno"
collect2.exe: error: ld returned 5 exit status
Using library IRremote in folder: C:\Documents and Settings\Santanu Mandal\My Documents\Arduino\libraries\IRremote (legacy)
exit status 1
Error compiling for board Arduino/Genuino Uno.

You have been bitten by a bug in the compiler toolchain. The bug has already been reported. Suggested workarounds:

add a few unused global variables
add some unused functions.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Serial.println cuts off first digit
I'm trying to perform a simple analogRead() and print out the result, as below:

void getVoltMeter() {

  readValue = analogRead(A2);
  readByte = readValue/4;
  Serial.println(readValue);
  Serial.println(readByte);

}

But the output is:
023
255

The voltage input is 5V, so I would expect it to read:
1023
255

Why is the first digit being cut off?

What board are you using?

What does it look like if you swap order of the println() commands?

What happens if you add a Serial.println() first?

josecanuc: if I swap the print commands, it reads "4, 1024"
@Majenko I'm using an Uno. If I put a blank print statement first, it prints the values as expected without truncation, so this is a solution. I mostly just want to understand what's going on that would make this happen.

What are you viewing the output in?

In the serial monitor

You must share your full sketch here.


text:
Fastest way to read an array of numbers from python
I'm trying to send an array of numbers from python to Arduino over the serial connection. I can reliably read a small incoming set of numbers (for example 123435678) from python, which I can then parse since I know how many digits are supposed to be in each number (for example, 1, 23456, 78). I do this with my Arduino code:

void getInput() {
     char buff[9];
     int field1;
     char field2[6];
     char field3[3];

  Serial.readBytes(buff, 8); //read 8 bytes from the Serial port
  buff[9] = '\0'; //null terminate the string we just read
  Serial.println(buff); //check that we got it
  for(int i=0; i<buff_len;i++) { //now we divide up the string into separate numbers
    if(i==0) {
      field1 = buff[0] - 48; //turn it into an int using ASCII
    }
    if(i>=1 && i<6) {
      field2[i-1] = buff[i];
      field2[5] = '\0';
    }
    if(i>=6) {
      field3[i-6]=buff[i];
      field3[2] = '\0';
    }
  }
  for(int i=0;i<buff_len;i++) { //clear the buffer
    buff[i]=0;
  }
}

But if I wanted to send a whole array whose contents I don't know in advance, for example like this:
for i in range(200):
    ser.write(i)

What's the best way to get these numbers to Arduino and file them away in an int array? Should I make the array in python first as a numpy.linspace() and send that?

While it's probably not your only issue, you invoke undefined behavior when you write to the 10th element (index 9) of the 9-element buff[9].

If you don't know the length of the data then you need to be sending start and end markers so your other code can tell where the transmission starts and ends.  I usually use < and >, so the data packet might look like <12345678>.  You don't have to use those particular characters, just pick something that you know won't show up in your data.

Yes. Putting a newline at the end of each is even more common, and plays well with many traditional computing tools.  Since there seem to be multiple fields in each entry, putting a space or comma between them would also help.


text:
NodeMCU v1 keeps dropping out
I've created a homebridge server on a Raspberry Pi Zero and have configured it to use my NodeMCU v1 (Esp - 12E Module) as an accessory to control RGB strip lights.
All works normally until you don't use the home kit to control the lights for certain amount of time (~30 seconds). My iPhone says that the accessory is non responsive until I force a command to happen, this after some time activates the accessory and goes back to normal.
Is there a way of keeping the NodeMCU active to HTTP responses all the time?
The code I have used is a mashup of a tutorial I used but I've modified it with some more features. (All coded in Arduino)
//NodeMCU RGB-Controller for Homebridge & HomeKit (Siri)

#include <ESP8266WiFi.h>
#include <math.h>

#define redPin 13 //D7 - Red channel
#define grnPin 12 //D6 - Green channel
#define bluPin 14 //D5 - Blue channel
#define white 5 //D1 - Blue channel

WiFiServer server(80); //Set server port

String readString;           //String to hold incoming request
String hexString = "000000"; //Define inititial color here (hex value), 080100 would be a calm warmtone i.e.

int state;

int r;
int g;
int b;

float R;
float G;
float B;

int x;
int V;

///// WiFi SETTINGS - Replace with your values /////////////////
const char* ssid = "xxxxxxx";
const char* password = "xxxxxxx";
IPAddress ip(192,168,1,234);      // set a fixed IP for the NodeMCU
IPAddress gateway(192,168,1,1);  // Your router IP
IPAddress subnet(255,255,255,0); // Subnet mask
////////////////////////////////////////////////////////////////////

void WiFiStart() {
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  WiFi.config(ip, gateway, subnet); //Set a fixed IP. You can comment this out and set it in your router instead.
  while (WiFi.status() != WL_CONNECTED) {
    delay(100);
    Serial.print("_");
  }
  Serial.println();
  Serial.println("Done");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  Serial.println("");

  server.begin();
}

void allOff() {
  state = 0;
  analogWrite(redPin, 0);
  analogWrite(grnPin, 0);
  analogWrite(bluPin, 0);
}

//Write requested hex-color to the pins (10bit pwm)
void setHex() {
  state = 1;
  long number = (long) strtol( &hexString[0], NULL, 16);
  r = number >> 16;
  g = number >> 8 & 0xFF;
  b = number & 0xFF;
  r = map(r, 0, 255, 0, 1023);  //added for 10bit pwm
  g = map(g, 0, 255, 0, 1023);  //added for 10bit pwm
  b = map(b, 0, 255, 0, 1023);  //added for 10bit pwm
  analogWrite(redPin, (r));
  analogWrite(grnPin, (g));
  analogWrite(bluPin, (b));
}

//Compute current brightness value

//For serial debugging only
void showValues() {

  Serial.print("Status on/off: ");
  Serial.println(state);
  Serial.print("RGB color: ");
  Serial.print(r);
  Serial.print(".");
  Serial.print(g);
  Serial.print(".");
  Serial.println(b);
  Serial.print("Hex color: ");
  Serial.println(hexString);

  Serial.print("Brightness: ");
  Serial.println(V);
  Serial.println("");

}

void setup(){
  Serial.begin(9600);
  delay(1);
  pinMode(redPin, OUTPUT);  //declaration added
  pinMode(grnPin, OUTPUT);  //declaration added
  pinMode(bluPin, OUTPUT);  //declaration added
  setHex(); //Set initial color after booting. Value defined above
  WiFi.mode(WIFI_STA);
  WiFiStart();
  //showValues(); //Uncomment for serial output
}

void loop() {
  //Reconnect on lost WiFi connection (superfluous - will reconnect anyway)
  if (WiFi.status() != WL_CONNECTED) {
    WiFiStart();
  }

  WiFiClient client = server.available();

  if (!client) {
    return;
  }

  while(client.connected() && !client.available()) {
    delay(1);
  }

  //Respond on certain Homebridge HTTP requests
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        if (readString.length() < 100) {
          readString += c;
        }
        if (c == '\n') {
          Serial.print("Request: "); //Uncomment for serial output
          Serial.println(readString); //Uncomment for serial output

          //Send reponse
         client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();

          //On
          if(readString.indexOf("on") >0) {
            setHex();
            Serial.println("on");
            showValues();
          }

          if(readString.indexOf("xw") >0) {

            Serial.println("won");
            analogWrite(white, 1024);
          }

          if(readString.indexOf("yw") >0) {

            Serial.println("woff");
            analogWrite(white, 0);
          }

          //Off
          if(readString.indexOf("off") >0) {
            allOff();
            showValues();
          }

          //Set color
          if(readString.indexOf("set") >0) {
            hexString = "";
            hexString = (readString.substring(9,15));
            setHex();
            //showValues();
          }

          //Status on/off
          if(readString.indexOf("status") >0) {
          client.println(state);
          }

          //Status color (hex)
          if(readString.indexOf("color") >0) {
          client.println(hexString);
          }

          //Status brightness (%)
          if(readString.indexOf("bright") >0) {

          client.println(V);
          }

          delay(1);
          client.stop();
          readString="";
        }
      }
    }
  }
}

You are probably running out of RAM because you are using the String object instead of a fixed-size char[] buffer. This code, in particular:
if (readString.length() < 100) {
  readString += c;
}

Concatenating String objects using the overloaded plus operator allocates a whole new block of RAM for the new, longer string. It frees the previous memory, but since you keep adding one character at a time, new strings won't be able to be put into the once-used RAM.
You should instead use C-style strings (character arrays) and the standard functions for managing them, such as strnlen() and strncat(), etc. Note, I am suggesting the versions of string functions with a maxlen parameter, which helps avoid bugs due to unterminated strings.

I can't seem to implement this

Share what you’ve tried. Thus page has a good overview http://www.gammon.com.au/concat

I had to make a new question as the comment wouldn't let me copy all my changed code: https://arduino.stackexchange.com/questions/48066/nodemcu-keeps-dropping-out-implementation?noredirect=1#comment95555_48066


text:
Arduino number detection
I am planning for a project but i am stuck with a task and hope you could help me. My work is to note down a number which is actually a set of readings displayed on a meter and store it on a arduino. My problem is that i need a detection technique so that i could record the number or extract the number from a image or video if u suggest to use a camera or recorder or purely can be a sensor. Thank you guys, waiting for you.

What kind of meter? Analog, digital, leds, lcd, ...?

What exactly is it you are trying to do? What does this "meter" measure? What form does that measurement and display take?

Abstraction is (often) a good thing. But for this question, we're going to need the details of this specific meter. How does the display work, can we wire into the display? How does the end sensor work, can we just replace it? Best would be if you upload an image and description of the sensor.

"Number detection" sounds like you're trying to interpret a 7-segment digital display - is that correct? One way would be to place 7 photo-detectors (times the number of digits), one per segment, on or at the face of the display. Sample the photo-detectors and create a 7-bit code representing the lit segments, into a byte. You could start with a simple lookup table that translates from code to the digit it represents. You might need to get clever about interpreting codes that shouldn't appear, but do, due, perhaps to light leakage, ambient lighting, or noise. The "lit" segments may only be lit for a fraction of second at a time, and only one at a time, if the display is multiplexed, so your sampling algorithm will have to take that into account. Must the display remain visible? You might need optics or optical fibers to view the segments without obstructing them.

+1 for the extreme "hacky" end-product that can be placed ontop of an 7segment and read it's value. But how is this superior to just reading the pins/lines that go to the 7segment? (If we have access to them, I would suggest reading those out).

Thanks! And of course, it isn't better. I tried to guess what the real requirement was based on the OP's question - is this a design-course exercise? - and to answer that. If I could have connectivity to the system, I'd do as you suggest. If I could have access to its firmware, I'd transmit the values by, e.g. serial.  In any case, we can't answer for real without a better spec.


text:
Is it possible to use WiFi and Bluetooth / BLE in the same ESP32 project?
@Majenko's answer works like a charm. I did have to make some changes as follows:
Per Majenko, you need to change the Tools > Partition scheme.  I used "No OTA (Large APP) as he suggested and it is now working.
However, the Partition Scheme option under Tools was not available for either of my devices (Huzzah32 or NodeMCU-32s).  I changed my board type (Tools > Board) to "ESP32 Dev Module" and several additional options appeared under Tools, including Partition Scheme.
Original Question: I am not able to use both the WiFi.h and BLE libraries at the same time.  Even the most minimal projects run out of memory during compile.  Am I doing something wrong?   I get identical results with both an Adafruit Huzzah32 and a NodeMCU-32S.
Does anyone know of a workaround, or barring that a suggested alternate board? A Raspberry pi zero W seems like overkill and the power consumption is ugly, so I don't want to do that unless I really have to.
#include <WiFi.h>
#include <BLEDevice.h>

void setup() {
  WiFi.mode(WIFI_MODE_STA);             // use a WiFi function
  BLEDevice::init("Minimal BLE WiFi");  // use a BLE function
}

void loop() { }

The error I get is

Arduino: 1.8.9 (Mac OS X), Board: "NodeMCU-32S, 80MHz, 921600"
Build options changed, rebuilding all Sketch uses 1443898 bytes (110%)
  of program storage space. Maximum is 1310720 bytes.
Global variables use 60208 bytes (18%) of dynamic memory, leaving
  267472 bytes for local variables. Maximum is 327680 bytes. Sketch too
  big; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips
  on reducing it. Error compiling for board NodeMCU-32S.

Could you please revert the question to the original state, we don't use "[SOLVED]" on titles nor post solutions inside questions. The best would be for you to post a new answer and move your solution there. Thanks!

Yes. Select a partition scheme that gives you more room. For example "No OTA (Large APP)" gives you 3MB of program space.

This worked.   I had to make make some changes to my Arduino IDE environment which I will add to my initial question.


text:
Modifying Arduino IMU library to rely on DSSCircuit's I2C Master Library
For an Arduino project I am working on, I am trying to modify the SparkFun 6 Degrees of Freedom IMU Digital Combo Board - ITG3200/ADXL345 to support DSSCircuit's I2C Master Library (https://github.com/DSSCircuits/I2C-Master-Library). This is to combat the known issue of the Arduino Wire library to often get hung up while trying to run the EndTransmission function.
I'm new to this and do not understand how the terms 'slave address' and 'register address' and 'bytes you want to send' are different, if they are. I also do not understand how buffering works in the base IMU library. Any information on those would be appreciated, but is not the focus of my question.
I use the example code of the IMU unit...
#include <FreeSixIMU.h>
#include <FIMU_ADXL345.h>
#include <FIMU_ITG3200.h>
#include <Wire.h>
#include <I2C.h>

int raw[6]; // x y z yaw pitch roll

// Set the FreeSixIMU object
FreeSixIMU sixDOF = FreeSixIMU();

void setup() {
  Serial.begin(9600);
  I2c.begin();

  delay(100);
  sixDOF.init(); //begin the IMU
  delay(100);
}

void loop() {
  sixDOF.getRawValues(raw);
  Serial.print(raw[0]);
  Serial.print(" x | ");
  Serial.print(raw[1]);
  Serial.print(" y | ");
  Serial.print(raw[2]);
  Serial.println(" z");
  delay(100);
}

And I changed the selected IMU library functions as follows:
// Writes val to address register on device
void ADXL345::writeTo(byte address, byte val) {
  I2c.write(address, val);
  // send register address
}

// Reads num bytes starting from address register on device in to _buff array
void ADXL345::readFrom(byte address, int num, byte _buff[]) {
  I2c.read(address, (byte) num);
  // sends address to read from
}

void ITG3200::writemem(uint8_t _addr, uint8_t _val) {
  I2c.write(_addr, _val);   // start transmission to device
}

void ITG3200::readmem(uint8_t _addr, uint8_t _nbytes, uint8_t __buff[]) {
  I2c.read(_addr, _addr, _nbytes);   // start transmission to device
}

And added the #include <I2C.h> statements to the headers files where applicable.
When running the example code, the serial output will not change values based on how I move the accelerometer, which makes me think I used the wrong slave address to read data from, or some other issue.
Can someone help me modify the IMU library to include DSSCircuit's Master I2C Library?
Thank you Stack Exchange Community!
John
EDIT:
Please see PersonAGem's edit below. Using the wire library is known to have arbitrary hangups, and in this example PersonAGem lists the edits I should make to the other libraries I am using as well as gives me the code I should use in my .ino.
I ask a new question about this topic here.

You are missing the rest of the code in reading operations. You are just requesting the data, no actually reading it from the device:
the original code of adlx345::read
void ADXL345::readFrom(byte address, int num, byte _buff[]) {
  Wire.beginTransmission(_dev_address); // start transmission to device
  Wire.write(address);             // sends address to read from
  Wire.endTransmission();         // end transmission

  Wire.beginTransmission(_dev_address); // start transmission to device
  Wire.requestFrom(_dev_address, num);    // request 6 bytes from device

  int i = 0;
  while(Wire.available())         // device may send less than requested (abnormal)
  {
    _buff[i] = Wire.read();    // receive a byte
    i++;
  }
  if(i != num){
    status = ADXL345_ERROR;
    error_code = ADXL345_READ_ERROR;
  }
  Wire.endTransmission();         // end transmission
}

would change to (if no mistakes made):
void ADXL345::readFrom(byte address, int num, byte _buff[]) {
  I2c.read(_dev_address, address, num) // request 6 bytes from device
  if(I2c.available() != num){  // device may send less than requested (abnormal)
    status = ADXL345_ERROR;
    error_code = ADXL345_READ_ERROR;
  }

  int i = 0;
  while(I2c.available())
  {
    _buff[i] = I2c.receive();    // receive a byte
    i++;
  }
}

you may need to force cast parameters between functions.
If for some reason you don't want the actual code and want to use another library, I'll suggest I2Cdev site with a well documented classes for adlx345 and ITG3200.
Edit:
This caused me no problem. That is the only 2 functions I changed:
// Writes val to address register on device
void ADXL345::writeTo(byte address, byte val) {
  I2c.write((uint8_t) _dev_address, (uint8_t) address, (uint8_t) val);
}

// Reads num bytes starting from address register on device in to _buff array
void ADXL345::readFrom(byte address, int num, byte _buff[]) {
  I2c.read((uint8_t) _dev_address, (uint8_t) address, (uint8_t) num);  // request 6 bytes from device
  if(I2c.available() != num){  // device may send less than requested (abnormal)
    status = ADXL345_ERROR;
    error_code = ADXL345_READ_ERROR;
  }

  int i = 0;
  while(I2c.available())
  {
    _buff[i] = I2c.receive();    // receive a byte
    i++;
  }
}

Arduino code used:
#include <I2C.h>
#include "FIMU_ADXL345.h"

ADXL345 acc = ADXL345();
int x=0,  y=0, z=0;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  I2c.begin();
  delay(100);
  acc.init(ADXL345_ADDR_ALT_LOW);
  delay(100);
  Serial.print("Is ACC OK?: ");
  Serial.println(acc.status);
  Serial.print("Any Error code?: ");
  Serial.println(acc.error_code);
  Serial.println("********Print all register current values********");
  acc.printAllRegister();
  Serial.println("********END register print******");
  Serial.println(acc.getRate());
}

void loop() {
  // put your main code here, to run repeatedly:
  acc.readAccel(&x,&y,&z);
  Serial.print(x);
  Serial.print('\t');
  Serial.print(y);
  Serial.print('\t');
  Serial.println(z);
  delay(500);
}

Output given:
Is ACC OK?: 1
Any Error code?: 0
********Print all register current values********
0x00: B11100101
0x1D: B00000000
0x1E: B00000000
0x1F: B00000000
0x20: B00000000
0x21: B00000000
0x22: B00000000
0x23: B00000000
0x24: B00000000
0x25: B00000000
0x26: B00000000
0x27: B00000000
0x28: B00000000
0x29: B00000000
0x2A: B00000000
0x2B: B00000000
0x2C: B00001010
0x2D: B00001000
0x2E: B00000000
0x2F: B00000000
0x30: B10000011
0x31: B00000000
0x32: B11110101
0x33: B11111111
0x34: B00000011
0x35: B00000000
0x36: B11100101
0x37: B00000000
0x38: B00000000
0x39: B00000000
********END register print******
100.00
-12 4   230
-10 2   231
-11 3   231
-12 3   228
-10 3   230
-11 2   231
-12 2   229
-11 3   229
-10 3   231
-11 3   229
-10 2   230
-12 4   230
-12 3   229
-10 2   229
-13 4   230
-11 3   230
-10 3   230
-11 2   230
-11 4   229
-11 3   230
-11 3   230
-11 3   229
-12 3   229
-10 2   229
-11 3   230
-11 3   231
-11 3   230
-15 14  227
34  104 210
138 95  191
243 18  88
323 -15 74
280 -8  -2
263 -2  37
212 10  163
16  39  233
28  114 195
29  161 170
33  124 211
5   49  244
7   22  224
-10 3   229
-11 2   230
-12 2   230
-11 3   231
-12 4   228

Thank you I will try this in the morning. I can see I did not realize I was not reading the data when I requested it.

Sorry, it did not work...
I am now getting something in the range of 0-256, only positive values, and they vary widely. I've seen 92 as minimum and 230 as maximum.
I modified your code ||      I2c.read(dev_address, address, num)  // request 6 bytes from device
|| --> ||      I2c.read(address, (byte) num);  // request 6 bytes from device
|| and it compiled.

*This is while it is lying on the table. Left to run for about a minutes. The code in general prints to serial about 7Hz as tested a week ago.

have you changed all the other functions?

@JohnDoe I managed to get an adlx345 for testing communication and all went fine apparently. Look at updated code for the read with the forced casts. However, I really advise you that this can result in many mistakes. I couldn't find any documentation for the I2C library you are suggesting.

I am forever grateful for your help. I'm away from the office for the holiday week, and look forward to trying this when I get back.

solved at this time.


text:
Digital input pin voltage treshold (voltage to register 1 or 0)
I was thinking of using multiple analog light sensors (variable resistance by light), but basically I only need to know if there is "a lot of light" or "not a lot of light". And would like to use interrupts.
Since I'm using multiple analog inputs, I can't set the ADC module to interrupt on a specific voltage, for each of the (5?) sensors?
I'd like to do this withouth using a external comparator.
I've checked the ATMega328p datasheet (going to use Arduino Nano probably).

The fun thing, however, is that on 5V a high signal is >2.6V and a low signal is <2.2V
What does this mean for the grey area? Would my inputs be glitching randomly? Would they maintain high, until below 2.2V and maintain low until above 2.6V? Or can the switching point be any where between that (and is it different per chip or pin?
EDIT: I've checked, my voltage divider circuit has 0.6V for "nothing" and 3V for "interrupted", so it should work neverthless. Though, I'm still interested in how the grey threshold area behaves.

Consider adding a differential amplifier like LM741 or LM341 with the sensor input connected to the non-inverting terminal and the inverting input connected to a potentiometer. This is always the best arrangement that I have found that works..when it comes to light sensors. You may adjust the potentiometer to such that the op-amp produces the desired output at the desired conditions. This has also the advantage that you easily adjust the threshold if the lighting conditions change by changing the potentiometer than changing the code.

The titles of the graphs are actually saying what happens: the hysteresis.
In other words:

if the input level is high (greater than 2.6V), it will be considered high through the hysteresis area (until it goes below 2.2V)
if the input level is low (below 2.2V), it will be considered low through the hysteresis area (until it goes above 2.6V)

According to the description you gave, this should work for your case.
In case it doesn't, you have to condition it until the values you want to consider 0 and 1 are respectively below 2.2V and above 2.6V, with a safety margin, for good measure (say 30%).
The hysteresis is meant to prevent noise from causing unwanted spurious transitions: without safety margin, it should be greater than 0.4V.
You can dimension the safety margin to meet your needs.
But, for the sake of completeness, I'll say that it might be preferable to have a timer to trigger periodic sampling with the ADC.
If you know the maximum frequency at which every input can vary, you can sample it at twice that frequency and be sure that you will not miss anything. Again, this is theory, I would probably make it 4 times, to allow for unforeseen variations.
This works as long as the conversion time of the ADC is shorter than the maximum combined frequency at which you need to read the values.
The GPIOs, of course, are faster, but might require additional circuitry for the conditioning I mentioned earlier.

Good, I was worried the input might go random when it's on 2.4V. But you're saying the 2.4V will leave it in the current state, only if it goes higher as 2.6V or lower as 2.2V it will cause a "transition". So one could say that the grey area is "stable".

After setting my voltage divider right, I've got a 0.6V for low and 3V for high. I might shift it a little higher, but that would indeed work, withouth having to worry about the "grey area", but it's good to know what the values in the datasheet mean.

It is designed exactly for that purpose, to increase the resilience of the circuit to noise and variation in components (think of the tolerances in the industrial manufacturing processes) and environments where they operate.

The challenge modern electronics face is that the physical world is not really changing, while the circuits are becoming low power (lower max voltage). So the 0 and 1 thresholds are getting closer: just compare an "old school" 5V circuit with Arduino, with a modern SoC that has Vdd=1.8V. The entire range of the modern circuit is smaller than the range allowed for logic 0 on the Arduino!

I was wondering about that also, my project was a proof of concept for a "planter monitor" which could measure maize seeds dropping. If I would ever put it on a real planter, I'd better have some noise immunity. I believe PLC's run at 24V for that reason. The advantage of low voltage would ve lower power? 1.8V is okay on a PCB, but I wouldn't run long wires with it (:

This is now digressing, but on long lines you do not usually put normal signal, you want to have something that has better S/N ratio. Example: differential signals used in old telephone lines. For modern, more complex cases, one uses complex modulations (that's what a DSL modem does, for example.)  As reference, check out this: https://en.wikipedia.org/wiki/Phase-shift_keying

In your case, you would probably use a level shifter against the bus/sensor used to dete the parameter you need. Ex: https://i.sstatic.net/DGm1u.png


text:
Problem communicating with ENC28J60
I want to send/receive strings to/from an ENC28J60 via a C# application. I used my own "protocol" to do this. For example I send "" to Arduino and it replies with a string containing temperature values. This method works fine in Serial communication mode, but freezes in Network mode. What am I missing here? Is there a better method to do this? I'm new to socket programming. I'm using UIPEthernet.h by ntruchsess.
My server-side (Arduino) code:

void checkAndReceiveFromTCPClients(){
  size_t size;
  if (EClient = EServer.available()){
    char* strIn;
    if(size = EClient.available() > 0){
      strIn = (char*)malloc(size + 1);
      memset(strIn, 0, size + 1);
      EClient.read(strIn, size);
    }
    strIn[size] = 0;
    String strInput = String(strIn);
    strInput.trim();
    //This replies to client (sends string) with a string (EClient.write(answer)):
    InterpretInputString(strInput);
    //EClient.stop();
    EClient.flush();
  }
}

C# code:
string SendAndReceiveOverNet(string Command) {
    Byte[] data = System.Text.Encoding.ASCII.GetBytes(Command);
    NetworkStream stream = TClient.GetStream();
    stream.Write(data, 0, data.Length);
    data = new Byte[256];
    String responseData = String.Empty;
    Int32 bytes = stream.Read(data, 0, data.Length);
    responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
    return responseData;
}

Something like this is needed here. If you use stream.Read without TClient.Available, the program will freeze or crash.
C# code:
string SendAndReceiveOverNet(string Command) {
    Byte[] data = System.Text.Encoding.ASCII.GetBytes(Command);
    NetworkStream stream = TClient.GetStream();
    stream.Write(data, 0, data.Length);
    String responseData = String.Empty;
    Int32 size = TClient.Available;
    if (size > 0)
    {
        data = new Byte[size];
        Int32 bytes = stream.Read(data, 0, data.Length);
        responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
    }
    return responseData;
}


text:
Is an atmega 2560 board compatible with the Adafruit Trellis?
I want to build a custom midi controller for my computer, and yes, Adafruit has a mini Untz project. For my purposes, I need more analog inputs than the Leonardo, and the only other option I can find is the atmega 2560. Can i use that?

You want to use the USB MIDI interface the Leonardo can create? No - the ATMega2560 doesn't have a native USB interface. You want to use some Serial-to-MIDI bridge software, or re-program the ATMega16U2 USB interface chip? Sure, you can use that then.

ok thanks i thought because the atmega has the scl sda connections it would be possible.can the atmega 2560 be used as a midi controller at all?

You want to use some Serial-to-MIDI bridge software, or re-program the ATMega16U2 USB interface chip? Sure, you can use that then.

Mega2560 also has 4 hardware serial ports. Serial() can be left alone for programming via the PC. Serial1, Serial2, Serial3 can all have Serial/USB chips added to talk to MIDI, after all it's just a Atmega16U2 that is programmed as needed.

MIDI comes in many different arrangements.
The two most important ones for you are "MIDI Over USB" and "Traditional Serial MIDI".
The former encapsulates MIDI messages and sends them over USB to the computer. This is what you normally get when you plug in a USB-based MIDI instrument, or a USB to MIDI adapter cable.
The latter is a simple serial port running at a specific baud rate. It's generally opto-isolated as well.
On the Leonardo you can do either of those methods (you haven't mentioned which you use), but on the ATMega2560 you can only do the latter (that is, connect the board to a USB to MIDI adaptor cable).  However the Arduino Mega2560 (Note: this is a board, what you talk about is a bare chip) has a USB interface chip that can be re-programmed to look like MIDI.  That will bridge between the "traditional serial MIDI" to the "MIDI over USB". However doing so may impare your ability to program the board.
Another option is to use some PC-based Serial-To-MIDI bridge software which reads normal Serial data as provided by the Arduino and converts it into MIDI signals within your computer.
A third option is to step away from Arduino and choose a board that has both a native USB interface (with MIDI support in software) and more analog inputs.  A board such as one of the Teensy 3.x range would probably suit you well.


text:
Receiving hex data from terminal
I am trying to transmit serial data from terminal to Arduino and I want to reconfirm that its the same data. But I am not able to get the right answer. I want data to be HEX. I want to check only the third last and last bytes since they will be changing every time.
I tried to write it in 2 different ways but none worked.
First try:
byte thisByte[]={0xAA, 0xBB, 0x06, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03};
void setup()
{
  // start serial port at 9600 bps:
  Serial.begin(9600);
}

void loop()
{
  while (Serial.available())
  {
    delay(250);
    // get the new byte:
    byte thisByte = Serial.read();
    // add it to the inputString:
    //inputString += char(intChar);

    if(thisByte == 0x03 || thisByte == 0x03)
    {
      Serial.print(thisByte, 'Hello');
      //digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(50);             // wait for a second
      Serial.print(thisByte, 'Nothing');
      //digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
    }
    Serial.print(thisByte,HEX);
    Serial.print(" | ");
  }
}

Second try:
const byte message[]={0xAA, 0xBB, 0x06, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03};
boolean found = false;

byte byte1 = 0xAA;
byte byte2 = 0xBB;
byte byte3 = 0x06;
byte byte4 = 0x00;
byte byte5 = 0x00;
byte byte6 = 0x00;
byte byte7 = 0x01;
byte byte8 = 0x01;
byte byte9 = 0x03;
byte byte10 = 0x03;

const byte Hallo;
//void rules();
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  // put your main code here, to run repeatedly:
  //int hexIn = Serial.read();
  //Serial.write(message,2);
  //Serial.write(message,sizeof(message));
  //delay(500000);
  while(Serial.available())
  {
    delay(10);  //small delay to allow input buffer to fill
    byte c = Serial.read();
    byte message = c;

    //Serial.print(c,HEX);
    //Serial.print(" | ");

    //if (c =!byte 0xAA && c =!byte 1 0xAA && c =!byte 0xAA && c =!byte 0xAA && c =!byte 0xAA && c =!byte 0xAA && c =!byte 0xAA && c =!byte 0xAA);

    if (c == message);
    //Serial.print("I received: ");
    Serial.println(c);

    // byte c = Serial.read();  //gets one byte from serial buffer
    // readmessage += c;
  } //makes the string readString
  //Serial.print(messsage);
  //readString=""; //clears variable for new input
}

What, exactly, is being entered into the serial console? Are you typing literal "0x03" or similar? Or are you somehow typing the 8-bit value 0x03?

I want data to be HEX ... i do not think that you understand what hex really means

what does right answer mean? ... so far only you know what you expect to see ... we need to know also, before we can help you.

Thank you for your reply. I was providing a data from terminal but not like 0x03. But AA BB 00 03 so. But now your code gave me a idea how it works. Thanks once again

Plus one more thing I wanted to ask you was that I am trying to send data packet completely and not single byte. So what I actually want to do or my work is to for eg: 0xAA, 0xBB, 0x06, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03

Plus one more thing I wanted to ask you was that I am trying to send data packet completely and not single byte. So what I actually want to do or my work is to for eg: 0xAA, 0xBB, 0x06, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03 the data in 8th and 10th position/byte is going to varry. But what I am not able to understand is that how to check them and get the feedback of changed bytes. Those are actually the outputs from display to arduino. Please if you  can just give me a idea or some assistance to write it. Thanks in advance

First, you have to understand what “hex” means. Basically, you are
representing binary data as text, where each byte is represented as
two characters. For example, the number 42 is represented as either “2A”
or “2a”. In C and C++, you can write this number as 0x2a, but I assume
your serial stream sends the raw hex data, without the “0x” prefix.
Thus, on the serial stream you may receive the character “2” (character
code 0x32 = 50 in decimal) followed, some time later, by “a” (charcode
0x61 = 97).
What you need is a conversion routine that takes these characters and
reconstructs the binary data out of them. Here is one such routine I
use. You have to provide it with an input string in and an output
array out large enough to store the resulting binary data. The
function will return the number of bytes filled in *size:
/*
 * Convert an hex string to binary. Spaces are allowed between bytes.
 * The output array is supposed to be large enough.
 * On return, *size is the size of the byte array.
 */
static void hex2bin(uint8_t *out, const char *in, size_t *size)
{
    size_t sz = 0;
    while (*in) {
        while (*in == ' ') in++;  // skip spaces
        if (!*in) break;
        uint8_t c = *in>='a' ? *in-'a'+10 : *in>='A' ? *in-'A'+10 : *in-'0';
        in++;
        c <<= 4;
        if (!*in) break;
        c |= *in>='a' ? *in-'a'+10 : *in>='A' ? *in-'A'+10 : *in-'0';
        in++;
        *out++ = c;
        sz++;
    }
    *size = sz;
}

As a mere convenience, the function above accepts spaces within the
string, but only between bytes. Notice however that it does not attempt
to do any error checking. You may want to improve it in this respect.
Next, you have to devise a way to frame your messages on the serial
line. Serial does not provide any framing per se: it only transmits byte
one by one. When dealing with text, a common scheme is to send a
carriage return (\r) to indicate the end of a message. With this
convention, you sketch has to buffer the bytes it receives until it
sees a carriage return. Then it can process the whole message as a
whole. This approach is nicely explained in the blog post Reading
Serial on the
Arduino,
by Majenko, a regular contributor to this site.
Here is an example that reads an hex string, converts it to binary, and
then sends it back as hex again:
void setup()
{
    Serial.begin(9600);
}

void loop()
{
    static char buffer[1024];
    static size_t length = 0;

    if (Serial.available()) {
        char c = Serial.read();

        // On carriage return, process the received data.
        if (c == '\r') {
            Serial.println();  // echo

            // Properly terminate the string.
            buffer[length] = '\0';

            // Convert the hex data to a byte array.
            size_t byte_count = length/2;
            uint8_t data[byte_count];
            hex2bin(data, buffer, &byte_count);

            // Echo back the byte array in hex.
            for (size_t i = 0; i < byte_count; i++) {
                Serial.print(data[i], HEX);
                Serial.print(" ");
            }
            Serial.println();

            // Reset the buffer for next line.
            length = 0;
        }

        // Otherwise buffer the incoming byte.
        else if (length < sizeof buffer - 1) {
            Serial.write(c);  // echo
            buffer[length++] = c;
        }
    }
}

Notice the lines with the comment “echo”: they are meant to help you see
in the terminal what you are typing. You can remove them if you do not
what the Arduino to echo your typing. I tested it by sending
AA bb06 000000 0101 03 03

and it replied
AA BB 6 0 0 0 1 1 3 3

Thank you very much for your reply. It worked really good. I mwill try more to code on this topic in order to understand it completely.


text:
Garbage when listening to serial
This is the atmega328p code that is supposed to send a predefined message repeatedly.

#include <avr/io.h>
#include <util/delay.h>

#define BAUD 9600
#define BAUD_PRESCALLER (((F_CPU / (BAUD * 16UL))) - 1)

void USART_init(void) {
    UBRR0H = (uint8_t) (BAUD_PRESCALLER >> 8);
    UBRR0L = (uint8_t) (BAUD_PRESCALLER);
    UCSR0B = (1 << RXEN0) | (1 << TXEN0);
    UCSR0C = (3 << UCSZ00);
}

void USART_send(unsigned char data) {
    while (!(UCSR0A & (1 << UDRE0)));
    UDR0 = data;
}

unsigned char USART_receive(void) {
    while (!(UCSR0A & (1 << RXC0)));
    return (unsigned char) UDR0;
}

void USART_putstring(char *StringPtr) {
    while (*StringPtr != 0x00) {
        USART_send((unsigned char) *StringPtr);
        StringPtr++;
    }
}

char String[] = "Hello world!!";

int main(void) {
    USART_init();
    while (1) {
        USART_putstring(String);
        _delay_ms(1000);
    }
    return 0;
}

If I try and listen to my serial port screen /dev/tty.wchusbserial141120 9600, only unicode nonsense comes back.
���

I am not quite sure what's the issue here.

Repeatedly send the character U non-stop and examine the TX waveform with an oscilloscope. If it's not 4800Hz you have a baud rate problem.

Might want to add the wiring. Might be missing something there.

Your program works as expected on an Uno (I would just add \r\n at the end of the message). How are you clocking your ATmega?

Do you have correct F_CPU in Makefile? Is the DIV8 fuse disabled?


text:
Arduino uno with microled library; draw shaped
I am really sorry for bothering you but i need help, again, with my arduino code. I am still learning so i make mistakes.
I am trying to draw shaped on i2c screen with Microled library. My code isn`t compiling, error is Unexpected declaration before { . That is one problem. I would also like to draw rectangle without edges, both empty and filled but i am struggling how to declare it, should i declare 4 lines or maybe display bitmap.
Anyway my code is here
#include <Arduino.h>
#include <Wire.h>
#include <MicroLCD.h>

LCD_SH1106 lcd; /* for SH1106 OLED module */
//LCD_SSD1306 lcd; /* for SSD1306 OLED module */

static const PROGMEM uint8_t smile[48 * 48 / 8] = {
0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xE0,0xF0,0xF8,0xF8,0xFC,0xFC,0xFE,0xFE,0x7E,0x7F,0x7F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x7F,0x7F,0x7E,0xFE,0xFE,0xFC,0xFC,0xF8,0xF8,0xF0,0xE0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xC0,0xF0,0xFC,0xFE,0xFF,0xFF,0xFF,0x3F,0x1F,0x0F,0x07,0x03,0x01,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x01,0x03,0x07,0x0F,0x1F,0x3F,0xFF,0xFF,0xFF,0xFE,0xFC,0xF0,0xC0,0x00,
0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x1F,0x1F,0x1F,0x3F,0x1F,0x1F,0x02,0x00,0x00,0x00,0x00,0x06,0x1F,0x1F,0x1F,0x3F,0x1F,0x1F,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,
0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xE0,0x00,0x00,0x30,0xF8,0xF8,0xF8,0xF8,0xE0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xE0,0xF8,0xF8,0xFC,0xF8,0x30,0x00,0x00,0xE0,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,
0x00,0x03,0x0F,0x3F,0x7F,0xFF,0xFF,0xFF,0xFC,0xF8,0xF0,0xE1,0xC7,0x87,0x0F,0x1F,0x3F,0x3F,0x3E,0x7E,0x7C,0x7C,0x7C,0x78,0x78,0x7C,0x7C,0x7C,0x7E,0x3E,0x3F,0x3F,0x1F,0x0F,0x87,0xC7,0xE1,0xF0,0xF8,0xFC,0xFF,0xFF,0xFF,0x7F,0x3F,0x0F,0x03,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x0F,0x1F,0x1F,0x3F,0x3F,0x7F,0x7F,0x7E,0xFE,0xFE,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFE,0xFE,0x7E,0x7F,0x7F,0x3F,0x3F,0x1F,0x1F,0x0F,0x07,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
};

static const PROGMEM uint8_t tick[16 * 16 / 8] =
{0x00,0x80,0xC0,0xE0,0xC0,0x80,0x00,0x80,0xC0,0xE0,0xF0,0xF8,0xFC,0x78,0x30,0x00,0x00,0x01,0x03,0x07,0x0F,0x1F,0x1F,0x1F,0x0F,0x07,0x03,0x01,0x00,0x00,0x00,0x00};

static const PROGMEM uint8_t cross[16 * 16 / 8] =
{0x00,0x0C,0x1C,0x3C,0x78,0xF0,0xE0,0xC0,0xE0,0xF0,0x78,0x3C,0x1C,0x0C,0x00,0x00,0x00,0x30,0x38,0x3C,0x1E,0x0F,0x07,0x03,0x07,0x0F,0x1E,0x3C,0x38,0x30,0x00,0x00};

void setup()
{
  delay(1000);
  delay(1000);
  lcd.clear();
  lcd.setCursor(40, 1);
  delay(500);
}

void line()
{
int x0 = 7; int y0 = 7;   // (x0,y0) = (7, 7)
int x1 = 42; int y1 = 24; // (x1,y1) = (42, 24)
oled.line(x0, y0, x1, y1);  // Draw a line from (x0,y0) to (x1,y1);
oled.display(); // Draw to the screen
}

void rectangle()
{
int x0 = 7; int y0 = 5;
int width = 24;
int height = 13;
oled.rect(x0, y0, width, height);
oled.display();
}

void filled()
{
oled.rectFill(7, 5, 35, 5); // Fill a rectangle from (7, 5) to (42, 10)
int radius = 13;
}

void circle()
oled.circle(LCDWIDTH/2, LCDHEIGHT/2, radius);
oled.display(); // Draw to the screen

oled.circleFill(42, 20, 7); // Fill a circle, 7 radius, centered at (42, 20)
oled.display(); // Draw to the screen
}

void loop()
{
  line();
  rectangle();
  filled();
  circle();
}
void printTitle(String title, int font)
{
  int middleX = oled.getLCDWidth() / 2;
  int middleY = oled.getLCDHeight() / 2;

  oled.clear(PAGE);
  oled.setFontType(font);
  oled.setCursor(middleX - (oled.getFontWidth() * (title.length()/2)),
                 middleY - (oled.getFontWidth() / 2));
  oled.print(title);
  oled.display();
  delay(1500);
  oled.clear(PAGE);
}

Full error is this
Arduino: 1.8.6 (Linux), Board: "Arduino/Genuino Uno"

In file included from /home/lutherus/scripts/sketch_nov14a/sketch_nov14a.ino:3:0:
/home/lutherus/builds/Arduino/build/linux/work/libraries/MicroLCD/MicroLCD.h:38:43: warning: '__progmem__' attribute ignored [-Wattributes]
     virtual void draw(const PROGMEM byte* buffer, byte width, byte height) {}
                                           ^
In file included from /home/lutherus/scripts/sketch_nov14a/sketch_nov14a.ino:3:0:
/home/lutherus/builds/Arduino/build/linux/work/libraries/MicroLCD/MicroLCD.h:67:35: warning: '__progmem__' attribute ignored [-Wattributes]
     void draw(const PROGMEM byte* buffer, byte width, byte height);
                                   ^
/home/lutherus/builds/Arduino/build/linux/work/libraries/MicroLCD/MicroLCD.h:84:35: warning: '__progmem__' attribute ignored [-Wattributes]
     void draw(const PROGMEM byte* buffer, byte width, byte height);
                                   ^
/home/lutherus/scripts/sketch_nov14a/sketch_nov14a.ino: In function 'void line()':
sketch_nov14a:39: error: 'oled' was not declared in this scope
 oled.line(x0, y0, x1, y1);  // Draw a line from (x0,y0) to (x1,y1);
 ^
/home/lutherus/scripts/sketch_nov14a/sketch_nov14a.ino: In function 'void rectangle()':
sketch_nov14a:48: error: 'oled' was not declared in this scope
 oled.rect(x0, y0, width, height);  // Draw a rectange from (7,5) to (31,18)
 ^
/home/lutherus/scripts/sketch_nov14a/sketch_nov14a.ino: In function 'void filled()':
sketch_nov14a:54: error: 'oled' was not declared in this scope
 oled.rectFill(7, 5, 35, 5); // Fill a rectangle from (7, 5) to (42, 10)
 ^
/home/lutherus/scripts/sketch_nov14a/sketch_nov14a.ino: At global scope:
sketch_nov14a:61: error: expected initializer before 'oled'
 oled.circle(LCDWIDTH/2, LCDHEIGHT/2, radius);
 ^
sketch_nov14a:62: error: 'oled' does not name a type
 oled.display(); // Draw to the screen
 ^
sketch_nov14a:64: error: 'oled' does not name a type
 oled.circleFill(42, 20, 7); // Fill a circle, 7 radius, centered at (42, 20)
 ^
sketch_nov14a:65: error: 'oled' does not name a type
 oled.display(); // Draw to the screen
 ^
sketch_nov14a:67: error: expected declaration before '}' token
 }
 ^
exit status 1
'oled' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Is that really the full text of the error?  I've never seen that one before.  I would think that if you want someone else to find the problem, the exact error message would be helpful.  Don't try to paraphrase it because you cut out vital information.  I'm sure the compiler told you exactly what line it found a problem on.  Start by looking there.

I notice that the circle function is missing an opening brace.  Not sure if that's the one that caused the error you see now but it definitely needs to be fixed.