Reference
MicroPython class for EBYTE E32 Series LoRa modules which are based on SEMTECH SX1276/SX1278 chipsets and are available for 170, 433, 470, 868 and 915MHz frequencies in 100mW and 1W transmitting power versions. They all use a simple UART interface to control the device.
Pin layout E32-868T20D (SX1276 868MHz 100mW DIP Wireless Module)
+---------------------------------------------+
| 0 - M0 (set mode) [*] |
| 0 - M1 (set mode) [*] |
| 0 - RXD (TTL UART input) [*] |
| 0 - TXD (TTL UART output) [*] |
| 0 - AUX (device status) [*] |
| 0 - VCC (3.3-5.2V) +---+
| 0 - GND (GND) SMA| Antenna
+-------------------------------------------------+
Transmission modes
-
Transparent : all modules have the same address and channel and can send/receive messages to/from each other. No address and channel is included in the message.
-
Fixed : all modules can have different addresses and channels. The transmission messages are prefixed with the destination address and channel information. If these differ from the settings of the transmitter, then the configuration of the module will be changed before the transmission. After the transmission is complete, the transmitter will revert to its prior configuration.
-
Fixed P2P : The transmitted message has the address and channel information of the receiver. Only this module will receive the message. This is a point to point transmission between 2 modules.
-
Fixed Broadcast : The transmitted message has address FFFF and a channel. All modules with any address and the same channel of the message will receive it.
-
Fixed Monitor : The receiver has adress FFFF and a channel. It will receive messages from all modules with any address and the same channel as the receiver.
-
Operating modes :
-
0=Normal (M0=0,M1=0) : UART and LoRa radio are on.
-
1=wake up (M0=1,M1=0) : Same as normal but preamble code is added to transmitted data to wake up the receiver.
-
2=power save (M0=0,M1=1) : UART is off, LoRa radio is on WOR(wake on radio) mode which means the device will turn on when there is data to be received. Transmission is not allowed.
-
3=sleep (M0=1,M1=1) : UART is on, LoRa radio is off. Is used to get/set module parameters or to reset the module.
Reference for class ebyteE32
ebyteE32
Class to interface an ESP32 via serial commands to the EBYTE E32 Series LoRa modules
Attributes:
Name | Type | Description |
---|---|---|
PORT |
dict
|
dictionary with UART ports |
PARSTR |
dict
|
dictionary with UART parity strings |
PARINV |
dict
|
dictionary with UART parity inverted |
PARBIT |
dict
|
dictionary with UART parity bits |
BAUDRATE |
dict
|
dictionary with UART baudrates |
BAUDRATEINV |
dict
|
dictionary with UART baudrates inverted |
DATARATE |
dict
|
dictionary with LoRa datarates |
DATARATEINV |
dict
|
dictionary with LoRa datarates inverted |
CMDS |
dict
|
dictionary with commands |
OPERMODE |
dict
|
dictionary with operating modes (set with M0 & M1) |
FREQ |
dict
|
dictionary with model frequencies ranges (MHz) |
FREQV |
dict
|
dictionary with version info frequencies |
MAXPOWER |
dict
|
dictionary with model maximum transmission power (mW) |
TRANSMODE |
dict
|
dictionary with transmission modes |
IOMODE |
dict
|
dictionary with I/O drive mode |
WUTIME |
dict
|
dictionary with wireless wakeup times from sleep mode |
FEC |
dict
|
dictionary with Forward Error Correction (FEC) mode |
TXPOWER |
dict
|
dictionary with transmission power T20/T27/T30 (dBm) |
Source code in loraE32/loraE32cp.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 |
|
__init__(PinM0, PinM1, PinAUX, Model='868T20D', Port='U1', Baudrate=9600, Parity='8N1', AirDataRate='2.4k', Address=0, Channel=6, debug=False)
constructor for ebyte E32 LoRa module
Examples:
>>> import board
>>> import ebyteE32
>>> M0pin = board.D2
>>> M1pin = board.D3
>>> AUXpin = board.D4
>>> e32 = ebyteE32(board.D2, board.D3, board.D4, Port='U2', Address=0x0001, Channel=0x04)
>>> e32.start()
'OK'
>>> e32.stop()
'OK'
Parameters:
Name | Type | Description | Default |
---|---|---|---|
PinM0 |
Pin
|
pin identifier for M0 |
required |
PinM1 |
Pin
|
pin identifier for M1 |
required |
PinAUX |
Pin
|
pin identifier for AUX |
required |
Model |
str
|
model of the module (default: '868T20D') |
'868T20D'
|
Port |
str
|
UART port identifier (default: 'U1') |
'U1'
|
Baudrate |
int
|
UART baudrate (default: 9600) |
9600
|
Parity |
str
|
UART parity (default: '8N1') |
'8N1'
|
AirDataRate |
str
|
LoRa air data rate (default: '2.4k') |
'2.4k'
|
Address |
int
|
LoRa address (default: 0x0000) |
0
|
Channel |
int
|
LoRa channel (default: 0x06) |
6
|
debug |
bool
|
debug mode (default: False) |
False
|
Source code in loraE32/loraE32cp.py
calcChecksum(payload)
Calculates checksum for sending/receiving payloads. Sums the ASCII character values mod256 and returns the lower byte of the two's complement of that value in hex notation.
Examples:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
payload |
str
|
payload to calculate checksum for |
required |
Returns:
Name | Type | Description |
---|---|---|
str | checksum in hex notation |
Source code in loraE32/loraE32cp.py
calcFrequency()
Calculate the frequency (= minimum frequency + channel * 1MHz)
Examples:
Returns:
Type | Description |
---|---|
None |
Source code in loraE32/loraE32cp.py
decodeConfig(message)
decode the config message from the ebyte E32 LoRa module to update the config dictionary
Examples:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message |
list
|
config message to decode |
required |
Returns:
Type | Description |
---|---|
None |
Source code in loraE32/loraE32cp.py
encodeConfig()
encode the config dictionary to create the config message of the ebyte E32 LoRa module
Examples:
Returns:
Name | Type | Description |
---|---|---|
list | config message if success, 'NOK' if error |
Source code in loraE32/loraE32cp.py
getConfig()
Get config parameters from the ebyte E32 LoRa module
Examples:
>>> getConfig()
=================== CONFIG =====================
model E32-868T20D
frequency 866Mhz
address 0x0001
channel 0x04
datarate 2.4kbps
port U2
baudrate 9600bps
parity 8N1
transmission transparent
IO mode TXD AUX push-pull output, RXD pull-up input
wakeup time 250ms
FEC on
TX power 20dBm
================================================
Returns:
Name | Type | Description |
---|---|---|
str | config parameters if success, 'NOK' if error |
Raises:
Type | Description |
---|---|
E(Error)
|
if error on getConfig |
Source code in loraE32/loraE32cp.py
getVersion()
Get the version info from the ebyte E32 LoRa module
Examples:
>>> getVersion()
================= E32 MODULE ===================
model 433Mhz
version 16
features 30
================================================
Returns:
Name | Type | Description |
---|---|---|
str | version info if success, 'NOK' if error |
Raises:
Type | Description |
---|---|
E(Error)
|
if error on getVersion |
Source code in loraE32/loraE32cp.py
loadConfigFromJson()
Load config dictionary from JSON file
Examples:
>>> loadConfigFromJson()
{'parity': '8N1', 'datarate': '2.4k', 'model': '868T20D', 'channel': 4, 'transmode': 0, 'port': 'U2', 'frequency': 866, 'baudrate': 9600, 'txpower': 0, 'iomode': 1, 'wutime': 0, 'address': 1, 'fec': 1}
Returns:
Name | Type | Description |
---|---|---|
dict | config dictionary |
Source code in loraE32/loraE32cp.py
recvMessage(from_address, from_channel, useChecksum=False)
Receive payload messages from ebyte E32 LoRa modules in transparent or fixed mode. The payload is a JSON string of a data dictionary to accomodate key value pairs commonly used to store sensor data. If checksumming is used, the checksum of the received payload including the checksum byte should result in 0 for a correct transmission. - transparent mode : payload will be received if the module has the same address and channel of the transmitter - fixed mode : only payloads from transmitters with this address and channel will be received; if the address is 0xFFFF, payloads from all transmitters with this channel will be received
Examples:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
from_address |
int
|
source address (0x0000 - 0xFFFF) |
required |
from_channel |
int
|
source channel (0x00 - 0x1F) |
required |
useChecksum |
bool
|
use 2's complement checksum (default: False) |
False
|
Returns:
Name | Type | Description |
---|---|---|
dict | data dictionary with payload data if success, None if error |
Raises:
Type | Description |
---|---|
E(Error)
|
if error on recvMessage |
Source code in loraE32/loraE32cp.py
reset()
Reset the ebyte E32 Lora module
Examples:
Returns:
Name | Type | Description |
---|---|---|
str | 'OK' if success, 'NOK' if error |
Raises:
Type | Description |
---|---|
E(Error)
|
if error on reset |
Source code in loraE32/loraE32cp.py
saveConfigToJson()
Save config dictionary to JSON file
Examples:
Returns:
Type | Description |
---|---|
None |
sendCommand(command)
Send a command to the ebyte E32 LoRa module. The module has to be in sleep mode
Examples:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command |
str
|
command to send |
required |
Returns:
Name | Type | Description |
---|---|---|
str | 'OK' if success, 'NOK' if error |
Raises:
Type | Description |
---|---|
E(Error)
|
if error on sendCommand |
Source code in loraE32/loraE32cp.py
sendMessage(to_address, to_channel, payload, useChecksum=False)
Send the payload to ebyte E32 LoRa modules in transparent or fixed mode. The payload is a data dictionary to accomodate key value pairs commonly used to store sensor data and is converted to a JSON string before sending. The payload can be appended with a 2's complement checksum to validate correct transmission.
- transparent mode : all modules with the same address and channel of the transmitter will receive the payload
- fixed mode : only the module with this address and channel will receive the payload; if the address is 0xFFFF all modules with the same channel will receive the payload
Examples:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
to_address |
int
|
target address (0x0000 - 0xFFFF) |
required |
to_channel |
int
|
target channel (0x00 - 0x1F) |
required |
payload |
dict
|
data dictionary to send |
required |
useChecksum |
bool
|
use 2's complement checksum (default: False) |
False
|
Returns:
Name | Type | Description |
---|---|---|
str | 'OK' if success, 'NOK' if error |
Raises:
Type | Description |
---|---|
E(Error)
|
if error on sendMessage |
Source code in loraE32/loraE32cp.py
setConfig(save_cmd)
Set config parameters for the ebyte E32 LoRa module
Examples:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
save_cmd |
str
|
'setConfigPwrDwnSave' or 'setConfig' |
required |
Returns:
Name | Type | Description |
---|---|---|
str | 'OK' if success, 'NOK' if error |
Source code in loraE32/loraE32cp.py
setOperationMode(mode)
Set operation mode of the E32 LoRa module
Examples:
Args: mode (str): 'normal', 'wakeup', 'powerdown', 'sleep'
Source code in loraE32/loraE32cp.py
setTransmissionMode(transmode)
Set the transmission mode of the E32 LoRa module
Examples:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transmode |
int
|
0 = transparent, 1 = fixed length |
required |
Returns:
Type | Description |
---|---|
None |
Source code in loraE32/loraE32cp.py
showConfig()
Show the config parameters of the ebyte E32 LoRa module on the shell
Examples:
>>> showConfig()
=================== CONFIG =====================
model E32-868T20D
frequency 866Mhz
address 0x0001
channel 0x04
datarate 2.4kbps
port U2
baudrate 9600bps
parity 8N1
transmission transparent
IO mode TXD AUX push-pull output, RXD pull-up input
wakeup time 250ms
FEC on
TX power 20dBm
================================================
Returns:
Name | Type | Description |
---|---|---|
str | with the config parameters |
Source code in loraE32/loraE32cp.py
start()
Start the ebyte E32 LoRa module
Raises:
Type | Description |
---|---|
E(Error)
|
if error on start UART |
Source code in loraE32/loraE32cp.py
stop()
Stop the ebyte E32 LoRa module
Examples:
Returns:
Name | Type | Description |
---|---|---|
str | 'OK' if success, 'NOK' if error |
Raises:
Type | Description |
---|---|
E(Error)
|
if error on stop |
Source code in loraE32/loraE32cp.py
waitForDeviceIdle()
Wait for the E32 LoRa module to become idle (AUX pin high)
Examples:
Returns:
Type | Description |
---|---|
None |