My code has an issue cant locate

This is code that I am having issues with. I’m new to this and this code is for a Temp Humid sensor display on a I2C display.
Error that I am getting is the following.
Arduino: 1.8.19 (Windows 10), Board: “Arduino Uno”

I:\Download folder main\OLED+Temp+Humid+Meter+-+DroneBot+Workshop\oled-temp-humid-meter\oled-temp-humid-meter.ino: In function 'void setup()':

oled-temp-humid-meter:34:14: error: a function-definition is not allowed here before '{' token

 void setup() {


oled-temp-humid-meter:43:24: error: a function-definition is not allowed here before '{' token

 void displayTempHumid(){


oled-temp-humid-meter:70:13: error: a function-definition is not allowed here before '{' token

 void loop() {


oled-temp-humid-meter:73:1: error: expected '}' at end of input



exit status 1

a function-definition is not allowed here before '{' token

end of error
Thanks to all

  OLED Temperature and Humidity Meter
  Displays results on 128 x 64 OLED display
  Uses AM2320 I2C Temperature and Humidity sensor
  Uses Adafruit SSD1306 OLED Library
  Uses Adafruit AM2320 Library
  Uses Adafruit GFX Graphics Library
  DroneBot Workshop 2019

// Include Wire Library for I2C
#include "Wire.h"

// Include Adafruit Graphics & OLED libraries
#include "Adafruit_GFX.h"
#include "Adafruit_SSD1306.h"

// Include Adafruit AM2320 Temp Humid Library
#include "Adafruit_AM2320.h"

// Reset pin not used but needed for library
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

// Define object am2320
Adafruit_AM2320 am2320 = Adafruit_AM2320();

void setup() {
  // Start Wire library for I2C
void setup() {
  // initialize OLED with I2C addr 0x78
  display.begin(SSD1306_SWITCHCAPVCC, 0x78);
  // Initialize Temp & Humid Sensor

void displayTempHumid(){
  // Delay to allow sensor to stabalize

  // Read Humidity
  float h = am2320.readHumidity();
  // Read temperature as Celsius
  float t = am2320.readTemperature();

  // Clear the display
  //Set the color - always use white despite actual display color
  //Set the font size
  //Set the cursor coordinates
  display.print("DroneBot Workshop");
  display.print("Humidity:    "); 
  display.print(" %");
  display.print("Temperature: "); 
  display.print(" C");
void loop() {

was it intentional? I am not familiar but this seems weird

1 Like

Hi and thanks for the reply.
The code is from the Adafruit SSD1306 Library. I was following a Youtube video from DroneBot workshop. Its supposed to use Temp Humid sensor and the results are to be sent to an Oled Display. I ran another Arduino code on the setup and I know the other code is working but for some reason I get the errors specified. I tried to contact the person from Droneworkshop but no response. like I mentioned I’m new to this so any help is appreciated.

Ehm ok, here is some help - look again at the code ilenia posted. This wasn’t just for fun, but because there are two key issues there.
The minor one is having the same function-name twice, which is a sign something of this is wrong.
The major issue is the fact you never closed the first “{”.

Missing brackets or generally not properly ending commands is a common issue and hard to figure out because of how code is written by the interpreter/compiler.

Anyway, if you actually read the error messages, they complain about “function-definition”. As you never closed the first bracket, all following functions are WITHIN THE FIRST FUNCTION. And it sounds like you are not allowed to define nested functions.

Thanks for the reply. I will check those issues out. Greatly appreciated


Thanks so much I figured it out with your help. Gratitude


Figured it out with your help Gratitude.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.