Firmware one direction serial data transmission

Support and help for the OpenLRSng project.

Moderator: kha

Post Reply
franpantano
Posts: 5
Joined: Thu Oct 22, 2015 9:36 am
Country: -

Firmware one direction serial data transmission

Post by franpantano »

Hello,

I am developing a project where I want to send back from the model the serial NMEA data from a 10Hz gps. I got two OpenLRS v2 receivers and have modified the 1.12 firmware version code to try to do the work I pretend.

I want just one direction transmission, no hopping, and only serial data.

I can program the boards with no problem, but seems something is not working properly as I do not get anything at the receiver end.

Would you please take a look at the code I am dealing with and suggest changes?

Thanks a lot




#include <Arduino.h>

#include "config.h"
#include "functions.h"
#include "rfm22b.h"

void setup() {


//LEDs
pinMode(GREEN_LED_pin, OUTPUT);
pinMode(RED_LED_pin, OUTPUT);

//RF module pins
pinMode(SDO_pin, INPUT); //SDO
pinMode(SDI_pin, OUTPUT); //SDI
pinMode(SCLK_pin, OUTPUT); //SCLK
pinMode(IRQ_pin, INPUT); //IRQ
pinMode(nSel_pin, OUTPUT); //nSEL


pinMode(0, INPUT); // Serial Rx
pinMode(1, OUTPUT);// Serial Tx


pinMode(RSSI_OUT, OUTPUT); //RSSI pinout

Serial.begin(SERIAL_BAUD_RATE); //Serial Transmission

#if (COMPILATION_TX == 0)
attachInterrupt(IRQ_interrupt, RFM22B_Int, FALLING);
#endif
}



//############ MAIN LOOP ##############
void loop() {

unsigned char i, tx_data_length;
unsigned char first_data = 0;


Red_LED_ON;

RF22B_init_parameter(); // Configure the RFM22B's registers

frequency_configurator(CARRIER_FREQUENCY); // Calibrate the RFM22B to this frequency, frequency hopping starts from here.

to_rx_mode();

sei();


//Hop to first frequency from Carrier
Hopping();

delay(1000);
Red_LED_OFF;
Green_LED_ON;
delay(1000);
Green_LED_OFF;
#if (COMPILATION_TX == 1)
Red_LED_ON;
delay(1000);
Red_LED_OFF;
#endif

RF_Mode = Receive;

while (1) { /* MAIN LOOP */

if (_spi_read(0x0C) == 0) {
Red_LED_ON;
RF22B_init_parameter(); // detect the locked module and reboot
to_rx_mode();
}


#if (COMPILATION_TX == 0)
if (RF_Mode == Received) // RFM22B INT pin Enabled by received Data
{
Red_LED_OFF;
Green_LED_ON;


send_read_address(0x7f); // Send the package read command

for (i = 0; i < RF_PACK_SIZE; i++) //read all buffer
{
RF_Rx_Buffer = read_8bit_data();
}
rx_reset();

if (RF_Rx_Buffer[0] == 'B') // Brige values
{
for (i = 2; i < RF_Rx_Buffer[1] + 2; i++) //write serial
Serial.print(RF_Rx_Buffer);
}

Rx_RSSI = _spi_read(0x26); // Read the RSSI value

//***************************************
//* thUndead's RSSI MOD
//* info: RSSI voltage according to avg rssi value
rssicounter++; //counter which resets after getting to 41

if (rssicounter <= 40) rssipwm = rssipwm + Rx_RSSI ; //adds values into temp buffer
else rssicounter = 0;

if (rssicounter == 40)
{
rssipwm = rssipwm / 40; // averege 40 rssi values to get stable reading
rssibuf = map(rssipwm, 40, 120, 10, 250); //map value for pwm: MAX = 2.6v bad rssi unver 1 v
analogWrite(RSSI_OUT, rssibuf); //write the RSSI voltage
rssipwm = 0;
}



RF_Mode = Receive;

Green_LED_OFF;

}
#endif

#if (COMPILATION_TX == 1)
//######## TELEMETRY TRANSPARENT BRIDGE #########
byte total_rx_byte = Serial.available(); // Read the Serial RX buffer size
if (total_rx_byte > 0)
{
Red_LED_OFF;
Green_LED_ON;

if (total_rx_byte > RF_PACK_SIZE-2) total_rx_byte = RF_PACK_SIZE-2; // Limit the package size as 15 byte

RF_Tx_Buffer[0] = 'B'; // Brige command
RF_Tx_Buffer[1] = total_rx_byte;

for (byte i = 0; i < total_rx_byte; i++)
RF_Tx_Buffer[2 + i] = Serial.read();

to_tx_mode();
rx_reset();

Green_LED_OFF;
}
#endif


}


}

franpantano
Posts: 5
Joined: Thu Oct 22, 2015 9:36 am
Country: -

Re: Firmware one direction serial data transmission

Post by franpantano »

Hello,

Some updates:

I did manage to make it work just once... Seems to be something at the receiver side initializing the rf module as just plugging and unplugging the board, suddenly it worked, but then I tried to do it again and no luck.

The code should be close to the good one, just need some help from the people that have more experience programming this device.

Thanks
User avatar
Kilrah
Posts: 11108
Joined: Sat Feb 18, 2012 6:56 pm
Country: Switzerland

Re: Firmware one direction serial data transmission

Post by Kilrah »

I've moved this thread to OpenLRSng section as I suppose it's what it relates to. Definitely isn't about an er9x model template ;)
franpantano
Posts: 5
Joined: Thu Oct 22, 2015 9:36 am
Country: -

Re: Firmware one direction serial data transmission

Post by franpantano »

Hello,

More updates...

I have managed the modules to talk each other. it seems I have to turn on the receiver first and then the transmitter. The code above is ok but, Now I am having the issue that I am not receiving the nmea data from the gps at the receiver end, instead a series of numbers... Any idea why is this happening?
franpantano
Posts: 5
Joined: Thu Oct 22, 2015 9:36 am
Country: -

Re: Firmware one direction serial data transmission

Post by franpantano »

Solved...

serial.print must be replaced by serial.write in order to get the ascii characters.

The code above is working perfectly so far.

franpantano
Posts: 5
Joined: Thu Oct 22, 2015 9:36 am
Country: -

Re: Firmware one direction serial data transmission

Post by franpantano »

Hello,

Currently I am working with the development and want to share the working code that sends the reduced NMEA GPGGA sentence through the OpenLRS system. I say reduced as I am sending only the portion of the sentence that have valuable information in order to optimize the air transmission.

So far, I need to switch on the receiver first and then the transmitter if I want the modules to talk each other. Anyone knows why is this happening?


#include <Arduino.h>

#include "config.h"
#include "functions.h"
#include "rfm22b.h"

void setup() {


//LEDs
pinMode(GREEN_LED_pin, OUTPUT);
pinMode(RED_LED_pin, OUTPUT);

//RF module pins
pinMode(SDO_pin, INPUT); //SDO
pinMode(SDI_pin, OUTPUT); //SDI
pinMode(SCLK_pin, OUTPUT); //SCLK
pinMode(IRQ_pin, INPUT); //IRQ
pinMode(nSel_pin, OUTPUT); //nSEL


pinMode(0, INPUT); // Serial Rx
pinMode(1, OUTPUT);// Serial Tx


pinMode(RSSI_OUT, OUTPUT); //RSSI pinout

Serial.begin(SERIAL_BAUD_RATE); //Serial Transmission

#if (COMPILATION_TX == 0)
attachInterrupt(IRQ_interrupt, RFM22B_Int, FALLING);
#endif
}



//############ MAIN LOOP ##############
void loop() {

unsigned int i;
byte c;

Red_LED_ON;

RF22B_init_parameter(); // Configure the RFM22B's registers

frequency_configurator(CARRIER_FREQUENCY); // Calibrate the RFM22B to this frequency, frequency hopping starts from here.

to_rx_mode();

sei();


//Hop to first frequency from Carrier
Hopping();

delay(1000);
Red_LED_OFF;
Green_LED_ON;
delay(1000);
Green_LED_OFF;
#if (COMPILATION_TX == 1)
Red_LED_ON;
delay(1000);
Red_LED_OFF;

//Configurando GPS
delay(1000);

Green_LED_ON;
while (Serial.available()) // Read the Serial RX buffer
Serial.read();
Serial.println("");
Serial.println("OpenLRS TX starting...");
Green_LED_OFF;

delay(3000);

while (Serial.available()) // Read the Serial RX buffer
Serial.read();

Serial.println("Waiting for GPS to connect...");
while (Serial.available() < RF_PACK_SIZE) ; // Waiting for GPS

Green_LED_ON;
while (Serial.available()) // Read the Serial RX buffer
Serial.read();
Serial.println("$PMTK314,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29"); //GGA only
Green_LED_OFF;

delay(1000);

Green_LED_ON;
while (Serial.available()) // Read the Serial RX buffer
Serial.read();
Serial.println("$PMTK220,100*2F"); //10 Hz
Green_LED_OFF;

#endif
#if (COMPILATION_TX == 0)
Serial.println("");
Serial.println("OpenLRS RX starting...");
#endif

RF_Mode = Receive;

while (1) { /* MAIN LOOP */

if (_spi_read(0x0C) == 0) {
Red_LED_ON;
RF22B_init_parameter(); // detect the locked module and reboot
to_rx_mode();
}


#if (COMPILATION_TX == 0)
if (RF_Mode == Received) // RFM22B INT pin Enabled by received Data
{
Red_LED_OFF;
Green_LED_ON;


send_read_address(0x7f); // Send the package read command

for (i = 0; i < RF_PACK_SIZE; i++) //read all buffer
{
RF_Rx_Buffer = read_8bit_data();
}
rx_reset();

if (RF_Rx_Buffer[0] == 'B') // Brige values
{
for (i = 2; i < RF_Rx_Buffer[1] + 2; i++) //write serial
Serial.write(RF_Rx_Buffer);
}

Rx_RSSI = _spi_read(0x26); // Read the RSSI value

//***************************************
//* thUndead's RSSI MOD
//* info: RSSI voltage according to avg rssi value
rssicounter++; //counter which resets after getting to 41

if (rssicounter <= 40) rssipwm = rssipwm + Rx_RSSI ; //adds values into temp buffer
else rssicounter = 0;

if (rssicounter == 40)
{
rssipwm = rssipwm / 40; // averege 40 rssi values to get stable reading
rssibuf = map(rssipwm, 40, 120, 10, 250); //map value for pwm: MAX = 2.6v bad rssi unver 1 v
analogWrite(RSSI_OUT, rssibuf); //write the RSSI voltage
rssipwm = 0;
}



RF_Mode = Receive;

Green_LED_OFF;

}
#endif

#if (COMPILATION_TX == 1)
while (Serial.available() == 0) ; // Wait for Serial data
if (Serial.read() == '$') {
while (Serial.available() == 0) ; // Wait for Serial data
if (Serial.read() == 'G') {
while (Serial.available() == 0) ; // Wait for Serial data
if (Serial.read() == 'P') {
while (Serial.available() == 0) ; // Wait for Serial data
if (Serial.read() == 'G') {
while (Serial.available() == 0) ; // Wait for Serial data
if (Serial.read() == 'G') {
while (Serial.available() == 0) ; // Wait for Serial data
if (Serial.read() == 'A') {
while (Serial.available() == 0) ; // Wait for Serial data
if (Serial.read() == ',') {
Red_LED_OFF;
Green_LED_ON;

i = 0;
while (Serial.available() == 0) ; // Wait for Serial data
c = Serial.read();

while ((c != '*') && (i+3 < RF_PACK_SIZE)) {
RF_Tx_Buffer[i + 2] = c;
i++;

while (Serial.available() == 0) ; // Wait for Serial data
c = Serial.read();
}
RF_Tx_Buffer[i+2] = '\n';
i++;

RF_Tx_Buffer[0] = 'B'; // Brige command
RF_Tx_Buffer[1] = i;

to_tx_mode();

Green_LED_OFF;
}
}
}
}
}
}
}
#endif


}


}

Post Reply

Return to “OpenLRSng”