Go Down

Topic: Arduino Arduino module communication by Lora Sx1278 (Read 112 times) previous topic - next topic

AlexandreMX

recently acquired a kit with two modules SX1278F




  previously the supplier sent me dorji programming creator Semteth
in this program you can change the rate of trasmicion the velisada mode sending the dbms data per second etc.
Sample code.

Code: [Select]

/**********************************************
Title:sx1276_7_8 demo code
Current version:v1.0
Function:demo
Processor Arduino
Clock:
Operate freqency:433MHZ band\
Date rate:for programme

---------------------------------modulation: Lora/FSK(Desplazamiento de frecuencia)----------------

deviation:for programme
Transmit one packet data time : Indefinite package
Work mode:
campany:WWW.DORJI.COM
author:DORJI
Contact:
Date:2014-07-02
*************************************************/
unsigned char mode;//lora--1/DSSS--0
unsigned char Freq_Sel;//
unsigned char Power_Sel;//
unsigned char Lora_Rate_Sel;//
unsigned char BandWide_Sel;//
unsigned char Fhss_Rate_Sel;//
#define SS     53
#define DIO0  7
#define DIO1  6
#define DIO2  5
#define DIO3  4
#define DIO4  3
#define DIO5  2
#define LED1   A0
#define LED2  A15
#define LED3   11
/**********************************************************
**Name: SPICmd8bit
**Function: SPI Write one byte
**Input: WrPara
**Output: none
**note: use for burst mode
**********************************************************/
void SPICmd8bit(unsigned char WrPara)
{
unsigned char bitcnt;
digitalWrite(SS, LOW);//nSEL_L();
digitalWrite(SCK, LOW);//SCK_L();
for(bitcnt=8; bitcnt!=0; bitcnt--)
{
digitalWrite(SCK, LOW);//SCK_L();
if(WrPara&0x80)
digitalWrite(MOSI, HIGH);//SDI_H();
else
digitalWrite(MOSI, LOW);//SDI_L();
digitalWrite(SCK, HIGH);//SCK_H();
WrPara <<= 1;
}
digitalWrite(SCK, LOW);//SCK_L();
digitalWrite(MOSI, HIGH);//SDI_H();
}
/**********************************************************
**Name: SPIRead8bit
**Function: SPI Read one byte
**Input: None
**Output: result byte
**Note: use for burst mode
**********************************************************/
unsigned char SPIRead8bit(void)
{
unsigned char RdPara = 0;
unsigned char bitcnt;
digitalWrite(SS, LOW);//nSEL_L();
digitalWrite(MOSI, HIGH);//SDI_H(); //Read one byte data from FIFO, MOSI hold to High
for(bitcnt=8; bitcnt!=0; bitcnt--)
{
digitalWrite(SCK, LOW);//SCK_L();
RdPara <<= 1;
digitalWrite(SCK, HIGH); //SCK_H();
if(digitalRead(MISO))//if(Get_SDO())
RdPara |= 0x01;
else
RdPara |= 0x00;
}
digitalWrite(SCK, LOW);//SCK_L();
return(RdPara);
}
/**********************************************************
**Name: SPIRead
**Function: SPI Read CMD
**Input: adr -> address for read
**Output: None
**********************************************************/
unsigned char SPIRead(unsigned char adr)
{
unsigned char tmp;
SPICmd8bit(adr); //Send address first
tmp = SPIRead8bit();
digitalWrite(SS, HIGH);//nSEL_H();
return(tmp);
}
/**********************************************************
**Name: SPIWrite
**Function: SPI Write CMD
**Input: u8 address & u8 data
**Output: None
**********************************************************/
void SPIWrite(unsigned char adr, unsigned char WrPara)
{
digitalWrite(SS, LOW);//nSEL_L();
SPICmd8bit(adr|0x80); //写入地址
SPICmd8bit(WrPara);//写入数据
digitalWrite(SCK, LOW);//SCK_L();
digitalWrite(MOSI, HIGH);//SDI_H();
digitalWrite(SS, HIGH);//nSEL_H();
}
/**********************************************************
**Name: SPIBurstRead
**Function: SPI burst read mode
**Input: adr-----address for read
** ptr-----data buffer point for read
** length--how many bytes for read
**Output: None
**********************************************************/
void SPIBurstRead(unsigned char adr, unsigned char *ptr, unsigned char leng)
{
unsigned char i;
if(leng<=1) //length must more than one
return;
else
{
digitalWrite(SCK, LOW); //SCK_L();
digitalWrite(SS, LOW);//nSEL_L();
SPICmd8bit(adr);
for(i=0;i<leng;i++)
ptr[i] = SPIRead8bit();
digitalWrite(SS, HIGH);//nSEL_H();
}
}
/**********************************************************
**Name: SPIBurstWrite
**Function: SPI burst write mode
**Input: adr-----address for write
** ptr-----data buffer point for write
** length--how many bytes for write
**Output: none
**********************************************************/
void BurstWrite(unsigned char adr, unsigned char *ptr, unsigned char leng)
{
unsigned char i;
if(leng<=1) //length must more than one
return;
else
{
digitalWrite(SCK, LOW);//SCK_L();
digitalWrite(SS, LOW);//nSEL_L();
SPICmd8bit(adr|0x80);
for(i=0;i<leng;i++)
SPICmd8bit(ptr[i]);
digitalWrite(SS, HIGH);//nSEL_H();
}
}
/************************************************
// RF module: sx1276_7_8
// Fhss:
// Carry Frequency: 434MHz
// Bit Rate: 1.2Kbps/2.4Kbps/4.8Kbps/9.6Kbps
// Tx Power Output: 20dbm/17dbm/14dbm/11dbm
// Frequency Deviation: +/-35KHz
// Receive Bandwidth: 83KHz
// Coding: NRZ
// Packet Format: 0x5555555555+0xAA2DD4+"Mark1 Lora sx1276_7_8" (total: 29 bytes)
// LoRa:
// Carry Frequency: 434MHz
// Spreading Factor: 6/7/8/9/10/11/12
// Tx Power Output: 20dbm/17dbm/14dbm/11dbm
//Receive Bandwidth:7.8KHz/10.4KHz/15.6KHz/20.8KHz/31.2KHz/41.7KHz/62.5KHz/125KHz/250KHz/500KHz
// Coding: NRZ
// Packet Format: "HR_WT Lora sx1276_7_8" (total: 21 bytes)
// Tx Current: about 120mA (RFOP=+20dBm,typ.)
// Rx Current: about 11.5mA (typ.)
**********************************************************/
///////////////////////////////////////////////// LoRa mode//////////////////////////////////////////////////
//Error Coding rate (CR)setting
#define CR_4_5
//#define CR_4_6 0
//#define CR_4_7 0
//#define CR_4_8 0
#ifdef CR_4_5
#define CR 0x01 // 4/5
#else
#ifdef CR_4_6
#define CR 0x02 // 4/6
#else
#ifdef CR_4_7
#define CR 0x03 // 4/7
#else
#ifdef CR_4_8
#define CR 0x04 // 4/8
#endif

..............................................


void setup() {
// put your setup code here, to run once:
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(SS, OUTPUT);
pinMode(SCK, OUTPUT);
pinMode(MOSI, OUTPUT);
pinMode(MISO, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
mode = 0x01;//lora mode
Freq_Sel = 0x00;//433Mhz
Power_Sel = 0xFF;//
Lora_Rate_Sel = 0x06;//
BandWide_Sel = 0x07;
Fhss_Rate_Sel = 0x00;
sx1276_7_8_Config();//
sx1276_7_8_LoRaEntryRx();
digitalWrite(LED1, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100);
digitalWrite(LED1, LOW); // turn the LED on (HIGH is the voltage level)
delay(100);// wait for a second
while(1)
{
 
//Master
digitalWrite(LED2, HIGH); // turn the LED on (HIGH is the voltage level)
sx1276_7_8_LoRaEntryTx();
sx1276_7_8_LoRaTxPacket();
digitalWrite(LED2,LOW); // turn the LED on (HIGH is the voltage level)
sx1276_7_8_LoRaEntryRx();
Serial.print("Error en la transmicion!");
delay(1000);
/* if(sx1276_7_8_LoRaRxPacket())
{
digitalWrite(LED2, HIGH); // turn the LED on (HIGH is the voltage level)
delay(2000);
digitalWrite(LED2, LOW); // turn the LED on (HIGH is the voltage level)
delay(2000);
}*/
//slave
/*if(sx1276_7_8_LoRaRxPacket())
{
digitalWrite(LED3, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000);// wait for a second
digitalWrite(LED3, LOW); // turn the LED on (HIGH is the voltage level)
delay(1000);// wait for a second
sx1276_7_8_LoRaEntryRx();
/*digitalWrite(LED3, HIGH); // turn the LED on (HIGH is the voltage level)
sx1276_7_8_LoRaEntryTx();
sx1276_7_8_LoRaTxPacket();
digitalWrite(LED3, LOW); // turn the LED on (HIGH is the voltage level)
sx1276_7_8_LoRaEntryRx();
*/
}
}



The code above is a sample, is not complete because I have a character limit.
  Annex below them ino code.

  But this programming, only helps me with link modules and LED modules comprises a data sending and one receiving.

Any idea how you could modify the code to send a message like "Hello World" or information from a sensor.
  I thank you for your time reading this and for your comments.

Hector_A

Closed for me, this post is duplicated with equal in Spanish.

Regards!

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy