LowPowerLab Forum

Hardware support => Moteino => Topic started by: MPParsley on November 25, 2016, 07:10:49 AM

Title: C question: error: expected unqualified-id
Post by: MPParsley on November 25, 2016, 07:10:49 AM
Hello, I'm using the moteino with a i2c LCD (library https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads/NewliquidCrystal_1.3.4.zip)

Now there seems to be a collision between the RFM69 library which uses radio.DATA and the LCD library which creates a struct DATA:

Serial.print((char)radio.DATA); results in an error: expected unqualified-id

NewliquidCrystal_1.3.4_slim/LCD.h:151:33: note: expanded from macro 'DATA'
#define DATA                    1


Any idea how to go about this?
Title: Re: C question: error: expected unqualified-id
Post by: perky on November 25, 2016, 07:23:12 AM
isn't radio.DATA a pointer to an array? That would mean you are casting it to a char rather than a char*.
Mark.
Title: Re: C question: error: expected unqualified-id
Post by: MPParsley on November 25, 2016, 07:30:15 AM
Could be but it results in the same error:
(sketch file) Gateway.ino:134:32: error: expected unqualified-id


     Serial.print((char*)radio.DATA);
                               ^
(personal library file) NewliquidCrystal_1.3.4_slim/LCD.h:151:33: note: expanded from macro 'DATA'
#define DATA                    1
                                ^

Note that when I remove the LCD library, this command works fine:
     Serial.print((char)radio.DATA);

What I don't understand is why the radio's property DATA is treated as a macro on the LCD library and how to prevent this.
Title: Re: C question: error: expected unqualified-id
Post by: perky on November 25, 2016, 07:47:20 AM
expected unqualified-id I think usually means you've put a semi-colon in the wrong place, that might be in a header file. Header file errors can cause all sorts of strange errors to pop up in seemingly unlelated code.
Mark.
Title: Re: C question: error: expected unqualified-id
Post by: MPParsley on November 25, 2016, 07:56:46 AM
thank you for your reply but syntax is valid, the code compiles nicely and as stated, simply removing this line will make it work:

#include <LiquidCrystal_I2C.h>

There seems to be something in this library that breaks the radio.DATA object.

In RFM69:
volatile byte RFM69::DATA[RF69_MAX_DATA_LEN];

in LiquidCrystal_I2C:
#define DATA                    1
Title: Re: C question: error: expected unqualified-id
Post by: perky on November 25, 2016, 09:00:20 AM
Sorry, a bit confused. You said there was an 'expected unqualified-id' error.  Are you saying there is no error on compilation even with that library header file included?
Unless you're saying the DATA #define in this header file is replacing the DATA part in radio.DATA to yield radio.1 in the pre-process before compilation?
Mark.
Title: Re: C question: error: expected unqualified-id
Post by: TomWS on November 25, 2016, 09:19:34 AM
Quote from: MPParsley on November 25, 2016, 07:56:46 AM
thank you for your reply but syntax is valid, the code compiles nicely and as stated, simply removing this line will make it work:

#include <LiquidCrystal_I2C.h>

There seems to be something in this library that breaks the radio.DATA object.

In RFM69:
volatile byte RFM69::DATA[RF69_MAX_DATA_LEN];

in LiquidCrystal_I2C:
#define DATA                    1
It appears that the authors of the LCD library made a very unfortunate choice of defining the constant 'DATA', which, as you say, is colliding with the RFM69 library DATA element.  You have some choices:
1. Only use one library at a time... 
2. Edit one of the libraries to change 'DATA' to something else.
3. petition the authors of the LCD library to change the DATA constant to LCD_DATA or some such.

I would recommend scanning the LCD library to see how often 'DATA' occurs.  I suspect that will be the easiest to change, especially when virtually every bit of code using the RFM69 library (including ALL of the examples) reference radio.DATA.

Tom

Tom
Title: Re: C question: error: expected unqualified-id
Post by: MPParsley on November 25, 2016, 03:15:54 PM
Thanks guys.

@TomWS, that is indeed what I expected. I'll see if I can contribute a patch to the LCD library but atm I created a ticket fot this issue: https://bitbucket.org/fmalpartida/new-liquidcrystal/issues/72/data

Do you know of any other/better libraries to deal with LCD over serial?
Title: Re: C question: error: expected unqualified-id
Post by: Felix on November 25, 2016, 04:14:16 PM
Try U8glib. It's a very solid library, though a more steep learning curve but it supports a huge variety of LCD controllers over SPI, I2C etc.
Title: Re: C question: error: expected unqualified-id
Post by: MPParsley on November 25, 2016, 04:36:00 PM
Thanks for the tip!

Seems like my pull request just got merged :)
Title: Re: C question: error: expected unqualified-id
Post by: TomWS on November 25, 2016, 05:36:16 PM
Quote from: Felix on November 25, 2016, 04:14:16 PM
Try U8glib. It's a very solid library, though a more steep learning curve but it supports a huge variety of LCD controllers over SPI, I2C etc.
I second this vote!  It is the go to LCD library supporting virtually all small LCD panels on the market.  AND it does not conflict with RFM69 library  :)

Tom
Title: Re: C question: error: expected unqualified-id
Post by: MPParsley on November 26, 2016, 02:39:44 AM
Would it work with 1602 (16x2), it's not listed on the supported page?
Title: Re: C question: error: expected unqualified-id
Post by: perky on November 26, 2016, 04:19:26 AM
I think this is a graphics LCD library, you're talking about a character LCD which I believe there are standard Arduino libraries for. Character LCDs are quite trivial to drive in comparison (the only real complication usually is in the power up reset routines which some chips have minor variations on, but most chips for character LCDs are HD44780 compatible).
Mark.
Title: Re: C question: error: expected unqualified-id
Post by: MPParsley on November 26, 2016, 04:45:54 AM
Hi perky,

The standard Arduino Liquidcrystal library works nicely if you build your own circuit which connects directly to the digital interface pins (2, 3, 4, 5, 11 & 12) but it doesn't offer support for an i2c interface which only connects to SCL & SDA.
Title: Re: C question: error: expected unqualified-id
Post by: perky on November 26, 2016, 08:22:44 AM
Ah, OK. I'm surprised no-one has written a lower level I2C driver for it yet.
Mark.