Ardino UNO Sketch too long

I have preapared the code for a smart device which did good for Arduno met a bit shows low space (107%memory required) for UNO
HOW TO TACKLE IT?
MY PREFRANCE IS Using the Arduino UNO

//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTEthernet.h>

#include <EmonLib.h>
EnergyMonitor emon1;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “2605f5a0-b19f-11e6-9ce1-1904e26cb7a0”;
char password = “”;
char clientID = “e5b06cd0-cf65-11e6-ae8c-f90e83be502a”;

unsigned long lastMillis = 0;

void setup() {
Serial.begin(9600);
Cayenne.begin(username, password, clientID);
emon1.voltage(2, 234, 1.7); // Voltage: input pin, calibration, phase_shift
emon1.current(1, 19.9); // Current: input pin, calibration.
}

void loop() {
Cayenne.loop();
emon1.calcVI(20,2000); // Calculate all. No.of half wavelengths (crossings), time-out
float pinVoltage ;
pinVoltage =emon1.realPower ;
Cayenne.virtualWrite(1, pinVoltage);
pinVoltage = emon1.apparentPower;
Cayenne.virtualWrite(2, pinVoltage);
pinVoltage = emon1.Vrms;
Cayenne.virtualWrite(3, pinVoltage);
pinVoltage = emon1.Irms;
Cayenne.virtualWrite(4, pinVoltage);
pinVoltage =emon1.powerFactor;
Cayenne.virtualWrite(5, pinVoltage);!
Serial.print(“Posting”);
delay(6000);

What includes are you using? Didn’t come through.

Craig

include Ethernet Include SPIInclude emonCeyeene

Hi @HamnaBazmi,

First thing is I am trying to determine what internet connection you will be using, then I can help you with a suitable sketch.

Looks like you are using the MQTT code, which is quite large and not suitable for the UNO.

If you go to cayenne.mydevices.com, and add an Arduino microcontroller, then select your ethernet or wifi shield, you will be presented with a suitable sketch. If you are using a Wifi101 shield, that library is also quite large and not really suitable for use with an Uno plus the Cayenne libraries and your energy monitor code.

Let me know what Internet connection you are using and I can help guide you.

Cheers,

Craig

Thanks @Leader for your intrest
I am using the Ethernet shield after getting the code as per you described I have to invoke Ethernet and Spi libraries to make my code run
Frther as it is energy monitoring so emon library takes raw data from analog channels and regimes data as per my requirement
I’m short code is at its least space UNI HAVE to increase I memory for me😎

What ethernet shield are you using? There are many?

Craig

1 Like

Winzet 5100

What about Dr slot will it help me if I burn the code as a file in it somthing like that

I would suggest (if you need more RAM) that you use the ESP12-e. I’m a big fan of the ESP12-e. You have SPI bus on this device.

1 Like

@HamnaBazmi,

Try this. Only 70% resources used:

/*
Cayenne Ethernet Example

This sketch connects to the Cayenne server using an Arduino Ethernet Shield W5100
and runs the main communication loop.

The Cayenne Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.

Steps:
1. Set the token variable to match the Arduino token from the Dashboard.
2. Compile and upload this sketch.

For Cayenne Dashboard widgets using digital or analog pins this sketch will automatically
send data on those pins to the Cayenne server. If the widgets use Virtual Pins, data
should be sent to those pins using virtualWrites. Examples for sending and receiving
Virtual Pin data are under the Basics folder.
*/

//#define CAYENNE_DEBUG         // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneEthernet.h>

#include "EmonLib.h"                   // Include Emon Library

EnergyMonitor emon1;


// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "YOUR TOKEN";

unsigned long lastMillis = 0;

void setup()
{
  Serial.begin(9600);
  Cayenne.begin(token);

  //load calibration factors into energy monitor
  emon1.voltage(2, 234, 1.7); // Voltage: input pin, calibration, phase_shift
  emon1.current(1, 19.9); // Current: input pin, calibration. 
}



void loop()
{
  Cayenne.run();

  //Take a power measurment every six seconds
  if (millis() - lastMillis > 6000) {

    lastMillis = millis();

    emon1.calcVI(20,2000); // Calculate all. No.of half wavelengths (crossings), time-out
  }
}

CAYENNE_OUT(V1)
{
   //update dashboard with last real power
   Cayenne.virtualWrite(1, emon1.realPower);
}

CAYENNE_OUT(V2)
{
   //update dashboard with last apparent power
   Cayenne.virtualWrite(2, emon1.apparentPower);
}

CAYENNE_OUT(V3)
{
   //update dashboard with last AC voltage
   Cayenne.virtualWrite(3, emon1.Vrms);
}

CAYENNE_OUT(V4)
{
   //update dashboard with last AC current
   Cayenne.virtualWrite(4, emon1.Irms);
}

CAYENNE_OUT(V5)
{
   //update dashboard with last power factor
   Cayenne.virtualWrite(5, emon1.powerFactor);
}

Cheers,

Craig

2 Likes

Thankyou so much for your kind reply…will try it ASAP