# My code has an issue cant locate

**URL:** <https://forum.freecodecamp.org/t/my-code-has-an-issue-cant-locate/492244>\
**Category:** General\
**Created:** [January 12, 2022, 2:52pm UTC](https://forum.freecodecamp.org/t/my-code-has-an-issue-cant-locate/492244 "2022-01-12T14:52:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![renoman2011](https://avatars.discourse-cdn.com/v4/letter/r/ce73a5/32.png) [@renoman2011](https://forum.freecodecamp.org/u/renoman2011)\
**Post date:** [January 12, 2022, 2:52pm UTC](https://forum.freecodecamp.org/t/my-code-has-an-issue-cant-locate/492244/1 "2022-01-12T14:52:12Z")

</div>

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”

```auto
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

```auto
/*
  OLED Temperature and Humidity Meter
  oled-temp-humid-meter.ino
  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
  https://dronebotworkshop.com
*/

// 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
  Wire.begin();
void setup() {
  
  // initialize OLED with I2C addr 0x78
  display.begin(SSD1306_SWITCHCAPVCC, 0x78);
  
  // Initialize Temp & Humid Sensor
  am2320.begin();
}

void displayTempHumid(){
  // Delay to allow sensor to stabalize
  delay(2000);

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

  // Clear the display
  display.clearDisplay();
  //Set the color - always use white despite actual display color
  display.setTextColor(WHITE);
  //Set the font size
  display.setTextSize(1);
  //Set the cursor coordinates
  display.setCursor(0,0);
  display.print("DroneBot Workshop");
  display.setCursor(0,10); 
  display.print("Humidity: "); 
  display.print(h);
  display.print(" %");
  display.setCursor(0,20);
  display.print("Temperature: "); 
  display.print(t);
  display.print(" C");
}
void loop() {
  displayTempHumid();
  display.display();
}

```

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 12, 2022, 2:59pm UTC](https://forum.freecodecamp.org/t/my-code-has-an-issue-cant-locate/492244/2 "2022-01-12T14:59:32Z")

</div>

> [@renoman2011](#):
>
> ```auto
> void setup() {
> // Start Wire library for I2C
> Wire.begin();
> void setup() {
> 
> ```

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

---

<div class="post-metadata">

**Author:** ![renoman2011](https://avatars.discourse-cdn.com/v4/letter/r/ce73a5/32.png) [@renoman2011](https://forum.freecodecamp.org/u/renoman2011)\
**Post date:** [January 12, 2022, 3:25pm UTC](https://forum.freecodecamp.org/t/my-code-has-an-issue-cant-locate/492244/3 "2022-01-12T15:25:57Z")

</div>

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.  
thanks

---

<div class="post-metadata">

**Author:** ![Jagaya](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jagaya/32/202277_2.png) [@Jagaya](https://forum.freecodecamp.org/u/Jagaya)\
**Post date:** [January 12, 2022, 3:37pm UTC](https://forum.freecodecamp.org/t/my-code-has-an-issue-cant-locate/492244/4 "2022-01-12T15:37:41Z")

</div>

> [@renoman2011](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![renoman2011](https://avatars.discourse-cdn.com/v4/letter/r/ce73a5/32.png) [@renoman2011](https://forum.freecodecamp.org/u/renoman2011)\
**Post date:** [January 12, 2022, 4:05pm UTC](https://forum.freecodecamp.org/t/my-code-has-an-issue-cant-locate/492244/5 "2022-01-12T16:05:52Z")

</div>

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

Ron

---

<div class="post-metadata">

**Author:** ![renoman2011](https://avatars.discourse-cdn.com/v4/letter/r/ce73a5/32.png) [@renoman2011](https://forum.freecodecamp.org/u/renoman2011)\
**Post date:** [January 12, 2022, 4:32pm UTC](https://forum.freecodecamp.org/t/my-code-has-an-issue-cant-locate/492244/6 "2022-01-12T16:32:07Z")

</div>

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

ron

---

<div class="post-metadata">

**Author:** ![renoman2011](https://avatars.discourse-cdn.com/v4/letter/r/ce73a5/32.png) [@renoman2011](https://forum.freecodecamp.org/u/renoman2011)\
**Post date:** [January 12, 2022, 4:32pm UTC](https://forum.freecodecamp.org/t/my-code-has-an-issue-cant-locate/492244/7 "2022-01-12T16:32:47Z")

</div>

Figured it out with your help Gratitude.  
ron

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [July 14, 2022, 4:33am UTC](https://forum.freecodecamp.org/t/my-code-has-an-issue-cant-locate/492244/8 "2022-07-14T04:33:02Z")

</div>

Closed on July 14, 2022, 4:33am UTC

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