Stuck on a "unqualified ID" code problem

I’m sure the issue is looking me right in the face here, but I keep getting the following error. Just getting started on this and can’t make it past this part. I’m new at this any help is much appreciated. I’m sure I’ll find more ing here as I go along.

EMT

Arduino: 1.8.10 (Mac OS X), Board: “Arduino MKR WiFi 1010”

3_mcp9808_blynk.2:27:1: error: expected unqualified-id before ‘{’ token
{
^

exit status 1
expected unqualified-id before ‘{’ token

#include <Wire.h>
#include "Adafruit_MCP9808.h"
#include <WiFi101.h>
#include <BlynkSimpleWiFiShield101.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "pSHTQXXXXXXXXXXXXXXXXX1thIKsTwt";

// Set password to "" for open networks.
char ssid[] = "XXXXXXXX 213";
char pass[] = "XXXXXXXXXX";



// Create the MCP9808 temperature sensor object
Adafruit_MCP9808 tempsensor_1 = Adafruit_MCP9808();
Adafruit_MCP9808 tempsensor_2 = Adafruit_MCP9808();
Adafruit_MCP9808 tempsensor_3 = Adafruit_MCP9808();

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

  Blynk.begin(auth, ssid, pass);
}

{                                                                    *This is the spot in the sketch I have the problem*
  // Make sure the sensor is found, you can also pass in a different i2c //
  (!tempsensor_1.begin(0x18)) {
    if (!tempsensor_2.begin(0x19))
      if (!tempsensor_3.begin(0x1A))

      }
  void loop() {


    // Read and print out the temperature, then convert to *F
    float c1 = tempsensor_1.readTempC();
    float c2 = tempsensor_2.readTempC();
    float c3 = tempsensor_3.readTempC();
    float f1 = c1 * 9.0 / 5.0 + 32;
    float f2 = c2 * 9.0 / 5.0 + 32;
    float f3 = c3 * 9.0 / 5.0 + 32;
    Blynk.virtualWrite(V5, f1);
    Blynk.virtualWrite(V6, f2);
    Blynk.virtualWrite(V7, f3);

  }```

you need to write the code correctly.

where did you copy the code from? make sure it is correctly bracketed.

Don’t recall where I got it, I do know it worked fine with just two sensors then ran into issues when I added the third. So it’s a bracketing issue? I tried several different permutations.

keep trying

you don’t seem to have added the third sensor properly.

but since you put typing in you code to point out where the problem is - we cant work out how.

[Unformatted code removed by moderator]

{
// Make sure the sensor is found, you can also pass in a different i2c
if (!tempsensor_1.begin(0x18)) 
if (!tempsensor_2.begin(0x19))
if (!tempsensor_3.begin(0x1A))
}

see if that allows it to compile?

i asked where you got it from because that section of code is a bit weird to me .

plus you don’t even have blynk.run() in your loop so not sure if that is actually your full code?

That fix got me farther down the sketch, thanks. Working on other issues down the line

1 Like