Cyton Uno+Cytron LoRa RFM + Espresso Lite V2.0

Bluetooth, XBee, RF......

Cyton Uno+Cytron LoRa RFM + Espresso Lite V2.0

Postby kelvinswee94 » Sun Mar 25, 2018 5:13 pm

Hi,
I was trying to connect cytron uno , cytron LoRa RFM shield and espresso litev2.0 together and upload data to the thingspeak, the data will be received from another LoRa node.

the LoRa RFM shield is attach on the cytron uno and the espresso lite v2.0 is connected like the attachment below

here is my code:
CODE: SELECT_ALL_CODE
#include <CytronWiFiShield.h>
#include <CytronWiFiClient.h>
#include <SoftwareSerial.h>
#include <ThingSpeak.h>
#include <WiFi.h>
#include <SPI.h>
#include <RH_RF95.h>
const char *ssid = "alexoi ASUS";
const char *pass = "ooi888168";
char thingSpeakAddress[] = "api.thingspeak.com";
String APIKey = "WW85UNEM7BW0FAM3";
const int updateThingSpeakInterval;     
ESP8266Client client;
WiFiServer server(80);
long lastConnectionTime = 0;
boolean lastConnected = false; 
#define RFM95_CS 10
#define RFM95_RST 7
#define RFM95_INT 2
#define RF95_FREQ 915.0
RH_RF95 rf95(RFM95_CS, RFM95_INT);
byte sendLen;
char buffer[50];
SoftwareSerial esp(8, 9); // RX, TX

void setup() {
  pinMode(RFM95_RST, OUTPUT);
  digitalWrite(RFM95_RST, HIGH);

  while (!Serial);
  Serial.begin(9600);
  delay(100);

  Serial.println("Arduino LoRa Receiver!");
 
  // manual reset
  digitalWrite(RFM95_RST, LOW);
  delay(10);
  digitalWrite(RFM95_RST, HIGH);
  delay(10);

  while (!rf95.init()) {
    Serial.println("LoRa radio init failed");
    while (1);
  }
  Serial.println("LoRa radio init OK!");

  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
  if (!rf95.setFrequency(RF95_FREQ)) {
    Serial.println("setFrequency failed");
    while (1);
  }
  Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);

  // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on

  // The default transmitter power is 13dBm, using PA_BOOST.
  // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
  // you can set transmitter powers from 5 to 23 dBm:
  rf95.setTxPower(23, false);

  esp.begin(9600);
 
  if(!wifi.begin(8, 9))
  {
    esp.println(F("Error talking to shield"));
    while(1);
  }
  esp.println(F("Start wifi connection"));
  if(!wifi.connectAP(ssid, pass))
  {
    esp.println(F("Error connecting to WiFi"));
    while(1);
  }
  esp.print(F("Connected to "));esp.println(wifi.SSID());
  esp.println(F("IP address: "));
  esp.println(wifi.localIP());
  ThingSpeak.begin(client);
  delay(1000);
 
 
}



void loop() {

       

 if (rf95.available())
  { 
    uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);
   
    if (rf95.recv(buf, &len))
    {
      RH_RF95::printBuffer("Received in HEX: ", buf, len);
      Serial.println("Received in DEC: ");
      int val = (int)strtol(buf,NULL,16);
      Serial.println(val);


     if (client.available()) {
     char c = client.read();
     Serial.print(c);
     }
     // Disconnect from ThingSpeak
     if (!client.connected() && lastConnected) {
     Serial.println("...disconnected");
     Serial.println();
     client.stop();
    }
      // Update ThingSpeak
     if (!client.connected() && (millis() - lastConnectionTime > updateThingSpeakInterval)) {
    updateThingSpeak("field1=" + val );
    Serial.println(val);
   

    }
  lastConnected = client.connected();
     
    }
    else
    {
      Serial.println("Receive failed");
    }
  }

}


void updateThingSpeak(String tsData) {
  if (client.connect(thingSpeakAddress, 80)) {
    client.print("POST /update HTTP/1.1\n");
    client.print("Host: api.thingspeak.com\n");
    client.print("Connection: close\n");
    client.print("X-THINGSPEAKAPIKEY: " + APIKey + "\n");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(tsData.length());
    client.print("\n\n");
    client.print(tsData);
    lastConnectionTime = millis();

    if (client.connected()) {
      Serial.println("Connecting to ThingSpeak...");
      Serial.println();
    }
  }
}



i use software serial to connect to the espresso lite v2.0.
the code doesn't work out, is my code wrong already?
can i use serial connection for both LoRa RFM shield and espresso lite v2.0?
hope anyone know can help me out

thanks!
Attachments
13.png
kelvinswee94
Novice
 
Posts: 16
Joined: Wed Nov 15, 2017 4:19 pm

Re: Cyton Uno+Cytron LoRa RFM + Espresso Lite V2.0

Postby bengchet » Mon Mar 26, 2018 11:42 am

Hi,

CODE: SELECT_ALL_CODE
  esp.begin(9600);
  if(!wifi.begin(8, 9))
  {
    esp.println(F("Error talking to shield"));
    while(1);
  }
  esp.println(F("Start wifi connection"));
  if(!wifi.connectAP(ssid, pass))
  {
    esp.println(F("Error connecting to WiFi"));
    while(1);
  }
  esp.print(F("Connected to "));esp.println(wifi.SSID());
  esp.println(F("IP address: "));
  esp.println(wifi.localIP());
  ThingSpeak.begin(client);
  delay(1000);


Initially you may be want to use Softwareserial esp(8, 9) to communicate between esp8266 and arduino uno, but note that wifi.begin(8, 9) has already handle that for you. So Softwareserial esp(8,9) is not needed anymore.

You should also change esp.begin(9600) to Serial.begin(9600) to view log at Arduino Serial monitor. The rest like esp.print(F(...)) and esp.println(F(...)), you should change to Serial.print(F(...)) and Serial.println(F(...)) to allow these info to be viewed properly at Serial monitor as well.

And also remind that, your hardware setup show pin 2 and pin 3 is connected to ESPresso Lite but in your sketch, you use pin 8 and 9 for wifi.begin. Please change the pins accordingly to match your sketch.
bengchet
Moderator
 
Posts: 237
Joined: Tue Aug 25, 2015 8:29 am

Re: Cyton Uno+Cytron LoRa RFM + Espresso Lite V2.0

Postby kelvinswee94 » Mon Mar 26, 2018 1:32 pm

bengchet WROTE:Hi,

CODE: SELECT_ALL_CODE
  esp.begin(9600);
  if(!wifi.begin(8, 9))
  {
    esp.println(F("Error talking to shield"));
    while(1);
  }
  esp.println(F("Start wifi connection"));
  if(!wifi.connectAP(ssid, pass))
  {
    esp.println(F("Error connecting to WiFi"));
    while(1);
  }
  esp.print(F("Connected to "));esp.println(wifi.SSID());
  esp.println(F("IP address: "));
  esp.println(wifi.localIP());
  ThingSpeak.begin(client);
  delay(1000);


Initially you may be want to use Softwareserial esp(8, 9) to communicate between esp8266 and arduino uno, but note that wifi.begin(8, 9) has already handle that for you. So Softwareserial esp(8,9) is not needed anymore.

You should also change esp.begin(9600) to Serial.begin(9600) to view log at Arduino Serial monitor. The rest like esp.print(F(...)) and esp.println(F(...)), you should change to Serial.print(F(...)) and Serial.println(F(...)) to allow these info to be viewed properly at Serial monitor as well.

And also remind that, your hardware setup show pin 2 and pin 3 is connected to ESPresso Lite but in your sketch, you use pin 8 and 9 for wifi.begin. Please change the pins accordingly to match your sketch.


Hi beng chet,
hi, because i attached CYTRON LoRA RFM Shield on top of the cytron uno, so i change the Tx, Rx pin to 8 and 9 respectively.
I attached the LoRa RFM shield like the photo below and connect Tx Rx to pin 8 and 9 of the LoRa shield
So now LoRa RFM shield and esp8266 are communicate with the arduino, so do i need assign one of them to software serial? because i was unable to initialize the esp8266 as well as the LoRa RFM shield if i didn't assign the software serial, there is nothing show up on the seral monitor, please advice, thanks!
Attachments
Capture.JPG
Capture.JPG (19.35 KiB) Viewed 4742 times
kelvinswee94
Novice
 
Posts: 16
Joined: Wed Nov 15, 2017 4:19 pm

Re: Cyton Uno+Cytron LoRa RFM + Espresso Lite V2.0

Postby bengchet » Mon Mar 26, 2018 2:47 pm

Hi,

In short,

Cytron LoRa Shield requires pin 2, 5, 6, 7, and 10 and SPI header pins. So if you are using it, make sure no other shield or hardware is using those pins. And it uses SPI communication, so no SoftwareSerial or HardwareSerial required.

ESP8266 requires Serial communication. So you can use softwareSerial with pin 8 and 9 as they are not interfering with Cytron LoRa Shield. wifi.begin(8,9) will create softwareSerial with rx pin 8 and tx pin 9 automatically.
bengchet
Moderator
 
Posts: 237
Joined: Tue Aug 25, 2015 8:29 am


Return to Wireless Device

Who is online

Users browsing this forum: No registered users and 13 guests

cron