Atmel 2560 Sensor Circuit

Hello,

I am using atmel 2560 chip on a circuit with LCD and Bosch BME680 Sensor and LoRA Module as per below links:

LCD Touch Screen:

LoRA Module:
https://www.digikey.com/product-detail/en/adafruit-industries-llc/3072/1528-1667-ND/6005357

BME Sensor
https://www.digikey.com/product-detail/en/bosch-sensortec/BME680/828-1077-1-ND/7401321

I am powering the circuit with this XP Power AC to DC converter. It is 10W 5V.

https://www.digikey.com/product-detail/en/xp-power/ECE10US05/1470-1115-ND/4487496

I am pulling out the GND, TX, RX, Reset Pins in order to be able to upload sketches to my MCU. I have an issue that when I connect the A/C Power to the power supply the circuit does not start (LCD stays black). When I connect GND, TX, RX, Reset Pins to external Arduino Chip that I am using as programmer the circuit starts to run correctly. Sometimes it continue to work after I remove the external pins but most of the time the LCD freezes up as soon as I remove external Pins.

Is the power supply does not provide enough power to the circuit? What else could be wrong?

Regards,
Ehab Zaky

ehabzaky:
I am using atmel 2560 chip on a circuit

Why does your Title say Atmega 328P?

Which is correct ?

...R

Delta_G:
You must have made some mistake. Talk to someone who can see the code and the wiring or show the code and wiring to someone who knows what they're doing an perhaps they can spot your mistake.

I would have thought that doing that here would have made sense. Not sure why you aren't asking us to take a look or what you think we can tell without seeing anything.

Thank you for your reply. Sorry, I was thinking somebody could help about type and power of AC DC converter as the circuit is working when I connect external programmer connected to PC.

Circuit diagram is attached with this post.

Code is here as well

#include <SPI.h>
#include <Wire.h>
#include "scstftlib.h"

// BME680 Includes
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"

// LCD Includes
#include <stdint.h>
#include "Adafruit_GFX.h"
#include "Adafruit_RA8875.h"
#include <Fonts/FreeSerifItalic24pt7b.h>
#include <Fonts/FreeSansBold24pt7b.h>


// LoRA
#include <RH_RF95.h>

#define RFM95_CS   53
#define RFM95_RST  19
#define RFM95_INT  18 //3 on old design
#define RFM95_EN   44
#define RF95_FREQ  915.0
RH_RF95 rf95(RFM95_CS, RFM95_INT);
int16_t packetnum = 0;  // packet counter, we increment per xmission

// BME680
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME680 bme; // I2C Communication with BME680

// Thermostat Relays
const int HeatPin  = 12;
const int CoolPin  = 11;
const int FanPin   = 10;

float TemperatureSetting = 20.0;
float CurrentTemperature = 0;
float CurrentHumidity = 0;
float CurrentPressure = 0;

#define SensorUpdateInterval 10000

void setup()
{
  // Initializing Libraries
  //Serial.begin(9600);
  InitializeSCSTFTLibrary();
  delay(1000);
  Wire.begin();        // join i2c bus (address optional for master)

  // Initialize Relay Pins
  pinMode (FanPin, OUTPUT);
  pinMode (CoolPin, OUTPUT);
  pinMode (HeatPin, OUTPUT);
  digitalWrite(FanPin, HIGH);
  digitalWrite(CoolPin, HIGH);
  digitalWrite(HeatPin, HIGH);
  
  // Initializing BME680 Sensor
  if (bme.begin())
  {
    // Set up oversampling and filter initialization
    bme.setTemperatureOversampling(BME680_OS_8X);
    bme.setHumidityOversampling(BME680_OS_2X);
    bme.setPressureOversampling(BME680_OS_4X);
    bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
    bme.setGasHeater(320, 150); // 320*C for 150 ms
  }
  else
  {
    //Serial.println("Could not find a valid BME680 sensor, check wiring!");
  }

  // Initializing Screen Contents
  tft.fillRect(0, 0, 267, 240, RA8875_RED);

  UpdateTemperatureSetting(0);
  if (bme.performReading())
  {
    DisplayCurrentTemperature(bme.temperature);
    DisplayCurrentHumidity(bme.humidity);
  }
  
  randomSeed(analogRead(0));

  // Initializing LoRA
  pinMode(RFM95_RST, OUTPUT);
  digitalWrite(RFM95_RST, HIGH);
  // manual reset
  digitalWrite(RFM95_RST, LOW);
  delay(10);
  digitalWrite(RFM95_RST, HIGH);
  delay(10);
  
  if (rf95.init())
  {
    //Serial.println("LoRa radio init OK!");
    // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
    if (!rf95.setFrequency(RF95_FREQ)) {
      //Serial.println("setFrequency failed");
      //while (1);
    }
    rf95.setTxPower(5, false);  
  }
  else
  {
    //Serial.println("LoRa radio init failed");
    //while (1);
  }
}

void loop()
{
  uint32_t thisSensorReadTime = millis();
  static uint32_t lastSensorReadTime = thisSensorReadTime;
  
  if ((thisSensorReadTime - lastSensorReadTime) > SensorUpdateInterval)
  {
    lastSensorReadTime = thisSensorReadTime;
    if (bme.performReading())
    {
      DisplayCurrentTemperature(bme.temperature);
      DisplayCurrentHumidity(bme.humidity);
    }
    else
    {
      //Serial.println("Failed to perform reading :(");
      return;
    }
  }

  int testCount = 0;
  TouchLocation myTouchLocations[5];
  GetTouchEvent(&testCount, myTouchLocations);
  if (testCount > 0)
  {
    if (myTouchLocations[0].x > 40 && myTouchLocations[0].x < 100 && myTouchLocations[0].y > 300 && myTouchLocations[0].y < 350 && TemperatureSetting < 30)
    {
      UpdateTemperatureSetting(0.5);
    }
    if (myTouchLocations[0].x > 40 && myTouchLocations[0].x < 100 && myTouchLocations[0].y > 370 && myTouchLocations[0].y < 420 && TemperatureSetting > 16)
    {
      UpdateTemperatureSetting(-0.5);
    }
  }


  // LoRA
  //Serial.println("Sending to rf95_server");
  // Send a message to rf95_server
  
  char radiopacket[20] = "Hello World #      ";
  itoa(packetnum++, radiopacket+13, 10);
  //Serial.print("Sending "); Serial.println(radiopacket);
  radiopacket[19] = 0;
  
  //Serial.println("Sending..."); delay(10);
  rf95.send((uint8_t *)radiopacket, 20);
 
  //Serial.println("Waiting for packet to complete..."); delay(10);
  rf95.waitPacketSent();
  // Now wait for a reply
  uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
  uint8_t len = sizeof(buf);
 
  //Serial.println("Waiting for reply..."); delay(10);
  if (rf95.waitAvailableTimeout(1000))
  { 
    // Should be a reply message for us now   
    if (rf95.recv(buf, &len))
    {
      //Serial.print("Got reply: ");
      //Serial.println((char*)buf);
      //Serial.print("RSSI: ");
      //Serial.println(rf95.lastRssi(), DEC);    
    }
    else
    {
      //Serial.println("Receive failed");
    }
  }
  else
  {
    //Serial.println("No reply, is there a listener around?");
  }
}

Robin2:
Why does your Title say Atmega 328P?

Which is correct ?

...R

Sorry by mistake. The correct is 2560. I updated the title.

To make it easy for people to help you please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

Your code is too long for me to study quickly without copying to my text editor. The text editor shows line numbers, identifies matching brackets and allows me to search for things like all instances of a particular variable or function.

Also please use the AutoFormat tool to indent your code for easier reading.

...R

Robin2:
To make it easy for people to help you please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

Your code is too long for me to study quickly without copying to my text editor. The text editor shows line numbers, identifies matching brackets and allows me to search for things like all instances of a particular variable or function.

Also please use the AutoFormat tool to indent your code for easier reading.

...R

Post updated thanks.

Image from Reply #3 so we don't have to download it. See this Simple Image Guide

...R

That sort of diagram may have all the info needed to build the circuit but it is very inconvenient for trouble shooting.

Can you make a pencil drawing showing how the relevant connections between the devices are made - just the connections that are relevant to the problem. Then post a photo of the drawing.

...R