Has anyone used a LowRa module eg talking to the Semtech SX1276

Started by TimB, Jul 03, 2026, 07:55 PM

Previous topic - Next topic

TimB


Hi All

I'm looking to start a project using LowRa and the Semtech SX1276 chip.

Just checking in if anyone has any code?

Thanks

Tim

trastikata

Are you looking for LoRa WAN or custom LoRa? I have a lot of projects with custom LoRa comms at 433 MHz, manufacturing my own (not FCC approved  :) ) modules too for hobby projects.

Example of one of my early LoRa projects here: http://www.blog.exrockets.com/blog/100-mw-433-mhz-long-range-30-km-gps-tracker-kit/


TimB


The aim is to build a custom Type K temperature transmitter network. It will be used in an industrial plant room setting.

The coms will be bursts of TX only every 30 seconds around 35 bytes at a time. Its a broadcast system. If the signal of 1 or 2 nodes is not getting through then they either buy another RX unit or a repeater.

I will need to get full compliance certification EC FCC etc.

Looking to use the Wio-SX1262 LoRa Wireless Module by seed studios.

Custom coms protocol is expected.

433 is probably ideal. 

Is the module you used still available?


trastikata

Hi Tim,

I designed my own modules and ordered small batch, because the ones sold either don't have a TCXO and LNA or they are too expensive.

I can help with the code, but if FCC certification is required, then I guess you'd need certified LoRa modules?




top204

I created some code for the SX126x transceivers last year, with the help of trastikata, but never used it in anything.

It may give you some ideas how to implement it further, so I have attached it below, and I think it is actually already on the forum, along with posts on it.

They are complex critters, and rather difficult to set up.

I also have a simplistic library that I created for the SX1278 transceiver, back in 2022, if that will help.

However, maybe the Ebyte E220 modules would be better for you Tim, as they have a simple serial interface, and can run at very low current (approx 150uA), and are very simple to operate. I have a library for them as well that I have used in a few applications and they are rather good. Simplistic, but good, and have an excellent range.

Regards
Les

TimB


Thanks Les

The Ebyte E220 modules sound great. I'm flitting from one to the other at this time. Its very handy to get a serious recommendation.
My aim is to have 10+ year Broadcast of the temp data every 30 mins. All controlled by a XLP pic. Going to serial would be fantastic. It would save so much development time.

I will have to be careful on the power but at least I'm going in the right direction now

Thanks Tim

shantanu@india

The most difficult part of LoRa @865/868 MHz is not software but the antenna choice. Drastic attenuation can take place if LOS is not maintained.
Regards
Shantanu

TimB


Hi shantanu

I need to make the antenna choice. I'm not really restricted apart from price. Any recommendations? I can have an external with no issues.

BTW I'm going to use a Ebyte E220 module, the antenna choice will dictate the module used.

Thanks

Tim

top204

With the E220 devices, I used two curly pieces of wire as a dipole aerial, and it still had a large range.

I did measure the wire so it was a harmonic measure of the frequency, but I found it was not too critical. And I also measured the current drawn in transmit mode, to make sure it was not overloading, and it wasn't.

Regards
Les

trastikata

Quote from: top204 on Jul 06, 2026, 03:19 PMAnd I also measured the current drawn in transmit mode, to make sure it was not overloading, and it wasn't.

Hi Les,

the SX1278 has a nice future - built in PA current limiting register, one can set it to a safe value, just have to make sure it is sufficient for the desired power output.

top204

The E220 uses the SX1262 or SX1268 devices, and they also have a PA that can be set.

Also, the E220 has a simple set of registers for setting it up, and the value in my E220 library file for them are:

'
' Mode Types
'
$define cE220_MODE_0_NORMAL       0
$define cE220_MODE_1_WAKE_UP      1
$define cE220_MODE_2_POWER_SAVING 2
$define cE220_MODE_3_SLEEP        3
$define cE220_MODE_3_PROGRAM      3
$define cE220_MODE_INIT           $FF
'
' Reg0 values to be ORed together
'
' Serial Baud rate (bits 5 to 7 of Reg0)
'
$define cE220_SERIAL_BAUD_1200      %00000000
$define cE220_SERIAL_BAUD_2400      %00100000
$define cE220_SERIAL_BAUD_4800      %01000000
$define cE220_SERIAL_BAUD_9600      %01100000       ' Default value
$define cE220_SERIAL_BAUD_19200     %10000000
$define cE220_SERIAL_BAUD_38400     %10100000
$define cE220_SERIAL_BAUD_57600     %11000000
$define cE220_SERIAL_BAUD_115200    %11100000
'
' Serial Mode (bits 3 and 4 of Reg0)
'
$define cE220_SERIAL_MODE_8N1       %00000000       ' Default value
$define cE220_SERIAL_MODE_8O1       %00001000
$define cE220_SERIAL_MODE_8E1       %00010000
'
' Air Data Rate (bps) (bits 0 to 2 of Reg0)
'
$define cE220_2_4K                  %00000010       ' Default value
$define cE220_4_8K                  %00000011
$define cE220_9_6K                  %00000100
$define cE220_19_2K                 %00000101
$define cE220_38_4K                 %00000110
$define cE220_62_5K                 %00000111
'
' Reg1 values to be ORed together
'
' Sub Packet (bytes) (bits 6 and 7 of Reg1)
'
$define cE220_SUB_PACKET_200        %00000000       ' Default value
$define cE220_SUB_PACKET_128        %01000000
$define cE220_SUB_PACKET_64         %10000000
$define cE220_SUB_PACKET_32         %11000000
'
' RSSI Ambient Noise Enable/Disable (bit 5 of Reg1)
'
$define cE220_RSSI_AMBIENT_ON       %00100000
$define cE220_RSSI_AMBIENT_OFF      %00000000       ' Default value
'
' Transmit Power (dBm) (bits 0 and 1 of Reg1)
'
$ifndef _E220_90022D    ' This set of defines for an E220_900T30D module
    $define cE220_TRANSMIT_POWER_30     %00000000       ' Default value
    $define cE220_TRANSMIT_POWER_27     %00000001
    $define cE220_TRANSMIT_POWER_24     %00000010
    $define cE220_TRANSMIT_POWER_21     %00000011
$else                   ' This set of defines for an E220_900T22D module
    $define cE220_TRANSMIT_POWER_22     %00000000       ' Default value
    $define cE220_TRANSMIT_POWER_17     %00000001
    $define cE220_TRANSMIT_POWER_13     %00000010
    $define cE220_TRANSMIT_POWER_10     %00000011
$endif
'
' Reg2 value
' Channel Control (0 to 255) (bits 0 to 7 of reg2)
'
' Reg3 values to be ORed together
'
$define cE220_RSSI_ON               %10000000
$define cE220_RSSI_OFF              %00000000       ' Default value

$define cE220_TRANSPARENT_MODE      %00000000       ' Default value
$define cE220_FIXED_MODE            %01000000

$define cE220_LBT_ON                %00010000
$define cE220_LBT_OFF               %00000000       ' Default value

$define cE220_WOR_500MS             %00000000
$define cE220_WOR_1000MS            %00000001
$define cE220_WOR_1500MS            %00000010
$define cE220_WOR_2000MS            %00000011
$define cE220_WOR_2500MS            %00000100
$define cE220_WOR_3000MS            %00000101
$define cE220_WOR_3500MS            %00000110
$define cE220_WOR_4000MS            %00000111

Notice the "cE220_TRANSMIT_POWER_xx" constant values?

If the lower power is used, it still has quite a bit of range, and the transmit current goes down.

To configure the E220, it uses simple async serial, and in operation, it acts like a full duplex serial interface, with a bit of lag because of the LoRA and when not in close range:

' Configure the E220 module
' Input     : E220_bChannel
'           : E220_wAddress
'           : E220_bReg0
'           : E220_bReg1
'           : E220_bReg3
' Output    : Returns false if a problem occurred
'           : Fills the array "E220_ConfigArray" with the config values received
' Notes     : Sets the mode back to normal when complete
'
Proc E220_SetConfigure(), Bit
    Dim bIndex As PRODL
   
    E220_SetMode(cE220_MODE_3_SLEEP)                ' Place the E220 module into Sleep/Config mode before writing

    HRSOut2 $C0, $00, $08,                          ' Send the command for a write and 8 bytes to write
            E220_wAddress.Byte1,                    ' Send the high byte of the address
            E220_wAddress.Byte0,                    ' Send the low byte of the address
            E220_bReg0,                             ' Send the Reg0 value
            E220_bReg1,                             ' Send the Reg1 value
            E220_bChannel,                          ' Send the Channel value (Reg2)
            E220_bReg3,                             ' Send the Reg3 value
            E220_wCrypt.Byte1,                      ' Send the CRYPT high byte
            E220_wCrypt.Byte0                       ' Send the CRYPT low byte
'
' Wait for the 11 values for the configuration
'
    For bIndex = 0 To 10
        HSerIn2 1000, TimedOut, [E220_ConfigArray[bIndex]]
    Next
    E220_SetMode(cE220_MODE_0_NORMAL)
    Result = True
    ExitProc
'
' Jump here if a time out occurs while waiting for the data
'
TimedOut:
    'HRSOut1Ln "E220_SetConfigure Timed Out"
    E220_SetMode(cE220_MODE_0_NORMAL)
    Result = False                                  ' Return a false result
EndProc

Regards
Les

TimB



Thanks Les

I will be TX only but this code is perfect for my needs

Also I will use software bit banging but that is just a simple change to rsout

shantanu@india

Hi Tim,
I have tried the most expensive  omnidirectional antenna around sold by RAKWireless....but still I did not get the desired results indoor. LoRa advertises 10km but to get that you need clear LOS & preferable Yagi.
I am yet to complete my experiment which would be at high rise buildings. I'll DM you my results.
Best of luck.
Regards
Shantanu

trastikata

Quote from: shantanu@india on Jul 07, 2026, 12:44 PMvariant=37636812734662"]antenna[/url] around sold by RAKWireless....but still I did not get the desired results indoor. LoRa advertises 10km but to get that you need clear LOS & preferable Yagi.

Hi shantanu,

With 100mW transmission power and a cheap Aliexpress whip antenna I get +30km when direct LOS and +18km with no LOS and transmitter literally on the ground and hills between the receiver and the transmitter. And this is not with maximum range settings.

There must be something amiss in the settings to get such a short range.

P.s. I also had poor results with SX126x , whereas SX1278 performs excellent.

top204

The complete include file is listed below.

$ifndef _E220_INC_
$define _E220_INC_
'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' EByte E220 LoRa Module routines
' Written by Les Johnson for the Positron8 BASIC compiler.
'
' Set the pins to use for an E220 module
'
$ifndef E220_M0_Pin
    $define E220_M0_Pin PORTA.0                         ' Connects to the E220 module's M0 pin
$endif
$ifndef E220_M1_Pin
    $define E220_M1_Pin PORTA.1                         ' Connects to the E220 module's M1 pin
$endif
$ifndef E220_M1_Pin
    $define E220_Aux_Pin PORTA.2                        ' Connects to the E220 module's AUX pin
$endif

$ifndef E220_TX_Pin
    $define E220_TX_Pin PORTC.4                         ' Connects to the E220 module's TX pin
$endif
$ifndef E220_RX_Pin
    $define E220_RX_Pin PORTC.5                         ' Connects to the E220 module's RX pin
$endif
'
' Setup USART2 (communicates with the E220 module)
'
    Declare HRSOut2_Pin   = E220_RX_Pin                 ' Connects to the E220 module's RX pin
    Declare HRSIn2_Pin    = E220_TX_Pin                 ' Connects to the E220 module's TX pin
    Declare Hserial2_Baud = 9600
'
' Mode Types
'
$define cE220_MODE_0_NORMAL       0
$define cE220_MODE_1_WAKE_UP      1
$define cE220_MODE_2_POWER_SAVING 2
$define cE220_MODE_3_SLEEP        3
$define cE220_MODE_3_PROGRAM      3
$define cE220_MODE_INIT           $FF
'
' Reg0 values to be ORed together
'
' Serial Baud rate (bits 5 to 7 of Reg0)
'
$define cE220_SERIAL_BAUD_1200      %00000000
$define cE220_SERIAL_BAUD_2400      %00100000
$define cE220_SERIAL_BAUD_4800      %01000000
$define cE220_SERIAL_BAUD_9600      %01100000       ' Default value
$define cE220_SERIAL_BAUD_19200     %10000000
$define cE220_SERIAL_BAUD_38400     %10100000
$define cE220_SERIAL_BAUD_57600     %11000000
$define cE220_SERIAL_BAUD_115200    %11100000
'
' Serial Mode (bits 3 and 4 of Reg0)
'
$define cE220_SERIAL_MODE_8N1       %00000000       ' Default value
$define cE220_SERIAL_MODE_8O1       %00001000
$define cE220_SERIAL_MODE_8E1       %00010000
'
' Air Data Rate (bps) (bits 0 to 2 of Reg0)
'
$define cE220_2_4K                  %00000010       ' Default value
$define cE220_4_8K                  %00000011
$define cE220_9_6K                  %00000100
$define cE220_19_2K                 %00000101
$define cE220_38_4K                 %00000110
$define cE220_62_5K                 %00000111
'
' Reg1 values to be ORed together
'
' Sub Packet (bytes) (bits 6 and 7 of Reg1)
'
$define cE220_SUB_PACKET_200        %00000000       ' Default value
$define cE220_SUB_PACKET_128        %01000000
$define cE220_SUB_PACKET_64         %10000000
$define cE220_SUB_PACKET_32         %11000000
'
' RSSI Ambient Noise Enable/Disable (bit 5 of Reg1)
'
$define cE220_RSSI_AMBIENT_ON       %00100000
$define cE220_RSSI_AMBIENT_OFF      %00000000       ' Default value
'
' Transmit Power (dBm) (bits 0 and 1 of Reg1)
'
$ifndef _E220_90022D    ' This set of defines for an E220_900T30D module
    $define cE220_TRANSMIT_POWER_30     %00000000       ' Default value
    $define cE220_TRANSMIT_POWER_27     %00000001
    $define cE220_TRANSMIT_POWER_24     %00000010
    $define cE220_TRANSMIT_POWER_21     %00000011
$else                   ' This set of defines for an E220_900T22D module
    $define cE220_TRANSMIT_POWER_22     %00000000       ' Default value
    $define cE220_TRANSMIT_POWER_17     %00000001
    $define cE220_TRANSMIT_POWER_13     %00000010
    $define cE220_TRANSMIT_POWER_10     %00000011
$endif
'
' Reg2 value
' Channel Control (0 to 255) (bits 0 to 7 of reg2)
'
' Reg3 values to be ORed together
'
$define cE220_RSSI_ON               %10000000
$define cE220_RSSI_OFF              %00000000       ' Default value

$define cE220_TRANSPARENT_MODE      %00000000       ' Default value
$define cE220_FIXED_MODE            %01000000

$define cE220_LBT_ON                %00010000
$define cE220_LBT_OFF               %00000000       ' Default value

$define cE220_WOR_500MS             %00000000
$define cE220_WOR_1000MS            %00000001
$define cE220_WOR_1500MS            %00000010
$define cE220_WOR_2000MS            %00000011
$define cE220_WOR_2500MS            %00000100
$define cE220_WOR_3000MS            %00000101
$define cE220_WOR_3500MS            %00000110
$define cE220_WOR_4000MS            %00000111
'
$define cE220_MAX_SIZE_TX_PACKET 64                 ' Alter this to match the "Sub Packet" value in Reg1. Chosen when setting up the E220 module

$ifndef True
    $define True 1
$endif
$ifndef False
    $define False 0
$endif
'
' Create some variables
'
    Dim E220_PacketArray[cE220_MAX_SIZE_TX_PACKET + 1] As Byte Heap     ' Holds the data packet data to send and receive
    Dim E220_PacketString    As String * cE220_MAX_SIZE_TX_PACKET At E220_PacketArray ' Holds the strings to send and receive
    Dim E220_ConfigArray[12] As Byte Heap                   ' Holds the config data received

    Dim E220_bMode    As Byte                               ' Holds the E220 mode. Altered by the M0 and M1 pins
    Dim E220_wAddress As Word Access = $0000                ' Holds the E220 16-bit address value
    Dim E220_bReg0    As Byte Access                        ' Holds the E220 REG0 value
    Dim E220_bReg1    As Byte Access                        ' Holds the E220 REG1 value
    Dim E220_bChannel As Byte Access = 23                   ' Holds the E220 channel value (REG2)
    Dim E220_bReg3    As Byte Access                        ' Holds the E220 REG3 value
    Dim E220_wCrypt   As Word = $0000                       ' Holds the E220 16-bit CRYPT_H and CRYPT_L registers value

'-------------------------------------------------------------------------------------------------------------
' Setup the 16-bit address for the E220 module
' Input     : pAddress holds the address value required
' Output    : None
' Notes     : Must call the E220_SetConfigure procedure to perform the change
'
$define E220_SetAddress(pAddress) E220_wAddress = pAddress

'-------------------------------------------------------------------------------------------------------------
' Setup the 8-bit channel for the E220 module
' Input     : pChannel holds the address value required
' Output    : None
' Notes     : Must call the E220_SetConfigure procedure to perform the change
'
$define E220_SetChannel(pChannel) E220_bChannel = pChannel

'-------------------------------------------------------------------------------------------------------------
' Setup Reg0 for the E220 module
' Input     : pValue holds the value to place into the register:
'               cE220_SERIAL_BAUD_1200
'               cE220_SERIAL_BAUD_2400
'               cE220_SERIAL_BAUD_4800
'               cE220_SERIAL_BAUD_9600          ' Default value
'               cE220_SERIAL_BAUD_19200
'               cE220_SERIAL_BAUD_38400
'               cE220_SERIAL_BAUD_57600
'               cE220_SERIAL_BAUD_115200
'             Serial Mode (bits 3 and 4 of Reg0)
'               cE220_SERIAL_MODE_8N1           ' Default value
'               cE220_SERIAL_MODE_8O1
'               cE220_SERIAL_MODE_8E1
'             Air Data Rate (bps) (bits 0 to 2 of Reg0)
'               cE220_2_4K                      ' Default value
'               cE220_4_8K
'               cE220_9_6K
'               cE220_19_2K
'               cE220_38_4K
'               cE220_62_5K
' Output    : None
' Notes     : Must call the E220_SetConfigure procedure to perform the change
'
$define E220_Set_Reg0(pValue) E220_bReg0 = pValue

'-------------------------------------------------------------------------------------------------------------
' Setup Reg0 for the E220 module
' Input     : pValue holds the value to place into the register:
'             Sub Packet (bytes) (bits 6 and 7 of Reg1)
'               cE220_SUB_PACKET_200            ' Default value
'               cE220_SUB_PACKET_128
'               cE220_SUB_PACKET_64
'               cE220_SUB_PACKET_32
'
'             RSSI Ambient Noise Enable/Disable (bit 5 of Reg1)
'
'               cE220_RSSI_AMBIENT_ON
'               cE220_RSSI_AMBIENT_OFF          ' Default value
'
'             Transmit Power (dBm) (bits 0 and 1 of Reg1)
'
'               cE220_TRANSMIT_POWER_30         ' Default value
'               cE220_TRANSMIT_POWER_27
'               cE220_TRANSMIT_POWER_24
'               cE220_TRANSMIT_POWER_21
' Output    : None
' Notes     : Must call the E220_SetConfigure procedure to perform the change
'
$define E220_Set_Reg1(pValue) E220_bReg1 = pValue

'-------------------------------------------------------------------------------------------------------------
' Setup Reg3 for the E220 module
' Input     : pValue holds the value to place into the register:
'               cE220_RSSI_ON
'               cE220_RSSI_OFF                  ' Default value
'
'               cE220_TRANSPARENT_MODE          ' Default value
'               cE220_FIXED_MODE
'
'               cE220_LBT_ON
'               cE220_LBT_OFF                   ' Default value
'
'               cE220_WOR_500MS
'               cE220_WOR_1000MS
'               cE220_WOR_1500MS
'               cE220_WOR_2000MS                ' Default value
'               cE220_WOR_2500MS
'               cE220_WOR_3000MS
'               cE220_WOR_3500MS
'               cE220_WOR_4000MS
' Output    : None
' Notes     : Must call the E220_SetConfigure procedure to perform the change
'
$define E220_Set_Reg3(pValue) E220_bReg3 = pValue

'-------------------------------------------------------------------------------------------------------------
' Setup 16-bit CRYPT value for the E220 module
' Input     : pValue holds the value to place into the registers
' Output    : None
' Notes     : Must call the E220_SetConfigure procedure to perform the change
'
$define Set_CRYPT(pValue) E220_wCrypt = pValue

'-------------------------------------------------------------------------------------------------------------
' Configure the E220 module
' Input     : E220_bChannel
'           : E220_wAddress
'           : E220_bReg0
'           : E220_bReg1
'           : E220_bReg3
' Output    : Returns false if a problem occurred
'           : Fills the array "E220_ConfigArray" with the config values received
' Notes     : Sets the mode back to normal when complete
'
Proc E220_SetConfigure(), Bit
    Dim bIndex As PRODL

    E220_SetMode(cE220_MODE_3_SLEEP)                ' Place the E220 module into Sleep/Config mode before writing

    HRSOut2 $C0, $00, $08,                          ' Send the command for a write and 8 bytes to write
            E220_wAddress.Byte1,                    ' Send the high byte of the address
            E220_wAddress.Byte0,                    ' Send the low byte of the address
            E220_bReg0,                             ' Send the Reg0 value
            E220_bReg1,                             ' Send the Reg1 value
            E220_bChannel,                          ' Send the Channel value (Reg2)
            E220_bReg3,                             ' Send the Reg3 value
            E220_wCrypt.Byte1,                      ' Send the CRYPT high byte
            E220_wCrypt.Byte0                       ' Send the CRYPT low byte
'
' Wait for the 11 values for the configuration
'
    For bIndex = 0 To 10
        HSerIn2 1000, TimedOut, [E220_ConfigArray[bIndex]]
    Next
'
' For debugging, display the values received from the config on a serial terminal
'
(*
TimedOut:
    HRSOut1Ln IHex2 E220_ConfigArray[0], ",",
             IHex2 E220_ConfigArray[1], ",",
             IHex2 E220_ConfigArray[2], ",",
             IHex2 E220_ConfigArray[3], ",",
             IHex2 E220_ConfigArray[4], ",",
             IHex2 E220_ConfigArray[5], ",",
             IHex2 E220_ConfigArray[6], ",",
             IHex2 E220_ConfigArray[7], ",",
             IHex2 E220_ConfigArray[8], ",",
             IHex2 E220_ConfigArray[9], ",",
             IHex2 E220_ConfigArray[10]
*)
    E220_SetMode(cE220_MODE_0_NORMAL)
    ExitProc
'
' Jump here if a time out occurs while waiting for the data
'
TimedOut:
    'HRSOut1Ln "E220_SetConfigure Timed Out"
    E220_SetMode(cE220_MODE_0_NORMAL)
    Result = False                                  ' Return a false result
EndProc

'-------------------------------------------------------------------------------------------------------------
' Read the Configure from the E220 module
' Input     : None
' Output    : Returns false if a problem occurred
'           : Fills the array "E220_ConfigArray" with the config values received
' Notes     : Sets the mode back to normal when complete
'
Proc E220_GetConfigure(), Bit
    Dim bIndex As PRODL
    Dim ByteIn As PRODH

    Result = True                                   ' Default to a true result
    E220_SetMode(cE220_MODE_3_SLEEP)                ' Place the E220 module into Sleep/Config mode before reading
    Clear E220_ConfigArray                          ' Clear the E220_ConfigArray before sending the commands

    HRSOut2 $C1, $00, $08                           ' Send the command to read the configs
'
' Wait for the 11 values for the configuration
'
    For bIndex = 0 To 10
        HSerIn2 1000, TimedOut, [E220_ConfigArray[bIndex]]
    Next
'
' For debugging, display the values received from the config on a serial terminal
'
(*
TimedOut:
    HRSOut1Ln IHex2 E220_ConfigArray[0], ",",
             IHex2 E220_ConfigArray[1], ",",
             IHex2 E220_ConfigArray[2], ",",
             IHex2 E220_ConfigArray[3], ",",
             IHex2 E220_ConfigArray[4], ",",
             IHex2 E220_ConfigArray[5], ",",
             IHex2 E220_ConfigArray[6], ",",
             IHex2 E220_ConfigArray[7], ",",
             IHex2 E220_ConfigArray[8], ",",
             IHex2 E220_ConfigArray[9], ",",
             IHex2 E220_ConfigArray[10]
*)
    E220_SetMode(cE220_MODE_0_NORMAL)
    ExitProc
'
' Jump here if a time out occurs while waiting for the data
'
TimedOut:
    'HRSOut1Ln "E220_GetConfigure Timed Out"
    E220_SetMode(cE220_MODE_0_NORMAL)
    Result = False                                  ' Return a false result
EndProc

'-------------------------------------------------------------------------------------------------------------
' Set the mode of the E220 module
' Input     : pMode holds the mode to set
' Output    : Returns false if a problem occurs
' Notes     : Keeps a record of the previous mode, so it will not set it the same
'           : This saves time.
'
Proc E220_SetMode(pMode As Byte), Bit
    Result = True
    If E220_bMode = pMode Then                      ' Is the mode, the same as the previous mode?
        ExitProc                                    ' Yes. So exit the procedure
    EndIf
    DelayMS 100
    If pMode = cE220_MODE_0_NORMAL Then             ' Mode 0. Normal operation?
        PinLow E220_M0_Pin
        PinLow E220_M1_Pin
    ElseIf pMode = cE220_MODE_1_WAKE_UP Then        ' Mode 1?
        PinHigh E220_M0_Pin
        PinLow E220_M1_Pin
    ElseIf pMode = cE220_MODE_2_POWER_SAVING Then   ' Mode 2?
        PinLow E220_M0_Pin
        PinHigh E220_M1_Pin
    ElseIf pMode = cE220_MODE_3_SLEEP Then          ' Mode 3. Setting operation?
        PinHigh E220_M0_Pin
        PinHigh E220_M1_Pin
    Else
        Result = False
    EndIf
    If Result = True Then
        E220_bMode = pMode
    EndIf
    DelayMS 512
EndProc

'-------------------------------------------------------------------------------------------------------------
' Set the default configurations in an E220 module
' Input     : None
' Output    : Returns false if a problem occures
' Notes     : None
'
Proc E220_SetDefaults(), Bit
    Dim Attempts As Byte

    E220_SetAddress($0000)
    E220_SetChannel(23)
    E220_Set_Reg0(cE220_SERIAL_BAUD_9600 | cE220_SERIAL_MODE_8N1 | cE220_2_4K)
    E220_Set_Reg1(cE220_SUB_PACKET_200 | cE220_RSSI_AMBIENT_OFF | cE220_TRANSMIT_POWER_30)
    E220_Set_Reg3(cE220_RSSI_OFF | cE220_TRANSPARENT_MODE | cE220_LBT_OFF | cE220_WOR_2000MS)

    Result = True
    For Attempts = 10 DownTo 0
        If E220_SetConfigure() = True Then
            ExitProc
        EndIf
        DelayMS 1000
    Next
    Result = False
EndProc

'-------------------------------------------------------------------------------------------------------------
' Setup the E220 library
' Input     : None
' Output    : None
' Notes     : Mode is defaulted to mode 0 for normal
'
Proc E220_Setup()
    PinLow E220_M0_Pin                  ' Set the M0 pin low
    PinLow E220_M1_Pin                  ' Set the M1 pin low

    PinInput E220_TX_Pin                ' Make the TX pin an input (requires a pull-up resistor)
    PinOutput E220_RX_Pin               ' Make the RX pin an output

    E220_bMode = cE220_MODE_0_NORMAL
    DelayMS 100                        ' Wait before returning
EndProc

$endif  ' _E220_INC_

Once the E220 has been configured for its channel (actually its frequency), and its address, it is simply a case of using it as a UART, with the TX and RX pins (reversed notation on them, so TX is actually RX, and vice-versa). It caught me out for a little while, when I was designing the code from the "utterly" dreadful datasheet. :-)

Make sure you connect the M0, M1, and the Aux pin, to the microcontroller. Because once in deep sleep mode, the Aux pin is used as an interrupt, and can wake the PIC device when it receives something.

Regards
Les



TimB


Thanks so much for the help. Its really appreciated

I'm toying with the idea of power cycling the system with a P-FET to turn it off between my 30 min TX bursts
Not sure if this will actually save me power over just using M1 and M2 to put it into sleep mode.
Do not know if I will have to resend the settings every time. I had heard that it remembers the settings during power outages.

I really need to eek every ounce of power out of my batteries. 10 year + life
Since the batteries have very little instant power abilities I will be adding a 0.22F supercap LOW ESR device and Pfet the charging of it. S caps I understand are not great when it comes to leakage. So limiting when the power can get into it will be handy.

BTW I also need to talk to a MCP9601 for a K type. That will be power strangled also. The duty of that is every 30 seconds.


top204

You are very welcome Tim.

The E220 will draw approx 120ua to 150uA when in deep sleep mode, and when it is woken via a receive, it brings the Aux line low, which can be connected to the PIC's INT0 pin, so wake it up, and start receiving the rest of the data. I had the whole receiver, using a PIC18F26K40 device, down to approx 130uA when the E220 was in sleep mode, and receiving data woke it up and allowed full communications.

There is a lag between tx and rx when in low power mode, but that is not really a problem if it is not over-fast data that needs to be sent/received.

Using the $C0 code for setting the configs, also saves them. So even if the device is powered off, it will remember the settings and its channel and address etc...

Regards
Les

JonW

I think a lot of people get the antenna choice and mounting wrong, and it can make a huge difference.

A quarter-wave whip is only half an antenna. It works against its ground plane, which needs to extend at least a quarter wavelength from the base - about 8.5cm at 868MHz, or 17cm at 433MHz (whip lengths roughly 8.2cm and 16.4cm respectively). Four quarter-wave radials work fine if you don't have a solid sheet. With that, the whip is resonant, well-matched and efficient - and 30km on 100 mW with line of sight and some height is entirely believable.
Screw the same whip onto a small PCB or plastic box with no real ground plane, and everything changes: it detunes, the match goes off, and the coax or PCB tracks become part of the antenna. You lose several dB and the pattern goes unpredictable - move a cable and the range changes. That's the "terrible" report. Same whip, different antenna system.
The other big factor is height and polarisation. Near the ground the earth cancels the signal at low angles, so keep the whip vertical and get it up in the air - beyond a short distance, doubling the height at both ends is worth about 12dB, far more than extra TX power. And match polarisation: a horizontal whip talking to a vertical gateway loses up to 20dB in clear line of sight.
Quarter-wave whip, vertical, proper ground plane, mounted high: 30km is realistic. Same whip flat on a tiny PCB at ground level: a few hundred metres.