Solving Error Code " expected unqualified-id before string constant"

Hi,
I have tried many things, checked the accolades, and can’t find the problem.
I use an Arduino Due, with a u8g2 SH1106 oled 128x64, with a INA219 current sensor module.
I intend to get the measured readings on the oled. But It wont compile.

Could someone please look at the code, and help?

Code:

//    Copyright[free]
//    < Free for all to benefit from. >

void setup() {
// INCLUDE  LIBRARies:
#include <LiquidCrystal.h>
  #include <U8g2lib.h>                // OLED
#include <U8x8lib.h>                 // OLED
#include <Adafruit_INA219.h>        // voltage sensor

  #include <Adafruit_INA219.h>;   // VOLTage SENSor
  #include <Wire.h>;             //  I2c communication library

                          // oled constructor: no reset pin
    u8g2_Ssh1106_128X64_noname_1_hw_i2c u8g2(u8g2_r0, u8x8_pin_none);
                          // set font for oled display:
    u8g2.setFont(u8g2_xxx_xe);


    Adafruit_INA219 ina219_A;      // set name
                           // Adafruit_INA219 ina219_B(0x41);
                           // for SECOND BOARD, CHANGE SOLDER PAD sets ADRESS
    ina219_A.begin();
                          // Initialize first board (default address 0x40)
                          //  ina219_B.begin();
                          // Initialize second board with the address 0x41
                }

void loop()   {
                                  // set floating integers
    float shuntvoltage = 0;
    float busvoltage   = 0;
    float current_mA   = 0;
    float loadvoltage  = 0;

                                   // measurements from ina219 i2c
    shuntvoltage = ina219.getShuntVoltage_mV();
    busvoltage   = ina219.getBusVoltage_V();
    current_mA   = ina219.getCurrent_mA();
    loadvoltage  = busvoltage + (shuntvoltage / 1000);
    power = (loadvoltage * current_mA);

                                    // print data
u8g2.drawStr(0, 15, "Bus Voltage:  ");
        u8g2.drawStr(busvoltage);
        u8g2.drawStr(" V");
u8g2.drawStr(0, 30, "Shunt Voltage:");
        u8g2.drawStr(shuntvoltage);
        u8g2.drawStr(" mV");
u8g2.drawStr(0, 45, "Load Voltage: ");
        u8g2.drawStr(loadvoltage);
        u8g2.drawStr(" V");
u8g2.drawStr(0, 60, "Current:      ");
        u8g2.drawStr(current_mA);
        u8g2.drawStr(" mA");
u8g2.drawStr(0, 75, "power:        ");
        u8g2.drawStr(power);
        u8g2.drawStr(" mW");
            }

error code:

Arduino: 1.8.11 (Windows 10), Board: "Arduino Due (Programming Port)"

In file included from C:\Users\ibona\Documents\Arduino\libraries\U8g2\src/U8x8lib.h:45:0,

                 from C:\Users\ibona\Documents\Arduino\libraries\U8g2\src/U8g2lib.h:50,

                 from C:\Users\ibona\Documents\Arduino\BASIC_SKETCH_error\BASIC_SKETCH_error.ino:7:

C:\Users\ibona\Documents\Arduino\libraries\U8g2\src/clib/u8x8.h: In function 'void setup()':

C:\Users\ibona\Documents\Arduino\libraries\U8g2\src/clib/u8x8.h:124:8: error: expected unqualified-id before string constant

 extern "C" {

        ^

BASIC_SKETCH_error:59:13: error: expected '}' at end of input

             }

             ^

exit status 1
expected '}' at end of input

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

"C:\Users\ibona\Documents\Arduino\libraries\U8g2\src/clib/u8x8.h:124:8: error: expected unqualified-id before string constant

extern “C” {
"
Is probably the cause.

Thank you!

(deleted)

Thanks spycatcher2k. I missed that one, but problem stays the same. "expected unqualified-id before string constant"

I don't know much about constructors, but can you have a comment inside one?

// oled constructor:
   U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

It seems it can be used, evanmars. I removed the comment, and the error code stayed the same

error: expected unqualified-id before string constant

extern "C" {

Move #include statements to outside of setup()

arduino_new: Move #include statements to outside of setup()

I have no clue what you are saying here. Makes no sense at all. What do you suggest?

(deleted)

if I do that, I get even more error codes " not declared"

Arduino: 1.8.11 (Windows 10), Board: "Arduino Due (Programming Port)"

C:\Users\ibona\Documents\Arduino\BASIC_SKETCH_error\BASIC_SKETCH_error.ino: In function 'void setup()':

BASIC_SKETCH_error:6:4: error: 'U8G2_SH1106_128X64_NONAME_1_HW_I2C' was not declared in this scope

    U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

    ^

BASIC_SKETCH_error:6:39: error: expected ';' before 'u8g2'

    U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

                                       ^

BASIC_SKETCH_error:8:4: error: 'u8g2' was not declared in this scope

    u8g2.setFont(u8g2_xxx_xe);

    ^

BASIC_SKETCH_error:8:17: error: 'u8g2_xxx_xe' was not declared in this scope

    u8g2.setFont(u8g2_xxx_xe);

                 ^

BASIC_SKETCH_error:11:4: error: 'Adafruit_INA219' was not declared in this scope

    Adafruit_INA219 ina219_A; // set name

    ^

BASIC_SKETCH_error:11:20: error: expected ';' before 'ina219_A'

    Adafruit_INA219 ina219_A; // set name

                    ^

BASIC_SKETCH_error:13:3: error: 'ina219_A' was not declared in this scope

   ina219_A.begin();  // Initialize first board (default address 0x40)

   ^

C:\Users\ibona\Documents\Arduino\BASIC_SKETCH_error\BASIC_SKETCH_error.ino: In function 'void loop()':

BASIC_SKETCH_error:31:18: error: 'ina219' was not declared in this scope

   shuntvoltage = ina219.getShuntVoltage_mV();

                  ^

BASIC_SKETCH_error:35:3: error: 'power' was not declared in this scope

   power = loadvoltage * current_mA ;

   ^

BASIC_SKETCH_error:38:4: error: 'u8g2' was not declared in this scope

    u8g2.drawStr(0,15,"Bus Voltage:   "); u8g2.drawStr(busvoltage);   u8g2.drawStr(" V");

    ^

exit status 1
'U8G2_SH1106_128X64_NONAME_1_HW_I2C' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
  float shuntvoltage = 0;
  float busvoltage   = 0;
  float current_mA   = 0;
  float loadvoltage  = 0;

//measurements
  shuntvoltage = ina219.getShuntVoltage_mV();
  busvoltage   = ina219.getBusVoltage_V();
  current_mA   = ina219.getCurrent_mA();
  loadvoltage  = busvoltage + (shuntvoltage / 1000);
  power = loadvoltage * current_mA

Makes no sense at all. (and is missing a semicolon - perhaps you could recycle the unwanted one here #include <wire.h>;)

TheMemberFormerlyKnownAsAWOL: ```



Makes no sense at all.;[/code])

Ah! you also don't get it. Thanks.

EVOSTARS:
Ah! you also don’t get it. Thanks.

Why initialise a bunch of variables to zero, then assign a new set of values?
That’s what I don’t get (unless you’re being paid by the LOC)

Also, sp. “Wire.h”

TheMemberFormerlyKnownAsAWOL: Why initialise a bunch of variables to zero, then assign a new set of values?

thanks, and I updated the code on first message

EVOSTARS:
thanks, and I updated the code on first message

Well, that was a dumb thing to do.
What did you change?
Now the rest of the thread doesn’t make sense.

No more errors. it all works.
topic can be closed
error was due to beginners virus

//INCLUDE  LIBRARies:
  #include <U8g2lib.h> // OLED
  #include <Adafruit_INA219.h> //VOLT sensor
  #include <wire.h> // i2C


// oled constructor: (rotation, [reset [, clock, data]]) 
//                    [full framebuffer, size = 1024 bytes]
  U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);
    //  2ND_HW_I2C  If supported, use second hardware I2C (Arduino Wire lib)scl1 and sda1

// 4x voltage sensor met 4 adressen i2c
  Adafruit_INA219 ina219_A(0x40); 
  Adafruit_INA219 ina219_B(0x41); 
  Adafruit_INA219 ina219_C(0x44);
  Adafruit_INA219 ina219_D(0x45);

// variabelen floating point
  float shuntvoltageA = 0;
  float shuntvoltageB = 0;
  float shuntvoltageC = 0;
  float shuntvoltageD = 0;
 
void setup() {
u8g2.begin();

  ina219_A.begin();  // Initialize first board (default address 0x40)
  ina219_B.begin();  // Initialize second board with the address 0x41
  ina219_C.begin();  // Initialize third board with the address 0x44
  ina219_D.begin();  // Initialize fourth board with the address 0x45
              }
      
void loop() {
  shuntvoltageA  = ina219_A.getShuntVoltage_mV();
  shuntvoltageB  = ina219_B.getShuntVoltage_mV();
  shuntvoltageC  = ina219_C.getShuntVoltage_mV();
  shuntvoltageD  = ina219_D.getShuntVoltage_mV();

  u8g2.clearBuffer(); // initialises screen buffer 
  u8g2.setFont(u8g2_font_8x13B_tf); // font
  // puts text into buffer:  
  u8g2.drawStr(0,12,"VoltA="); 
  u8g2.setCursor(55,12);
  u8g2.print(shuntvoltageA);
  u8g2.drawStr(100,12," mV");
 
  u8g2.drawStr(0,26,"VoltB="); 
  u8g2.setCursor(55,26);
  u8g2.print(shuntvoltageB);
  u8g2.drawStr(100,26," mV");
 
  u8g2.drawStr(0,40,"VoltC="); 
   u8g2.setCursor(55,40);
  u8g2.print(shuntvoltageC);
  u8g2.drawStr(100,40," mV");

  u8g2.drawStr(0,54,"VoltD="); 
  u8g2.setCursor(55,54);
  u8g2.print(shuntvoltageD);
  u8g2.drawStr(100,54," mV");

  u8g2.sendBuffer();  // sends buffer to screen
  delay(1500);
  
//  busvoltage    = ina219_A.getBusVoltage_V(); // voorlopig niet nodig
//  current_mA    = ina219_A.getCurrent_mA();
//  loadvoltage   = busvoltage + (shuntvoltage / 1000);
//  power         = (current_mA * shuntvoltage);


              }

I don't think there's a closed comment function.

But you can edit the title and add "[Solved]" as a prefix.