Libelium is offering new technical support channels, to contact with de Technical Support team to solve any issue our doubt please contact with your sales agent or visit our contact site



Post a new topicPost a reply Page 2 of 2   [ 18 posts ]
Go to page Previous  1, 2
Author Message
 Post subject: Re: Arduino Uno+Multiprotocol radio shield+temperature senso
PostPosted: Mon Jul 03, 2017 7:12 am 

Joined: Mon Sep 28, 2009 12:06 pm
Posts: 11366
Hi titi,

Can you show us how do yo connect the sensor to our shield?

Which code are you using? Can you show it to us?

It seems that you are having problems with the i2c, it can be that the i2c of the sensor works using 3v3 and the i2c of the arduino uno uses 5V. Also, it can be that you power on/off something in the i2c bus and then it can't start again.

Regards


Top
 Profile  
 
 Post subject: Re: Arduino Uno+Multiprotocol radio shield+temperature senso
PostPosted: Mon Jul 03, 2017 5:14 pm 

Joined: Mon Jun 12, 2017 4:19 pm
Posts: 15
hello,

I give you some pictures of my system :
http://www.cjoint.com/c/GGdp2lGKw6X

Of course with LoRaWAN module :
http://www.cjoint.com/c/GGdp3f2aYZX

I use this library, firstly the .h:

Code:
#ifndef _TH02_DEV_H
#define _TH02_DEV_H

/****************************************************************************/
/***        Including Files                                               ***/
/****************************************************************************/
#include <Wire.h>
#include <Arduino.h>

/****************************************************************************/
/***        Macro Definitions                                             ***/
/****************************************************************************/
#define TH02_I2C_DEV_ID      0x40
#define REG_STATUS           0x00
#define REG_DATA_H           0x01
#define REG_DATA_L           0x02
#define REG_CONFIG           0x03
#define REG_ID               0x11

#define STATUS_RDY_MASK      0x01    //poll RDY,0 indicate the conversion is done

#define CMD_MEASURE_HUMI     0x01    //perform a humility measurement
#define CMD_MEASURE_TEMP     0x11    //perform a temperature measurement

#define TH02_WR_REG_MODE      0xC0
#define TH02_RD_REG_MODE      0x80
/****************************************************************************/
/***        Class Definition                                              ***/
/****************************************************************************/
class TH02_dev
{
public:
   void begin();
   uint8_t isAvailable();
   float ReadTemperature(void);
   float ReadHumidity(void);
private:
   void TH02_IIC_WriteCmd(uint8_t u8Cmd);
   uint8_t TH02_IIC_ReadReg(uint8_t u8Reg);
   void TH02_IIC_WriteReg(uint8_t u8Reg,uint8_t u8Data);
   uint16_t TH02_IIC_ReadData(void);
   uint16_t TH02_IIC_ReadData2byte(void);
};
extern TH02_dev TH02;

#endif  // _TH02_DEV_H


Secondly, the .cpp :

Code:
/****************************************************************************/
/***        Include files                                                 ***/
/****************************************************************************/
#include "TH02_dev.h"
#include <Wire.h>
#include <Arduino.h>
/* Use Serial IIC */
#ifdef SERIAL_IIC
#endif

TH02_dev TH02;
/****************************************************************************/
/***       Local Variable                                                 ***/
/****************************************************************************/


/****************************************************************************/
/***       Class member Functions                                         ***/
/****************************************************************************/

void TH02_dev::begin(void)
{
    /* Start IIC */
    Wire.begin();
   /* TH02 don't need to software reset */
}

float TH02_dev::ReadTemperature(void)
{   
    /* Start a new temperature conversion */
   TH02_IIC_WriteReg(REG_CONFIG, CMD_MEASURE_TEMP);       
    //delay(100);
   /* Wait until conversion is done */
   while(!isAvailable());
   uint16_t value = TH02_IIC_ReadData();
   
   value = value >> 2;
   /*
     Formula:
      Temperature(C) = (Value/32) - 50    
   */   
   float temper = (value/32.0)-50.0;
   
   return temper;
}
 
float TH02_dev::ReadHumidity(void)
{
 /* Start a new humility conversion */
   TH02_IIC_WriteReg(REG_CONFIG, CMD_MEASURE_HUMI);
   
   /* Wait until conversion is done */
   //delay(100);
   while(!isAvailable());
   uint16_t value = TH02_IIC_ReadData();
   
   value = value >> 4;
 
   /*
     Formula:
      Humidity(%) = (Value/16) - 24    
   */   

   float humility = (value/16.0)-24.0;
   
   return humility;
}

/****************************************************************************/
/***       Local Functions                                                ***/
/****************************************************************************/
uint8_t TH02_dev::isAvailable()
{
    uint8_t status =  TH02_IIC_ReadReg(REG_STATUS);
   if(status & STATUS_RDY_MASK)
   {
       return 0;    //ready
   }
   else
   {
       return 1;    //not ready yet
   }
}

void TH02_dev::TH02_IIC_WriteCmd(uint8_t u8Cmd)
{      
   /* Port to arduino */
   Wire.beginTransmission(TH02_I2C_DEV_ID);
   Wire.write(u8Cmd);
   Wire.endTransmission();
}

uint8_t TH02_dev::TH02_IIC_ReadReg(uint8_t u8Reg)
{
    /* Port to arduino */
    uint8_t Temp = 0;
   
   /* Send a register reading command */
    TH02_IIC_WriteCmd(u8Reg);   
      
   Wire.requestFrom(TH02_I2C_DEV_ID, 1);   
   while(Wire.available())
   {
       Temp = Wire.read();   
   }
      
   return Temp;
}

void TH02_dev::TH02_IIC_WriteReg(uint8_t u8Reg,uint8_t u8Data)
{           
   Wire.beginTransmission(TH02_I2C_DEV_ID);   
   Wire.write(u8Reg);   
   Wire.write(u8Data);   
   Wire.endTransmission();   
}

uint16_t TH02_dev::TH02_IIC_ReadData(void)
{                       
   /* Port to arduino */   
   uint16_t Temp = TH02_IIC_ReadData2byte();
   return Temp;
}

uint16_t TH02_dev::TH02_IIC_ReadData2byte()
{
    uint16_t TempData = 0;
   uint16_t tmpArray[3]={0};

   int cnt = 0;
   TH02_IIC_WriteCmd(REG_DATA_H);   
   
   Wire.requestFrom(TH02_I2C_DEV_ID, 3);   
   while(Wire.available())
   {
       tmpArray[cnt] = (uint16_t)Wire.read();                      
      cnt++;
   }
   /* MSB */
   TempData = (tmpArray[1]<<8)|(tmpArray[2]);
   return TempData;
}


But in my program I just use the functions begin() and ReadTemperature()/ReadHumidity().

A point that to know if I use 3V3 or 5V the temperature sensor or the LoRaWAN works independently of each other. But when I plug together it doesn't work.


Top
 Profile  
 
 Post subject: Re: Arduino Uno+Multiprotocol radio shield+temperature senso
PostPosted: Tue Jul 04, 2017 7:31 am 

Joined: Mon Sep 28, 2009 12:06 pm
Posts: 11366
Hi titi,

Please, copy here the code that you upload to your Arduino.

You are having problems with the i2c protocol, the i2c bus is very sensitive when connecting and disconnecting devices and can produce a fault on the bus. That's why we recommend to isolate the i2c bus on each device.

Regards


Top
 Profile  
 
 Post subject: Re: Arduino Uno+Multiprotocol radio shield+temperature senso
PostPosted: Tue Jul 04, 2017 9:08 am 

Joined: Mon Jun 12, 2017 4:19 pm
Posts: 15
hi,

How can I isolate the I2C bus on each device ?

I give you my program :

Code:
#include <ChainableLED.h>
#include <Wire.h>
#include "AirQuality.h"
#include <TH02_dev.h>
// Cooking API libraries
#include <arduinoUART.h>
#include <arduinoUtils.h>

// LoRaWAN library
#include <arduinoLoRaWAN.h>

#define SOUND_SENSOR A1
#define FLAME_SENSOR 3 //connect SENSOR to digital pin3
#define IR_SENSOR 2 // connect SENSOR to digital pin2
#define THRESHOLD_VALUE 450//The threshold to turn the led on 400.00*5/1024 = 1.95v

//Declaration des sorties pour les Led RGB
ChainableLED led1(6, 7, 1);
byte colorLED = 0xFF;
//Instanciation du capteur de qualite d'air
AirQuality airqualitysensor;
int current_quality = -1;
int previous_quality = -1;

char data[15] = "0000000000";
boolean IRstate = 1, FRstate = 1;
boolean LastIRstate = 1, LastFRstate = 1;

//////////////////////////////////////////////
uint8_t socket = SOCKET1;
//////////////////////////////////////////////
// Pin definition for LoRaWAN module error LED:
const int error_led =  13;

// Device parameters for Back-End registration
////////////////////////////////////////////////////////////
char DEVICE_EUI[]  = "0102030405060707";
char DEVICE_ADDR[] = "05060707";
char NWK_SESSION_KEY[] = "01020304050607080910111213141516";
char APP_SESSION_KEY[] = "000102030405060708090A0B0C0D0E0F";
////////////////////////////////////////////////////////////

// Define port to use in Back-End: from 1 to 223
uint8_t PORT = 3;

//Variable
uint8_t error;

//Déclaration des variables permattant de faire le timer
unsigned long heurecourante = 0;
unsigned long dateDernierChangement = 0;
unsigned long intervalle =0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(57600);

   /* Power up,delay 150ms,until voltage is stable */
  delay(150);
  /* Reset HP20x_dev */
  TH02.begin();
  delay(100);
 
  //Declaration des entrées pour les capteurs IR
  pinMode(IR_SENSOR, INPUT);
  pinMode(SOUND_SENSOR, INPUT);
 
  //Lancement de l'acquisition pour la capteur d'air
  airqualitysensor.init(14);
  //Initialisation des leds
  led1.init();


  //------------------------------------
  //Module LoRaWAN configuration
  //------------------------------------

  //////////////////////////////////////////////
  // 1. Switch on
  //////////////////////////////////////////////
  LoRaWAN.ON(socket);

  //////////////////////////////////////////////
  // 2. Set Device EUI
  //////////////////////////////////////////////
  LoRaWAN.setDeviceEUI(DEVICE_EUI);

  //////////////////////////////////////////////
  // 3. Set Device Address
  //////////////////////////////////////////////
  LoRaWAN.setDeviceAddr(DEVICE_ADDR);

  //////////////////////////////////////////////
  // 4. Set Network Session Key
  //////////////////////////////////////////////
  LoRaWAN.setNwkSessionKey(NWK_SESSION_KEY);

  //////////////////////////////////////////////
  // 5. Set ApIRication Session Key
  //////////////////////////////////////////////
  LoRaWAN.setAppSessionKey(APP_SESSION_KEY);

  //////////////////////////////////////////////
  // 6. Save configuration
  //////////////////////////////////////////////
  LoRaWAN.saveConfig();

  //------------------------------------
  //Module configured
  //------------------------------------

  LoRaWAN.getDeviceEUI();
  //Serial.println(LoRaWAN._devEUI);
  //Device EUI in LoRaWAN._devEUI

  LoRaWAN.getDeviceAddr();
  //Serial.println(LoRaWAN._devAddr);
  //Device Addres in LoRaWAN._devAddr
}

void loop() {
  // put your main code here, to run repeatedly:

  delay(2000);
  heurecourante =  millis();
  intervalle = heurecourante - dateDernierChangement;
  //////////////////////////////////////////////
  // 1. Switch on
  //////////////////////////////////////////////
  LoRaWAN.ON(socket);
  //Serial.println(IRstate);
  //Serial.println(LastIRstate);
  /*Serial.print("Ma trame initiale est de : ");
    Serial.println(trame);*/

  // If reflection is detected on sensor 1
  if (digitalRead(IR_SENSOR) == 0) {
    //Serial.println("detection IR1");
    IRstate = digitalRead(IR_SENSOR);
    data[0] = '0';
    data[1] = '1';
    //Serial.println(IRstate);
  }
  else {
    IRstate = digitalRead(IR_SENSOR);
    data[0] = '0';
    data[1] = '0';
    //Serial.println(IRstate);
  }

  if(isFlameDetected()){
    FRstate = digitalRead(FLAME_SENSOR);
    //Serial.println("Detection de la flammme");
    //Serial.println(FRstate);
    data[2] = '0';
    data[3] = '1';
  }
  else {
    FRstate = digitalRead(FLAME_SENSOR);
    //Serial.println("Pas de flammme");
    //Serial.println(FRstate);
    data[2] = '0';
    data[3] = '0';
  }

  int noiseValue = analogRead(SOUND_SENSOR);
  //int noiseValue = 255;
  String stringOne = String(noiseValue, HEX);
  stringOne.toUpperCase();
  //Serial.println(noiseValue);
  //Serial.println(stringOne.length());

  for (int i = 0; i < stringOne.length(); i++) {
      if(stringOne.length() == 3) {
        data[6] = '0';
        data[7+i] = stringOne.charAt(i);
      }
      else { //(stringOne.length() == 2)
        data[6] = '0';
        data[7] = '0';
        data[8+i] = stringOne.charAt(i); 
      }
  }

  current_quality=airqualitysensor.slope();
  //String stringone2 = String(current_quality,HEX);
  //Serial.println(stringone2);
  //data[5] = stringone2.charAt(0);
  data[4] = '0';
  switch(current_quality) {
    case 0:
      data[5] = '0';
      break;
    case 1:
      data[5] = '1';
      break;
    case 2:
      data[5] = '2';
      break;
    case 3:
      data[5] = '3';
      break;
    default:
      //Serial.println("Problème sur la valeur de retour du capteur AIR");
      break;
  }

  float temper = TH02.ReadTemperature();
  Serial.println("Temperature: ");   
  Serial.print(temper);
 
  Serial.println(data);
  //data[0] = 70;
  //Serial.println(stringone2.toUpperCase());
  //int longueur = len(data);
  //Serial.println(longueur);
  //delay(2000);

  if ((noiseValue > THRESHOLD_VALUE) || (IRstate != LastIRstate) || (FRstate != LastFRstate) || (current_quality != previous_quality))
  {
    delay(1000);

    if ((noiseValue > THRESHOLD_VALUE) || (IRstate != LastIRstate) || (FRstate != LastFRstate) || (current_quality != previous_quality))
    {

      //Serial.println("detection +5s donc envoi");
      //////////////////////////////////////////////
      // 1. Switch on
      //////////////////////////////////////////////
      LoRaWAN.ON(socket);

      //////////////////////////////////////////////
      // 2. Join network
      //////////////////////////////////////////////
      error = LoRaWAN.joinABP();
      //Serial.println(error);

      // Check status
      if ( error == 0 )
      {
        //2. Join network OK
        //Serial.println(data);

        //////////////////////////////////////////////
        // 3. Send confirmed packet with ACK
        //////////////////////////////////////////////
        error = LoRaWAN.sendConfirmed(PORT, data);
        //Serial.println(error);
          // Error messages:
          /*
           '6' : Module hasn't joined a network
           '5' : Sending error
           '4' : Error with data length
           '2' : Module didn't response
           '1' : Module communication error
        */
        //Serial.println(error);
        // Check status
         if ( error == 0 )
          {
           //3. Send Unconfirmed packet OK
           if (LoRaWAN._dataReceived == true)
           {
             //There's data on
             //port number: LoRaWAN._port
             //and Data in: LoRaWAN._data
             digitalWrite(error_led, LOW);
           }
          }
          else
          {
           //3. Send Confirmed packet error
           digitalWrite(error_led, HIGH);
          }
      }
      else
      {
        //2. Join network error
        digitalWrite(error_led, HIGH);
      }

      //////////////////////////////////////////////
      // 4. Switch off
      //////////////////////////////////////////////
      error = LoRaWAN.OFF(socket);

      // Check status
      if ( error == 0 )
      {
        //4. Switch OFF OK
        digitalWrite(error_led, LOW);
      }
      else
      {
        //4. Switch OFF error
        digitalWrite(error_led, HIGH);
      }

      LastIRstate = IRstate;
      LastFRstate = FRstate;
      previous_quality = current_quality;

      if (LastIRstate == 0) {
        led1.setColorRGB(0, colorLED, 0, 0);
      } else {
        led1.setColorRGB(0, 0, colorLED, 0);
      }

      if(LastFRstate == 0 ) {
        //Activation du buzzer
      } else {
        //Desactivation du buzzer
      }
      delay(10000);
    }

    //Serial.println("detection +5s et envoi");
  }

  else {
    Serial.println("on envoit pas de message car pas evenement");
  }

if (intervalle >= 300000) {
               
                Serial.println("on rentre dans la boucle d'envoi du timer toutes les 5 minutes");
                    //////////////////////////////////////////////
                // 1. Switch on
                //////////////////////////////////////////////
                LoRaWAN.ON(socket);
               
                //////////////////////////////////////////////
                // 2. Join network
                //////////////////////////////////////////////
                error = LoRaWAN.joinABP();
                //Serial.println(error);

                // Check status
                if( error == 0 )
                {
                  //2. Join network OK
                  //Serial.println(data);
             
                //////////////////////////////////////////////
                // 3. Send confirmed packet with ACK
                //////////////////////////////////////////////
                  error = LoRaWAN.sendConfirmed(PORT, data);
                 
                  // Error messages:
                  /*
                   * '6' : Module hasn't joined a network
                   * '5' : Sending error
                   * '4' : Error with data length
                   * '2' : Module didn't response
                   * '1' : Module communication error
                   */
                  //Serial.println(error);
                  // Check status
                  if( error == 0 )
                  {
                    //3. Send Unconfirmed packet OK
                    if (LoRaWAN._dataReceived == true)
                    {
                      //There's data on
                      //port number: LoRaWAN._port
                      //and Data in: LoRaWAN._data
                      digitalWrite(error_led, LOW);
                    }
                  }
                  else
                  {
                    //3. Send Confirmed packet error
                    digitalWrite(error_led, HIGH);
                  }
                }
                else
                {
                  //2. Join network error
                  digitalWrite(error_led, HIGH);
                }
   
                //////////////////////////////////////////////
                // 4. Switch off
                //////////////////////////////////////////////
                error = LoRaWAN.OFF(socket);
             
                // Check status
                if( error == 0 )
                {
                  //4. Switch OFF OK
                  digitalWrite(error_led, LOW);
                }
                else
                {
                  //4. Switch OFF error
                  digitalWrite(error_led, HIGH);
                }

                dateDernierChangement = heurecourante ;
                delay(10000);
      }

}

void pinsInit()
{
    pinMode(FLAME_SENSOR, INPUT);
    pinMode(IR_SENSOR, INPUT);
}

boolean isFlameDetected()
{
    if(digitalRead(FLAME_SENSOR))
      return false;
    else return true;
}

void turnOnLED()
{
    led1.setColorRGB(0, colorLED, 0, 0);
   
}
void turnOffLED()
{
     led1.setColorRGB(0, 0, colorLED, 0);
   
}
int len(char inText[])
{
  int length = 0;
 
  while (inText[length] != 0)
    length++;
 
  return length;
}

ISR(TIMER1_OVF_vect)
{
  if(airqualitysensor.counter==61)//set 2 seconds as a detected duty
  {

      airqualitysensor.last_vol=airqualitysensor.first_vol;
      airqualitysensor.first_vol=analogRead(A0);
      airqualitysensor.counter=0;
      airqualitysensor.timer_index=1;
      PORTB=PORTB^0x20;
  }
  else
  {
    airqualitysensor.counter++;
  }
}


I have some sensors but when I add the I2C sensor the program displays that :
http://www.cjoint.com/c/GGeh7jlI0FX


Top
 Profile  
 
 Post subject: Re: Arduino Uno+Multiprotocol radio shield+temperature senso
PostPosted: Tue Jul 04, 2017 3:10 pm 

Joined: Mon Sep 28, 2009 12:06 pm
Posts: 11366
Hi titi,

titi wrote:
How can I isolate the I2C bus on each device ?

There are some i2c isolator chips available in some stores.

titi wrote:
I give you my program :

Can you power on the module once you switch on the LoRAWAN module?
I have tried it with other i2c sensor and if i have:

Code:
mysensor.begin();
LoRaWAN.ON(socket);


It doesn't work

But if i have:

Code:
LoRaWAN.ON(socket);
mysensor.begin();


It works.

Regards


Top
 Profile  
 
 Post subject: Re: Arduino Uno+Multiprotocol radio shield+temperature senso
PostPosted: Wed Jul 05, 2017 9:30 am 

Joined: Mon Jun 12, 2017 4:19 pm
Posts: 15
Hi,

I have already tested and the program blocked for both solutions but I will try again. Will be in touch, thanks for your replies.


Top
 Profile  
 
 Post subject: Re: Arduino Uno+Multiprotocol radio shield+temperature senso
PostPosted: Wed Jul 05, 2017 9:55 am 

Joined: Mon Jun 12, 2017 4:19 pm
Posts: 15
It doesn't work. The only way is to buy an I2C isolator or to change the sensor with another communication.
What do you have as I2C sensor that you plug on your base shield Arduino ?


Top
 Profile  
 
 Post subject: Re: Arduino Uno+Multiprotocol radio shield+temperature senso
PostPosted: Thu Jul 06, 2017 7:24 am 

Joined: Mon Sep 28, 2009 12:06 pm
Posts: 11366
Hi titi,

I have tried it with a BME280 sensor.

Regards


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 2 of 2   [ 18 posts ]
Go to page Previous  1, 2


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Libelium theme based on 610nm Style by Daniel St. Jules of http://www.gamexe.net


© Libelium Comunicaciones Distribuidas S.L. | Terms of use.