[SOLVED] problem with I2C LCD library

Started by gianmarko, March 14, 2014, 06:07:16 AM

gianmarko

good morning Gentlemen

i am having a problem with a code i wrote. is a simple remote thermometer. i want to have, at the receiver side, a lcd displaying the temperature received from another moteino.

when i include the libraries

#include <LCD.h>
#include <LiquidCrystal_I2C.h>

the line of code
      buff1 = ((char)radio.DATA);


generates the following error when compiling

mot_rec_short.ino: In function 'void loop()':
mot_rec_short.ino:76:31: error: expected unqualified-id before numeric constant
mot_rec_short.ino:76:31: error: expected ')' before numeric constant


as i suck at C, hope someone can shed some light on the mystery :-)

here the complete code

#include <RFM69.h>
#include <SPI.h>
#include <SPIFlash.h>

#include <Wire.h>
//#include <LCD.h>
//#include <LiquidCrystal_I2C.h>


#define NODEID 1 //unique for each node on same network
#define NETWORKID 100 //the same on all nodes that talk to each other

#define FREQUENCY RF69_915MHZ
#define ENCRYPTKEY "gianmarcorizzo12" //exactly the same 16 characters/bytes on all nodes!

#define ACK_TIME 30 // max # of ms to wait for an ack
#define LED 9 // Moteinos have LEDs on D9
#define SERIAL_BAUD 115200

#define I2C_ADDR    0x27
#define BACKLIGHT_PIN     3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7



RFM69 radio;
SPIFlash flash(8, 0xEF30); //EF40 for 16mbit windbond chip
bool promiscuousMode = false; //set to 'true' to sniff all packets on the same network






void setup() {
  Serial.begin(SERIAL_BAUD);
  delay(10);
  radio.initialize(FREQUENCY,NODEID,NETWORKID);
#ifdef IS_RFM69HW
  radio.setHighPower(); //uncomment only for RFM69HW!
#endif
  radio.encrypt(ENCRYPTKEY);
  radio.promiscuous(promiscuousMode);
  char buff[50];
  sprintf(buff, "\nListening at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
  Serial.println(buff);
  pinMode (3, OUTPUT);

}

byte ackCount=0;
void loop() {
char buff1[10];
long ref1 = 0;
float ref2 = 0;


  if (radio.receiveDone())
  {

    for (byte i = 0; i < radio.DATALEN; i++)
      buff1 = ((char)radio.DATA);
     


ref1 = atoi(buff1);
ref2 = (ref1 / 9.31)-1.4; // calibration 1.4 deg C


  Serial.println(ref2);
   
    if (radio.ACK_REQUESTED)
    {
      byte theNodeID = radio.SENDERID;
      radio.sendACK();
      Serial.print(" - ACK sent.");

     
     
    }
    if (ref2 > 19.5)
    {
    digitalWrite(3, LOW);
        Serial.println("off"); 

    }
   
    if (ref2 < 19)
    {
    digitalWrite(3, HIGH);
    Serial.println("on"); 
    }
   
   
    Serial.println();
    Blink(LED,3);
  }
}

void Blink(byte PIN, int DELAY_MS)
{
  pinMode(PIN, OUTPUT);
  digitalWrite(PIN,HIGH);
  delay(DELAY_MS);
  digitalWrite(PIN,LOW);
}

Felix

What does your data that you send look like? Is it an integer or a decimal number?

radio.DATA is a byte array pointer. So you can't convert it to a char.
You could use sscanf to read your integer or decimal into a variable like this:

uint16_t tmp=0;
sscanf((const char*)radio.DATA, "some text here %u more text after (if any)", &tmp);


If your variable is a float use %f instead. See this reference for all the possible printf/scanf arguments: http://www.cplusplus.com/reference/cstdio/printf/

gianmarko

#2
Hi Felix

this is the code that sends data. it is a integer.

    int reading = analogRead(sensorPin); 
   
    itoa(reading, buff, 10);
    byte buffLen=strlen(buff);

    if (radio.sendWithRetry(GATEWAYID, buff, buffLen))
     Serial.print(" ok!");
    else Serial.print(" nothing...");


basically all need is to receive the same integer i send from the trasmitter side, put it in some variable so i can then use it for the logic to start/stop the heating boiler.

as i said, i suck at C, the funny thing is that the receiver code works fine if i dont include the LCD libraries...

i cannibilized the code from some other moteino application, where char was used...


Felix

Hey I think the easiest way for you to transmit an integer is with the struct send/receive examples, just replace the existing variables with a single integer variable:
https://github.com/LowPowerLab/RFM69/tree/master/Examples

OR .. since int is a 2 byte you could just read the first 2 bytes from radio.DATA (like radio.DATA
  • and [1]) and make an integer with them:

    uint8_t temp=0;
    temp =  (radio.DATA[0] << 8) +  radio.DATA[1];
    

gianmarko

thanks a lot for the suggestions. however i am investigating some more, as using the lcd libraries im using, even your original receiver code breaks down

these are the libraries im using.

https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads

i tried other lcd i2c libraries, they dont break the code but they dont work with my display/i2c interface


Felix

Sorry but I don't know what else to suggest, I am not familiar with those libraries.

gianmarko

no prob Felix.

very happy with your products. great stuff indeed. 


Quote from: Felix on March 14, 2014, 12:32:42 PM
Sorry but I don't know what else to suggest, I am not familiar with those libraries.

ShadowGrass

I had the same problem.  I saw that there were a lot of the same pins being used for the wireless and the LCD, so for about $5 I ended up sending the data from the Moteino to another Arduino Mini clone through serial (TX/RX).  The Arduino does my SPI LCD just fine.  Just my 2c.

gianmarko

the problem must be software, as i am able to use the I2C display with the same moteino, just cant include the radio and the I2C lcd libraries at the same time

i dont think is a problem with digital outputs as the I2C uses A4 and A5

i found other I2C LCD libraries that are compatible with the moteino libraries, just they dont work with this specific I2C adapter/LCD display.  which is funny as hardware looks the same.

as last resort ill get a different I2C display, neater than adding a second arduino :-)

Quote from: ShadowGrass on March 14, 2014, 06:03:51 PM
I had the same problem.  I saw that there were a lot of the same pins being used for the wireless and the LCD, so for about $5 I ended up sending the data from the Moteino to another Arduino Mini clone through serial (TX/RX).  The Arduino does my SPI LCD just fine.  Just my 2c.

Felix

The i2c LCD I used is working without issue, as shown in the Mailbox Notifier standalone receiver: https://github.com/LowPowerLab/MailboxNotifier/blob/master/MailboxNotifier2_receiver.ino

gianmarko

i found a i2c LCD library that works with the RFM69 libraries, my cheap pcf8574 board, the hdm16216 lcd,  and my crappy code :-) which might be wrong but due to the mysterious nature of C, nevertheless works

library downloadable (for the time being) here

http://www.divshare.com/download/24151116-7dc


Felix


gianmarko