Arduino unresponsive

Hello all,

I have a problem with my Arduino mega 2560(clone); I’ve written a program, and yesterday it ran successfully all day, but now it won’t respond anymore after uploading. Even when I upload a different program (an I2C_scan program I found on the internet), it does upload, but it stops giving output to the serial monitor anymore. I suspect it’s a memory issue and included the freemem() function, but since it won’t run I can’t check what it does.

I hope this is the right place to ask, if it’s a problem with the hardware I’ll have to go to a different place.

I’m using Ubuntu 14.14, and IDE 1.8.2

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "Adafruit_VCNL4010.h"

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

Adafruit_VCNL4010 vcnl;

#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
   #define Serial SerialUSB

const float a = 21.59357;
const float b = -0.00018;
const float c = 13.71153;
const float d = -0.00002;

void setup() {
  // initialize OLED with the I2C addr 0x3D (for the 128x64)
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  

  // Clear the OLED buffer.

 //Initialize VCNL4010 sensor
  Serial.println("VCNL4010 test");

  if (! vcnl.begin()){
    Serial.println("Sensor not found :(");
    while (1);
  Serial.println("Found VCNL4010");

// Freemem() function to return the number of bytes free in RAM      
extern int  __bss_end; 
extern int  *__brkval; 
int freemem()
int free_memory; 
if((int)__brkval == 0) 
   free_memory = ((int)&free_memory) - ((int)&__bss_end); 
   free_memory = ((int)&free_memory) - ((int)__brkval); 
return free_memory; 

void loop() {
  // put your main code here, to run repeatedly:
  float prox = vcnl.readProximity();

  //Debug formula
//  Serial.print("proximity= ");
//  Serial.println(prox,5);
//  Serial.print("b*prox=");
//  Serial.print((b*prox),5);
//  Serial.print(", ");
//  Serial.print("d*prox=");
//  Serial.println((d*prox),5);
//  Serial.print("e^(b*prox)=");
//  Serial.print(exp(b*prox),5);
//  Serial.print(", ");
//  Serial.print("e^(d*prox)=");
//  Serial.println(exp(d*prox),5);
//  Serial.print("a*e^(b*prox)=");
//  Serial.print(a*exp(b*prox),5);
//  Serial.print(", ");
//  Serial.print("c*e^(d*prox)=");
//  Serial.println(c*exp(d*prox),5);

  //Calculate Distance using proximity value from sensor
  float dist = a*exp(b*prox)+c*exp(d*prox);

  //Display proximity value and distance on OLED
  display.print("Prx: ");
  display.print("Dst: ");

Make sure the baud rate menu at the bottom right corner of the Serial Monitor window is set to 9600.

Thank you. I checked, it's set to 9600.

If all fails, I try another computer.

Even when I upload a different program (an I2C_scan program I found on the internet), it does upload, but it stops giving output to the serial monitor anymore.

Try a simple program that just prints "Hello World" to the Serial Monitor every second.


Can you test with the blink example so you can be sure your sketch is being uploaded?

Sorry for all the trouble, it appears it was the sensor that was giving hiccups. And the I2C program also called on that. When I disconnect it, everything works fine again.